Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Proof of concept for creating mp3 waveforms
Ruby
branch: master

README.markdown

mp3 to png

Requirements:

  • mpg123 (cli tool, on OSX install with sudo port install mpg123)
  • gruff (gem)

Generate raw file

With an intermediate raw file

mpg123 -d 192 -O file.raw 2009-11-15-1830.mp3
./wave.rb file.raw

Inline on CLI

mpg123 -s -d 192 2009-11-15-1830.mp3 | ./wave.rb

Some explanation on mpg123 options: (see also mpg123 --longhelp)

-d n   --doublespeed n    play only every nth frame
-s     --stdout           write raw audio to stdout (host native format)
-O                        raw output filename

ToDo:

  • wrap it up in tests
  • Using gruff for the moment, maybe we get some inprovements when we're using RMagic directly (not sure)

Some Stats

Some outputted examples

(test done with a 24 kbit/s, 24000 Hz mono file)

The higher the rate, the less samples are used. This also makes the waveform less dense.

Rate:    4, Time taken to generate image: 13.44 sec
Rate:   16, Time taken to generate image: 3.68 sec
Rate:   32, Time taken to generate image: 1.94 sec
Rate:   64, Time taken to generate image: 0.95 sec
Rate:  128, Time taken to generate image: 0.50 sec
Rate:  256, Time taken to generate image: 0.35 sec
Rate:  512, Time taken to generate image: 0.20 sec
Rate: 1024, Time taken to generate image: 0.12 sec
Rate: 2048, Time taken to generate image: 0.08 sec

example at a rate of 4    example at a rate of 512  example at a rate of 2048 example at a rate of 16384 example at a rate of 32768

More reading:


Created by Leon Berenschot
Copyright (c) 2009 Wendbaar.nl. All rights reserved.

Something went wrong with that request. Please try again.