Game Development Reference
In-Depth Information
void UnqueueAll()
{
int Queued;
alGetSourcei( FSourceID, AL_BUFFERS_QUEUED, &Queued );
if ( Queued > 0 )
alSourceUnqueueBuffers(FSourceID, Queued, &FBufferID);
}
For ininite sound looping, we can implement the LoopSound() method in the
AudioSource class:
void LoopSound( bool Loop )
{
alSourcei( FSourceID, AL_LOOPING, Loop ? 1 : 0);
}
The Android OS runs on multiple hardware architectures, and this can cause some additional
dificulties when reading the .wav iles. If the CPU we are running on has a big-endian
architecture, we have to swap the bytes in the ields of the sWAVHeader structure. The
modiied constructor of the WavProvider class looks like the following:
WavProvider(clPtr<Blob> source)
{
FRawData = source;
sWAVHeader H = *(sWAVHeader*)(FRawData->GetData());
#if __BIG_ENDIAN__
Header.FormatTag = SwapBytes16(Header.FormatTag);
Header.Channels = SwapBytes16(Header.Channels);
Header.SampleRate = SwapBytes32(Header.SampleRate);
Header.DataSize = SwapBytes32(Header.DataSize);
Header.nBlockAlign = SwapBytes16(Header.nBlockAlign);
Header.nBitsperSample = SwapBytes16(Header.nBitsperSample);
Big-endian memory byte order requires lower and higher bytes of 16-bit values to be swapped:
if ( (Header.nBitsperSample == 16) )
{
clPtr<Blob> NewBlob = new clBlob();
NewBlob->CopyBlob( FRawData.GetInternalPtr() );
FRawData = NewBlob;
unsigned short* Ptr =
(unsigned short*)FRawData->GetData();
for ( size_t i = 0 ; i != Header.DataSize / 2; i++ )
{
*Ptr = SwapBytes16(*Ptr);
Ptr++;
}
}
 
Search WWH ::




Custom Search