Skip to main content

Module audio

Module audio 

Source
Expand description

Audio: ES8311 codec on I²S0 (DMA channel 1) and the internal I²C bus, driving an NS4150B speaker amplifier and fed by an analog MEMS mic.

Two drivers share the hardware, one at a time:

  • AudioResources::recorder captures the microphone. Silent by construction: I²S TX is never set up (DOUT stays unconnected), and the codec’s DAC stays powered down, muted, at minimum volume and unclocked.
  • AudioResources::player plays audio through the speaker (or headphones, which mute the amplifier in hardware).

Both borrow the resources, so a program can record, drop the Recorder, then play, as often as it likes. They also share one 32 KB DMA stream buffer, since only one of them can exist at a time.

The codec takes its master clock from the I²S bit clock, so the clock must keep running whenever the codec is powered. Both drivers start the I²S stream before powering the codec; Recorder::shutdown and Player::shutdown power it down before stopping the stream. Plain drop stops the stream at once and leaves the codec for the next init to reset.

Samples are interleaved 16-bit stereo (L R L R …). The ES8311 has one ADC, so a recording carries the microphone in the left slot; the right slot mirrors it.

Structs§

AudioResources
I²S0, DMA channel 1 and the codec link pins.
MicGain
Analog microphone pre-amplifier gain, 0–30 dB in 3 dB steps. The codec adds a further +24 dB digital ADC_SCALE (register 0x16 reset value).
Player
Audio output.
Recorder
Microphone capture.
Volume
Digital volume: −95.5 dB to +32 dB in 0.5 dB steps (0xBF = 0 dB).

Enums§

Error
Audio errors.
SampleRate
Sample rates supported with BCLK-derived clocking and 16-bit stereo frames. These are the rates for which Espressif’s coefficient table has an MCLK = 32 × fs entry; lower rates are left out until verified.

Constants§

FRAME_BYTES
Bytes per stereo 16-bit frame.

Type Aliases§

Codec
The codec on the shared bus.