DELPHI AREA
MESSAGE BOARD
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   Favorites   Watched Topics     RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Using LiveAudioRecorder to record a Wav file

 
   Reply to topic       DELPHI AREA Forum Index -> DELPHI AREA's Products
View previous topic :: View next topic  
Author Message
Rron
Member


Joined: 10 Mar 2005
Posts: 3
Location: Quebec, Canada

PostPosted: 10/03/05 15:28    Post subject: Using LiveAudioRecorder to record a Wav file Reply with quote

I am trying to record using LiveAudioRecorder but can't seem to make it work to create a Wav file (they are always empty). I have read all messages on this board and looked at the source code and the Broadcaster example and passed hours trying averything and anything I can think of without success.

I am almost certain that its my OnData event that I am coding wrong. Does anyone have a sample code that could get me on the right track. I imagine its the way to use the Buffer value and/or the TWave that I am not getting.

Thank you
Back to top
View user's profile Visit poster's website
Kambiz
Administrator


Joined: 07 Mar 2003
Posts: 506
Location: Tehran, Iran

PostPosted: 10/03/05 18:09    Post subject: Reply with quote

It would be nice if you post your code here to figure out what's wrong.

By the way, why you don't use TStockAudioRecorder to simplify this task?

Kambiz
Back to top
View user's profile Send e-mail Visit poster's website
Rron
Member


Joined: 10 Mar 2005
Posts: 3
Location: Quebec, Canada

PostPosted: 10/03/05 20:03    Post subject: Reply with quote

I am using LiveAudioRecorder because I want the recording to stop if the noise level is below a certain level as in the Broadcaster example. I had no problem using the TStockAudioRecorder but cannot find a way to prevent the recording of low sound level portions.

I have tried so many things that I am posting the simplest code I have tried (and I am not good with pointers and maybe why I cannot get this to work)

Code:
procedure TMainForm.LiveAudioRecorder1Data(Sender: TObject;
  const Buffer: Pointer; BufferSize: Cardinal; var FreeIt: Boolean);
begin
  if TheAudioLevel > MaxSilenceLevel then
  Begin
    AudioRecorder1.Wave.Write(Buffer, BufferSize);
  end;
end;


I have also tried using the Audiobuffer as in the Receiver example with no success, and a lot of other things. So I think that what is comes down to is how to use the buffer information to create a Wave file of the live recording.

Thank you for your help, your time and the Components you have created and put out as Freeware.
Back to top
View user's profile Visit poster's website
Kambiz
Administrator


Joined: 07 Mar 2003
Posts: 506
Location: Tehran, Iran

PostPosted: 11/03/05 08:30    Post subject: Reply with quote

Firstly, you should consider that Buffer is a pointer, so you should write the buffer in to the stream as follow:

Code:
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:
uses
  mmSystem, WaveUtils;

2. Declare the helper variables.

Code:
var
  WaveFormatEx: TWaveFormatEx;
  ckInfo, ckData: TMMCKInfo;
  mmIO: HMMIO;

3. Initialize the wave content in OnActivate event of the LiveAudioRecorder.

Code:

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:
mmioWrite(mmIO, Buffer, BufferSize);

5. Finalize the task in OnDeactivate event of the LiveAudioRecorder.

Code:
CloseWaveAudio(mmio, ckInfo, ckData);


Hope that it helps.
Kambiz
Back to top
View user's profile Send e-mail Visit poster's website
Rron
Member


Joined: 10 Mar 2005
Posts: 3
Location: Quebec, Canada

PostPosted: 11/03/05 13:33    Post subject: Reply with quote

WOW, it works. A BIG thank you for your time.
I Created Stream as a TWave and just added : Stream.SaveToFile('MyPath\Name.WAV'); after the CloseWaveAudio.

With this code I also understood a couple of your other routines and some TWave manipulation.

Once again thank you
Back to top
View user's profile Visit poster's website
Display posts from previous:   
   Reply to topic       DELPHI AREA Forum Index -> DELPHI AREA's Products All times are GMT
Page 1 of 1

Add to favorites

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group