Support snd resources with non-0 sustain loop start frame

This commit is contained in:
Iliyas Jorio 2022-09-25 19:06:52 +02:00
parent 38d2be66b6
commit 15d3606631
3 changed files with 18 additions and 3 deletions

View File

@ -175,8 +175,21 @@ static void InstallSoundInChannel(SndChannelPtr chan, const Ptr sampledSoundHead
{
impl.source.SetLoop(true);
if (info.loopStart != 0)
TODO2("Warning: looping on a portion of the snd isn't supported yet");
// Set sustain loop start frame
if ((int) info.loopStart >= impl.source.length)
{
TODO2("Warning: Illegal sustain loop start frame");
}
else
{
impl.source.sustainOffset = info.loopStart;
}
// Check sustain loop end frame
if ((int) info.loopEnd != impl.source.length)
{
TODO2("Warning: Unsupported sustain loop end frame");
}
}
//---------------------------------

View File

@ -247,6 +247,7 @@ void Source::Init(int theSampleRate, int theLength)
{
this->samplerate = theSampleRate;
this->length = theLength;
this->sustainOffset = 0;
SetGain(1);
SetPan(0);
SetPitch(1);
@ -592,7 +593,7 @@ void WavStream::FillBuffer(int16_t* dst, int fillLength)
// Loop back and continue filling buffer if we didn't fill the buffer
if (fillLength > 0)
{
idx = 0;
idx = sustainOffset;
}
}
}

View File

@ -46,6 +46,7 @@ namespace cmixer
int16_t pcmbuf[BUFFER_SIZE]; // Internal buffer with raw stereo PCM
int samplerate; // Stream's native samplerate
int length; // Stream's length in frames
int sustainOffset; // Offset of the sustain loop in frames
int end; // End index for the current play-through
int state; // Current state (playing|paused|stopped)
int64_t position; // Current playhead position (fixed point)