Reputation: 424
I have been working on a Silverlight voice chat application, using speex(basically C# ported Jspeex) for encoding and decoding. I want to implement the following:
The following is the code that i have implemented so far:
/*****************************Encoding**********************************/
JSpeexEnc encoder = new JSpeexEnc();
public byte[] SpeexEncoding(byte[] InputBuffer)
{
MemoryStream msIn = new MemoryStream(InputBuffer);
MemoryStream msOut = new MemoryStream();
encoder.EncodeToSpeex(new RandomInputStream(msIn), new RandomOutputStream(msOut));
return msOut.GetBuffer();
}
void SendVoiceBuffer(object VoiceBuffer, EventArgs e)
{
byte[] PCM_Buffer = (byte[])VoiceBuffer;
if (PCM_Buffer.Length >= 8000)
{
byte[] buffer = SpeexEncoding(PCM_Buffer);
Send_Bytes(buffer);
//this.Dispatcher.BeginInvoke(new ShowMessagedelegate(ShowBufferSize), buffer.Length.ToString());
}
}
/****************************Decoding***************************************/
private void PlayReceivedBuffer(byte[] Encodedbuffer)
{
// if (MuteCheckBox.IsChecked == false)
try
{
JSpeexDec decoder = new JSpeexDec();
decoder.setDestFormat(JSpeexDec.FILE_FORMAT_RAW);
decoder.setStereo(true);
MemoryStream InStream = new MemoryStream(Encodedbuffer);
MemoryStream OutStream = new MemoryStream();
decoder.decode(new RandomInputStream(InStream), new RandomOutputStream(OutStream));
PlayWave(OutStream.GetBuffer());
}
catch (Exception) { }
StartReceiving();
}
void PlayWave(byte[] PCMBytes)
{
MemoryStream ms_PCM = new MemoryStream(PCMBytes,44,PCMBytes.Length-44);
MemoryStream ms_Wave = new MemoryStream();
_pcm.SavePcmToWav(ms_PCM, ms_Wave, 16, 8000, 1);
WaveMediaStreamSource WaveStream = new WaveMediaStreamSource(ms_Wave);
mediaElement1.SetSource(WaveStream);
mediaElement1.Play();
}
I have been tweaking the speex encoding and decoding classes to get a optimum voice quality with no luck. And have been searching the speex class for any AEC that I can possible access and implement, no luck here as well, but the speex documentation mentions about the AEC in C++, but not clear how to implement in C#.
I'm new to C# development, please guide, if possible point me to a direction which will help me implement this AEC and increase the voice quality. I appreciate any guidance.
Thanks!
Upvotes: 2
Views: 1174