Click here to Skip to main content
13,147,956 members (94,735 online)
Click here to Skip to main content
Add your own
alternative version


140 bookmarked
Posted 2 Jan 2001

How to play and record sounds

, 12 Mar 2001
Rate this:
Please Sign up or sign in to vote.
A simple application that shows how to play and record sounds under Windows


This is a simple application that shows you how to play and record sound under windows.
It uses the old multimedia API. A better solution may be to use DirectSound.

Quick Guide to the Code

Start with the two functions in CFisterDlg called OnPlay and OnRecord. Follow them down to the depth you need to use the classes.

Short description

CSoundIn is a wrapper class that will let you retreive sound from the soundcard. The main functions are Start() and Stop()

CSoundOut is a wrapper class that will let you play sound on the soundcard. The main functions are Start() and Stop()

CSoundFile is a wrapper class of a single wave file, it can either be a file reader or a file writer object. See the constructor.

CSoundBase is a very small class that encapsulates the wave format.

CBuffer is a very small class that encapsulates a simple one dimentional buffer.

The project has a number of different callback functions:

  • One callback function makes the Play button change it's label to stop when it has finished playing the file. CDialogDlg enherits
    and overloads a function that CPipe can call when it has finished playing the wave file.
  • Another callback function make it possible for CSoundIn to callback to CPipe when it has filled the input buffer. Thus CPipe can give CSoundIn a new buffer to fill.
  • A clone of the above principle is also used in CSoundOut, which enables it to callback to the owner when it is finished playing the sound in a given buffer.

Problems that I encountered

I have spent almost 2 days debugging the following stupid problem. When CSoundIn and CSoundOut inherit from CSoundBase and CWinThread the order in which they are listed must be as shown below. If not, the callback functions, which are started by the WinThread message handler, will not be able to access the member variables of the CSoundIn object.

class CSoundIn : public CWinThread, public CSoundBase

During these two days of fustration I also tried to implement the callback as regular callback functions called by the device driver. This is possible using ::waveInOpen(...). But since this callback function is not allowed to call any of the ::waveInXXX(...) functions it is not of much use.


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

Thomas Holme
Web Developer
Denmark Denmark
No Biography provided

You may also be interested in...

Comments and Discussions

GeneralRe: unable to record the data from microphone Pin
Figu.Lin10-Feb-09 16:30
memberFigu.Lin10-Feb-09 16:30 
GeneralHelp me with default recording device!!! Pin
Hung In26-Jul-06 16:01
memberHung In26-Jul-06 16:01 
GeneralHi Pin
LuckyBoydtt13-Jul-06 8:05
memberLuckyBoydtt13-Jul-06 8:05 
GeneralRe: Hi Pin
Andy Byron22-Dec-06 3:47
memberAndy Byron22-Dec-06 3:47 
GeneralRe: Hi Pin
LuckyBoydtt22-Dec-06 4:05
memberLuckyBoydtt22-Dec-06 4:05 
Generalt Pin
angshu1201198415-Jun-06 23:54
memberangshu1201198415-Jun-06 23:54 
GeneralHelp me! Pin
trananh19-Jan-06 15:03
membertrananh19-Jan-06 15:03 
GeneralError Message: Still 3 buffers in waveIn queue Pin
srettig15-Nov-05 11:01
membersrettig15-Nov-05 11:01 
QuestionCan i do this in C# Pin
Kumar Muthu29-Oct-05 0:26
memberKumar Muthu29-Oct-05 0:26 
GeneralMore help in rectifying errors Pin
armimex200028-Oct-05 13:46
memberarmimex200028-Oct-05 13:46 
AnswerRe: More help in rectifying errors Pin
Gokcer Gokdal10-Nov-05 11:34
memberGokcer Gokdal10-Nov-05 11:34 
GeneralAudio and Video Pin
Kisi00719-Oct-05 7:33
memberKisi00719-Oct-05 7:33 
GeneralSave the Recorded Sound to a .Wav File, Pin
REU7-Oct-05 8:43
memberREU7-Oct-05 8:43 

Hello everybody I just started with this thing of programing, a few months ago,,

I want to know if its possible to save the recorded sound into a .Wav file,, also I I recorded many times can I save many .Wav

othe question that I have is ???

which Variable or where can I find the Final Final with the Sound data,
I mean if I need to send all the Audio data trough a socket
where can I find the block or the file that contains the Audio Data,, and where can I find the lenght in bytes of the captured file.

Can I use Windows sockets to control the Start capture and Stop capture functions, and then send the file through a socket,and when I receive the file in the other side,, how can I save the Audio Data to a .Wav file,,

or is it possible to save the Audio Data to .Wav file and then send it through the socket ???

its really urgent these questions, if somebody can help me,,

I write my email

Im trying to find solutions and this code is so amazing , simple and amazing to capture the sound that I need,
thanx everybody



GeneralRe: Save the Recorded Sound to a .Wav File, Pin
yasar7910-Jan-06 1:08
memberyasar7910-Jan-06 1:08 
Generalselecting two input sources Pin
rajeev_geom7-Oct-05 1:03
memberrajeev_geom7-Oct-05 1:03 
GeneralVery nice design Pin
Gokcer Gokdal24-Aug-05 13:13
memberGokcer Gokdal24-Aug-05 13:13 
QuestionHow can I record playback sound when Only Microphone is selected in Window Record Control Pin
jackshelingzhang6-Jun-05 2:31
memberjackshelingzhang6-Jun-05 2:31 
Generalhelp in rectifying the errors Pin
nagulmeera4-Dec-04 0:49
membernagulmeera4-Dec-04 0:49 
GeneralRe: help in rectifying the errors Pin
Jordan Walters29-Sep-05 2:10
memberJordan Walters29-Sep-05 2:10 
GeneralRecord and Play the Sound in two different machine. Pin
Josep Ignatius22-Nov-04 23:56
sussJosep Ignatius22-Nov-04 23:56 
Generalhelp me,plz Pin
chaitanya123215-Jul-04 22:14
susschaitanya123215-Jul-04 22:14 
GeneralA simple way to play sound... Pin
Mark Sparrow24-May-04 18:42
sussMark Sparrow24-May-04 18:42 
GeneralRe: A simple way to play sound... Pin
DavidCrow8-Jun-04 3:21
memberDavidCrow8-Jun-04 3:21 
GeneralRe: A simple way to play sound... ? Pin
mohsen nourian3-Jul-04 22:05
membermohsen nourian3-Jul-04 22:05 
GeneralRe: A simple way to play sound... ? Pin
wavefan3-Jul-04 23:33
susswavefan3-Jul-04 23:33 

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.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.170915.1 | Last Updated 13 Mar 2001
Article Copyright 2001 by Thomas Holme
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid