Coder Social home page Coder Social logo

loretoparisi / audiowaveform Goto Github PK

View Code? Open in Web Editor NEW

This project forked from bbc/audiowaveform

0.0 2.0 0.0 3.78 MB

C++ program to generate waveform data and render waveform images from audio files

Home Page: https://waveform.prototyping.bbc.co.uk

License: GNU General Public License v3.0

CMake 7.28% C 10.65% C++ 79.29% Makefile 1.63% Roff 0.80% Objective-C 0.36%

audiowaveform's Introduction

Audio Waveform Image Generator

Build Status

audiowaveform is a C++ command-line application that generates waveform data from either MP3, WAV, FLAC, or Ogg Vorbis format audio files. Waveform data can be used to produce a visual rendering of the audio, similar in appearance to audio editing applications.

Example Waveform

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 audio signal by first combining the input 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 output.

Installation

Ubuntu

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

Arch Linux

There is an audiowaveform package available in the AUR.

Mac OSX via Homebrew

To install audiowaveform using Homebrew:

$ brew tap bbc/audiowaveform
$ brew install audiowaveform

Windows

Windows binaries are not currently available. Please follow this issue for details.

Building from source

audiowaveform requires cmake 2.8.7 or later, g++ 4.6.3 or later, and Boost 1.46.0 or later.

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

Fedora

$ sudo dnf install git make cmake gcc-c++ libmad-devel \
  libid3tag-devel libsndfile-devel gd-devel boost-devel

CentOS

If you have not already done so, you should follow the instructions here to add the RPM Fusion free repository. For example, for CentOS 7:

$ sudo yum localinstall --nogpgcheck \
  https://download1.rpmfusion.org/free/el/rpmfusion-free-release-7.noarch.rpm

and then install the dependencies:

$ sudo yum install git make cmake gcc-c++ libmad-devel \
  libid3tag-devel libsndfile-devel gd-devel boost-devel

Ubuntu

$ sudo apt-get install git make cmake gcc g++ libmad0-dev \
  libid3tag0-dev libsndfile1-dev libgd-dev libboost-filesystem-dev \
  libboost-program-options-dev \
  libboost-regex-dev

Note: for Ubuntu 12.04, replace libgd-dev with libgd2-xpm-dev.

Alpine

$ apk add git make cmake gcc g++ libmad-dev \
  libid3tag-dev libsndfile-dev gd-dev boost-dev

SUSE

$ zypper install git cmake gcc-c++ libmad-devel \
  libid3tag-devel libsndfile-devel gd-devel \
  libboost_filesystem1_67_0-devel \
  libboost_program_options1_67_0-devel \
  libboost_regex1_67_0-devel

Note: replace 1_67_0 with the boost version actually available.

Mac OSX

Install XCode and Homebrew, then:

$ 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

audiowaveform uses Google Test for unit testing. Following this advice in the Google Test FAQ, download the source and unzip:

$ 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

Build

$ 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:

$ cmake -D CMAKE_BUILD_TYPE=Debug ..

If you don't want to compile the unit tests add -D ENABLE_TESTS=0:

$ cmake -D ENABLE_TESTS=0 ..

To statically link the library dependencies add -D BUILD_STATIC=1, for example:

$ cmake -D BUILD_STATIC=1 ..

To compile with clang instead of g++:

$ cmake -D CMAKE_C_COMPILER=/usr/local/bin/clang -D CMAKE_CXX_COMPILER=/usr/local/bin/clang++ ..

Test

$ make test

To see detailed test output:

$ ./audiowaveform_tests

Install

$ sudo make install

By default this installs the audiowaveform program in /usr/local/bin, and man pages in /usr/local/share/man. To change these locations, add a -D CMAKE_INSTALL_PREFIX=... option when invoking cmake above.

Run

$ audiowaveform --help

Command line options

audiowaveform accepts the following command-line options:

Short Long Description
--help Show help message
-v --version Show version information
-i <filename> --input-filename <filename> Input audio (.wav, .flac, .mp3, or .ogg) or waveform data (.dat) file name
-o <filename> --output-filename <filename> Output waveform data (.dat or .json), audio (.wav), or PNG image (.png) file name
-z <level> --zoom <zoom> Zoom level (samples per pixel), default: 256. Not valid if --end or --pixels-per-second is also specified
--pixels-per-second <zoom> Zoom level (pixels per second), default: 100. Not valid if --end or --zoom is also specified
-b <bits> --bits <bits> Number of bits resolution when creating a waveform data file (either 8 or 16), default: 16
--split-channels Output files are multi-channel, not combined into a single waveform
-s <seconds> --start <seconds> Start time (seconds), default: 0
-e <seconds> --end <seconds> End time (seconds). Not valid if --zoom is also specified
-w <width> --width <width> Width of output image (pixels), default: 800
-h <height> --height <height> Height of output image (pixels), default: 250
-c <scheme> --colors <scheme> Color scheme of output image (either 'audition' or 'audacity'), default: audacity
--border-color <color> Border color (in rrggbb[aa] hex format), default: set by --colors option
--background-color <color> Background color (in rrggbb[aa] hex format), default: set by --colors option
--waveform-color <color> Waveform color (in rrggbb[aa] hex format), default: set by --colors option
--axis-label-color <color> Axis label color (in rrggbb[aa] hex format), default: set by --colors option
--no-axis-labels Render PNG images without axis labels
--with-axis-labels Render PNG images with axis labels (default)
--amplitude-scale <scale> Amplitude scale (number or auto), default: 1
--compression <level> PNG compression level: 0 (none) to 9 (best), or -1 (default)

Usage

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.

To create a waveform data file containing multiple channels, rather than combining all channels into a single waveform:

$ audiowaveform -i test.mp3 -o test.dat -z 256 -b 8 --split-channels

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

If you are using audiowaveform to generate waveform data for use in a web application, e.g, using Peaks.js, you can choose whether to use binary or JSON format waveform data.

The following command generates waveform data in JSON format:

$ audiowaveform -i test.flac -o test.json -z 256 -b 8

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

Data Formats

You can find details of the waveform data file formats produced by audiowaveform here.

Credits

This program contains code from the following open-source projects, used under the terms of these projects' respective licenses:

License

See COPYING for details.

Contributing

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.

Authors

This software was written by Chris Needham, chris.needham at bbc.co.uk.

Copyright

Copyright 2013-2018 British Broadcasting Corporation

audiowaveform's People

Contributors

alt- avatar chrisn avatar dbpolito avatar moustaki avatar nullr0ute avatar oskarpersson avatar pr0ps avatar thom4parisot avatar wincentbalin avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.