Easiest way to use speex preprocessor in C#?

2.7k views Asked by At

I need to use the speex preprocessor, and only the preprocessor in my VOIP app (don't need to use the codec). My app is written in C#. I think I know the easiest steps, but not sure where to find these items.

Easiest in my opinion, if I can find these:

  1. Windows DLL that contains only the preprocessor functions, or if small enough in size I guess the entire speex library would be OK. So far I've only found binarys in EXE format, so if I can't find the binaries I'd have to install the compiler they use to build their source and probably several other libraries (as is my experience with most open source builds).

  2. C# versions of the header files, for pinvoking the DLL functions.

So my question is, does anyone know where I can find these? I'm sure people have created these before, based on the huge number of speex users, just not able to find any on-line.

Hope people don't think I'm lazy, I just hate doing this kind of "busy work" if I know many others have probably already done the exact same thing :)

Update: I did find http://www.rarewares.org/files/others/libspeex-dll-1.2rc1.zip which includes libspeex.dll, but the DLL has no exports so not sure how they expect that to work. The other binaries they have are also just EXEs.

2

There are 2 answers

1
eselk On BEST ANSWER

I only ended up using a few functions, but incase anyone doesn't want to do the work, here is what I wrote:

    [DllImportAttribute("libspeexdsp.dll")]
    public static extern IntPtr speex_echo_state_init(int frameSize,int filterLength);

    [DllImportAttribute("libspeexdsp.dll")]
    public static extern void speex_echo_state_destroy(IntPtr st);

    [DllImportAttribute("libspeexdsp.dll")]
    public static extern void speex_echo_cancellation(IntPtr st, IntPtr recorded, IntPtr played, IntPtr echoRemoved);

    [DllImportAttribute("libspeexdsp.dll")]
    public static extern void speex_echo_playback(IntPtr st, IntPtr played);

    [DllImportAttribute("libspeexdsp.dll")]
    public static extern void speex_echo_capture(IntPtr st, IntPtr recorded, IntPtr echoRemoved);

    [DllImportAttribute("libspeexdsp.dll")]
    public unsafe static extern int speex_echo_ctl(IntPtr st, int id, ref IntPtr val);

    [DllImportAttribute("libspeexdsp.dll")]
    public static extern IntPtr speex_preprocess_state_init(int frameSize, int sampleRate);

    [DllImportAttribute("libspeexdsp.dll")]
    public static extern int speex_preprocess_ctl(IntPtr st, int id, IntPtr val);

    [DllImportAttribute("libspeexdsp.dll")]
    public static extern int speex_preprocess_run(IntPtr st, IntPtr recorded);

    [DllImportAttribute("libspeexdsp.dll")]
    public static extern void speex_preprocess_state_destroy(IntPtr st);

I guess I was lucky in that there were not a lot of structures to delcare, mostly everything is IntPtr or int, so pretty easy.

As far as finding the binaries, I didn't find them precompiled anywhere, but the source did include VS solution files that compiled with only a couple of minor changes, so I guess that part is easy enough for anyone using C#, since they'll be using VS anyway. For some reason I had assumed it would require some other compiler, like GCC, or others that most open source projects seem to use (none of which I'm familiar with). Again, luckily, it didn't!

3
Jonathan Henson On

Speex is written and C, and it has exports. I just downloaded the source code myself and looked. Download the source here, and go from there http://www.speex.org/downloads/. It looks to be quite extensive, ... happy coding.

Of course, there is this, but it is still in beta:

http://nspeex.codeplex.com/