This commit is contained in:
2026-02-12 21:00:02 -08:00
parent 77f8236347
commit 8bdbf227ca
1141 changed files with 1010880 additions and 2 deletions

View File

@@ -0,0 +1,29 @@
# Decoding a MP3 file
In this example we decode a MP3 file into RAW output and write the output with the help of a PWM signal to the pins.
Currently we provide multiple mp3 decoders
- libhelix
- tinymp3
Unfortunatly non of those are currently stable in all environments....
### Output Device: Earphone
To test the output I am using an earphone from a mobile phone.
We get 2 signals one for the left and the other for the right channel.
![DAC](https://pschatzmann.github.io/Resources/img/earphones.jpg)
The pins depend on the Processor:
| EarPhone | ESP32 | RPI Pico | MBED |
| -----------| -------------|---------------|--------------|
| Left | GPI2 | GPI2 | GPI2 |
| Right | GPI3 | GPIO3 | GPI3 |
| GND | GND | GND | GND |
To verify check the PIN_PWM_START in AudioConfig.h or you can set the pins by calling setPins() method on the PWMConfig object.

View File

@@ -0,0 +1,44 @@
/**
* @file stream-memory_mp3-analog.ino
* @author Phil Schatzmann
* @brief decode MP3 stream and output as analog signal
* @version 0.1
* @date 2021-01-24
*
* @copyright Copyright (c) 2021
*/
#include "AudioTools.h"
#include "AudioTools/AudioCodecs/CodecMP3Helix.h"
#include "BabyElephantWalk60_mp3.h"
MemoryStream mp3(BabyElephantWalk60_mp3, BabyElephantWalk60_mp3_len);
PWMAudioOutput out; // PWM output
EncodedAudioStream decoded(&out, new MP3DecoderHelix()); // output to decoder
StreamCopy copier(decoded, mp3); // copy in to out
void setup(){
Serial.begin(115200);
AudioToolsLogger.begin(Serial, AudioToolsLogLevel::Info);
// begin processing
auto cfg = out.defaultConfig();
out.begin(cfg);
decoded.begin();
}
void loop(){
if (mp3) {
copier.copy();
} else {
auto info = decoded.decoder().audioInfo();
LOGI("The audio rate from the mp3 file is %d", info.sample_rate);
LOGI("The channels from the mp3 file is %d", info.channels);
out.end();
stop();
}
}