tsunami 0.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.gitignore +21 -0
- data/LICENSE +20 -0
- data/README.rdoc +17 -0
- data/Rakefile +55 -0
- data/VERSION +1 -0
- data/lib/tsunami.rb +101 -0
- data/test/helper.rb +10 -0
- data/test/test_tsunami.rb +7 -0
- data/tsunami.gemspec +60 -0
- metadata +95 -0
data/.document
ADDED
data/.gitignore
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 Andrei Bocan
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
= tsunami
|
2
|
+
|
3
|
+
Horrible, just horrible =(
|
4
|
+
|
5
|
+
== Note on Patches/Pull Requests
|
6
|
+
|
7
|
+
* Fork the project.
|
8
|
+
* Make your feature addition or bug fix.
|
9
|
+
* Add tests for it. This is important so I don't break it in a
|
10
|
+
future version unintentionally.
|
11
|
+
* Commit, do not mess with rakefile, version, or history.
|
12
|
+
(if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
|
13
|
+
* Send me a pull request. Bonus points for topic branches.
|
14
|
+
|
15
|
+
== Copyright
|
16
|
+
|
17
|
+
Copyright (c) 2010 Andrei Bocan. See LICENSE for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = "tsunami"
|
8
|
+
gem.summary = %Q{It draws waveforms.}
|
9
|
+
gem.description = %Q{For reals, it draws waveforms, man}
|
10
|
+
gem.email = "zmaxor@gmail.com"
|
11
|
+
gem.homepage = "http://github.com/zmack/tsunami"
|
12
|
+
gem.authors = ["Andrei Bocan"]
|
13
|
+
gem.add_dependency "rmagick", ">= 0"
|
14
|
+
gem.add_dependency "narray", ">= 0"
|
15
|
+
gem.add_development_dependency "thoughtbot-shoulda", ">= 0"
|
16
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
17
|
+
end
|
18
|
+
Jeweler::GemcutterTasks.new
|
19
|
+
rescue LoadError
|
20
|
+
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
21
|
+
end
|
22
|
+
|
23
|
+
require 'rake/testtask'
|
24
|
+
Rake::TestTask.new(:test) do |test|
|
25
|
+
test.libs << 'lib' << 'test'
|
26
|
+
test.pattern = 'test/**/test_*.rb'
|
27
|
+
test.verbose = true
|
28
|
+
end
|
29
|
+
|
30
|
+
begin
|
31
|
+
require 'rcov/rcovtask'
|
32
|
+
Rcov::RcovTask.new do |test|
|
33
|
+
test.libs << 'test'
|
34
|
+
test.pattern = 'test/**/test_*.rb'
|
35
|
+
test.verbose = true
|
36
|
+
end
|
37
|
+
rescue LoadError
|
38
|
+
task :rcov do
|
39
|
+
abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
task :test => :check_dependencies
|
44
|
+
|
45
|
+
task :default => :test
|
46
|
+
|
47
|
+
require 'rake/rdoctask'
|
48
|
+
Rake::RDocTask.new do |rdoc|
|
49
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
50
|
+
|
51
|
+
rdoc.rdoc_dir = 'rdoc'
|
52
|
+
rdoc.title = "tsunami #{version}"
|
53
|
+
rdoc.rdoc_files.include('README*')
|
54
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
55
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.0.0
|
data/lib/tsunami.rb
ADDED
@@ -0,0 +1,101 @@
|
|
1
|
+
#this class was inspired by rjp's awesome http://github.com/rjp/cdcover
|
2
|
+
require 'rubygems'
|
3
|
+
require 'RMagick'
|
4
|
+
require 'narray'
|
5
|
+
|
6
|
+
class Tsunami
|
7
|
+
|
8
|
+
attr_accessor :size, :width, :height
|
9
|
+
attr_accessor :audio_file, :image_file
|
10
|
+
attr_accessor :bitrate
|
11
|
+
attr_accessor :offset
|
12
|
+
|
13
|
+
def initialize size, audio_file, image_file
|
14
|
+
# graph parameters
|
15
|
+
@size = size
|
16
|
+
@width = (@size).to_i
|
17
|
+
@height = 130
|
18
|
+
@bitrate = '500'
|
19
|
+
@offset = 5
|
20
|
+
@audio_file = audio_file
|
21
|
+
@image_file = image_file
|
22
|
+
#testing_parameters
|
23
|
+
end
|
24
|
+
|
25
|
+
def create_waveform_image
|
26
|
+
buckets = fill_buckets width,@audio_file
|
27
|
+
p buckets
|
28
|
+
p size
|
29
|
+
gc = build_graph buckets,size
|
30
|
+
#create new image canvas
|
31
|
+
canvas = Magick::Image.new(@width + 20, @height) { self.background_color = 'transparent' }
|
32
|
+
# canvas = Magick::ImageList.new('images/waveform.png')
|
33
|
+
gc.draw(canvas)
|
34
|
+
canvas.write(@image_file)
|
35
|
+
end
|
36
|
+
|
37
|
+
#fill the buckets
|
38
|
+
def fill_buckets width,file
|
39
|
+
buckets = NArray.int(width,2)
|
40
|
+
#let sox fetch the byte array
|
41
|
+
bytes = sox_get_bytes file
|
42
|
+
bucket_size = (((bytes.size-1).to_f / width)+0.5).to_i + 1
|
43
|
+
(0..bytes.total-1).each do |i|
|
44
|
+
value = bytes[i]
|
45
|
+
index = i/bucket_size
|
46
|
+
#minimum
|
47
|
+
buckets[index,0] = value if value < buckets[index,0]
|
48
|
+
#maximum
|
49
|
+
buckets[index,1] = value if value > buckets[index,1]
|
50
|
+
#total value
|
51
|
+
#buckets[index,2] += value
|
52
|
+
#count
|
53
|
+
#buckets[index,3] += 1
|
54
|
+
#negative total
|
55
|
+
#buckets[index,4] += value if value < 0
|
56
|
+
#positive total
|
57
|
+
#buckets[index,5] += value if value > 0
|
58
|
+
end
|
59
|
+
return buckets
|
60
|
+
end
|
61
|
+
|
62
|
+
#open file with sox and return a byte array with sweet waveform information in it
|
63
|
+
def sox_get_bytes file, channels = 1
|
64
|
+
x=nil
|
65
|
+
# read a 16 bit linear raw PCM file
|
66
|
+
sox_command = [ 'sox', file, '-t', 'raw', '-r', @bitrate, '-c', channels.to_s, '-s', '-L', '-' ]
|
67
|
+
# we have to fork/exec to get a clean commandline
|
68
|
+
IO.popen('-') { |p|
|
69
|
+
if p.nil? then
|
70
|
+
$stderr.close
|
71
|
+
# raw 16 bit linear PCM one channel
|
72
|
+
exec *sox_command
|
73
|
+
end
|
74
|
+
x = p.read
|
75
|
+
}
|
76
|
+
if x.size == 0 then
|
77
|
+
puts "sox returned no data, command was\n> #{sox_command.join(' ')}"
|
78
|
+
exit 1
|
79
|
+
end
|
80
|
+
return NArray.to_na(x.unpack("s*"))
|
81
|
+
end
|
82
|
+
|
83
|
+
#build the waveform graph
|
84
|
+
def build_graph buckets,size
|
85
|
+
gc = Magick::Draw.new
|
86
|
+
scale = 32768/@height*2.75
|
87
|
+
midpoint = @height/2
|
88
|
+
p buckets.size
|
89
|
+
(0..(buckets.size/2)-1).each do |i|
|
90
|
+
low = buckets[i,0]
|
91
|
+
high = buckets[i,1]
|
92
|
+
gc.stroke('red')
|
93
|
+
gc.stroke_width(1)
|
94
|
+
low_point = midpoint+low/scale
|
95
|
+
high_point = midpoint+high/scale
|
96
|
+
gc.line(i+@offset, low_point.to_i, i+@offset, high_point.to_i)
|
97
|
+
puts "#{i+@offset}, #{low_point.to_i}, #{i+@offset}, #{high_point.to_i}"
|
98
|
+
end
|
99
|
+
return gc
|
100
|
+
end
|
101
|
+
end
|
data/test/helper.rb
ADDED
data/tsunami.gemspec
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{tsunami}
|
8
|
+
s.version = "0.0.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Andrei Bocan"]
|
12
|
+
s.date = %q{2010-03-09}
|
13
|
+
s.description = %q{For reals, it draws waveforms, man}
|
14
|
+
s.email = %q{zmaxor@gmail.com}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE",
|
17
|
+
"README.rdoc"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".document",
|
21
|
+
".gitignore",
|
22
|
+
"LICENSE",
|
23
|
+
"README.rdoc",
|
24
|
+
"Rakefile",
|
25
|
+
"VERSION",
|
26
|
+
"lib/tsunami.rb",
|
27
|
+
"test/helper.rb",
|
28
|
+
"test/test_tsunami.rb",
|
29
|
+
"tsunami.gemspec"
|
30
|
+
]
|
31
|
+
s.homepage = %q{http://github.com/zmack/tsunami}
|
32
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
33
|
+
s.require_paths = ["lib"]
|
34
|
+
s.rubygems_version = %q{1.3.5}
|
35
|
+
s.summary = %q{It draws waveforms.}
|
36
|
+
s.test_files = [
|
37
|
+
"test/helper.rb",
|
38
|
+
"test/test_tsunami.rb"
|
39
|
+
]
|
40
|
+
|
41
|
+
if s.respond_to? :specification_version then
|
42
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
43
|
+
s.specification_version = 3
|
44
|
+
|
45
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
46
|
+
s.add_runtime_dependency(%q<rmagick>, [">= 0"])
|
47
|
+
s.add_runtime_dependency(%q<narray>, [">= 0"])
|
48
|
+
s.add_development_dependency(%q<thoughtbot-shoulda>, [">= 0"])
|
49
|
+
else
|
50
|
+
s.add_dependency(%q<rmagick>, [">= 0"])
|
51
|
+
s.add_dependency(%q<narray>, [">= 0"])
|
52
|
+
s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
|
53
|
+
end
|
54
|
+
else
|
55
|
+
s.add_dependency(%q<rmagick>, [">= 0"])
|
56
|
+
s.add_dependency(%q<narray>, [">= 0"])
|
57
|
+
s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
metadata
ADDED
@@ -0,0 +1,95 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: tsunami
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Andrei Bocan
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2010-03-09 00:00:00 +02:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: rmagick
|
17
|
+
type: :runtime
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: "0"
|
24
|
+
version:
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: narray
|
27
|
+
type: :runtime
|
28
|
+
version_requirement:
|
29
|
+
version_requirements: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: "0"
|
34
|
+
version:
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
name: thoughtbot-shoulda
|
37
|
+
type: :development
|
38
|
+
version_requirement:
|
39
|
+
version_requirements: !ruby/object:Gem::Requirement
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: "0"
|
44
|
+
version:
|
45
|
+
description: For reals, it draws waveforms, man
|
46
|
+
email: zmaxor@gmail.com
|
47
|
+
executables: []
|
48
|
+
|
49
|
+
extensions: []
|
50
|
+
|
51
|
+
extra_rdoc_files:
|
52
|
+
- LICENSE
|
53
|
+
- README.rdoc
|
54
|
+
files:
|
55
|
+
- .document
|
56
|
+
- .gitignore
|
57
|
+
- LICENSE
|
58
|
+
- README.rdoc
|
59
|
+
- Rakefile
|
60
|
+
- VERSION
|
61
|
+
- lib/tsunami.rb
|
62
|
+
- test/helper.rb
|
63
|
+
- test/test_tsunami.rb
|
64
|
+
- tsunami.gemspec
|
65
|
+
has_rdoc: true
|
66
|
+
homepage: http://github.com/zmack/tsunami
|
67
|
+
licenses: []
|
68
|
+
|
69
|
+
post_install_message:
|
70
|
+
rdoc_options:
|
71
|
+
- --charset=UTF-8
|
72
|
+
require_paths:
|
73
|
+
- lib
|
74
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
75
|
+
requirements:
|
76
|
+
- - ">="
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
version: "0"
|
79
|
+
version:
|
80
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
81
|
+
requirements:
|
82
|
+
- - ">="
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
version: "0"
|
85
|
+
version:
|
86
|
+
requirements: []
|
87
|
+
|
88
|
+
rubyforge_project:
|
89
|
+
rubygems_version: 1.3.5
|
90
|
+
signing_key:
|
91
|
+
specification_version: 3
|
92
|
+
summary: It draws waveforms.
|
93
|
+
test_files:
|
94
|
+
- test/helper.rb
|
95
|
+
- test/test_tsunami.rb
|