pschatzmann / arduino-audio-tools

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

Incorrect size of core dump image on YourCee AI Thinker ESP32-A1S Audio Kit V2.2 A417 #1662

Closed peterburk closed 2 months ago

peterburk commented 2 months ago

Problem Description

After flashing the example send-receive sketch in Arduino Audio Tools, the serial monitor shows:

rst:0x1 (POWERON_RESET),boot:0x1f (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:1
load:0x3fff0030,len:1448
load:0x40078000,len:14844
ho 0 tail 12 room 4
load:0x40080400,len:4
load:0x40080404,len:3356
entry 0x4008059c
E (398) esp_cor⸮յ⸮}⸮⸮⸮͡⸮ Incorrect size of core dump image: -4
[W] I2SESP32V1.h : 184 - Invalid channel_format: 3

I'm using the ESP32 Dev Module board definition in Arduino.

Device Description

YourCee AI Thinker ESP32-A1S Audio Kit V2.2 A417

Sketch

send-receive example

Other Steps to Reproduce

Tried squeezelite-esp32 and esp-idf successfully

What is your development environment

Arduino IDE 2.3.2, macOS Sonoma

I have checked existing issues, discussions and online documentation

pschatzmann commented 2 months ago

If you are using an AudioKit, did you replace the I2SStream ?

The Arduino IDE Version is irrelevant: the important information is the ESP32 core version!

peterburk commented 2 months ago

Yes, I replaced the I2SStream. Now I see: `ets Jul 29 2019 12:21:46

rst:0x1 (POWERON_RESET),boot:0x1f (SPI_FAST_FLASH_BOOT) configsip: 0, SPIWP:0xee clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00 mode:DIO, clock div:1 load:0x3fff0030,len:1448 load:0x40078000,len:14844 ho 0 tail 12 room 4 load:0x40080400,len:4 load:0x40080404,len:3356 entry 0x4008059c E (421) esp_cor⸮Eյ⸮}⸮⸮⸮͡⸮ Incorrect size of core dump image: -4 E (54) i2s_common: i2s_new_channel(812): no available channel found [E] I2SESP32V1.h : 433 - i2s_channel `

pschatzmann commented 2 months ago

I was using AudioBoardStream out(AudioKitEs8388V1); and can't reproduce your issue. Start with a simple AudioKit Sine Generator sketch and continue only if this is working!

See here

With log level info I am getting:

10:19:09.157 -> rst:0x1 (POWERON_RESET),boot:0x1f (SPI_FAST_FLASH_BOOT)
10:19:09.157 -> configsip: 0, SPIWP:0xee
10:19:09.157 -> clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
10:19:09.157 -> mode:DIO, clock div:1
10:19:09.157 -> load:0x3fff0030,len:4832
10:19:09.157 -> load:0x40078000,len:16460
10:19:09.157 -> load:0x40080400,len:4
10:19:09.157 -> load:0x40080404,len:3504
10:19:09.157 -> entry 0x400805cc
10:19:09.608 -> [I] SoundGenerator.h : 164 - SineWaveGenerator::begin(channels=1, sample_rate=22000, frequency=493.88)
10:19:09.608 -> [I] SoundGenerator.h : 149 - bool audio_tools::SineWaveGenerator<T>::begin() [with T = short int]
10:19:09.608 -> [I] AudioTypes.h : 128 - SoundGenerator: sample_rate: 22000 / channels: 1 / bits_per_sample: 16
10:19:09.641 -> [I] Buffers.h : 372 - resize: 2
10:19:09.641 -> [I] SoundGenerator.h : 192 - setFrequency: 493.88
10:19:09.641 -> [I] SoundGenerator.h : 193 - active: true
10:19:09.641 -> [I] AudioStreams.h : 1010 - begin sample_rate: 22000, channels: 1, bits: 16
10:19:09.641 -> Warning: Pin '13' not set up because of conflict
10:19:09.674 -> [I] AudioTypes.h : 128 - in: sample_rate: 22000 / channels: 1 / bits_per_sample: 16
10:19:09.674 -> [I] AudioTypes.h : 128 - out: sample_rate: 22000 / channels: 1 / bits_per_sample: 16
10:19:09.674 -> [I] AudioTypes.h : 128 -  sample_rate: 22000 / channels: 1 / bits_per_sample: 16
10:19:09.705 -> [I] I2SConfigESP32V1.h : 73 - rx/tx mode: TX_MODE
10:19:09.674 -> [I] AudioTypes.h : 128 -  sample_rate: 22000 / channels: 1 / bits_per_sample: 16
10:19:09.705 -> [I] I2SConfigESP32V1.h : 73 - rx/tx mode: TX_MODE
10:19:09.705 -> [I] I2SConfigESP32V1.h : 74 - port_no: 0
10:19:09.705 -> [I] I2SConfigESP32V1.h : 75 - is_master: Master
10:19:09.705 -> [I] I2SConfigESP32V1.h : 76 - sample rate: 22000
10:19:09.705 -> [I] I2SConfigESP32V1.h : 77 - bits per sample: 16
10:19:09.705 -> [I] I2SConfigESP32V1.h : 78 - number of channels: 1
10:19:09.705 -> [I] I2SConfigESP32V1.h : 79 - signal_type: Digital
10:19:09.705 -> [I] I2SConfigESP32V1.h : 81 - i2s_format: I2S_STD_FORMAT
10:19:09.737 -> [I] I2SConfigESP32V1.h : 84 - use_apll: true
10:19:09.737 -> [I] I2SConfigESP32V1.h : 90 - pin_mck: 0
10:19:09.737 -> [I] I2SConfigESP32V1.h : 92 - pin_bck: 27
10:19:09.737 -> [I] I2SConfigESP32V1.h : 94 - pin_ws: 25
10:19:09.737 -> [I] I2SConfigESP32V1.h : 96 - pin_data: 26
10:19:09.737 -> [I] I2SESP32V1.h : 214 - tx: 26, rx: -1
10:19:09.737 -> [W] I2SESP32V1.h : 184 - Invalid channel_format: 3 (using 1)
10:19:09.737 -> [I] StreamCopy.h : 158 - StreamCopy::copy out 128 -> 128 -> 128 bytes - in 1 hops
10:19:09.769 -> [I] StreamCopy.h : 158 - StreamCopy::copy out 128 -> 128 -> 128 bytes - in 1 hops
10:19:09.769 -> [I] StreamCopy.h : 158 - StreamCopy::copy out 128 -> 128 -> 128 bytes - in 1 hops
10:19:09.801 -> [I] StreamCopy.h : 158 - StreamCopy::copy out 128 -> 128 -> 128 bytes - in 1 hops
10:19:09.801 -> [I] StreamCopy.h : 158 - StreamCopy::copy out 128 -> 128 -> 128 bytes - in 1 hops
10:19:09.801 -> [I] StreamCopy.h : 158 - StreamCopy::copy out 128 -> 128 -> 128 bytes - in 1 hops
...

You might have selected the wrong board or driver. Also double check if you get your board working in Arduino w/o my library first

peterburk commented 2 months ago

The same "Incorrect size of core dump image: -4" error shows when installing other sketches from other libraries, such as MinimalDiagnostics.ino.

What is the correct board and driver to use for the ESP32-A1S?

pschatzmann commented 2 months ago

I am using "ESP32 Dev Module"

peterburk commented 2 months ago

I got it working! The "Incorrect size of core dump" message still shows, but a sine wave is generated and comes out of the DAC. Here's the sketch:

#include <Arduino.h>
#include "AudioTools.h"
#include "AudioLibs/I2SCodecStream.h"
#include <Wire.h>

// I2C
#define SDAPIN 33        // I2C Data,  Adafruit ESP32 S3 3, Sparkfun Thing Plus C 23
#define SCLPIN 32        // I2C Clock, Adafruit ESP32 S3 4, Sparkfun Thing Plus C 22
#define I2CSPEED 100000 // Clock Rate

#define ES8388_ADDR 0x10

#define ACK_CHECK_EN 0x1

/* ES8388 register */
#define ES8388_CONTROL1 0x00
#define ES8388_CONTROL2 0x01
#define ES8388_CHIPPOWER 0x02
#define ES8388_ADCPOWER 0x03
#define ES8388_DACPOWER 0x04
#define ES8388_CHIPLOPOW1 0x05
#define ES8388_CHIPLOPOW2 0x06
#define ES8388_ANAVOLMANAG 0x07
#define ES8388_MASTERMODE 0x08

/* ADC */
#define ES8388_ADCCONTROL1 0x09
#define ES8388_ADCCONTROL2 0x0a
#define ES8388_ADCCONTROL3 0x0b
#define ES8388_ADCCONTROL4 0x0c
#define ES8388_ADCCONTROL5 0x0d
#define ES8388_ADCCONTROL6 0x0e
#define ES8388_ADCCONTROL7 0x0f
#define ES8388_ADCCONTROL8 0x10
#define ES8388_ADCCONTROL9 0x11
#define ES8388_ADCCONTROL10 0x12
#define ES8388_ADCCONTROL11 0x13
#define ES8388_ADCCONTROL12 0x14
#define ES8388_ADCCONTROL13 0x15
#define ES8388_ADCCONTROL14 0x16

/* DAC */
#define ES8388_DACCONTROL1 0x17
#define ES8388_DACCONTROL2 0x18
#define ES8388_DACCONTROL3 0x19
#define ES8388_DACCONTROL4 0x1a
#define ES8388_DACCONTROL5 0x1b
#define ES8388_DACCONTROL6 0x1c
#define ES8388_DACCONTROL7 0x1d
#define ES8388_DACCONTROL8 0x1e
#define ES8388_DACCONTROL9 0x1f
#define ES8388_DACCONTROL10 0x20
#define ES8388_DACCONTROL11 0x21
#define ES8388_DACCONTROL12 0x22
#define ES8388_DACCONTROL13 0x23
#define ES8388_DACCONTROL14 0x24
#define ES8388_DACCONTROL15 0x25
#define ES8388_DACCONTROL16 0x26
#define ES8388_DACCONTROL17 0x27
#define ES8388_DACCONTROL18 0x28
#define ES8388_DACCONTROL19 0x29
#define ES8388_DACCONTROL20 0x2a
#define ES8388_DACCONTROL21 0x2b
#define ES8388_DACCONTROL22 0x2c
#define ES8388_DACCONTROL23 0x2d
#define ES8388_DACCONTROL24 0x2e
#define ES8388_DACCONTROL25 0x2f
#define ES8388_DACCONTROL26 0x30
#define ES8388_DACCONTROL27 0x31
#define ES8388_DACCONTROL28 0x32
#define ES8388_DACCONTROL29 0x33
#define ES8388_DACCONTROL30 0x34

// I2S, your configuration for the ES8311 board
#define MCLKPIN 0 // Master Clock
#define BCLKPIN 27 // Bit Clock
#define WSPIN 25    // Word select
#define DOPIN 26    // This is connected to DI on ES8311 (MISO)
#define DIPIN 35    // This is connected to DO on ES8311 (MOSI)

// AudioDriverES8311Class es8311(ES8311ADDR);
AudioInfo audio_info(44200, 2, 16);                    // sampling rate, # channels, bit depth
SineWaveGenerator<int16_t> sine_wave(32000);           // amplitude
GeneratedSoundStream<int16_t> sound_stream(sine_wave); // sound generator
DriverPins my_pins;                                    // board pins
AudioBoard audio_board(AudioDriverES8388, my_pins);    // audio board
I2SCodecStream i2s_out_stream(audio_board);            // i2s coded
StreamCopy copier(i2s_out_stream, sound_stream);       // stream copy sound generator to i2s codec

void writeReg(uint8_t reg_add, uint8_t data)
{
  Wire.beginTransmission(ES8388_ADDR);
  Wire.write(reg_add);      // sends MSB
  Wire.write(data);       // sends LSB
  Wire.endTransmission(true);
  delay(1);
}

void setup()
{
    // Setup logging
    Serial.begin(115200);
    Wire.begin(SDAPIN, SCLPIN);

    AudioLogger::instance().begin(Serial, AudioLogger::Warning);
    LOGLEVEL_AUDIODRIVER = AudioDriverWarning;
    delay(3000);

    Serial.println("Setup starting...");

    Serial.println("I2C pin ...");
    my_pins.addI2C(PinFunction::CODEC, SCLPIN, SDAPIN, ES8388_ADDR, I2CSPEED, Wire, true);

  /* mute DAC during setup, power up all systems, slave mode */
  writeReg(ES8388_DACCONTROL3, 0x04);
  writeReg(ES8388_CONTROL2, 0x50);
  writeReg(ES8388_CHIPPOWER, 0x00);
  writeReg(ES8388_MASTERMODE, 0x00);

  /* power up DAC and enable LOUT1+2 / ROUT1+2, ADC sample rate = DAC sample rate */
  writeReg(ES8388_DACPOWER, 0x3e);
  writeReg(ES8388_CONTROL1, 0x12);

  /* DAC I2S setup: 16 bit word length, I2S format; MCLK / Fs = 256*/
  writeReg(ES8388_DACCONTROL1, 0x18);
  writeReg(ES8388_DACCONTROL2, 0x02);

  /* DAC to output route mixer configuration: ADC MIX TO OUTPUT */
  writeReg(ES8388_DACCONTROL16, 0x1B);
  writeReg(ES8388_DACCONTROL17, 0x90);
//writeReg(ES8388_DACCONTROL17, 0xD0);
  writeReg(ES8388_DACCONTROL20, 0x90);
//writeReg(ES8388_DACCONTROL20, 0xD0);

  /* DAC and ADC use same LRCK, enable MCLK input; output resistance setup */
  writeReg(ES8388_DACCONTROL21, 0x80);
  writeReg(ES8388_DACCONTROL23, 0x00);

//   /* DAC volume control: 0dB (maximum, unattented)  */
    //   writeReg(ES8388_DACCONTROL5, 0x00);
    //   writeReg(ES8388_DACCONTROL4, 0x00);
      writeReg(ES8388_DACCONTROL5, 0x30);
      writeReg(ES8388_DACCONTROL4, 0x30);

  /* power down ADC while configuring; volume: +9dB for both channels */
  writeReg(ES8388_ADCPOWER, 0xff);
  writeReg(ES8388_ADCCONTROL1, 0x88);  // +24db

  /* select LINPUT2 / RINPUT2 as ADC input; stereo; 16 bit word length, format right-justified, MCLK / Fs = 256 */
  writeReg(ES8388_ADCCONTROL2, 0xf0);  // 50
  writeReg(ES8388_ADCCONTROL3, 0x80);  // 00
  writeReg(ES8388_ADCCONTROL4, 0x0e);
  writeReg(ES8388_ADCCONTROL5, 0x02);

  /* set ADC volume */
  writeReg(ES8388_ADCCONTROL8, 0x20);
  writeReg(ES8388_ADCCONTROL9, 0x20);

  /* set LOUT1 / ROUT1 volume: 0dB (unattenuated) */
//   writeReg(ES8388_DACCONTROL24, 0x1e);
//   writeReg(ES8388_DACCONTROL25, 0x1e);
  writeReg(ES8388_DACCONTROL24, 0x00);
  writeReg(ES8388_DACCONTROL25, 0x00);

  /* set LOUT2 / ROUT2 volume: 0dB (unattenuated) */
//   writeReg(ES8388_DACCONTROL26, 0x1e);
//   writeReg(ES8388_DACCONTROL27, 0x1e);
        writeReg(ES8388_DACCONTROL26, 0x10);
        writeReg(ES8388_DACCONTROL27, 0x10);

  /* power up and enable DAC; power up ADC (no MIC bias) */
  writeReg(ES8388_DACPOWER, 0x3c);
  writeReg(ES8388_DACCONTROL3, 0x00);
//   writeReg(ES8388_ADCPOWER, 0x00);

    Serial.println("I2S pin ...");
    my_pins.addI2S(PinFunction::CODEC, MCLKPIN, BCLKPIN, WSPIN, DOPIN, DIPIN);
    my_pins.addPin(PinFunction::MCLK_SOURCE, MCLKPIN, PinLogic::Output);

    Serial.println("Pins begin ...");
    // my_pins.begin();

    Serial.println("Board begin ...");
    audio_board.begin();

    Serial.println("I2S begin ...");
    auto i2s_config = i2s_out_stream.defaultConfig();
    i2s_config.copyFrom(audio_info);
    i2s_out_stream.begin(i2s_config); // this should apply I2C and I2S configuration

    // Setup sine wave
    Serial.println("Sine wave begin...");
    sine_wave.begin(audio_info, N_B4); // 493.88 Hz

    Serial.println("Setup completed ...");
}

// Arduino loop - copy sound to out
void loop()
{
    copier.copy();
}

and the serial console:

ets Jul 29 2019 12:21:46

rst:0x1 (POWERON_RESET),boot:0x1f (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:1
load:0x3fff0030,len:1448
load:0x40078000,len:14844
ho 0 tail 12 room 4
load:0x40080400,len:4
load:0x40080404,len:3356
entry 0x4008059c
E (420) esp_cor⸮Eյ⸮}⸮⸮⸮͡⸮ Incorrect size of core dump image: -4
Setup starting...
I2C pin ...
I2S pin ...
Pins begin ...
Board begin ...
I2S begin ...
Sine wave begin...
Setup completed ...
pschatzmann commented 2 months ago

Why so complicated ?

This short sketch should work as well

If it doesn't activate the logging and compare the used pins with yours

peterburk commented 2 months ago

The streams-generator-audiokit sketch did work as well! And so did the streams-synth-audiokit :)

Now I'm trying to get effects to work, with a goal of being able to add reverb to audio from the line in port.

I've based the following on streams-audiokit-effects-audiokit, but the output just sounds like the original input.

/**
 * @file streams-i2s-i2s.ino
 * @brief Copy audio from I2S to I2S  - I2S uses 1 i2s port
 * @author Phil Schatzmann
 * @copyright GPLv3
 */

#include "AudioTools.h"
#include "es8388.h"
#include "Wire.h"

//uint16_t sample_rate=40000;
//uint16_t channels = 2;
// Audio Format
const int sample_rate = 44100;
const int channels = 1;

uint16_t bits_per_sample = 16; // or try with 24 or 32
I2SStream i2s;

FilteredStream<int16_t, float> filtered(i2s, channels);  // Defiles the filter as BaseConverter
AudioEffectStream effects(filtered); // input from kit
StreamCopy copier(filtered, i2s); // copies sound into i2s (both from kit to filtered or filered to kit are supported)

// StreamCopy copier(i2s, i2s); // copies sound into i2s

// Effects control input
float volumeControl = 0.1;
int16_t clipThreashold = 6000;
float fuzzEffectValue = 32200;
int16_t fuzzMaxValue = 32200;
int16_t tremoloDuration = 2000;
float tremoloDepth = 100;

// Effects
Boost boost(volumeControl);
Distortion distortion(clipThreashold);
Fuzz fuzz(fuzzEffectValue);
Tremolo tremolo(tremoloDuration, tremoloDepth, sample_rate);

// Update values in effects
void updateValues(){
  // update values in controls
  boost.setVolume(volumeControl);
  boost.setActive(volumeControl>0);
  distortion.setClipThreashold(clipThreashold);
  distortion.setActive(clipThreashold>0);
  fuzz.setFuzzEffectValue(fuzzEffectValue);
  fuzz.setMaxOut(fuzzMaxValue);
  fuzz.setActive(fuzzEffectValue>0);
  tremolo.setDepth(tremoloDepth);
  tremolo.setDuration(tremoloDuration);
  tremolo.setActive(tremoloDuration>0);
}

// Arduino Setup
void setup(void) {  
  // Open Serial 
  Serial.begin(115200);
  // change to Warning to improve the quality
  AudioLogger::instance().begin(Serial, AudioLogger::Error); 

  // Input/Output Modes
  es_dac_output_t output = (es_dac_output_t) ( DAC_OUTPUT_LOUT1 | DAC_OUTPUT_LOUT2 | DAC_OUTPUT_ROUT1 | DAC_OUTPUT_ROUT2 );
  es_adc_input_t input = ADC_INPUT_LINPUT2_RINPUT2;
  //  es_adc_input_t input = ADC_INPUT_LINPUT1_RINPUT1;

  TwoWire wire(0);
  wire.setPins( 33, 32 );

  es8388 codec;
  codec.begin( &wire );
  codec.config( bits_per_sample, output, input, 90 );

  // start I2S in
  Serial.println("starting I2S...");
  auto config = i2s.defaultConfig(RXTX_MODE);
  config.sample_rate = sample_rate; 
  config.bits_per_sample = bits_per_sample; 
  config.channels = 2;
  config.i2s_format = I2S_STD_FORMAT;
  config.pin_ws = 25;
  config.pin_bck = 27;
  config.pin_data = 26;
  config.pin_data_rx = 35;
  config.pin_mck = 0;

  // setup effects
  effects.addEffect(boost);
  effects.addEffect(distortion);
  effects.addEffect(fuzz);
  effects.addEffect(tremolo);
  effects.begin(config);
  updateValues();

  i2s.begin(config);

  Serial.println("I2S started...");
}

// Arduino loop - copy sound to out 
void loop() {
  copier.copy();
}

When I tried adding freeverb, I got the following error:

/Users/peter/Documents/Arduino/libraries/es8388/examples/streams-i2s-i2s/streams-i2s-i2s.ino: In function 'void setup()':
/Users/peter/Documents/Arduino/libraries/es8388/examples/streams-i2s-i2s/streams-i2s-i2s.ino:103:20: error: no matching function for call to 'audio_tools::AudioEffectStreamT<short int>::addEffect(stk::FreeVerb&)'
  103 |   effects.addEffect(freeverb);
      |   ~~~~~~~~~~~~~~~~~^~~~~~~~~~
In file included from /Users/peter/Documents/Arduino/libraries/arduino-audio-tools/src/AudioTools.h:92,
                 from /Users/peter/Documents/Arduino/libraries/es8388/examples/streams-i2s-i2s/streams-i2s-i2s.ino:8:
/Users/peter/Documents/Arduino/libraries/arduino-audio-tools/src/AudioEffects/AudioEffects.h:346:10: note: candidate: 'void audio_tools::AudioEffectStreamT<T>::addEffect(audio_tools::AudioEffect&) [with T = short int]'
  346 |     void addEffect(AudioEffect &effect){
      |          ^~~~~~~~~
/Users/peter/Documents/Arduino/libraries/arduino-audio-tools/src/AudioEffects/AudioEffects.h:346:33: note:   no known conversion for argument 1 from 'stk::FreeVerb' to 'audio_tools::AudioEffect&'
  346 |     void addEffect(AudioEffect &effect){
      |                    ~~~~~~~~~~~~~^~~~~~
/Users/peter/Documents/Arduino/libraries/arduino-audio-tools/src/AudioEffects/AudioEffects.h:352:10: note: candidate: 'void audio_tools::AudioEffectStreamT<T>::addEffect(audio_tools::AudioEffect*) [with T = short int]'
  352 |     void addEffect(AudioEffect *effect){
      |          ^~~~~~~~~
/Users/peter/Documents/Arduino/libraries/arduino-audio-tools/src/AudioEffects/AudioEffects.h:352:33: note:   no known conversion for argument 1 from 'stk::FreeVerb' to 'audio_tools::AudioEffect*'
  352 |     void addEffect(AudioEffect *effect){
      |                    ~~~~~~~~~~~~~^~~~~~

exit status 1

Compilation error: no matching function for call to 'audio_tools::AudioEffectStreamT<short int>::addEffect(stk::FreeVerb&)'

This might not matter though, because I read the Limitations: "The Effects work only on one channel, so if you provide 2 channels, the are combined before applying the effects and then are replicated to give the correct channels as output"

I was hoping to create a stereo reverb effect, but it may only work with mono channels.

pschatzmann commented 2 months ago

Look at the error message: you did not provide an AudioEffect subclass!