Playdate->sound->sampleplayer->play with repeat set to 0 (indefinate play) only repeats 64 times every time with adpcm encoded wav file

calling pd->sound->sampleplayer->play with repeats set to 0 is supposed to play your sample indefinatly until stop() is called called according to the documentation:

however this does not seem to be the case it seems to repeat exactly 64 times each time and then stops repeating i don't know why but i tested with a few audio files both long and small ones it stops always after 64 repeats (which is an odd nr's if you ask me).

I've used the following sound to test this (it's easy to count the times) :
draw.zip (20.3 KB)

and i've used the following example updateloop / program to test it out. In both simulator as on playdate it stops repeating after 64 times

Am i doing something wrong codewise ? or is this a bug ?

SamplePlayer* player = NULL;
AudioSample* Sample = NULL;
// main update function
int update(void* ud)
{
	if (player == NULL)
	{
		player = pd->sound->sampleplayer->newPlayer();
		if (player)
		{
			Sample = pd->sound->sample->load("draw");
			if (Sample)
			{
				pd->sound->sampleplayer->setSample(player, Sample);
				pd->sound->sampleplayer->setVolume(player, 1.0f, 1.0f);
				pd->sound->sampleplayer->play(player, 0, 1.0f);
			}
		}
	}
	return 1;
}

edit this only seems to happen with ADPCM encoded wav files, i rencoded the draw.wav file to pcm 16 bit signed and it does not have the issue

I just put a fix in for this! What's happening is on the 64th loop the end of the file syncs up with the audio frame, then the next time around the decoder causes the player to bail early because it doesn't have anything left to decode, which skips the loop check that would normally move the decoder back to the start of the file. This actually happens on all ADPCM files, but the number of loops it takes can be any power of two up to 256.

Thanks for catching this! It's a pretty obscure bug, good job nailing it down!

1 Like