Click here to Skip to main content
11,412,833 members (78,503 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

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

Share

About the Author

Saneesh
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] Pin
Elmue at 13-Oct-14 16:30
memberElmue13-Oct-14 16:30 
GeneralRe: Works, but is beginner code and several issues to be fixed Pin
dalkeeper at 4-Mar-15 9:32
memberdalkeeper4-Mar-15 9:32 
GeneralMy vote of 3 Pin
glp3329 at 24-Nov-13 22:59
memberglp332924-Nov-13 22:59 
QuestionWhere/How does it write? Pin
Member 9230820 at 25-Jul-12 5:56
memberMember 923082025-Jul-12 5:56 
AnswerRe: Where/How does it write? Pin
Saneesh at 26-Jul-12 4:52
memberSaneesh26-Jul-12 4:52 
GeneralMy vote of 5 Pin
wserra at 6-Jul-12 22:06
memberwserra6-Jul-12 22:06 
GeneralMy vote of 2 Pin
arjo129 at 30-Jun-12 15:59
memberarjo12930-Jun-12 15:59 
GeneralRe: My vote of 2 Pin
wserra at 6-Jul-12 22:08
memberwserra6-Jul-12 22:08 
GeneralRe: My vote of 2 Pin
Saneesh at 8-Jul-12 13:40
memberSaneesh8-Jul-12 13:40 
GeneralRe: My vote of 2 Pin
wserra at 8-Jul-12 18:00
memberwserra8-Jul-12 18:00 
My pleasure and my gratitude for the education!
Beyond reading books, one becomes a really good deveoper by imitating those who write exciting applications. I plan to adapt your code and turn it as an intercom for Microsoft's Flight Simulator. For the receiver part I'll need to play a sound stored in a buffer instead of a file. The easy parts is finding the APIs. The difficult part is overcoming unforeseen obstacles, like excessive lag or playing simultaneous buffers when two people speak at the same time. Is there anything you would advice to be particularly careful about?
GeneralCan you help? Pin
Member 7796615 at 22-Apr-11 20:44
memberMember 779661522-Apr-11 20:44 
GeneralWon't compile using Visual Studio 2010 (SP1) Pin
Michael B Pliam at 13-Apr-11 10:58
memberMichael B Pliam13-Apr-11 10:58 
GeneralRe: Won't compile using Visual Studio 2010 (SP1) Pin
Saneesh at 23-Apr-11 5:12
memberSaneesh23-Apr-11 5:12 
AnswerRe: Won't compile using Visual Studio 2010 (SP1) Pin
tom tom tom tom tom at 5-Oct-11 1:37
membertom tom tom tom tom5-Oct-11 1:37 
GeneralRe: Won't compile using Visual Studio 2010 (SP1) Pin
Saneesh at 5-Oct-11 5:45
memberSaneesh5-Oct-11 5:45 
Generalsource code Pin
sunilpatilgs at 16-Mar-11 20:01
membersunilpatilgs16-Mar-11 20:01 
Generalgetting waveform n samples Pin
sunilpatilgs at 11-Mar-11 0:28
membersunilpatilgs11-Mar-11 0:28 
GeneralRe: getting waveform n samples Pin
Saneesh at 11-Mar-11 6:58
memberSaneesh11-Mar-11 6:58 
GeneralRe: getting waveform n samples Pin
peppelisme at 5-Jun-11 8:17
memberpeppelisme5-Jun-11 8:17 
Questionhow to display wave form Pin
sunilpatilgs at 8-Mar-11 19:00
membersunilpatilgs8-Mar-11 19:00 
AnswerSanesh can you contact me? Pin
Member 7737783 at 8-Mar-11 22:16
memberMember 77377838-Mar-11 22:16 
GeneralRe: Sanesh can you contact me? Pin
Saneesh at 9-Mar-11 5:15
memberSaneesh9-Mar-11 5:15 
AnswerRe: how to display wave form Pin
Saneesh at 9-Mar-11 5:15
memberSaneesh9-Mar-11 5:15 
GeneralMy vote of 5 Pin
boyewa at 13-Sep-10 8:30
memberboyewa13-Sep-10 8:30 
Generalwriting audio to serial port Pin
abhishek505004 at 26-Mar-10 21:27
memberabhishek50500426-Mar-10 21:27 
GeneralRe: writing audio to serial port Pin
Saneesh at 21-Apr-10 6:22
memberSaneesh21-Apr-10 6:22 
GeneralTimer is not working when recording a sound Pin
NightBeforeChirstmas at 13-Jan-10 23:32
memberNightBeforeChirstmas13-Jan-10 23:32 
GeneralRe: Timer is not working when recording a sound Pin
Saneesh at 14-Jan-10 4:34
memberSaneesh14-Jan-10 4:34 
Questionsegmenting the output Pin
wui ngiap at 2-Oct-09 5:56
memberwui ngiap2-Oct-09 5:56 
GeneralWaveinaddBuffer returns 33! Pin
albertinho86 at 24-Sep-09 4:48
memberalbertinho8624-Sep-09 4:48 
GeneralRe: WaveinaddBuffer returns 33! Pin
Saneesh at 30-Sep-09 6:45
memberSaneesh30-Sep-09 6:45 
GeneralRe: WaveinaddBuffer returns 33! Pin
albertinho86 at 30-Sep-09 12:14
memberalbertinho8630-Sep-09 12:14 
GeneralRecording Audio Output [modified] Pin
sairamdp at 12-Jun-09 22:11
membersairamdp12-Jun-09 22:11 
GeneralRe: Recording Audio Output Pin
Saneesh at 14-Jun-09 4:11
memberSaneesh14-Jun-09 4:11 
GeneralCalling waveInAddBuffer from waveInProc Pin
GMV at 21-May-09 12:39
memberGMV21-May-09 12:39 
GeneralRe: Calling waveInAddBuffer from waveInProc Pin
Saneesh at 22-May-09 5:05
memberSaneesh22-May-09 5:05 
GeneralRe: Calling waveInAddBuffer from waveInProc Pin
GMV at 22-May-09 12:17
memberGMV22-May-09 12:17 
GeneralRe: Calling waveInAddBuffer from waveInProc Pin
Saneesh at 1-Jun-09 17:24
memberSaneesh1-Jun-09 17:24 
GeneralNEED VC6 Version Pin
wakaley at 17-Mar-09 0:36
memberwakaley17-Mar-09 0:36 
GeneralRe: NEED VC6 Version Pin
Saneesh at 17-Mar-09 5:19
memberSaneesh17-Mar-09 5:19 
GeneralUsing your program Pin
w1e2i3 at 12-Jan-09 20:03
memberw1e2i312-Jan-09 20:03 
GeneralRe: Using your program Pin
Saneesh at 13-Jan-09 5:21
memberSaneesh13-Jan-09 5:21 
GeneralMemory Leak Pin
yktan at 15-Dec-08 2:37
memberyktan15-Dec-08 2:37 
GeneralRe: Memory Leak Pin
Saneesh at 15-Dec-08 9:08
memberSaneesh15-Dec-08 9:08 
GeneralI need VC6 version pls... Pin
krishna Vuppala at 1-Nov-08 23:29
memberkrishna Vuppala1-Nov-08 23:29 
GeneralRe: I need VC6 version pls... Pin
Saneesh at 3-Nov-08 10:41
memberSaneesh3-Nov-08 10:41 
GeneralRe: I need VC6 version pls... Pin
Member 8701235 at 27-Apr-12 23:48
memberMember 870123527-Apr-12 23:48 
QuestionHow can i add my own format to the drop down Pin
Member 4655365 at 11-Jul-08 1:36
memberMember 465536511-Jul-08 1:36 
AnswerRe: How can i add my own format to the drop down Pin
Saneesh at 13-Jul-08 17:11
memberSaneesh13-Jul-08 17:11 
GeneralVC V6 Pin
dave7dave at 7-Oct-07 13:09
memberdave7dave7-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.150427.1 | Last Updated 12 Jul 2007
Article Copyright 2006 by Saneesh
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid