audio: need to clear the rest of the buffer at end of sample.

This commit is contained in:
Henrik Rydgård committed 2012-12-26 19:12:23 +01:00
1 parent b82852d8b3
commit ddd3e4384f
2 files changed
+9 -6

No files matched your search

+7 -3
View File
@@ -41,14 +41,14 @@ void VagDecoder::Start(u8 *data, int vagSize, bool loopEnabled) {
s_2 = 0.0;
}
bool VagDecoder::DecodeBlock() {
void VagDecoder::DecodeBlock() {
int predict_nr = GetByte();
int shift_factor = predict_nr & 0xf;
predict_nr >>= 4;
int flags = GetByte();
if (flags == 7) {
end_ = true;
return false;
return;
}
else if (flags == 6) {
loopStartBlock_ = curBlock_;
@@ -73,7 +73,6 @@ bool VagDecoder::DecodeBlock() {
if (curBlock_ == numBlocks_) {
end_ = true;
}
return true;
}
void VagDecoder::GetSamples(s16 *outSamples, int numSamples) {
@@ -90,6 +89,11 @@ void VagDecoder::GetSamples(s16 *outSamples, int numSamples) {
s_2 = 0.0;
}
DecodeBlock();
if (end_) {
// Clear the rest of the buffer and return.
memset(&outSamples[i], 0, (numSamples - i) * sizeof(s16));
return;
}
}
outSamples[i] = end_ ? 0 : samples[curSample++];
}
+2 -3
View File
@@ -74,15 +74,14 @@ enum VoiceType {
// It compresses 28 16-bit samples into a block of 16 bytes.
// TODO: Get rid of the doubles, making sure it does not impact sound quality.
// Doubles are pretty fast on Android devices these days though.
class VagDecoder
{
class VagDecoder {
public:
VagDecoder() : data_(0), read_(0) {}
void Start(u8 *data, int vagSize, bool loopEnabled);
void GetSamples(s16 *outSamples, int numSamples);
bool DecodeBlock();
void DecodeBlock();
bool End() const { return end_; }
u8 GetByte() {