323 |
* @see SetPos() |
* @see SetPos() |
324 |
*/ |
*/ |
325 |
unsigned long Sample::Read(void* pBuffer, unsigned long SampleCount) { |
unsigned long Sample::Read(void* pBuffer, unsigned long SampleCount) { |
326 |
if (!Compressed) return pCkData->Read(pBuffer, SampleCount, FrameSize); |
if (!Compressed) return pCkData->Read(pBuffer, SampleCount, FrameSize); //FIXME: channel inversion due to endian correction? |
327 |
else { //FIXME: no support for mono compressed samples yet, are there any? |
else { //FIXME: no support for mono compressed samples yet, are there any? |
328 |
|
if (this->SamplePos >= this->SamplesTotal) return 0; |
329 |
//TODO: efficiency: we simply assume here that all frames are compressed, maybe we should test for an average compression rate |
//TODO: efficiency: we simply assume here that all frames are compressed, maybe we should test for an average compression rate |
330 |
// best case needed buffer size (all frames compressed) |
// best case needed buffer size (all frames compressed) |
331 |
unsigned long assumedsize = (SampleCount << 1) + // *2 (16 Bit, stereo, but assume all frames compressed) |
unsigned long assumedsize = (SampleCount << 1) + // *2 (16 Bit, stereo, but assume all frames compressed) |
354 |
// reload from disk to local buffer if needed |
// reload from disk to local buffer if needed |
355 |
if (remainingbytes < 8194) { |
if (remainingbytes < 8194) { |
356 |
if (pCkData->GetState() != RIFF::stream_ready) { |
if (pCkData->GetState() != RIFF::stream_ready) { |
357 |
this->SamplePos += (SampleCount - remainingsamples); |
this->SamplePos = this->SamplesTotal; |
|
//if (this->SamplePos > this->SamplesTotal) this->SamplePos = this->SamplesTotal; |
|
358 |
return (SampleCount - remainingsamples); |
return (SampleCount - remainingsamples); |
359 |
} |
} |
360 |
assumedsize = remainingsamples; |
assumedsize = remainingsamples; |
474 |
} |
} |
475 |
} |
} |
476 |
this->SamplePos += (SampleCount - remainingsamples); |
this->SamplePos += (SampleCount - remainingsamples); |
477 |
//if (this->SamplePos > this->SamplesTotal) this->SamplePos = this->SamplesTotal; |
if (this->SamplePos > this->SamplesTotal) this->SamplePos = this->SamplesTotal; |
478 |
return (SampleCount - remainingsamples); |
return (SampleCount - remainingsamples); |
479 |
} |
} |
480 |
} |
} |