lame 0.0.3 → 0.0.4
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/.travis.yml +3 -4
- data/README.md +51 -17
- data/lib/lame.rb +1 -0
- data/lib/lame/buffer.rb +1 -1
- data/lib/lame/encoder.rb +10 -11
- data/lib/lame/encoding/long_buffer_encoder.rb +1 -1
- data/lib/lame/encoding/stereo_buffer_encoder.rb +1 -0
- data/lib/lame/ffi.rb +2 -0
- data/lib/lame/version.rb +1 -1
- 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 +25 -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 +159 -157
- data/spec/ffi/id3tag_spec.rb +24 -24
- 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 +0 -1
- metadata +38 -60
@@ -6,32 +6,32 @@ module LAME
|
|
6
6
|
|
7
7
|
subject(:decoder) { StreamDecoder.new(decode_flags, mp3_data, stream) }
|
8
8
|
|
9
|
-
let(:decode_flags) {
|
10
|
-
let(:mp3_data) {
|
9
|
+
let(:decode_flags) { double("decode flags") }
|
10
|
+
let(:mp3_data) { double("mp3 data") }
|
11
11
|
|
12
12
|
let(:stream) { StringIO.new(stream_string) }
|
13
13
|
let(:stream_string) { "a" * 1024 + "b" * 1024}
|
14
14
|
|
15
15
|
it "creates a single frame decoder" do
|
16
|
-
SingleFrameDecoder.
|
16
|
+
expect(SingleFrameDecoder).to receive(:new).with(decode_flags, mp3_data)
|
17
17
|
decoder
|
18
18
|
end
|
19
19
|
|
20
20
|
it "it passes chunks of stream into the single frame decoder" do
|
21
|
-
single_frame_decoder =
|
22
|
-
SingleFrameDecoder.
|
21
|
+
single_frame_decoder = double("single_frame_decoder")
|
22
|
+
allow(SingleFrameDecoder).to receive(:new).and_return(single_frame_decoder)
|
23
23
|
|
24
|
-
single_frame_decoder.
|
24
|
+
expect(single_frame_decoder).to receive(:decode).exactly(:twice)
|
25
25
|
|
26
26
|
decoder.each_decoded_frame
|
27
27
|
end
|
28
28
|
|
29
29
|
it "yields the decoded frame" do
|
30
|
-
single_frame_decoder =
|
31
|
-
SingleFrameDecoder.
|
30
|
+
single_frame_decoder = double("single frame decoder")
|
31
|
+
allow(SingleFrameDecoder).to receive(:new).and_return(single_frame_decoder)
|
32
32
|
|
33
|
-
single_frame_decoder.
|
34
|
-
single_frame_decoder.
|
33
|
+
allow(single_frame_decoder).to receive(:decode).with("a"*1024).and_yield(:one)
|
34
|
+
allow(single_frame_decoder).to receive(:decode).with("b"*1024).and_yield(:two).and_yield(:three)
|
35
35
|
|
36
36
|
expect { |block|
|
37
37
|
decoder.each_decoded_frame(&block)
|
data/spec/delegation_spec.rb
CHANGED
@@ -14,7 +14,7 @@ module LAME
|
|
14
14
|
|
15
15
|
describe Delegation do
|
16
16
|
|
17
|
-
let(:global_flags) {
|
17
|
+
let(:global_flags) { double("global_flags") }
|
18
18
|
subject { FakeEncoder.new }
|
19
19
|
|
20
20
|
before do
|
@@ -23,71 +23,71 @@ module LAME
|
|
23
23
|
|
24
24
|
context "#delegate_alias_to_lame" do
|
25
25
|
it "delegates #foo= to LAME" do
|
26
|
-
LAME.
|
27
|
-
subject.foo =
|
26
|
+
expect(LAME).to receive(:lame_set_bar).with(global_flags, anything)
|
27
|
+
subject.foo = double("delegate")
|
28
28
|
end
|
29
29
|
|
30
30
|
it "delegates #foo to LAME" do
|
31
|
-
LAME.
|
31
|
+
expect(LAME).to receive(:lame_get_bar).with(global_flags)
|
32
32
|
subject.foo
|
33
33
|
end
|
34
34
|
|
35
35
|
it "delegates #foo? to LAME" do
|
36
|
-
LAME.
|
36
|
+
expect(LAME).to receive(:lame_get_bar).with(global_flags)
|
37
37
|
subject.foo?
|
38
38
|
end
|
39
39
|
end
|
40
40
|
|
41
41
|
context "#delegate_to_lame" do
|
42
42
|
it "delegates #baz= to LAME" do
|
43
|
-
LAME.
|
44
|
-
subject.baz =
|
43
|
+
expect(LAME).to receive(:lame_set_baz).with(global_flags, anything)
|
44
|
+
subject.baz = double("delegate")
|
45
45
|
end
|
46
46
|
|
47
47
|
it "delegates #baz to LAME" do
|
48
|
-
LAME.
|
48
|
+
expect(LAME).to receive(:lame_get_baz).with(global_flags)
|
49
49
|
subject.baz
|
50
50
|
end
|
51
51
|
|
52
52
|
it "delegates #baz? to LAME" do
|
53
|
-
LAME.
|
53
|
+
expect(LAME).to receive(:lame_get_baz).with(global_flags)
|
54
54
|
subject.baz?
|
55
55
|
end
|
56
56
|
end
|
57
57
|
|
58
58
|
context "#delegate_id3_to_lame" do
|
59
59
|
it "delegates #qux= to LAME" do
|
60
|
-
LAME.
|
61
|
-
subject.qux =
|
60
|
+
expect(LAME).to receive(:id3tag_set_qux).with(global_flags, anything)
|
61
|
+
subject.qux = double("delegate")
|
62
62
|
end
|
63
63
|
end
|
64
64
|
|
65
65
|
context "type conversion" do
|
66
66
|
it "converts the input type" do
|
67
|
-
value =
|
68
|
-
Delegation::TypeConvertor.
|
69
|
-
LAME.
|
67
|
+
value = double("value")
|
68
|
+
expect(Delegation::TypeConvertor).to receive(:convert).with(value)
|
69
|
+
allow(LAME).to receive(:lame_set_baz)
|
70
70
|
subject.baz = value
|
71
71
|
end
|
72
72
|
|
73
73
|
it "passes on converted value to setter" do
|
74
|
-
value =
|
75
|
-
converted_value =
|
76
|
-
Delegation::TypeConvertor.
|
77
|
-
LAME.
|
74
|
+
value = double("value")
|
75
|
+
converted_value = double("converted_value")
|
76
|
+
allow(Delegation::TypeConvertor).to receive(:convert).and_return(converted_value)
|
77
|
+
expect(LAME).to receive(:lame_set_baz).with(global_flags, converted_value)
|
78
78
|
subject.baz = value
|
79
79
|
end
|
80
80
|
|
81
81
|
it "converts question mark style getters to return booleans" do
|
82
|
-
LAME.
|
83
|
-
Delegation::TypeConvertor.
|
82
|
+
allow(LAME).to receive(:lame_get_baz).and_return(0)
|
83
|
+
expect(Delegation::TypeConvertor).to receive(:convert_return).with(0)
|
84
84
|
subject.baz?
|
85
85
|
end
|
86
86
|
|
87
87
|
it "converts question mark style getters to return booleans" do
|
88
|
-
LAME.
|
89
|
-
Delegation::TypeConvertor.
|
90
|
-
subject.baz
|
88
|
+
allow(LAME).to receive(:lame_get_baz)
|
89
|
+
allow(Delegation::TypeConvertor).to receive(:convert_return).and_return(false)
|
90
|
+
expect(subject.baz?).to be_falsy
|
91
91
|
end
|
92
92
|
end
|
93
93
|
|
@@ -99,45 +99,45 @@ module LAME
|
|
99
99
|
|
100
100
|
describe "#convert" do
|
101
101
|
it "converts true to 1" do
|
102
|
-
converter.convert(true).
|
102
|
+
expect(converter.convert(true)).to eql 1
|
103
103
|
end
|
104
104
|
|
105
105
|
it "converts false to 0" do
|
106
|
-
converter.convert(false).
|
106
|
+
expect(converter.convert(false)).to eql 0
|
107
107
|
end
|
108
108
|
|
109
109
|
it "converts a string to a pointer with correct value" do
|
110
110
|
input = "some string"
|
111
111
|
value = converter.convert(input)
|
112
|
-
value.
|
113
|
-
value.get_string(0).
|
112
|
+
expect(value).to be_a(::FFI::MemoryPointer)
|
113
|
+
expect(value.get_string(0)).to eql input
|
114
114
|
end
|
115
115
|
|
116
116
|
it "does not convert other values" do
|
117
|
-
converter.convert(:foo).
|
118
|
-
converter.convert(1.2).
|
117
|
+
expect(converter.convert(:foo)).to eql :foo
|
118
|
+
expect(converter.convert(1.2)).to eql 1.2
|
119
119
|
end
|
120
120
|
end
|
121
121
|
|
122
122
|
describe "#convert_return" do
|
123
123
|
it "converts 1 to true" do
|
124
|
-
converter.convert_return(1).
|
124
|
+
expect(converter.convert_return(1)).to eql true
|
125
125
|
end
|
126
126
|
|
127
127
|
it "converts 0 to false" do
|
128
|
-
converter.convert_return(0).
|
128
|
+
expect(converter.convert_return(0)).to eql false
|
129
129
|
end
|
130
130
|
|
131
131
|
it "converts 0.0 to false" do
|
132
|
-
converter.convert_return(0.0).
|
132
|
+
expect(converter.convert_return(0.0)).to eql false
|
133
133
|
end
|
134
134
|
|
135
135
|
it "returns truthy to true" do
|
136
|
-
converter.convert_return(:truthy).
|
137
|
-
converter.convert_return("truthy").
|
138
|
-
converter.convert_return(Object).
|
139
|
-
converter.convert_return(Object.new).
|
140
|
-
converter.convert_return(4.2).
|
136
|
+
expect(converter.convert_return(:truthy)).to eql true
|
137
|
+
expect(converter.convert_return("truthy")).to eql true
|
138
|
+
expect(converter.convert_return(Object)).to eql true
|
139
|
+
expect(converter.convert_return(Object.new)).to eql true
|
140
|
+
expect(converter.convert_return(4.2)).to eql true
|
141
141
|
end
|
142
142
|
end
|
143
143
|
|
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
|