387 lines
9.8 KiB
C++
387 lines
9.8 KiB
C++
#include "Precompiled.h"
|
|
|
|
|
|
|
|
|
|
#include "RakiTests/Initializer/TestInitializer.h"
|
|
|
|
|
|
#include "RakiEngine/Data/Serialization/Serializer.h"
|
|
#include "RakiEngine/Data/Stream/SeekableStreamPart.h"
|
|
#include "RakiEngine/Data/WaveFile/RiffChunkManager.h"
|
|
#include "RakiEngine/Data/WaveFile/WaveFile.h"
|
|
|
|
#if defined ( RAKI_PLATFORM_WIN32 )
|
|
|
|
#include "RakiTests/_Win32/CoInitializeInitObject.h"
|
|
|
|
#endif // ( RAKI_PLATFORM_WIN32 )
|
|
|
|
|
|
#if defined ( RAKI_USING_XAUDIO2 )
|
|
|
|
#include "RakiEngine/Sounds/_XAudio2/BufferSoundNative.h"
|
|
|
|
#elif defined ( RAKI_PLATFORM_PS3 )
|
|
|
|
#include <cell/mstream.h>
|
|
#include <sysutil/sysutil_common.h>
|
|
#include "RakiEngine/Sounds/_PS3/BufferSoundNative_PS3.h"
|
|
|
|
#elif defined ( RAKI_PLATFORM_WII )
|
|
|
|
#include <revolution/vi.h>
|
|
#include <revolution/pad.h>
|
|
|
|
#include "RakiEngine/Sounds/_Wii/BufferSoundNative_Wii.h"
|
|
|
|
#include <revolution/os.h>
|
|
#include <revolution/ax.h>
|
|
#include <revolution/mem.h>
|
|
#include <revolution/ai.h>
|
|
#include <revolution/dvd.h>
|
|
#include <revolution/vi.h>
|
|
|
|
#endif
|
|
|
|
#include "RakiTests/Stream/BinFileReader.h"
|
|
#include "RakiTests/Stream/ReadFileStream.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace raki
|
|
{
|
|
|
|
|
|
extern void SystemAllocator_Initialize();
|
|
|
|
|
|
bool TestWaveFile( const char * _path, const bool _isLooping );
|
|
bool TestWaveFile( const char * _path, const bool _isLooping )
|
|
{
|
|
RiffChunkManager::singleton().setShouldReadDataBlockForWaveData( true );
|
|
|
|
|
|
ReadFileStream fileStream;
|
|
|
|
bool opened = fileStream.open( _path );
|
|
|
|
if ( !opened )
|
|
return false;
|
|
|
|
Serializer serializer( &fileStream );
|
|
|
|
WaveFile waveFile;
|
|
waveFile.serialize( serializer );
|
|
|
|
BufferSoundNative bufferSound;
|
|
|
|
const bool isMusic = false;
|
|
SoundParams soundParams( isMusic, _isLooping );
|
|
|
|
|
|
#if defined ( RAKI_USING_XAUDIO2 )
|
|
/*
|
|
|
|
SeekableStreamPart streamPart( &fileStream, waveFile.getChunkOffsetInStream( "data" ), waveFile.getChunkSize( "data" ) );
|
|
|
|
#if defined ( RAKI_PLATFORM_WIN32 )
|
|
|
|
void * buffer = Memory::malloc( waveFile.getChunkSize( "data" ), Memory::data );
|
|
|
|
#elif defined ( RAKI_PLATFORM_XB360 )
|
|
|
|
void * buffer = XPhysicalAlloc( waveFile.getChunkSize( "data" ), MAXULONG_PTR, XMA_BYTES_PER_PACKET, PAGE_READWRITE );
|
|
|
|
#endif
|
|
|
|
RAKI_ASSERT( buffer );
|
|
u64 dataSizeRead = streamPart.stream( buffer, waveFile.getChunkSize( "data" ) );
|
|
RAKI_ASSERT( dataSizeRead == waveFile.getChunkSize( "data" ) );
|
|
|
|
Format format( isMusic, _isLooping );
|
|
|
|
MemoryBlock data( buffer, dataSizeRead );
|
|
format.setData( (WAVEFORMATEX*)waveFile.getChunkData( "fmt " ), waveFile.getChunkSize( "fmt " ), &data );
|
|
|
|
#if defined ( RAKI_PLATFORM_XB360 )
|
|
u32 * seekTable = (u32*)waveFile.getChunkData( "seek" );
|
|
u32 nbSeekBlocks = waveFile.getChunkSize( "seek" ) / sizeof( u32 );
|
|
u32 sampleSize = seekTable[ nbSeekBlocks - 1 ];
|
|
if ( sampleSize > 768 )
|
|
sampleSize -= 768;
|
|
format.setLoopSampleSize( sampleSize );
|
|
#endif // defined ( RAKI_PLATFORM_XB360 )
|
|
*/
|
|
bool created = bufferSound.createVoice( &waveFile, soundParams );
|
|
RAKI_ASSERT( created );
|
|
|
|
bufferSound.start();
|
|
|
|
if ( _isLooping )
|
|
{
|
|
f32 timeBeginning = Time::getTime();
|
|
|
|
// wait 5 seconds
|
|
while ( ( Time::getTime() - timeBeginning ) < 5 )
|
|
Thread::sleep(15);
|
|
}
|
|
else
|
|
{
|
|
while ( bufferSound.isPlaying() )
|
|
Thread::sleep(15);
|
|
}
|
|
|
|
bufferSound.stop();
|
|
|
|
Thread::sleep(100);
|
|
/*
|
|
#if defined (RAKI_PLATFORM_WIN32)
|
|
|
|
Memory::free( buffer );
|
|
buffer = NULL;
|
|
|
|
#elif defined (RAKI_PLATFORM_XB360)
|
|
|
|
XPhysicalFree( buffer ) ;
|
|
buffer = NULL;
|
|
|
|
#endif
|
|
*/
|
|
#elif defined ( RAKI_PLATFORM_PS3 )
|
|
|
|
/*
|
|
WAVEFORMATEX * formatEx = (WAVEFORMATEX*)waveFile.getChunkData( "fmt " );
|
|
u32 waveFormatSize = waveFile.getChunkSize( "fmt " );
|
|
|
|
BufferSoundNative bufferSound;
|
|
const bool isMusic = false;
|
|
Format format( isMusic, _isLooping );
|
|
|
|
char msfChunk[] = "msf ";
|
|
MemoryBlock dataBlock( waveFile.getChunkData( msfChunk ), waveFile.getChunkSize( msfChunk ) );
|
|
|
|
char fmtChunk[] = "fmt ";
|
|
format.setData( (WAVEFORMATEX*) waveFile.getChunkData( fmtChunk ), waveFile.getChunkSize( fmtChunk ), &dataBlock );
|
|
*/
|
|
bufferSound.createVoice( &waveFile, soundParams );
|
|
|
|
bufferSound.updateVolume( true );
|
|
|
|
bufferSound.start();
|
|
|
|
if ( _isLooping )
|
|
{
|
|
f32 timeBeginning = Time::getTime();
|
|
|
|
// wait 5 seconds
|
|
while ( ( Time::getTime() - timeBeginning ) < 5 )
|
|
{
|
|
Thread::sleep( 16 );
|
|
|
|
int ret = cellSysutilCheckCallback();
|
|
RAKI_ASSERT( ret == CELL_OK );
|
|
}
|
|
}
|
|
else
|
|
{
|
|
while( bufferSound.isPlaying() )
|
|
{
|
|
Thread::sleep( 16 );
|
|
|
|
int ret = cellSysutilCheckCallback();
|
|
RAKI_ASSERT( ret == CELL_OK );
|
|
}
|
|
}
|
|
|
|
bufferSound.destroyVoice();
|
|
|
|
|
|
|
|
#elif defined ( RAKI_PLATFORM_WII )
|
|
|
|
/*
|
|
BufferSoundNative bufferSound;
|
|
|
|
const bool isMusic = false;
|
|
Format format( isMusic, _isLooping );
|
|
|
|
WAVEFORMATEX * formatEx = (WAVEFORMATEX*)waveFile.getChunkData( "fmt " );
|
|
format.setFormat( formatEx );
|
|
|
|
void * dspL = Memory::mallocMem2Aligned32( 96, Memory::data );
|
|
memcpy( dspL, waveFile.getChunkData( "dspL"), 96 );
|
|
DCStoreRange( dspL, 96 );
|
|
|
|
void * datL = Memory::mallocMem2Aligned32( waveFile.getChunkSize( "datL" ), Memory::data );
|
|
memcpy( datL, waveFile.getChunkData( "datL"), waveFile.getChunkSize( "datL" ) );
|
|
DCStoreRange( datL, waveFile.getChunkSize( "datL" ) );
|
|
|
|
format.setDataL( dspL, datL );
|
|
|
|
if ( waveFile.getChunkSize( "datR" ) )
|
|
{
|
|
void * dspR = Memory::mallocMem2Aligned32( 96, Memory::data );
|
|
memcpy( dspR, waveFile.getChunkData( "dspR"), 96 );
|
|
DCStoreRange( dspR, 96 );
|
|
|
|
void * datR = Memory::mallocMem2Aligned32( waveFile.getChunkSize( "datR" ), Memory::data );
|
|
memcpy( datR, waveFile.getChunkData( "datL"), waveFile.getChunkSize( "datR" ) );
|
|
DCStoreRange( datR, waveFile.getChunkSize( "datR" ) );
|
|
|
|
format.setDataR( dspR, datR );
|
|
}
|
|
|
|
/*
|
|
//format.setDataL( dspR, datR );
|
|
format.setDataL( waveFile.getChunkData( "dspL"), waveFile.getChunkData( "datL") );
|
|
DCStoreRange( waveFile.getChunkData( "dspL"), 96 );
|
|
DCStoreRange( waveFile.getChunkData( "datL"), waveFile.getChunkSize( "datL") );
|
|
*/
|
|
|
|
// format.setDataR( waveFile.getChunkData( "dspR"), waveFile.getChunkData( "datR") );
|
|
|
|
/*
|
|
WAVEFORMATEX formatEx = { 0 };
|
|
formatEx.wFormatTag = 1;
|
|
formatEx.nChannels = 1;
|
|
formatEx.nSamplesPerSec = 32000;
|
|
formatEx.nAvgBytesPerSec = 64000;
|
|
formatEx.nBlockAlign = 2;
|
|
formatEx.wBitsPerSample = 16;
|
|
|
|
bool opened = binFileReader.readFrom( "cymbal.dsp" );
|
|
void * data1 = binFileReader.getData();
|
|
//void * data2 = LoadFileIntoRam( "cymbal.dsp" );
|
|
|
|
DCStoreRange( data1, binFileReader.getSize() );
|
|
|
|
//int cmp = memcmp( data1, data2, binFileReader.getSize() );
|
|
|
|
void * data = data1;
|
|
|
|
format.setFormat( &formatEx, false );
|
|
format.setDataL( data, (void*)(96 + (u32)data ) );
|
|
|
|
// testnow( binFileReader.getData() );
|
|
*/
|
|
bufferSound.createVoice( &waveFile, soundParams );
|
|
|
|
bufferSound.start();
|
|
|
|
bufferSound.updateVolume( true );
|
|
|
|
if ( _isLooping )
|
|
{
|
|
f32 timeBeginning = Time::getTime();
|
|
|
|
// wait 5 seconds
|
|
while ( ( Time::getTime() - timeBeginning ) < 5 )
|
|
{
|
|
Thread::sleep(15);
|
|
// VIWaitForRetrace();
|
|
}
|
|
}
|
|
else
|
|
{
|
|
while ( bufferSound.isPlaying() )
|
|
VIWaitForRetrace();
|
|
}
|
|
|
|
bufferSound.destroyVoice();
|
|
|
|
// wait for audio callback
|
|
VIWaitForRetrace();
|
|
|
|
|
|
#endif // defined ( RAKI_USING_XAUDIO2 ) then defined ( RAKI_PLATFORM_PS3 ) then defined ( RAKI_PLATFORM_WII )
|
|
|
|
|
|
return true;
|
|
}
|
|
|
|
} // namespace raki
|
|
|
|
#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
|
|
{
|
|
|
|
//bool opened = fileStream.open( "game:\\134_BXmn_LOOP_LoopsMasters_PunkRock.xma" );
|
|
//bool opened = fileStream.open( "/app_home/d:/ITF/ITF/extern/Raki/TestData/Tchaiko2.wav.riff" );
|
|
//bool opened = fileStream.open( "sfx_menu_logo_appear.wav.ckd" );
|
|
|
|
|
|
#if defined ( RAKI_PLATFORM_WII )
|
|
DVDInit();
|
|
VIInit();
|
|
|
|
raki::SystemAllocator_Initialize();
|
|
|
|
#elif defined ( RAKI_PLATFORM_WIN32 )
|
|
|
|
raki::CoInitializeInitObject coInitializeInitObject;
|
|
|
|
#endif
|
|
|
|
|
|
raki::TestInitializer initializer;
|
|
|
|
|
|
|
|
#if defined ( RAKI_PLATFORM_WIN32 )
|
|
|
|
const char path_stereo[] = "../../../../TestData/Sfx_CageDoor_Discover.wav";
|
|
const char path_mono[] = "../../../../TestData/Sfx_ChangeCostume_01.wav";
|
|
const char path_loop[] = "../../../../TestData/Test_125_Hz_multiple_of_1152_samples_LOOP.wav";
|
|
|
|
#elif defined ( RAKI_PLATFORM_XB360 )
|
|
|
|
const char path_stereo[] = "game:\\Sfx_CageDoor_Discover.wav.x360";
|
|
const char path_mono[] = "game:\\Sfx_ChangeCostume_01.wav.x360";
|
|
const char path_loop[] = "game:\\Test_125_Hz_multiple_of_1152_samples_LOOP.wav.x360";
|
|
|
|
#elif defined ( RAKI_PLATFORM_PS3 )
|
|
|
|
const char path_stereo[] = "/app_home/Sfx_CageDoor_Discover.wav.ps3";
|
|
const char path_mono[] = "/app_home/Sfx_ChangeCostume_01.wav.ps3";
|
|
const char path_loop[] = "/app_home/Test_125_Hz_multiple_of_1152_samples_LOOP.wav.ps3";
|
|
|
|
#elif defined ( RAKI_PLATFORM_WII )
|
|
|
|
const char path_stereo[] = "Sfx_CageDoor_Discover.wav.wii";
|
|
const char path_mono[] = "Sfx_ChangeCostume_01.wav.wii";
|
|
const char path_loop[] = "Test_125_Hz_multiple_of_1152_samples_LOOP.wav.wii";
|
|
|
|
#endif
|
|
|
|
|
|
bool playedOK = raki::TestWaveFile( path_loop, true );
|
|
RAKI_ASSERT( playedOK );
|
|
|
|
if ( !playedOK )
|
|
return -1;
|
|
|
|
playedOK = raki::TestWaveFile( path_stereo, false );
|
|
RAKI_ASSERT( playedOK );
|
|
|
|
if ( !playedOK )
|
|
return -1;
|
|
|
|
playedOK = raki::TestWaveFile( path_mono, false );
|
|
RAKI_ASSERT( playedOK );
|
|
|
|
if ( !playedOK )
|
|
return -1;
|
|
|
|
return 0;
|
|
}
|
|
|