Audio Waveform Image Generator
audiowaveform is a C++ command-line application that generates waveform data from either MP3, WAV, or FLAC format audio files. Waveform data can be used to produce a visual rendering of the audio, similar in appearance to audio editing applications.
Waveform data files are saved in either binary format (.dat) or JSON (.json). Given an input waveform data file, audiowaveform can also render the audio waveform as a PNG image at a given time offset and zoom level.
The waveform data is produced from an input stereo audio signal by first
combining the left and right channels to produce a mono signal. The next stage
is to compute the minimum and maximum sample values over groups of N input
samples (where N is controlled by the
--zoom command-line option), such that
each N input samples produces one pair of minimum and maxmimum points in the
Binary packages are available on Ubuntu Launchpad here.
$ sudo add-apt-repository ppa:chris-needham/ppa $ sudo apt-get update $ sudo apt-get install audiowaveform
There is an
audiowaveform package available in the AUR.
Mac OSX via Homebrew
audiowaveform using Homebrew:
$ brew tap bbc/audiowaveform $ brew install audiowaveform
Windows binaries are not currently available. Please follow this issue for details.
Building from source
The software has been developed on Ubuntu 12.04 and Fedora 18. Due to compiler and library version requirements, the software may not build on earlier operating system releases.
Install package dependencies
libmad is available from the RPM Fusion free repository. Before running the
yum command you should follow the instructions
here to add this repository, if you have
not already done so.
$ sudo yum install git make cmake gcc-c++ libmad-devel \ libid3tag-devel libsndfile-devel gd-devel boost-devel
$ sudo apt-get install git make cmake gcc g++ libmad0-dev \ libid3tag0-dev libsndfile1-dev libgd2-xpm-dev libboost-filesystem-dev \ libboost-program-options-dev \ libboost-regex-dev
$ brew install cmake libmad libid3tag libsndfile gd $ brew install boost --with-c++11
Obtain the source code
$ git clone https://github.com/bbc/audiowaveform.git $ cd audiowaveform
Install Google Test test framework
$ wget https://github.com/google/googletest/archive/release-1.8.0.tar.gz $ tar xzf release-1.8.0.tar.gz $ ln -s googletest-release-1.8.0/googletest googletest $ ln -s googletest-release-1.8.0/googlemock googlemock
$ mkdir build $ cd build $ cmake .. $ make
The default build type is Release. To build in Debug mode add
-D CMAKE_BUILD_TYPE=Debug to the
cmake command above. If you don't want to
compile the unit tests add
To compile with clang instead of g++:
$ cmake -D CMAKE_C_COMPILER=/usr/local/bin/clang -D CMAKE_CXX_COMPILER=/usr/local/bin/clang++ ..
$ make test
To see detailed test output:
$ sudo make install
By default this installs the
audiowaveform program in
man pages in
/usr/local/share/man. To change these locations, add a
-D CMAKE_INSTALL_PREFIX=... option when invoking
$ audiowaveform --help
Command line options
audiowaveform accepts the following command-line options:
||Show help message|
||Show version information|
||Input mono or stereo audio (.wav or .mp3) or waveform data (.dat) file name|
||Output waveform data (.dat or .json), audio (.wav), or PNG image (.png) file name|
||Zoom level (samples per pixel), default: 256. Not valid if
||Zoom level (pixels per second), default: 100. Not valid if
||Number of bits resolution when creating a waveform data file (either 8 or 16), default: 16|
||Start time (seconds), default: 0|
||End time (seconds). Not valid if
||Width of output image (pixels), default: 800|
||Height of output image (pixels), default: 250|
||Color scheme of output image (either 'audition' or 'audacity'), default: audacity|
||Border color (in rrggbb[aa] hex format), default: set by
||Background color (in rrggbb[aa] hex format), default: set by
||Waveform color (in rrggbb[aa] hex format), default: set by
||Axis label color (in rrggbb[aa] hex format), default: set by
||Render PNG images without axis labels|
||Render PNG images with axis labels (default)|
||Amplitude scale (number or
||PNG compression level: 0 (none) to 9 (best), or -1 (default)|
In general, you should use audiowaveform to create waveform data files (.dat) from input MP3 or WAV audio files, then create waveform images from the waveform data files.
For example, to create a waveform data file from an MP3 file, at 256 samples per point with 8-bit resolution:
$ audiowaveform -i test.mp3 -o test.dat -z 256 -b 8
Then, to create a PNG image of a waveform, either specify the zoom level, in samples per pixel, or the time region to render.
The following command creates a 1000x200 pixel PNG image from a waveform data file, at 50 pixels per second, starting at 5.0 seconds from the start of the audio:
$ audiowaveform -i test.dat -o test.png --pixels-per-second 50 -s 5.0 -w 1000 -h 200
This command creates a 1000x200 pixel PNG image from a waveform data file, showing the region from 45.0 seconds to 60.0 seconds from the start of the audio:
$ audiowaveform -i test.dat -o test.png -s 45.0 -e 60.0 -w 1000 -h 200
Note that it is not possible to set a zoom level less than that used to create the original waveform data file.
It is also possible to create PNG images directly from either MP3 or WAV files, although if you want to render multiple images from the same audio file, it's generally preferable to first create a waveform data (.dat) file, and create the images from that, as decoding long MP3 files can take significant time.
The following command creates a 1000x200 PNG image directly from a WAV file, at 300 samples per pixel, starting at 60.0 seconds from the start of the audio:
$ audiowaveform -i test.wav -o test.png -z 300 -s 60.0 -w 1000 -h 200
The following command converts a waveform data file (.dat) to JSON format:
$ audiowaveform -i test.dat -o test.json
In addition, audiowaveform can also be used to convert MP3 to WAV format audio:
$ audiowaveform -i test.mp3 -o test.wav
This program contains code from the following open-source projects, used under the terms of these projects' respective licenses:
See COPYING for details.
If you have a feature request or want to report a bug, we'd be happy to hear from you. Please either raise an issue, or fork the project and send us a pull request.
This software was written by Chris Needham, chris.needham at bbc.co.uk.
Copyright 2013-2016 British Broadcasting Corporation