Introduction
Introduction Statistics Contact Development Disclaimer Help
Add gzip support for raw audio files, import the media generator - warvox - VoI…
Log
Files
Refs
README
---
commit a64de8bc7baea28846729624cb83ec8d32b6d46c
parent 3a47479fdb9dc463945b69e36fe5a1a71a3f4bc8
Author: HD Moore <[email protected]>
Date: Sun, 15 Feb 2009 03:47:45 +0000
Add gzip support for raw audio files, import the media generator
Diffstat:
M bin/create_flowdb.rb | 6 +++---
A bin/create_media.rb | 84 +++++++++++++++++++++++++++++…
M lib/warvox/audio/raw.rb | 7 +++++++
3 files changed, 94 insertions(+), 3 deletions(-)
---
diff --git a/bin/create_flowdb.rb b/bin/create_flowdb.rb
@@ -26,12 +26,12 @@ db = File.new(dst, "w")
dir = Dir.new(src)
cnt = 0
-set = dir.entries.sort.grep(/\.raw$/)
+set = dir.entries.sort.grep(/\.raw/)
set.each do |ent|
- next if not ent =~ /\.raw$/
+ next if not ent =~ /\.raw/
puts "[*] [#{sprintf("%.5d/%.5d", cnt+1, set.length)}] Processing #{en…
raw = WarVOX::Audio::Raw.from_file( File.join(src, ent) )
- db.write( ent.gsub('.raw', '') + " " + raw.to_flow + "\n" )
+ db.write( ent.gsub(/\.raw|\.gz/, '') + " " + raw.to_flow + "\n" )
cnt += 1
end
diff --git a/bin/create_media.rb b/bin/create_media.rb
@@ -0,0 +1,84 @@
+#!/usr/bin/env ruby
+###################
+
+#
+# Load the library path
+#
+base = __FILE__
+while File.symlink?(base)
+ base = File.expand_path(File.readlink(base), File.dirname(base))
+end
+$:.unshift(File.join(File.expand_path(File.dirname(base)), '..', 'lib'))
+require 'warvox'
+
+#
+# Script
+#
+
+def usage
+ $stderr.puts "#{$0} [/path/to/raw/data/] <destination dir> "
+ exit
+end
+
+require "fileutils"
+require "tempfile"
+
+src = ARGV.shift || usage
+dst = ARGV.shift || File.join(File.dirname(base), '..', 'data', 'media')
+
+FileUtils.mkdir_p(dst)
+
+calls = []
+dir = Dir.new(src)
+dir.entries.sort.each do |ent|
+
+ path = File.join(src, ent)
+ next if ent !~ /(.*)\.raw/m
+ num = $1
+
+ puts "Processing #{num}..."
+
+ # Decompress the audio file
+ rawfile = Tempfile.new("rawfile")
+ datfile = Tempfile.new("datfile")
+
+ cnt = 0
+ raw = WarVOX::Audio::Raw.from_file(path)
+ rawfile.write(raw.samples.pack('v*'))
+ datfile.write(raw.samples.map{|val| cnt +=1; "#{cnt} #{val}"}.join("\n…
+ rawfile.flush
+ datfile.flush
+
+ # Plot samples to a graph
+ plotter = Tempfile.new("gnuplot")
+
+ plotter.puts("set ylabel \"Signal\"")
+ plotter.puts("set xlabel \"Time\"")
+
+ plotter.puts("set terminal png medium size 640,480 transparent")
+ plotter.puts("set output \"#{dst}/#{num}_big.png\"")
+ plotter.puts("plot \"#{datfile.path}\" using 1:2 title \"#{num}\" with…
+
+ plotter.puts("set output \"#{dst}/#{num}_big_dots.png\"")
+ plotter.puts("plot \"#{datfile.path}\" using 1:2 title \"#{num}\" with…
+
+ plotter.puts("set terminal png small size 160,120 transparent")
+ plotter.puts("set format x ''")
+ plotter.puts("set format y ''")
+ plotter.puts("set output \"#{dst}/#{num}.png\"")
+ plotter.puts("plot \"#{datfile.path}\" using 1:2 title \"#{num}\" with…
+ plotter.flush
+
+ system("gnuplot #{plotter.path}")
+ File.unlink(plotter.path)
+ File.unlink(datfile.path)
+ plotter.close
+ datfile.close
+
+ # Generate a MP3 audio file
+ system("sox -s -w -r 8000 -t raw -c 1 #{rawfile.path} #{dst}/#{num}.wa…
+ system("lame #{dst}/#{num}.wav #{dst}/#{num}.mp3 >/dev/null 2>&1")
+ File.unlink("#{dst}/#{num}.wav")
+ File.unlink(rawfile.path)
+ rawfile.close
+end
diff --git a/lib/warvox/audio/raw.rb b/lib/warvox/audio/raw.rb
@@ -1,6 +1,9 @@
module WarVOX
module Audio
class Raw
+
+
+ require 'zlib'
##
# RAW AUDIO - 8khz little-endian 16-bit signed
@@ -26,6 +29,10 @@ class Raw
if(not File.readable?(path))
raise Error, "The specified audio file does not exist"
end
+
+ if(path =~ /\.gz$/)
+ return self.new(Zlib::GzipReader.open(path).read)
+ end
self.new(File.read(path, File.size(path)))
end
You are viewing proxied material from jay.scot. The copyright of proxied material belongs to its original authors. Any comments or complaints in relation to proxied material should be directed to the original authors of the content concerned. Please see the disclaimer for more details.