Hi
In using the setup in the title, I’m trying to manipulate the ADC values coming to the ESP from the ADC in the Audio Codec, but I haven’t been able to make sense of the numbers in the array returned (e.g. sBuffer[3]) or find the i2s_read and i2s_write functions in the .cpp file to try to figure it out better. Any help would be greatly appreciated!
Thanks!
Details:
I’m using the ESP32 development board with the WM8906 and things are working great. I’ve run many of the examples, and have settled on Example 8: I2S Passthrough as the baseline for what I want to do: Digital Signal Processing on the audio signal read by the ADC on the CODEC, sent to the ESP32 over I2S, some manipulation, and then sending it back over I2S to the CODEC for output by the DAC.
I have been struggling to figure out how to get the numerical values from the buffer without luck. I thought I understood arrays, but I’m not getting it. I’ve been using the Sparkfun logic analyzer to decode the I2S data, and there I see the equivalent of signed 16 bit integers changing as expected when driven by a sine wave from a function generator (+/- 0.3 volts at 300 Hz, corresponding to about +/-6860).
However, when I try to look at the values in sBufferr from the function call below, I don’t get numbers I can use.
#define bufferLen 64
int16_t sBuffer[bufferLen];
esp_err_t result = i2s_read(I2S_PORT, &sBuffer, bufferLen, &bytesIn, portMAX_DELAY);
or set the buffer values to known values before the call to:
esp_err_t result_w = i2s_write(I2S_PORT, &sBuffer, bytesIn, &bytesOut, portMAX_DELAY);
I’m not having much luck. For example, if I read the buffer once (say in setup) and print the results using
int32_t value;
…
value=sBuffer[ii];
Serial.println(value,DEC);
Also tried masking out the 16 right most bits and casting to uint16 and int16
uint16_t value_uint16;
int16_t value_int16;
value_uint16=sBuffer[ii]& 0xFFFF;
value_int16=(int16_t)value_uint16;
While driving the left channel only, I get values like 29989, 117, -2878,118,-2967 … in the first 32 slots of the 64 element long buffer, and zeros for the last 32 which seems promising. But these aren’t the expected values for a relatively low frequency sine wave (300 Hz) or the values I’m capturing from the I2S bus with the logic analyzer.
When I tried filling the buffer before the write command with the integers 0 through 63 (sBuffer[i]= value, every other value shows up on the bus analyzer, which seems encouraging, but I haven’t been able to sort it out.
I’ve looked for the source code for i2s_read and i2s_write, without any luck (only the .h file declarations). If anyone knows where that is, I’d appreciate it.
I’ve attempted some different ways to access this array and done a fair bit of googling. I’m guessing that somehow is more levels of indirect addressing than I am understanding.
My goal is to work through the labs from the Prof Tretter’s University of Maryland old digital signal processing for communications lab course and lab text book which is really great material (https://user.eng.umd.edu/~tretter/). I’ve made some progress on another processor, but I really want to do it with an audio CODEC and this seems like exactly the right thing.