Click here to Skip to main content
12,818,508 members (32,614 online)
Click here to Skip to main content
Add your own
alternative version


15 bookmarked
Posted 22 Jun 2008

Playing Wave Resources

, 22 Jun 2008 CPOL
Rate this:
Please Sign up or sign in to vote.
Playing Wave Resources using a low level audio API.


If your application needs to play a Wave resource using a low level audio API, just follow the "Using the code" section below.

Using the code

It's simple: just include, instantiate, load, and play.

Add "RscWaveOut.h" and "RscWaveOut.cpp" to your project (for formats other than 22050Hz, 8bps, Mono, tweak some values in the CRscWaveOut class; that can be easily done). Go to Project settings > link > add "winmm.lib".

  1. Add a member
  2. CRscWaveOut m_RscWaveOut;
  3. Load a wave resource (in the OnInitDialog() or the constructor of the main class, for example)
  4. m_RscWaveOut.LoadWaveResource(IDR_WAVE_TICK_HIGH, AfxGetApp()->m_hInstance);
  5. Play the wave (under a button maybe)
  6. m_RscWaveOut.PlayWave();


The situation was that my application had to include Wave files as a resource and play them quickly and frequently. There are other high-middle level audio APIs like the sndPlaySound function but I noticed that sndPlaySound internally creates and destroys a thread every time it plays a Wave. I guessed that was one reason for the noticeable sound latency in my application. I tried to use the low level audio API - waveOut~ and mmio~ functions. Fortunately I could encapsulate all the necessary functions in a class CRscWaveOut that you can apply to your project very quickly.

The CRscWaveOut class might be useful:

  • If a Wave file must be located in the resources of your project.
  • If the play must be quick and precise on time using a low level audio API.

Though I haven't tested this on Wave samples longer than 100ms, I guess the class will work successfully. If there is trouble, look close into the CallBack function of CRscWaveOut. By handling other messages than just the ones provided (e.g., MM_WOM_DONE), you can easily take care of buffering long Wave resources.

The sample is an MFC project but the core CRscWaveOut class is built on Win32 APIs so you can use that class in ATL, WTL, and Win32 projects. For example, I used some of the code for quick sound generation in my metronome ActiveX of


  • 2008.06.23: Created.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Team Leader An Online Market
Korea (Republic of) Korea (Republic of)
Software engineer having worked 8 years.
The main skill would be C++, ATL, COM
But for the past three years I have been digging on Web service related skill - .Net MS-SQL etc in current company.
My other interest is business, playing traditional music, dealing with people and evolutionary biology.

You may also be interested in...


Comments and Discussions

GeneralMy vote of 2 Pin
wang_aniu14-Sep-11 6:01
memberwang_aniu14-Sep-11 6:01 
GeneralSmall note Pin
symreds26-Dec-10 8:31
membersymreds26-Dec-10 8:31 
QuestionProblem Pin
cch6710-Dec-08 11:50
membercch6710-Dec-08 11:50 

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.170308.1 | Last Updated 22 Jun 2008
Article Copyright 2008 by jangtimjang
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid