#include "Precompiled.h" #include "RakiEngine/Data/MemoryBlock/MemoryBlock.h" #include "RakiEngine/Data/WaveFile/BinWaveData/BinWaveData.h" #include "RakiEngine/Data/WaveFile/RiffChunkManager.h" #include "RakiEngine/Sounds/PCMStreamSource.h" #include "RakiEngine/Sounds/StreamBufferInfo.h" #include "RakiEngine/Sounds/SoftwareEngine/StreamSoftwareSound.h" #include "RakiEngine/Sources/SineSource.h" #include "RakiEngine/Sources/Synth/MonophonicSynth.h" #include "RakiTests/Sounds/PCMDataProvider.h" #include "RakiEngine/Utils/Calcs.h" #if defined ( RAKI_USING_XAUDIO2 ) #include "RakiEngine/Sounds/_XAudio2/PCMStreamSoundNative.h" #elif defined ( RAKI_PLATFORM_PS3 ) #include #include "RakiEngine/Sounds/_PS3/BufferSoundNative_PS3.h" #include "RakiEngine/Sounds/_PS3/PCMStreamSoundNative_PS3.h" #include "RakiTests/Sounds/MP3DataProvider.h" #elif defined ( RAKI_PLATFORM_WII ) #include #include "RakiEngine/Sounds/_Wii/BufferSoundNative_Wii.h" #include "RakiEngine/Sounds/_Wii/PCMStreamSoundNative_Wii.h" #elif defined ( RAKI_PLATFORM_CAFE ) #include "RakiEngine/Sounds/_Cafe/PCMStreamSoundNative_Cafe.h" #include "RakiTests/_Cafe/Memory/SimpleHeap_Cafe.h" #endif #if defined ( RAKI_PLATFORM_WIN32 ) #include "RakiTests/_Win32/CoInitializeInitObject.h" #endif // ( RAKI_PLATFORM_WIN32 ) #include "RakiTests/Initializer/TestInitializer.h" namespace raki { extern void SystemAllocator_Initialize(); #define STREAMINGSOURCE_NB_CHANNELS 2 #define STREAMINGSOURCE_MAIN_THREAD_UPDATE_PERIOD_MILLISECONDS 100 #define STREAMINGSOURCE_BUFFER_SAMPLESIZE ( STREAMINGSOURCE_MAIN_THREAD_UPDATE_PERIOD_MILLISECONDS * RAKI_NATIVE_SAMPLING_RATE / 800 ) // should be divided by 1000 for milliseconds - multiple by a bit more than 1.2 for safety #define STREAMINGSOURCE_BUFFER_ALIGNED_SAMPLESIZE ( ( STREAMINGSOURCE_BUFFER_SAMPLESIZE + 63 ) - ( ( STREAMINGSOURCE_BUFFER_SAMPLESIZE + 63 ) % 64 ) ) // should be divided by 1000 for milliseconds - multiple by a bit more than 1.2 for safety #define STREAMINGSOURCE_BUFFER_BYTESIZE ( STREAMINGSOURCE_BUFFER_ALIGNED_SAMPLESIZE * 2 * STREAMINGSOURCE_NB_CHANNELS ) void TestSourceStreaming_Sine(); void TestSourceStreaming_Sine() { bool buffersAllocated = false; #if defined ( RAKI_PLATFORM_WIN32 ) #if defined ( RAKI_USING_SOFTWARE_ENGINE ) StreamSoftwareSound pcmStreamSound; #else PCMStreamSoundNative pcmStreamSound; #endif // pcmStreamSound.getStreamBufferInfo()->setStreamUpdateClient( &testUpdateClient ); buffersAllocated = pcmStreamSound.allocateBuffers( STREAMINGSOURCE_BUFFER_BYTESIZE ); RAKI_ASSERT( buffersAllocated ); #elif defined ( RAKI_PLATFORM_XB360 ) PCMStreamSoundNative pcmStreamSound; buffersAllocated = pcmStreamSound.allocateBuffers( STREAMINGSOURCE_BUFFER_BYTESIZE ); RAKI_ASSERT( buffersAllocated ); #elif defined ( RAKI_PLATFORM_WII ) || defined ( RAKI_PLATFORM_CAFE ) PCMStreamSoundNative pcmStreamSound( STREAMINGSOURCE_NB_CHANNELS ); buffersAllocated = pcmStreamSound.allocateBuffers( STREAMINGSOURCE_BUFFER_BYTESIZE ); RAKI_ASSERT( buffersAllocated ); #elif defined ( RAKI_PLATFORM_PS3 ) PCMStreamSoundNative pcmStreamSound; // mp3StreamSound.getStreamBufferInfo()->setStreamUpdateClient( &testUpdateClient ); buffersAllocated = pcmStreamSound.allocateBuffers( STREAMINGSOURCE_BUFFER_BYTESIZE ); RAKI_ASSERT( buffersAllocated ); #endif const bool isMusic = false; const bool isLooping = false; SoundParams soundParams( isMusic, isLooping ); SineSource source( STREAMINGSOURCE_NB_CHANNELS ); bool create = pcmStreamSound.createVoice( &source, soundParams ); RAKI_ASSERT( create ); pcmStreamSound.prepare( &source ); pcmStreamSound.updateRouting( true ); pcmStreamSound.start(); bool isPlaying = pcmStreamSound.isPlaying(); RAKI_ASSERT( isPlaying ); int count = 0; for ( ;; ) { bool isPlaying = false; #ifdef RAKI_PLATFORM_WII VIWaitForRetrace(); #else // RAKI_PLATFORM_WII Thread::sleep( 25 ); #endif // RAKI_PLATFORM_WII pcmStreamSound.update(); #if defined ( RAKI_PLATFORM_WIN32 ) isPlaying |= pcmStreamSound.isPlaying(); #else isPlaying |= pcmStreamSound.isPlaying(); #endif // if ( !isPlaying ) // break; ++count; } /* pcmStreamSound.stop(); // XAudio2 doc: Stop is always asynchronous, even if called within a callback Thread::sleep( 5000 ); pcmStreamSound.destroyVoice(); Thread::sleep( 500 ); */ } } // namespace raki #if defined ( RAKI_PLATFORM_CAFE ) u32 running_core; u32 main_core; u32 first_subcore; u32 second_subcore; u32 wait_main_core; u32 wait_first_subcore; u32 wait_second_subcore; OSRendezvous rendezvous; void SetupCoreIds(void) { running_core = OSGetCoreId(); main_core = OSGetMainCoreId(); first_subcore = 0; second_subcore = 2; wait_main_core = OS_WAIT_CORE_MAIN; wait_first_subcore = OS_WAIT_CORE_SUB1; wait_second_subcore = OS_WAIT_CORE_SUB2; if (main_core == 0) { first_subcore = 1; second_subcore = 2; wait_main_core = OS_WAIT_CORE_SUB1; wait_first_subcore = OS_WAIT_CORE_MAIN; wait_second_subcore = OS_WAIT_CORE_SUB2; } else if (main_core == 2) { first_subcore = 0; second_subcore = 1; wait_main_core = OS_WAIT_CORE_SUB2; wait_first_subcore = OS_WAIT_CORE_SUB1; wait_second_subcore = OS_WAIT_CORE_MAIN; } } int run_demo (int intArg, void *ptrArg) { raki::SimpleHeap_Cafe::init(); raki::TestInitializer initializer; raki::TestSourceStreaming_Sine(); return 0; } #endif #if defined ( RAKI_USING_XAUDIO2 ) int _tmain( int /*argc*/, _TCHAR* /*argv[]*/ ) #else // RAKI_USING_XAUDIO2 int main( int /*argc*/, char * /*argv[]*/ ) #endif // RAKI_USING_XAUDIO2 { #if defined ( RAKI_PLATFORM_WII ) DVDInit(); VIInit(); raki::SystemAllocator_Initialize(); #elif defined ( RAKI_PLATFORM_WIN32 ) raki::CoInitializeInitObject coInitializeInitObject; #elif defined ( RAKI_PLATFORM_CAFE ) u32 gx2InitAttribs[] = { GX2_INIT_ATTRIB_NULL // terminates the list }; GX2Init(gx2InitAttribs); // launch test on Core 0 if present if (OSGetCoreCount() == 3) { OSThread* defaultThread0; SetupCoreIds(); OSReport("Running Core == %d\n", running_core); OSReport("OS Main Core == %d\n\n", main_core); OSInitRendezvous(&rendezvous); // // Restart default thread on 1st subcore, core0 // defaultThread0 = OSGetDefaultThread(first_subcore); OSRunThread(defaultThread0, run_demo, 0, (void*) 0x23232323); OSWaitRendezvous(&rendezvous, wait_first_subcore); } else { run_demo(0, NULL); } GX2Shutdown(); return 0; #endif #if !defined ( RAKI_PLATFORM_CAFE ) raki::TestInitializer initializer; raki::TestSourceStreaming_Sine(); return 0; #endif // !defined ( RAKI_PLATFORM_CAFE ) }