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 :

Code: Untitled.cpp Select all


#include <driver/i2s.h>
#include<cmath>
#include <driver/dac.h>

#define I2S_WS 15
#define I2S_SD 32
#define I2S_SCK 14

#define I2S_PORT I2S_NUM_0

void setup() {
Serial.begin(115200);
Serial.println("Setup I2S ...");

delay(1000);
i2s_install();
i2s_setpin();
i2s_start(I2S_PORT);
delay(500);
}

void loop() {
int16_t sample = 0;
int bytes = i2s_pop_sample(I2S_PORT, (char*)&sample, portMAX_DELAY);
if(bytes > 0){
int partieEntiere =(int)floor((sample+3276-1)/256); // convert to a 8-bit integer
Serial.println(partieEntiere);
dacWrite(25,partieEntiere); //send to the DAC
}
}
// config the i2s protocol
void i2s_install(){
const i2s_config_t i2s_config = {
.mode = i2s_mode_t(I2S_MODE_MASTER | I2S_MODE_RX),
.sample_rate = 44100,
.bits_per_sample = I2S_BITS_PER_SAMPLE_16BIT,
.channel_format = I2S_CHANNEL_FMT_ONLY_LEFT,
.communication_format = i2s_comm_format_t(I2S_COMM_FORMAT_I2S | I2S_COMM_FORMAT_I2S_MSB),
.intr_alloc_flags = 0, // default interrupt priority
.dma_buf_count = 8,
.dma_buf_len = 64,
.use_apll = false
};

i2s_driver_install(I2S_PORT, &i2s_config, 0, NULL);
}

void i2s_setpin(){
const i2s_pin_config_t pin_config = {
.bck_io_num = I2S_SCK,
.ws_io_num = I2S_WS,
.data_out_num = -1,
.data_in_num = I2S_SD
};

i2s_set_pin(I2S_PORT, &pin_config);
}
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 2841 times

Who is online

Users browsing this forum: PetalBot, Semrush [Bot] and 4 guests