Bonjour,
Quelqu'un peut m'aider à résoudre ce code ?
De plus, si quelqu'un peut m'aider pour mon projet complet avec des connaissance sur l'esp32 je suis preneur !
Je souhaite en effet programmer un esp32 lyrat v4.3 pour enregistrer l'audio d'un casque via la prise jack (AUX IN) sur une carte SD
merci
Voici le code (problème aux lignes 74 et 75 pour le WAVheader avec un message d'erreur : 'WAVheader' was not declared in this scope
`#include <SD.h>
#include <driver/i2s.h>
#include "wav_header.h" // Assumes a wav_header.h file is available for generating WAV headers
// Pin definitions for LyraT v4.3 SD card (adjust based on your setup if needed)
#define SD_CS_PIN 13 // CS pin for SD card
// I2S configuration parameters
#define SAMPLE_RATE 44100 // 44.1kHz sample rate
#define BIT_DEPTH 16 // 16-bit audio
#define CHANNELS 2 // Stereo audio
// Recording settings
const int RECORD_TIME_SECONDS = 10; // Record duration in seconds
unsigned long recordStartTime;
// File for saving audio data
File audioFile;
// I2S setup for LyraT
void setupI2S() {
// I2S configuration for audio input
i2s_config_t i2s_config = {
.mode = (i2s_mode_t)(I2S_MODE_MASTER | I2S_MODE_RX), // Only RX (recording) mode
.sample_rate = SAMPLE_RATE,
.bits_per_sample = I2S_BITS_PER_SAMPLE_16BIT,
.channel_format = I2S_CHANNEL_FMT_RIGHT_LEFT, // Stereo
.communication_format = I2S_COMM_FORMAT_I2S,
.intr_alloc_flags = ESP_INTR_FLAG_LEVEL1,
.dma_buf_count = 8,
.dma_buf_len = 1024,
.use_apll = false,
.tx_desc_auto_clear = false,
.fixed_mclk = 0
};
// I2S pin configuration for LyraT v4.3
i2s_pin_config_t pin_config = {
.bck_io_num = 27,
.ws_io_num = 26,
.data_out_num = -1, // Not used for RX mode
.data_in_num = 35
};
// Install and configure I2S driver
i2s_driver_install(I2S_NUM_0, &i2s_config, 0, NULL);
i2s_set_pin(I2S_NUM_0, &pin_config);
i2s_set_clk(I2S_NUM_0, SAMPLE_RATE, I2S_BITS_PER_SAMPLE_16BIT, I2S_CHANNEL_STEREO);
}
void setup() {
Serial.begin(115200);
while (!Serial)
; // Wait for Serial to connect
// Initialize SD card
if (!SD.begin(SD_CS_PIN)) {
Serial.println("SD Card mount failed!");
while (1)
;
}
Serial.println("SD Card mounted.");
// Initialize I2S for recording
setupI2S();
Serial.println("I2S initialized.");
// Open file for recording and write WAV header
audioFile = SD.open("/recording.wav", FILE_WRITE);
if (!audioFile) {
Serial.println("Failed to open file for writing.");
while (1)
;
}
// Write the WAV header
WAVheader header(SAMPLE_RATE, BIT_DEPTH, CHANNELS);
audioFile.write(header.getHeader(), header.getHeaderSize());
// Start recording
Serial.println("Recording...");
recordStartTime = millis();
recordAudio(audioFile, RECORD_TIME_SECONDS);
audioFile.close();
Serial.println("Recording stopped.");
}
void loop() {
// Empty loop as recording is handled in setup for this example
}
void recordAudio(File &file, int seconds) {
uint8_t audioBuffer[512];
size_t bytesRead;
while (millis() - recordStartTime < seconds * 1000) {
// Read audio data from I2S and write to SD card
i2s_read(I2S_NUM_0, audioBuffer, sizeof(audioBuffer), &bytesRead, portMAX_DELAY);
if (bytesRead > 0) {
file.write(audioBuffer, bytesRead);
}
delay(10); // Optional small delay to yield processing time
}
}
`