lamer 0.1.0 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +33 -0
- data/VERSION +1 -1
- data/lamer.gemspec +55 -0
- data/lib/lamer.rb +119 -0
- data/spec/decoding_spec.rb +18 -0
- data/spec/encoding_spec.rb +161 -0
- data/spec/lamer_spec.rb +126 -0
- data/spec/output.mp3 +0 -0
- data/spec/spec_helper.rb +16 -0
- data/spec/test.mp3 +0 -0
- metadata +16 -4
- data/spec/lame_encoder_spec.rb +0 -302
data/Rakefile
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = "lamer"
|
8
|
+
gem.summary = "Ruby wrapper for the LAME library"
|
9
|
+
gem.description = "Ruby wrapper for the LAME library. Currently wraps around the LAME executable so you can use LAME in your Ruby programs."
|
10
|
+
gem.email = "mauricio@edge14.com"
|
11
|
+
gem.homepage = "http://github.com/mgomes/lamer"
|
12
|
+
gem.authors = ["Chris Anderson", "Mauricio Gomes"]
|
13
|
+
end
|
14
|
+
Jeweler::GemcutterTasks.new
|
15
|
+
rescue LoadError
|
16
|
+
puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
|
17
|
+
end
|
18
|
+
|
19
|
+
require 'spec/rake/spectask'
|
20
|
+
Spec::Rake::SpecTask.new(:spec) do |spec|
|
21
|
+
spec.libs << 'lib' << 'spec'
|
22
|
+
spec.spec_files = FileList['spec/**/*_spec.rb']
|
23
|
+
end
|
24
|
+
|
25
|
+
Spec::Rake::SpecTask.new(:rcov) do |spec|
|
26
|
+
spec.libs << 'lib' << 'spec'
|
27
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
28
|
+
spec.rcov = true
|
29
|
+
end
|
30
|
+
|
31
|
+
task :spec => :check_dependencies
|
32
|
+
|
33
|
+
task :default => :spec
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.2
|
data/lamer.gemspec
ADDED
@@ -0,0 +1,55 @@
|
|
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{lamer}
|
8
|
+
s.version = "0.1.2"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Chris Anderson", "Mauricio Gomes"]
|
12
|
+
s.date = %q{2010-02-09}
|
13
|
+
s.description = %q{Ruby wrapper for the LAME library. Currently wraps around the LAME executable so you can use LAME in your Ruby programs.}
|
14
|
+
s.email = %q{mauricio@edge14.com}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE",
|
17
|
+
"README.md"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
"LICENSE",
|
21
|
+
"README.md",
|
22
|
+
"Rakefile",
|
23
|
+
"VERSION",
|
24
|
+
"lamer.gemspec",
|
25
|
+
"lib/lamer.rb",
|
26
|
+
"spec/decoding_spec.rb",
|
27
|
+
"spec/encoding_spec.rb",
|
28
|
+
"spec/lamer_spec.rb",
|
29
|
+
"spec/output.mp3",
|
30
|
+
"spec/spec_helper.rb",
|
31
|
+
"spec/test.mp3"
|
32
|
+
]
|
33
|
+
s.homepage = %q{http://github.com/mgomes/lamer}
|
34
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
35
|
+
s.require_paths = ["lib"]
|
36
|
+
s.rubygems_version = %q{1.3.5}
|
37
|
+
s.summary = %q{Ruby wrapper for the LAME library}
|
38
|
+
s.test_files = [
|
39
|
+
"spec/decoding_spec.rb",
|
40
|
+
"spec/encoding_spec.rb",
|
41
|
+
"spec/lamer_spec.rb",
|
42
|
+
"spec/spec_helper.rb"
|
43
|
+
]
|
44
|
+
|
45
|
+
if s.respond_to? :specification_version then
|
46
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
47
|
+
s.specification_version = 3
|
48
|
+
|
49
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
50
|
+
else
|
51
|
+
end
|
52
|
+
else
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
data/lib/lamer.rb
ADDED
@@ -0,0 +1,119 @@
|
|
1
|
+
class Lamer
|
2
|
+
|
3
|
+
# These constants come from the LAME documentation
|
4
|
+
MP3_Bitrates = [32, 40, 48, 56, 64, 80, 96, 112, 128, 160, 192, 224, 256, 320]
|
5
|
+
Sample_Rates = [8, 11.025, 12, 16, 22.05, 24, 32, 44.1, 48]
|
6
|
+
Encoding_Quality = (0..9)
|
7
|
+
VBR_Quality = (0..6)
|
8
|
+
Channels = {:mono => 'm', :stereo => 's', :joint => 'j', :auto => 'a', :mid_side => 'f'}
|
9
|
+
Replay_Gain = {:fast => "--replaygain-fast", :accurate => "--replaygain-accurate",
|
10
|
+
:none => "--noreplaygain", :clip_detect => "--clipdetect", :default => nil}
|
11
|
+
|
12
|
+
attr_accessor :options, :id3_options
|
13
|
+
|
14
|
+
def initialize
|
15
|
+
@options = {}
|
16
|
+
end
|
17
|
+
|
18
|
+
def argument_list
|
19
|
+
@options.delete :id3_version unless @id3_options
|
20
|
+
@options.collect {|k,v| v}.join(' ')
|
21
|
+
end
|
22
|
+
|
23
|
+
def command_line
|
24
|
+
raise ArgumentError, "No input file specified." unless @input_file
|
25
|
+
['lame', argument_list, @input_file, @output_file, id3_arguments].select{|x| !(x.nil? || x.empty?)}.join(' ')
|
26
|
+
end
|
27
|
+
|
28
|
+
def convert!
|
29
|
+
system command_line
|
30
|
+
end
|
31
|
+
|
32
|
+
# methods for setting options on the encoder
|
33
|
+
|
34
|
+
def sample_rate(rate)
|
35
|
+
raise ArgumentError unless Sample_Rates.include? rate
|
36
|
+
@options[:sample_rate] = "--resample #{rate}"
|
37
|
+
end
|
38
|
+
|
39
|
+
def bitrate(kbps)
|
40
|
+
raise ArgumentError, "legal bitrates: #{MP3_Bitrates.join(', ')}" unless MP3_Bitrates.include? kbps
|
41
|
+
@options[:bitrate] = "-b #{kbps}"
|
42
|
+
end
|
43
|
+
|
44
|
+
def encode_quality(quality)
|
45
|
+
quality_keys = Hash.new { |h,k| k }.merge( { :high => 2, :fast => 7 } )
|
46
|
+
quality = quality_keys[quality]
|
47
|
+
raise ArgumentError, "legal qualities: #{Encoding_Quality.to_a.join(', ')}" unless Encoding_Quality.include? quality
|
48
|
+
@options[:encode_quality] = "-q #{quality}"
|
49
|
+
end
|
50
|
+
|
51
|
+
def vbr_quality(quality)
|
52
|
+
raise ArgumentError, "legal qualities: #{VBR_Quality.to_a.join(', ')}" unless VBR_Quality.include? quality
|
53
|
+
@options[:vbr_quality], @options[:vbr] = "-V #{quality}", "-v"
|
54
|
+
end
|
55
|
+
|
56
|
+
def mode(channels)
|
57
|
+
@options[:mode] = Channels[channels] ? "-m #{Channels[channels]}" : nil
|
58
|
+
end
|
59
|
+
|
60
|
+
def replay_gain(gain)
|
61
|
+
@options[:replay_gain] = Replay_Gain[gain]
|
62
|
+
end
|
63
|
+
|
64
|
+
# options for dealing with the input and output files
|
65
|
+
|
66
|
+
def input_file(filename)
|
67
|
+
@input_file = filename
|
68
|
+
mark_as_copy! if filename =~ /\.mp3$/
|
69
|
+
end
|
70
|
+
|
71
|
+
def output_file(filename)
|
72
|
+
@output_file = filename
|
73
|
+
end
|
74
|
+
|
75
|
+
def decode_mp3!
|
76
|
+
@options.clear
|
77
|
+
@options[:decode_mp3] = "--decode"
|
78
|
+
end
|
79
|
+
|
80
|
+
def output_ogg!
|
81
|
+
@options[:output_ogg] = "--ogg"
|
82
|
+
end
|
83
|
+
|
84
|
+
def input_mp3!
|
85
|
+
@options[:input_mp3] = "--mp3input"
|
86
|
+
mark_as_copy!
|
87
|
+
end
|
88
|
+
|
89
|
+
def input_raw(sample_rate, swapbytes = false)
|
90
|
+
@options[:input_raw] = "-r -s #{sample_rate}#{' -x' if swapbytes}"
|
91
|
+
end
|
92
|
+
|
93
|
+
def mark_as_copy!
|
94
|
+
@options[:copy] = "-o"
|
95
|
+
end
|
96
|
+
|
97
|
+
# id3 options
|
98
|
+
|
99
|
+
def id3 options
|
100
|
+
@id3_options = @id3_options ? @id3_options.merge(options) : options
|
101
|
+
end
|
102
|
+
|
103
|
+
def id3_arguments
|
104
|
+
id3_fields = { :title => 'tt', :artist => 'ta', :album => 'tl',
|
105
|
+
:year => 'ty', :comment => 'tc', :track_number => 'tn',
|
106
|
+
:genre => 'tg' }
|
107
|
+
return nil if @id3_options.nil? || @id3_options.empty?
|
108
|
+
@id3_options.select{|k,v| id3_fields[k]}.collect {|k,v| "--#{id3_fields[k]} #{v}"}.join(' ')
|
109
|
+
end
|
110
|
+
|
111
|
+
def id3_version_only version
|
112
|
+
@options[:id3_version] = "--id3v#{version}-only"
|
113
|
+
end
|
114
|
+
|
115
|
+
def id3_add_v2!
|
116
|
+
@options[:id3_version] = "--add-id3v2"
|
117
|
+
end
|
118
|
+
|
119
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper'
|
2
|
+
|
3
|
+
describe "A Lamer, used for decoding," do
|
4
|
+
before(:each) do
|
5
|
+
@la = Lamer.new
|
6
|
+
end
|
7
|
+
|
8
|
+
it "should decode mp3s" do
|
9
|
+
@la.decode_mp3!
|
10
|
+
@la.options[:decode_mp3].should == "--decode"
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should decode mp3s without other options" do
|
14
|
+
@la.vbr_quality 4
|
15
|
+
@la.decode_mp3!
|
16
|
+
@la.options.length.should == 1
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,161 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper'
|
2
|
+
|
3
|
+
describe "A high-quality VBR encoder without a file" do
|
4
|
+
|
5
|
+
before(:each) do
|
6
|
+
@la = Lamer.new
|
7
|
+
@la.vbr_quality 4
|
8
|
+
@la.sample_rate 44.1
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should ouput the correct command line options" do
|
12
|
+
[ /-v/,/-V 4/,/--resample 44\.1/].each do |match|
|
13
|
+
@la.argument_list.should =~ match
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should balk at returning the command line" do
|
18
|
+
lambda {@la.command_line}.should raise_error(ArgumentError)
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should balk at running the conversion" do
|
22
|
+
lambda {@la.convert!}.should raise_error(ArgumentError)
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
|
27
|
+
describe "An encoder with a file specified" do
|
28
|
+
|
29
|
+
before(:each) do
|
30
|
+
@la = Lamer.new
|
31
|
+
@la.input_file "/Path/to/my/audio_file.wav"
|
32
|
+
end
|
33
|
+
|
34
|
+
it "should provide the right command line" do
|
35
|
+
@la.command_line.should == "lame /Path/to/my/audio_file.wav"
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
|
40
|
+
describe "An encoder with options and an input and output file specified" do
|
41
|
+
|
42
|
+
before(:each) do
|
43
|
+
@la = Lamer.new
|
44
|
+
@la.encode_quality :high
|
45
|
+
@la.input_file "/Path/to/my/audio_file.wav"
|
46
|
+
@la.output_file "/Path/to/my/audio_file.mp3"
|
47
|
+
end
|
48
|
+
|
49
|
+
it "should provide the right command line" do
|
50
|
+
@la.command_line.should == "lame -q 2 /Path/to/my/audio_file.wav /Path/to/my/audio_file.mp3"
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
54
|
+
|
55
|
+
describe "An encoder sent various id3 information" do
|
56
|
+
|
57
|
+
before(:each) do
|
58
|
+
@la = Lamer.new
|
59
|
+
end
|
60
|
+
|
61
|
+
it "should set the title" do
|
62
|
+
@la.id3 :title => "The All-Knowning Mind of Minolta"
|
63
|
+
@la.id3_options[:title].should == "The All-Knowning Mind of Minolta"
|
64
|
+
@la.id3_arguments.should == "--tt The All-Knowning Mind of Minolta"
|
65
|
+
end
|
66
|
+
|
67
|
+
it "should set multiple values" do
|
68
|
+
@la.id3 :title => "The All-Knowning Mind of Minolta"
|
69
|
+
@la.id3 :artist => "Tin Man Shuffler"
|
70
|
+
@la.id3_options[:title].should == "The All-Knowning Mind of Minolta"
|
71
|
+
@la.id3_options[:artist].should == "Tin Man Shuffler"
|
72
|
+
@la.id3_arguments.should =~ /--tt The All-Knowning Mind of Minolta/
|
73
|
+
@la.id3_arguments.should =~ /--ta Tin Man Shuffler/
|
74
|
+
end
|
75
|
+
|
76
|
+
it "should set the title, artist, album, year, comment, track number, and genre" do
|
77
|
+
@la.id3 :title => 'title', :artist => 'artist', :album => 'album',
|
78
|
+
:year => 1998, :comment => 'comment', :track_number => 1,
|
79
|
+
:genre => 'genre'
|
80
|
+
[/--tt title/,/--ta artist/, /--tl album/,/--ty 1998/,/--tc comment/,/--tn 1/,/--tg genre/].each do |match|
|
81
|
+
@la.id3_arguments.should =~ match
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
it "should ignore nonsense values" do
|
86
|
+
@la.id3 :bugz => "Not Real"
|
87
|
+
@la.id3_arguments.should_not =~ /Real/
|
88
|
+
@la.id3 :title => "Coolbeans"
|
89
|
+
@la.id3_arguments.should =~ /Coolbeans/
|
90
|
+
end
|
91
|
+
|
92
|
+
it "should add v1 or v2 id3 tags as requested" do
|
93
|
+
2.times do |n|
|
94
|
+
@la.id3_version_only n
|
95
|
+
@la.options[:id3_version].should == "--id3v#{n}-only"
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
it "should allow adding v2 tags on top of default behaviour" do
|
100
|
+
@la.id3_add_v2!
|
101
|
+
@la.options[:id3_version].should == "--add-id3v2"
|
102
|
+
end
|
103
|
+
|
104
|
+
it "should not output id3_version unless tags are set" do
|
105
|
+
@la.id3_version_only 1
|
106
|
+
@la.argument_list.should == ""
|
107
|
+
end
|
108
|
+
|
109
|
+
describe "An encoder with id3 options and an input file" do
|
110
|
+
before(:each) do
|
111
|
+
@la = Lamer.new
|
112
|
+
@la.id3 :title => 'title', :artist => 'artist', :album => 'album',
|
113
|
+
:year => 1998, :comment => 'comment', :track_number => 1,
|
114
|
+
:genre => 'genre'
|
115
|
+
@la.input_file File.join( File.dirname( __FILE__ ), 'test.mp3' )
|
116
|
+
end
|
117
|
+
|
118
|
+
it "should output those options to the command line" do
|
119
|
+
[/--tt title/,/--ta artist/, /--tl album/,/--ty 1998/,/--tc comment/,/--tn 1/,/--tg genre/].each do |match|
|
120
|
+
@la.command_line.should =~ match
|
121
|
+
end
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
describe "An encoder starting with an mp3 file" do
|
126
|
+
before(:each) do
|
127
|
+
@root = './spec/'
|
128
|
+
begin
|
129
|
+
File.delete File.join( File.dirname( __FILE__ ), 'output.mp3' )
|
130
|
+
rescue
|
131
|
+
end
|
132
|
+
@la = Lamer.new
|
133
|
+
@la.input_file "#{@root}test.mp3"
|
134
|
+
@la.output_file "#{@root}output.mp3"
|
135
|
+
@la.input_mp3!
|
136
|
+
end
|
137
|
+
|
138
|
+
it "should provide the right command line" do
|
139
|
+
[/lame/,/--mp3input/, /-o/,/#{@root}test.mp3/,/#{@root}output.mp3/].each do |match|
|
140
|
+
@la.command_line.should =~ match
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
it "should successfully output a low bitrate version" do
|
145
|
+
@la.bitrate 32
|
146
|
+
@la.mode :mono
|
147
|
+
File.exists?("#{@root}output.mp3").should == false
|
148
|
+
@la.convert!
|
149
|
+
File.exists?("#{@root}output.mp3").should == true
|
150
|
+
end
|
151
|
+
end
|
152
|
+
|
153
|
+
describe "The runtime environment" do
|
154
|
+
it "should have lame version 3.9x installed" do
|
155
|
+
version = `lame --help`
|
156
|
+
version.should =~ /LAME/
|
157
|
+
version.should =~ /3\.9+/
|
158
|
+
end
|
159
|
+
end
|
160
|
+
|
161
|
+
end
|
data/spec/lamer_spec.rb
ADDED
@@ -0,0 +1,126 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper'
|
2
|
+
|
3
|
+
describe "A new Lamer" do
|
4
|
+
|
5
|
+
before(:each) do
|
6
|
+
@la = Lamer.new
|
7
|
+
end
|
8
|
+
|
9
|
+
it "should have a blank argument list" do
|
10
|
+
@la.argument_list.empty?.should == true
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should record valid bitrates" do
|
14
|
+
@la.bitrate 128
|
15
|
+
@la.options[:bitrate].should == "-b 128"
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should record valid sample rates" do
|
19
|
+
@la.sample_rate 44.1
|
20
|
+
@la.options[:sample_rate].should == "--resample 44.1"
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should record valid VBR quality" do
|
24
|
+
@la.vbr_quality 5
|
25
|
+
@la.options[:vbr_quality].should == "-V 5"
|
26
|
+
@la.options[:vbr].should == "-v"
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should record valid quality" do
|
30
|
+
@la.encode_quality 1
|
31
|
+
@la.options[:encode_quality].should == "-q 1"
|
32
|
+
end
|
33
|
+
|
34
|
+
it "should record valid quality" do
|
35
|
+
@la.encode_quality 5
|
36
|
+
@la.options[:encode_quality].should == "-q 5"
|
37
|
+
end
|
38
|
+
|
39
|
+
it "should record valid quality shortcut" do
|
40
|
+
@la.encode_quality :high
|
41
|
+
@la.options[:encode_quality].should == "-q 2"
|
42
|
+
@la.encode_quality :fast
|
43
|
+
@la.options[:encode_quality].should == "-q 7"
|
44
|
+
end
|
45
|
+
|
46
|
+
it "should balk at invalid bitrates" do
|
47
|
+
lambda {@la.bitrate 113}.should raise_error(ArgumentError)
|
48
|
+
end
|
49
|
+
|
50
|
+
it "should balk at invalid sample rates" do
|
51
|
+
lambda {@la.sample_rate 113}.should raise_error(ArgumentError)
|
52
|
+
end
|
53
|
+
|
54
|
+
it "should balk at invalid VBR qualities" do
|
55
|
+
lambda {@la.vbr_quality 113}.should raise_error(ArgumentError)
|
56
|
+
end
|
57
|
+
|
58
|
+
it "should balk at invalid encode qualities" do
|
59
|
+
lambda {@la.encode_quality 113}.should raise_error(ArgumentError)
|
60
|
+
end
|
61
|
+
|
62
|
+
it "should set mode to stereo or mono" do
|
63
|
+
{:stereo => '-m s', :mono => '-m m', :joint => '-m j'}.each do |option, setting|
|
64
|
+
@la.mode option
|
65
|
+
@la.options[:mode].should == setting
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
it "should set mode to nil on bad option" do
|
70
|
+
@la.mode :bugz
|
71
|
+
@la.options[:mode].should == nil
|
72
|
+
end
|
73
|
+
|
74
|
+
it "should accept flag that input is mp3" do
|
75
|
+
@la.input_mp3!
|
76
|
+
@la.options[:input_mp3].should == "--mp3input"
|
77
|
+
end
|
78
|
+
|
79
|
+
it "should accept an input filename" do
|
80
|
+
@la.input_file "/Path/to/my/audio_file.wav"
|
81
|
+
@la.command_line.should == "lame /Path/to/my/audio_file.wav"
|
82
|
+
end
|
83
|
+
|
84
|
+
it "should accept replygain options" do
|
85
|
+
{:accurate => "--replaygain-accurate",
|
86
|
+
:fast => "--replaygain-fast",
|
87
|
+
:none => "--noreplaygain",
|
88
|
+
:clip_detect => "--clipdetect",
|
89
|
+
:default => nil
|
90
|
+
}.each do |option, setting|
|
91
|
+
@la.replay_gain option
|
92
|
+
@la.options[:replay_gain].should == setting
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
it "should accept raw PCM files" do
|
97
|
+
@la.input_raw 44.1
|
98
|
+
@la.options[:input_raw].should == "-r -s 44.1"
|
99
|
+
@la.input_raw 32, true
|
100
|
+
@la.options[:input_raw].should == "-r -s 32 -x"
|
101
|
+
end
|
102
|
+
|
103
|
+
it "should mark as copy when requested" do
|
104
|
+
@la.mark_as_copy!
|
105
|
+
@la.options[:copy].should == "-o"
|
106
|
+
end
|
107
|
+
it "should mark as copy when starting from a file ending in .mp3" do
|
108
|
+
@la.input_file "/Path/to/my/audio_file.mp3"
|
109
|
+
@la.options[:copy].should == "-o"
|
110
|
+
end
|
111
|
+
it "should mark as copy when starting from an mp3 file" do
|
112
|
+
@la.input_mp3!
|
113
|
+
@la.options[:copy].should == "-o"
|
114
|
+
end
|
115
|
+
it "should not mark as copy when starting from a file not ending in .mp3" do
|
116
|
+
@la.input_file "/Path/to/my/audio_file.aif"
|
117
|
+
@la.options[:copy].should == nil
|
118
|
+
end
|
119
|
+
|
120
|
+
it "should output ogg files when requested" do
|
121
|
+
@la.output_ogg!
|
122
|
+
@la.options[:output_ogg].should == "--ogg"
|
123
|
+
end
|
124
|
+
|
125
|
+
end
|
126
|
+
|
data/spec/output.mp3
ADDED
Binary file
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
|
3
|
+
def smart_require(lib_name, gem_name, gem_version = '>= 0.0.0')
|
4
|
+
begin
|
5
|
+
require lib_name if lib_name
|
6
|
+
rescue LoadError
|
7
|
+
if gem_name
|
8
|
+
gem gem_name, gem_version
|
9
|
+
require lib_name if lib_name
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
smart_require 'spec', 'spec', '>= 1.2.6'
|
15
|
+
|
16
|
+
require File.expand_path(File.join(File.dirname(__FILE__), '../lib/lamer'))
|
data/spec/test.mp3
ADDED
Binary file
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lamer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chris Anderson
|
@@ -14,7 +14,7 @@ date: 2010-02-09 00:00:00 -05:00
|
|
14
14
|
default_executable:
|
15
15
|
dependencies: []
|
16
16
|
|
17
|
-
description: Ruby wrapper for the LAME library
|
17
|
+
description: Ruby wrapper for the LAME library. Currently wraps around the LAME executable so you can use LAME in your Ruby programs.
|
18
18
|
email: mauricio@edge14.com
|
19
19
|
executables: []
|
20
20
|
|
@@ -24,9 +24,18 @@ extra_rdoc_files:
|
|
24
24
|
- LICENSE
|
25
25
|
- README.md
|
26
26
|
files:
|
27
|
-
- VERSION
|
28
27
|
- LICENSE
|
29
28
|
- README.md
|
29
|
+
- Rakefile
|
30
|
+
- VERSION
|
31
|
+
- lamer.gemspec
|
32
|
+
- lib/lamer.rb
|
33
|
+
- spec/decoding_spec.rb
|
34
|
+
- spec/encoding_spec.rb
|
35
|
+
- spec/lamer_spec.rb
|
36
|
+
- spec/output.mp3
|
37
|
+
- spec/spec_helper.rb
|
38
|
+
- spec/test.mp3
|
30
39
|
has_rdoc: true
|
31
40
|
homepage: http://github.com/mgomes/lamer
|
32
41
|
licenses: []
|
@@ -56,4 +65,7 @@ signing_key:
|
|
56
65
|
specification_version: 3
|
57
66
|
summary: Ruby wrapper for the LAME library
|
58
67
|
test_files:
|
59
|
-
- spec/
|
68
|
+
- spec/decoding_spec.rb
|
69
|
+
- spec/encoding_spec.rb
|
70
|
+
- spec/lamer_spec.rb
|
71
|
+
- spec/spec_helper.rb
|
data/spec/lame_encoder_spec.rb
DELETED
@@ -1,302 +0,0 @@
|
|
1
|
-
$: << File.join( File.dirname( __FILE__ ), '../lib' )
|
2
|
-
|
3
|
-
require 'rubygems'
|
4
|
-
require_gem 'rspec'
|
5
|
-
require 'lame_encoder'
|
6
|
-
|
7
|
-
context "A new LameEncoder" do
|
8
|
-
|
9
|
-
setup do
|
10
|
-
@la = LameEncoder.new
|
11
|
-
end
|
12
|
-
|
13
|
-
specify "has a blank argument list" do
|
14
|
-
@la.argument_list.should_be_empty
|
15
|
-
end
|
16
|
-
|
17
|
-
specify "records valid bitrates" do
|
18
|
-
@la.bitrate 128
|
19
|
-
@la.options[:bitrate].should_equal "-b 128"
|
20
|
-
end
|
21
|
-
|
22
|
-
specify "records valid sample rate" do
|
23
|
-
@la.sample_rate 44.1
|
24
|
-
@la.options[:sample_rate].should_equal "--resample 44.1"
|
25
|
-
end
|
26
|
-
|
27
|
-
specify "records valid VBR quality" do
|
28
|
-
@la.vbr_quality 5
|
29
|
-
@la.options[:vbr_quality].should_equal "-V 5"
|
30
|
-
@la.options[:vbr].should_equal "-v"
|
31
|
-
end
|
32
|
-
|
33
|
-
specify "records valid quality" do
|
34
|
-
@la.encode_quality 1
|
35
|
-
@la.options[:encode_quality].should_equal "-q 1"
|
36
|
-
end
|
37
|
-
|
38
|
-
specify "records valid quality" do
|
39
|
-
@la.encode_quality 5
|
40
|
-
@la.options[:encode_quality].should_equal "-q 5"
|
41
|
-
end
|
42
|
-
|
43
|
-
specify "records valid quality shortcut" do
|
44
|
-
@la.encode_quality :high
|
45
|
-
@la.options[:encode_quality].should_equal "-q 2"
|
46
|
-
@la.encode_quality :fast
|
47
|
-
@la.options[:encode_quality].should_equal "-q 7"
|
48
|
-
end
|
49
|
-
|
50
|
-
specify "balks at invalid bitrate" do
|
51
|
-
lambda {@la.bitrate 113}.should_raise ArgumentError
|
52
|
-
end
|
53
|
-
|
54
|
-
specify "balks at invalid sample rate" do
|
55
|
-
lambda {@la.sample_rate 113}.should_raise ArgumentError
|
56
|
-
end
|
57
|
-
|
58
|
-
specify "balks at invalid VBR quality" do
|
59
|
-
lambda {@la.vbr_quality 113}.should_raise ArgumentError
|
60
|
-
end
|
61
|
-
|
62
|
-
specify "balks at invalid encode quality" do
|
63
|
-
lambda {@la.encode_quality 113}.should_raise ArgumentError
|
64
|
-
end
|
65
|
-
|
66
|
-
specify "sets mode to stereo or mono" do
|
67
|
-
{:stereo => '-m s', :mono => '-m m', :joint => '-m j'}.each do |option, setting|
|
68
|
-
@la.mode option
|
69
|
-
@la.options[:mode].should_equal setting
|
70
|
-
end
|
71
|
-
end
|
72
|
-
|
73
|
-
specify "sets mode to nil on bad option" do
|
74
|
-
@la.mode :bugz
|
75
|
-
@la.options[:mode].should_be nil
|
76
|
-
end
|
77
|
-
|
78
|
-
specify "decodes mp3s" do
|
79
|
-
@la.decode_mp3!
|
80
|
-
@la.options[:decode_mp3].should_equal "--decode"
|
81
|
-
lambda {@la.options[:new_value] = 'something'}.should_raise TypeError
|
82
|
-
end
|
83
|
-
|
84
|
-
specify "decodes mp3s without other options" do
|
85
|
-
@la.vbr_quality 4
|
86
|
-
@la.decode_mp3!
|
87
|
-
@la.options.length.should_equal 1
|
88
|
-
end
|
89
|
-
|
90
|
-
specify "accepts flag that input is mp3" do
|
91
|
-
@la.input_mp3!
|
92
|
-
@la.options[:input_mp3].should_equal "--mp3input"
|
93
|
-
end
|
94
|
-
|
95
|
-
specify "accepts an input filename" do
|
96
|
-
@la.input_file "/Path/to/my/audio_file.wav"
|
97
|
-
@la.command_line.should_equal "lame /Path/to/my/audio_file.wav"
|
98
|
-
end
|
99
|
-
|
100
|
-
specify "accepts replygain options" do
|
101
|
-
{:accurate => "--replaygain-accurate",
|
102
|
-
:fast => "--replaygain-fast",
|
103
|
-
:none => "--noreplaygain",
|
104
|
-
:clip_detect => "--clipdetect",
|
105
|
-
:default => nil
|
106
|
-
}.each do |option, setting|
|
107
|
-
@la.replay_gain option
|
108
|
-
@la.options[:replay_gain].should_equal setting
|
109
|
-
end
|
110
|
-
end
|
111
|
-
|
112
|
-
specify "accepts raw PCM files" do
|
113
|
-
@la.input_raw 44.1
|
114
|
-
@la.options[:input_raw].should_equal "-r -s 44.1"
|
115
|
-
@la.input_raw 32, true
|
116
|
-
@la.options[:input_raw].should_equal "-r -s 32 -x"
|
117
|
-
end
|
118
|
-
|
119
|
-
specify "marks as copy when requested" do
|
120
|
-
@la.mark_as_copy!
|
121
|
-
@la.options[:copy].should_equal "-o"
|
122
|
-
end
|
123
|
-
specify "marks as copy when starting from a file ending in .mp3" do
|
124
|
-
@la.input_file "/Path/to/my/audio_file.mp3"
|
125
|
-
@la.options[:copy].should_equal "-o"
|
126
|
-
end
|
127
|
-
specify "marks as copy when starting from an mp3 file" do
|
128
|
-
@la.input_mp3!
|
129
|
-
@la.options[:copy].should_equal "-o"
|
130
|
-
end
|
131
|
-
specify "does not mark as copy when starting from a file not ending in .mp3" do
|
132
|
-
@la.input_file "/Path/to/my/audio_file.aif"
|
133
|
-
@la.options[:copy].should_be_nil
|
134
|
-
end
|
135
|
-
|
136
|
-
specify "outputs ogg files when requested" do
|
137
|
-
@la.output_ogg!
|
138
|
-
@la.options[:output_ogg].should_equal "--ogg"
|
139
|
-
end
|
140
|
-
|
141
|
-
end
|
142
|
-
|
143
|
-
context "A high-quality VBR encoder without a file" do
|
144
|
-
|
145
|
-
setup do
|
146
|
-
@la = LameEncoder.new
|
147
|
-
@la.vbr_quality 4
|
148
|
-
@la.sample_rate 44.1
|
149
|
-
end
|
150
|
-
|
151
|
-
specify "ouputs the correct command line options" do
|
152
|
-
[ /-v/,/-V 4/,/--resample 44\.1/].each do |match|
|
153
|
-
@la.argument_list.should_match match
|
154
|
-
end
|
155
|
-
end
|
156
|
-
|
157
|
-
specify "balks at returning the command line" do
|
158
|
-
lambda {@la.command_line}.should_raise ArgumentError
|
159
|
-
end
|
160
|
-
|
161
|
-
specify "balks at running the conversion" do
|
162
|
-
lambda {@la.convert!}.should_raise ArgumentError
|
163
|
-
end
|
164
|
-
|
165
|
-
end
|
166
|
-
|
167
|
-
context "An encoder with a file specified" do
|
168
|
-
|
169
|
-
setup do
|
170
|
-
@la = LameEncoder.new
|
171
|
-
@la.input_file "/Path/to/my/audio_file.wav"
|
172
|
-
end
|
173
|
-
|
174
|
-
specify "provides the right command line" do
|
175
|
-
@la.command_line.should_equal "lame /Path/to/my/audio_file.wav"
|
176
|
-
end
|
177
|
-
|
178
|
-
end
|
179
|
-
|
180
|
-
context "An encoder with options and an input and output file specified" do
|
181
|
-
|
182
|
-
setup do
|
183
|
-
@la = LameEncoder.new
|
184
|
-
@la.encode_quality :high
|
185
|
-
@la.input_file "/Path/to/my/audio_file.wav"
|
186
|
-
@la.output_file "/Path/to/my/audio_file.mp3"
|
187
|
-
end
|
188
|
-
|
189
|
-
specify "provides the right command line" do
|
190
|
-
@la.command_line.should_equal "lame -q 2 /Path/to/my/audio_file.wav /Path/to/my/audio_file.mp3"
|
191
|
-
end
|
192
|
-
|
193
|
-
end
|
194
|
-
|
195
|
-
context "An encoder sent various id3 information" do
|
196
|
-
|
197
|
-
setup do
|
198
|
-
@la = LameEncoder.new
|
199
|
-
end
|
200
|
-
|
201
|
-
specify "sets the title" do
|
202
|
-
@la.id3 :title => "The All-Knowning Mind of Minolta"
|
203
|
-
@la.id3_options[:title].should_equal "The All-Knowning Mind of Minolta"
|
204
|
-
@la.id3_arguments.should_equal "--tt The All-Knowning Mind of Minolta"
|
205
|
-
end
|
206
|
-
|
207
|
-
specify "sets multiple values" do
|
208
|
-
@la.id3 :title => "The All-Knowning Mind of Minolta"
|
209
|
-
@la.id3 :artist => "Tin Man Shuffler"
|
210
|
-
@la.id3_options[:title].should_equal "The All-Knowning Mind of Minolta"
|
211
|
-
@la.id3_options[:artist].should_equal "Tin Man Shuffler"
|
212
|
-
@la.id3_arguments.should_match /--tt The All-Knowning Mind of Minolta/
|
213
|
-
@la.id3_arguments.should_match /--ta Tin Man Shuffler/
|
214
|
-
end
|
215
|
-
|
216
|
-
specify "sets title, artist, album, year, comment, track number, and genre" do
|
217
|
-
@la.id3 :title => 'title', :artist => 'artist', :album => 'album',
|
218
|
-
:year => 1998, :comment => 'comment', :track_number => 1,
|
219
|
-
:genre => 'genre'
|
220
|
-
[/--tt title/,/--ta artist/, /--tl album/,/--ty 1998/,/--tc comment/,/--tn 1/,/--tg genre/].each do |match|
|
221
|
-
@la.id3_arguments.should_match match
|
222
|
-
end
|
223
|
-
end
|
224
|
-
|
225
|
-
specify "ignores nonsense values" do
|
226
|
-
@la.id3 :bugz => "Not Real"
|
227
|
-
@la.id3_arguments.should_not_match /Real/
|
228
|
-
@la.id3 :title => "Coolbeans"
|
229
|
-
@la.id3_arguments.should_match /Coolbeans/
|
230
|
-
end
|
231
|
-
|
232
|
-
specify "adds v1 or v2 id3 tags as requested" do
|
233
|
-
2.times do |n|
|
234
|
-
@la.id3_version_only n
|
235
|
-
@la.options[:id3_version].should_equal "--id3v#{n}-only"
|
236
|
-
end
|
237
|
-
end
|
238
|
-
|
239
|
-
specify "allows adding v2 tags on top of default behaviour" do
|
240
|
-
@la.id3_add_v2!
|
241
|
-
@la.options[:id3_version].should_equal "--add-id3v2"
|
242
|
-
end
|
243
|
-
|
244
|
-
specify "does not output id3_version unless tags are set" do
|
245
|
-
@la.id3_version_only 1
|
246
|
-
@la.argument_list.should_equal ""
|
247
|
-
end
|
248
|
-
|
249
|
-
context "An encoder with id3 options and an input file" do
|
250
|
-
setup do
|
251
|
-
@la = LameEncoder.new
|
252
|
-
@la.id3 :title => 'title', :artist => 'artist', :album => 'album',
|
253
|
-
:year => 1998, :comment => 'comment', :track_number => 1,
|
254
|
-
:genre => 'genre'
|
255
|
-
@la.input_file File.join( File.dirname( __FILE__ ), 'test.mp3' )
|
256
|
-
end
|
257
|
-
|
258
|
-
specify "outputs those options to the command line" do
|
259
|
-
[/--tt title/,/--ta artist/, /--tl album/,/--ty 1998/,/--tc comment/,/--tn 1/,/--tg genre/].each do |match|
|
260
|
-
@la.command_line.should_match match
|
261
|
-
end
|
262
|
-
end
|
263
|
-
end
|
264
|
-
|
265
|
-
context "An encoder starting with an mp3 file" do
|
266
|
-
setup do
|
267
|
-
@root = './spec/'
|
268
|
-
begin
|
269
|
-
File.delete File.join( File.dirname( __FILE__ ), 'output.mp3' )
|
270
|
-
rescue
|
271
|
-
end
|
272
|
-
@la = LameEncoder.new
|
273
|
-
@la.input_file "#{@root}test.mp3"
|
274
|
-
@la.output_file "#{@root}output.mp3"
|
275
|
-
@la.input_mp3!
|
276
|
-
end
|
277
|
-
|
278
|
-
specify "provides the right command line" do
|
279
|
-
[/lame/,/--mp3input/, /-o/,/#{@root}test.mp3/,/#{@root}output.mp3/].each do |match|
|
280
|
-
@la.command_line.should_match match
|
281
|
-
end
|
282
|
-
end
|
283
|
-
|
284
|
-
specify "successfully outputs a low bitrate version" do
|
285
|
-
@la.bitrate 32
|
286
|
-
@la.mode :mono
|
287
|
-
File.should_not_exist "#{@root}output.mp3"
|
288
|
-
@la.convert!
|
289
|
-
File.should_exist "#{@root}output.mp3"
|
290
|
-
end
|
291
|
-
end
|
292
|
-
|
293
|
-
context "The runtime environment" do
|
294
|
-
specify "should have lame version 3.96 installed" do
|
295
|
-
version = `lame --help`
|
296
|
-
version.should_match /LAME/
|
297
|
-
version.should_match /3\.96/
|
298
|
-
end
|
299
|
-
end
|
300
|
-
|
301
|
-
end
|
302
|
-
|