안녕하세요.. 사운드 녹음과 재생이라는 제목으로 올라온 강좌의 예제 입니다.
근데, 컴파일이 안되서요...
이걸 Delphi 1, 2 버전이라는데..... 저는 지금 Delphi 5 로 작업하고 있거든요..
어디를 고쳐야 하는지.. 아니면, 폼에 빠진게 있는지... 여러분의 도움을 부탁드립니다.
-------------------------------------------------------------------
Echo1.pas
-------------------------------------------------------------------
unit echo1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
MMSystem, WinTypes, WinProcs;
const
memBlockLength = 500;
type
Tmemblock = array[0..memblocklength] of byte;
PmemBlock = ^TmemBlock;
TForm1 = class(TForm)
procedure FormCreate(Sender: TObject);
procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
private
{ Private declarations }
HwaveIn : PHWaveIn;
HWaveOut : PHWaveOut;
close_invoked, close_complete : boolean;
in_count, out_count : integer;
procedure MMOutDone(var msg : Tmessage);
message MM_WOM_DONE;
procedure MMInDone(var msg : Tmessage);
message MM_WIM_DATA;
public
{ Public declarations }
end;
{ TPCMWaveFormat = record
wf : TWaveFormat;
wBitsPerSample : Word;
end;
}
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.FormCreate(Sender: TObject);
var
WaveFormat : PPCMWaveFormat;
Header : PWaveHdr;
memBlock : PmemBlock;
i, j : integer;
begin
WaveFormat := new(PPCMwaveFormat);
with WaveFormat^.wf do
begin
WFormatTag := WAVE_FORMAT_PCM;
NChannels := 1;
NSamplesPerSec := 11000;
NAvgBytesPerSec := 11000;
NBlockAlign := 1;
waveformat^.wBitsPerSample := 8;
end;
i := waveOutOpen(nil, 0, PWaveFormat(WaveFormat), 0, 0, WAVE_FORMAT_QUERY);
if i<>0 then
application.messagebox('Error', 'Play format not supported', mb_OK);
i := waveInOpen(nil, 0, PWaveFormat(WaveFormat), 0, 0, WAVE_FORMAT_QUERY);
if i<>0 then
application.messagebox('Error', 'Record format not supported', mb_OK);
HwaveOut := new(PHwaveOut);
i := waveOutOpen(HWaveOut, 0, Pwaveformat(WaveFormat), form1.handle, 0, CALLBACK_WINDOW);
if i<>0 then
application.messagebox('Error', 'Problem creating play handle', mb_OK);
HwaveIn := new(PHwaveIn);
i := waveInOpen(HWaveIn, 0, Pwaveformat(WaveFormat), form1.handle, 0, CALLBACK_WINDOW);
if i<>0 then
application.messagebox('Error', 'Problem creating record handle', mb_OK);
in_count := 0;
out_count := 0;
for j:=1 to 3 do
begin
Header := new(PWaveHdr);
memBlock := new(PmemBlock);
Header := new(PwaveHdr);
with header^ do
begin
lpdata := pointer(memBlock);
dwbufferlength := memblocklength;
dwbytesrecorded := 0;
dwUser := 0;
dwflags := 0;
dwloops := 0;
end;
i := waveInPrepareHeader(HWaveIn^, Header, sizeof(TWavehdr));
if i<>0 then
application.messagebox('In Prepare error', 'error', mb_OK);
i := waveInAddBuffer(HWaveIn^, Header, sizeof(TWaveHdr));
if i<>0 then
application.messagebox('Add buffer error', 'error', mb_OK);
inc(in_count);
end;
i := waveInStart(HwaveIn^);
if i<>0 then
application.messagebox('Start error', 'error', mb_ok);
close_invoked := false;
close_complete := false;
end;
procedure TForm1.MMOutDone(var msg:Tmessage);
var
Header : PWaveHdr;
i : integer;
begin
dec(out_count);
Header := PWaveHdr(msg.lparam);
i := waveOutUnPrepareHeader(HWaveOut^, Header, sizeof(TWavehdr));
if i<>0 then
application.messagebox('Out Un Prepare error', 'error', mb_ok);
dispose(Header^.lpdata);
dispose(Header);
if (out_count=0) then
begin
WaveOutClose(HWaveOut^);
HwaveOut := nil;
end;
if (in_count=0) and (out_count=0) then
begin
close_complete := true;
close;
end;
end;
procedure TForm1.MMInDone(var msg:Tmessage);
var
Header : PWaveHdr;
memBlock : PmemBlock;
i : integer;
begin
dec(in_count);
Header := PWaveHdr(msg.lparam);
i := waveInUnPrepareHeader(HWaveIn^, Header, sizeof(TWavehdr));
if i<>0 then
application.messagebox('In Un Prepare error', 'error', mb_ok);
if not(close_invoked) then
begin
i := waveOutPrepareHeader(HWaveOut^, Header, sizeof(TWavehdr));
if i<>0 then
application.messagebox('Out prepare error', 'error', mb_ok);
i := waveOutWrite(HWaveOut^, Header, sizeof(TWaveHdr));
if i<>0 then
application.messagebox('Wave out error', 'error', mb_ok);
inc(out_count);
Header := new(PWaveHdr);
memBlock := new(PmemBlock);
Header := new(PwaveHdr);
with header^ do
begin
lpdata := pointer(memBlock);
dwbufferlength := memblocklength;
dwbytesrecorded := 0;
dwUser := 0;
dwflags := 0;
dwloops := 0;
end;
i := waveInPrepareHeader(HWaveIn^, Header, sizeof(TWavehdr));
if i<>0 then
application.messagebox('In Prepare error', 'error', mb_ok);
i := waveInAddBuffer(HWaveIn^, Header, sizeof(TWaveHdr));
if i<>0 then
application.messagebox('Add buffer error', 'error', mb_ok);
inc(in_count);
end;
if (in_count=0) then
begin
WaveInClose(HWaveIn);
HWaveIn := nil;
end;
if (in_count=0) and (out_count=0) then
begin
close_complete := true;
close;
end;
end;
procedure TForm1.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
begin
if HWaveOut <> nil then
WaveOutReset(HWaveOut^);
if HwaveIn <> nil then
WaveInReset(HWaveIn^);
close_invoked := true;
canclose := close_complete;
end;
end.
----------------------------------------------------------------
WaveOutOpen에서 쓰이는 파라메터의 형이 PWaveFormat 에서 PWaveFormatEx로 바뀜
아래와 같이 고치세요...
> -------------------------------------------------------------------
> Echo1.pas
> -------------------------------------------------------------------
> unit echo1;
>
> interface
>
> uses
> Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
> MMSystem;
********************************************************************************
=====> WinTypes, WinProcs; 삭제
********************************************************************************
>
> const
> memBlockLength = 500;
> type
> Tmemblock = array[0..memblocklength] of byte;
> PmemBlock = ^TmemBlock;
>
> TForm1 = class(TForm)
> procedure FormCreate(Sender: TObject);
> procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
> private
> { Private declarations }
> HwaveIn : PHWaveIn;
> HWaveOut : PHWaveOut;
> close_invoked, close_complete : boolean;
> in_count, out_count : integer;
> procedure MMOutDone(var msg : Tmessage);
> message MM_WOM_DONE;
> procedure MMInDone(var msg : Tmessage);
> message MM_WIM_DATA;
> public
> { Public declarations }
> end;
>
> { TPCMWaveFormat = record
> wf : TWaveFormat;
> wBitsPerSample : Word;
> end;
> }
>
> var
> Form1: TForm1;
>
> implementation
>
> {$R *.DFM}
>
> procedure TForm1.FormCreate(Sender: TObject);
> var
> WaveFormat : PPCMWaveFormat;
> Header : PWaveHdr;
> memBlock : PmemBlock;
> i, j : integer;
> begin
> WaveFormat := new(PPCMwaveFormat);
> with WaveFormat^.wf do
> begin
> WFormatTag := WAVE_FORMAT_PCM;
> NChannels := 1;
> NSamplesPerSec := 11000;
> NAvgBytesPerSec := 11000;
> NBlockAlign := 1;
> waveformat^.wBitsPerSample := 8;
> end;
>
> i := waveOutOpen(nil, 0, PWaveFormat(WaveFormat), 0, 0, WAVE_FORMAT_QUERY);
********************************************************************************
=====> i := waveOutOpen(nil, 0, PWaveFormatEx(WaveFormat), 0, 0, WAVE_FORMAT_QUERY);
********************************************************************************
>
> if i<>0 then
> application.messagebox('Error', 'Play format not supported', mb_OK);
>
> i := waveInOpen(nil, 0, PWaveFormat(WaveFormat), 0, 0, WAVE_FORMAT_QUERY);
********************************************************************************
=====> i := waveOutOpen(nil, 0, PWaveFormatEx(WaveFormat), 0, 0, WAVE_FORMAT_QUERY);
********************************************************************************
>
> if i<>0 then
> application.messagebox('Error', 'Record format not supported', mb_OK);
>
> HwaveOut := new(PHwaveOut);
>
> i := waveOutOpen(HWaveOut, 0, Pwaveformat(WaveFormat), form1.handle, 0, CALLBACK_WINDOW);
********************************************************************************
=====> i := waveOutOpen(HWaveOut, 0, PwaveformatEx(WaveFormat), form1.handle, 0, CALLBACK_WINDOW);
********************************************************************************
>
> if i<>0 then
> application.messagebox('Error', 'Problem creating play handle', mb_OK);
>
> HwaveIn := new(PHwaveIn);
> i := waveInOpen(HWaveIn, 0, Pwaveformat(WaveFormat), form1.handle, 0, CALLBACK_WINDOW);
********************************************************************************
=====> i := waveOutOpen(HWaveOut, 0, PwaveformatEx(WaveFormat), form1.handle, 0, CALLBACK_WINDOW);
********************************************************************************
>
> if i<>0 then
> application.messagebox('Error', 'Problem creating record handle', mb_OK);
>
> in_count := 0;
> out_count := 0;
>
> for j:=1 to 3 do
> begin
> Header := new(PWaveHdr);
> memBlock := new(PmemBlock);
>
> Header := new(PwaveHdr);
> with header^ do
> begin
> lpdata := pointer(memBlock);
> dwbufferlength := memblocklength;
> dwbytesrecorded := 0;
> dwUser := 0;
> dwflags := 0;
> dwloops := 0;
> end;
>
> i := waveInPrepareHeader(HWaveIn^, Header, sizeof(TWavehdr));
>
> if i<>0 then
> application.messagebox('In Prepare error', 'error', mb_OK);
>
> i := waveInAddBuffer(HWaveIn^, Header, sizeof(TWaveHdr));
>
> if i<>0 then
> application.messagebox('Add buffer error', 'error', mb_OK);
>
> inc(in_count);
>
> end;
>
> i := waveInStart(HwaveIn^);
> if i<>0 then
> application.messagebox('Start error', 'error', mb_ok);
>
> close_invoked := false;
> close_complete := false;
> end;
>
> procedure TForm1.MMOutDone(var msg:Tmessage);
> var
> Header : PWaveHdr;
> i : integer;
> begin
> dec(out_count);
>
> Header := PWaveHdr(msg.lparam);
> i := waveOutUnPrepareHeader(HWaveOut^, Header, sizeof(TWavehdr));
>
> if i<>0 then
> application.messagebox('Out Un Prepare error', 'error', mb_ok);
>
> dispose(Header^.lpdata);
> dispose(Header);
>
> if (out_count=0) then
> begin
> WaveOutClose(HWaveOut^);
> HwaveOut := nil;
> end;
>
> if (in_count=0) and (out_count=0) then
> begin
> close_complete := true;
> close;
> end;
> end;
>
> procedure TForm1.MMInDone(var msg:Tmessage);
> var
> Header : PWaveHdr;
> memBlock : PmemBlock;
> i : integer;
> begin
> dec(in_count);
> Header := PWaveHdr(msg.lparam);
> i := waveInUnPrepareHeader(HWaveIn^, Header, sizeof(TWavehdr));
>
> if i<>0 then
> application.messagebox('In Un Prepare error', 'error', mb_ok);
>
> if not(close_invoked) then
> begin
> i := waveOutPrepareHeader(HWaveOut^, Header, sizeof(TWavehdr));
>
> if i<>0 then
> application.messagebox('Out prepare error', 'error', mb_ok);
>
> i := waveOutWrite(HWaveOut^, Header, sizeof(TWaveHdr));
>
> if i<>0 then
> application.messagebox('Wave out error', 'error', mb_ok);
>
> inc(out_count);
>
> Header := new(PWaveHdr);
> memBlock := new(PmemBlock);
>
> Header := new(PwaveHdr);
> with header^ do
> begin
> lpdata := pointer(memBlock);
> dwbufferlength := memblocklength;
> dwbytesrecorded := 0;
> dwUser := 0;
> dwflags := 0;
> dwloops := 0;
> end;
>
> i := waveInPrepareHeader(HWaveIn^, Header, sizeof(TWavehdr));
>
> if i<>0 then
> application.messagebox('In Prepare error', 'error', mb_ok);
>
> i := waveInAddBuffer(HWaveIn^, Header, sizeof(TWaveHdr));
>
> if i<>0 then
> application.messagebox('Add buffer error', 'error', mb_ok);
>
> inc(in_count);
> end;
>
> if (in_count=0) then
> begin
> WaveInClose(HWaveIn);
********************************************************************************
=====> WaveInClose(HWaveIn^);
********************************************************************************
> HWaveIn := nil;
> end;
>
> if (in_count=0) and (out_count=0) then
> begin
> close_complete := true;
> close;
> end;
> end;
>
>
> procedure TForm1.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
> begin
> if HWaveOut <> nil then
> WaveOutReset(HWaveOut^);
>
> if HwaveIn <> nil then
> WaveInReset(HWaveIn^);
>
> close_invoked := true;
> canclose := close_complete;
>
> end;
>
> end.
> ----------------------------------------------------------------
>
>
>
>
>