Click here to Skip to main content
11,580,580 members (67,545 online)
Click here to Skip to main content

How to play and record sounds

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

Introduction

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 CPipe 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.

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

Thomas Holme
Web Developer
Denmark Denmark
No Biography provided

You may also be interested in...

Comments and Discussions

 
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::PostQuitMessage(0)!!! Pin
Andrew Altham31-Jan-04 2:58
memberAndrew Altham31-Jan-04 2:58 
Generalplay more than one file at a moment Pin
Anonymous19-Jan-04 22:54
sussAnonymous19-Jan-04 22:54 
GeneralCSoundIn::Stop() change to avoid "still %d buffers in waveIn queue" Pin
filipverschueren@hotmail.com1-Jan-04 1:55
memberfilipverschueren@hotmail.com1-Jan-04 1:55 
GeneralRe: CSoundIn::Stop() change to avoid "still %d buffers in waveIn queue" Pin
ze_seb25-Mar-05 6:39
sussze_seb25-Mar-05 6:39 
Generalplease help me to solve the link errors in the program of how to play and record Pin
elaine tan2-Dec-03 5:17
memberelaine tan2-Dec-03 5:17 
hi,I have saved the files (how to play and record sound) in a folder and try to build it but occur some errors like :

Buffer.obj : error LNK2001: unresolved external symbol "void __cdecl ErrorMsg(char const *,...)" (?ErrorMsg@@YAXPBDZZ)
nafxcwd.lib(thrdcore.obj) : error LNK2001: unresolved external symbol __endthreadex
nafxcwd.lib(thrdcore.obj) : error LNK2001: unresolved external symbol __beginthreadex
libcd.lib(crt0.obj) : error LNK2001: unresolved external symbol _main
Debug/Buffer.exe : fatal error LNK1120: 4 unresolved externals
Error executing link.exe.

Buffer.exe - 5 error(s), 0 warning(s)

this is only one of the file errors. thus may i ask how to settle it? or any objects have been lost?
anyone who know the solution ,pls help me.thanks..

elaine tan
QuestionHow to support a sound input device in C# Pin
CNWORM22-Aug-03 20:39
memberCNWORM22-Aug-03 20:39 
AnswerRe: How to support a sound input device in C# Pin
Anonymous29-Oct-03 17:13
sussAnonymous29-Oct-03 17:13 
QuestionHow to record sound played by other program Pin
pnnam30-Jul-03 23:19
susspnnam30-Jul-03 23:19 
AnswerRe: How to record sound played by other program Pin
Anonymous29-Oct-03 17:15
sussAnonymous29-Oct-03 17:15 
GeneralRe: How to record sound played by other program Pin
sanpee9-Dec-03 3:26
membersanpee9-Dec-03 3:26 
QuestionHow to avoid popuping error dialog instantly? Pin
_sailinsky28-May-03 16:48
member_sailinsky28-May-03 16:48 
AnswerRe: How to avoid popuping error dialog instantly? Pin
Anonymous29-Oct-03 17:16
sussAnonymous29-Oct-03 17:16 
Questionhow can I download it? Pin
lidoo18-May-03 18:22
memberlidoo18-May-03 18:22 
GeneralWinCE Pin
henrytaihk22-Mar-03 0:52
memberhenrytaihk22-Mar-03 0:52 
GeneralMemory leak! Pin
WaHaha20-Mar-03 3:29
memberWaHaha20-Mar-03 3:29 
GeneralRe: Memory leak! Pin
burchtimp10-Jun-04 11:31
memberburchtimp10-Jun-04 11:31 
QuestionHow can I record from line-in not from microphone? Pin
soichi27-Feb-03 13:38
membersoichi27-Feb-03 13:38 
AnswerRe: How can I record from line-in not from microphone? Pin
edlogic@edlogic.com14-Mar-03 11:14
memberedlogic@edlogic.com14-Mar-03 11:14 
GeneralRe: How can I record from line-in not from microphone? Pin
mircokramer10-Apr-03 21:46
membermircokramer10-Apr-03 21:46 
GeneralRe: How can I record from line-in not from microphone? Pin
edlogic3-Feb-07 19:54
memberedlogic3-Feb-07 19:54 
Generalexcuse me Pin
NeverGrief21-Nov-02 6:15
memberNeverGrief21-Nov-02 6:15 
GeneralSound retrival Pin
Anonymous17-Sep-02 11:51
sussAnonymous17-Sep-02 11:51 

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.150603.1 | Last Updated 13 Mar 2001
Article Copyright 2001 by Thomas Holme
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid