ExceleTel Header Logo

 

menu_end_leftmenu_homemenu_aboutmenu_productsmenu_salesmenu_supportmenu_searchmenu_end_right

 

etWaveFormats Sample Program Source Code for Delphi

const NL = #13 + #10; //insert a new line

var
Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
 var x: TWAVFORMATS; // create an index variable of TeleTools TWAVFORMATS type
begin
     // enable all of the TeleTools components and show TeleScopes
     Memo1.Lines.Delete(0);
     etRecord1.Enabled := True;
     etRecord1.TeleScope.Visible := True;
     etPlay1.Enabled := True;
     etPlay1.TeleScope.Visible := True;

     { ***** FILL ComboBoxWavFmtIDs *****
     { Use the ID's of all the major wave formats as referenced in the
     { etTTConst.pas file. Since we aren't using all the formats in order
     { as in the shortcut below this code section, we can't just use the
     { item index to reference the constant that refers to the item.
     { Here, we are only using mono formats, which skips every other one
     { in the list, so we create an object to hold the odd number values
     { assigned to those wave formats and put them and a text description
     { of them in the combobox
     }
     ComboBoxWavFmtIds.Items.AddObject('Unknown', TObject(0));
     ComboBoxWavFmtIDs.Items.AddObject('wfPCM08000M08', TObject(1));
     ComboBoxWavFmtIDs.Items.AddObject('wfPCM08000M16', TObject(3));
     ComboBoxWavFmtIDs.Items.AddObject('wfPCM11025M08', TObject(5));
     ComboBoxWavFmtIDs.Items.AddObject('wfPCM11025M16', TObject(7));
     ComboBoxWavFmtIDs.Items.AddObject('wfPCM22050M08', TObject(9));
     ComboBoxWavFmtIDs.Items.AddObject('wfPCM22050M16', TObject(11));

     { ***** FILL ComboBoxWavFmtNames *****
     { NOTE: This method only available on TeleTools v3.8 and above!
     ( If you know the exact string specified for wave formats as shown
     { below and described in the etTTConst.pas file, you can just enter
     { them and refer to them by the .source.format.name property
     { Here we populate the next combobox by the format name string
     { with just the first few Mono wave formats
     }
     ComboBoxWavFmtNames.Items.Add('Unknown');
     ComboBoxWavFmtNames.Items.Add('PCM 8,000 Hz, 8-bit, Mono');
     ComboBoxWavFmtNames.Items.Add('PCM 8,000 Hz, 16-bit, Mono');
     ComboBoxWavFmtNames.Items.Add('PCM 11,025 Hz, 8-bit, Mono');
     ComboBoxWavFmtNames.Items.Add('PCM 11,025 Hz, 16-bit, Mono');
     ComboBoxWavFmtNames.Items.Add('PCM 22,050 Hz, 8-bit, Mono');
     ComboBoxWavFmtNames.Items.Add('PCM 22,050 Hz, 16-bit, Mono');

     This shortcut only works if you want to populate a component with
     a sequential list of the TeleTools wave constants that are defined
     in the etTTConst.pas file. We use the constants like wfUnknown and
     wfPCM08000M08 to describe the wave format and assign them to values
     from 0 to the last defined format (referenced by wfCOUNT). Here we
     start with the first format (wfUnknown) to the last wave format and
     populate the next combobox with the wave formats

     For x := wfUnknown to wfIMAADPCM08000M04 do
     // known typo, ET_WAV_FOMAT will be corrected to ET_WAV_FORMAT in 3.8
     ComboBoxWavFmtShortCut.Items.Add(ET_WAV_FOMAT[x].sName);

     // Fill ComboBoxWavFile with some test wave files
     ComboBoxWavFile.Items.Add('8kHz,8bit,Mono');
     ComboBoxWavFile.Items.Add('8kHz,16bit,Mono');
     ComboBoxWavFile.Items.Add('11kHz,8bit,Mono');
     ComboBoxWavFile.Items.Add('22kHz,16bit,Mono');

     ComboBoxWavFmtIDs.ItemIndex := 1;
     ComboBoxWavFmtNames.ItemIndex := 1;
     ComboBoxWavFmtShortCut.ItemIndex := 1;
     ComboBoxWavFile.ItemIndex := 0;
     RadioGroupSetWavFmtMethod.ItemIndex := 0;

     // fill the combobox with all our audio devices
     ComboBoxAudioDevs.Items := etPlay1.Device.List;
     ComboBoxAudioDevs.ItemIndex := 0
  end;

procedure TForm1.ComboBoxWavFmtIDsChange(Sender: TObject);
begin
    etRecord1.Source.Format.ID :=TWAVFORMATS(ComboBoxWavFmtIDs.Items.Objects[ComboBoxWavFmtIDs.ItemIndex]);
    Memo1.Lines.Add('Selection is = ' + ComboBoxWavFmtIDs.Text);
    WriteWavInfo(Sender);
end;

procedure TForm1.ComboBoxWavFmtNamesChange(Sender: TObject);
begin
   // check to make sure this is version 4.0 or above to use this method
   if StrToInt((MidStr(etRecord1.About.Version,1,1) + MidStr(etRecord1.About.Version,3,1))) < 40 then
     begin
        Memo1.Lines.Add('Your version is ' + etRecord1.About.Version + ', you must have version');
        Memo1.Lines.Add('4.0 of TeleTools or above to use this method');
        Memo1.Lines.Add('');
     end
   else
     begin
        etRecord1.Source.Format.Name := ComboBoxWavFmtNames.Text;
        Memo1.Lines.Add('Selection is = ' + ComboBoxWavFmtNames.Text);
        WriteWavInfo(Sender);
     end
end;


procedure TForm1.ComboBoxWavFmtShortCutChange(Sender: TObject);
begin
   etRecord1.Source.Format.ID := TWAVFORMATs(ComboBoxWavFmtShortCut.ItemIndex);
   Memo1.Lines.Add('Selection is = ' + ComboBoxWavFmtShortCut.Text);
   WriteWavInfo(Sender);
end;

procedure TForm1.RadioGroupSetWavFmtMethodClick(Sender: TObject);
begin
   If RadioGroupSetWavFmtMethod.ItemIndex = 0 then // using ID's
     Begin
        ComboBoxWavFmtNames.Enabled := False;
        ComboBoxWavFmtIDs.Enabled := True;
        ComboBoxWavFmtShortCut.Enabled := False;
        ComboBoxWavFile.Enabled := False;
        CheckBoxCodecsEnabled.Enabled := False;
        ButtonPlay.Enabled := False;
        ComboBoxWavFmtIDsChange(Sender); // make sure change triggers
     end
   else if RadioGroupSetWavFmtMethod.ItemIndex = 1 then // using names
     Begin
        ComboBoxWavFmtNames.Enabled := True;
        ComboBoxWavFmtIDs.Enabled := False;
        ComboBoxWavFmtShortCut.Enabled := False;
        ComboBoxWavFile.Enabled := False;
        CheckBoxCodecsEnabled.Enabled := False;
        ButtonPlay.Enabled := False;
        ComboBoxWavFmtNamesChange(Sender);
     end
   else if RadioGroupSetWavFmtMethod.ItemIndex = 2 then // using shortcut
     Begin
        ComboBoxWavFmtNames.Enabled := False;
        ComboBoxWavFmtIDs.Enabled := False;
        ComboBoxWavFmtShortCut.Enabled := True;
        ComboBoxWavFile.Enabled := False;
        CheckBoxCodecsEnabled.Enabled := False;
        ButtonPlay.Enabled := False;
        ComboBoxWavFmtShortCutChange(Sender);
      End
   else if RadioGroupSetWavFmtMethod.ItemIndex = 3 then // playing a wave
     Begin
        ComboBoxWavFmtNames.Enabled := False;
        ComboBoxWavFmtIDs.Enabled := False;
        ComboBoxWavFmtShortCut.Enabled := False;
        ComboBoxWavFile.Enabled := True;
        CheckBoxCodecsEnabled.Enabled := True;
        ButtonPlay.Enabled := True;
        ComboBoxWavFmtShortCutChange(Sender);
      End
    else
       Memo1.Lines.Add('Error: RadioButton selection out of range')
end;

procedure TForm1.WriteWavInfo(Sender: TObject);
begin
   If Sender = ButtonPlay then
     begin
       Memo1.Lines.Add('etPlay.Device.Name = ' + etPlay1.Device.Name);
       Memo1.Lines.Add('etPlay.Device.ID = ' + IntToStr(etPlay1.Device.ID));
       Memo1.Lines.Add('etPlay.Source.Format.Name = ' + etPlay1.Source.Format.Name);
       Memo1.Lines.Add('etPlay.Source.Format.ID = ' + IntToStr(Integer(etPlay1.Source.Format.ID)));
       Memo1.Lines.Add('etPlay.Source.Format.AvgBytesPerSec = '+IntToStr(etPlay1.Source.Format.AvgBytesPerSec));
       Memo1.Lines.Add('etPlay.Source.Format.BitsPerSample = ' + IntToStr(etPlay1.Source.Format.BitsPerSample));
       Memo1.Lines.Add('etPlay.Source.Format.BlockAlign = ' + IntToStr(etPlay1.Source.Format.BlockAlign));
       Memo1.Lines.Add('etPlay.Source.Format.Channels = ' + IntToStr(etPlay1.Source.Format.Channels));
       Memo1.Lines.Add('etPlay.Source.Format.SamplesPerSec = ' + IntToStr(etPlay1.Source.Format.SamplesPerSec));
       Memo1.Lines.Add('etPlay.Source.Format.Tag = ' + IntToStr(etPlay1.Source.Format.Tag));
       Memo1.Lines.Add('');
    end
  else
    begin
       Memo1.Lines.Add('etRecord.Device.Name = ' + etRecord1.Device.Name);
       Memo1.Lines.Add('etRecord.Device.ID = ' + IntToStr(etRecord1.Device.ID));
       Memo1.Lines.Add('etRecord.Source.Format.Name = ' + etRecord1.Source.Format.Name);
       Memo1.Lines.Add('etRecord.Source.Format.ID = ' + IntToStr(Integer(etRecord1.Source.Format.ID)));
       Memo1.Lines.Add('etRecord.Source.Format.AvgBytesPerSec = '+IntToStr(etRecord1.Source.Format.AvgBytesPerSec));
       Memo1.Lines.Add('etRecord.Source.Format.BitsPerSample = ' + IntToStr(etRecord1.Source.Format.BitsPerSample));
       Memo1.Lines.Add('etRecord.Source.Format.BlockAlign = ' + IntToStr(etRecord1.Source.Format.BlockAlign));
       Memo1.Lines.Add('etRecord.Source.Format.Channels = ' + IntToStr(etRecord1.Source.Format.Channels));
       Memo1.Lines.Add('etRecord.Source.Format.SamplesPerSec = ' + IntToStr(etRecord1.Source.Format.SamplesPerSec));
       Memo1.Lines.Add('etRecord.Source.Format.Tag = ' + IntToStr(etRecord1.Source.Format.Tag));
       Memo1.Lines.Add('');
    end
end;

procedure TForm1.ButtonClearClick(Sender: TObject);
begin
    Memo1.Lines.Clear;
end;

procedure TForm1.ButtonPlayClick(Sender: TObject);
var sFileName: string;
begin
    If CheckBoxCodecsEnabled.Checked then
      begin
        etPlay1.Device.CODECsEnabled := True;
        Memo1.Lines.Add('CODECS Enabled = True');
      end
    else
      begin
      etPlay1.Device.CODECsEnabled := False;
      Memo1.Lines.Add('CODECS Enabled = False');
    end;

    etPlay1.Device.ID := ComboBoxAudioDevs.ItemIndex;
    Case ComboBoxWavFile.ItemIndex of
      0: sFileName := 'waveformats_8k8bit';
      1: sFileName := 'waveformats_8k16bit';
      2: sFileName := 'waveformats_11k8bit';
      3: sFileName := 'waveformats_22k16bit';
    end;
    etPlay1.Source.FileName := sFileName;
    WriteWavInfo(Sender);
    Memo1.Lines.Add('etPlay1.Source.Filename := ' + sFileName);
    Memo1.Lines.Add('Sending wave file to ' + etPlay1.Device.Name + '...'); 
    // stop the wave file if one is playing and the play button is pressed again
    if etPlay1.Device.Active then
      begin
        etPlay1.Device.Active := False;
        if etPlay1.Device.Active then
        Memo1.Lines.Add(#9 + 'Error = ' + etPlay1.Error.Text);
      end;
      // play the wave file
      etPlay1.device.Active := true;
      if not etPlay1.Device.Active then
        begin
          Memo1.Lines.add('Error playing wave file, ' + etPlay1.Error.Text);
          If (etPlay1.Error.Text = 'WAVERR_BADFORMAT') or (etPlay1.Error.Text ='MMSYSERR_ERROR') then
            begin
              Memo1.Lines.Add('...Or your device is not on a call in the connected state');
              Memo1.Lines.Add(' Try playing to your soundcard...');
            end;
          Memo1.lines.add('');
          etPlay1.Device.Active :=false;
        end
      else
        Memo1.Lines.add('etPlay1.Device.Active := True');
end;

procedure TForm1.etPlay1Done(Sender: TObject);
begin
Memo1.Lines.Add('OnDone')
end;

procedure TForm1.BitBtnInfoClick(Sender: TObject);
begin
ShowMessage(' etWaveFormats Sample Program' + NL + NL + 'Copyright(c) 2003 ExceleTel Inc.'
+ NL + NL + ' www.exceletel.com');
end;


end.

 

 
 


Copyright © 1997-2007 ExceleTel Inc. All rights reserved. Friday August 17, 2007 11:05:24 AM

Contact Us