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/encoder_spec.rb
CHANGED
|
@@ -8,7 +8,7 @@ module LAME
|
|
|
8
8
|
context "initialization" do
|
|
9
9
|
|
|
10
10
|
it "initializes GlobalFlags" do
|
|
11
|
-
FFI::GlobalFlags.
|
|
11
|
+
expect(FFI::GlobalFlags).to receive(:new)
|
|
12
12
|
Encoder.new
|
|
13
13
|
end
|
|
14
14
|
|
|
@@ -16,14 +16,14 @@ module LAME
|
|
|
16
16
|
|
|
17
17
|
context "configuration" do
|
|
18
18
|
|
|
19
|
-
let(:configuration) {
|
|
19
|
+
let(:configuration) { double(Configuration).as_null_object }
|
|
20
20
|
|
|
21
21
|
before do
|
|
22
|
-
Configuration.
|
|
22
|
+
allow(Configuration).to receive(:new).and_return(configuration)
|
|
23
23
|
end
|
|
24
24
|
|
|
25
25
|
it "initializes a Configuration object" do
|
|
26
|
-
Configuration.
|
|
26
|
+
expect(Configuration).to receive(:new).with(kind_of(GlobalFlags))
|
|
27
27
|
encoder.configure { }
|
|
28
28
|
end
|
|
29
29
|
|
|
@@ -35,18 +35,18 @@ module LAME
|
|
|
35
35
|
|
|
36
36
|
it "assigns the Configuration object" do
|
|
37
37
|
encoder.configure { }
|
|
38
|
-
encoder.configuration.
|
|
38
|
+
expect(encoder.configuration).to eql configuration
|
|
39
39
|
end
|
|
40
40
|
|
|
41
41
|
it "applies the configuration" do
|
|
42
|
-
configuration.
|
|
43
|
-
configuration.
|
|
42
|
+
allow(configuration).to receive(:applied?).and_return(false)
|
|
43
|
+
expect(configuration).to receive(:apply!)
|
|
44
44
|
encoder.configure { }
|
|
45
45
|
end
|
|
46
46
|
|
|
47
47
|
it "gets the framesize" do
|
|
48
|
-
configuration.
|
|
49
|
-
encoder.framesize.
|
|
48
|
+
expect(configuration).to receive(:framesize).and_return(1234)
|
|
49
|
+
expect(encoder.framesize).to eql 1234
|
|
50
50
|
end
|
|
51
51
|
end
|
|
52
52
|
|
|
@@ -57,54 +57,54 @@ module LAME
|
|
|
57
57
|
let(:samples) { [0,0] }
|
|
58
58
|
|
|
59
59
|
let(:global_flags) { subject.global_flags }
|
|
60
|
-
let(:configuration) {
|
|
60
|
+
let(:configuration) { double(Configuration, :framesize => 100) }
|
|
61
61
|
|
|
62
62
|
before do
|
|
63
|
-
Configuration.
|
|
64
|
-
configuration.
|
|
63
|
+
allow(Configuration).to receive(:new).and_return(configuration)
|
|
64
|
+
allow(configuration).to receive(:applied?).and_return(true)
|
|
65
65
|
end
|
|
66
66
|
|
|
67
67
|
describe "#encode_short" do
|
|
68
68
|
|
|
69
69
|
before do
|
|
70
|
-
Encoding::ShortBufferEncoder.
|
|
70
|
+
allow(Encoding::ShortBufferEncoder).to receive(:new).and_return(double.as_null_object)
|
|
71
71
|
end
|
|
72
72
|
|
|
73
73
|
it "applies the configuration if not done already" do
|
|
74
|
-
configuration.
|
|
75
|
-
configuration.
|
|
74
|
+
allow(configuration).to receive(:applied?).and_return(false)
|
|
75
|
+
expect(configuration).to receive(:apply!)
|
|
76
76
|
encoder.encode_short(left, right) { }
|
|
77
77
|
end
|
|
78
78
|
|
|
79
79
|
it "does not apply the configuration if already applied" do
|
|
80
|
-
configuration.
|
|
81
|
-
configuration.
|
|
80
|
+
allow(configuration).to receive(:applied?).and_return(true)
|
|
81
|
+
expect(configuration).to_not receive(:apply!)
|
|
82
82
|
encoder.encode_short(left, right) { }
|
|
83
83
|
end
|
|
84
84
|
|
|
85
85
|
context "delegation" do
|
|
86
|
-
let(:short_encoder) {
|
|
86
|
+
let(:short_encoder) { double.as_null_object }
|
|
87
87
|
|
|
88
88
|
before do
|
|
89
|
-
Encoding::ShortBufferEncoder.
|
|
89
|
+
allow(Encoding::ShortBufferEncoder).to receive(:new).and_return(short_encoder)
|
|
90
90
|
end
|
|
91
91
|
|
|
92
92
|
it "create a short encoder with configuration" do
|
|
93
|
-
Encoding::ShortBufferEncoder.
|
|
93
|
+
expect(Encoding::ShortBufferEncoder).to receive(:new).with(configuration)
|
|
94
94
|
|
|
95
95
|
encoder.encode_short(left, right) { }
|
|
96
96
|
end
|
|
97
97
|
|
|
98
98
|
it "delegates encoding to the short encoder" do
|
|
99
|
-
left.
|
|
100
|
-
short_encoder.
|
|
99
|
+
allow(left).to receive_messages(:length => 100) # exactly framesize
|
|
100
|
+
expect(short_encoder).to receive(:encode_frame).with(left, right)
|
|
101
101
|
|
|
102
102
|
encoder.encode_short(left, right) { }
|
|
103
103
|
end
|
|
104
104
|
|
|
105
105
|
it "yields the encoder results" do
|
|
106
|
-
mp3_data =
|
|
107
|
-
short_encoder.
|
|
106
|
+
mp3_data = double("mp3_data")
|
|
107
|
+
allow(short_encoder).to receive(:encode_frame).and_return(mp3_data)
|
|
108
108
|
|
|
109
109
|
expect { |block|
|
|
110
110
|
encoder.encode_short(left, right, &block)
|
|
@@ -114,26 +114,26 @@ module LAME
|
|
|
114
114
|
it "delegates multiple times for large input" do
|
|
115
115
|
right = left = [0]*150 # larger than framesize
|
|
116
116
|
|
|
117
|
-
short_encoder.
|
|
118
|
-
left_frame.length.
|
|
119
|
-
right_frame.length.
|
|
117
|
+
expect(short_encoder).to receive(:encode_frame) do |left_frame, right_frame|
|
|
118
|
+
expect(left_frame.length).to eql 100
|
|
119
|
+
expect(right_frame.length).to eql 100
|
|
120
120
|
end
|
|
121
121
|
|
|
122
|
-
short_encoder.
|
|
123
|
-
left_frame.length.
|
|
124
|
-
right_frame.length.
|
|
122
|
+
expect(short_encoder).to receive(:encode_frame) do |left_frame, right_frame|
|
|
123
|
+
expect(left_frame.length).to eql 50
|
|
124
|
+
expect(right_frame.length).to eql 50
|
|
125
125
|
end
|
|
126
126
|
|
|
127
127
|
encoder.encode_short(left, right) { }
|
|
128
128
|
end
|
|
129
129
|
|
|
130
130
|
it "yields multiple times for large input" do
|
|
131
|
-
mp3_data1 =
|
|
132
|
-
mp3_data2 =
|
|
131
|
+
mp3_data1 = double("frame1")
|
|
132
|
+
mp3_data2 = double("frame2")
|
|
133
133
|
|
|
134
134
|
left = [0]*150 # larger than framesize
|
|
135
135
|
|
|
136
|
-
short_encoder.
|
|
136
|
+
allow(short_encoder).to receive(:encode_frame).and_return(mp3_data1, mp3_data2)
|
|
137
137
|
|
|
138
138
|
expect { |block|
|
|
139
139
|
encoder.encode_short(left, right, &block)
|
|
@@ -144,8 +144,8 @@ module LAME
|
|
|
144
144
|
|
|
145
145
|
describe "#encode_float" do
|
|
146
146
|
it "create a float encoder" do
|
|
147
|
-
Encoding::FloatBufferEncoder.
|
|
148
|
-
Encoding::FloatBufferEncoder.
|
|
147
|
+
allow(Encoding::FloatBufferEncoder).to receive(:new).and_return(double.as_null_object)
|
|
148
|
+
expect(Encoding::FloatBufferEncoder).to receive(:new).with(configuration)
|
|
149
149
|
|
|
150
150
|
encoder.encode_float(left, right) { }
|
|
151
151
|
end
|
|
@@ -153,8 +153,8 @@ module LAME
|
|
|
153
153
|
|
|
154
154
|
describe "#encode_long" do
|
|
155
155
|
it "create a long encoder" do
|
|
156
|
-
Encoding::LongBufferEncoder.
|
|
157
|
-
Encoding::LongBufferEncoder.
|
|
156
|
+
allow(Encoding::LongBufferEncoder).to receive(:new).and_return(double.as_null_object)
|
|
157
|
+
expect(Encoding::LongBufferEncoder).to receive(:new).with(configuration)
|
|
158
158
|
|
|
159
159
|
encoder.encode_long(left, right) { }
|
|
160
160
|
end
|
|
@@ -163,44 +163,44 @@ module LAME
|
|
|
163
163
|
describe "#encode_interleaved_short" do
|
|
164
164
|
|
|
165
165
|
before do
|
|
166
|
-
Encoding::InterleavedShortBufferEncoder.
|
|
166
|
+
allow(Encoding::InterleavedShortBufferEncoder).to receive(:new).and_return(double.as_null_object)
|
|
167
167
|
end
|
|
168
168
|
|
|
169
169
|
it "applies the configuration if not done already" do
|
|
170
|
-
configuration.
|
|
171
|
-
configuration.
|
|
170
|
+
allow(configuration).to receive(:applied?).and_return(false)
|
|
171
|
+
expect(configuration).to receive(:apply!)
|
|
172
172
|
encoder.encode_interleaved_short(samples) { }
|
|
173
173
|
end
|
|
174
174
|
|
|
175
175
|
it "does not apply the configuration if already applied" do
|
|
176
|
-
configuration.
|
|
177
|
-
configuration.
|
|
176
|
+
allow(configuration).to receive(:applied?).and_return(true)
|
|
177
|
+
expect(configuration).to_not receive(:apply!)
|
|
178
178
|
encoder.encode_interleaved_short(samples) { }
|
|
179
179
|
end
|
|
180
180
|
|
|
181
181
|
context "delegation" do
|
|
182
|
-
let(:interleaved_short_encoder) {
|
|
182
|
+
let(:interleaved_short_encoder) { double.as_null_object }
|
|
183
183
|
|
|
184
184
|
before do
|
|
185
|
-
Encoding::InterleavedShortBufferEncoder.
|
|
185
|
+
allow(Encoding::InterleavedShortBufferEncoder).to receive(:new).and_return(interleaved_short_encoder)
|
|
186
186
|
end
|
|
187
187
|
|
|
188
188
|
it "create a short encoder with configuration" do
|
|
189
|
-
Encoding::InterleavedShortBufferEncoder.
|
|
189
|
+
expect(Encoding::InterleavedShortBufferEncoder).to receive(:new).with(configuration)
|
|
190
190
|
|
|
191
191
|
encoder.encode_interleaved_short(samples) { }
|
|
192
192
|
end
|
|
193
193
|
|
|
194
194
|
it "delegates encoding to the short encoder" do
|
|
195
|
-
samples.
|
|
196
|
-
interleaved_short_encoder.
|
|
195
|
+
allow(samples).to receive_messages(:length => 200) # exactly framesize
|
|
196
|
+
expect(interleaved_short_encoder).to receive(:encode_frame).with(samples)
|
|
197
197
|
|
|
198
198
|
encoder.encode_interleaved_short(samples) { }
|
|
199
199
|
end
|
|
200
200
|
|
|
201
201
|
it "yields the encoder results" do
|
|
202
|
-
mp3_data =
|
|
203
|
-
interleaved_short_encoder.
|
|
202
|
+
mp3_data = double("mp3_data")
|
|
203
|
+
allow(interleaved_short_encoder).to receive(:encode_frame).and_return(mp3_data)
|
|
204
204
|
|
|
205
205
|
expect { |block|
|
|
206
206
|
encoder.encode_interleaved_short(samples, &block)
|
|
@@ -210,24 +210,24 @@ module LAME
|
|
|
210
210
|
it "delegates multiple times for large input" do
|
|
211
211
|
samples = [0]*300 # larger than framesize
|
|
212
212
|
|
|
213
|
-
interleaved_short_encoder.
|
|
214
|
-
samples.length.
|
|
213
|
+
expect(interleaved_short_encoder).to receive(:encode_frame) do |samples|
|
|
214
|
+
expect(samples.length).to eql 200
|
|
215
215
|
end
|
|
216
216
|
|
|
217
|
-
interleaved_short_encoder.
|
|
218
|
-
samples.length.
|
|
217
|
+
expect(interleaved_short_encoder).to receive(:encode_frame) do |samples|
|
|
218
|
+
expect(samples.length).to eql 100
|
|
219
219
|
end
|
|
220
220
|
|
|
221
221
|
encoder.encode_interleaved_short(samples) { }
|
|
222
222
|
end
|
|
223
223
|
|
|
224
224
|
it "yields multiple times for large input" do
|
|
225
|
-
mp3_data1 =
|
|
226
|
-
mp3_data2 =
|
|
225
|
+
mp3_data1 = double("frame1")
|
|
226
|
+
mp3_data2 = double("frame2")
|
|
227
227
|
|
|
228
228
|
samples = [0]*300 # larger than framesize
|
|
229
229
|
|
|
230
|
-
interleaved_short_encoder.
|
|
230
|
+
allow(interleaved_short_encoder).to receive(:encode_frame).and_return(mp3_data1, mp3_data2)
|
|
231
231
|
|
|
232
232
|
expect { |block|
|
|
233
233
|
encoder.encode_interleaved_short(samples, &block)
|
|
@@ -238,8 +238,8 @@ module LAME
|
|
|
238
238
|
|
|
239
239
|
describe "#encode_interleaved_float" do
|
|
240
240
|
it "create a float encoder" do
|
|
241
|
-
Encoding::InterleavedFloatBufferEncoder.
|
|
242
|
-
Encoding::InterleavedFloatBufferEncoder.
|
|
241
|
+
allow(Encoding::InterleavedFloatBufferEncoder).to receive(:new).and_return(double.as_null_object)
|
|
242
|
+
expect(Encoding::InterleavedFloatBufferEncoder).to receive(:new).with(configuration)
|
|
243
243
|
|
|
244
244
|
encoder.encode_interleaved_float(samples) { }
|
|
245
245
|
end
|
|
@@ -250,28 +250,28 @@ module LAME
|
|
|
250
250
|
context "flushing" do
|
|
251
251
|
|
|
252
252
|
let(:global_flags) { subject.global_flags }
|
|
253
|
-
let(:configuration) {
|
|
254
|
-
let(:flusher) {
|
|
253
|
+
let(:configuration) { double(Configuration) }
|
|
254
|
+
let(:flusher) { double(Encoding::Flusher).as_null_object }
|
|
255
255
|
|
|
256
256
|
before do
|
|
257
|
-
Configuration.
|
|
258
|
-
configuration.
|
|
259
|
-
Encoding::Flusher.
|
|
257
|
+
allow(Configuration).to receive(:new).and_return(configuration)
|
|
258
|
+
allow(configuration).to receive(:applied?).and_return(true)
|
|
259
|
+
allow(Encoding::Flusher).to receive(:new).and_return(flusher)
|
|
260
260
|
end
|
|
261
261
|
|
|
262
262
|
it "creates a flusher" do
|
|
263
|
-
Encoding::Flusher.
|
|
263
|
+
expect(Encoding::Flusher).to receive(:new).with(configuration)
|
|
264
264
|
encoder.flush { }
|
|
265
265
|
end
|
|
266
266
|
|
|
267
267
|
it "flushes the final frame" do
|
|
268
|
-
flusher.
|
|
268
|
+
expect(flusher).to receive(:flush)
|
|
269
269
|
encoder.flush { }
|
|
270
270
|
end
|
|
271
271
|
|
|
272
272
|
it "yields the flushed mp3 data" do
|
|
273
|
-
mp3_data =
|
|
274
|
-
flusher.
|
|
273
|
+
mp3_data = double("mp3_data")
|
|
274
|
+
allow(flusher).to receive(:flush).and_return(mp3_data)
|
|
275
275
|
|
|
276
276
|
expect { |block|
|
|
277
277
|
encoder.flush(&block)
|
|
@@ -279,9 +279,9 @@ module LAME
|
|
|
279
279
|
end
|
|
280
280
|
|
|
281
281
|
it "returns the flushed data if no block was given" do
|
|
282
|
-
mp3_data =
|
|
283
|
-
flusher.
|
|
284
|
-
encoder.flush.
|
|
282
|
+
mp3_data = double("mp3_data")
|
|
283
|
+
allow(flusher).to receive(:flush).and_return(mp3_data)
|
|
284
|
+
expect(encoder.flush).to eql mp3_data
|
|
285
285
|
end
|
|
286
286
|
|
|
287
287
|
end
|
|
@@ -289,28 +289,28 @@ module LAME
|
|
|
289
289
|
context "lametag frame" do
|
|
290
290
|
|
|
291
291
|
let(:global_flags) { subject.global_flags }
|
|
292
|
-
let(:configuration) {
|
|
293
|
-
let(:vbr_info) {
|
|
292
|
+
let(:configuration) { double(Configuration) }
|
|
293
|
+
let(:vbr_info) { double(Encoding::VBRInfo).as_null_object }
|
|
294
294
|
|
|
295
295
|
before do
|
|
296
|
-
Configuration.
|
|
297
|
-
configuration.
|
|
298
|
-
Encoding::VBRInfo.
|
|
296
|
+
allow(Configuration).to receive(:new).and_return(configuration)
|
|
297
|
+
allow(configuration).to receive(:applied?).and_return(true)
|
|
298
|
+
allow(Encoding::VBRInfo).to receive(:new).and_return(vbr_info)
|
|
299
299
|
end
|
|
300
300
|
|
|
301
301
|
it "creates vbr info" do
|
|
302
|
-
Encoding::VBRInfo.
|
|
302
|
+
expect(Encoding::VBRInfo).to receive(:new).with(configuration)
|
|
303
303
|
encoder.vbr_frame { }
|
|
304
304
|
end
|
|
305
305
|
|
|
306
306
|
it "creates the vbr frame" do
|
|
307
|
-
vbr_info.
|
|
307
|
+
expect(vbr_info).to receive(:frame)
|
|
308
308
|
encoder.vbr_frame { }
|
|
309
309
|
end
|
|
310
310
|
|
|
311
311
|
it "yields the vbr frame" do
|
|
312
|
-
mp3_data =
|
|
313
|
-
vbr_info.
|
|
312
|
+
mp3_data = double("mp3_data")
|
|
313
|
+
allow(vbr_info).to receive(:frame).and_return(mp3_data)
|
|
314
314
|
|
|
315
315
|
expect { |block|
|
|
316
316
|
encoder.vbr_frame(&block)
|
|
@@ -318,38 +318,38 @@ module LAME
|
|
|
318
318
|
end
|
|
319
319
|
|
|
320
320
|
it "returns the vbr frame if no block was given" do
|
|
321
|
-
mp3_data =
|
|
322
|
-
vbr_info.
|
|
323
|
-
encoder.vbr_frame.
|
|
321
|
+
mp3_data = double("mp3_data")
|
|
322
|
+
allow(vbr_info).to receive(:frame).and_return(mp3_data)
|
|
323
|
+
expect(encoder.vbr_frame).to eql mp3_data
|
|
324
324
|
end
|
|
325
325
|
|
|
326
326
|
end
|
|
327
327
|
|
|
328
328
|
context "id3" do
|
|
329
329
|
let(:global_flags) { subject.global_flags }
|
|
330
|
-
let(:configuration) {
|
|
331
|
-
let(:id3) {
|
|
330
|
+
let(:configuration) { double(Configuration) }
|
|
331
|
+
let(:id3) { double(Encoding::Id3).as_null_object }
|
|
332
332
|
|
|
333
333
|
before do
|
|
334
|
-
Configuration.
|
|
335
|
-
configuration.
|
|
336
|
-
Encoding::Id3.
|
|
334
|
+
allow(Configuration).to receive(:new).and_return(configuration)
|
|
335
|
+
allow(configuration).to receive(:applied?).and_return(true)
|
|
336
|
+
allow(Encoding::Id3).to receive(:new).and_return(id3)
|
|
337
337
|
end
|
|
338
338
|
|
|
339
339
|
it "creates vbr info" do
|
|
340
|
-
Encoding::Id3.
|
|
340
|
+
expect(Encoding::Id3).to receive(:new).with(configuration)
|
|
341
341
|
encoder.id3v1 { }
|
|
342
342
|
end
|
|
343
343
|
|
|
344
344
|
context "v1" do
|
|
345
345
|
it "creates the id3v1 frame" do
|
|
346
|
-
id3.
|
|
346
|
+
expect(id3).to receive(:v1)
|
|
347
347
|
encoder.id3v1 { }
|
|
348
348
|
end
|
|
349
349
|
|
|
350
350
|
it "yields the vbr frame" do
|
|
351
|
-
mp3_data =
|
|
352
|
-
id3.
|
|
351
|
+
mp3_data = double("mp3_data")
|
|
352
|
+
allow(id3).to receive(:v1).and_return(mp3_data)
|
|
353
353
|
|
|
354
354
|
expect { |block|
|
|
355
355
|
encoder.id3v1(&block)
|
|
@@ -357,21 +357,21 @@ module LAME
|
|
|
357
357
|
end
|
|
358
358
|
|
|
359
359
|
it "returns the vbr frame if no block was given" do
|
|
360
|
-
mp3_data =
|
|
361
|
-
id3.
|
|
362
|
-
encoder.id3v1.
|
|
360
|
+
mp3_data = double("mp3_data")
|
|
361
|
+
allow(id3).to receive(:v1).and_return(mp3_data)
|
|
362
|
+
expect(encoder.id3v1).to eql mp3_data
|
|
363
363
|
end
|
|
364
364
|
end
|
|
365
365
|
|
|
366
366
|
context "v2" do
|
|
367
367
|
it "creates the id3v2 frame" do
|
|
368
|
-
id3.
|
|
368
|
+
expect(id3).to receive(:v2)
|
|
369
369
|
encoder.id3v2 { }
|
|
370
370
|
end
|
|
371
371
|
|
|
372
372
|
it "yields the vbr frame" do
|
|
373
|
-
mp3_data =
|
|
374
|
-
id3.
|
|
373
|
+
mp3_data = double("mp3_data")
|
|
374
|
+
allow(id3).to receive(:v2).and_return(mp3_data)
|
|
375
375
|
|
|
376
376
|
expect { |block|
|
|
377
377
|
encoder.id3v2(&block)
|
|
@@ -379,9 +379,9 @@ module LAME
|
|
|
379
379
|
end
|
|
380
380
|
|
|
381
381
|
it "returns the vbr frame if no block was given" do
|
|
382
|
-
mp3_data =
|
|
383
|
-
id3.
|
|
384
|
-
encoder.id3v2.
|
|
382
|
+
mp3_data = double("mp3_data")
|
|
383
|
+
allow(id3).to receive(:v2).and_return(mp3_data)
|
|
384
|
+
expect(encoder.id3v2).to eql mp3_data
|
|
385
385
|
end
|
|
386
386
|
end
|
|
387
387
|
end
|
|
@@ -4,42 +4,42 @@ module LAME
|
|
|
4
4
|
module Encoding
|
|
5
5
|
describe Flusher do
|
|
6
6
|
|
|
7
|
-
let(:global_flags) {
|
|
8
|
-
let(:configuration) {
|
|
7
|
+
let(:global_flags) { double("global_flags") }
|
|
8
|
+
let(:configuration) { double(Configuration, :global_flags => global_flags, :framesize => 1152, :output_buffer_size => 8640) }
|
|
9
9
|
|
|
10
10
|
subject(:flusher) { Flusher.new(configuration) }
|
|
11
11
|
|
|
12
12
|
it "creates output buffer" do
|
|
13
|
-
LAME.
|
|
13
|
+
allow(LAME).to receive(:lame_encode_flush).and_return(0)
|
|
14
14
|
|
|
15
|
-
Buffer.
|
|
15
|
+
expect(Buffer).to receive(:create_empty).with(:uchar, 8640).and_return(double.as_null_object)
|
|
16
16
|
|
|
17
17
|
flusher.flush
|
|
18
18
|
end
|
|
19
19
|
|
|
20
20
|
it "flushes" do
|
|
21
|
-
|
|
22
|
-
Buffer.
|
|
21
|
+
output_double = double("output", :get_bytes => [])
|
|
22
|
+
allow(Buffer).to receive(:create_empty).with(:uchar, 8640).and_return(output_double)
|
|
23
23
|
|
|
24
|
-
LAME.
|
|
25
|
-
flags.
|
|
26
|
-
buffer.
|
|
27
|
-
buffer_size.
|
|
24
|
+
expect(LAME).to receive(:lame_encode_flush) do |flags, buffer, buffer_size|
|
|
25
|
+
expect(flags).to eql global_flags
|
|
26
|
+
expect(buffer).to eql output_double
|
|
27
|
+
expect(buffer_size).to eql 8640
|
|
28
28
|
end
|
|
29
29
|
|
|
30
30
|
flusher.flush
|
|
31
31
|
end
|
|
32
32
|
|
|
33
33
|
it "returns the flushed data" do
|
|
34
|
-
LAME.
|
|
34
|
+
allow(LAME).to receive(:lame_encode_flush).and_return(512)
|
|
35
35
|
|
|
36
|
-
mp3_data =
|
|
37
|
-
output =
|
|
38
|
-
output.
|
|
36
|
+
mp3_data = double("mp3_data")
|
|
37
|
+
output = double("output")
|
|
38
|
+
allow(output).to receive(:get_bytes).with(0, 512).and_return(mp3_data)
|
|
39
39
|
|
|
40
|
-
Buffer.
|
|
40
|
+
allow(Buffer).to receive(:create_empty).with(:uchar, 8640).and_return(output)
|
|
41
41
|
|
|
42
|
-
flusher.flush.
|
|
42
|
+
expect(flusher.flush).to eql mp3_data
|
|
43
43
|
end
|
|
44
44
|
|
|
45
45
|
end
|
data/spec/encoding/id3_spec.rb
CHANGED
|
@@ -4,100 +4,100 @@ module LAME
|
|
|
4
4
|
module Encoding
|
|
5
5
|
describe Id3 do
|
|
6
6
|
|
|
7
|
-
let(:global_flags) {
|
|
8
|
-
let(:configuration) {
|
|
7
|
+
let(:global_flags) { double }
|
|
8
|
+
let(:configuration) { double(Configuration, :global_flags => global_flags, :framesize => 1152, :output_buffer_size => 8640) }
|
|
9
9
|
|
|
10
10
|
subject(:id3) { Id3.new(configuration) }
|
|
11
11
|
|
|
12
12
|
describe "#v1" do
|
|
13
13
|
it "creates empty and filled output buffer" do
|
|
14
|
-
LAME.
|
|
14
|
+
allow(LAME).to receive(:lame_get_id3v1_tag).and_return(1024, 1024)
|
|
15
15
|
|
|
16
16
|
# Determine size
|
|
17
|
-
Buffer.
|
|
17
|
+
expect(Buffer).to receive(:create_empty).with(:uchar, 0).and_return(double.as_null_object)
|
|
18
18
|
|
|
19
19
|
# Actual tag
|
|
20
|
-
Buffer.
|
|
20
|
+
expect(Buffer).to receive(:create_empty).with(:uchar, 1024).and_return(double.as_null_object)
|
|
21
21
|
|
|
22
22
|
id3.v1
|
|
23
23
|
end
|
|
24
24
|
|
|
25
25
|
it "creates tag" do
|
|
26
26
|
# Determine size
|
|
27
|
-
LAME.
|
|
28
|
-
flags.
|
|
29
|
-
buffer.size.
|
|
30
|
-
buffer_size.
|
|
27
|
+
expect(LAME).to receive(:lame_get_id3v1_tag) do |flags, buffer, buffer_size|
|
|
28
|
+
expect(flags).to eql global_flags
|
|
29
|
+
expect(buffer.size).to eql 0
|
|
30
|
+
expect(buffer_size).to eql 0
|
|
31
31
|
1024
|
|
32
32
|
end
|
|
33
33
|
|
|
34
34
|
# Get actual tag
|
|
35
|
-
LAME.
|
|
36
|
-
flags.
|
|
37
|
-
buffer.size.
|
|
38
|
-
buffer_size.
|
|
35
|
+
expect(LAME).to receive(:lame_get_id3v1_tag) do |flags, buffer, buffer_size|
|
|
36
|
+
expect(flags).to eql global_flags
|
|
37
|
+
expect(buffer.size).to eql 1024
|
|
38
|
+
expect(buffer_size).to eql 1024
|
|
39
39
|
end
|
|
40
40
|
|
|
41
41
|
id3.v1
|
|
42
42
|
end
|
|
43
43
|
|
|
44
44
|
it "returns the id3 tag" do
|
|
45
|
-
LAME.
|
|
45
|
+
allow(LAME).to receive(:lame_get_id3v1_tag).and_return(512, 512)
|
|
46
46
|
|
|
47
|
-
mp3_data =
|
|
48
|
-
output =
|
|
49
|
-
output.
|
|
47
|
+
mp3_data = double("mp3_data")
|
|
48
|
+
output = double("output")
|
|
49
|
+
allow(output).to receive(:get_bytes).with(0, 512).and_return(mp3_data)
|
|
50
50
|
|
|
51
|
-
Buffer.
|
|
52
|
-
Buffer.
|
|
51
|
+
allow(Buffer).to receive(:create_empty).with(:uchar, 0)
|
|
52
|
+
allow(Buffer).to receive(:create_empty).with(:uchar, 512).and_return(output)
|
|
53
53
|
|
|
54
|
-
id3.v1.
|
|
54
|
+
expect(id3.v1).to eql mp3_data
|
|
55
55
|
end
|
|
56
56
|
end
|
|
57
57
|
|
|
58
58
|
describe "#v2" do
|
|
59
59
|
it "creates empty and filled output buffer" do
|
|
60
|
-
LAME.
|
|
60
|
+
allow(LAME).to receive(:lame_get_id3v2_tag).and_return(1024, 1024)
|
|
61
61
|
|
|
62
62
|
# Determine size
|
|
63
|
-
Buffer.
|
|
63
|
+
expect(Buffer).to receive(:create_empty).with(:uchar, 0).and_return(double.as_null_object)
|
|
64
64
|
|
|
65
65
|
# Actual tag
|
|
66
|
-
Buffer.
|
|
66
|
+
expect(Buffer).to receive(:create_empty).with(:uchar, 1024).and_return(double.as_null_object)
|
|
67
67
|
|
|
68
68
|
id3.v2
|
|
69
69
|
end
|
|
70
70
|
|
|
71
71
|
it "creates tag" do
|
|
72
72
|
# Determine size
|
|
73
|
-
LAME.
|
|
74
|
-
flags.
|
|
75
|
-
buffer.size.
|
|
76
|
-
buffer_size.
|
|
73
|
+
expect(LAME).to receive(:lame_get_id3v2_tag) do |flags, buffer, buffer_size|
|
|
74
|
+
expect(flags).to eql global_flags
|
|
75
|
+
expect(buffer.size).to eql 0
|
|
76
|
+
expect(buffer_size).to eql 0
|
|
77
77
|
1024
|
|
78
78
|
end
|
|
79
79
|
|
|
80
80
|
# Get actual tag
|
|
81
|
-
LAME.
|
|
82
|
-
flags.
|
|
83
|
-
buffer.size.
|
|
84
|
-
buffer_size.
|
|
81
|
+
expect(LAME).to receive(:lame_get_id3v2_tag) do |flags, buffer, buffer_size|
|
|
82
|
+
expect(flags).to eql global_flags
|
|
83
|
+
expect(buffer.size).to eql 1024
|
|
84
|
+
expect(buffer_size).to eql 1024
|
|
85
85
|
end
|
|
86
86
|
|
|
87
87
|
id3.v2
|
|
88
88
|
end
|
|
89
89
|
|
|
90
90
|
it "returns the id3 tag" do
|
|
91
|
-
LAME.
|
|
91
|
+
allow(LAME).to receive(:lame_get_id3v2_tag).and_return(512, 512)
|
|
92
92
|
|
|
93
|
-
mp3_data =
|
|
94
|
-
output =
|
|
95
|
-
output.
|
|
93
|
+
mp3_data = double("mp3_data")
|
|
94
|
+
output = double("output")
|
|
95
|
+
allow(output).to receive(:get_bytes).with(0, 512).and_return(mp3_data)
|
|
96
96
|
|
|
97
|
-
Buffer.
|
|
98
|
-
Buffer.
|
|
97
|
+
allow(Buffer).to receive(:create_empty).with(:uchar, 0)
|
|
98
|
+
allow(Buffer).to receive(:create_empty).with(:uchar, 512).and_return(output)
|
|
99
99
|
|
|
100
|
-
id3.v2.
|
|
100
|
+
expect(id3.v2).to eql mp3_data
|
|
101
101
|
end
|
|
102
102
|
end
|
|
103
103
|
|