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

  • SEARCH
  • Home
  • 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 774961
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T19:12:47+00:00 2026-05-14T19:12:47+00:00

Naudio Library: http://naudio.codeplex.com/ I’m trying to convert an MP3 file to a WAV file,

  • 0

Naudio Library: http://naudio.codeplex.com/

I’m trying to convert an MP3 file to a WAV file, but I’ve run in to a small error. I know what’s going wrong, but I don’t really know how to go about fixing it.

Here’s the piece of code I’m running:

private void button1_Click(object sender, EventArgs e) {
    using(Mp3FileReader reader = new Mp3FileReader(@"path\to\MP3")) {
        using(WaveFileWriter writer = new WaveFileWriter(@"C:\test.wav", new WaveFormat())) {
            int counter = 0;
            while(reader.Read(test, counter, test.Length + counter) != 0) {
                writer.WriteData(test, counter, test.Length + counter);
                counter += 512;
            }
        }
    }
}

reader.Read() goes into the Mp3FileReader class, and the method looks like this:

public override int Read(byte[] sampleBuffer, int offset, int numBytes)
{
    if (numBytes % waveFormat.BlockAlign != 0)
        //throw new ApplicationException("Must read complete blocks");
        numBytes -= (numBytes % waveFormat.BlockAlign);
    return mp3Stream.Read(sampleBuffer, offset, numBytes);
}

mp3Stream is an object of the Stream class.

The problem is: I’m getting an ArgumentException. MSDN says that this is because the sum of offset and numBytes is greater than the length of sampleBuffer.

Documentation: http://msdn.microsoft.com/en-us/library/system.io.stream.read.aspx

This happens because I increase the counter every time, but the size of the byte array test remains the same.

What I’ve been wondering is: do I need to increase the size of the array dynamically, or do I need to find out the needed size at the beginning and set it right away?

And also, instead of 512, the method in Mp3FileReader returns 365 the first time. Which is the size of a whole block. But I’m writing the full 512. I’m basically just using the read to check if I’m not at the end of the file yet. Do I need to catch the return value and do something with that, or am I good here?

  • 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-14T19:12:48+00:00Added an answer on May 14, 2026 at 7:12 pm

    You’ll need to use the return value of Read() to determine how many bytes you actually got. It doesn’t have to be 512, you already found that out. And keep in mind that you are working with streams, not arrays. Make it look similar to this:

       using (var reader = new Mp3FileReader(@"path\to\MP3")) {
            using (var writer = new WaveFileWriter(@"C:\test.wav", new WaveFormat())) {
                var buf = new byte[4096];
                for (;;) {
                    var cnt = reader.Read(buf, 0, buf.Length);
                    if (cnt == 0) break;
                    writer.WriteData(buf, 0, cnt);
                }
            }
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to convert a WAV file into a WMA file using NAudio. I've
I'm looking for a library capable of creating an audio file (mp3 or wav).
I use NAudio. Before everything was good. But yesterday there was an error: All
Similar but different to: Firstly NAudio error: "NoDriver calling acmFormatSuggest" and now ACM Stream
When using NAudio to playback an MP3 file [in the console], I can't figure
I just tried to run the NAudio demos and I'm getting a weird error:
I have been using the code in http://opensebj.blogspot.com/2009/04/naudio-tutorial-5-recording-audio.html to record audio. Basically this code:
I have been working on a specialized mp3/wav/(wma later?) player using the excellent NAudio
I have already referenced NAudio library in my project how ever when i run
I have wav file in which using the naudio lib i have been able

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.