51 lines
1.3 KiB
C++
51 lines
1.3 KiB
C++
/**
|
|
* @file test-codec-opus.ino
|
|
* @author Phil Schatzmann
|
|
* @brief generate sine wave -> encoder -> decoder -> audiokit (i2s)
|
|
* @version 0.1
|
|
* @date 2022-04-30
|
|
*
|
|
* @copyright Copyright (c) 2022
|
|
*
|
|
*/
|
|
#include "AudioTools.h"
|
|
#include "AudioTools/AudioCodecs/CodecOpus.h"
|
|
|
|
int sample_rate = 24000;
|
|
int channels = 1; // The stream will have 2 channels
|
|
|
|
SineWaveGenerator<int16_t> sineWave( 32000); // subclass of SoundGenerator with max amplitude of 32000
|
|
GeneratedSoundStream<int16_t> sound( sineWave); // Stream generated from sine wave
|
|
CsvOutput<int16_t> out(Serial, 2); // Output of sound on desktop
|
|
OpusAudioEncoder enc;
|
|
OpusAudioDecoder dec;
|
|
EncodedAudioStream decoder(&out, &dec); // encode and write
|
|
EncodedAudioStream encoder(&decoder, &enc); // encode and write
|
|
StreamCopy copier(encoder, sound);
|
|
|
|
void setup() {
|
|
Serial.begin(115200);
|
|
AudioToolsLogger.begin(Serial, AudioToolsLogLevel::Debug);
|
|
|
|
|
|
// Setup sine wave
|
|
auto cfgs = sineWave.defaultConfig();
|
|
cfgs.sample_rate = sample_rate;
|
|
cfgs.channels = channels;
|
|
cfgs.bits_per_sample = 16;
|
|
sineWave.begin(cfgs, N_B4);
|
|
|
|
// Opus decoder needs to know the audio info
|
|
decoder.begin(cfgs);
|
|
|
|
// configure and start encoder
|
|
enc.config().application = OPUS_APPLICATION_AUDIO;
|
|
encoder.begin(cfgs);
|
|
|
|
Serial.println("Test started...");
|
|
}
|
|
|
|
|
|
void loop() {
|
|
copier.copy();
|
|
} |