Feb 1, 2012 at 11:45 PM

Hey Christoph,

Just wanted to let you know there's a bug in the SpeexEncoder class where the VBR property is always set to true:

/// Turns encoding in variable bit rate on or off.
public bool VBR
          return encoder.Vbr;

          encoder.Vbr = true;

I also noticed that VBR encodings don't decode properly. The Speex C++ library decodes VBR fine, but the NSpeex library produces some voodoo'ish results. It looks like the first part gets somewhat decoded (has some noise mixed in), but the remaining 2/3 audio is silence. It's not a deal-breaker as I can work with CBR, but I thought I would raise the issue if it's not already known.

Also, there's a more efficient way to copy data buffers that you've shown in your documentation. Instead of running a for-loop and bit converting each value, just use the Buffer.BlockCopy() method. It's a lot faster.

Other than that, thanks for this port. You did a good job.

Feb 2, 2012 at 7:50 AM

Thanks for this information! Will look into the VBR issues you found.


Feb 8, 2012 at 7:30 PM

I cannot reproduce the VBR propblems you are describing. I modified the sample to work on Vbr and I see that the encoded packets coming out of the encoder have different size. On the decoder side I am able to get a correct frame back from the decoder.

btw: thanks for the hint on the Buffer.BlockCopy (doc updated) !

Feb 10, 2013 at 10:49 PM

I am usingNAudio which in turn calls Nspeex.

I am also having the issue where VBR cannot be set to 'false'.

encoder.VBR = false;

no errros reported, but in the class VBR seems to be hardcoded to 'true'

BTW, I am expecting a return encoded size of 38 bytes for a input of 160 samples. With VBR being set to true am I right in saying this causes a a different number of bytes to be returned.

Using narrow mode, mode = 5, quality = 6, framesize 160.

I am 'transmitting' live audio to over 500 boxed which will only accept streamed packets with the audio data being set to 38 per packet....
Thus I need multiples of 38 byte audio streams... or 38 encoded bytes per 20ms..

I am hoping VBR being set to false will help me out??

Thanks for any feedback...
Feb 10, 2013 at 10:51 PM

just noticed the year of the OP was Feb 2012, not 2013...

Has this bug being fixed? or is it me?

Feb 11, 2013 at 7:13 AM
The VBR bug has been fixed and I just uploaded the latest release containing this fix (v 1.1.2).

In VBR mode you cannot expect that every packet has the same sice. When encoding you get the encoded bytes for that frame and this information must be known to the receiver/decoder side in order to know how many bytes to read from the stream (either network or file).

Having a constraint that every decoder expects 38Bytes is quite a problem as soon as you tweak the settings in the encoder.

Feb 11, 2013 at 1:26 PM
Thanks Chris,

I appreciate your feedback and speed in compiling a new dll.

I simple swopped the old dll 1.1.1 by deleting the reference and adding the reference to the new version 1.1.2.

I am using it via NAudioDemo. (SpeexChatCodec)

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NAudio.Wave;
using NSpeex;
using System.ComponentModel.Composition;
using System.Diagnostics;

namespace NAudioDemo.NetworkChatDemo
class NarrowBandSpeexCodec : SpeexChatCodec
    public NarrowBandSpeexCodec() : 
        base(BandMode.Narrow, 8000, "Speex Narrow Band")

} etc................................
However, at reference insert time, your classes are seen and accepted but at build time I receive errors 'type cannot be found' for all the NSpeex types.

So my question is: what is the difference between ver 1,1.1 and 1.1.2 ??

and how can I resolve?

Feb 11, 2013 at 1:33 PM
just for clarity, if I put back ver 1.1.1

everything compiles and runs without error...
Feb 11, 2013 at 3:38 PM

Quitting, VS10, and launching as Admin and then referencing version 1.1.2 does the trick. So the above is a visual studio bug/error.

However, not of the woods yet. When I access the types within the speex dll (SpeexChatCodec.cs from NAudio) I get a run time error.
'Must use the rewriter when using contract.requires<TException>'

If I comment out only the Speex calls within. SpeexChatCodec.' it compiles without error. So something in the nspeex dll is invoking this error.

I have no idea what contract.requires is. Never seen it before...

Getting there Chris.... Do you invoke Contracts in your new dll.
Feb 12, 2013 at 9:57 AM
In NSpeex I used Microsoft Code Contracts. Kinda nice thing if you writer libraries but unfortunately it is not widely know and used.

get the latest release v1.1.3 where these code contracts are taken out for the release builds and it should work for you.

Feb 12, 2013 at 10:39 AM
Hi Chris,

I appreciate your speed in this, but Im still getting the same error with ver 1.1.3...

Its seems its hasnt being totally stripped of the contracts dependency!

Feb 12, 2013 at 11:07 AM
Pretty anoying, these code contracts nowadays. Seems they have changed the behavior on compile time which left the contracts in the compiled code.

Anyway, deleted them from code and replaced v1.1.3 release.

Feb 12, 2013 at 6:11 PM
Great stuff,

Thanks Chris. Works well.

Maybe as thanks I should buy your book. :-)
Feb 12, 2013 at 6:17 PM
<p dir="ltr">I am happy that it finally worked! There have been so many complaints about these code contracts in the past...</p> <p dir="ltr">Better to donate the money as I don't get much revenue from the book :)</p> <p dir="ltr">C</p> <div style="margin:0 0 0 .8ex; border-left:1px #ccc solid; padding-left:1ex"> <div> <p>From: ndorr</p> <div>Great stuff, <br> <br> Thanks Chris. Works well. <br> <br> Maybe as thanks I should buy your book. :-)<br> </div> <div> <p>Read the <a href="" target="_blank"> full discussion online</a>.</p> <p>To add a post to this discussion, reply to this email (<a href="[nspeex:289553]" target="_blank"></a>)</p> <p>To start a new discussion for this project, email <a href="" target="_blank"></a></p> <p>You are receiving this email because you subscribed to this discussion on CodePlex. You can <a href="" target="_blank"> unsubscribe or change your settings</a> on</p> <p>Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at <a href="" target="_blank"></a></p> </div> </div> </div>