Example #1
0
// Play
void AudioStream::Play (long volume, int looping)
{
	if (m_pdsb) {
		// If playing, stop
		if (m_fPlaying) {
			if ( m_bIsPaused == FALSE)
			Stop_and_Rewind();
		}

		// Cue for playback if necessary
		if (!m_fCued) {
			Cue ();
		}

		if ( looping )
			m_bLooping = 1;
		else
			m_bLooping = 0;

		// Begin DirectSound playback
		HRESULT hr = m_pdsb->Play (0, 0, DSBPLAY_LOOPING);
		if (hr == DS_OK) {
			m_nTimeStarted = timer_get_milliseconds();
			Set_Volume(volume);
			// Kick off timer to service buffer
			m_timer.constructor();

			m_timer.Create (m_nBufService, m_nBufService, DWORD (this), TimerCallback);

			// Playback begun, no longer cued
			m_fPlaying = TRUE;
			m_bIsPaused = FALSE;
		}
		else {
			// If the buffer was lost, try to restore it
			if ( hr == DSERR_BUFFERLOST ) {
				hr = m_pdsb->Restore();
				if ( hr == DS_OK ) {
					hr = m_pdsb->Play (0, 0, DSBPLAY_LOOPING);
				}
				else {
					nprintf(("Sound", "Sound => Lost a buffer, tried restoring but got %s\n", get_DSERR_text(hr) ));
					Int3();	// get Alan, he wants to see this
				}
			}

			if ( hr != DS_OK ) {
				nprintf(("Sound", "Sound => Play failed with return value %s\n", get_DSERR_text(hr) ));
			}
		}
	}
}
Example #2
0
// Set_Volume
void AudioStream::Set_Volume(long vol)
{
	if ( vol < -10000 )
		vol = -10000;
	
	if ( vol > 0 )
		vol = 0;

	Assert( vol >= -10000 && vol <= 0 );
	h_result = m_pdsb->SetVolume(vol);
	m_lVolume = vol;
	if ( h_result != DS_OK )
		nprintf(("Sound","SOUND => SetVolume() failed with code '%s'\n", get_DSERR_text(h_result) ));
}
Example #3
0
// ---------------------------------------------------------------------------------------
// ds3d_update_listener()
//
//	returns:		0		=>		success
//					-1		=>		failure
//
int ds3d_update_listener(vector *pos, vector *vel, matrix *orient)
{
	HRESULT			hr;

	if (DS3D_inited == FALSE)
		return 0;

	if ( pDS3D_listener == NULL )
		return -1;
	
	// set the listener position
	if ( pos != NULL ) {
		hr = pDS3D_listener->SetPosition(pos->x, pos->y, pos->z, DS3D_DEFERRED); 
	}

	// set the listener veclocity
	if ( vel != NULL ) {
		hr = pDS3D_listener->SetVelocity(vel->x, vel->y, vel->z, DS3D_DEFERRED); 
	}

	if ( orient != NULL ) {
		hr = pDS3D_listener->SetOrientation(	orient->fvec.x, orient->fvec.y, orient->fvec.z,
															orient->uvec.x, orient->uvec.y, orient->uvec.z,
															DS3D_DEFERRED );
	}

	float rolloff_factor = 1.0f;
	if (ds_using_a3d() == true) {
		rolloff_factor = 3.0f;		// A3D rolloff
	} else {
		rolloff_factor = 3.0f;		// EAX rolloff
	}

	hr = pDS3D_listener->SetRolloffFactor( rolloff_factor, DS3D_DEFERRED );
	hr = pDS3D_listener->SetDopplerFactor( 1.0f, DS3D_DEFERRED );
	
	hr = pDS3D_listener->CommitDeferredSettings();
	if ( hr != DS_OK ) {
		nprintf(("SOUND","Error in pDS3D_listener->CommitDeferredSettings(): %s\n", get_DSERR_text(hr) ));
		return -1;
	}

	return 0;
}
Example #4
0
// ---------------------------------------------------------------------------------------
// ds3d_init_listener()
//
//
//	returns:		0		=>		success
//					-1		=>		failure
//
int ds3d_init_listener()
{
	HRESULT			hr;

	if ( pDS3D_listener != NULL )
		return 0;

	hr = pPrimaryBuffer->QueryInterface(IID_IDirectSound3DListener, (void**)&pDS3D_listener);
	if (hr != DS_OK) {
		nprintf(("Sound","SOUND => Fatal error calling pPrimaryBuffer->QueryInterface(): %s\n", get_DSERR_text(hr) ));
		return -1;
	}

	return 0;		
}
Example #5
0
// ---------------------------------------------------------------------------------------
// ds3d_init_listener()
//
//
//	returns:		0		=>		success
//					-1		=>		failure
//
int ds3d_init_listener()
{
#ifdef USE_OPENAL
	// this is already setup in ds_init()
#else
	HRESULT hr;

	if (pDS3D_listener != NULL)
		return 0;

	hr = pPrimaryBuffer->QueryInterface(IID_IDirectSound3DListener, (void**)&pDS3D_listener);
	if (hr != DS_OK)
	{
		nprintf(("Sound", "SOUND => Fatal error calling pPrimaryBuffer->QueryInterface(): %s\n", get_DSERR_text(hr)));
		return -1;
	}
#endif

	return 0;
}
Example #6
0
// ---------------------------------------------------------------------------------------
// ds3d_update_listener()
//
//	returns:		0		=>		success
//					-1		=>		failure
//
int ds3d_update_listener(vec3d* pos, vec3d* vel, matrix* orient)
{
	if (DS3D_inited == FALSE)
		return 0;

#ifdef USE_OPENAL
	// set the listener position
	if ( pos != NULL ) {
		OpenAL_ErrorPrint( alListener3f(AL_POSITION, pos->xyz.x, pos->xyz.y, pos->xyz.z) );
	}

	// set the listener velocity
	if ( vel != NULL ) {
		OpenAL_ErrorPrint( alListener3f(AL_VELOCITY, vel->xyz.x, vel->xyz.y, vel->xyz.z) );
	}

	// set the listener orientation
	if ( orient != NULL ) {
		// uvec is up/top vector, fvec is at/front vector
		ALfloat list_orien[] = { orient->vec.fvec.xyz.x, orient->vec.fvec.xyz.y, orient->vec.fvec.xyz.z,
									orient->vec.uvec.xyz.x, orient->vec.uvec.xyz.y, orient->vec.uvec.xyz.z };
		OpenAL_ErrorPrint( alListenerfv(AL_ORIENTATION, list_orien) );
	}

#else

	HRESULT hr;

	if (pDS3D_listener == NULL)
		return -1;

	// set the listener position
	if (pos != NULL)
	{
		hr = pDS3D_listener->SetPosition(pos->xyz.x, pos->xyz.y, pos->xyz.z, DS3D_DEFERRED);
	}

	// set the listener veclocity
	if (vel != NULL)
	{
		hr = pDS3D_listener->SetVelocity(vel->xyz.x, vel->xyz.y, vel->xyz.z, DS3D_DEFERRED);
	}

	if (orient != NULL)
	{
		hr = pDS3D_listener->SetOrientation(orient->vec.fvec.xyz.x, orient->vec.fvec.xyz.y, orient->vec.fvec.xyz.z,
			orient->vec.uvec.xyz.x, orient->vec.uvec.xyz.y, orient->vec.uvec.xyz.z,
			DS3D_DEFERRED);
	}

	float rolloff_factor = 1.0f;
	if (ds_using_a3d() == true)
	{
		rolloff_factor = 3.0f;		// A3D rolloff
	}
	else
	{
		rolloff_factor = 3.0f;		// EAX rolloff
	}

	hr = pDS3D_listener->SetRolloffFactor(rolloff_factor, DS3D_DEFERRED);
	hr = pDS3D_listener->SetDopplerFactor(1.0f, DS3D_DEFERRED);

	hr = pDS3D_listener->CommitDeferredSettings();
	if (hr != DS_OK)
	{
		nprintf(("SOUND", "Error in pDS3D_listener->CommitDeferredSettings(): %s\n", get_DSERR_text(hr)));
		return -1;
	}
#endif

	return 0;
}