-
-
Notifications
You must be signed in to change notification settings - Fork 278
Converting the Data Format
Phil Schatzmann edited this page Mar 27, 2023
·
23 revisions
You can use the more generic FormatConverterStream to change of the
- bits_per_sample
- number of channels
This class is supporting both: the conversion on the input and on the output side.
#include "AudioTools.h"
uint16_t sample_rate=44100;
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, to_channels); // Output to Serial
AudioInfo from(44100, 2, 32);
AudioInfo to(44100, 2, 16);
FormatConverterStream conv(out);
StreamCopy copier(conv, in_stream); // copies sound to out
void setup(){
Serial.begin(115200);
AudioLogger::instance().begin(Serial, AudioLogger::Info);
sine_wave.begin(from, N_B4);
in_stream.begin(from);
conv.begin(from, to);
out.begin(to);
}
void loop(){
copier.copy();
}
#include "AudioTools.h"
SineWaveGenerator<int32_t> sine_wave(32000); // 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, to_channels); // Output to Serial
AudioInfo from(44100, 2, 32);
AudioInfo to(44100, 2, 16);
FormatConverterStream conv(out);
StreamCopy copier(out, conv); // copies converted sound to out
void setup(){
Serial.begin(115200);
AudioLogger::instance().begin(Serial, AudioLogger::Info);
sine_wave.begin(from, N_B4);
conv.begin(from, to);
in_stream.begin();
out.begin(to);
}
void loop(){
copier.copy();
}