Click here to Skip to main content
11,925,292 members (64,162 online)
Click here to Skip to main content
Add your own
alternative version


76 bookmarked

Simple audio recording program

, 12 Jul 2007
Rate this:
Please Sign up or sign in to vote.
Simplest way to record sound...

Sample Image - SoundRecord.jpg


This sample program make use of waveInxxxx functions to read from an audio input device like a sound card and write it to a .wav file using mmioxxx functions. It is one of the simplest way to record sound with all the format capabilities supported by the hardware device

Initially, by using waveInGetNumDevs, we can find all the devices and then by using waveInGetDevCaps, we can find the formats it is supported.

To start recording, first select a device and then open the device with waveInOpen API call with the specified format (i.e. 16 bit etc). The output file is also prepared with all the headers filled in properly. Here i am using only PCM format which is easy. If you have more codecs installed on your PC, you can change that one also. But be sure that you supplied the proper values in the WAVEFORMATEX structure.

waveIn needs buffers to start recording. It is better to give more buffers for buffering to avoid any delays. I have used 3 here, but you can add more if your PC needs more time in writing to the HDD and thus causing the delay. Once the buffers are added in the queue, waveInStart will start recording. For each data chunk, the callback function specified in the waveinOpen will get the buffers. Just write it to the file and mark the buffer again for recording by calling the same addbuffer fn.

Once done with recording, adjust the chunk headers using the mmioascend APIs. Thats it.


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Software Developer (Senior)
United States United States
I am from the beautiful sea side town called Kochi ( cochin), Kerala, South India.

You may also be interested in...

Comments and Discussions

GeneralRe: Sanesh can you contact me? Pin
Saneesh9-Mar-11 5:15
memberSaneesh9-Mar-11 5:15 
AnswerRe: how to display wave form Pin
Saneesh9-Mar-11 5:15
memberSaneesh9-Mar-11 5:15 
GeneralMy vote of 5 Pin
boyewa13-Sep-10 8:30
memberboyewa13-Sep-10 8:30 
Generalwriting audio to serial port Pin
abhishek50500426-Mar-10 21:27
memberabhishek50500426-Mar-10 21:27 
i am working on serial port communication and i have c code for file transfer from one pc to another pc. Now i want to record the audio file on another pc. But my problem is MMIOxxx functions use HMMIO handle while serial port uses different HANDLE type. so how can i solve this problem?
GeneralRe: writing audio to serial port Pin
Saneesh21-Apr-10 6:22
memberSaneesh21-Apr-10 6:22 
GeneralTimer is not working when recording a sound Pin
NightBeforeChirstmas13-Jan-10 23:32
memberNightBeforeChirstmas13-Jan-10 23:32 
GeneralRe: Timer is not working when recording a sound Pin
Saneesh14-Jan-10 4:34
memberSaneesh14-Jan-10 4:34 
Questionsegmenting the output Pin
wui ngiap2-Oct-09 5:56
memberwui ngiap2-Oct-09 5:56 
GeneralWaveinaddBuffer returns 33! Pin
albertinho8624-Sep-09 4:48
memberalbertinho8624-Sep-09 4:48 
GeneralRe: WaveinaddBuffer returns 33! Pin
Saneesh30-Sep-09 6:45
memberSaneesh30-Sep-09 6:45 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.151126.1 | Last Updated 12 Jul 2007
Article Copyright 2006 by Saneesh
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid