Link to home
Start Free TrialLog in
Avatar of saar2
saar2

asked on

Recording a wave file

Hi

How can I record a new WAV file from the mic and save it into a new file?

Saar
Avatar of msac_m
msac_m

There are a lot of sound components in the Delphi Super page
and they are capable of getting the sound from the Sound Card,
and capable of giving them in the buffers.

 When the buffer is filled, the component fires the onbufferarrive or something like that. In the event handler of this event simply write the arrived buffer to the HD.(I think that some of these components must have the ability of directly writing to a wav file.
)
If they lack this ability(recording to wav file), you must add a header to very first beginning of the file.

As you know WAV file has header, which holds the size of the file , the sampling frequency used and the things like that, So you must arrange the header.

To have the header done;
1- first write the header section to the HD. (Before writing anything to HD.)
2- Start recording, add the coming data to the end of the header that you wrote.
2- After completing the record , return the header section and write the correct values for the file size, frequecy ..


Regards,


Avatar of saar2

ASKER

Where is the Delphi Super page ?

Could you please give me the source code for the header writing?

Thank you,
Saar
saar2,

 this article is already a good start :

 http://www.undu.com/DN970901/00000022.htm

 It is for D1 so you'll need to change some code.

 DSP : http://sunsite.icm.edu.pl/delphi/

 and another good one :

 Torry : http://www.torry.ru/index.htm

Regards, Zif.
ASKER CERTIFIED SOLUTION
Avatar of trillo
trillo

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
As ZifNab stated
 the edlphi uper page URL is
 http://sunsite.icm.edu.pl/delphi/

Regards
Avatar of saar2

ASKER

msac_m, I looked at the Delphi Super Page and I didn't find any free component which let me create and save a file. I tried to download some files but the links were broken.

trillo, I don't know much about Delphi. Do I need to create Tmediaplayer object?
How do I use the Open/Close commands? What is the "i" variable?

Thank you all,
Saar
Ok.... let's see:
The code I posted here makes use of API functions, this means that you don't have to create a TMedaPlayer component, reducing the memory and executable space needed.

The open, close, save (and others) are called MCI commands ("multimedia command interface"), and the are used with the mciSendString APi function. This is a powerful function that allows you to manipulate almost any kind of multimedia type (audio, midi, avi video, CD, etc..)
What is the "i" variable.... It's optional but it's always useful. The mciSendString functions always return a value depending on the string used, but in all cases when the functions is succesfull it returns 0. This will allow you to trap errors, if "i" is different from 0 an error occurred.

There are a lot of these MCI command strings and the keywords and syntax depend on each command and device. You can find the documentation of MCI commands on help files, or if you don't have them you have two choices: Searching on the Web or just write "Trillo, tell e more about MCI", OK?
I hope this helped you a little bit.
Trillo