Procedure Tform1.WNDPROC(var msg:TMessage);
var Hdr:PWaveHdr; i:integeR; r:real;
begin
INHERITED;
case msg.Msg of
MM_WIM_OPEN:
begin
Button1.Enabled:=false;
Button2.Enabled:=true;
Form2.Show;
end;
MM_WIM_CLOSE:
begin
Button1.Enabled:=true;
Button2.Enabled:=false;
Combobox2.Enabled:=true;
Combobox3.Enabled:=true;
Form2.Hide;
end;
MM_WIM_DATA:
if WaveIn<>nil then
begin
Hdr:=PWaveHdr(msg.LParam);
if hdr^.dwBytesRecorded>0
then r:=Form2.ClientWidth/hdr^.dwBytesRecorded
else r:=0;
PatBlt(Form2.Canvas.Handle,0,0,Form2.ClientWidth,form2.ClientHeight,BLACKNESS);//WHITENESS DSTINVERT DSTCOPY ...
(* oder form2.canvas.fillrect(Form2.canvas.cliprect); *)
Form2.Canvas.Pen.Color:=clLime;
Form2.Canvas.MoveTo(0,PArrayBuf(hdr.lpData)^[0]);
for i:=0 to hdr^.dwBytesRecorded-1 do Form2.Canvas.lineTo(round(r*i),PArrayBuf(hdr.lpData)^[i]);
Procedure Tform1.InitWaveIn(IsInit:boolean);
var
i:integer;
WaveHdr:PWaveHdr;
DaBuffer:PArrayBuf;
openError,PrepareError,BufferAddError,StartError:integer;
begin
if IsInit then
begin
WaveFormat.wFormatTag:=WAVE_FORMAT_PCM;
WaveFormat.nChannels:=1; //MONO
WaveFormat.nSamplesPerSec:=strtoint(Combobox2.Text);
WaveFormat.nAvgBytesPerSec:=strtoint(Combobox2.Text);
WaveFormat.nBlockAlign:=strtoint(Combobox3.Text);
WaveFormat.wBitsPerSample:=8;
WaveIn:=new(PHWaveIn);
openError:=WaveInOpen(WaveIn,0,@WaveFormat,handle,0,CALLBACK_WINDOW);
for i:=1 to 8 do
begin
DaBuffer:=new(PArrayBuf);
WaveHdr:=new(PWaveHdr);
with WaveHdr^ do
begin
lpData:=pointer(DaBuffer);
dwBufferLength:=sizeof(DaBuffer);//1024 = 1 KByte
dwBytesRecorded:=0;
dwUser:=0;
dwFlags:=0;
dwLoops:=0;
end;
PrepareError:=WaveInPrepareHeader(WaveIn^,WaveHdr,sizeOf(TWaveHdr));
BufferAddError:=WaveInAddBuffer(WaveIn^,WaveHdr,Sizeof(TWaveHdr));//Schreibt die Header in die "zu Verarbeiten Liste"
end;
StartError:=WaveInStart(WaveIn^);//Startet das "Verarbeiten"
if (openError<>0)or(PrepareError<>0)or(BufferAddError<>0)or(StartError<>0)then
Showmessage(
'WaveInOpen :'+inttostr(openError)+#13+
'WaveInPrepareHeader :'+inttostr(PrepareError)+#13+
'WaveInAddBuffer :'+inttostr(BufferAddError)+#13+
'StartError :'+inttostr(StartError)+#13);
end else
begin
WaveInStop(WaveIn^);//Stop
if WaveIn<>nil then WaveInReset(WaveIn^);
if WaveIn<>nil then WaveInClose(WaveIn^);
Dispose(WaveIn);
WaveIn:=nil;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
IsOn:=true;
InitWaveIn(true);
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
IsOn:=false;
InitWaveIn(false);
end;