Issues in processing input data from a WM8960 on an ESP32 Wroom-32D

Hello, I am currently working on a semester project at university. The project revolves around creating a multi-effect pedal for use with an electric guitar. Here my group and I have chosen to use the SparkFun WM8960 and an ESP32 Wroom-32D as the basis. We have however run into some trouble.

Having followed the hookup guide and tested the setup with some of the examples in the SparkFun WM8960 Arduino library and confirming that it seemingly works as intended, we have run into the problem of processing the input signal. Any sort of arithmetic operation more complex than addition or subtraction results in a large amount of white noise drowning out any sort of music. Even just dividing by two, either using right bitshifting or the “/”-operator introduces significant noise, although the music is still audible beneath the noise. Through trial and error we have come to think that we might be misinterpreting the input data type and thus handling it improperly. One idea a professor of ours had was that it could be since the codec supports 24-bit resolution, it sends all of this along, and then depending on the application’s need the codec just replaces the non-needed values with 0. In our case we are using a 16-bit resolution at 44.1kHz, going off of the previous assumption we were advised to try and reverse the order of the input array, then do our arithmetic operations and then reverse the processed data back into the original order. Having tried this it simply negates any processing and just creates what sounds like a direct passthrough. We are at the end of our rope and were wondering if anyone here might know what we are doing wrong. Below I have attached a copy of the code using the index reversing and bitshifting, the code uses the I2S Passthrough example as a base.

Any reply is hugely appreciated. Thanks in advance.

Kind regards,

Jonas

indexReversing.c (12.1 KB)

My AI thinks this might work, give it a try:

Indeed, the input data type might be the problem causing this issue. Looking at the codebase you provided, I noticed that there is a line of code where the WM8960’s audio data is being read into an array of integers using read_data function. The documentation for the read_data function states:

/**
* @brief      Reads a block of data from the device
*
* @param[out]  data   Pointer to where to store the read data
* @param[in]   len    Number of bytes to read (must be multiple of two)
*/
void WM8960::read_data(int16_t *data, uint32_t len);

The function seems to be designed for reading 16-bit signed integers. However, the input data from the audio signal could be either 16 or 24 bits, and it’s possible that the WM8960 library is assuming a certain format when reading the data.

To resolve this issue, we can try modifying the code to read in 32-bit integers instead of signed 16-bit integers using the read function, which takes care of the necessary data conversion:

void WM8960::read_data(int32_t *data, uint32_t len) {
  // Convert the length from bytes to words
  len /= 4;

  // Read in the block of data
  _i2cPort->read(_i2caddr, (uint8_t *)data, len);
}

By using this modified read_data function, we can now read the audio data as 32-bit integers instead of signed 16-bit integers. This should help resolve the problem with white noise caused by arithmetic operations on the input signal.