Encoding 32bit I2S stream? #479
-
My I2S mems mic encodes at 18 bits and this requires at least 24bit storage, but only 32bit seems to be working. Which is fine. But I’m curious how to encode the raw stream. All the voice encoders seem to use 16bit streams as input. Can I bit shift the 18 bits into 16 losing a little precision? Any other ideas? |
Beta Was this translation helpful? Give feedback.
Replies: 6 comments 15 replies
-
Did you try to request 16 bits from the microphone ? I was usually getting this to work with 1 channel with proper data and one channel with noise that can be just replaced with a copy of the proper data with the help of a ConverterFillLeftAndRight<int16_t>. You can also convert 32 to 16 bits by wrapping the input stream into a NumberFormatConverterStream |
Beta Was this translation helpful? Give feedback.
-
I committed some corrections, hoping that this might help. However I strongly recommend to start with the I2S to Csv sketch and add additional layers - step by step - only after you confirmed that you get the expected output. Otherwise it will get too difficult to locate the source of your issue. |
Beta Was this translation helpful? Give feedback.
-
@jeffiel I am playing now with the same mic - SPH0645 and i cannot get it to work below 32bits. So far my only prove that its working at 32bits is the streams-i2s-serial example where I can see that the data read from the mic changes with the sound I make. I also cannot figure out how I can encode the 32bit mic sound to wav. Did you find a solution? |
Beta Was this translation helpful? Give feedback.
-
32 bit wav files: When I tried last, this was working w/o any issues: just make sure that you give the correct configuration to the webserver that has bits_per_sample set to 32 |
Beta Was this translation helpful? Give feedback.
-
Yes, I would expect it to oscillate around 0 as well. But the shape looks promising: what happens if you record a sine wave e.g. with https://onlinetonegenerator.com/ ? Do you get a sine wave as output. In this case you could just shift the values up... |
Beta Was this translation helpful? Give feedback.
-
Using google I found that the SPH0645 seems to have a DC-Offset Problem. |
Beta Was this translation helpful? Give feedback.
Did you try to request 16 bits from the microphone ?
I was usually getting this to work with 1 channel with proper data and one channel with noise that can be just replaced with a copy of the proper data with the help of a ConverterFillLeftAndRight<int16_t>.
You can also convert 32 to 16 bits by wrapping the input stream into a NumberFormatConverterStream