lame 0.0.3 → 0.0.5
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.
- checksums.yaml +7 -0
- data/.github/workflows/ci.yml +47 -0
- data/.travis.yml +3 -4
- data/README.md +51 -19
- data/docs/lame-3.101.h +1357 -0
- data/lame.gemspec +2 -1
- data/lib/lame/buffer.rb +1 -1
- data/lib/lame/encoder.rb +10 -11
- data/lib/lame/encoding/interleaved_int_buffer_encoder.rb +15 -0
- data/lib/lame/encoding/long_buffer_encoder.rb +1 -1
- data/lib/lame/encoding/stereo_buffer_encoder.rb +1 -0
- data/lib/lame/ffi/functions.rb +99 -38
- data/lib/lame/ffi.rb +2 -0
- data/lib/lame/version.rb +1 -1
- data/lib/lame.rb +2 -0
- data/spec/buffer_spec.rb +8 -8
- data/spec/configuration_spec.rb +76 -76
- data/spec/decoder_spec.rb +34 -34
- data/spec/decoding/decoded_frame_spec.rb +7 -7
- data/spec/decoding/id3_tag_parser_spec.rb +3 -3
- data/spec/decoding/mp3_data_header_parser_spec.rb +21 -21
- data/spec/decoding/mpeg_audio_frame_finder_spec.rb +15 -15
- data/spec/decoding/mpeg_audio_frame_matcher_spec.rb +2 -2
- data/spec/decoding/single_frame_decoder_spec.rb +36 -35
- data/spec/decoding/stream_decoder_spec.rb +10 -10
- data/spec/delegation_spec.rb +37 -37
- data/spec/encoder_spec.rb +100 -100
- data/spec/encoding/flusher_spec.rb +16 -16
- data/spec/encoding/id3_spec.rb +38 -38
- data/spec/encoding/interleaved_buffer_encoder_spec.rb +32 -25
- data/spec/encoding/stereo_buffer_encoder_spec.rb +34 -33
- data/spec/encoding/vbr_info_spec.rb +16 -16
- data/spec/ffi/decode_flags_spec.rb +3 -2
- data/spec/ffi/encoding_spec.rb +22 -22
- data/spec/ffi/global_flags_spec.rb +166 -160
- data/spec/ffi/id3tag_spec.rb +26 -26
- data/spec/ffi/mp3_data_spec.rb +3 -3
- data/spec/integration/encoding_spec.rb +75 -3
- data/spec/integration/id3_tags_spec.rb +18 -18
- data/spec/lib/custom_matchers.rb +4 -4
- data/spec/lib/wave_file_generator.rb +9 -9
- data/spec/spec_helper.rb +14 -10
- metadata +58 -67
data/spec/configuration_spec.rb
CHANGED
|
@@ -4,84 +4,84 @@ module LAME
|
|
|
4
4
|
describe Configuration do
|
|
5
5
|
|
|
6
6
|
context "intialization" do
|
|
7
|
-
let(:global_flags) {
|
|
7
|
+
let(:global_flags) { double("global_flags") }
|
|
8
8
|
|
|
9
9
|
subject(:configuration) { Configuration.new(global_flags) }
|
|
10
10
|
|
|
11
11
|
it "initializes with global flags" do
|
|
12
|
-
configuration.global_flags.
|
|
12
|
+
expect(configuration.global_flags).to eql global_flags
|
|
13
13
|
end
|
|
14
14
|
|
|
15
15
|
it "initializes a AsmOptimization configuration object" do
|
|
16
|
-
Configuration::AsmOptimization.
|
|
16
|
+
expect(Configuration::AsmOptimization).to receive(:new).with(global_flags)
|
|
17
17
|
configuration.asm_optimization
|
|
18
18
|
end
|
|
19
19
|
|
|
20
20
|
it "memoizes one AsmOptimization configuration object" do
|
|
21
|
-
Configuration::AsmOptimization.
|
|
22
|
-
Configuration::AsmOptimization.
|
|
21
|
+
allow(Configuration::AsmOptimization).to receive(:new).and_return(double)
|
|
22
|
+
expect(Configuration::AsmOptimization).to receive(:new).exactly(:once)
|
|
23
23
|
2.times { configuration.asm_optimization }
|
|
24
24
|
end
|
|
25
25
|
|
|
26
26
|
it "initializes a Id3 configuration object" do
|
|
27
|
-
Configuration::Id3.
|
|
27
|
+
expect(Configuration::Id3).to receive(:new).with(global_flags)
|
|
28
28
|
configuration.id3
|
|
29
29
|
end
|
|
30
30
|
|
|
31
31
|
it "memoizes one Id3 configuration object" do
|
|
32
|
-
Configuration::Id3.
|
|
33
|
-
Configuration::Id3.
|
|
32
|
+
allow(Configuration::Id3).to receive(:new).and_return(double)
|
|
33
|
+
expect(Configuration::Id3).to receive(:new).exactly(:once)
|
|
34
34
|
2.times { configuration.id3 }
|
|
35
35
|
end
|
|
36
36
|
|
|
37
37
|
it "initializes a Quantization configuration object" do
|
|
38
|
-
Configuration::Quantization.
|
|
38
|
+
expect(Configuration::Quantization).to receive(:new).with(global_flags)
|
|
39
39
|
configuration.quantization
|
|
40
40
|
end
|
|
41
41
|
|
|
42
42
|
it "memoizes one Quantization configuration object" do
|
|
43
|
-
Configuration::Quantization.
|
|
44
|
-
Configuration::Quantization.
|
|
43
|
+
allow(Configuration::Quantization).to receive(:new).and_return(double)
|
|
44
|
+
expect(Configuration::Quantization).to receive(:new).exactly(:once)
|
|
45
45
|
2.times { configuration.quantization }
|
|
46
46
|
end
|
|
47
47
|
|
|
48
48
|
it "initializes a VBR configuration object" do
|
|
49
|
-
Configuration::VBR.
|
|
49
|
+
expect(Configuration::VBR).to receive(:new).with(global_flags)
|
|
50
50
|
configuration.vbr
|
|
51
51
|
end
|
|
52
52
|
|
|
53
53
|
it "memoizes one VBR configuration object" do
|
|
54
|
-
Configuration::VBR.
|
|
55
|
-
Configuration::VBR.
|
|
54
|
+
allow(Configuration::VBR).to receive(:new).and_return(double)
|
|
55
|
+
expect(Configuration::VBR).to receive(:new).exactly(:once)
|
|
56
56
|
2.times { configuration.vbr }
|
|
57
57
|
end
|
|
58
58
|
|
|
59
59
|
it "initializes a Filtering configuration object" do
|
|
60
|
-
Configuration::Filtering.
|
|
60
|
+
expect(Configuration::Filtering).to receive(:new).with(global_flags)
|
|
61
61
|
configuration.filtering
|
|
62
62
|
end
|
|
63
63
|
|
|
64
64
|
it "memoizes one Filtering configuration object" do
|
|
65
|
-
Configuration::Filtering.
|
|
66
|
-
Configuration::Filtering.
|
|
65
|
+
allow(Configuration::Filtering).to receive(:new).and_return(double)
|
|
66
|
+
expect(Configuration::Filtering).to receive(:new).exactly(:once)
|
|
67
67
|
2.times { configuration.filtering }
|
|
68
68
|
end
|
|
69
69
|
|
|
70
70
|
it "initializes a PsychoAcoustics configuration object" do
|
|
71
|
-
Configuration::PsychoAcoustics.
|
|
71
|
+
expect(Configuration::PsychoAcoustics).to receive(:new).with(global_flags)
|
|
72
72
|
configuration.psycho_acoustics
|
|
73
73
|
end
|
|
74
74
|
|
|
75
75
|
it "memoizes one PsychoAcoustics configuration object" do
|
|
76
|
-
Configuration::PsychoAcoustics.
|
|
77
|
-
Configuration::PsychoAcoustics.
|
|
76
|
+
allow(Configuration::PsychoAcoustics).to receive(:new).and_return(double)
|
|
77
|
+
expect(Configuration::PsychoAcoustics).to receive(:new).exactly(:once)
|
|
78
78
|
2.times { configuration.psycho_acoustics }
|
|
79
79
|
end
|
|
80
80
|
|
|
81
81
|
context "Id3" do
|
|
82
82
|
|
|
83
83
|
it "initializes the Id3 tag" do
|
|
84
|
-
LAME.
|
|
84
|
+
expect(LAME).to receive(:id3tag_init).with(global_flags)
|
|
85
85
|
Configuration::Id3.new(global_flags)
|
|
86
86
|
end
|
|
87
87
|
|
|
@@ -89,17 +89,17 @@ module LAME
|
|
|
89
89
|
|
|
90
90
|
describe "#apply! / #applied?" do
|
|
91
91
|
it "is not applied by default" do
|
|
92
|
-
configuration.
|
|
92
|
+
expect(configuration).not_to be_applied
|
|
93
93
|
end
|
|
94
94
|
|
|
95
95
|
it "applies the configuration" do
|
|
96
|
-
LAME.
|
|
96
|
+
expect(LAME).to receive(:lame_init_params).with(global_flags)
|
|
97
97
|
configuration.apply!
|
|
98
|
-
configuration.
|
|
98
|
+
expect(configuration).to be_applied
|
|
99
99
|
end
|
|
100
100
|
|
|
101
101
|
it "raises an error if configuration could not be applied" do
|
|
102
|
-
LAME.
|
|
102
|
+
allow(LAME).to receive(:lame_init_params).and_return(-1)
|
|
103
103
|
expect {
|
|
104
104
|
configuration.apply!
|
|
105
105
|
}.to raise_error(ConfigurationError)
|
|
@@ -109,12 +109,12 @@ module LAME
|
|
|
109
109
|
describe "#framesize" do
|
|
110
110
|
|
|
111
111
|
it "gets framesize from LAME if configuration was applied" do
|
|
112
|
-
LAME.
|
|
112
|
+
allow(LAME).to receive(:lame_init_params)
|
|
113
113
|
configuration.apply!
|
|
114
114
|
|
|
115
|
-
LAME.
|
|
116
|
-
LAME.
|
|
117
|
-
configuration.framesize.
|
|
115
|
+
allow(LAME).to receive(:lame_get_framesize).and_return(42)
|
|
116
|
+
expect(LAME).to receive(:lame_get_framesize).with(global_flags)
|
|
117
|
+
expect(configuration.framesize).to eql 42
|
|
118
118
|
end
|
|
119
119
|
|
|
120
120
|
it "raises an error if configuration was not applied" do
|
|
@@ -124,12 +124,12 @@ module LAME
|
|
|
124
124
|
end
|
|
125
125
|
|
|
126
126
|
it "calculates the output buffer size based on the framesize" do
|
|
127
|
-
LAME.
|
|
127
|
+
allow(LAME).to receive(:lame_init_params)
|
|
128
128
|
configuration.apply!
|
|
129
129
|
|
|
130
|
-
LAME.
|
|
131
|
-
LAME.
|
|
132
|
-
configuration.output_buffer_size.
|
|
130
|
+
allow(LAME).to receive(:lame_get_framesize).and_return(1152)
|
|
131
|
+
expect(LAME).to receive(:lame_get_framesize).with(global_flags)
|
|
132
|
+
expect(configuration.output_buffer_size).to eql 8640
|
|
133
133
|
end
|
|
134
134
|
|
|
135
135
|
end
|
|
@@ -148,7 +148,7 @@ module LAME
|
|
|
148
148
|
#
|
|
149
149
|
context "set/get delegation" do
|
|
150
150
|
|
|
151
|
-
let(:global_flags) {
|
|
151
|
+
let(:global_flags) { double(GlobalFlags) }
|
|
152
152
|
subject(:configuration) { Configuration.new(global_flags) }
|
|
153
153
|
|
|
154
154
|
context "basic fields" do
|
|
@@ -183,8 +183,8 @@ module LAME
|
|
|
183
183
|
it { should delegate(:emphasis) }
|
|
184
184
|
|
|
185
185
|
it "delegates #preset= to LAME.lame_set_preset" do
|
|
186
|
-
LAME.
|
|
187
|
-
configuration.preset =
|
|
186
|
+
expect(LAME).to receive(:lame_set_preset).with(global_flags, anything)
|
|
187
|
+
configuration.preset = double
|
|
188
188
|
end
|
|
189
189
|
|
|
190
190
|
end
|
|
@@ -193,17 +193,17 @@ module LAME
|
|
|
193
193
|
subject(:asm_optimization) { configuration.asm_optimization }
|
|
194
194
|
|
|
195
195
|
it "delegates #mmx to LAME.lame_set_asm_optimizations" do
|
|
196
|
-
LAME.
|
|
196
|
+
expect(LAME).to receive(:lame_set_asm_optimizations).with(global_flags, :MMX, 1)
|
|
197
197
|
asm_optimization.mmx = true
|
|
198
198
|
end
|
|
199
199
|
|
|
200
200
|
it "delegates #amd_3dnow to LAME.lame_set_asm_optimizations" do
|
|
201
|
-
LAME.
|
|
201
|
+
expect(LAME).to receive(:lame_set_asm_optimizations).with(global_flags, :AMD_3DNOW, 1)
|
|
202
202
|
asm_optimization.amd_3dnow = true
|
|
203
203
|
end
|
|
204
204
|
|
|
205
205
|
it "delegates #sse to LAME.lame_set_asm_optimizations" do
|
|
206
|
-
LAME.
|
|
206
|
+
expect(LAME).to receive(:lame_set_asm_optimizations).with(global_flags, :SSE, 1)
|
|
207
207
|
asm_optimization.sse = true
|
|
208
208
|
end
|
|
209
209
|
end
|
|
@@ -215,37 +215,37 @@ module LAME
|
|
|
215
215
|
it { should delegate(:write_automatic).to(:write_id3tag_automatic) }
|
|
216
216
|
|
|
217
217
|
before do
|
|
218
|
-
LAME.
|
|
218
|
+
allow(LAME).to receive(:id3tag_init)
|
|
219
219
|
end
|
|
220
220
|
|
|
221
221
|
it "delegates #v2= to LAME.id3tag_add_v2" do
|
|
222
|
-
LAME.
|
|
222
|
+
expect(LAME).to receive(:id3tag_add_v2).with(global_flags)
|
|
223
223
|
id3.v2 = true
|
|
224
224
|
end
|
|
225
225
|
|
|
226
226
|
it "delegates #v1_only= to LAME.id3tag_v1_only" do
|
|
227
|
-
LAME.
|
|
227
|
+
expect(LAME).to receive(:id3tag_v1_only).with(global_flags)
|
|
228
228
|
id3.v1_only = true
|
|
229
229
|
end
|
|
230
230
|
|
|
231
231
|
it "delegates #v2_only= to LAME.id3tag_v2_only" do
|
|
232
|
-
LAME.
|
|
232
|
+
expect(LAME).to receive(:id3tag_v2_only).with(global_flags)
|
|
233
233
|
id3.v2_only = true
|
|
234
234
|
end
|
|
235
235
|
|
|
236
236
|
it "delegates #v1_space= to LAME.id3tag_v1_space" do
|
|
237
|
-
LAME.
|
|
237
|
+
expect(LAME).to receive(:id3tag_space_v1).with(global_flags)
|
|
238
238
|
id3.v1_space = true
|
|
239
239
|
end
|
|
240
240
|
|
|
241
241
|
it "delegates #v2_padding= to LAME.id3tag_pad_v2" do
|
|
242
|
-
LAME.
|
|
242
|
+
expect(LAME).to receive(:id3tag_pad_v2).with(global_flags)
|
|
243
243
|
id3.v2_padding = true
|
|
244
244
|
end
|
|
245
245
|
|
|
246
246
|
it "delegates #v2_padding_size= to LAME.id3tag_set_pad" do
|
|
247
|
-
value =
|
|
248
|
-
LAME.
|
|
247
|
+
value = double
|
|
248
|
+
expect(LAME).to receive(:id3tag_set_pad).with(global_flags, value)
|
|
249
249
|
id3.v2_padding_size = value
|
|
250
250
|
end
|
|
251
251
|
|
|
@@ -253,10 +253,10 @@ module LAME
|
|
|
253
253
|
[ :title, :artist, :album, :year, :comment ].each do |field|
|
|
254
254
|
|
|
255
255
|
it "sets the #{field} with string buffer" do
|
|
256
|
-
LAME.
|
|
257
|
-
flags.
|
|
258
|
-
string_buffer.
|
|
259
|
-
string_buffer.get_string(0).
|
|
256
|
+
expect(LAME).to receive(:"id3tag_set_#{field}") do |flags, string_buffer|
|
|
257
|
+
expect(flags).to eql global_flags
|
|
258
|
+
expect(string_buffer).to be_a(::FFI::MemoryPointer)
|
|
259
|
+
expect(string_buffer.get_string(0)).to eql "Some #{field}"
|
|
260
260
|
end
|
|
261
261
|
id3.send(:"#{field}=", "Some #{field}")
|
|
262
262
|
end
|
|
@@ -264,37 +264,37 @@ module LAME
|
|
|
264
264
|
end
|
|
265
265
|
|
|
266
266
|
it "sets the track" do
|
|
267
|
-
LAME.
|
|
268
|
-
flags.
|
|
269
|
-
value.
|
|
267
|
+
expect(LAME).to receive(:"id3tag_set_track") do |flags, value|
|
|
268
|
+
expect(flags).to eql global_flags
|
|
269
|
+
expect(value).to eql 42
|
|
270
270
|
end
|
|
271
271
|
id3.track = 42
|
|
272
272
|
end
|
|
273
273
|
|
|
274
274
|
it "sets the genre by name" do
|
|
275
|
-
LAME.
|
|
276
|
-
flags.
|
|
277
|
-
value.
|
|
278
|
-
value.get_string(0).
|
|
275
|
+
expect(LAME).to receive(:id3tag_set_genre) do |flags, value|
|
|
276
|
+
expect(flags).to eql global_flags
|
|
277
|
+
expect(value).to be_a(::FFI::MemoryPointer)
|
|
278
|
+
expect(value.get_string(0)).to eql "147"
|
|
279
279
|
end
|
|
280
280
|
id3.genre = "SynthPop"
|
|
281
281
|
end
|
|
282
282
|
|
|
283
283
|
it "sets the genre by id" do
|
|
284
|
-
LAME.
|
|
285
|
-
flags.
|
|
286
|
-
value.
|
|
287
|
-
value.get_string(0).
|
|
284
|
+
expect(LAME).to receive(:id3tag_set_genre) do |flags, value|
|
|
285
|
+
expect(flags).to eql global_flags
|
|
286
|
+
expect(value).to be_a(::FFI::MemoryPointer)
|
|
287
|
+
expect(value.get_string(0)).to eql "81"
|
|
288
288
|
end
|
|
289
289
|
|
|
290
290
|
id3.genre = 81
|
|
291
291
|
end
|
|
292
292
|
|
|
293
293
|
it "sets non-standard genre name" do
|
|
294
|
-
LAME.
|
|
295
|
-
flags.
|
|
296
|
-
value.
|
|
297
|
-
value.get_string(0).
|
|
294
|
+
expect(LAME).to receive(:id3tag_set_genre) do |flags, value|
|
|
295
|
+
expect(flags).to eql global_flags
|
|
296
|
+
expect(value).to be_a(::FFI::MemoryPointer)
|
|
297
|
+
expect(value.get_string(0)).to eql "Ruby FFI Rock"
|
|
298
298
|
end
|
|
299
299
|
id3.genre = "Ruby FFI Rock"
|
|
300
300
|
end
|
|
@@ -312,23 +312,23 @@ module LAME
|
|
|
312
312
|
it { should delegate(:msfix) }
|
|
313
313
|
|
|
314
314
|
it "delegates #reservoir= to LAME.lame_set_disable_reservoir" do
|
|
315
|
-
LAME.
|
|
315
|
+
expect(LAME).to receive(:lame_set_disable_reservoir).with(global_flags, 1)
|
|
316
316
|
quantization.reservoir = false
|
|
317
317
|
end
|
|
318
318
|
|
|
319
319
|
it "delegates #reservoir to LAME.lame_get_disable_reservoir" do
|
|
320
|
-
LAME.
|
|
320
|
+
expect(LAME).to receive(:lame_get_disable_reservoir).with(global_flags)
|
|
321
321
|
quantization.reservoir
|
|
322
322
|
end
|
|
323
323
|
|
|
324
324
|
it "delegates #reservoir? to LAME.lame_get_disable_reservoir" do
|
|
325
|
-
LAME.
|
|
325
|
+
expect(LAME).to receive(:lame_get_disable_reservoir).with(global_flags)
|
|
326
326
|
quantization.reservoir?
|
|
327
327
|
end
|
|
328
328
|
|
|
329
329
|
it "converts the return value 0 for #reservoir? to false" do
|
|
330
|
-
LAME.
|
|
331
|
-
quantization.reservoir
|
|
330
|
+
allow(LAME).to receive(:lame_get_disable_reservoir).and_return(0)
|
|
331
|
+
expect(quantization.reservoir?).to be_falsy
|
|
332
332
|
end
|
|
333
333
|
end
|
|
334
334
|
|
|
@@ -365,23 +365,23 @@ module LAME
|
|
|
365
365
|
it { should delegate(:athaa_sensitivity) }
|
|
366
366
|
|
|
367
367
|
it "delegates #ath= to LAME.lame_set_noATH" do
|
|
368
|
-
LAME.
|
|
368
|
+
expect(LAME).to receive(:lame_set_noATH).with(global_flags, 1)
|
|
369
369
|
psycho_acoustics.ath = false
|
|
370
370
|
end
|
|
371
371
|
|
|
372
372
|
it "delegates #ath to LAME.lame_get_noATH" do
|
|
373
|
-
LAME.
|
|
373
|
+
expect(LAME).to receive(:lame_get_noATH).with(global_flags)
|
|
374
374
|
psycho_acoustics.ath
|
|
375
375
|
end
|
|
376
376
|
|
|
377
377
|
it "delegates #ath? to LAME.lame_get_noATH" do
|
|
378
|
-
LAME.
|
|
378
|
+
expect(LAME).to receive(:lame_get_noATH).with(global_flags)
|
|
379
379
|
psycho_acoustics.ath?
|
|
380
380
|
end
|
|
381
381
|
|
|
382
382
|
it "converts the return value 0 for #ath? to true" do
|
|
383
|
-
LAME.
|
|
384
|
-
psycho_acoustics.ath
|
|
383
|
+
allow(LAME).to receive(:lame_get_noATH).and_return(0)
|
|
384
|
+
expect(psycho_acoustics.ath?).to be_truthy
|
|
385
385
|
end
|
|
386
386
|
end
|
|
387
387
|
|
data/spec/decoder_spec.rb
CHANGED
|
@@ -3,16 +3,16 @@ require 'spec_helper'
|
|
|
3
3
|
module LAME
|
|
4
4
|
describe Decoder do
|
|
5
5
|
|
|
6
|
-
let(:decode_flags) {
|
|
7
|
-
let(:mp3_file) {
|
|
8
|
-
let(:id3_tag_parser) {
|
|
9
|
-
let(:mp3_data_header_parser) {
|
|
6
|
+
let(:decode_flags) { double("decode flags") }
|
|
7
|
+
let(:mp3_file) { double("mp3 file") }
|
|
8
|
+
let(:id3_tag_parser) { double("id3 tag parser", :skip! => nil) }
|
|
9
|
+
let(:mp3_data_header_parser) { double("mp3 data header parser", :parse! => nil) }
|
|
10
10
|
|
|
11
11
|
# Stub away all collaborators:
|
|
12
12
|
before do
|
|
13
|
-
Decoding::Id3TagParser.
|
|
14
|
-
Decoding::Mp3DataHeaderParser.
|
|
15
|
-
FFI::DecodeFlags.
|
|
13
|
+
allow(Decoding::Id3TagParser).to receive(:new).and_return(id3_tag_parser)
|
|
14
|
+
allow(Decoding::Mp3DataHeaderParser).to receive(:new).and_return(mp3_data_header_parser)
|
|
15
|
+
allow(FFI::DecodeFlags).to receive(:new).and_return(decode_flags)
|
|
16
16
|
end
|
|
17
17
|
|
|
18
18
|
subject(:decoder) { Decoder.new(mp3_file) }
|
|
@@ -20,74 +20,74 @@ module LAME
|
|
|
20
20
|
context "initialization" do
|
|
21
21
|
|
|
22
22
|
it "initializes DecodeFlags" do
|
|
23
|
-
FFI::DecodeFlags.
|
|
23
|
+
expect(FFI::DecodeFlags).to receive(:new)
|
|
24
24
|
Decoder.new(mp3_file)
|
|
25
25
|
end
|
|
26
26
|
|
|
27
27
|
it "has the DecodeFlags" do
|
|
28
|
-
decode_flags =
|
|
29
|
-
FFI::DecodeFlags.
|
|
30
|
-
decoder.decode_flags.
|
|
28
|
+
decode_flags = double("decode_flags")
|
|
29
|
+
allow(FFI::DecodeFlags).to receive(:new).and_return(decode_flags)
|
|
30
|
+
expect(decoder.decode_flags).to eql decode_flags
|
|
31
31
|
end
|
|
32
32
|
|
|
33
33
|
it "has the mp3 file path" do
|
|
34
|
-
decoder.mp3_file.
|
|
34
|
+
expect(decoder.mp3_file).to eql mp3_file
|
|
35
35
|
end
|
|
36
36
|
|
|
37
37
|
it "skips the id3 offset" do
|
|
38
|
-
Decoding::Id3TagParser.
|
|
39
|
-
id3_tag_parser.
|
|
38
|
+
expect(Decoding::Id3TagParser).to receive(:new).with(mp3_file)
|
|
39
|
+
expect(id3_tag_parser).to receive(:skip!)
|
|
40
40
|
|
|
41
41
|
decoder
|
|
42
42
|
end
|
|
43
43
|
|
|
44
44
|
it "parses the mp3 data header" do
|
|
45
|
-
parser =
|
|
46
|
-
mp3_data =
|
|
47
|
-
Decoding::Mp3DataHeaderParser.
|
|
48
|
-
parser.
|
|
45
|
+
parser = double("parser")
|
|
46
|
+
mp3_data = double("mp3_data")
|
|
47
|
+
expect(Decoding::Mp3DataHeaderParser).to receive(:new).with(decode_flags, mp3_file).and_return(parser)
|
|
48
|
+
expect(parser).to receive(:parse!).and_return(mp3_data)
|
|
49
49
|
|
|
50
|
-
decoder.mp3_data.
|
|
50
|
+
expect(decoder.mp3_data).to eql mp3_data
|
|
51
51
|
end
|
|
52
52
|
|
|
53
53
|
end
|
|
54
54
|
|
|
55
55
|
context "after initialization" do
|
|
56
56
|
|
|
57
|
-
let(:mp3_data) {
|
|
57
|
+
let(:mp3_data) { double("mp3 data") }
|
|
58
58
|
|
|
59
59
|
# stubbing galore!
|
|
60
60
|
before do
|
|
61
|
-
FFI::DecodeFlags.
|
|
61
|
+
allow(FFI::DecodeFlags).to receive(:new).and_return(decode_flags)
|
|
62
62
|
|
|
63
|
-
parser =
|
|
64
|
-
Decoding::Mp3DataHeaderParser.
|
|
65
|
-
parser.
|
|
63
|
+
parser = double("parser")
|
|
64
|
+
allow(Decoding::Mp3DataHeaderParser).to receive(:new).and_return(parser)
|
|
65
|
+
allow(parser).to receive(:parse!).and_return(mp3_data)
|
|
66
66
|
end
|
|
67
67
|
|
|
68
68
|
describe "#each_decoded_frame" do
|
|
69
69
|
|
|
70
|
-
let(:stream_decoder) {
|
|
70
|
+
let(:stream_decoder) { double("stream_decoder") }
|
|
71
71
|
before do
|
|
72
|
-
Decoding::StreamDecoder.
|
|
72
|
+
allow(Decoding::StreamDecoder).to receive(:new).and_return(stream_decoder)
|
|
73
73
|
end
|
|
74
74
|
|
|
75
75
|
it "initializes a stream decoder with mp3 file and mp3 data" do
|
|
76
|
-
stream_decoder.
|
|
76
|
+
allow(stream_decoder).to receive(:each_decoded_frame)
|
|
77
77
|
|
|
78
|
-
Decoding::StreamDecoder.
|
|
78
|
+
expect(Decoding::StreamDecoder).to receive(:new).with(decode_flags, mp3_data, mp3_file)
|
|
79
79
|
|
|
80
80
|
decoder.each_decoded_frame
|
|
81
81
|
end
|
|
82
82
|
|
|
83
83
|
it "delegates to a stream decoder" do
|
|
84
|
-
stream_decoder.
|
|
84
|
+
expect(stream_decoder).to receive(:each_decoded_frame)
|
|
85
85
|
|
|
86
86
|
decoder.each_decoded_frame
|
|
87
87
|
end
|
|
88
88
|
|
|
89
89
|
it "re-yields the stream decoder's yield" do
|
|
90
|
-
stream_decoder.
|
|
90
|
+
allow(stream_decoder).to receive(:each_decoded_frame).and_yield(:one).and_yield(:two)
|
|
91
91
|
|
|
92
92
|
expect { |block|
|
|
93
93
|
decoder.each_decoded_frame(&block)
|
|
@@ -99,8 +99,8 @@ module LAME
|
|
|
99
99
|
describe "#channel_mode" do
|
|
100
100
|
|
|
101
101
|
it "delegates to mp3_data" do
|
|
102
|
-
mp3_data.
|
|
103
|
-
decoder.channel_mode.
|
|
102
|
+
expect(mp3_data).to receive(:channel_mode).and_return(:stereo)
|
|
103
|
+
expect(decoder.channel_mode).to eql :stereo
|
|
104
104
|
end
|
|
105
105
|
|
|
106
106
|
end
|
|
@@ -108,8 +108,8 @@ module LAME
|
|
|
108
108
|
describe "#sample_rate" do
|
|
109
109
|
|
|
110
110
|
it "delegates to mp3_data" do
|
|
111
|
-
mp3_data.
|
|
112
|
-
decoder.sample_rate.
|
|
111
|
+
allow(mp3_data).to receive(:sample_rate).and_return(44100)
|
|
112
|
+
expect(decoder.sample_rate).to eql 44100
|
|
113
113
|
end
|
|
114
114
|
|
|
115
115
|
end
|
|
@@ -5,13 +5,13 @@ module LAME
|
|
|
5
5
|
describe DecodedFrame do
|
|
6
6
|
|
|
7
7
|
it "is initialized with left and right samples" do
|
|
8
|
-
left =
|
|
9
|
-
right =
|
|
8
|
+
left = double("left")
|
|
9
|
+
right = double("right")
|
|
10
10
|
|
|
11
11
|
decoded_frame = DecodedFrame.new(left, right)
|
|
12
12
|
|
|
13
|
-
decoded_frame.left.
|
|
14
|
-
decoded_frame.right.
|
|
13
|
+
expect(decoded_frame.left).to eql left
|
|
14
|
+
expect(decoded_frame.right).to eql right
|
|
15
15
|
end
|
|
16
16
|
|
|
17
17
|
it "can be built with FFI Buffers" do
|
|
@@ -23,8 +23,8 @@ module LAME
|
|
|
23
23
|
|
|
24
24
|
decoded_frame = DecodedFrame.from_short_buffers(left_buffer, right_buffer)
|
|
25
25
|
|
|
26
|
-
decoded_frame.left.
|
|
27
|
-
decoded_frame.right.
|
|
26
|
+
expect(decoded_frame.left).to eql [1,2,3,4]
|
|
27
|
+
expect(decoded_frame.right).to eql [5,6,7,8]
|
|
28
28
|
end
|
|
29
29
|
|
|
30
30
|
describe "#samples" do
|
|
@@ -35,7 +35,7 @@ module LAME
|
|
|
35
35
|
|
|
36
36
|
decoded_frame = DecodedFrame.new(left, right)
|
|
37
37
|
|
|
38
|
-
decoded_frame.samples.
|
|
38
|
+
expect(decoded_frame.samples).to eql [[1,5],[2,6],[3,7],[4,8]]
|
|
39
39
|
end
|
|
40
40
|
end
|
|
41
41
|
|
|
@@ -21,13 +21,13 @@ module LAME
|
|
|
21
21
|
|
|
22
22
|
it "seeks the file until after the id3 tag" do
|
|
23
23
|
parser.skip!
|
|
24
|
-
stream.pos.
|
|
24
|
+
expect(stream.pos).to eql 351
|
|
25
25
|
end
|
|
26
26
|
|
|
27
27
|
it "start from the start of the stream" do
|
|
28
28
|
stream.seek(42)
|
|
29
29
|
parser.skip!
|
|
30
|
-
stream.pos.
|
|
30
|
+
expect(stream.pos).to eql 351
|
|
31
31
|
end
|
|
32
32
|
end
|
|
33
33
|
|
|
@@ -43,7 +43,7 @@ module LAME
|
|
|
43
43
|
|
|
44
44
|
it "does not seek the stream if no header is present" do
|
|
45
45
|
parser.skip!
|
|
46
|
-
stream.pos.
|
|
46
|
+
expect(stream.pos).to eql 0
|
|
47
47
|
end
|
|
48
48
|
end
|
|
49
49
|
|