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.
Files changed (43) hide show
  1. checksums.yaml +7 -0
  2. data/.github/workflows/ci.yml +47 -0
  3. data/.travis.yml +3 -4
  4. data/README.md +51 -19
  5. data/docs/lame-3.101.h +1357 -0
  6. data/lame.gemspec +2 -1
  7. data/lib/lame/buffer.rb +1 -1
  8. data/lib/lame/encoder.rb +10 -11
  9. data/lib/lame/encoding/interleaved_int_buffer_encoder.rb +15 -0
  10. data/lib/lame/encoding/long_buffer_encoder.rb +1 -1
  11. data/lib/lame/encoding/stereo_buffer_encoder.rb +1 -0
  12. data/lib/lame/ffi/functions.rb +99 -38
  13. data/lib/lame/ffi.rb +2 -0
  14. data/lib/lame/version.rb +1 -1
  15. data/lib/lame.rb +2 -0
  16. data/spec/buffer_spec.rb +8 -8
  17. data/spec/configuration_spec.rb +76 -76
  18. data/spec/decoder_spec.rb +34 -34
  19. data/spec/decoding/decoded_frame_spec.rb +7 -7
  20. data/spec/decoding/id3_tag_parser_spec.rb +3 -3
  21. data/spec/decoding/mp3_data_header_parser_spec.rb +21 -21
  22. data/spec/decoding/mpeg_audio_frame_finder_spec.rb +15 -15
  23. data/spec/decoding/mpeg_audio_frame_matcher_spec.rb +2 -2
  24. data/spec/decoding/single_frame_decoder_spec.rb +36 -35
  25. data/spec/decoding/stream_decoder_spec.rb +10 -10
  26. data/spec/delegation_spec.rb +37 -37
  27. data/spec/encoder_spec.rb +100 -100
  28. data/spec/encoding/flusher_spec.rb +16 -16
  29. data/spec/encoding/id3_spec.rb +38 -38
  30. data/spec/encoding/interleaved_buffer_encoder_spec.rb +32 -25
  31. data/spec/encoding/stereo_buffer_encoder_spec.rb +34 -33
  32. data/spec/encoding/vbr_info_spec.rb +16 -16
  33. data/spec/ffi/decode_flags_spec.rb +3 -2
  34. data/spec/ffi/encoding_spec.rb +22 -22
  35. data/spec/ffi/global_flags_spec.rb +166 -160
  36. data/spec/ffi/id3tag_spec.rb +26 -26
  37. data/spec/ffi/mp3_data_spec.rb +3 -3
  38. data/spec/integration/encoding_spec.rb +75 -3
  39. data/spec/integration/id3_tags_spec.rb +18 -18
  40. data/spec/lib/custom_matchers.rb +4 -4
  41. data/spec/lib/wave_file_generator.rb +9 -9
  42. data/spec/spec_helper.rb +14 -10
  43. metadata +58 -67
@@ -7,42 +7,42 @@ module LAME
7
7
  # stubbing galore!
8
8
 
9
9
  let(:framesize) { 1152 }
10
- let(:samples) { stub(:size => framesize*2) }
11
- let(:global_flags) { stub }
12
- let(:configuration) { stub(Configuration, :global_flags => global_flags, :framesize => framesize, :output_buffer_size => 8640) }
10
+ let(:samples) { double("samples", :size => framesize*2) }
11
+ let(:global_flags) { double("global_flags") }
12
+ let(:configuration) { double(Configuration, :global_flags => global_flags, :framesize => framesize, :output_buffer_size => 8640) }
13
13
 
14
14
  subject(:encoder) { described_class.new(configuration) }
15
15
 
16
16
  it "creates input buffers" do
17
- LAME.stub(lame_function).and_return(0)
17
+ allow(LAME).to receive(lame_function).and_return(0)
18
18
 
19
- Buffer.should_receive(:create).with(data_type, samples)
19
+ expect(Buffer).to receive(:create).with(data_type, samples)
20
20
 
21
21
  encoder.encode_frame(samples)
22
22
  end
23
23
 
24
24
  it "creates output buffer" do
25
- LAME.stub(lame_function).and_return(0)
25
+ allow(LAME).to receive(lame_function).and_return(0)
26
26
 
27
- Buffer.stub(:create)
28
- Buffer.should_receive(:create_empty).with(:uchar, 8640).and_return(stub.as_null_object)
27
+ allow(Buffer).to receive(:create)
28
+ expect(Buffer).to receive(:create_empty).with(:uchar, 8640).and_return(double.as_null_object)
29
29
 
30
30
  encoder.encode_frame(samples)
31
31
  end
32
32
 
33
33
  it "encodes the input" do
34
- samples_stub = stub("samples")
35
- output_stub = stub("output", :get_bytes => [])
34
+ samples_stub = double("samples")
35
+ output_stub = double("output", :get_bytes => [])
36
36
 
37
- Buffer.stub(:create).with(data_type, samples).and_return(samples_stub)
38
- Buffer.stub(:create_empty).with(:uchar, 8640).and_return(output_stub)
37
+ allow(Buffer).to receive(:create).with(data_type, samples).and_return(samples_stub)
38
+ allow(Buffer).to receive(:create_empty).with(:uchar, 8640).and_return(output_stub)
39
39
 
40
- LAME.should_receive(lame_function) do |flags, interleaved_buffer, framesize, output, output_size|
41
- flags.should eql global_flags
42
- interleaved_buffer.should eql samples_stub
43
- framesize.should eql 1152
44
- output.should eql output_stub
45
- output_size.should eql 8640
40
+ expect(LAME).to receive(lame_function) do |flags, interleaved_buffer, framesize, output, output_size|
41
+ expect(flags).to eql global_flags
42
+ expect(interleaved_buffer).to eql samples_stub
43
+ expect(framesize).to eql 1152
44
+ expect(output).to eql output_stub
45
+ expect(output_size).to eql 8640
46
46
 
47
47
  0 # return value
48
48
  end
@@ -51,16 +51,16 @@ module LAME
51
51
  end
52
52
 
53
53
  it "returns the encoded data" do
54
- LAME.stub(lame_function).and_return(512)
54
+ allow(LAME).to receive(lame_function).and_return(512)
55
55
 
56
- mp3_data = stub
57
- output = stub
58
- output.stub(:get_bytes).with(0, 512).and_return(mp3_data)
56
+ mp3_data = double("mp3_data")
57
+ output = double("output")
58
+ allow(output).to receive(:get_bytes).with(0, 512).and_return(mp3_data)
59
59
 
60
- Buffer.stub(:create)
61
- Buffer.stub(:create_empty).with(:uchar, 8640).and_return(output)
60
+ allow(Buffer).to receive(:create)
61
+ allow(Buffer).to receive(:create_empty).with(:uchar, 8640).and_return(output)
62
62
 
63
- encoder.encode_frame(samples).should eql mp3_data
63
+ expect(encoder.encode_frame(samples)).to eql mp3_data
64
64
  end
65
65
  end
66
66
 
@@ -77,5 +77,12 @@ module LAME
77
77
  let(:lame_function) { :lame_encode_buffer_interleaved_ieee_float }
78
78
  end
79
79
  end
80
+
81
+ describe InterleavedIntBufferEncoder do
82
+ it_should_behave_like "a interleaved buffer encoder" do
83
+ let(:data_type) { :int }
84
+ let(:lame_function) { :lame_encode_buffer_interleaved_int }
85
+ end
86
+ end
80
87
  end
81
88
  end
@@ -7,47 +7,47 @@ module LAME
7
7
  # stubbing galore!
8
8
 
9
9
  let(:framesize) { 1152 }
10
- let(:left) { stub(:size => framesize) }
11
- let(:right) { stub }
12
- let(:global_flags) { stub }
13
- let(:configuration) { stub(Configuration, :global_flags => global_flags, :framesize => framesize, :output_buffer_size => 8640) }
10
+ let(:left) { double("left", :size => framesize) }
11
+ let(:right) { double("right") }
12
+ let(:global_flags) { double("global_flags") }
13
+ let(:configuration) { double(Configuration, :global_flags => global_flags, :framesize => framesize, :output_buffer_size => 8640) }
14
14
 
15
15
  subject(:encoder) { described_class.new(configuration) }
16
16
 
17
17
  it "creates input buffers" do
18
- LAME.stub(lame_function).and_return(0)
18
+ allow(LAME).to receive(lame_function).and_return(0)
19
19
 
20
- Buffer.should_receive(:create).with(data_type, left)
21
- Buffer.should_receive(:create).with(data_type, right)
20
+ expect(Buffer).to receive(:create).with(data_type, left)
21
+ expect(Buffer).to receive(:create).with(data_type, right)
22
22
 
23
23
  encoder.encode_frame(left, right)
24
24
  end
25
25
 
26
26
  it "creates output buffer" do
27
- LAME.stub(lame_function).and_return(0)
27
+ allow(LAME).to receive(lame_function).and_return(0)
28
28
 
29
- Buffer.stub(:create)
30
- Buffer.should_receive(:create_empty).with(:uchar, 8640).and_return(stub.as_null_object)
29
+ allow(Buffer).to receive(:create)
30
+ expect(Buffer).to receive(:create_empty).with(:uchar, 8640).and_return(double.as_null_object)
31
31
 
32
32
  encoder.encode_frame(left, right)
33
33
  end
34
34
 
35
35
  it "encodes the input" do
36
- left_stub = stub("left")
37
- right_stub = stub("right")
38
- output_stub = stub("output", :get_bytes => [])
39
-
40
- Buffer.stub(:create).with(data_type, left).and_return(left_stub)
41
- Buffer.stub(:create).with(data_type, right).and_return(right_stub)
42
- Buffer.stub(:create_empty).with(:uchar, 8640).and_return(output_stub)
43
-
44
- LAME.should_receive(lame_function) do |flags, left_buffer, right_buffer, framesize, output, output_size|
45
- flags.should eql global_flags
46
- left_buffer.should eql left_stub
47
- right_buffer.should eql right_stub
48
- framesize.should eql 1152
49
- output.should eql output_stub
50
- output_size.should eql 8640
36
+ left_double = double("left")
37
+ right_double = double("right")
38
+ output_double = double("output", :get_bytes => [])
39
+
40
+ allow(Buffer).to receive(:create).with(data_type, left).and_return(left_double)
41
+ allow(Buffer).to receive(:create).with(data_type, right).and_return(right_double)
42
+ allow(Buffer).to receive(:create_empty).with(:uchar, 8640).and_return(output_double)
43
+
44
+ expect(LAME).to receive(lame_function) do |flags, left_buffer, right_buffer, framesize, output, output_size|
45
+ expect(flags).to eql global_flags
46
+ expect(left_buffer).to eql left_double
47
+ expect(right_buffer).to eql right_double
48
+ expect(framesize).to eql 1152
49
+ expect(output).to eql output_double
50
+ expect(output_size).to eql 8640
51
51
 
52
52
  0 # return value
53
53
  end
@@ -56,16 +56,16 @@ module LAME
56
56
  end
57
57
 
58
58
  it "returns the encoded data" do
59
- LAME.stub(lame_function).and_return(512)
59
+ allow(LAME).to receive(lame_function).and_return(512)
60
60
 
61
- mp3_data = stub
62
- output = stub
63
- output.stub(:get_bytes).with(0, 512).and_return(mp3_data)
61
+ mp3_data = double("mp3_data")
62
+ output = double("output")
63
+ allow(output).to receive(:get_bytes).with(0, 512).and_return(mp3_data)
64
64
 
65
- Buffer.stub(:create)
66
- Buffer.stub(:create_empty).with(:uchar, 8640).and_return(output)
65
+ allow(Buffer).to receive(:create)
66
+ allow(Buffer).to receive(:create_empty).with(:uchar, 8640).and_return(output)
67
67
 
68
- encoder.encode_frame(left, right).should eql mp3_data
68
+ expect(encoder.encode_frame(left, right)).to eql mp3_data
69
69
  end
70
70
  end
71
71
 
@@ -85,7 +85,8 @@ module LAME
85
85
 
86
86
  describe LongBufferEncoder do
87
87
  it_should_behave_like "a stereo buffer encoder" do
88
- let(:data_type) { :long }
88
+ # can be either int32 or int64 depending on system architecture
89
+ let(:data_type) { :"int#{::LAME::FFI::LONG_SIZE}" }
89
90
  let(:lame_function) { :lame_encode_buffer_long2 }
90
91
  end
91
92
  end
@@ -4,42 +4,42 @@ module LAME
4
4
  module Encoding
5
5
  describe VBRInfo do
6
6
 
7
- let(:global_flags) { stub }
8
- let(:configuration) { stub(Configuration, :global_flags => global_flags, :framesize => 1152, :output_buffer_size => 8640 ) }
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(:vbr_info) { VBRInfo.new(configuration) }
11
11
 
12
12
  it "creates output buffer" do
13
- LAME.stub(:lame_get_lametag_frame).and_return(0)
13
+ allow(LAME).to receive(:lame_get_lametag_frame).and_return(0)
14
14
 
15
- Buffer.should_receive(:create_empty).with(:uchar, 8640).and_return(stub.as_null_object)
15
+ expect(Buffer).to receive(:create_empty).with(:uchar, 8640).and_return(double.as_null_object)
16
16
 
17
17
  vbr_info.frame
18
18
  end
19
19
 
20
20
  it "cretes the vbr frame" do
21
- output_stub = stub("output", :get_bytes => [])
22
- Buffer.stub(:create_empty).with(:uchar, 8640).and_return(output_stub)
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.should_receive(:lame_get_lametag_frame) do |flags, buffer, buffer_size|
25
- flags.should eql global_flags
26
- buffer.should eql output_stub
27
- buffer_size.should eql 8640
24
+ expect(LAME).to receive(:lame_get_lametag_frame) 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
  vbr_info.frame
31
31
  end
32
32
 
33
33
  it "returns the vbr frame" do
34
- LAME.stub(:lame_get_lametag_frame).and_return(512)
34
+ allow(LAME).to receive(:lame_get_lametag_frame).and_return(512)
35
35
 
36
- mp3_data = stub
37
- output = stub
38
- output.stub(:get_bytes).with(0, 512).and_return(mp3_data)
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.stub(:create_empty).with(:uchar, 8640).and_return(output)
40
+ allow(Buffer).to receive(:create_empty).with(:uchar, 8640).and_return(output)
41
41
 
42
- vbr_info.frame.should eql mp3_data
42
+ expect(vbr_info.frame).to eql mp3_data
43
43
  end
44
44
 
45
45
  end
@@ -1,14 +1,15 @@
1
1
  module LAME
2
+
2
3
  describe DecodeFlags do
3
4
  it "initializes LAME" do
4
5
  pointer = ::FFI::Pointer.new(0)
5
- LAME.should_receive(:hip_decode_init).and_return(pointer)
6
+ expect(LAME).to receive(:hip_decode_init).and_return(pointer)
6
7
  DecodeFlags.new
7
8
  end
8
9
 
9
10
  it "closes the LAME struct pointer" do
10
11
  pointer = ::FFI::Pointer.new(0)
11
- LAME.should_receive(:hip_decode_exit).with(pointer)
12
+ expect(LAME).to receive(:hip_decode_exit).with(pointer)
12
13
  DecodeFlags.release(pointer)
13
14
  end
14
15
  end
@@ -14,11 +14,11 @@ module LAME
14
14
  context "initialization" do
15
15
 
16
16
  it "initializes the parameters" do
17
- LAME.lame_init_params(@flags_pointer).should eql 0
17
+ expect(LAME.lame_init_params(@flags_pointer)).to eql 0
18
18
  end
19
19
 
20
20
  it "inits the bitstream" do
21
- LAME.lame_init_bitstream(@flags_pointer).should eql 0
21
+ expect(LAME.lame_init_bitstream(@flags_pointer)).to eql 0
22
22
  end
23
23
 
24
24
  end
@@ -45,7 +45,7 @@ module LAME
45
45
 
46
46
  it "encodes" do
47
47
  return_code = LAME.lame_encode_buffer(@flags_pointer, input_buffer_left, input_buffer_right, input_buffer_size, output_buffer, output_buffer_size)
48
- return_code.should >= 0
48
+ expect(return_code).to be >= 0
49
49
  end
50
50
  end
51
51
 
@@ -54,7 +54,7 @@ module LAME
54
54
 
55
55
  it "encodes" do
56
56
  return_code = LAME.lame_encode_buffer_float(@flags_pointer, input_buffer_left, input_buffer_right, input_buffer_size, output_buffer, output_buffer_size)
57
- return_code.should >= 0
57
+ expect(return_code).to be >= 0
58
58
  end
59
59
  end
60
60
 
@@ -63,7 +63,7 @@ module LAME
63
63
 
64
64
  it "encodes" do
65
65
  return_code = LAME.lame_encode_buffer_ieee_float(@flags_pointer, input_buffer_left, input_buffer_right, input_buffer_size, output_buffer, output_buffer_size)
66
- return_code.should >= 0
66
+ expect(return_code).to be >= 0
67
67
  end
68
68
  end
69
69
 
@@ -72,7 +72,7 @@ module LAME
72
72
 
73
73
  it "encodes" do
74
74
  return_code = LAME.lame_encode_buffer_ieee_double(@flags_pointer, input_buffer_left, input_buffer_right, input_buffer_size, output_buffer, output_buffer_size)
75
- return_code.should >= 0
75
+ expect(return_code).to be >= 0
76
76
  end
77
77
  end
78
78
 
@@ -81,7 +81,7 @@ module LAME
81
81
 
82
82
  it "encodes" do
83
83
  return_code = LAME.lame_encode_buffer_long(@flags_pointer, input_buffer_left, input_buffer_right, input_buffer_size, output_buffer, output_buffer_size)
84
- return_code.should >= 0
84
+ expect(return_code).to be >= 0
85
85
  end
86
86
  end
87
87
 
@@ -90,7 +90,7 @@ module LAME
90
90
 
91
91
  it "encodes" do
92
92
  return_code = LAME.lame_encode_buffer_long2(@flags_pointer, input_buffer_left, input_buffer_right, input_buffer_size, output_buffer, output_buffer_size)
93
- return_code.should >= 0
93
+ expect(return_code).to be >= 0
94
94
  end
95
95
  end
96
96
 
@@ -99,7 +99,7 @@ module LAME
99
99
 
100
100
  it "encodes" do
101
101
  return_code = LAME.lame_encode_buffer_int(@flags_pointer, input_buffer_left, input_buffer_right, input_buffer_size, output_buffer, output_buffer_size)
102
- return_code.should >= 0
102
+ expect(return_code).to be >= 0
103
103
  end
104
104
  end
105
105
 
@@ -110,7 +110,7 @@ module LAME
110
110
 
111
111
  it "encodes" do
112
112
  return_code = LAME.lame_encode_buffer_interleaved(@flags_pointer, input_buffer_interleaved, input_buffer_size, output_buffer, output_buffer_size)
113
- return_code.should >= 0
113
+ expect(return_code).to be >= 0
114
114
  end
115
115
  end
116
116
 
@@ -119,7 +119,7 @@ module LAME
119
119
 
120
120
  it "encodes" do
121
121
  return_code = LAME.lame_encode_buffer_interleaved_ieee_float(@flags_pointer, input_buffer_interleaved, input_buffer_size, output_buffer, output_buffer_size)
122
- return_code.should >= 0
122
+ expect(return_code).to be >= 0
123
123
  end
124
124
  end
125
125
 
@@ -128,7 +128,7 @@ module LAME
128
128
 
129
129
  it "encodes" do
130
130
  return_code = LAME.lame_encode_buffer_interleaved_ieee_double(@flags_pointer, input_buffer_interleaved, input_buffer_size, output_buffer, output_buffer_size)
131
- return_code.should >= 0
131
+ expect(return_code).to be >= 0
132
132
  end
133
133
  end
134
134
 
@@ -140,14 +140,14 @@ module LAME
140
140
  let(:input_type) { :short }
141
141
 
142
142
  it "flushes" do
143
- LAME.lame_encode_flush(@flags_pointer, output_buffer, output_buffer_size).should be >= 0
143
+ expect(LAME.lame_encode_flush(@flags_pointer, output_buffer, output_buffer_size)).to be >= 0
144
144
  end
145
145
 
146
146
  it "flushes nogap" do
147
147
  # encode something so the flush doesn't give an error
148
148
  LAME.lame_encode_buffer(@flags_pointer, input_buffer_left, input_buffer_right, input_buffer_size, output_buffer, output_buffer_size)
149
149
 
150
- LAME.lame_encode_flush_nogap(@flags_pointer, output_buffer, output_buffer_size).should >= 0
150
+ expect(LAME.lame_encode_flush_nogap(@flags_pointer, output_buffer, output_buffer_size)).to be >= 0
151
151
  end
152
152
  end
153
153
 
@@ -165,7 +165,7 @@ module LAME
165
165
 
166
166
  frame_size = LAME.lame_get_lametag_frame(@flags_pointer, output_buffer, output_buffer_size)
167
167
  #p output_buffer.get_bytes(0, frame_size)
168
- frame_size.should eql 417
168
+ expect(frame_size).to eql 417
169
169
  end
170
170
  end
171
171
 
@@ -182,7 +182,7 @@ module LAME
182
182
 
183
183
  bitrate_count = bitrate_count_ptr.read_array_of_int(14)
184
184
  # 9th = 128 (see below)
185
- bitrate_count.should eql [0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0]
185
+ expect(bitrate_count).to eql [0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0]
186
186
  end
187
187
 
188
188
  it "has bitrate kbps" do
@@ -191,7 +191,7 @@ module LAME
191
191
 
192
192
  bitrate_kbps = bitrate_kbps_ptr.read_array_of_int(14)
193
193
  # 9th = 128 (see bitrate table, without 0)
194
- bitrate_kbps.should eql [32, 40, 48, 56, 64, 80, 96, 112, 128, 160, 192, 224, 256, 320]
194
+ expect(bitrate_kbps).to eql [32, 40, 48, 56, 64, 80, 96, 112, 128, 160, 192, 224, 256, 320]
195
195
  end
196
196
 
197
197
  it "has stereo mode hist" do
@@ -200,11 +200,11 @@ module LAME
200
200
 
201
201
  stereo_mode_hist = stereo_mode_hist_ptr.read_array_of_int(4)
202
202
  # see lame.h for meaning
203
- stereo_mode_hist.should eql [0, 0, 1, 0]
203
+ expect(stereo_mode_hist).to eql [0, 0, 1, 0]
204
204
  end
205
205
 
206
206
  it "has bitrate stereo mode hist" do
207
- pending "multi-dimensional array"
207
+ skip "multi-dimensional array"
208
208
  end
209
209
 
210
210
  it "has block type hist" do
@@ -213,17 +213,17 @@ module LAME
213
213
 
214
214
  block_type_hist = block_type_hist_ptr.read_array_of_int(6)
215
215
  # see lame.h for meaning
216
- block_type_hist.should eql [4, 0, 0, 0, 0, 4]
216
+ expect(block_type_hist).to eql [4, 0, 0, 0, 0, 4]
217
217
  end
218
218
 
219
219
  it "has bitrate block type hist" do
220
- pending "multi-dimensional array"
220
+ skip "multi-dimensional array"
221
221
  end
222
222
  end
223
223
 
224
224
  context "closing" do
225
225
  it "closes" do
226
- LAME.lame_close(@flags_pointer).should eql 0
226
+ expect(LAME.lame_close(@flags_pointer)).to eql 0
227
227
  end
228
228
  end
229
229
  end