I get quite a lot of questions about how to render audio waveforms with NAudio and although there are a few examples of doing exactly this in the NAudio demo projects, I didn’t have a demo that takes an audio file and creates a PNG of the waveform. This can be especially useful if you are wanting to create server-side waveforms in a web application.

So I’ve decided to open source a little utility I created a while ago for doing just that. You give it the path of the file, and it uses NAudio’s AudioFileReader class to read out the samples so it can support a wide range of input formats. Then there are lots of customization options for how the peaks are generated and what the waveform will look like.

Customization options include:

  • Supports several peak calculation strategies (max, average, sampled, RMS, decibels)
  • Supports different colours or gradients for the top and bottom half
  • Supports different sizes for top and bottom half
  • Overall image size and background can be customized
  • Transparent backgrounds
  • Support for SoundCloud style bars
  • Several built-in rendering styles

Test Harness App

It comes with a built-in test harness app makes it easy to experiment with the various rendering options and save the results as a PNG.

Test Harness UI

Example Waveforms

Basic solid colour waveform

Basic solid color


Gradient vertical bars (old SoundCloud style)

Gradient vertical bars


Blocks (SoundCloud style)



Orange Blocks


Transparent Backgrounds

Transparent Background


Transparent Background

You can check out all the source code on GitHub

Want to get up to speed with the the fundamentals principles of digital audio and how to got about writing audio applications with NAudio? Be sure to check out my Pluralsight courses, Digital Audio Fundamentals, and Audio Programming with NAudio.
Vote on HN
comments powered by Disqus