This project has moved. For the latest updates, please go here.

G711A Playback From RTP Stream

Nov 11, 2010 at 8:52 AM

Hi All

Please can someone help me i have a application i have written to grap a RTP stream and decode the voice data the data is sent in G711A format and i have it very nearly working

My problem is i get garbled audio form my speakers but i can hear my voice in the audio stream as well i know my units are sending the data corretly as if i use a different decoder it all works perfectly

i think my problem is that i can set my incoming waveformat to have 16 bits per sample as NAudio throws an execption "AcmNotPossible calling acmFormatSuggest" my code for my wave format is as follows

Public Overrides ReadOnly Property WaveFormat() As NAudio.Wave.WaveFormat
        Get
            Dim a As WaveFormat
            'a = WaveFormat.CreateALawFormat(8000, 1)

            a = WaveFormat.CreateCustomFormat(WaveFormatEncoding.ALaw, 8000, 1, 8000, 1, 16)


            Return a
        End Get
    End Property

 

Thanks in advance for any help

 

Colin

Coordinator
Nov 11, 2010 at 8:57 AM

a-law is almost certainly 8 bits per sample, not 16. Are you definitely only sending the raw a-law compressed data to the decoder?

Nov 11, 2010 at 9:30 AM
Edited Nov 11, 2010 at 9:39 AM

Yes only the Alaw data is being presented i have also used the StreamCoders libary with the same units and that works perfectly

The noice is always there no matter if i am speaking into it or not

Would a recording of the audio help???

Colin

Coordinator
Nov 11, 2010 at 9:36 AM

how are you playing back the decoded audio?

Nov 11, 2010 at 9:42 AM

hi

i am playing backing back the audio throught my speakers on my sound card my code is as follows

ON RTP new packet

Dim input As New G711_Wave_Stream(packet.DataPointer)

Dim a As WaveStream = WaveFormatConversionStream.CreatePcmStream(input)

Dim output(a.Length) As Byte

a.Read(output, 0, output.Length - 1)

Naudio_mainOutput.AddSamples(output, 0, output.Length)

a.Dispose()

input.Dispose()

 

Dims

Private NAudio_WaveOut As IWavePlayer
Private Naudio_mainOutput As BufferedSampleStream

NAudio_WaveOut = New DirectSoundOut(300)
Naudio_mainOutput = New BufferedSampleStream

NAudio_WaveOut.Init(Naudio_mainOutput)
NAudio_WaveOut.Play()

G711_Wave Stream is

Imports NAudio.Wave

Public Class G711_Wave_Stream
    Inherits WaveStream

    Private Data() As Byte
    Private Pos As Long

    Public Sub New(ByVal Input() As Byte)
        Data = Input
    End Sub

    Public Overrides ReadOnly Property Length() As Long
        Get
            Return Data.Length
        End Get
    End Property

    Public Overrides Property Position() As Long
        Get
            Return Pos
        End Get
        Set(ByVal value As Long)
            Pos = value
        End Set
    End Property

    Public Overrides Function Read(ByVal buffer() As Byte, ByVal offset As Integer, ByVal count As Integer) As Integer
        Array.Copy(Data, 0, buffer, offset, Data.Length - 1)
        Return Data.Length
    End Function

    Public Overrides ReadOnly Property WaveFormat() As NAudio.Wave.WaveFormat
        Get
            Dim a As WaveFormat
            'a = WaveFormat.CreateALawFormat(8000, 1)

            a = WaveFormat.CreateCustomFormat(WaveFormatEncoding.ALaw, 8000, 1, 8000, 1, 16)


            Return a
        End Get
    End Property
End Class



Colin
Coordinator
Nov 11, 2010 at 9:48 AM

I'm not a VB expert, but I don't think you need those -1's. Also, what is the WaveFormat property of Naudio_mainOutput? It should be exactly the same as the WaveFormat of your "a" WaveStream

Nov 11, 2010 at 10:14 AM

Hi

The format is:

_waveformat = new WaveFormat(8000, 16, 1);
 
Is this wrong? 
Colin

 

Coordinator
Nov 11, 2010 at 11:21 AM

no, that's correct. to debug further, make a WAV file with the ALaw header, and all the raw compressed data in it. See if Windows Media player can play it

Mark

 

Nov 11, 2010 at 11:28 AM

Hi

 

I will try that now

Where can i find the details for the headder?

Thanks and sorry for being a pain in the arse

 

Colin

Coordinator
Nov 11, 2010 at 11:42 AM

just use WaveFileWriter and pass in WaveFormat.CreateALawFormat(8000, 1) as the WaveFormat.

Nov 11, 2010 at 1:24 PM

Hi

I have done that no joy Windows Media wopnt play the file at all i know the RTp libary i am using is giving me the correct data as it will work with the other libary

I have also converted a file using the demo app and that worked ok

I am really lost now

 

Colin

Coordinator
Nov 11, 2010 at 1:29 PM

the chances are the compression is not quite what you think it is then. Have a look at NAudio Demo app for examples of how to use the ACM codecs. I use the NAudio a-law conversion a lot so I know it does work.

Mark

 

Nov 11, 2010 at 1:32 PM

Do you have any source for RTP Alaw at all i dont mind if it is in C# i can convert it or do you know of any projects using Alaw ov RTP and Naudio

Colin

Nov 11, 2010 at 1:40 PM

I have just read the document about the unit i am connecting to and it states that it is G.711 @ 64Kbps and 10MS periods

Dont know if this helps

 

Colin

Coordinator
Nov 11, 2010 at 1:57 PM

sounds like you are passing the RTP headers through the codec too. get rid of the RTP. you just want plain a-law

Nov 11, 2010 at 3:16 PM

Hi

 

I have just taken the code form http://www.codeproject.com/KB/security/g711audio.aspx to decode the G711 from the RTP Packet and it works perfectly

There deffanitly seems to be a problem with the decode using your libary do you have any other pointers or ideas

Maybe i can supply with with a small app with a sample of the G711 data i am getting?

 

Colin

Coordinator
Nov 11, 2010 at 3:27 PM

sure, make it available to download somewhere and post a link. I can't guarantee I'll have time to look at it in detail though

Mark

Nov 11, 2010 at 3:41 PM

Ok thanks i will knock somwthing up in the morning for you

I will include decode from naudio and also the codeproject code i found

Colin

Nov 12, 2010 at 10:34 AM

Hi Mark

Thanks for your time with this problem

I will PM you a link for the demo

Colin