Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lots of loss #705

Open
fensoft opened this issue Sep 15, 2024 · 1 comment
Open

lots of loss #705

fensoft opened this issue Sep 15, 2024 · 1 comment

Comments

@fensoft
Copy link

fensoft commented Sep 15, 2024

conditions:

  • 1m away from my router
  • using localhost mp3 through python3 -m http.server

results: lots of jittering.

actions tried:

  • increase esp32 cpu frequency
  • increase AudioFileSourceBuffer buffer size
  • increase AudioOutputI2S dma_buffer
  • set channel to mono
    but no change

here is my code:

#include <Arduino.h>
#include <WiFi.h>
#include "AudioFileSourceICYStream.h"
#include "AudioFileSourceBuffer.h"
#include "AudioGeneratorMP3.h"
#include <AudioOutputI2S.h>
#include "pins.h"

#ifndef STASSID
#define STASSID "wifi_wpa2"
#define STAPSK  "<password>"
#endif

const char* ssid = STASSID;
const char* password = STAPSK;

AudioGeneratorMP3 *mp3;
AudioFileSourceHTTPStream *file;
AudioFileSourceBuffer *buff;
AudioOutputI2S *out;

// Called when there's a warning or error (like a buffer underflow or decode hiccup)
void StatusCallback(void *cbData, int code, const char *string)
{
  const char *ptr = reinterpret_cast<const char *>(cbData);
  // Note that the string may be in PROGMEM, so copy it to RAM for printf
  char s1[64];
  strncpy_P(s1, string, sizeof(s1));
  s1[sizeof(s1)-1]=0;
  Serial.printf("STATUS(%s) '%d' = '%s'\n", ptr, code, s1);
  Serial.flush();
}


void setup()
{
  Serial.begin(115200);
  delay(1000);
  Serial.println("Connecting to WiFi");

  WiFi.disconnect();
  WiFi.softAPdisconnect(true);
  WiFi.mode(WIFI_STA);
  
  WiFi.begin(ssid, password);

  while (WiFi.status() != WL_CONNECTED) {
    Serial.println("...Connecting to WiFi");
    delay(1000);
  }
  Serial.println("Connected");
  Serial.println((int)getCpuFrequencyMhz());

  audioLogger = &Serial;
  file = new AudioFileSourceHTTPStream("http://localip/file.mp3");
  file->useHTTP10();
  buff = new AudioFileSourceBuffer(file, 8192);
  buff->RegisterStatusCB(StatusCallback, (void*)"buffer");
  out = new AudioOutputI2S(0, 0, 32);
  out->SetChannels(1);
  out->SetOutputModeMono(true);
  out->SetPinout(BCK, WS, DOUT);
  mp3 = new AudioGeneratorMP3();
  mp3->RegisterStatusCB(StatusCallback, (void*)"mp3");
  mp3->begin(buff, out);
}


void loop()
{
  static int lastms = 0;

  if (mp3->isRunning()) {
    if (millis()-lastms > 1000) {
      lastms = millis();
      Serial.printf("Running for %d ms...\n", lastms);
      Serial.flush();
     }
    if (!mp3->loop()) mp3->stop();
  } else {
    Serial.printf("MP3 done\n");
    delay(1000);
  }
}
@fensoft
Copy link
Author

fensoft commented Sep 15, 2024

Looks like the file is the reason but I don't know why:

ok.mp3: MPEG ADTS, layer III, v1, 128 kbps, 44.1 kHz, JntStereo
bad.mp3: Audio file with ID3 version 2.3.0, contains: MPEG ADTS, layer III, v1, 64 kbps, 44.1 kHz, Stereo

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant