SHARE
Facebook X Pinterest WhatsApp

Playing Wave Files Directly From The Resource via DirectSound

Introduction Public Interface Usage Download Comments   Introduction (back to top) This class is a “spin off” of the CGTetris application. The CDirectSound class makes it easy to play a WAVE file directly from the resource (without copying it into a temporary file) via Microsoft’s DirectX component DirectSound. The class is designed to play small […]

Written By
thumbnail
CodeGuru Staff
CodeGuru Staff
Nov 14, 1998
CodeGuru content and product recommendations are editorially independent. We may make money when you click on links to our partners. Learn More

Introduction

Public Interface

Usage

Download

Comments

 

Introduction (back to top)

This class is a “spin off” of the CGTetris
application. The CDirectSound class makes it easy to play a WAVE file directly
from the resource (without copying it into a temporary file) via Microsoft’s
DirectX component DirectSound. The class is designed to play small sounds,
that can be placed completely into memory. No streaming is realized in
this implementation. One can use the class to play WAVE files, too.
In this case you have to load the entire file into memory and to pass the
pointer to the beginning of the buffer to the Create() method. To use this
class you need at least DirectX version 3.

Public Interface (back to top)

// create the sound object. You cannot use a
MIDI object until


// you “Create()” one!

BOOL Create(LPVOID pSoundData, DWORD dwSize,
CWnd * pParent = 0);


BOOL Create(LPCTSTR pszResID, CWnd * pParent
= 0);


BOOL Create(UINT uResID, CWnd * pParent =
0);

// Play the sound file. Normally the playback
will stop after


// the sound played off.

BOOL Play(DWORD dwStartPosition = 0, BOOL
bInfinite = FALSE);

BOOL Stop();

BOOL Pause();

BOOL Continue();

// Enable/disable the sound object. If you
call Play() on a


// disabled sound object, nothing will happen.
This makes


// it somewhat easier to globally switch
off sounds in an


// application.

BOOL EnableSound(BOOL bEnable = TRUE);

BOOL IsEnabled() const;

Usage (back to top)

The source consists of 2 files:

DirectSound.[h|cpp]

Add a WAVE resource into your application (from the Menu Insert->Resource->import->*.wav).

“Create()” your CDirectSound (derived) object giving it the resource-id
of your WAVE resource. Now you can call Play(), Pause(), Stop() etc.

Download(back to top)

Download demo project – 5 KB

Download source – 71 KB

Recommended for you...

Drawing 3D OpenGL Graphics on Google Maps
Mandelbrot Using C++ AMP
CodeGuru Staff
Jan 27, 2012
Simple C++ MP3 Player Class
CodeGuru Staff
Aug 22, 2011
Library for Raw Video Processing
CodeGuru Staff
Jun 14, 2011
CodeGuru Logo

CodeGuru covers topics related to Microsoft-related software development, mobile development, database management, and web application programming. In addition to tutorials and how-tos that teach programmers how to code in Microsoft-related languages and frameworks like C# and .Net, we also publish articles on software development tools, the latest in developer news, and advice for project managers. Cloud services such as Microsoft Azure and database options including SQL Server and MSSQL are also frequently covered.

Property of TechnologyAdvice. © 2025 TechnologyAdvice. All Rights Reserved

Advertiser Disclosure: Some of the products that appear on this site are from companies from which TechnologyAdvice receives compensation. This compensation may impact how and where products appear on this site including, for example, the order in which they appear. TechnologyAdvice does not include all companies or all types of products available in the marketplace.