Click here to Skip to main content
15,867,568 members
Articles / Programming Languages / C++
Article

Simple audio recording program

Rate me:
Please Sign up or sign in to vote.
4.18/5 (31 votes)
12 Jul 20071 min read 399.3K   18.5K   83   109
Simplest way to record sound...

Sample Image - SoundRecord.jpg

Introduction

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.

License

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


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

Comments and Discussions

 
QuestionExecution in Unicode environment .. Pin
Member 1410982613-Jan-19 20:35
Member 1410982613-Jan-19 20:35 
BugWorks, but is beginner code and several issues to be fixed Pin
Elmue13-Oct-14 15:30
Elmue13-Oct-14 15:30 
GeneralRe: Works, but is beginner code and several issues to be fixed Pin
dalkeeper4-Mar-15 8:32
dalkeeper4-Mar-15 8:32 
GeneralMy vote of 3 Pin
glp332924-Nov-13 21:59
glp332924-Nov-13 21:59 
QuestionWhere/How does it write? Pin
Member 923082025-Jul-12 4:56
Member 923082025-Jul-12 4:56 
AnswerRe: Where/How does it write? Pin
Saneesh26-Jul-12 3:52
Saneesh26-Jul-12 3:52 
GeneralMy vote of 5 Pin
simviews6-Jul-12 21:06
simviews6-Jul-12 21:06 
GeneralMy vote of 2 Pin
arjo12930-Jun-12 14:59
arjo12930-Jun-12 14:59 
GeneralRe: My vote of 2 Pin
simviews6-Jul-12 21:08
simviews6-Jul-12 21:08 
GeneralRe: My vote of 2 Pin
Saneesh8-Jul-12 12:40
Saneesh8-Jul-12 12:40 
GeneralRe: My vote of 2 Pin
simviews8-Jul-12 17:00
simviews8-Jul-12 17:00 
GeneralCan you help? Pin
Member 779661522-Apr-11 19:44
Member 779661522-Apr-11 19:44 
GeneralWon't compile using Visual Studio 2010 (SP1) Pin
Michael B Pliam13-Apr-11 9:58
Michael B Pliam13-Apr-11 9:58 
GeneralRe: Won't compile using Visual Studio 2010 (SP1) Pin
Saneesh23-Apr-11 4:12
Saneesh23-Apr-11 4:12 
AnswerRe: Won't compile using Visual Studio 2010 (SP1) Pin
tom tom tom tom tom5-Oct-11 0:37
tom tom tom tom tom5-Oct-11 0:37 
GeneralRe: Won't compile using Visual Studio 2010 (SP1) Pin
Saneesh5-Oct-11 4:45
Saneesh5-Oct-11 4:45 
Generalsource code Pin
Sunil Patil G S16-Mar-11 19:01
Sunil Patil G S16-Mar-11 19:01 
Generalgetting waveform n samples Pin
Sunil Patil G S10-Mar-11 23:28
Sunil Patil G S10-Mar-11 23:28 
GeneralRe: getting waveform n samples Pin
Saneesh11-Mar-11 5:58
Saneesh11-Mar-11 5:58 
GeneralRe: getting waveform n samples Pin
peppelisme5-Jun-11 7:17
peppelisme5-Jun-11 7:17 
Questionhow to display wave form Pin
Sunil Patil G S8-Mar-11 18:00
Sunil Patil G S8-Mar-11 18:00 
AnswerSanesh can you contact me? Pin
Member 77377838-Mar-11 21:16
Member 77377838-Mar-11 21:16 
GeneralRe: Sanesh can you contact me? Pin
Saneesh9-Mar-11 4:15
Saneesh9-Mar-11 4:15 
AnswerRe: how to display wave form Pin
Saneesh9-Mar-11 4:15
Saneesh9-Mar-11 4:15 
GeneralMy vote of 5 Pin
boyewa13-Sep-10 7:30
boyewa13-Sep-10 7:30 
it has really helped me

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.