mp3preview 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/History.txt +4 -0
- data/Manifest.txt +16 -0
- data/PostInstall.txt +7 -0
- data/README.rdoc +48 -0
- data/Rakefile +26 -0
- data/example/wave.rb +3 -0
- data/lib/mp3preview.rb +7 -0
- data/lib/mp3preview/mp3_preview.rb +106 -0
- data/script/console +10 -0
- data/script/console.cmd +1 -0
- data/script/destroy +14 -0
- data/script/destroy.cmd +1 -0
- data/script/generate +14 -0
- data/script/generate.cmd +1 -0
- data/test/test_helper.rb +3 -0
- data/test/test_mp3preview.rb +11 -0
- metadata +94 -0
data/History.txt
ADDED
data/Manifest.txt
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
History.txt
|
2
|
+
Manifest.txt
|
3
|
+
PostInstall.txt
|
4
|
+
README.rdoc
|
5
|
+
Rakefile
|
6
|
+
example/wave.rb
|
7
|
+
lib/mp3preview.rb
|
8
|
+
lib/mp3preview/mp3_preview.rb
|
9
|
+
script/console
|
10
|
+
script/console.cmd
|
11
|
+
script/destroy
|
12
|
+
script/destroy.cmd
|
13
|
+
script/generate
|
14
|
+
script/generate.cmd
|
15
|
+
test/test_helper.rb
|
16
|
+
test/test_mp3preview.rb
|
data/PostInstall.txt
ADDED
data/README.rdoc
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
= mp3preview
|
2
|
+
|
3
|
+
* http://github.com/strny/mp3preview
|
4
|
+
|
5
|
+
== DESCRIPTION:
|
6
|
+
|
7
|
+
MP3Preview generates a waveform image from given mp3. Lame needed.
|
8
|
+
|
9
|
+
== FEATURES/PROBLEMS:
|
10
|
+
|
11
|
+
* FIX (list of features or problems)
|
12
|
+
|
13
|
+
== SYNOPSIS:
|
14
|
+
|
15
|
+
FIX (code sample of usage)
|
16
|
+
|
17
|
+
== REQUIREMENTS:
|
18
|
+
|
19
|
+
* FIX (list of requirements)
|
20
|
+
|
21
|
+
== INSTALL:
|
22
|
+
|
23
|
+
gem install mp3preview
|
24
|
+
|
25
|
+
== LICENSE:
|
26
|
+
|
27
|
+
(The MIT License)
|
28
|
+
|
29
|
+
Copyright (c) 2009 FIXME full name
|
30
|
+
|
31
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
32
|
+
a copy of this software and associated documentation files (the
|
33
|
+
'Software'), to deal in the Software without restriction, including
|
34
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
35
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
36
|
+
permit persons to whom the Software is furnished to do so, subject to
|
37
|
+
the following conditions:
|
38
|
+
|
39
|
+
The above copyright notice and this permission notice shall be
|
40
|
+
included in all copies or substantial portions of the Software.
|
41
|
+
|
42
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
43
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
44
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
45
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
46
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
47
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
48
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
gem 'hoe', '>= 2.1.0'
|
3
|
+
require 'hoe'
|
4
|
+
require 'fileutils'
|
5
|
+
require './lib/mp3preview'
|
6
|
+
|
7
|
+
Hoe.plugin :newgem
|
8
|
+
# Hoe.plugin :website
|
9
|
+
# Hoe.plugin :cucumberfeatures
|
10
|
+
|
11
|
+
# Generate all the Rake tasks
|
12
|
+
# Run 'rake -T' to see list of generated tasks (from gem root directory)
|
13
|
+
$hoe = Hoe.spec 'mp3preview' do
|
14
|
+
self.developer 'Pavel Strnad', 'p.strnad@doradus.cz'
|
15
|
+
# self.post_install_message = 'PostInstall.txt' # TODO remove if post-install message not required
|
16
|
+
self.rubyforge_name = self.name # TODO this is default value
|
17
|
+
self.extra_deps = [['rmagick']]
|
18
|
+
|
19
|
+
end
|
20
|
+
|
21
|
+
require 'newgem/tasks'
|
22
|
+
Dir['tasks/**/*.rake'].each { |t| load t }
|
23
|
+
|
24
|
+
# TODO - want other tests/tasks run by default? Add them to the list
|
25
|
+
# remove_task :default
|
26
|
+
# task :default => [:spec, :features]
|
data/example/wave.rb
ADDED
data/lib/mp3preview.rb
ADDED
@@ -0,0 +1,106 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'RMagick'
|
3
|
+
require 'open3'
|
4
|
+
|
5
|
+
|
6
|
+
class MP3Preview
|
7
|
+
|
8
|
+
#Internal class for representing points
|
9
|
+
class Point
|
10
|
+
attr_reader :x, :y
|
11
|
+
def initialize(x, y)
|
12
|
+
@x = x
|
13
|
+
@y = y
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
attr_reader :file, :output_file, :size, :width, :height, :current_pixel, :chunk_size, :points
|
18
|
+
|
19
|
+
def initialize(file, output_file, width, height)
|
20
|
+
@file = file
|
21
|
+
@output_file = output_file
|
22
|
+
@width = width
|
23
|
+
@height = height
|
24
|
+
@size = get_file_size
|
25
|
+
@chunk_size = set_chunk_size(self.size, self.width)
|
26
|
+
@points = []
|
27
|
+
@current_pixel=-1
|
28
|
+
end
|
29
|
+
|
30
|
+
|
31
|
+
# this is the main method
|
32
|
+
###
|
33
|
+
def generate_image
|
34
|
+
#convert mp3 file to raw, 8-bit, unsigned
|
35
|
+
command = "sox #{self.file} -t raw -b -u -"
|
36
|
+
Open3.popen3(command) do |stdin, stdout, stderr|
|
37
|
+
while buffer = stdout.read(self.chunk_size)
|
38
|
+
write(buffer)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
draw_image
|
42
|
+
end
|
43
|
+
|
44
|
+
|
45
|
+
|
46
|
+
private
|
47
|
+
|
48
|
+
def write(samples)
|
49
|
+
min = 2**7
|
50
|
+
max = -(2**7)
|
51
|
+
samples.each_byte do |sample|
|
52
|
+
sample_int = sample - 128
|
53
|
+
if (max < sample_int)
|
54
|
+
max = sample_int
|
55
|
+
end
|
56
|
+
if (min > sample_int)
|
57
|
+
min = sample_int
|
58
|
+
end
|
59
|
+
end
|
60
|
+
@current_pixel = @current_pixel + 1
|
61
|
+
create_point(self.current_pixel(), max, min)
|
62
|
+
end
|
63
|
+
|
64
|
+
def get_file_size
|
65
|
+
# using sox get number of chunks
|
66
|
+
command = "sox #{self.file} -e stat"
|
67
|
+
out = ''
|
68
|
+
Open3.popen3(command) do |stdin, stdout, stderr|
|
69
|
+
out = stderr.readline
|
70
|
+
end
|
71
|
+
out.split(":")[1].to_i
|
72
|
+
end
|
73
|
+
|
74
|
+
def create_point(pixel, smaxValue, sminValue)
|
75
|
+
#get the max y value for a sound
|
76
|
+
maxValue = 2**7
|
77
|
+
yMax = normalize(smaxValue, maxValue)
|
78
|
+
yMin = normalize(sminValue, maxValue)
|
79
|
+
|
80
|
+
self.points << Point.new(pixel, yMax.to_i)
|
81
|
+
self.points << Point.new(pixel, yMin.to_i)
|
82
|
+
end
|
83
|
+
|
84
|
+
def normalize(value, maxValue)
|
85
|
+
(self.height / 2) + (value.to_f * ((self.height / 2) / maxValue.to_f))
|
86
|
+
end
|
87
|
+
|
88
|
+
def draw_image
|
89
|
+
canvas = Magick::Image.new(width, height)
|
90
|
+
gc = Magick::Draw.new
|
91
|
+
i = 0
|
92
|
+
gc.stroke('blue')
|
93
|
+
while (i < self.points.size)
|
94
|
+
start_point = self.points[i]
|
95
|
+
end_point = self.points[i+1]
|
96
|
+
gc.line(start_point.x, start_point.y, end_point.x, end_point.y)
|
97
|
+
i = i + 2
|
98
|
+
end
|
99
|
+
gc.draw(canvas)
|
100
|
+
canvas.write(self.output_file)
|
101
|
+
end
|
102
|
+
|
103
|
+
def set_chunk_size(size, width)
|
104
|
+
size / width
|
105
|
+
end
|
106
|
+
end
|
data/script/console
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# File: script/console
|
3
|
+
irb = RUBY_PLATFORM =~ /(:?mswin|mingw)/ ? 'irb.bat' : 'irb'
|
4
|
+
|
5
|
+
libs = " -r irb/completion"
|
6
|
+
# Perhaps use a console_lib to store any extra methods I may want available in the cosole
|
7
|
+
# libs << " -r #{File.dirname(__FILE__) + '/../lib/console_lib/console_logger.rb'}"
|
8
|
+
libs << " -r #{File.dirname(__FILE__) + '/../lib/mp3preview.rb'}"
|
9
|
+
puts "Loading mp3preview gem"
|
10
|
+
exec "#{irb} #{libs} --simple-prompt"
|
data/script/console.cmd
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
@ruby script/console %*
|
data/script/destroy
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'rubigen'
|
6
|
+
rescue LoadError
|
7
|
+
require 'rubygems'
|
8
|
+
require 'rubigen'
|
9
|
+
end
|
10
|
+
require 'rubigen/scripts/destroy'
|
11
|
+
|
12
|
+
ARGV.shift if ['--help', '-h'].include?(ARGV[0])
|
13
|
+
RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
|
14
|
+
RubiGen::Scripts::Destroy.new.run(ARGV)
|
data/script/destroy.cmd
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
@ruby script/destroy %*
|
data/script/generate
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'rubigen'
|
6
|
+
rescue LoadError
|
7
|
+
require 'rubygems'
|
8
|
+
require 'rubigen'
|
9
|
+
end
|
10
|
+
require 'rubigen/scripts/generate'
|
11
|
+
|
12
|
+
ARGV.shift if ['--help', '-h'].include?(ARGV[0])
|
13
|
+
RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
|
14
|
+
RubiGen::Scripts::Generate.new.run(ARGV)
|
data/script/generate.cmd
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
@ruby script/generate %*
|
data/test/test_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,94 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: mp3preview
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Pavel Strnad
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-12-01 00:00:00 +01: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: hoe
|
27
|
+
type: :development
|
28
|
+
version_requirement:
|
29
|
+
version_requirements: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 2.4.0
|
34
|
+
version:
|
35
|
+
description: MP3Preview generates a waveform image from given mp3. Lame needed.
|
36
|
+
email:
|
37
|
+
- p.strnad@doradus.cz
|
38
|
+
executables: []
|
39
|
+
|
40
|
+
extensions: []
|
41
|
+
|
42
|
+
extra_rdoc_files:
|
43
|
+
- History.txt
|
44
|
+
- Manifest.txt
|
45
|
+
- PostInstall.txt
|
46
|
+
files:
|
47
|
+
- History.txt
|
48
|
+
- Manifest.txt
|
49
|
+
- PostInstall.txt
|
50
|
+
- README.rdoc
|
51
|
+
- Rakefile
|
52
|
+
- example/wave.rb
|
53
|
+
- lib/mp3preview.rb
|
54
|
+
- lib/mp3preview/mp3_preview.rb
|
55
|
+
- script/console
|
56
|
+
- script/console.cmd
|
57
|
+
- script/destroy
|
58
|
+
- script/destroy.cmd
|
59
|
+
- script/generate
|
60
|
+
- script/generate.cmd
|
61
|
+
- test/test_helper.rb
|
62
|
+
- test/test_mp3preview.rb
|
63
|
+
has_rdoc: true
|
64
|
+
homepage: http://github.com/strny/mp3preview
|
65
|
+
licenses: []
|
66
|
+
|
67
|
+
post_install_message:
|
68
|
+
rdoc_options:
|
69
|
+
- --main
|
70
|
+
- README.rdoc
|
71
|
+
require_paths:
|
72
|
+
- lib
|
73
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
74
|
+
requirements:
|
75
|
+
- - ">="
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: "0"
|
78
|
+
version:
|
79
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - ">="
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: "0"
|
84
|
+
version:
|
85
|
+
requirements: []
|
86
|
+
|
87
|
+
rubyforge_project: mp3preview
|
88
|
+
rubygems_version: 1.3.5
|
89
|
+
signing_key:
|
90
|
+
specification_version: 3
|
91
|
+
summary: MP3Preview generates a waveform image from given mp3
|
92
|
+
test_files:
|
93
|
+
- test/test_mp3preview.rb
|
94
|
+
- test/test_helper.rb
|