Don't loop PCM samples when loopPos < 0.

This commit is contained in:
Unknown W. Brackets 2014-02-16 17:34:23 -08:00
parent 95fc9624b4
commit 6b984c5593
2 changed files with 33 additions and 0 deletions

View file

@ -394,9 +394,16 @@ void SasVoice::ReadSamples(s16 *output, int numSamples) {
needed -= size;
out += size;
if (pcmIndex >= pcmSize) {
if (!loop) {
// All out, quit. We'll end in HaveSamplesEnded().
break;
}
pcmIndex = pcmLoopPos;
}
}
if (needed > 0) {
memset(out, 0, needed * sizeof(s16));
}
}
break;
case VOICETYPE_ATRAC3:
@ -418,6 +425,24 @@ void SasVoice::ReadSamples(s16 *output, int numSamples) {
}
}
bool SasVoice::HaveSamplesEnded() {
switch (type) {
case VOICETYPE_VAG:
// TODO: Is it here, or before the samples are processed?
return false;
case VOICETYPE_PCM:
return pcmIndex >= pcmSize;
case VOICETYPE_ATRAC3:
// TODO: Is it here, or before the samples are processed?
return false;
default:
return false;
}
}
void SasInstance::MixVoice(SasVoice &voice) {
switch (voice.type) {
case VOICETYPE_VAG:
@ -489,6 +514,8 @@ void SasInstance::MixVoice(SasVoice &voice) {
//voice.sampleFrac &= grainSize * PSP_SAS_PITCH_BASE - 1;
voice.sampleFrac -= numSamples * PSP_SAS_PITCH_BASE;
if (voice.HaveSamplesEnded())
voice.envelope.End();
if (voice.envelope.HasEnded())
{
// NOTICE_LOG(SCESAS, "Hit end of envelope");
@ -659,6 +686,11 @@ void SasVoice::DoState(PointerWrap &p)
p.Do(sampleFrac);
p.Do(pitch);
p.Do(loop);
if (s < 2 && type == VOICETYPE_PCM) {
// We set loop incorrectly before, and always looped.
// Let's keep always looping, since it's usually right.
loop = true;
}
p.Do(noiseFreq);

View file

@ -215,6 +215,7 @@ struct SasVoice {
void DoState(PointerWrap &p);
void ReadSamples(s16 *output, int numSamples);
bool HaveSamplesEnded();
bool playing;
bool paused; // a voice can be playing AND paused. In that case, it won't play.