Game Development Reference
In-Depth Information
19. The code above uses the size of the sWAVHeader structure to determine the offset
of the audio data:
The alignment of structure fields should be set to 1 for sWAVHeader . Our
declaration is compatible with Clang and GCC compilers from Android NDK
and MinGW. Use #pragma pack for VisualStudio.
struct __attribute__((packed,aligned(1))) sWAVHeader
{
unsigned char RIFF[4];
unsigned int Size;
unsigned char WAVE[4];
unsigned char FMT[4];
unsigned int SizeFmt;
unsigned short FormatTag;
unsigned short Channels;
unsigned int SampleRate;
unsigned int AvgBytesPerSec;
unsigned short nBlockAlign;
unsigned short nBitsperSample;
unsigned char Reserved[4];
unsigned int DataSize;
};
Later we reuse this structure for the loading of the .wav iles.
How it works...
First, we declare the global variables holding our virtual ilesystem and the SoundThread
object:
clPtr<FileSystem> g_FS;
SoundThread g_Sound;
We create our usual application template and in the OnStart() callback function, we start
a thread that initializes the OpenAL library:
void OnStart( const std::string& RootPath )
{
g_FS = new FileSystem();
g_FS->Mount( "." );
#if defined(ANDROID)
g_FS->Mount( RootPath );
g_FS->AddAliasMountPoint( RootPath, "assets" );
#endif
g_Sound.Start( iThread::Priority_Normal );
}
 
Search WWH ::




Custom Search