Jerry
Jerry

Reputation: 424

How do I implement Acoustic echo cancellation on Silverlight C#, I'm using speex

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:

  1. Acoustic Echo Cancellation using Speex in C#: I have been looking around, haven't found a viable solution or was really unsure how that can be done.
  2. The quality of the voice is quite noise and breaks every 30 sec's.

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

Answers (0)

Related Questions