pschatzmann / arduino-audio-tools

Arduino Audio Tools (a powerful Audio library not only for Arduino)
GNU General Public License v3.0
1.55k stars 237 forks source link

MP3EncoderLAME - [Error] lame.c : 2769 - calloc(1,38808) -> 0x0 #321

Closed janczeresnia closed 2 years ago

janczeresnia commented 2 years ago

I also encountered a error in the MP3 LAME encoder.

Serial log:

[Error] lame.c : 2769 - calloc(1,38808) -> 0x0 
available MALLOC_CAP_8BIT: 25588 / MALLOC_CAP_32BIT: 64500  / MALLOC_CAP_SPIRAM: 0

MP3 encode/decode sketch:

/**
 * ESP32 MP3 MAD and LAME Audio Tools Test
 * https://github.com/pschatzmann/arduino-libmad
 * https://github.com/pschatzmann/arduino-liblame
 * generate sine wave -> encoder -> decoder -> dac GPIO 25 and 26
 */

#include "AudioTools.h"
#include "AudioCodecs/CodecMP3MAD.h"
#include "AudioCodecs/CodecMP3LAME.h"

uint16_t sample_rate = 44100;                             // The stream will have 44100 Hz sample rate
uint8_t channels = 2;                                     // The stream will have 2 channels
uint8_t bits_per_sample = 16;                             // The stream will have 16 bit per sample
uint16_t f = 1000;                                        // Sine frequency 1kHz

SineWaveGenerator<int16_t> sineWave(32000);               // subclass of SoundGenerator with max amplitude of 32000
GeneratedSoundStream<int16_t> sound(sineWave);            // Stream generated from sine wave
AnalogAudioStream dac;                                    // Analog output DAC GPIO 25 and 26
EncodedAudioStream decoder(&dac, new MP3DecoderMAD());    // decoder and write
EncodedAudioStream encoder(&decoder, new MP3EncoderLAME());// encoder and write
StreamCopy copier(encoder, sound); 

void setup() {
  Serial.begin(115200);
  while (!Serial && (millis() < 1000)) delay(1000); delay(2000);
  Serial.println(F("\nESP32 MP3 AudioTools Test\n"));
  AudioLogger::instance().begin(Serial, AudioLogger::Warning);
  Serial.printf("Sample rate %d Hz, %d channels, %d bit per sample\n",sample_rate,channels,bits_per_sample);

  // Setup sine wave
  Serial.printf("Setup %d Hz sine wave\n",f);
  auto cfgs = sineWave.defaultConfig();
  cfgs.sample_rate = sample_rate;
  cfgs.channels = channels;
  cfgs.bits_per_sample = bits_per_sample;
  sineWave.begin(cfgs, f);

  // Setup DAC out
  Serial.println(F("Setup DAC"));
  auto cfgd = dac.defaultConfig(TX_MODE);
  cfgd.sample_rate = sample_rate;
  cfgd.channels = channels;
  cfgd.bits_per_sample = bits_per_sample;
  dac.begin(cfgd);

  // start decoder
  Serial.println(F("Start MAD decoder"));
  decoder.begin();

  // start encoder
  Serial.println(F("Start LAME encoder"));
  encoder.begin(cfgs);

  Serial.println(F("MP3 test started..."));
}

void loop() {
  copier.copy();
}

Arduino IDE 1.8.19 on Linux arduino-esp32 2.0.4 MCU: ESP32 Dev module

pschatzmann commented 2 years ago

Just read the readme https://github.com/pschatzmann/arduino-liblame