Maybe someone here is familiar with ESP 8266, here I am using the library from Earlephilhower, maybe someone can help with how the library plays audio in repeating cycles without pause
#include <Arduino.h>
#include "AudioFileSourcePROGMEM.h"
#include "AudioGeneratorWAV.h"
#include "AudioOutputI2SNoDAC.h"
// VIOLA sample taken from https://ccrma.stanford.edu/~jos/pasp/Sound_Examples.html
#include "viola.h"
AudioGeneratorWAV *wav;
AudioFileSourcePROGMEM *file;
AudioOutputI2SNoDAC *out;
void setup()
{
Serial.begin(115200);
delay(1000);
Serial.printf("WAV start\n");
audioLogger = &Serial;
file = new AudioFileSourcePROGMEM( viola, sizeof(viola) );
out = new AudioOutputI2SNoDAC();
wav = new AudioGeneratorWAV();
wav->begin(file, out);
}
void loop()
{
if (wav->isRunning()) {
if (!wav->loop()) wav->loop();
} else {
Serial.printf("WAV done\n");
delay(1000);
}
}
(You may give it a try, though I'm not convinced that it is a clean solution as it is creating new instances of wav and file without removing/freeing the previous resources)
After looking into the library on github I found this function
bool AudioFileSourcePROGMEM::seek(int32_t pos, int dir)
{
if (!opened) return false;
uint32_t newPtr;
switch (dir) {
case SEEK_SET: newPtr = pos; break;
case SEEK_CUR: newPtr = filePointer + pos; break;
case SEEK_END: newPtr = progmemLen - pos; break;
default: return false;
}
if (newPtr > progmemLen) return false;
filePointer = newPtr;
return true;
}
If I understand it correctly it should be possible to set the filePointer to 0 again when the wave file ended. That could be a way to endlessly loop (if no other functions interfere) ... I cannot test it but will check if it compiles ..
I moved your topic to an appropriate forum category @yuzeng_39 .
In the future, please take some time to pick the forum category that best suits the subject of your topic. There is an "About the _____ category" topic at the top of each category that explains its purpose.