简体   繁体   中英

NAudio file saved in wave prepends added padding to the file

I have code like so:

        mp3File = new Mp3FileReader("someMP3Files.mp3");
        WaveChannel32 inputStream = new WaveChannel32(mp3File);
        streamProcessor = new WaveStreamProcessor(inputStream);
        CreateWaveFile("test.wav", inputStream);

so basically it takes the mp3 and converts it to a wave file called test. Looking at the converted file, I see this using audacity.

Note the highlighted area why does it give the blank space and does not duplicate exactly as it is?

检查突出显示的黄色部分

Any ideas?

My create wave method:

    public static void CreateWaveFile(string filename, WaveStream stream)
    {
        using (WaveFileWriter writer = new WaveFileWriter(filename, stream.WaveFormat))
        {
            byte[] buffer = new byte[stream.Length];
            while (true)
            {
                int bytesRead = stream.Read(buffer, 0, buffer.Length);
                if (bytesRead == 0)
                    break;
                writer.WriteData(buffer, 0, bytesRead);
            }
        }
    }

Clarification, the padding is actually added when the Mp3FileReader is created.

MemoryStream mp3Buffered = new MemoryStream();
using (var responseStream = resp.GetResponseStream())
{
    byte[] buffer = new byte[65536];
    int bytesRead = responseStream.Read(buffer, 0, buffer.Length);
    while (bytesRead > 0)
    {
        mp3Buffered.Write(buffer, 0, bytesRead);
        bytesRead = responseStream.Read(buffer, 0, buffer.Length);
    }
}

mp3Buffered.Position = 0;
using (var mp3Stream = new Mp3FileReader(mp3Buffered))
{    
    WaveFileWriter.CreateWaveFile("file.wav", mp3Stream);
}

I wasn't too sure what you meant by that question, however I tried my best and researched so this is what I found. And I also think padding is automatically added when those files are converted.

Note: Please don't bash me if I'm wrong in the comments, check my profile later and you'll see why. :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM