Skip to content

Performance

Phil Schatzmann edited this page Dec 12, 2022 · 33 revisions

Overview

The framework is supporting quite a few scenarios. The default settings have been chosen to work well in avarage with most of the scenarios. You have quite a few options to tweak the performance for your individual case. A good starting point are the settings in the AudioConfig.h. You either can change the values directly in the AudioConfig.h or create a local AudioConfigLocal.h file. The most relevant settings are

  • DEFAULT_BUFFER_SIZE
  • I2S_BUFFER_SIZE
  • I2S_BUFFER_COUNT

Please note that increasing the values might improve if the audio is breaking up. Reducing the values is reducing the delays!
The i2s buffer definition can also be changed programmatically in your sketch when you define your i2s config.

StreamCopy

When you define the StreamCopy you can specify the buffer size in the constructor

StreamCopy(Print &to, Stream &from, int buffer_size=DEFAULT_BUFFER_SIZE);

AudioPlayer

When you define the AudioSourceSdFat you can define the SPI speed in MHz in the constructor:

AudioSourceSdFat(const char* startFilePath = "/", const char* ext = ".mp3", int chipSelect = PIN_CS, int speedMHz = 2);

URLStream

The URLStream is usually fast enough to stream audio data. Make sure that you have a good wifi and network connection. To optimize the settings you can try to play around with the copy buffer size which is provided in the constructor and the I2S Buffers.

URLStreamBuffered

The following is valid for the ESP32 only. The URLStreamBuffered uses it's own task and buffer to store the received (encoded) data which is defined by

  • DEFAULT_BUFFER_SIZE,
  • URL_STREAM_BUFFER_COUNT

In this case it is advisable to increase the URL_STREAM_BUFFER_COUNT and e.g. keep the I2S_BUFFER_COUNT as small as possible!

The following parameters are also relevant:

#define URL_STREAM_CORE 0
#define URL_STREAM_PRIORITY 2
#define STACK_SIZE 30000
#define URL_CLIENT_TIMEOUT 60000;
#define URL_HANDSHAKE_TIMEOUT 120000

If you are running low on memory you might consider to comment out the USE_URLSTREAM_TASK

Logging

Last but not least: If you have activated logging please note the following. A log level of Info or below is leading to a poor audio quality. So after your sketch is working do not forget to set the Log level back to Warning or Error!