You've already forked M5Module-Audio
mirror of
https://github.com/m5stack/M5Module-Audio.git
synced 2026-05-20 11:37:50 -07:00
70 lines
1.8 KiB
Arduino
70 lines
1.8 KiB
Arduino
/*
|
|
* SPDX-FileCopyrightText: 2026 M5Stack Technology CO LTD
|
|
*
|
|
* SPDX-License-Identifier: MIT
|
|
*
|
|
* @Hardwares: M5Core/M5Core2/M5CoreS3 + Module Audio
|
|
* @Dependent Library:
|
|
* M5Unified: https://github.com/m5stack/M5Unified
|
|
* Module Audio: https://github.com/m5stack/M5Module-Audio
|
|
*
|
|
* @Note: If use CoreS3, please switch to the B Pins.
|
|
*/
|
|
|
|
#include "M5Unified.h"
|
|
#include "M5Module_Audio.h"
|
|
|
|
M5ModuleAudio device;
|
|
|
|
static uint8_t audio_buf[4096];
|
|
|
|
void setup()
|
|
{
|
|
delay(1000);
|
|
auto cfg = M5.config();
|
|
cfg.serial_baudrate = 115200;
|
|
M5.begin(cfg);
|
|
|
|
if (!device.begin(Wire)) {
|
|
while (1) {
|
|
Serial.println("Module Audio not found");
|
|
delay(1000);
|
|
}
|
|
}
|
|
device.setHPMode(AUDIO_HPMODE_NATIONAL);
|
|
device.setMICStatus(AUDIO_MIC_OPEN);
|
|
device.setRGBBrightness(100);
|
|
Serial.printf("getHPMode:%d\n", device.getHPMode());
|
|
Serial.printf("getMICStatus:%d\n", device.getMICStatus());
|
|
for (int i = 0; i <= 2; i++) {
|
|
device.setRGBLED(i, 0xFFFFFF);
|
|
}
|
|
Serial.println("Read Reg ES8388 :");
|
|
uint8_t *reg = device.readAllReg();
|
|
if (reg != nullptr) {
|
|
for (uint8_t i = 0; i < 53; i++) {
|
|
Serial.printf("Reg-%02d = 0x%02x\r\n", i, reg[i]);
|
|
}
|
|
}
|
|
device.setMicInputLine(ADC_INPUT_LINPUT2_RINPUT2);
|
|
device.setMicGain(MIC_GAIN_12DB);
|
|
device.setMicAdcVolume(80);
|
|
device.setSpeakerVolume(50);
|
|
device.setSpeakerOutput(DAC_OUTPUT_OUT1);
|
|
device.setBitsSample(ES_MODULE_ADC_DAC, BIT_LENGTH_16BITS);
|
|
device.setSampleRate(SAMPLE_RATE_32K);
|
|
}
|
|
|
|
void loop()
|
|
{
|
|
if (!device.record(audio_buf, sizeof(audio_buf))) {
|
|
Serial.println("record failed");
|
|
return;
|
|
}
|
|
|
|
if (!device.play(audio_buf, sizeof(audio_buf))) {
|
|
Serial.println("play failed");
|
|
return;
|
|
}
|
|
}
|