Advertisement Jump to content


This topic is now archived and is closed to further replies.


DirectSound questions!

This topic is 5459 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

C:\Documents and Settings\Owner\Desktop\AnoMaLY Engine\Sound.cpp(9) : error C2065: ''CLSID_IDirectMusicPerformance'' : undeclared identifier C:\Documents and Settings\Owner\Desktop\AnoMaLY Engine\Sound.cpp(25) : error C2065: ''CLSID_IDirectMusicLoader'' : undeclared identifier C:\Documents and Settings\Owner\Desktop\AnoMaLY Engine\Sound.cpp(32) : error C2065: ''CLSID_IDirectMusicSegment'' : undeclared identifier I''m getting these errors when I compile this ( did I forget to include something? ): Also, is this a good way to work with sound or not? I''m working on an engine, and I''m not sure how to go about doing the sound. Any help would be appreciated!
#include "GlobalClass.h"

	//We need to initialize COM first.

	CoInitialize( NULL );
	//We gotta create the performance object.

	CoCreateInstance( CLSID_IDirectMusicPerformance,
					  ( void** ) &Performance );

	//Time to initialize the performance object.

	Performance->InitAudio( NULL,//no need for this

							NULL,//no need for this

							hwnd,//our main window handle that was passed in


							64,//64 channels

							DMUS_AUDIOF_ALL,//all synthesizer features

							NULL );//default audio path

	//Time to create the loader object that will load all the sound files

	CoCreateInstance( CLSID_IDirectMusicLoader,
					  ( void** ) &Loader );

	//We gotta create a music segment.

	CoCreateInstance( CLSID_IDirectMusicSegment,
					  ( void** ) &Segment);

	//Make a function call to load the segment.



	//Set the search directory to the directory the program is in.

	char searchPath[ MAX_PATH ];
	WCHAR wSearchPath[ MAX_PATH ];

	GetCurrentDirectory(MAX_PATH, searchPath);

	MultiByteToWideChar(CP_ACP, 0, searchPath, -1, wSearchPath, MAX_PATH);

	Loader->SetSearchDirectory( GUID_DirectMusicAllTypes, wSearchPath, FALSE );

	//Here''s where we would load a sound segment.

	//Here''s an example.

	char filename[ MAX_PATH ] = "test.wav";
	WCHAR wFilename[MAX_PATH];

	MultiByteToWideChar(CP_ACP, 0, filename, -1, wFilename, MAX_PATH);

	Loader->LoadObjectFromFile( CLSID_DirectMusicSegment,
								( void** ) &Segment);

	//We''ll need the sound''s band to play the sound.

	Segment->Download( Performance );

BOOL cSOUND::PlaySounds()
	Performance->PlaySegmentEx( Segment, NULL, NULL, 0, 0, NULL, NULL, NULL );

	return TRUE;

Here''s the header file just in case:
#ifndef Sound_H_
#define Sound_H_

class cSOUND

	//The constructor will initialize all the stuff. It will take a 

	//window handle parameter because we''ll need it.

	cSOUND( HWND hwnd );
	BOOL LoadSegment();

	BOOL PlaySounds();


	//We need a localized window handle so we can initialize

	//the performance object.

	HWND hWnd; 
	//These are the objects we need to use DirectXAudio

	//This is basically the main interface for the sound.

	IDirectMusicPerformance8*	Performance;
	//This loads the music.

	IDirectMusicLoader8*		Loader;

	//This is the music segment which will encapsulate all our sounds.

	IDirectMusicSegment8*		Segment;



Share this post

Link to post
Share on other sites
Also, I''m not too clear on what''s going on with DirectSound and DirectMusic. Is DirectSound obsolete? Some of the articles use DirectMusic for simple sounds, but I thought it was for music? I just need some clearing up.


Share this post

Link to post
Share on other sites
Maybe you''re missing a header file or something. Do you have "objbase.h" "dmusici.h" and "dsound.h" included? Are you linking to "dsound.lib"? I dunno if you need dsound.h, but if you don''t, try including it.

DirectSound isn''t obsolete, but Microsoft suggests that you use the components of DirectX Audio to work with sounds now. In DirectSound, you need to parse the wave header, create buffers, and do even more work if you want to stream sounds. DirectX Audio handles most of everything, so you don''t have to do any of this.
DirectX Audio has a performance object and a loader object, all you have to do is create segments and use these components to play sounds. It''s a lot easier this way. This is how DirectMusic is designed to work, but now it encompases WAV files so you can basically play WAV sounds with DirectMusic / DirectX Audio interfaces. What you''re doing now is using DirectMusic interfaces to play WAV sounds, which is what Microsoft recommends.

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!