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.
Files changed (38) hide show
  1. checksums.yaml +7 -0
  2. data/.travis.yml +3 -4
  3. data/README.md +51 -17
  4. data/lib/lame.rb +1 -0
  5. data/lib/lame/buffer.rb +1 -1
  6. data/lib/lame/encoder.rb +10 -11
  7. data/lib/lame/encoding/long_buffer_encoder.rb +1 -1
  8. data/lib/lame/encoding/stereo_buffer_encoder.rb +1 -0
  9. data/lib/lame/ffi.rb +2 -0
  10. data/lib/lame/version.rb +1 -1
  11. data/spec/buffer_spec.rb +8 -8
  12. data/spec/configuration_spec.rb +76 -76
  13. data/spec/decoder_spec.rb +34 -34
  14. data/spec/decoding/decoded_frame_spec.rb +7 -7
  15. data/spec/decoding/id3_tag_parser_spec.rb +3 -3
  16. data/spec/decoding/mp3_data_header_parser_spec.rb +21 -21
  17. data/spec/decoding/mpeg_audio_frame_finder_spec.rb +15 -15
  18. data/spec/decoding/mpeg_audio_frame_matcher_spec.rb +2 -2
  19. data/spec/decoding/single_frame_decoder_spec.rb +36 -35
  20. data/spec/decoding/stream_decoder_spec.rb +10 -10
  21. data/spec/delegation_spec.rb +37 -37
  22. data/spec/encoder_spec.rb +100 -100
  23. data/spec/encoding/flusher_spec.rb +16 -16
  24. data/spec/encoding/id3_spec.rb +38 -38
  25. data/spec/encoding/interleaved_buffer_encoder_spec.rb +25 -25
  26. data/spec/encoding/stereo_buffer_encoder_spec.rb +34 -33
  27. data/spec/encoding/vbr_info_spec.rb +16 -16
  28. data/spec/ffi/decode_flags_spec.rb +3 -2
  29. data/spec/ffi/encoding_spec.rb +22 -22
  30. data/spec/ffi/global_flags_spec.rb +159 -157
  31. data/spec/ffi/id3tag_spec.rb +24 -24
  32. data/spec/ffi/mp3_data_spec.rb +3 -3
  33. data/spec/integration/encoding_spec.rb +75 -3
  34. data/spec/integration/id3_tags_spec.rb +18 -18
  35. data/spec/lib/custom_matchers.rb +4 -4
  36. data/spec/lib/wave_file_generator.rb +9 -9
  37. data/spec/spec_helper.rb +0 -1
  38. metadata +38 -60
@@ -4,42 +4,42 @@ module LAME
4
4
  module Encoding
5
5
  describe Flusher 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(:flusher) { Flusher.new(configuration) }
11
11
 
12
12
  it "creates output buffer" do
13
- LAME.stub(:lame_encode_flush).and_return(0)
13
+ allow(LAME).to receive(:lame_encode_flush).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
  flusher.flush
18
18
  end
19
19
 
20
20
  it "flushes" 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_encode_flush) 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_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.stub(:lame_encode_flush).and_return(512)
34
+ allow(LAME).to receive(:lame_encode_flush).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
- flusher.flush.should eql mp3_data
42
+ expect(flusher.flush).to eql mp3_data
43
43
  end
44
44
 
45
45
  end
@@ -4,100 +4,100 @@ module LAME
4
4
  module Encoding
5
5
  describe Id3 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 }
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.stub(:lame_get_id3v1_tag).and_return(1024, 1024)
14
+ allow(LAME).to receive(:lame_get_id3v1_tag).and_return(1024, 1024)
15
15
 
16
16
  # Determine size
17
- Buffer.should_receive(:create_empty).with(:uchar, 0).and_return(stub.as_null_object)
17
+ expect(Buffer).to receive(:create_empty).with(:uchar, 0).and_return(double.as_null_object)
18
18
 
19
19
  # Actual tag
20
- Buffer.should_receive(:create_empty).with(:uchar, 1024).and_return(stub.as_null_object)
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.should_receive(:lame_get_id3v1_tag) do |flags, buffer, buffer_size|
28
- flags.should eql global_flags
29
- buffer.size.should eql 0
30
- buffer_size.should eql 0
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.should_receive(:lame_get_id3v1_tag) do |flags, buffer, buffer_size|
36
- flags.should eql global_flags
37
- buffer.size.should eql 1024
38
- buffer_size.should eql 1024
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.stub(:lame_get_id3v1_tag).and_return(512, 512)
45
+ allow(LAME).to receive(:lame_get_id3v1_tag).and_return(512, 512)
46
46
 
47
- mp3_data = stub
48
- output = stub
49
- output.stub(:get_bytes).with(0, 512).and_return(mp3_data)
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.stub(:create_empty).with(:uchar, 0)
52
- Buffer.stub(:create_empty).with(:uchar, 512).and_return(output)
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.should eql mp3_data
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.stub(:lame_get_id3v2_tag).and_return(1024, 1024)
60
+ allow(LAME).to receive(:lame_get_id3v2_tag).and_return(1024, 1024)
61
61
 
62
62
  # Determine size
63
- Buffer.should_receive(:create_empty).with(:uchar, 0).and_return(stub.as_null_object)
63
+ expect(Buffer).to receive(:create_empty).with(:uchar, 0).and_return(double.as_null_object)
64
64
 
65
65
  # Actual tag
66
- Buffer.should_receive(:create_empty).with(:uchar, 1024).and_return(stub.as_null_object)
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.should_receive(:lame_get_id3v2_tag) do |flags, buffer, buffer_size|
74
- flags.should eql global_flags
75
- buffer.size.should eql 0
76
- buffer_size.should eql 0
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.should_receive(:lame_get_id3v2_tag) do |flags, buffer, buffer_size|
82
- flags.should eql global_flags
83
- buffer.size.should eql 1024
84
- buffer_size.should eql 1024
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.stub(:lame_get_id3v2_tag).and_return(512, 512)
91
+ allow(LAME).to receive(:lame_get_id3v2_tag).and_return(512, 512)
92
92
 
93
- mp3_data = stub
94
- output = stub
95
- output.stub(:get_bytes).with(0, 512).and_return(mp3_data)
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.stub(:create_empty).with(:uchar, 0)
98
- Buffer.stub(:create_empty).with(:uchar, 512).and_return(output)
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.should eql mp3_data
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) { 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
 
@@ -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