void CSoundComponent::Startup() { if (InitXACT(mEngName.c_str())==false || LoadWaveBank(mWaveName.c_str())==false || LoadSoundBank(mSoundName.c_str())==false) { CloseXACT(); // give up } }
//-------------------------------------------------------------------------------------- // Entry point to the program //-------------------------------------------------------------------------------------- int main( int argc, char* argv[] ) { HRESULT hr; IXACT3Engine* pXACTEngine = NULL; IXACT3Wave* pXACTWave = NULL; BYTE* pWaveBuffer = NULL; HANDLE hStreamingFile = NULL; DWORD dwState = 0; // Init XACT wprintf( L"Initializing XACT audio engine...\n\n" ); if( FAILED( hr = InitXACT( &pXACTEngine ) ) ) { wprintf( L"Failed to init XACT" ); CleanupXACT( pXACTEngine ); return 0; } // Load in-memory wave file wprintf( L"Loading %s into an in-memory IXACTWave interface...\n", EXAMPLE_FILENAME ); if( FAILED( hr = LoadWaveFileInMemory( pXACTEngine, EXAMPLE_FILENAME, EXAMPLE_SECONDS, EXAMPLE_SAMPLERATE, EXAMPLE_CHANNELS, EXAMPLE_BITRATE, &pXACTWave, &pWaveBuffer ) ) ) { if( hr == HRESULT_FROM_WIN32( ERROR_FILE_NOT_FOUND ) ) wprintf( L"Failed to load wave file because media not found\n" ); else wprintf( L"Failed to load wave file" ); CleanupXACT( pXACTEngine ); return 0; } // Play in-memory wave file wprintf( L"Playing in-memory XACT wave... Press escape to stop\n\n" ); if( FAILED( hr = pXACTWave->Play() ) ) { wprintf( L"Failed to play XACT wave file\n" ); CleanupXACT( pXACTEngine ); return 0; } // Loop while allowing XACT to do work. Rendering could be intermixed here dwState = 0; while( dwState != XACT_STATE_STOPPED ) { pXACTEngine->DoWork(); Sleep( 10 ); pXACTWave->GetState( &dwState ); if( GetAsyncKeyState( VK_ESCAPE ) ) pXACTWave->Stop( XACT_FLAG_STOP_IMMEDIATE ); } // Now that the in-memory wave has stopped playing, its safe to delete the memory SAFE_DELETE_ARRAY( pWaveBuffer ); // Wait till the escape key is released while( GetAsyncKeyState( VK_ESCAPE ) ) Sleep( 10 ); // Load streaming wave file wprintf( L"Loading %s into a streaming IXACTWave interface...\n", EXAMPLE2_FILENAME ); if( FAILED( hr = LoadWaveFileStreaming( pXACTEngine, EXAMPLE2_FILENAME, EXAMPLE2_SECONDS, EXAMPLE2_SAMPLERATE, EXAMPLE2_CHANNELS, EXAMPLE2_BITRATE, &pXACTWave, &hStreamingFile ) ) ) { if( hr == HRESULT_FROM_WIN32( ERROR_FILE_NOT_FOUND ) ) wprintf( L"Failed to load wave file because media not found\n" ); else wprintf( L"Failed to load wave file" ); CleanupXACT( pXACTEngine ); return 0; } // Call DoWork until the wave is fully prepared dwState = 0; while( dwState != XACT_STATE_PREPARED ) { pXACTEngine->DoWork(); Sleep( 10 ); pXACTWave->GetState( &dwState ); } // Play in-memory wave file wprintf( L"Playing streaming XACT wave... Press escape to stop\n\n" ); if( FAILED( hr = pXACTWave->Play() ) ) { wprintf( L"Failed to play XACT wave file\n" ); CleanupXACT( pXACTEngine ); return 0; } // Loop while allowing XACT to do work. Rendering could be intermixed here dwState = 0; while( dwState != XACT_STATE_STOPPED ) { pXACTEngine->DoWork(); Sleep( 10 ); pXACTWave->GetState( &dwState ); if( GetAsyncKeyState( VK_ESCAPE ) ) pXACTWave->Stop( XACT_FLAG_STOP_IMMEDIATE ); } // Now that the streaming wave has stopped playing, its safe to close the file handle CloseHandle( hStreamingFile ); // Cleanup XACT state wprintf( L"Finished playing XACT wave\n" ); CleanupXACT( pXACTEngine ); }