ESP8266Audio
ESP8266Audio copied to clipboard
Seeking in AudioGeneratorWAV gets invalid RIFF header
Hello all!
I successfully got ESP8266Audio
running on my ESP32, and it is outputting a wav file read from an SD card via a pcm5102
DAC.
I need to be able to dynamically seek to different positions in the wav file and play it back at varying speeds. I read through the code and it seemed like the right way to do this is to call file->seek(5, SEEK_SET)
.
Calling this function in combination with file->getPos
shows that I am indeed increasing the position from 0 -> 5 (seconds? miliseconds?). Unfortunately, when I do this, the audio fails to play and outputs the following error:
AudioGeneratorWAV::ReadWAVInfo: cannot read WAV, invalid RIFF header, got: 570225EE
AudioGeneratorWAV::begin: failed during ReadWAVInfo
Here is the full ESP8266Audio implementation, in case it helps:
static const i2s_config_t i2s_config = {
.mode = i2s_mode_t(I2S_MODE_MASTER | I2S_MODE_TX),
.sample_rate = 44100,
.bits_per_sample = i2s_bits_per_sample_t(16),
.channel_format = I2S_CHANNEL_FMT_RIGHT_LEFT,
.communication_format = i2s_comm_format_t(0x01), // I2S_COMM_FORMAT_STAND_I2S,
.intr_alloc_flags = 0, // default interrupt priority
.dma_buf_count = 8,
.dma_buf_len = 64,
.use_apll = false
};
static const i2s_pin_config_t pin_config = {
.bck_io_num = i2sBitClockPin,
.ws_io_num = i2sLeftRightClockPin,
.data_out_num = i2sDataOutPin,
.data_in_num = I2S_PIN_NO_CHANGE
};
void setup() {
i2s_driver_install(i2s_port_t(i2sPortNumber), &i2s_config, 0, NULL);
i2s_set_pin(i2s_port_t(i2sPortNumber), &pin_config);
audioLogger = &Serial;
dac = new AudioOutputI2S();
wav = new AudioGeneratorWAV();
file = new AudioFileSourceSD("/gnome.wav");
file->seek(5, SEEK_SET);
wav->begin(file, dac);
}
void loop() {
if (wav->isRunning()) {
if (!wav->loop()) {
wav->stop();
Serial.println("Stopped");
}
}
}
Hello! Did you find a way to adjust the playback speed?