Hi all. I am connecting my mkrzero derived custom board to a MAX98357 over I2S and trying to output a sine wave to test initially. The interface and power isolation I think is good as no pop/click "noise" and volume is fine, but the sine wave sounds more like an old-school modem! So I am thinking about signed/unsigned data, L/R/mono issues maybe, but I have got nowhere investigating these.
If I print the sine values they look fine ( eg. -23169, -12539, 0, 12539, 23169, 30272, 32767, 30272, 23169, 12539, 0, -12539, -23169, -30272, -32767, -30272, -23169, -12539..).
I have tried a few sample rates. I am using the I2S.h library and simply doing I2S.begin(I2S_PHILIPS_MODE, sampleRate, 16) and then a bunch of I2S.write(x). Maybe I am missing some more config stuff? I am driving SDMODE high for mono data.
In which case you need to pre calculate the samples of the sin wave and put them in a buffer in the setup function.
Then to generate the signals you just output successive samples in the buffer. If you use a floating point buffer pointer, with an increment less than 1, then you can control the speed of the output with the increment size.
Of course you only use the integer part of the buffer pointer when fetching samples from the buffer.
nice tip thanks! I have hooked it up to my adpcm decoder now and strangely the volume there is much lower, it's not quite full-scale but I get peaks at +/- 20,000, so about 2/3rds full-scale of 32768. Maybe it's a log thing...