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


DirectMusic and Listeners

Recommended Posts

I am settings a up a 3D sound engine. Right now, I am I am creating a Segment, 3DSoundBuffer, AudioPath, and Listener for every sound. My sounds are playing and positioning fine, but changing the position of the listener require I change it for each sound object. It seems to me that I should be able to have a single listener. I have looked at a couple tutorials on using DirectMusic for 3D Sound, but they all are creating a listener for each sound.
HRESULT                  hr;
WCHAR wstrFileName[MAX_PATH];
MultiByteToWideChar(CP_ACP, 0, filename, -1,  wstrFileName, 150);

// Create a new WavFile,  this will be added to the link list.

WavFile * tempWav;			
tempWav = new WavFile;
    if(tempWav == NULL)
        return false;            

	if (SUCCEEDED(hr = CSound::m_Performance->CreateStandardAudioPath
		(DMUS_APATH_DYNAMIC_3D, 64, TRUE, &tempWav->m_AudioPath)))
				hr = tempWav->m_AudioPath->GetObjectInPath( 
					GUID_NULL, 0, IID_IDirectSound3DBuffer8, 
					(LPVOID*) &tempWav->m_SoundBuffer);
			if (FAILED(hr))

	// Don't clear object data.

	// Get the buffer params

	tempWav->m_dsBufferParams.dwSize = sizeof(DS3DBUFFER);
	tempWav->m_SoundBuffer->GetAllParameters( &tempWav->m_dsBufferParams );

	// Set new 3D buffer parameters

	tempWav->m_dsBufferParams.dwMode = DS3DMODE_HEADRELATIVE;
	tempWav->m_SoundBuffer->SetAllParameters( &tempWav->m_dsBufferParams, DS3D_IMMEDIATE );
	//Listener for 3D Sound

	tempWav->m_AudioPath->GetObjectInPath( 0, DMUS_PATH_PRIMARY_BUFFER, 0, GUID_NULL, 
										0, IID_IDirectSound3DListener,(LPVOID*) &tempWav->m_Listener );		
	// Get listener parameters

	tempWav->m_dsListenerParams.dwSize = sizeof(DS3DLISTENER);
	tempWav->m_Listener->GetAllParameters( &tempWav->m_dsListenerParams );	

    ZeroMemory(tempWav->filename, 128);
    strncpy(tempWav->filename, filename, strlen(filename));

		CLSID_DirectMusicSegment,	// Class identifier.

		IID_IDirectMusicSegment8,	// ID of desired interface.

		wstrFileName,				// Filename.

		(LPVOID*) &tempWav->m_pSegment		// Pointer that receives interface.

		delete tempWav;
		return false;

	// Push the new wav file on the the link list.

	tempWav->next = m_WavTop; 
	m_WavTop = tempWav;
	return true;
[edited by - darkpatch on October 6, 2003 12:55:15 PM]

Share this post

Link to post
Share on other sites
Guest Anonymous Poster
Listener is a shared object between all sound sourses.
Just set
tempWav->m_dsBufferParams.dwMode to DS3DMODE_NORMAL instead DS3DMODE_HEADRELATIVE.
Now you can set positions for sounds and listener independently.

Share this post

Link to post
Share on other sites