0
0

Hi,

I´ve problems to understand the example how to record a sound to wav. Does anybody know how to record a sound to wav in Delphi. Any examples are welcome.

Thanks

Speed78

  • You must to post comments
0
0

Set the FSOUND_SetOutput to NONREALTIME:

[code:389aoz2x]
FSOUND_SetOutput(FSOUND_OUTPUT_NOSOUND_NONREALTIME);
if not FSOUND_Init(44100, 32, 0) then
begin
MessageDlg(FMOD_ErrorString(FSOUND_GetError), mtError, mbOKCancel,0);
FSOUND_Close();
exit;
end;
[/code:389aoz2x]

Create A DSP-Callback (rawwrite_dsp is a pointer):
WriteBuffer is a function: function WriteBuffer(OriginalBuffer: Pointer; NewBuffer: Pointer; Length, Param: Integer): Pointer; stdcall;

[code:389aoz2x]
rawwrite_dsp := FSOUND_DSP_Create(@WriteBuffer, FSOUND_DSP_DEFAULTPRIORITY_USER, 0);
FSOUND_DSP_SetActive(RawWrite_DSP, true);
stream := FSOUND_Stream_Open(inFileName, FSOUND_NORMAL + FSOUND_MPEGACCURATE, 0, 0);
[/code:389aoz2x]

Create a new file using a TFileStream
Set the values in this record and write this header to the new .wav file:

[code:389aoz2x]{ format of WAV file header }
TWavHeader = record { parameter description }
rId : array [0..3] of char; { ‘RIFF’ 4 characters }
rLen : longint; { length of DATA + FORMAT chunk }
{ FORMAT CHUNK }
wId : array [0..3] of char; { ‘WAVE’ }
fId : array [0..3] of char; { ‘fmt ‘ }
fLen : longint; { length of FORMAT DATA = 16 }
{ format data }
wFormatTag : word; { $01 = PCM }
nChannels : word; { 1 = mono, 2 = stereo }
nSamplesPerSec : longint; { Sample frequency ie 44100}
nAvgBytesPerSec : longint; { = nChannels * nSamplesPerSec *
(nBitsPerSample/8) }
nBlockAlign : word; { = nChannels * (nBitsPerSAmple / 8 }
wBitsPerSample : word; { 8 or 16 }
{ DATA CHUNK }
dId : array [0..3] of char; { ‘data’ }
wSampleLength : longint;
end;[/code:389aoz2x]

then just write the NewBuffer from the DSP-Callback to the file like this:
[code:389aoz2x]
function WriteBuffer(OriginalBuffer: Pointer; NewBuffer: Pointer; Length, Param: Integer): Pointer; stdcall;
begin
outFile.Write(Newbuffer^, length * 4); //4 bytes a sample
end;
[/code:389aoz2x]

Note:
Don’t forget to stop with writing when the stream has finished. (use a endcallback or something)
To write samples to wave instead of streams use the FSOUND_SAMPLE_Lock an FSOUND_SAMPLE_UnLock

  • You must to post comments
Showing 1 result
Your Answer

Please first to submit.