Rendering an mp3 as a waveform image in ruby?? : RUBY

This is a discussion on Rendering an mp3 as a waveform image in ruby?? within the RUBY forums in Programming Languages category; Does anyone know of a way, in ruby, to render an mp3 into a waveform graphic? Like you'd see in audio editing tools like Audacity, Soundforge etc. Just a jpeg as the end result is fine. Hoping there might be a gem out there for this... thanks max -- Posted via http://www.ruby-forum.com/ ....

Go Back   ObjectMix Forum > Programming Languages > RUBY

Object Mix

Register FAQ Calendar Search Today's Posts Mark Forums Read
  #1  
Old 07-24-2008, 10:29 AM
Max Williams
Guest
 
Default Rendering an mp3 as a waveform image in ruby??

Does anyone know of a way, in ruby, to render an mp3 into a waveform
graphic? Like you'd see in audio editing tools like Audacity,
Soundforge etc. Just a jpeg as the end result is fine. Hoping there
might be a gem out there for this...

thanks
max
--
Posted via http://www.ruby-forum.com/.

Reply With Quote
  #2  
Old 07-24-2008, 01:28 PM
Farrel Lifson
Guest
 
Default Re: Rendering an mp3 as a waveform image in ruby??

2008/7/24 Max Williams <toastkid.williams@gmail.com>:
> Does anyone know of a way, in ruby, to render an mp3 into a waveform
> graphic? Like you'd see in audio editing tools like Audacity,
> Soundforge etc. Just a jpeg as the end result is fine. Hoping there
> might be a gem out there for this...


I don't think there's a Ruby gem to allow direct decoding of mp3
files, however it should be doable using mpg123 or some other program
callable from the shell which can decode mp3's.

The command 'mpg123 -O file.raw file.mp3' produces raw 16bit stereo
PCM data (I think sampled at 22KHz) from the .mp3 file and stores it
in the .raw file. So for every 4 bytes you read the first two bytes
would be the signal strength of the one channel and the second two
bytes would be the signal strength of the second channel. You could
then use String#unpack (I think 'ss' will unpack to shorts, which were
signed 16bits last I checked) to decode these bytes and get the values
you need. You could then plot these values using a gem like RMagick. I
haven't executed this code but it could look like:

File.open('file.raw') do |file|
while !file.eof?
first_channel_data, second_channel_data = file.read(4).unpack('ss')
# Plot data here
end
end

Farrel
--
Aimred - Ruby and Rails Development and Consulting
http://www.aimred.com

Reply With Quote
  #3  
Old 07-25-2008, 03:34 AM
Max Williams
Guest
 
Default Re: Rendering an mp3 as a waveform image in ruby??

Ah, that's useful, thanks farrel.
--
Posted via http://www.ruby-forum.com/.

Reply With Quote
Reply


Thread Tools


All times are GMT -5. The time now is 07:21 PM.


Powered by vBulletin® Version 3.7.2
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
vB Ad Management by =RedTyger=

In an effort to better serve ads to our visitors, cookies are used on objectmix.com. For more information, check out our Privacy Policy.