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.01k stars 432 forks source link

Audio plays slowly on RP2040 #558

Open elominp opened 2 years ago

elominp commented 2 years ago

Hello,

Thanks for the work on the library, it works pretty well except that I have an issue on the output audio on a RP2040 based-board, whatever audio file I play is indeed played but slowly, like 2-3 times slower than real I think.

Same thing for examples, I tried the PlayWAVFromPROGMEM and PlayAACFromPROGMEM for example and I'm pretty sure they should be played faster than what I hear, at least when comparing audio files on my computer :)

For example, even for this simple sketch I adapted to use my PCM5102 DAC:

#include <Arduino.h>

#include "AudioFileSourcePROGMEM.h"
#include "AudioGeneratorWAV.h"
#include "AudioOutputI2S.h"

// VIOLA sample taken from https://ccrma.stanford.edu/~jos/pasp/Sound_Examples.html
#include "viola.h"

AudioGeneratorWAV *wav;
AudioFileSourcePROGMEM *file;
AudioOutputI2S *out;

void setup()
{
  Serial.begin(115200);
  delay(1000);
  Serial.printf("WAV start\n");

  audioLogger = &Serial;
  file = new AudioFileSourcePROGMEM( viola, sizeof(viola) );
  out = new AudioOutputI2S(44100, 9, 11);
  wav = new AudioGeneratorWAV();
  wav->begin(file, out);
}

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

The sound plays slowly, being the original viola file or replaced by the content of another WAV file I convert to C-Array and I even try changing settings from -Os to -O2 and overclocking to 250MHz my pico without any change so I don't think it's necessarily a raw performance issue.

At the inverse, I tried to play my WAV file in a much more complex sketch still with the exact same play speed, it didn't get slower.

Do you have any idea what could cause this effect / distortion please?

Thanks for your help :)