static void RLXAPI Render(void) { HRESULT hr; if (g_lpDS3DListener) { hr = SYS_DXTRACE(g_lpDS3DListener->CommitDeferredSettings()); } }
// --------------------------------------------------------------------------------------- // 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; }
//=========================================================================== // DS_Listener // SFXLP_UNITS_PER_METER // SFXLP_DOPPLER // SFXLP_UPDATE //=========================================================================== void DS_Listener(int property, float value) { if(!dsListener) return; switch(property) { case SFXLP_UPDATE: // Commit any deferred settings. dsListener->CommitDeferredSettings(); EAXCommitDeferred(); break; case SFXLP_UNITS_PER_METER: dsListener->SetDistanceFactor(1/value, DS3D_IMMEDIATE); break; case SFXLP_DOPPLER: dsListener->SetDopplerFactor(value, DS3D_IMMEDIATE); break; } }
//----------------------------------------------------------------------------- // Name: MainDlgProc() // Desc: Handles dialog messages //----------------------------------------------------------------------------- INT_PTR CALLBACK MainDlgProc( HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam ) { HRESULT hr; switch( msg ) { case WM_INITDIALOG: OnInitDialog( hDlg ); break; case WM_COMMAND: switch( LOWORD(wParam) ) { case IDC_SOUNDFILE: OnOpenSoundFile( hDlg ); break; case IDCANCEL: EndDialog( hDlg, IDCANCEL ); break; case IDC_PLAY: if( FAILED( hr = OnPlaySound( hDlg ) ) ) { DXTRACE_ERR( TEXT("OnPlaySound"), hr ); MessageBox( hDlg, "Error playing DirectSound buffer." "Sample will now exit.", "DirectSound Sample", MB_OK | MB_ICONERROR ); EndDialog( hDlg, IDABORT ); } break; case IDC_STOP: if( g_pSound ) { g_pSound->Stop(); g_pSound->Reset(); } // Update the UI controls to show the sound as stopped EnablePlayUI( hDlg, TRUE ); SetDlgItemText( hDlg, IDC_STATUS, TEXT("Sound stopped.") ); break; case IDC_DEFER: g_bDeferSettings = !g_bDeferSettings; OnSliderChanged( hDlg ); break; case IDC_APPLY: // Call the IDirectSound3DListener::CommitDeferredSettings // method to execute all of the deferred commands at once. // This is many times more efficent than recomputing everything // for every call. if( g_pDSListener ) g_pDSListener->CommitDeferredSettings(); break; default: return FALSE; // Didn't handle message } break; case WM_TIMER: if( wParam == IDT_MOVEMENT_TIMER ) OnMovementTimer( hDlg ); break; case WM_NOTIFY: OnSliderChanged( hDlg ); break; case WM_DESTROY: // Cleanup everything KillTimer( hDlg, 1 ); SAFE_RELEASE( g_pDSListener ); SAFE_RELEASE( g_pDS3DBuffer ); SAFE_DELETE( g_pSound ); SAFE_DELETE( g_pSoundManager ); break; default: return FALSE; // Didn't handle message } return TRUE; // Handled message }
// --------------------------------------------------------------------------------------- // 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; }