earlephilhower / ESP8266Audio

Arduino library to play MOD, WAV, FLAC, MIDI, RTTTL, MP3, and AAC files on I2S DACs or with a software emulated delta-sigma DAC on the ESP8266 and ESP32
GNU General Public License v3.0
2.05k stars 435 forks source link

Finish bufferred samples #520

Open RomanLut opened 2 years ago

RomanLut commented 2 years ago

AudioGenerator should let AudioOutput finish playing buffered samples.

Reproduction:

The common loop:

if (mp3->isRunning()) { if (!mp3->loop()) mp3->stop(); } else { Serial.printf("MP3 done\n"); delay(1000); }

stops AudioOutput as soon as last sample is pushed to output. All buferred samples are discarded.

Solution: After pushing last sample, AudioGenerator should call AudioOutput->finish() as long as it returns false. While finishing, AudioGenerator should return true from AudioGenerator->IsRunning() and AudioGenerator->loop().

Implemented for AudioOutputI2S ( and AudioOutputNoDAC effectivelly ) , and AudioGeneratorMP3 and AudioGeneratorWAV. Other classes work as before ( not affected ).