#include "Precompiled.h" #ifndef RAKI_USING_SOFTWARE_ENGINE #error ("this test requires RAKI_USING_SOFTWARE_ENGINE") #endif #include "RakiEngine/Data/MemoryBlock/MemoryBlock.h" #include "RakiEngine/Data/Serialization/SerializationStream.h" #include "RakiEngine/Data/Stream/MemoryStream/MemoryStream.h" #include "RakiEngine/Data/Stream/SeekableStreamPart.h" #include "RakiEngine/Data/Stream/AsyncReadStreamer.h" #include "RakiEngine/Data/WaveFile/BinWaveData/BinWaveData.h" #include "RakiEngine/Data/WaveFile/RiffChunkManager.h" #include "RakiEngine/Data/WaveFile/WaveFile.h" #include "RakiEngine/Sounds/Sequencer/Sequencer.h" #include "RakiEngine/Sounds/Sequencer/SineNoteMemBlock.h" #include "RakiEngine/Sounds/StreamBufferInfo.h" #include "RakiEngine/System/Streaming/StreamingThread.h" #include "RakiEngine/Utils/Calcs.h" #include "RakiTests/Sounds/PCMDataProvider.h" #include "RakiTests/Stream/ReadFileStream.h" #include "RakiEngine/Sounds/SoftwareEngine/BufferSoftwareSound.h" #include "RakiEngine/Sounds/SoftwareEngine/StreamSoftwareSound.h" #include "RakiEngine/Engine/SoftwareEngine/SoftwareEngine.h" #include "RakiEngine/Utils/Calcs.h" #if defined ( RAKI_USING_XAUDIO2 ) #include "RakiEngine/Sounds/_XAudio2/BufferSoundNative.h" #include "RakiEngine/Sounds/_XAudio2/PCMStreamSoundNative.h" #include "RakiEngine/Sounds/_XAudio2/XMA2StreamSoundNative_X360.h" #include "RakiEngine/Specific/_XB360/Specific_X360.h" #include "RakiTests/Sounds/XMA2DataProvider.h" #elif defined ( RAKI_PLATFORM_PS3 ) #elif defined ( RAKI_PLATFORM_WII ) #include #elif defined ( RAKI_PLATFORM_CAFE ) #elif defined ( RAKI_PLATFORM_ORBIS ) #include "OrbisInput.h" #include #endif #if defined ( RAKI_PLATFORM_WIN32 ) #include "RakiTests/_Win32/CoInitializeInitObject.h" #endif // ( RAKI_PLATFORM_WIN32 ) #include "RakiTests/Initializer/TestInitializer.h" //#define TESTING_STREAMING_TOO namespace raki { extern void SystemAllocator_Initialize(); #if defined ( RAKI_PLATFORM_WII ) || defined ( RAKI_PLATFORM_CAFE ) #define BUFFER_PREFETCH_SIZE 55040 #else #define BUFFER_PREFETCH_SIZE ( 2 * 0x10000 ) //#define BUFFER_PREFETCH_SIZE ( 2 * 0x1000 ) #endif class TestData { public: TestData() { } void load( const char * _path ) { ReadFileStream file; bool opened = file.open( _path ); RAKI_ASSERT_WITH_MESSAGE( opened, "Invalid path" ); SerializationStream stream( &file ); m_waveFile.read( stream, true ); RAKI_ASSERT( m_waveFile.getChunkData( RiffChunkManager::ms_riffTagData ) ); // checking that data is loaded RAKI_ASSERT( m_waveFile.getChunkData( RiffChunkManager::ms_riffTagFmt ) ); // checking that data is loaded } WaveFile m_waveFile; }; void TestSoftwareSoundStreaming( const char * _path ); void TestSoftwareSoundStreaming( const char * _path ) { #ifdef RAKI_PLATFORM_ORBIS OrbisInput input; input.init(); #endif // RAKI_PLATFORM_ORBIS TestData testData[2]; testData[0].load( _path ); testData[1].load( _path ); BufferSoftwareSound bufferSoftwareSound0; BufferSoftwareSound bufferSoftwareSound1; #ifdef TESTING_STREAMING_TOO // streaming StreamingThread streamingThread; streamingThread.start(); ReadFileStream file; bool opened = file.open( _path ); RAKI_ASSERT_WITH_MESSAGE( opened, "Invalid path" ); WaveFile waveFile; Serializer serializer( &file ); waveFile.read( serializer ); RAKI_ASSERT( waveFile.getChunkData( RiffChunkManager::ms_riffTagData ) ); // checking that data is loaded RAKI_ASSERT( waveFile.getChunkData( RiffChunkManager::ms_riffTagFmt ) ); // checking that data is loaded file.close(); file.open( _path ); // SeekableStreamPart streamPart( &file, waveFile.getChunkOffsetInStream( RiffChunkManager::ms_riffTagData ), waveFile.getChunkSize( RiffChunkManager::ms_riffTagData ) ); void * prefetchBuffer = NULL; const u64 prefetchBufferSize = 0; SeekableStream * _stream; void * clientData = NULL; AsyncReadStreamer asyncReadStreamer; asyncReadStreamer.allocateBuffers( 0x10000 ); asyncReadStreamer.setStreamData( prefetchBuffer, prefetchBufferSize, &streamPart, clientData ); asyncReadStreamer.setStreamingThread( &streamingThread ); const u64 bytesPerSample = 4; const u32 nbChannels = 2; const bool isLooping = false; PCMDataProvider pcmDataProvider( &asyncReadStreamer, clientData, bytesPerSample, nbChannels, isLooping ); StreamSoftwareSound streamSoftwareSound; streamSoftwareSound.allocateBuffers( 0x1000 ); streamSoftwareSound.prepare( &pcmDataProvider ); streamSoftwareSound.start( ); #endif // TESTING_STREAMING_TOO bufferSoftwareSound0.createVoice( &testData[0].m_waveFile, SoundParams() ); bufferSoftwareSound1.createVoice( &testData[0].m_waveFile, SoundParams() ); bufferSoftwareSound0.start(); bool addAnotherSound = true; float timeBeginning = Time::getTime(); float timeToStartSecondSound = 2.f; // 2 seconds float timeToStopFirst = 240.f; // 4 minutes float timeToStopSecond = 240.f; // 4 minutes float timeEllapsed = 0.f; bool stopFirstSound = true; bool stopSecondSound = true; while ( bufferSoftwareSound0.isPlaying() || bufferSoftwareSound1.isPlaying() #ifdef TESTING_STREAMING_TOO || streamSoftwareSound.isPlaying() #endif // TESTING_STREAMING_TOO ) { #ifdef TESTING_STREAMING_TOO asyncReadStreamer.update( true ); streamSoftwareSound.update(); #endif // TESTING_STREAMING_TOO // update input #ifdef RAKI_PLATFORM_ORBIS input.update(); /* if( input.isButtonPressed( 0, SCE_PAD_BUTTON_L1 ) ) { bufferSoftwareSound0.pause(); } else { bufferSoftwareSound0.resume(); } if( input.isButtonPressed( 0, SCE_PAD_BUTTON_R1 ) ) { bufferSoftwareSound1.pause(); } else { bufferSoftwareSound1.resume(); }*/ /* u8 l2Val = 0; u8 r2Val = 0; if( input.getL2Val(0, l2Val) ) { bufferSoftwareSound0.setVolume( 1.f - (f32)l2Val / 255.f ); } if( input.getR2Val(0, r2Val) ) { bufferSoftwareSound1.setVolume( 1.f - (f32)r2Val / 255.f ); }*/ #endif // RAKI_PLATFORM_ORBIS /* // update sounds f32 currentTime = Time::getTime(); f32 duration = currentTime - timeBeginning; if( ( duration > timeToStartSecondSound ) && addAnotherSound ) { //bufferSoftwareSound1.start(); addAnotherSound = false; } if( duration > timeToStopFirst && stopFirstSound ) { bufferSoftwareSound0.stop(); stopFirstSound = false; } if( duration > timeToStopSecond && stopSecondSound ) { bufferSoftwareSound1.stop(); stopSecondSound = false; }*/ Thread::sleep( 17 ); // simulate a main thread } bufferSoftwareSound0.destroyVoice(); bufferSoftwareSound1.destroyVoice(); #ifdef TESTING_STREAMING_TOO streamingThread.stop(); #endif // TESTING_STREAMING_TOO // wait for destroyVoice and streamingThread.stop commands to be processed while ( !bufferSoftwareSound0.isVoiceDestroyed() || !bufferSoftwareSound1.isVoiceDestroyed() #ifdef TESTING_STREAMING_TOO || streamingThread.isRunning() #endif // TESTING_STREAMING_TOO ) { Thread::sleep( 5 ); } } } // namespace raki #if defined ( RAKI_PLATFORM_ORBIS ) size_t sceLibcHeapSize = SCE_LIBC_HEAP_SIZE_EXTENDED_ALLOC_NO_LIMIT; unsigned int sceLibcHeapExtendedAlloc = 1; #endif //RAKI_PLATFORM_ORBIS #if defined ( RAKI_USING_XAUDIO2 ) int _tmain( int /*argc*/, _TCHAR* /*argv[]*/ ) #elif defined( RAKI_PLATFORM_ORBIS ) int main( int argc, char *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 ) #if defined ( RAKI_PLATFORM_WIN32 ) //const char path[] = "d:/Projects/JD/code/radu_bolovan_JD5/JD/playground/raki_modifs/main/extern/Raki/TestData/BlameIt.wav"; const char path[] = "E:/Temp/Raki/TestData/Mus_Jun_Cage_Free_04_2M.wav"; #elif defined ( RAKI_PLATFORM_ORBIS ) const char path[] = "/hostapp/_raki_/BlameIt.wav"; #elif defined ( RAKI_PLATFORM_XB360 ) const char path1[] = "game:\\Mus_Jun_Cage_Free_04_2M.wav.x360"; const char path2[] = "game:\\Mus_Jun_Cage_Free_04_2M.wav.x360"; #elif defined ( RAKI_PLATFORM_PS3 ) const char path1[] = "/app_home/Y:/JD5/JD/main/extern/Raki/TestData/Mus_Jun_Cage_Free_04_2M.wav.ps3"; const char path2[] = "/app_home/Y:/JD5/JD/main/extern/Raki/TestData/Mus_Jun_Cage_Free_04_2M.wav.ps3"; #elif defined ( RAKI_PLATFORM_WII ) const char path1[] = "_raki_/Mus_Jun_Cage_Free_04_2M.wav.wii"; const char path2[] = "_raki_/Mus_Jun_Cage_Free_04_2M.wav.wii"; #endif //raki::Engine::createSingleton(); raki::TestInitializer initializer; raki::TestSoftwareSoundStreaming( path ); return 0; #endif // !defined ( RAKI_PLATFORM_CAFE ) }