Click here to Skip to main content
11,721,671 members (79,976 online)
Click here to Skip to main content

Simple audio recording program

, 12 Jul 2007 254.1K 12.4K 76
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.

You may also be interested in...

Comments and Discussions

 
GeneralCan you help? Pin
Member 779661522-Apr-11 19:44
memberMember 779661522-Apr-11 19:44 
GeneralWon't compile using Visual Studio 2010 (SP1) Pin
Michael B Pliam13-Apr-11 9:58
memberMichael B Pliam13-Apr-11 9:58 
GeneralRe: Won't compile using Visual Studio 2010 (SP1) Pin
Saneesh23-Apr-11 4:12
memberSaneesh23-Apr-11 4:12 
AnswerRe: Won't compile using Visual Studio 2010 (SP1) Pin
tom tom tom tom tom5-Oct-11 0:37
membertom tom tom tom tom5-Oct-11 0:37 
GeneralRe: Won't compile using Visual Studio 2010 (SP1) Pin
Saneesh5-Oct-11 4:45
memberSaneesh5-Oct-11 4:45 
Generalsource code Pin
sunilpatilgs16-Mar-11 19:01
membersunilpatilgs16-Mar-11 19:01 
Generalgetting waveform n samples Pin
sunilpatilgs10-Mar-11 23:28
membersunilpatilgs10-Mar-11 23:28 
GeneralRe: getting waveform n samples Pin
Saneesh11-Mar-11 5:58
memberSaneesh11-Mar-11 5:58 
GeneralRe: getting waveform n samples Pin
peppelisme5-Jun-11 7:17
memberpeppelisme5-Jun-11 7:17 
Questionhow to display wave form Pin
sunilpatilgs8-Mar-11 18:00
membersunilpatilgs8-Mar-11 18:00 
AnswerSanesh can you contact me? Pin
Member 77377838-Mar-11 21:16
memberMember 77377838-Mar-11 21:16 
GeneralRe: Sanesh can you contact me? Pin
Saneesh9-Mar-11 4:15
memberSaneesh9-Mar-11 4:15 
AnswerRe: how to display wave form Pin
Saneesh9-Mar-11 4:15
memberSaneesh9-Mar-11 4:15 
GeneralMy vote of 5 Pin
boyewa13-Sep-10 7:30
memberboyewa13-Sep-10 7:30 
Generalwriting audio to serial port Pin
abhishek50500426-Mar-10 20:27
memberabhishek50500426-Mar-10 20:27 
GeneralRe: writing audio to serial port Pin
Saneesh21-Apr-10 5:22
memberSaneesh21-Apr-10 5:22 
GeneralTimer is not working when recording a sound Pin
NightBeforeChirstmas13-Jan-10 22:32
memberNightBeforeChirstmas13-Jan-10 22:32 
GeneralRe: Timer is not working when recording a sound Pin
Saneesh14-Jan-10 3:34
memberSaneesh14-Jan-10 3:34 
Questionsegmenting the output Pin
wui ngiap2-Oct-09 4:56
memberwui ngiap2-Oct-09 4:56 
GeneralWaveinaddBuffer returns 33! Pin
albertinho8624-Sep-09 3:48
memberalbertinho8624-Sep-09 3:48 
GeneralRe: WaveinaddBuffer returns 33! Pin
Saneesh30-Sep-09 5:45
memberSaneesh30-Sep-09 5:45 
GeneralRe: WaveinaddBuffer returns 33! Pin
albertinho8630-Sep-09 11:14
memberalbertinho8630-Sep-09 11:14 
GeneralRecording Audio Output [modified] Pin
sairamdp12-Jun-09 21:11
membersairamdp12-Jun-09 21:11 
GeneralRe: Recording Audio Output Pin
Saneesh14-Jun-09 3:11
memberSaneesh14-Jun-09 3:11 
GeneralCalling waveInAddBuffer from waveInProc Pin
GMV21-May-09 11:39
memberGMV21-May-09 11:39 
GeneralRe: Calling waveInAddBuffer from waveInProc Pin
Saneesh22-May-09 4:05
memberSaneesh22-May-09 4:05 
GeneralRe: Calling waveInAddBuffer from waveInProc Pin
GMV22-May-09 11:17
memberGMV22-May-09 11:17 
GeneralRe: Calling waveInAddBuffer from waveInProc Pin
Saneesh1-Jun-09 16:24
memberSaneesh1-Jun-09 16:24 
GeneralNEED VC6 Version Pin
wakaley16-Mar-09 23:36
memberwakaley16-Mar-09 23:36 
GeneralRe: NEED VC6 Version Pin
Saneesh17-Mar-09 4:19
memberSaneesh17-Mar-09 4:19 
GeneralUsing your program Pin
w1e2i312-Jan-09 19:03
memberw1e2i312-Jan-09 19:03 
GeneralRe: Using your program Pin
Saneesh13-Jan-09 4:21
memberSaneesh13-Jan-09 4:21 
GeneralMemory Leak Pin
yktan15-Dec-08 1:37
memberyktan15-Dec-08 1:37 
GeneralRe: Memory Leak Pin
Saneesh15-Dec-08 8:08
memberSaneesh15-Dec-08 8:08 
GeneralI need VC6 version pls... Pin
krishna Vuppala1-Nov-08 22:29
memberkrishna Vuppala1-Nov-08 22:29 
GeneralRe: I need VC6 version pls... Pin
Saneesh3-Nov-08 9:41
memberSaneesh3-Nov-08 9:41 
GeneralRe: I need VC6 version pls... Pin
Member 870123527-Apr-12 22:48
memberMember 870123527-Apr-12 22:48 
QuestionHow can i add my own format to the drop down Pin
Member 465536511-Jul-08 0:36
memberMember 465536511-Jul-08 0:36 
AnswerRe: How can i add my own format to the drop down Pin
Saneesh13-Jul-08 16:11
memberSaneesh13-Jul-08 16:11 
GeneralVC V6 Pin
dave7dave7-Oct-07 12:09
memberdave7dave7-Oct-07 12:09 
GeneralRe: VC V6 Pin
Saneesh4-Jan-08 6:08
memberSaneesh4-Jan-08 6:08 
GeneralVB.NET Pin
BIRDENT30-Jul-07 21:38
memberBIRDENT30-Jul-07 21:38 
GeneralRe: VB.NET Pin
Saneesh31-Jul-07 5:56
memberSaneesh31-Jul-07 5:56 
GeneralSaving sound (*wav) into access database Pin
indray2j16-Jul-07 22:31
memberindray2j16-Jul-07 22:31 
GeneralRe: Saving sound (*wav) into access database Pin
Saneesh17-Jul-07 4:07
memberSaneesh17-Jul-07 4:07 
GeneralRe: Saving sound (*wav) into access database Pin
indray2j17-Jul-07 20:14
memberindray2j17-Jul-07 20:14 
GeneralComplete Program.. Pin
indray2j8-Jul-07 22:05
memberindray2j8-Jul-07 22:05 
GeneralRe: Complete Program.. Pin
Saneesh9-Jul-07 4:18
memberSaneesh9-Jul-07 4:18 
GeneralRe: Complete Program.. Pin
indray2j10-Jul-07 21:47
memberindray2j10-Jul-07 21:47 
GeneralRe: Complete Program.. Pin
Saneesh11-Jul-07 4:04
memberSaneesh11-Jul-07 4:04 

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
Web04 | 2.8.150901.1 | Last Updated 12 Jul 2007
Article Copyright 2006 by Saneesh
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid