DirectSound questions!

Started by
3 comments, last by PoLiSh_Peta 20 years, 2 months ago
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"

cSOUND::cSOUND( HWND hwnd )
{
	//We need to initialize COM first.

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

	CoCreateInstance( CLSID_IDirectMusicPerformance,
					  NULL,
					  CLSCTX_INPROC,
					  IID_IDirectMusicPerformance8,
					  ( 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

							DMUS_APATH_SHARED_STEREOPLUSREVERB,//audio path

							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,
					  NULL,
					  CLSCTX_INPROC,
					  IID_IDirectMusicLoader8,
					  ( void** ) &Loader );

	//We gotta create a music segment.

	CoCreateInstance( CLSID_IDirectMusicSegment,
					  NULL,
					  CLSCTX_INPROC,
					  IID_IDirectMusicSegment8,
					  ( void** ) &Segment);

	//Make a function call to load the segment.

	LoadSegment();
}

cSOUND::~cSOUND()
{
	Performance->CloseDown();
	Loader->Release();
	Performance->Release();
	Segment->Release();
	CoUninitialize();
}

cSOUND::LoadSegment()
{
	//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,
								IID_IDirectMusicSegment8,
								wFilename,
								( 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
{
public:

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

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

	cSOUND( HWND hwnd );
	~cSOUND();
	
	BOOL LoadSegment();

	BOOL PlaySounds();

private:

	//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;

};

#endif
There are two inevitabilities in life: death and failure.-PoLiSh
Advertisement
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.

-Peter
There are two inevitabilities in life: death and failure.-PoLiSh
Nobody knows anything about DirectSound/DirectMusic?

-Peter

[edited by - PoLiSh_Peta on February 8, 2004 10:22:48 AM]
There are two inevitabilities in life: death and failure.-PoLiSh
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.
---Will DDR for food.
Thanks Weston.

-Peter
There are two inevitabilities in life: death and failure.-PoLiSh

This topic is closed to new replies.

Advertisement