markheath / skypevoicechanger

37 stars 17 forks source link

Any suggestion how to properly use speex AEC 1.2rc1 in skypevoicechanger? #4

Open swdevbali opened 3 years ago

swdevbali commented 3 years ago

Hi Mark! :)

Okay, I finally able to get my hand on the correct libspeexdsp that contains AEC functions. Do you plan on adding aec on it though?

So, anyway, what I already achieve is:

What I am missing is really executing the AEC functions. What I still trying to find is: as AEC is the process of removing what being played in what being recorded, how do I get the part that what being played as in your article here?

As for the function signature here: public static extern void speex_echo_cancellation(IntPtr st, IntPtr recorded, IntPtr played, IntPtr echoRemoved);

Here is my latest tries: (will directly crashing the app when I try to hit the Record button)

        private void RecorderOnDataAvailable(object sender, WaveInEventArgs waveInEventArgs)
        {
            //Incoming data, process it
            IntPtr ptr_recorded = Marshal.AllocHGlobal(waveInEventArgs.Buffer.Length);
            Marshal.Copy(waveInEventArgs.Buffer, 0, ptr_recorded, waveInEventArgs.Buffer.Length);

            IntPtr ptr_played = Marshal.AllocHGlobal(waveInEventArgs.Buffer.Length);
            Marshal.Copy(waveInEventArgs.Buffer, 0, ptr_played, waveInEventArgs.Buffer.Length);

            //TODO: REMOVE ECHO HERE
            IntPtr ptr_wavein_output = Marshal.AllocHGlobal(waveInEventArgs.Buffer.Length);            
            speex_echo_cancellation(speex_echo_state, ptr_recorded, ptr_played, ptr_wavein_output);            
            //speex_preprocess_run(den, ptr_wavein_output);

            //COPY BACK THE RESULTANT PROCESS
            byte[] wavein_processed = new byte[waveInEventArgs.Buffer.Length];
            Marshal.Copy(ptr_wavein_output, wavein_processed, 0, waveInEventArgs.Buffer.Length);

            //SUCCESS PLAYING IT!
            audioPipeline.ProcessOutgoing(wavein_processed, waveInEventArgs.Buffer.Length);
            bufferedWaveProvider.AddSamples(wavein_processed, 0, waveInEventArgs.BytesRecorded); //playback
        }

This line create the crash issue speex_echo_cancellation(speex_echo_state, ptr_recorded, ptr_played, ptr_wavein_output);

Below is the screenshot of the application: image

The code is here if you want to try it.

Got to say, this repository hold potential possibility for any audio related projects. Thank you Mark!

swdevbali commented 3 years ago

Btw, it really awesome to see my voice changed in realtime!