voice amplifier

boooleen
Posts: 3
Joined: Thu May 12, 2022 7:43 pm

voice amplifier

Postby boooleen » Thu May 12, 2022 7:47 pm

Hello !
My project is to make a voice amplifier with a mic INMP441 and a speaker on a esp32 card.
So I use the i2s protocol to collect the data from the mic and I convert the data to a 8-bits integer to send it to the DAC and then send it to the speaker (with a PAM8403 between).
The problem is that I can't transmit the sound from my microphone correctly to the speaker, there is only an unpleasant noise coming out of it.
If you have any suggestion, it would really help me.
I join my code there :
  1. #include <driver/i2s.h>
  2. #include<cmath>
  3. #include <driver/dac.h>
  4.  
  5. #define I2S_WS 15        
  6. #define I2S_SD 32
  7. #define I2S_SCK 14
  8.  
  9. #define I2S_PORT I2S_NUM_0
  10.  
  11. void setup() {
  12.   Serial.begin(115200);
  13.   Serial.println("Setup I2S ...");
  14.  
  15.   delay(1000);
  16.   i2s_install();
  17.   i2s_setpin();
  18.   i2s_start(I2S_PORT);
  19.   delay(500);
  20. }
  21.  
  22. void loop() {
  23.   int16_t sample = 0;
  24.   int bytes = i2s_pop_sample(I2S_PORT, (char*)&sample, portMAX_DELAY);
  25.   if(bytes > 0){
  26.     int partieEntiere =(int)floor((sample+3276-1)/256);  // convert to a 8-bit integer
  27.     Serial.println(partieEntiere);
  28.     dacWrite(25,partieEntiere);  //send to the DAC
  29.   }
  30. }
  31. // config the i2s protocol
  32. void i2s_install(){
  33.   const i2s_config_t i2s_config = {
  34.     .mode = i2s_mode_t(I2S_MODE_MASTER | I2S_MODE_RX),
  35.     .sample_rate = 44100,
  36.     .bits_per_sample = I2S_BITS_PER_SAMPLE_16BIT,
  37.     .channel_format = I2S_CHANNEL_FMT_ONLY_LEFT,
  38.     .communication_format = i2s_comm_format_t(I2S_COMM_FORMAT_I2S | I2S_COMM_FORMAT_I2S_MSB),
  39.     .intr_alloc_flags = 0, // default interrupt priority
  40.     .dma_buf_count = 8,
  41.     .dma_buf_len = 64,
  42.     .use_apll = false
  43.   };
  44.  
  45.   i2s_driver_install(I2S_PORT, &i2s_config, 0, NULL);
  46. }
  47.  
  48. void i2s_setpin(){
  49.   const i2s_pin_config_t pin_config = {
  50.     .bck_io_num = I2S_SCK,
  51.     .ws_io_num = I2S_WS,
  52.     .data_out_num = -1,
  53.     .data_in_num = I2S_SD
  54.   };
  55.  
  56.   i2s_set_pin(I2S_PORT, &pin_config);
  57. }
Last edited by boooleen on Fri May 13, 2022 10:05 am, edited 1 time in total.

rpiloverbd
Posts: 101
Joined: Tue Mar 22, 2022 5:23 am

Re: voice amplifier

Postby rpiloverbd » Fri May 13, 2022 7:04 am

I think your problem has nothing to do with your code. It is related to the hardware. I think you'd better post your schematic. If you have created a PCB, you can post your layout to the following forum:

https://www.pcbway.com/project/shareproject/

There are many expert designers hanging around that forum who may guide you in the right direction regarding your design.

boooleen
Posts: 3
Joined: Thu May 12, 2022 7:43 pm

Re: voice amplifier

Postby boooleen » Fri May 13, 2022 10:53 am

There is my shematic Image[/img]
Attachments
schema circuit.PNG
schema circuit.PNG (294.03 KiB) Viewed 2269 times

Who is online

Users browsing this forum: Baidu [Spider] and 42 guests