Click here to Skip to main content
11,410,550 members (56,665 online)
Click here to Skip to main content

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.

Comments and Discussions

BugWorks, but is beginner code and several issues to be fixed [modified] PinmemberElmue13-Oct-14 16:30 
GeneralRe: Works, but is beginner code and several issues to be fixed Pinmemberdalkeeper4-Mar-15 9:32 
GeneralMy vote of 3 Pinmemberglp332924-Nov-13 22:59 
QuestionWhere/How does it write? PinmemberMember 923082025-Jul-12 5:56 
AnswerRe: Where/How does it write? PinmemberSaneesh26-Jul-12 4:52 
GeneralMy vote of 5 Pinmemberwserra6-Jul-12 22:06 
GeneralMy vote of 2 Pinmemberarjo12930-Jun-12 15:59 
GeneralRe: My vote of 2 Pinmemberwserra6-Jul-12 22:08 
GeneralRe: My vote of 2 PinmemberSaneesh8-Jul-12 13:40 
GeneralRe: My vote of 2 Pinmemberwserra8-Jul-12 18:00 
GeneralCan you help? PinmemberMember 779661522-Apr-11 20:44 
GeneralWon't compile using Visual Studio 2010 (SP1) PinmemberMichael B Pliam13-Apr-11 10:58 
GeneralRe: Won't compile using Visual Studio 2010 (SP1) PinmemberSaneesh23-Apr-11 5:12 
AnswerRe: Won't compile using Visual Studio 2010 (SP1) Pinmembertom tom tom tom tom5-Oct-11 1:37 
GeneralRe: Won't compile using Visual Studio 2010 (SP1) PinmemberSaneesh5-Oct-11 5:45 
Generalsource code Pinmembersunilpatilgs16-Mar-11 20:01 
Generalgetting waveform n samples Pinmembersunilpatilgs11-Mar-11 0:28 
GeneralRe: getting waveform n samples PinmemberSaneesh11-Mar-11 6:58 
GeneralRe: getting waveform n samples Pinmemberpeppelisme5-Jun-11 8:17 
Questionhow to display wave form Pinmembersunilpatilgs8-Mar-11 19:00 
AnswerSanesh can you contact me? PinmemberMember 77377838-Mar-11 22:16 
GeneralRe: Sanesh can you contact me? PinmemberSaneesh9-Mar-11 5:15 
AnswerRe: how to display wave form PinmemberSaneesh9-Mar-11 5:15 
There are several articles available on how to do it. Which way you want? If you want it by frequency, you have to convert it into frequency domain using FFT and then display it. Simple way would be to just the amplitude of the signal.

GeneralMy vote of 5 Pinmemberboyewa13-Sep-10 8:30 
Generalwriting audio to serial port Pinmemberabhishek50500426-Mar-10 21:27 
GeneralRe: writing audio to serial port PinmemberSaneesh21-Apr-10 6:22 
GeneralTimer is not working when recording a sound PinmemberNightBeforeChirstmas13-Jan-10 23:32 
GeneralRe: Timer is not working when recording a sound PinmemberSaneesh14-Jan-10 4:34 
Questionsegmenting the output Pinmemberwui ngiap2-Oct-09 5:56 
GeneralWaveinaddBuffer returns 33! Pinmemberalbertinho8624-Sep-09 4:48 
GeneralRe: WaveinaddBuffer returns 33! PinmemberSaneesh30-Sep-09 6:45 
GeneralRe: WaveinaddBuffer returns 33! Pinmemberalbertinho8630-Sep-09 12:14 
GeneralRecording Audio Output [modified] Pinmembersairamdp12-Jun-09 22:11 
GeneralRe: Recording Audio Output PinmemberSaneesh14-Jun-09 4:11 
GeneralCalling waveInAddBuffer from waveInProc PinmemberGMV21-May-09 12:39 
GeneralRe: Calling waveInAddBuffer from waveInProc PinmemberSaneesh22-May-09 5:05 
GeneralRe: Calling waveInAddBuffer from waveInProc PinmemberGMV22-May-09 12:17 
GeneralRe: Calling waveInAddBuffer from waveInProc PinmemberSaneesh1-Jun-09 17:24 
GeneralNEED VC6 Version Pinmemberwakaley17-Mar-09 0:36 
GeneralRe: NEED VC6 Version PinmemberSaneesh17-Mar-09 5:19 
GeneralUsing your program Pinmemberw1e2i312-Jan-09 20:03 
GeneralRe: Using your program PinmemberSaneesh13-Jan-09 5:21 
GeneralMemory Leak Pinmemberyktan15-Dec-08 2:37 
GeneralRe: Memory Leak PinmemberSaneesh15-Dec-08 9:08 
GeneralI need VC6 version pls... Pinmemberkrishna Vuppala1-Nov-08 23:29 
GeneralRe: I need VC6 version pls... PinmemberSaneesh3-Nov-08 10:41 
GeneralRe: I need VC6 version pls... PinmemberMember 870123527-Apr-12 23:48 
QuestionHow can i add my own format to the drop down PinmemberMember 465536511-Jul-08 1:36 
AnswerRe: How can i add my own format to the drop down PinmemberSaneesh13-Jul-08 17:11 
GeneralVC V6 Pinmemberdave7dave7-Oct-07 13:09 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    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.150414.5 | Last Updated 12 Jul 2007
Article Copyright 2006 by Saneesh
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid