marcel-licence / ml_synth_basic_example

Arduino polyphonic synthesizer project (not a Moog) for ESP32 - STM32 - Teensy and more
GNU General Public License v3.0
33 stars 8 forks source link

Direct input #5

Open Leizar06001 opened 1 month ago

Leizar06001 commented 1 month ago

Hi, I was looking for a esp synth for a project and I got very interested in your work, but my goal was to be able to use the synth without any additional device. I really only need a small keyboard and I wanted to make it using the touch pins of the esp. I tried to understand how the midi functions are calling for notes on and off, as well as the wave shapes but I don't get it So I wonder, would it be doable to bypass the midi interface and use my own function to control the synth ?

Leizar06001 commented 4 weeks ago

So, I think I will change my approche, I am going to use an other ESP to manage the inputs and send data through MIDI serial, its probably easier.

Now I've found an issue with the board initializing, I have a esp32 audio kit v2.2 with a ES8388 codec. I tried to use "BOARD_ESP32_AUDIO_KIT_ES8388" but it doesnt work, and I believe there is a small mistake in the board file :

#define I2S_MCLK_PIN ES8388_PIN_MCLK
#define I2S_BCLK_PIN ES8388_PIN_SCLK
#define I2S_WCLK_PIN ES8388_PIN_LRCK
#define I2S_DOUT_PIN ES8388_PIN_DIN
#define I2S_DIN_PIN ES8388_PIN_DOUT

I2S_DOUT_PIN is mapped to the ES8388_PIN_DIN instead of DOUT, same for I2S_DIN_PIN

But that didnt solve everything, I found that "BOARD_ML_SYNTH_V2" works the best, I can also get the oled display to work using this board

Now, I dont have any sound output even though the display shows 'sound'. What made it work was to first upload another code from one project using this board like this example : https://github.com/pschatzmann/arduino-audio-tools/tree/main/examples/examples-audiokit/streams-synth-audiokit

Then if I upload the ml_synth, I get sound. I am investigating what's the issue but I don't have much knowledge with those audio board, I am thinking maybe the codec is not correctly setup at start, or it doesnt have the right parameters like the sound volume...

marcel-licence commented 4 weeks ago

Hi, I could imagine that the ES8388 was not initialized. Did you check the serial monitor output? There are a lot of different ESP32 audio kits with different pin settings. In the header file which is included when activating BOARD_ESP32_AUDIO_KIT_ES8388 are additional settings to select the I2S and I2C config which changes the pin settings. The serial monitor might help to identify the correct I2C setting and it seems I2S was set correctly.

Leizar06001 commented 4 weeks ago

Yes so I did set the right I2C and I2S, I can see the registers are written and then read, no error or warning, but then there is no sound output. For now, it's really ugly but I start the esp and initiate it with the other library, then reboot and use your code. I also managed to edit the midi config so that the second esp can send whatever command I need, and I really like the sound it makes, you did great on that ! Also the visualizer is sick

marcel-licence commented 3 weeks ago

What values are read from the ES8388? I worked often with the ESP32 Audio Kit and wonder that you have no sound. I really want to fix this in case there is a bug. I am happy that you like the sound =)

Leizar06001 commented 3 weeks ago

Connect to ES8388 codec... SDA: 33 SCL: 32 freq: 400000 0x00: 0x05 0x01: 0x40 AdcCh1! MixChAMPL! ES8388 setup finished! Reg 0x00 = 0x05 Reg 0x01 = 0x40 Reg 0x02 = 0x00 Reg 0x03 = 0x00 Reg 0x04 = 0x3c Reg 0x05 = 0x00 Reg 0x06 = 0x00 Reg 0x07 = 0x7c Reg 0x08 = 0x00 Reg 0x09 = 0x88 Reg 0x0a = 0x50 Reg 0x0b = 0x02 Reg 0x0c = 0x0c Reg 0x0d = 0x02 Reg 0x0e = 0x30 Reg 0x0f = 0x20 Reg 0x10 = 0x00 Reg 0x11 = 0x00 Reg 0x12 = 0x16 Reg 0x13 = 0xb0 Reg 0x14 = 0x32 Reg 0x15 = 0x06 Reg 0x16 = 0x00 Reg 0x17 = 0x18 Reg 0x18 = 0x02 Reg 0x19 = 0x22 Reg 0x1a = 0x00 Reg 0x1b = 0x02 Reg 0x1c = 0x08 Reg 0x1d = 0x00 Reg 0x1e = 0x1f Reg 0x1f = 0xf7 Reg 0x20 = 0xfd Reg 0x21 = 0xff Reg 0x22 = 0x1f Reg 0x23 = 0xf7 Reg 0x24 = 0xfd Reg 0x25 = 0xff Reg 0x26 = 0x1b Reg 0x27 = 0xb8 Reg 0x28 = 0x28 Reg 0x29 = 0x28 Reg 0x2a = 0xb8 Reg 0x2b = 0x80 Reg 0x2c = 0x00 Reg 0x2d = 0x00 Reg 0x2e = 0x1e Reg 0x2f = 0x1e Reg 0x30 = 0x1e Reg 0x31 = 0x1e Reg 0x32 = 0x00 Reg 0x33 = 0xaa Reg 0x34 = 0xaa I2S configured using following pins: BCLK,BCK: 27 WCLK,LCK: 25 DOUT: 26 DIN: 35

This is what I get using "BOARD_ESP32_AUDIO_KIT_ES8388" In this setup I am not getting any sound out, I've not been able to figure it out. Also the display doesn't work, it might be related to the i2c pins not being the same as the codec

marcel-licence commented 3 weeks ago

The I2C setup looked good so far. On some ESP32 Audio Kit's you need to use another I2C port for the OLED when it is not available at the pin headers. On some other the ES8388 uses I2C shared with the pin header.

To test the codec alone I would suggest to setup the #define OUTPUT_SAW_TEST in config.h to generate a test signal. I don't know if anything changed on the ESP32 audio kit in the meantime. I am sure we will figure it out

Leizar06001 commented 3 weeks ago

yes, so I tried to do something like

define ES8388_PIN_SDA 33

define ES8388_PIN_SCL 32

define I2C_ENABLED

define I2C_SDA 21

define I2C_SCL 22

But that wasnt enough for the display to work

For the sound,

define NOTE_ON_AFTER_SETUP or

define OUTPUT_SAW_TEST

didnt help, I could see the wave on the display but there was no sound I tried to understand how the other library was setting up the codec but no success yet

I also noticed some "poping" before and after playing a note, due to the audio chip going into some sort of sleep mode, atm I dont have much time to study the datasheet so I added some checks in the "Synth_Process" function so that when no voice is playing I fill the right and left channel with a constant value. Maybe you already fixed this and its only due to my codec not being correctly initialized

marcel-licence commented 3 weeks ago

Do you use the line out or the speaker connector? There is one digital signal which can turn on/off the amplifier on the PCB. I would expect that one LED is blinking on the PCB.

Leizar06001 commented 3 weeks ago

I use the line out One led blinking for midi signal, I use gpio 19