Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7585957
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T19:18:15+00:00 2026-05-30T19:18:15+00:00

I’ve been looking over the NAudio examples trying to work out how I can

  • 0

I’ve been looking over the NAudio examples trying to work out how I can get ulaw samples suitable for packaging up as an RTP payload. I’m attempting to generate the samples from an mp3 file using the code below. Not surprisingly, since I don’t really have a clue what I’m doing with NAudio, when I transmit the samples across the network to a softphone all I get is static.

Can anyone provide any direction on how I should be getting 160 bytes (8Khz @ 20ms) ULAW samples from an MP3 file using NAudio?

private void GetAudioSamples()
{
    var pcmStream = WaveFormatConversionStream.CreatePcmStream(new Mp3FileReader("whitelight.mp3"));
    byte[] buffer = new byte[2];
    byte[] sampleBuffer = new byte[160];
    int sampleIndex = 0;
    int bytesRead = pcmStream.Read(buffer, 0, 2);

    while (bytesRead > 0)
    {
        var ulawByte = MuLawEncoder.LinearToMuLawSample(BitConverter.ToInt16(buffer, 0));
        sampleBuffer[sampleIndex++] = ulawByte;

        if (sampleIndex == 160)
        {
            m_rtpChannel.AddSample(sampleBuffer);
            sampleBuffer = new byte[160];
            sampleIndex = 0;
        }

        bytesRead = pcmStream.Read(buffer, 0, 2);
    }

    logger.Debug("Finished adding audio samples.");
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T19:18:17+00:00Added an answer on May 30, 2026 at 7:18 pm

    Below is the way I eventually got it working. I do lose one of the channels from the mp3, and I guess there’s some way to combine the channels as part of a conversion, but that doesn’t matter for my situation.

    The 160 byte buffer size gives me 20ms ulaw samples which work perfectly with the SIP softphone I’m testing with.

    var pcmFormat = new WaveFormat(8000, 16, 1);
    var ulawFormat = WaveFormat.CreateMuLawFormat(8000, 1);
    
    using (WaveFormatConversionStream pcmStm = new WaveFormatConversionStream(pcmFormat, new Mp3FileReader("whitelight.mp3")))
    {
        using (WaveFormatConversionStream ulawStm = new WaveFormatConversionStream(ulawFormat, pcmStm))
        {
            byte[] buffer = new byte[160];
            int bytesRead = ulawStm.Read(buffer, 0, 160);
    
            while (bytesRead > 0)
            {
                byte[] sample = new byte[bytesRead];
                Array.Copy(buffer, sample, bytesRead);
                m_rtpChannel.AddSample(sample);
    
                bytesRead = ulawStm.Read(buffer, 0, 160);
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a jquery bug and I've been looking for hours now, I can't
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
Does anyone know how can I replace this 2 symbol below from the string
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
I'm trying to create an if statement in PHP that prevents a single post

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.