Project update 6 of 11
For this week’s update, we’ll take a closer look at the WM8978 audio codec and how to enable and use the additional inputs and outputs on the PICO DSP. We’ll also have a look at how to run your DSP code on either core 0 or core 1 of the ESP32.
The WM8978 includes a programmable gain amplifier at the input stage, to which both the microphone and line level inputs are routed. Once an instance of class WM8978 has been created and the codec has been initialized, the microphone, line level, and auxiliary inputs can be enabled by calling the
inputCfg function in the driver library:
wm8978.inputCfg(0,0,0); // select 1 to enable Mic/Line/Aux
The gain of the microphones, line, and auxiliary inputs can be adjusted:
wm8978.micGain(55); wm8978.lineinGain(0); wm8978.auxGain(0);
Note that the gain scale for the microphones is 0.75 dB per step and for the line and aux inputs, 3 dB per step.
The mono output (pin MN on the GPIO header) can be enabled with the function:
wm8978.monoOut(1); // select 1 to enable mono output
And you can put the codec into standby mode by calling:
wm8978.sleep(1); // select 1 to enable standby
If you have a look through the library, you’ll see other functions for enabling and configuring some of the other features of the codec, including setting the sample rate, the EQ at the input of the ADC, and the headphone/line out and speaker gain.
The ESP32 contains two I2S peripherals, one for each core. You can set the parameters in the I2S configuration to communicate with the codec using either core when the driver is installed:
i2s_driver_install(I2S_NUM_0, &i2s_config, 0, NULL); // I2S NUM_0 for Core O, NUM_1 for Core 1 i2s_set_pin(I2S_NUM_0, &pin_config); // I2S NUM_0 for Core O, NUM_1 for Core 1 PIN_FUNC_SELECT(PERIPHS_IO_MUX_GPIO0_U, FUNC_GPIO0_CLK_OUT1); // Selects pin GPIO0 for MCLK REG_WRITE(PIN_CTRL, 0xFFFFFFF0); // 0xFFFFFFF0 for Core 0, 0xFFFFFFFF for Core 1
This can be useful, for example, if your application requires a real-time web server and DSP processing, as processing tasks can be assigned to different cores using FreeRTOS.