Any ideas? Does mp3 play works without external DAC on ESP32? #1668
-
I got board with amplifier ICs FM8002A and ESP32. I am able to play mp3, but sound is heavy distorted (Wav or mp3 file). I have tried different combinations: Best I got listen here #include "AudioTools.h"
#include "AudioLibs/AudioSourceSPIFFS.h"
#include "AudioCodecs/CodecMP3Helix.h"
const char *startFilePath = "/";
const char *ext = "mp3";
AudioSourceSPIFFS source(startFilePath, ext);
I2SStream i2s;
// AnalogAudioStream i2s; //no sound
MP3DecoderHelix decoder;
AudioPlayer player(source, i2s, decoder);
void printMetaData(MetaDataType type, const char *str, int len)
{
Serial.print("==> ");
Serial.print(toStr(type));
Serial.print(": ");
Serial.println(str);
}
void setup()
{
Serial.begin(115200);
delay(1000); // Add a small delay to ensure proper initialization
AudioLogger::instance().begin(Serial, AudioLogger::Info);
auto cfg = i2s.defaultConfig(TX_MODE); // loud noise sound almost no melody
// auto cfg = i2s.defaultConfig(RX_MODE); // no sound
i2s.begin(cfg);
player.setMetadataCallback(printMetaData);
player.begin();
}
void loop()
{
player.copy();
} Can someone give me any suggestion at lest confirm that it should work or that you had same problems ;(. Thanks Output: --- Opened the serial port /dev/tty.usbserial-210 ----
[I] AudioTypes.h : 128 - out: sample_rate: 44100 / channels: 2 / bits_per_sample: 16
[I] AudioTypes.h : 128 - sample_rate: 44100 / channels: 2 / bits_per_sample: 16
[I] I2SConfigESP32.h : 80 - rx/tx mode: TX_MODE
[I] I2SConfigESP32.h : 81 - port_no: 0
[I] I2SConfigESP32.h : 82 - is_master: Master
[I] I2SConfigESP32.h : 83 - sample rate: 44100
[I] I2SConfigESP32.h : 84 - bits per sample: 16
[I] I2SConfigESP32.h : 85 - number of channels: 2
[I] I2SConfigESP32.h : 86 - signal_type: Digital
[I] I2SConfigESP32.h : 88 - i2s_format: I2S_STD_FORMAT
[I] I2SConfigESP32.h : 90 - auto_clear: true
[I] I2SConfigESP32.h : 92 - use_apll: true
[I] I2SConfigESP32.h : 97 - buffer_count:6
[I] I2SConfigESP32.h : 98 - buffer_size:512
[I] I2SConfigESP32.h : 103 - pin_bck: 14
[I] I2SConfigESP32.h : 105 - pin_ws: 15
[I] I2SConfigESP32.h : 107 - pin_data: 22
[I] AudioPlayer.h : 404 - virtual void audio_tools::AudioPlayer::setMetadataCallback(void (*)(audio_tools::MetaDataType, const char*, int), audio_tools::ID3TypeSelection)
[I] AudioPlayer.h : 338 - setVolume(1.000000)
[I] VolumeStream.h : 199 - setVolume: 1.000000 at 0
[I] VolumeStream.h : 199 - setVolume: 1.000000 at 1
[I] AudioTypes.h : 128 - out: sample_rate: 44100 / channels: 2 / bits_per_sample: 16
[I] MetaDataID3.h : 569 - virtual void audio_tools::MetaDataID3::begin()
[I] AudioSourceSPIFFS.h : 49 - selectStream: 0
[I] AudioSourceSPIFFS.h : 53 - Using file /ascr-mon.mp3
[I] StreamCopy.h : 70 - buffer_size=1024
[I] AudioTypes.h : 128 - MP3DecoderHelix sample_rate: 44100 / channels: 1 / bits_per_sample: 16
[I] AudioPlayer.h : 230 - sample_rate: 44100
[I] AudioPlayer.h : 231 - bits_per_sample: 16
[I] AudioPlayer.h : 232 - channels: 1
[I] AudioTypes.h : 128 - in: sample_rate: 44100 / channels: 1 / bits_per_sample: 16
[I] AudioTypes.h : 128 - out: sample_rate: 44100 / channels: 1 / bits_per_sample: 16
[I] I2SStream.h : 91 - virtual void audio_tools::I2SStream::setAudioInfo(audio_tools::AudioInfo)
[I] AudioTypes.h : 128 - in: sample_rate: 44100 / channels: 1 / bits_per_sample: 16
[I] AudioTypes.h : 128 - out: sample_rate: 44100 / channels: 1 / bits_per_sample: 16
[I] I2SStream.h : 100 - restarting i2s
[I] AudioTypes.h : 128 - I2SStream sample_rate: 44100 / channels: 1 / bits_per_sample: 16
[I] AudioTypes.h : 128 - sample_rate: 44100 / channels: 1 / bits_per_sample: 16
[I] I2SConfigESP32.h : 80 - rx/tx mode: TX_MODE
[I] I2SConfigESP32.h : 81 - port_no: 0
[I] I2SConfigESP32.h : 82 - is_master: Master
[I] I2SConfigESP32.h : 83 - sample rate: 44100
[I] I2SConfigESP32.h : 84 - bits per sample: 16
[I] I2SConfigESP32.h : 85 - number of channels: 1
[I] I2SConfigESP32.h : 86 - signal_type: Digital
[I] I2SConfigESP32.h : 88 - i2s_format: I2S_STD_FORMAT
[I] I2SConfigESP32.h : 90 - auto_clear: true
[I] I2SConfigESP32.h : 92 - use_apll: true
[I] I2SConfigESP32.h : 97 - buffer_count:6
[I] I2SConfigESP32.h : 98 - buffer_size:512
[I] I2SConfigESP32.h : 103 - pin_bck: 14
[I] I2SConfigESP32.h : 105 - pin_ws: 15
[I] I2SConfigESP32.h : 107 - pin_data: 22
[I] StreamCopy.h : 158 - StreamCopy::copy 1024 -> 1024 -> 1024 bytes - in 1 hops |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments
-
You are crazy to start like this! There are some DACs that require some specific format setting and some which do not support 16 bits. Further info you can find in the Wiki |
Beta Was this translation helpful? Give feedback.
-
Thanks for the suggestions. I tried various approaches and ultimately switched the jumper on the board to use AnalogAudioStream. While this improved the situation, there's still a significant amount of background noise, along with sharp noises at the start and end of the audio. I've attached some audio samples for reference. I suspect that the I2S isn't functioning perfectly or may have inherent limitations. Unfortunately, I'm unable to change the hardware at this point. Do you have any ideas on how to address this? Perhaps a filter could help? Results are: Not working?: I have no experience with sound, so any suggestions would be helpful. Could this be normal for ESP32 without a dedicated audio chip? Thanks Testing code: #include "AudioTools.h"
// AudioInfo info(44100, 2, 16); //not working.
AudioISnfo info(22050, 2, 16);
SineWaveGenerator<int16_t> sineWave(32000);
GeneratedSoundStream<int16_t> sound(sineWave);
// I2SStream out; //not working
AnalogAudioStream out;
StreamCopy copier(out, sound);
// Arduino Setup
void setup(void)
{
// Open Serial
Serial.begin(115200);
while (!Serial)
;
AudioLogger::instance().begin(Serial, AudioLogger::Info);
// start I2S
Serial.println("starting I2S...");
auto config = out.defaultConfig(TX_MODE);
config.copyFrom(info);
out.begin(config);
// Setup sine wave
sineWave.begin(info, N_B4);
// B4-sounds almost correct but noise recorded on phone,
// C0 no sound,
// G5 little added buzz
Serial.println("started...");
}
uint64_t lastTime = millis();
void loop()
{
if (millis() - lastTime < 1000)
{
copier.copy();
}
else if (millis() - lastTime > 1500)
{
Serial.println("Pause for 0.5s");
lastTime = millis();
}
} |
Beta Was this translation helpful? Give feedback.
-
You should use a proper I2S DAC to feed your amplifier |
Beta Was this translation helpful? Give feedback.
You are crazy to start like this!
Read this wiki and try to do a proper root cause analysis. Advance only after to you have the i2s working properly...
There are some DACs that require some specific format setting and some which do not support 16 bits. Further info you can find in the Wiki