Game Development Reference
In-Depth Information
extra->m_WavFormatEx.nAvgBytesPerSec =
extra->m_WavFormatEx.nSamplesPerSec* extra->m_WavFormatEx.nChannels*2;
extra->m_WavFormatEx.nBlockAlign
= 2* extra->m_WavFormatEx.nChannels;
extra->m_WavFormatEx.wFormatTag
= 1;
DWORD size = 4096 * 16;
DWORD pos = 0;
int
sec = 0;
int
ret = 1;
// get the total number of PCM samples
DWORD bytes = (DWORD)ov_pcm_total(&vf, -1);
bytes *= 2 * vi->channels;
if (handle->Size() != bytes)
{
GCC_ERROR(
The Ogg size does not match the memory buffer size
);
ov_clear(&vf);
SAFE_DELETE(vorbisMemoryFile);
return false;
}
// now read in the bits
while(ret && pos<bytes)
{
ret = ov_read(&vf, handle->WriteableBuffer()+pos, size, 0, 2, 1, &sec);
pos += ret;
if (bytes - pos < size)
{
size = bytes - pos;
}
}
extra->m_LengthMilli = 1000.f * ov_time_total(&vf, -1);
ov_clear(&vf);
delete vorbisMemoryFile;
return true;
}
This method shows you how to decompress an OGG memory buffer using the Vor-
bis API. The method will decompress the OGG stream into a PCM buffer that is
essentially identical to the results you saw earlier with the WaveResourceLoader .
The first part of the method initializes the OggMemoryFile structure and sets up
the callback functions for Vorbis. Then a structure called vorbis_info is used to
initialize the members of the WAVEFORMATEX , stored with the resource handle.
Search WWH ::




Custom Search