This sample demonstrates the setup of audio encoders (AAC, MP3) and running a feedback loop.
using StreamCoders.Decoder;
using StreamCoders.Encoder;
using StreamCoders.Wave;
using System;
namespace SpeechEncoderTest
{
class Program
{
static void Main(string[] args)
{
WaveInput win = new WaveInput();
win.BitsPerSample = 16;
win.Channels = 2;
win.SampleRate = 22050;
win.OpenDevice(null);
win.Start();
WaveOutput wout = new WaveOutput();
wout.Channels = 2;
wout.SampleRate = 22050;
wout.BitsPerSample = 16;
wout.Init();
wout.OpenDevice(null);
AACEncoder enc = new AACEncoder();
enc.InputBitsPerSample = 16;
enc.InputChannels = 2;
enc.InputSampleFrequency = 22050;
enc.OutputBitrate = 128000;
enc.Init();
String initstr = enc.ConfigParameter;
AACDecoder dec = new AACDecoder();
dec.Channels = 2;
dec.SampleRate = 22050;
dec.BitsPerSample = 16;
dec.AudioSource = StreamSources.FILE_OTHER;
bool res = dec.Init();
int bytescollected = 0;
win.ClearBuffers();
while (true)
{
if (win.SamplesAvailable == true)
{
byte[] samples = win.GetAllData();
bytescollected += samples.Length;
byte[] encodedBytes = enc.Encode(samples);
if (encodedBytes != null)
{
byte[] raw = dec.Decode(encodedBytes);
if (raw != null)
{
if(raw.Length > 0)
wout.Enqueue(raw);
}
}
}
wout.UnprepareBuffers();
}
}
}
}