Playing G.711 ALaw data

Oct 11, 2009 at 1:25 PM

Hey,

I'm trying to play raw G.711 ALaw data that I've received over the network using NAudio. Since I didn't expect NAudio to decode ALaw on it's own, I've taken care of that and am now trying to play the resulting short-samples.

I've implemented my own IWaveProvider based on WaveProvider16:

 

 

            public class G711WaveProvider : WaveProvider16
            {
                private object samplesLock = new object();
                private ManualResetEvent haveData = new ManualResetEvent(false);
                private int required;
                private Queue<short> samples = new Queue<short>();

                public G711WaveProvider()
                    : base(8000, 1)
                {
                }

                public override int Read(short[] buffer, int off, int len)
                {
                    lock (samplesLock)
                    {
                        int have = samples.Count;
                        if (have >= len)
                        {
                            for (int i = 0; i < len; i++)
                            {
                                buffer[off + i] = samples.Dequeue();
                            }
                            return len;
                        }

                        required = len - have;
                    }
                    haveData.WaitOne();
                    haveData.Reset();
                    return Read(buffer, off, len);
                }

                public void Feed(short[] d)
                {
                    lock (samplesLock)
                    {
                        foreach (short s in d) samples.Enqueue(s);
                        if (required > 0)
                        {
                            required -= d.Length;
                            if (required <= 0)
                                haveData.Set();
                        }
                    }
                }

                public new WaveFormat WaveFormat
                {
                    get
                    {
                        return WaveFormat.CreateCustomFormat(WaveFormatEncoding.Pcm, 8000, 1, 16000, 2, 16);
                    }
                }

            }

I've tried a bunch of different WaveFormats, no change. I should also mention that I develop on a Vista 64bit machine and WaveOut didn't work properly (stopped reading samples after filling its default three buffers), so I'm now using DirectSoundOut but only hearing noise.

Any idea on this? I've confirmed using WireShark that the data transferred is the "real deal".

 

Coordinator
Oct 11, 2009 at 4:31 PM

Hi there,

did you know NAudio can already do A-law decompression using the WaveFormatConversionStream?

it works nicely.

The wave format should be the format you are converting your a-law to. I would expect that would be 8kHz, 16 bit mono PCM.

Have you also tried writing your converted A-law to a wav file, just to make sure your conversion stream is working correctly?

 

Oct 11, 2009 at 5:11 PM

Hey,

I've implemented a WaveStream that receives the pure byte[]-Data I get over the wire. It reports WaveFormat.CreateALawFormat(8000, 1) as WaveFormat. My WaveFormatConversionStream uses WaveFormat.CreateCustomFormat(WaveFormatEncoding.Pcm, 8000, 1, 16000, 2, 16) as target Format. This combination still yields the same result: noise :(

I've recorded both my previous method and the ConversionStream one using WaveRecorder, playing the resulting wav with VLC results in the same noise I hear through NAudio. I've uploaded that wav http://rapidshare.com/files/291649176/call.wav.html

Thanks for answering though :)

Coordinator
Oct 12, 2009 at 1:35 PM

are you sure your input audio is a-law? I have successfully used NAudio to decompress a-law many times.

Mark

 

 

Oct 12, 2009 at 4:19 PM
Hey,

I receive data over RTP and the payload type sent clearly marks it as
G.711 ALaw. Also, the received data does kinda reflect the input: I'm
using a third party program to generate the RTP traffic which records
from my microphone, and as I speak louder, noise gets louder :o

Greetings

2009/10/12 markheath <notifications@codeplex.com>:
> From: markheath
>
> are you sure your input audio is a-law? I have successfully used NAudio to
> decompress a-law many times.
>
> Mark
>
>
>
>
>
> Read the full discussion online.
>
> To add a post to this discussion, reply to this email
> ([email removed])
>
> To start a new discussion for this project, email
> [email removed]
>
> You are receiving this email because you subscribed to this discussion on
> CodePlex. You can unsubscribe on codePlex.com.
>
> Please note: Images and attachments will be removed from emails. Any posts
> to this discussion will also be available online at codeplex.com
Oct 12, 2009 at 6:36 PM

Hey,

I'm sorry for having wasted your time. The problem was in my RTP stuff, causing the whole payload to be the first byte of the real payload.

Having fixed that, it works great now. I love NAudio, it's really my kind of library. Great work and thanks :)

Greetings

Coordinator
Oct 12, 2009 at 6:47 PM

cool, glad you got it working