Clean Looping Mod for AudioPlaySDWav Using File.seek(int)

Status
Not open for further replies.

grinch

Well-known member
Hi, I recently posted about making a SD wav file player object that could handle more than 2 channels. Well I did that and it's working really well! Now I'm trying to add in clean looping functionality to the object (as a replacement for the super hacky: if(!wavPlayer.isPlaying()){ wavPlayer.play("filename.wav"); } method).

I think I've succeeded in doing this as well but I'd like to check to make sure the code I've added is doing what I think its doing and will not create problems down the line:

The key element of the looping is in the update function:
Code:
end:	// end of file reached or other reason to stop
  if(state != STATE_STOP && isRepeating){
    Serial.println("Trying Repeat!"); //tell us we're repeating 
    wavfile.seek(44); //setting wavfile read index to 44 to skip wav header information
    goto readagain; //read wavfile from beginning
  }
	wavfile.close(); //will never reach this unless we manually set STATE_STOP
Also did some logic stuff elsewhere with state but that's not important to my main question.

The main question is this:

Does wavfile.seek(44) actually set the file read index to 44? If so it seems like this would effectively loop the file by having it start reading from the first sample again (since byte 44 is the beginning of the audio data in a wav file). Is this a correct assumption?
 
Status
Not open for further replies.
Back
Top