Firstly, you should consider that Buffer is a pointer, so you should write the buffer in to the stream as follow:
- Code: Select all
Wave.Write(Buffer^, BufferSize);
Secondly, the RIFF format doesn't let you to create a wave file in this way.
Here is the procedure you should follow to create a wave file:
1. Include the required units to the uses clause of your unit.
- Code: Select all
uses
mmSystem, WaveUtils;
2. Declare the helper variables.
- Code: Select all
var
WaveFormatEx: TWaveFormatEx;
ckInfo, ckData: TMMCKInfo;
mmIO: HMMIO;
3. Initialize the wave content in OnActivate event of the LiveAudioRecorder.
- Code: Select all
SetPCMAudioFormatS(@WaveFormatEx, LiveAudioRecorder.PCMFormat);
mmIO := CreateStreamWaveAudio(Stream, @WaveFormatEx, ckInfo, ckData);
Stream: could be any writable stream. For your case, I suggest to use TFileStream.
4. Add wave data to the stream in OnData event of the LiveAudioRecorder.
- Code: Select all
mmioWrite(mmIO, Buffer, BufferSize);
5. Finalize the task in OnDeactivate event of the LiveAudioRecorder.
- Code: Select all
CloseWaveAudio(mmio, ckInfo, ckData);
Hope that it helps.
Kambiz