2024-08-21 11:21 PM
Hi all,
I reach out to you all to give some pointers or advice for me where to look into to solve this mystery.
I set up my Nuc-STM32F439ZI eval board i2s peripheral to play my audio sine wav file.
I used Audacity to generate 13KHz sine wave audio file with 48KHz sampling, 16-bit PCM wav file, then using Wav2Code to generate the array binary.
For STM32, I set I2S with 48KHz Sampling rate, Half-Duplex Master, Mode Master Transmit, I2S Philips, 16 bits data on 16 bits frame, DMA half word, Circular mode.
I2S generated correct signal, bit clock, frame rate, data valid but when I feed this sine wave to an amplifier and monitor the output of the amplifier on the scope, I saw my sine wave double in frequency which is 22KHz to 26KHz.
I then tried different way to create the sine wave with the look up table from the sine wave math function with the frequency of 1KHz, and the result is the same at the amplifier output, I got 2KHz sine wave.
Does anyone else this behavior or anything you experienced?
2024-08-22 12:17 AM - edited 2024-08-22 12:18 AM
> I2S generated correct signal, bit clock, frame rate,
How did you verify that?
> data valid
What's that?
> then tried different way to create the sine wave with the look up table from the sine wave math function with the frequency of 1KHz, and the result is the same at the amplifier output, I got 2KHz sine wave.
There are many ways how to do a mistake when generating signal. Show how do you do it.
JW
2024-08-22 12:52 AM
> I2S generated correct signal, bit clock, frame rate,
How did you verify that?
I used logic analyzer to check the I2S signal from STM32's I2S pins, bit clock, frame, data all decoded from the array data.
>data valid meaning my I2S signals matching with my prepared data array.
For the manual way to generate the data for sine wave, you are correct there are so many way, and I used the references online showing how to generate the buffer of data using sine wave in math.h header file.
The details is here
In short
#include "limits.h"
#include "math.h"
const int Fs = 48000; // sample rate (Hz)
const int LUT_SIZE = 1024; // lookup table size
int16_t LUT[LUT_SIZE]; // our sine wave LUT
for (int i = 0; i < LUT_SIZE; ++i)
{
LUT[i] = (int16_t)roundf(SHRT_MAX * sinf(2.0f * M_PI * (float)i / LUT_SIZE));
} // fill LUT with 16 bit sine wave sample values
2024-08-22 02:10 AM
> int16_t buff[BUFF_SIZE]; // output buffer
And you then play back from this buffer?
Don't forget, that I2S is *stereo*, i.e. you have to have *two* values per sample.
JW