Read Ogg Vorbis data directly into out buffer
This commit is contained in:
@@ -192,12 +192,17 @@ namespace lime
|
|||||||
bool loadOggSample(OggVorbis_File &oggFile, QuickVec<unsigned char> &outBuffer, int *channels, int *bitsPerSample, int* outSampleRate)
|
bool loadOggSample(OggVorbis_File &oggFile, QuickVec<unsigned char> &outBuffer, int *channels, int *bitsPerSample, int* outSampleRate)
|
||||||
{
|
{
|
||||||
// 0 for Little-Endian, 1 for Big-Endian
|
// 0 for Little-Endian, 1 for Big-Endian
|
||||||
int endian = 0;
|
#ifdef HXCPP_BIG_ENDIAN
|
||||||
|
#define BUFFER_READ_TYPE 1
|
||||||
|
#else
|
||||||
|
#define BUFFER_READ_TYPE 0
|
||||||
|
#endif
|
||||||
|
|
||||||
int bitStream;
|
int bitStream;
|
||||||
long bytes = 1;
|
long bytes = 1;
|
||||||
|
int totalBytes = 0;
|
||||||
|
|
||||||
#define BUFFER_SIZE 32768
|
#define BUFFER_SIZE 32768
|
||||||
char array[BUFFER_SIZE];
|
|
||||||
|
|
||||||
//Get the file information
|
//Get the file information
|
||||||
//vorbis data
|
//vorbis data
|
||||||
@@ -216,19 +221,25 @@ namespace lime
|
|||||||
//Return the same rate as well
|
//Return the same rate as well
|
||||||
*outSampleRate = pInfo->rate;
|
*outSampleRate = pInfo->rate;
|
||||||
|
|
||||||
|
// Seem to need four times the read PCM total
|
||||||
|
outBuffer.resize(ov_pcm_total(&oggFile, -1)*4);
|
||||||
|
|
||||||
while (bytes > 0)
|
while (bytes > 0)
|
||||||
{
|
{
|
||||||
// Read up to a buffer's worth of decoded sound data
|
if (outBuffer.size() < totalBytes + BUFFER_SIZE)
|
||||||
bytes = ov_read(&oggFile, array, BUFFER_SIZE, endian, 2, 1, &bitStream);
|
|
||||||
if (bytes)
|
|
||||||
{
|
{
|
||||||
outBuffer.Set((unsigned char*)array, bytes);
|
outBuffer.resize(totalBytes + BUFFER_SIZE);
|
||||||
}
|
}
|
||||||
|
// Read up to a buffer's worth of decoded sound data
|
||||||
|
bytes = ov_read(&oggFile, (char*)outBuffer.begin() + totalBytes, BUFFER_SIZE, BUFFER_READ_TYPE, 2, 1, &bitStream);
|
||||||
|
totalBytes += bytes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
outBuffer.resize(totalBytes);
|
||||||
ov_clear(&oggFile);
|
ov_clear(&oggFile);
|
||||||
|
|
||||||
#undef BUFFER_SIZE
|
#undef BUFFER_SIZE
|
||||||
|
#undef BUFFER_READ_TYPE
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user