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
@@ -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
|
|
@@ -7,42 +7,42 @@ module LAME
|
|
7
7
|
# stubbing galore!
|
8
8
|
|
9
9
|
let(:framesize) { 1152 }
|
10
|
-
let(:samples) {
|
11
|
-
let(:global_flags) {
|
12
|
-
let(:configuration) {
|
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.
|
17
|
+
allow(LAME).to receive(lame_function).and_return(0)
|
18
18
|
|
19
|
-
Buffer.
|
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.
|
25
|
+
allow(LAME).to receive(lame_function).and_return(0)
|
26
26
|
|
27
|
-
Buffer.
|
28
|
-
Buffer.
|
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 =
|
35
|
-
output_stub =
|
34
|
+
samples_stub = double("samples")
|
35
|
+
output_stub = double("output", :get_bytes => [])
|
36
36
|
|
37
|
-
Buffer.
|
38
|
-
Buffer.
|
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.
|
41
|
-
flags.
|
42
|
-
interleaved_buffer.
|
43
|
-
framesize.
|
44
|
-
output.
|
45
|
-
output_size.
|
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.
|
54
|
+
allow(LAME).to receive(lame_function).and_return(512)
|
55
55
|
|
56
|
-
mp3_data =
|
57
|
-
output =
|
58
|
-
output.
|
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.
|
61
|
-
Buffer.
|
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).
|
63
|
+
expect(encoder.encode_frame(samples)).to eql mp3_data
|
64
64
|
end
|
65
65
|
end
|
66
66
|
|
@@ -7,47 +7,47 @@ module LAME
|
|
7
7
|
# stubbing galore!
|
8
8
|
|
9
9
|
let(:framesize) { 1152 }
|
10
|
-
let(:left) {
|
11
|
-
let(:right) {
|
12
|
-
let(:global_flags) {
|
13
|
-
let(:configuration) {
|
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.
|
18
|
+
allow(LAME).to receive(lame_function).and_return(0)
|
19
19
|
|
20
|
-
Buffer.
|
21
|
-
Buffer.
|
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.
|
27
|
+
allow(LAME).to receive(lame_function).and_return(0)
|
28
28
|
|
29
|
-
Buffer.
|
30
|
-
Buffer.
|
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
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
Buffer.
|
41
|
-
Buffer.
|
42
|
-
Buffer.
|
43
|
-
|
44
|
-
LAME.
|
45
|
-
flags.
|
46
|
-
left_buffer.
|
47
|
-
right_buffer.
|
48
|
-
framesize.
|
49
|
-
output.
|
50
|
-
output_size.
|
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.
|
59
|
+
allow(LAME).to receive(lame_function).and_return(512)
|
60
60
|
|
61
|
-
mp3_data =
|
62
|
-
output =
|
63
|
-
output.
|
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.
|
66
|
-
Buffer.
|
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).
|
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
|
-
|
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) {
|
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(:vbr_info) { VBRInfo.new(configuration) }
|
11
11
|
|
12
12
|
it "creates output buffer" do
|
13
|
-
LAME.
|
13
|
+
allow(LAME).to receive(:lame_get_lametag_frame).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
|
vbr_info.frame
|
18
18
|
end
|
19
19
|
|
20
20
|
it "cretes the vbr frame" 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_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.
|
34
|
+
allow(LAME).to receive(:lame_get_lametag_frame).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
|
-
vbr_info.frame.
|
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.
|
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.
|
12
|
+
expect(LAME).to receive(:hip_decode_exit).with(pointer)
|
12
13
|
DecodeFlags.release(pointer)
|
13
14
|
end
|
14
15
|
end
|