naudio / NAudio.WaveFormRenderer

Simple utility to render waveforms of audio files in various styles using System.Drawing

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

ArgumentException: Must read complete blocks: requested 35310, block align is 4

MrKsiJ opened this issue · comments

The problem arises with the picker, I tried different picker strategies, they all fail, but I need to get a picture of the sound wave from the file. The file is successfully converted to a WAV file from MP3 and its wave can also be obtained in the Audacity program, but I need a wave in the form of an image. I've looked at some examples of how to do this, however I need help with this issue.

It works with the following Patch in public class WaveFormRenderer.
samplePerPixel may not be uneven (because stepSize can be uneven too)

    public Image Render(WaveStream waveStream, IPeakProvider peakProvider, WaveFormRendererSettings settings)
    {
        int bytesPerSample = (waveStream.WaveFormat.BitsPerSample / 8);
        var samples = waveStream.Length / (bytesPerSample);
        var samplesPerPixel = (int)(samples / settings.Width);
        /**/ Patch Start
        int rest = samplesPerPixel % bytesPerSample;
        if (rest > 0)
        {
            samplesPerPixel += rest;
        }
        // Patch End**
        var stepSize = settings.PixelsPerPeak + settings.SpacerPixels;
        peakProvider.Init(waveStream.ToSampleProvider(), samplesPerPixel * stepSize);
        return Render(peakProvider, settings);
    }