lamer 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. data/LICENSE +20 -0
  2. data/README.md +45 -0
  3. data/VERSION +1 -0
  4. data/spec/lame_encoder_spec.rb +302 -0
  5. metadata +59 -0
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2010 Chris Anderson, Mauricio Gomes
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.md ADDED
@@ -0,0 +1,45 @@
1
+ Lamer
2
+ =====
3
+
4
+ ### Ruby Wrapper Around the LAME Library
5
+
6
+ Currently the program wraps around the [LAME](http://lame.sourceforge.net/) executable and exposes the LAME
7
+ command line options to your Ruby program.
8
+
9
+ Todo
10
+ ----
11
+
12
+ * Documentation
13
+ * Wrap the LAME library as an extension to remove the binary requirements
14
+
15
+ Install
16
+ -------
17
+
18
+ sudo gem install lamer
19
+
20
+ Prerequisites
21
+ -------------
22
+
23
+ ### LAME
24
+
25
+ [LAME](http://lame.sourceforge.net/) is a high quality MPEG Audio Layer III (MP3) encoder licensed under the LGPL. Below is
26
+ a list of pre-built binaries and a link to the source code.
27
+
28
+ * [OS X](http://web.me.com/krmathis/)
29
+ * [openSUSE](http://packman.links2linux.org/package/lame)
30
+ * [Ubuntu](https://help.ubuntu.com/community/Medibuntu)
31
+ * [RHEL/CentOS/Fedora ](http://atrpms.net/name/lame/)
32
+ * [Source](http://lame.sourceforge.net/download.php)
33
+
34
+ Credits
35
+ -------
36
+
37
+ This wrapper is built around the code of [lame-encoder](http://lame-encoder.rubyforge.org/) by
38
+ Chris Anderson.
39
+
40
+ Authors
41
+ -------
42
+
43
+ * [Chris Anderson](http://github.com/jchris)
44
+ * [Mauricio Gomes](http://github.com/mgomes)
45
+
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
@@ -0,0 +1,302 @@
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
+
metadata ADDED
@@ -0,0 +1,59 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: lamer
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Chris Anderson
8
+ - Mauricio Gomes
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2010-02-09 00:00:00 -05:00
14
+ default_executable:
15
+ dependencies: []
16
+
17
+ description: Ruby wrapper for the LAME library
18
+ email: mauricio@edge14.com
19
+ executables: []
20
+
21
+ extensions: []
22
+
23
+ extra_rdoc_files:
24
+ - LICENSE
25
+ - README.md
26
+ files:
27
+ - VERSION
28
+ - LICENSE
29
+ - README.md
30
+ has_rdoc: true
31
+ homepage: http://github.com/mgomes/lamer
32
+ licenses: []
33
+
34
+ post_install_message:
35
+ rdoc_options:
36
+ - --charset=UTF-8
37
+ require_paths:
38
+ - lib
39
+ required_ruby_version: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: "0"
44
+ version:
45
+ required_rubygems_version: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ version: "0"
50
+ version:
51
+ requirements: []
52
+
53
+ rubyforge_project:
54
+ rubygems_version: 1.3.5
55
+ signing_key:
56
+ specification_version: 3
57
+ summary: Ruby wrapper for the LAME library
58
+ test_files:
59
+ - spec/lame_encoder_spec.rb