TheNut

Feb 1, 2012 at 10: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
{
     get
     {
          return encoder.Vbr;
     }

     set
     {
          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.

Coordinator
Feb 2, 2012 at 6:50 AM

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

 

Coordinator
Feb 8, 2012 at 6: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 9:49 PM
Hi,

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 9:51 PM
Sorry,

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

Has this bug being fixed? or is it me?

Thanks,
Niall
Coordinator
Feb 11, 2013 at 6: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.

Chris
Feb 11, 2013 at 12: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
{
[Export(typeof(INetworkChatCodec))]
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?

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

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

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.
Coordinator
Feb 12, 2013 at 8: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.

C
Feb 12, 2013 at 9: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!

Niall
Coordinator
Feb 12, 2013 at 10: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.

c
Feb 12, 2013 at 5:11 PM
Great stuff,

Thanks Chris. Works well.

Maybe as thanks I should buy your book. :-)
Coordinator
Feb 12, 2013 at 5: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="http://nspeex.codeplex.com/discussions/289553#post1000157" target="_blank"> full discussion online</a>.</p> <p>To add a post to this discussion, reply to this email (<a href="mailto:nspeex@discussions.codeplex.com?subject=[nspeex:289553]" target="_blank">nspeex@discussions.codeplex.com</a>)</p> <p>To start a new discussion for this project, email <a href="mailto:nspeex@discussions.codeplex.com" target="_blank"> nspeex@discussions.codeplex.com</a></p> <p>You are receiving this email because you subscribed to this discussion on CodePlex. You can <a href="https://nspeex.codeplex.com/subscriptions/thread/project/edit" target="_blank"> unsubscribe or change your settings</a> on codePlex.com.</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="http://codeplex.com" target="_blank">codeplex.com</a></p> </div> </div> </div>