s3-blob-utils/ADC/kitty-rx/main/usb_audio.c

48 lines
1.2 KiB
C

/*
* UAC2 microphone: feeds WiFi-received audio to USB host.
*
* The usb_device_uac component calls our input callback periodically
* (every CONFIG_UAC_MIC_INTERVAL_MS). We read from the shared ring buffer
* and hand it to the USB stack. If the ring buffer has insufficient data,
* we zero-fill the remainder (silence).
*/
#include <string.h>
#include "esp_log.h"
#include "usb_device_uac.h"
#include "usb_audio.h"
#define TAG "uac"
static ring_buf_t *s_rb;
static esp_err_t mic_input_cb(uint8_t *buf, size_t len, size_t *bytes_read, void *ctx)
{
size_t got = ring_buf_read(s_rb, buf, len);
if (got < len)
memset(buf + got, 0, len - got);
*bytes_read = len;
return ESP_OK;
}
void usb_audio_init(ring_buf_t *rb)
{
s_rb = rb;
uac_device_config_t cfg = {
.output_cb = NULL,
.input_cb = mic_input_cb,
.set_mute_cb = NULL,
.set_volume_cb = NULL,
.cb_ctx = NULL,
};
esp_err_t err = uac_device_init(&cfg);
if (err != ESP_OK) {
ESP_LOGE(TAG, "uac_device_init failed: %s", esp_err_to_name(err));
return;
}
ESP_LOGI(TAG, "UAC2 mic ready: 48kHz 16-bit stereo");
}