I am providing the untyped NumberFormatConverterStream class to convert between different signed bit sizes. This class is using the typed templated NumberFormatConverterStreamT do do the actual work.
Currently there are also some Codecs that can also be used to convert the nubmer format: e.g. L8, L16 and Float.
I decided to extend the functionality of NumberFormatConverterStreamT to potentially support any number type, so that we can also use unsigned data types for the conversion as well. Here is an example Arduino Sketch
#include "AudioTools.h"
SineWaveGenerator<int16_t> sineWave;
GeneratedSoundStream<int16_t> sound(sineWave);
CsvOutput<uint8_t> out(Serial, sound.audioInfo().channels);
NumberFormatConverterStreamT<int16_t, uint8_t> nfc(out);
StreamCopy copier(nfc, sound);
void setup(void) {
// Open Serial
Serial.begin(115200);
AudioToolsLogger.begin(Serial, AudioToolsLogLevel::Warning);
nfc.begin();
out.begin();
sineWave.begin();
// Setup sine wave
sineWave.setFrequency(N_B4);
Serial.println("started...");
}
void loop() {
copier.copy();
}
This sketch generates a sine wave in int16_t and converts it to the uint8_t data range (from 0 through 255 decimal).
I have tested the functionality with uint8_t, int8_t, int16_t, uint16_t, int24_t (int24_3bytes_t and int24_4bytes_t), uint32_t, int32_t, FloatAudio.
0 Comments