Encoder16 bit , i2s 32 bit #727
-
I have INMP441 which give 32 bit data and want to pas this to encoder , and as per my knowledge encoder support 16 bit data , further I am facing difficulty in converting 32 bit data to 16 bit data . For this i remove upper 16 bit from array and lower 16 bit will my required data , is my observation correct ?? below is my Pseudocode . File dataFile = SD.open("example.wav", FILE_WRITE); if (i2s.available()>0){
-----------32------------||--------------32------------|| |
Beta Was this translation helpful? Give feedback.
Replies: 5 comments 5 replies
-
Why don't just just use the FormatConverterStream ? If you really want to wast some memory your buffer32 should be int32_t and your buffer16 should be int16_t. |
Beta Was this translation helpful? Give feedback.
-
I try to use FormatConverterStream but i am missing some thing , because the i cant listen audio Below i try to use FormatConverterStream |
Beta Was this translation helpful? Give feedback.
-
Just did a test, and I confirm that there seems to be an issue. However the following is working w/o any issues #include "AudioTools.h"
#include "AudioLibs/AudioKit.h"
SineWaveGenerator<int32_t> sine_wave; // subclass of SoundGenerator with max amplitude of 32000
GeneratedSoundStream<int32_t> in_stream(sine_wave); // Stream generated from sine wave
//CsvStream<int16_t> out(Serial);
AudioKitStream out;
AudioInfo from(44100, 2, 32);
AudioInfo to(44100, 2, 16);
NumberFormatConverterStream conv(out);
StreamCopy copier(conv, in_stream); // copies sound to out
void setup(){
Serial.begin(115200);
AudioLogger::instance().begin(Serial, AudioLogger::Warning);
sine_wave.begin(from, N_B4);
in_stream.begin(from);
conv.begin(from.bits_per_sample, to.bits_per_sample);
auto cfg = out.defaultConfig(TX_MODE);
cfg.copyFrom(to);
out.begin(cfg);
}
void loop(){
copier.copy();
}
You could also use the typed version by replacing NumberFormatConverterStreamT<int32_t, int16_t> conv(out);
conv.begin();
|
Beta Was this translation helpful? Give feedback.
-
with typed version . but no success , now log is also different , #include "AudioTools.h" ESPNowStream now; StreamCopy copier(encoder, conv); const char *peers[] = {"0C:B8:15:C3:40:68"}; auto cfg = now.defaultConfig(); now.begin(cfg); // start i2s input with default configuration Serial.println("Sender started..."); void loop() { [I] Communication.h : 107 - setting mac 94:E6:86:04:89:44 mac: 94:E6:86:04:89:44 |
Beta Was this translation helpful? Give feedback.
-
[E] CodecSBC.h : 330 - Invalid sample_rate: 0 |
Beta Was this translation helpful? Give feedback.
Why don't just just use the FormatConverterStream ?
If you want to program it yourself, I suggest to do some casts, then you can do regular calculations. The input it int32_t* and the result should end in int16_t*.
If you really want to wast some memory your buffer32 should be int32_t and your buffer16 should be int16_t.