Converting 32 bit stream to 16 bit #629
-
Hi Phil: First of all, thank you very much for the fantastic library. In a project where I want to save the output from an I2S microphone to SD card, I am running into the following problem: When I artificially generate the output (via SineWaveGenerator) in 16 bit everything works perfect. However, the microphone produces a 32 bit stream which I obviously need to convert to 16 bit. That's where I am struggling. I used the following code to test but receive only zeros on the serial monitor: #include "AudioTools.h" uint16_t sample_rate=44100; SineWaveGenerator<int32_t> sine_wave(32000); // subclass of SoundGenerator with max amplitude of 32000 void setup(){ sine_wave.begin(1, sample_rate, N_B4); out.begin(); void loop(){ What am I doing wrong with the converter function? Any help is very much appreciated. Werner |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 4 replies
-
Did you try to output the 32 bit GeneratedSoundStream directly. I propose that you leave the amplitude away in the constructor of the sine_wave or increase it to the max value of a 32 bit number. |
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
-
Quite recently I added some functionality to determine the max number by data type. Initially I relied on the size, but this does not work for int24_t because this has 4 bytes like the int32_t. If the volume is still too low you can add a VolumeStream to your chain.... |
Beta Was this translation helpful? Give feedback.
-
Thank you very much, then I will try that. |
Beta Was this translation helpful? Give feedback.
I was running your sketch with my proposed change with
SineWaveGenerator<int32_t> sine_wave;
And for me it works like a charm:
When you use 32000 as max amplitude the converted signal is oscillating around +-0.00001490116 which gives 0 when converted to an integer!