interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Wave, dspDTMF;
type
TfmMain = class(TForm)
Button1: TButton;
OpenDialog1: TOpenDialog;
Label1: TLabel;
Edit1: TEdit;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure FormDestroy(Sender: TObject);
private
DTMF: TdspDTMF; // DTMF decoder (see the dspDTMF
unit)
procedure OnTone(Sender: TObject; Tone: Char);
end;
var
fmMain: TfmMain;
implementation
{$R *.dfm}
procedure TfmMain.FormCreate(Sender: TObject);
begin
Caption:= Application.Title;
DTMF:= TdspDTMF.Create;
DTMF.OnTone:= OnTone;
end;
procedure TfmMain.FormDestroy(Sender: TObject);
begin
DTMF.Free;
end;
procedure TfmMain.Button1Click(Sender: TObject);
var
B: Byte;
S: SmallInt;
Wave: TWaveFileStream;
begin
if OpenDialog1.Execute then
begin
Edit1.Text:= '';
Wave:= TWaveFileStream.Create(OpenDialog1.FileName, fmOpenRead);
try
Wave.Open(false);
if Wave.Format.nChannels <> 1 then
begin
MessageDlg('This demo supports Mono files only', mtWarning, [mbCancel], 0);
Edit1.Text:= 'Format not supported';
Exit;
end;
DTMF.SampleRate:= Wave.Format.nSamplesPerSec;
DTMF.Initialize;
Caption:= 'Searching for tones...';
Application.ProcessMessages;
try
if Wave.Format.wBitsPerSample = 8 then
begin
DTMF.Threshold:= 1; // Set amplitude threshold
while Wave.Read(B, 1) = 1 do DTMF.Put(B)
end else
begin
DTMF.Threshold:= 100; // Set amplitude threshold
while Wave.Read(S, 2) = 2 do DTMF.Put(S);
end;
DTMF.Finilize;
finally
Caption:= Application.Title;
end;
finally
Wave.Free;
if Edit1.Text = '' then Edit1.Text:= 'not found...';
end;
end;
end;
procedure TfmMain.OnTone(Sender: TObject; Tone: Char);
begin
Edit1.Text:= Edit1.Text + Tone;
end;
end.