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
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 0f9c8a30dc79a2724fb0a6361ee9d3e7d04524a8
|
4
|
+
data.tar.gz: 9a104153f78a75fcf6dbece38724d53a6f4b70c5
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 3dc02e4a9f569481f0c5d071150f882f284f5509a341ccd797431318034061b2a54a56da0de88a36e4a770d37c7ac6af90bbbaca0ccf14d31948654e58473db5
|
7
|
+
data.tar.gz: 2fa5a1aa873a10ec03538953260a0dde515b32dde49d464022d097d28ba7f480541923efff32d50fc551bfbe5aba530a52658f86b926fc92e5afb7748c0a8c8f
|
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -1,13 +1,17 @@
|
|
1
1
|
# LAME
|
2
2
|
|
3
|
+
[](http://badge.fury.io/rb/lame)
|
3
4
|
[](https://travis-ci.org/rdvdijk/lame)
|
4
5
|
[](https://codeclimate.com/github/rdvdijk/lame)
|
5
6
|
[](https://coveralls.io/r/rdvdijk/lame)
|
7
|
+
[](https://gemnasium.com/rdvdijk/lame)
|
6
8
|
|
7
9
|
FFI powered library for the [LAME MP3 encoder](http://lame.sourceforge.net/).
|
8
10
|
|
9
11
|
## Installation
|
10
12
|
|
13
|
+
### Installing the gem
|
14
|
+
|
11
15
|
Add this line to your application's Gemfile:
|
12
16
|
|
13
17
|
gem 'lame'
|
@@ -20,6 +24,16 @@ Or install it yourself as:
|
|
20
24
|
|
21
25
|
$ gem install lame
|
22
26
|
|
27
|
+
### Installing LAME
|
28
|
+
|
29
|
+
To use this gem, you need to have the LAME development library (`libmp3lame-dev`) installed.
|
30
|
+
|
31
|
+
Ubuntu/Debian: `sudo apt-get install libmp3lame-dev`
|
32
|
+
|
33
|
+
Mac OS X with Homebrew: `brew install lame`
|
34
|
+
|
35
|
+
Or build it from source, visit the [LAME website](http://lame.sourceforge.net/).
|
36
|
+
|
23
37
|
## Usage
|
24
38
|
|
25
39
|
Create a default `LAME::Encoder` with default settings:
|
@@ -54,27 +68,28 @@ See all encoding methods in the Encoding section below.
|
|
54
68
|
|
55
69
|
### Configuration
|
56
70
|
|
57
|
-
|
71
|
+
Here are all the encoding configuration options. The values use here are the
|
72
|
+
defaults. You can set any option prior to encoding.
|
58
73
|
|
59
74
|
```ruby
|
60
|
-
# These are the defaults:
|
61
75
|
encoder.configure do |config|
|
76
|
+
config.bitrate = 128
|
77
|
+
config.quality = 3
|
78
|
+
config.mode = :join_stereo
|
79
|
+
|
62
80
|
config.number_of_samples = 4294967295
|
63
|
-
config.input_samplerate = 44100
|
64
81
|
config.number_of_channels = 2
|
82
|
+
config.input_samplerate = 44100
|
83
|
+
config.output_samplerate = 44100
|
65
84
|
config.scale = 0.95
|
66
85
|
config.scale_left = 1.0
|
67
86
|
config.scale_left = 1.0
|
68
|
-
config.output_samplerate = 44100
|
69
87
|
config.analysis = false
|
70
88
|
config.decode_only = false
|
71
|
-
config.quality = 3
|
72
|
-
config.mode = :join_stereo
|
73
89
|
config.force_mid_side = false
|
74
90
|
config.free_format = false
|
75
91
|
config.replay_gain = false
|
76
92
|
config.decode_on_the_fly = false
|
77
|
-
config.bitrate = 128
|
78
93
|
config.preset = :EXTREME # no LAME default
|
79
94
|
config.copyright = false
|
80
95
|
config.original = true
|
@@ -89,11 +104,11 @@ encoder.configure do |config|
|
|
89
104
|
config.emphasis = false
|
90
105
|
|
91
106
|
# auto-detected by default
|
92
|
-
config.asm_optimization.mmx
|
93
|
-
config.asm_optimization.
|
94
|
-
config.asm_optimization.sse
|
107
|
+
config.asm_optimization.mmx = true
|
108
|
+
config.asm_optimization.amd_3dnow = true
|
109
|
+
config.asm_optimization.sse = true
|
95
110
|
|
96
|
-
# these
|
111
|
+
# these options can't be "unset" once set to true
|
97
112
|
config.id3.v2 = false
|
98
113
|
config.id3.v1_only = false
|
99
114
|
config.id3.v2_only = false
|
@@ -101,6 +116,15 @@ encoder.configure do |config|
|
|
101
116
|
config.id3.v2_padding = false
|
102
117
|
config.id3.v2_padding_size = 128
|
103
118
|
|
119
|
+
config.id3.write_automatic = true
|
120
|
+
config.id3.title = nil
|
121
|
+
config.id3.artist = nil
|
122
|
+
config.id3.album = nil
|
123
|
+
config.id3.year = nil
|
124
|
+
config.id3.comment = nil
|
125
|
+
config.id3.track = nil
|
126
|
+
config.id3.genre = nil
|
127
|
+
|
104
128
|
config.quantization.reservoir = true
|
105
129
|
config.quantization.comp = 9
|
106
130
|
config.quantization.comp_short = 9
|
@@ -136,8 +160,8 @@ end
|
|
136
160
|
|
137
161
|
### Encoding
|
138
162
|
|
139
|
-
See `spec/integration/encoding_spec.rb
|
140
|
-
to an MP3 file.
|
163
|
+
See [`encoding_spec.rb`](spec/integration/encoding_spec.rb) for examples how
|
164
|
+
to encode a WAV file to an MP3 file.
|
141
165
|
|
142
166
|
The available encoding functions are:
|
143
167
|
|
@@ -174,13 +198,23 @@ The `left` and `right` are arrays of sample values for the given data type.
|
|
174
198
|
|
175
199
|
### Decoding
|
176
200
|
|
177
|
-
See `spec/integration/decoding_spec.rb
|
178
|
-
to an WAV file.
|
201
|
+
See [`decoding_spec.rb`](spec/integration/decoding_spec.rb) for examples how
|
202
|
+
to decode an MP3 file to an WAV file.
|
179
203
|
|
180
204
|
### Development
|
181
205
|
|
182
206
|
This section contains some references used during development of this gem.
|
183
207
|
|
208
|
+
#### Testing
|
209
|
+
|
210
|
+
Run the unit tests with rspec:
|
211
|
+
|
212
|
+
$ rspec
|
213
|
+
|
214
|
+
Run the integration tests by using the `slow` tag:
|
215
|
+
|
216
|
+
$ rspec -t slow
|
217
|
+
|
184
218
|
#### ID3v2 tags
|
185
219
|
|
186
220
|
To use ID3v2 tags in files, see this post on the `lame-dev` mailing list:
|
@@ -195,7 +229,7 @@ So:
|
|
195
229
|
4. Write id3v1 tag at end of file
|
196
230
|
5. Write vbr 'lametag' at start of audio (using the size of the id3v2 tag)
|
197
231
|
|
198
|
-
See the example code in `spec/integration/encoding_spec.rb
|
232
|
+
See the example code in [`encoding_spec.rb`](spec/integration/encoding_spec.rb).
|
199
233
|
|
200
234
|
#### Decoding
|
201
235
|
|
@@ -225,7 +259,7 @@ After this, we are ready to decode MP3 data.
|
|
225
259
|
5. Handle the decoded audio.
|
226
260
|
6. Now repeat this process (`GOTO 1`) until the end of the MP3 file.
|
227
261
|
|
228
|
-
See the example code in `spec/integration/decoding_spec.rb
|
262
|
+
See the example code in [`decoding_spec.rb`](spec/integration/decoding_spec.rb).
|
229
263
|
|
230
264
|
## Contributing
|
231
265
|
|
data/lib/lame.rb
CHANGED
data/lib/lame/buffer.rb
CHANGED
data/lib/lame/encoder.rb
CHANGED
@@ -1,15 +1,12 @@
|
|
1
1
|
module LAME
|
2
2
|
class Encoder
|
3
3
|
|
4
|
-
|
4
|
+
BUFFER_ENCODERS = {
|
5
5
|
:short => Encoding::ShortBufferEncoder,
|
6
6
|
:float => Encoding::FloatBufferEncoder,
|
7
|
-
:long
|
8
|
-
|
9
|
-
|
10
|
-
INTERLEAVED_ENCODERS = {
|
11
|
-
:short => Encoding::InterleavedShortBufferEncoder,
|
12
|
-
:float => Encoding::InterleavedFloatBufferEncoder
|
7
|
+
:long => Encoding::LongBufferEncoder,
|
8
|
+
:short_interleaved => Encoding::InterleavedShortBufferEncoder,
|
9
|
+
:float_interleaved => Encoding::InterleavedFloatBufferEncoder
|
13
10
|
}
|
14
11
|
|
15
12
|
attr_reader :global_flags
|
@@ -36,11 +33,11 @@ module LAME
|
|
36
33
|
end
|
37
34
|
|
38
35
|
def encode_interleaved_short(samples, &block)
|
39
|
-
encode_interleaved(samples, :
|
36
|
+
encode_interleaved(samples, :short_interleaved, &block)
|
40
37
|
end
|
41
38
|
|
42
39
|
def encode_interleaved_float(samples, &block)
|
43
|
-
encode_interleaved(samples, :
|
40
|
+
encode_interleaved(samples, :float_interleaved, &block)
|
44
41
|
end
|
45
42
|
|
46
43
|
def flush(&block)
|
@@ -81,7 +78,8 @@ module LAME
|
|
81
78
|
apply_configuration
|
82
79
|
|
83
80
|
each_frame(left, right) do |left_frame, right_frame|
|
84
|
-
|
81
|
+
encoder = BUFFER_ENCODERS[data_type].new(configuration)
|
82
|
+
mp3_data = encoder.encode_frame(left_frame, right_frame)
|
85
83
|
yield mp3_data
|
86
84
|
end
|
87
85
|
end
|
@@ -90,7 +88,8 @@ module LAME
|
|
90
88
|
apply_configuration
|
91
89
|
|
92
90
|
each_interleaved_frame(interleaved_samples) do |interleaved_frame|
|
93
|
-
|
91
|
+
encoder = BUFFER_ENCODERS[data_type].new(configuration)
|
92
|
+
mp3_data = encoder.encode_frame(interleaved_frame)
|
94
93
|
yield mp3_data
|
95
94
|
end
|
96
95
|
end
|
data/lib/lame/ffi.rb
CHANGED
data/lib/lame/version.rb
CHANGED
data/spec/buffer_spec.rb
CHANGED
@@ -7,19 +7,19 @@ module LAME
|
|
7
7
|
input = [-42, 0, 42]
|
8
8
|
buffer = Buffer.create(:short, input)
|
9
9
|
|
10
|
-
buffer.
|
11
|
-
buffer.size.
|
12
|
-
buffer.type_size.
|
13
|
-
buffer.get_array_of_short(0, 3).
|
10
|
+
expect(buffer).to be_a(::FFI::MemoryPointer)
|
11
|
+
expect(buffer.size).to eql 6 # shorts are two bytes
|
12
|
+
expect(buffer.type_size).to eql 2
|
13
|
+
expect(buffer.get_array_of_short(0, 3)).to eql [-42, 0, 42]
|
14
14
|
end
|
15
15
|
|
16
16
|
it "creates an empty buffer" do
|
17
17
|
buffer = Buffer.create_empty(:uchar, 100)
|
18
18
|
|
19
|
-
buffer.
|
20
|
-
buffer.size.
|
21
|
-
buffer.type_size.
|
22
|
-
buffer.get_array_of_uchar(0, 100).
|
19
|
+
expect(buffer).to be_a(::FFI::MemoryPointer)
|
20
|
+
expect(buffer.size).to eql 100
|
21
|
+
expect(buffer.type_size).to eql 1
|
22
|
+
expect(buffer.get_array_of_uchar(0, 100)).to eql [0]*100
|
23
23
|
end
|
24
24
|
|
25
25
|
end
|
data/spec/configuration_spec.rb
CHANGED
@@ -4,84 +4,84 @@ module LAME
|
|
4
4
|
describe Configuration do
|
5
5
|
|
6
6
|
context "intialization" do
|
7
|
-
let(:global_flags) {
|
7
|
+
let(:global_flags) { double("global_flags") }
|
8
8
|
|
9
9
|
subject(:configuration) { Configuration.new(global_flags) }
|
10
10
|
|
11
11
|
it "initializes with global flags" do
|
12
|
-
configuration.global_flags.
|
12
|
+
expect(configuration.global_flags).to eql global_flags
|
13
13
|
end
|
14
14
|
|
15
15
|
it "initializes a AsmOptimization configuration object" do
|
16
|
-
Configuration::AsmOptimization.
|
16
|
+
expect(Configuration::AsmOptimization).to receive(:new).with(global_flags)
|
17
17
|
configuration.asm_optimization
|
18
18
|
end
|
19
19
|
|
20
20
|
it "memoizes one AsmOptimization configuration object" do
|
21
|
-
Configuration::AsmOptimization.
|
22
|
-
Configuration::AsmOptimization.
|
21
|
+
allow(Configuration::AsmOptimization).to receive(:new).and_return(double)
|
22
|
+
expect(Configuration::AsmOptimization).to receive(:new).exactly(:once)
|
23
23
|
2.times { configuration.asm_optimization }
|
24
24
|
end
|
25
25
|
|
26
26
|
it "initializes a Id3 configuration object" do
|
27
|
-
Configuration::Id3.
|
27
|
+
expect(Configuration::Id3).to receive(:new).with(global_flags)
|
28
28
|
configuration.id3
|
29
29
|
end
|
30
30
|
|
31
31
|
it "memoizes one Id3 configuration object" do
|
32
|
-
Configuration::Id3.
|
33
|
-
Configuration::Id3.
|
32
|
+
allow(Configuration::Id3).to receive(:new).and_return(double)
|
33
|
+
expect(Configuration::Id3).to receive(:new).exactly(:once)
|
34
34
|
2.times { configuration.id3 }
|
35
35
|
end
|
36
36
|
|
37
37
|
it "initializes a Quantization configuration object" do
|
38
|
-
Configuration::Quantization.
|
38
|
+
expect(Configuration::Quantization).to receive(:new).with(global_flags)
|
39
39
|
configuration.quantization
|
40
40
|
end
|
41
41
|
|
42
42
|
it "memoizes one Quantization configuration object" do
|
43
|
-
Configuration::Quantization.
|
44
|
-
Configuration::Quantization.
|
43
|
+
allow(Configuration::Quantization).to receive(:new).and_return(double)
|
44
|
+
expect(Configuration::Quantization).to receive(:new).exactly(:once)
|
45
45
|
2.times { configuration.quantization }
|
46
46
|
end
|
47
47
|
|
48
48
|
it "initializes a VBR configuration object" do
|
49
|
-
Configuration::VBR.
|
49
|
+
expect(Configuration::VBR).to receive(:new).with(global_flags)
|
50
50
|
configuration.vbr
|
51
51
|
end
|
52
52
|
|
53
53
|
it "memoizes one VBR configuration object" do
|
54
|
-
Configuration::VBR.
|
55
|
-
Configuration::VBR.
|
54
|
+
allow(Configuration::VBR).to receive(:new).and_return(double)
|
55
|
+
expect(Configuration::VBR).to receive(:new).exactly(:once)
|
56
56
|
2.times { configuration.vbr }
|
57
57
|
end
|
58
58
|
|
59
59
|
it "initializes a Filtering configuration object" do
|
60
|
-
Configuration::Filtering.
|
60
|
+
expect(Configuration::Filtering).to receive(:new).with(global_flags)
|
61
61
|
configuration.filtering
|
62
62
|
end
|
63
63
|
|
64
64
|
it "memoizes one Filtering configuration object" do
|
65
|
-
Configuration::Filtering.
|
66
|
-
Configuration::Filtering.
|
65
|
+
allow(Configuration::Filtering).to receive(:new).and_return(double)
|
66
|
+
expect(Configuration::Filtering).to receive(:new).exactly(:once)
|
67
67
|
2.times { configuration.filtering }
|
68
68
|
end
|
69
69
|
|
70
70
|
it "initializes a PsychoAcoustics configuration object" do
|
71
|
-
Configuration::PsychoAcoustics.
|
71
|
+
expect(Configuration::PsychoAcoustics).to receive(:new).with(global_flags)
|
72
72
|
configuration.psycho_acoustics
|
73
73
|
end
|
74
74
|
|
75
75
|
it "memoizes one PsychoAcoustics configuration object" do
|
76
|
-
Configuration::PsychoAcoustics.
|
77
|
-
Configuration::PsychoAcoustics.
|
76
|
+
allow(Configuration::PsychoAcoustics).to receive(:new).and_return(double)
|
77
|
+
expect(Configuration::PsychoAcoustics).to receive(:new).exactly(:once)
|
78
78
|
2.times { configuration.psycho_acoustics }
|
79
79
|
end
|
80
80
|
|
81
81
|
context "Id3" do
|
82
82
|
|
83
83
|
it "initializes the Id3 tag" do
|
84
|
-
LAME.
|
84
|
+
expect(LAME).to receive(:id3tag_init).with(global_flags)
|
85
85
|
Configuration::Id3.new(global_flags)
|
86
86
|
end
|
87
87
|
|
@@ -89,17 +89,17 @@ module LAME
|
|
89
89
|
|
90
90
|
describe "#apply! / #applied?" do
|
91
91
|
it "is not applied by default" do
|
92
|
-
configuration.
|
92
|
+
expect(configuration).not_to be_applied
|
93
93
|
end
|
94
94
|
|
95
95
|
it "applies the configuration" do
|
96
|
-
LAME.
|
96
|
+
expect(LAME).to receive(:lame_init_params).with(global_flags)
|
97
97
|
configuration.apply!
|
98
|
-
configuration.
|
98
|
+
expect(configuration).to be_applied
|
99
99
|
end
|
100
100
|
|
101
101
|
it "raises an error if configuration could not be applied" do
|
102
|
-
LAME.
|
102
|
+
allow(LAME).to receive(:lame_init_params).and_return(-1)
|
103
103
|
expect {
|
104
104
|
configuration.apply!
|
105
105
|
}.to raise_error(ConfigurationError)
|
@@ -109,12 +109,12 @@ module LAME
|
|
109
109
|
describe "#framesize" do
|
110
110
|
|
111
111
|
it "gets framesize from LAME if configuration was applied" do
|
112
|
-
LAME.
|
112
|
+
allow(LAME).to receive(:lame_init_params)
|
113
113
|
configuration.apply!
|
114
114
|
|
115
|
-
LAME.
|
116
|
-
LAME.
|
117
|
-
configuration.framesize.
|
115
|
+
allow(LAME).to receive(:lame_get_framesize).and_return(42)
|
116
|
+
expect(LAME).to receive(:lame_get_framesize).with(global_flags)
|
117
|
+
expect(configuration.framesize).to eql 42
|
118
118
|
end
|
119
119
|
|
120
120
|
it "raises an error if configuration was not applied" do
|
@@ -124,12 +124,12 @@ module LAME
|
|
124
124
|
end
|
125
125
|
|
126
126
|
it "calculates the output buffer size based on the framesize" do
|
127
|
-
LAME.
|
127
|
+
allow(LAME).to receive(:lame_init_params)
|
128
128
|
configuration.apply!
|
129
129
|
|
130
|
-
LAME.
|
131
|
-
LAME.
|
132
|
-
configuration.output_buffer_size.
|
130
|
+
allow(LAME).to receive(:lame_get_framesize).and_return(1152)
|
131
|
+
expect(LAME).to receive(:lame_get_framesize).with(global_flags)
|
132
|
+
expect(configuration.output_buffer_size).to eql 8640
|
133
133
|
end
|
134
134
|
|
135
135
|
end
|
@@ -148,7 +148,7 @@ module LAME
|
|
148
148
|
#
|
149
149
|
context "set/get delegation" do
|
150
150
|
|
151
|
-
let(:global_flags) {
|
151
|
+
let(:global_flags) { double(GlobalFlags) }
|
152
152
|
subject(:configuration) { Configuration.new(global_flags) }
|
153
153
|
|
154
154
|
context "basic fields" do
|
@@ -183,8 +183,8 @@ module LAME
|
|
183
183
|
it { should delegate(:emphasis) }
|
184
184
|
|
185
185
|
it "delegates #preset= to LAME.lame_set_preset" do
|
186
|
-
LAME.
|
187
|
-
configuration.preset =
|
186
|
+
expect(LAME).to receive(:lame_set_preset).with(global_flags, anything)
|
187
|
+
configuration.preset = double
|
188
188
|
end
|
189
189
|
|
190
190
|
end
|
@@ -193,17 +193,17 @@ module LAME
|
|
193
193
|
subject(:asm_optimization) { configuration.asm_optimization }
|
194
194
|
|
195
195
|
it "delegates #mmx to LAME.lame_set_asm_optimizations" do
|
196
|
-
LAME.
|
196
|
+
expect(LAME).to receive(:lame_set_asm_optimizations).with(global_flags, :MMX, 1)
|
197
197
|
asm_optimization.mmx = true
|
198
198
|
end
|
199
199
|
|
200
200
|
it "delegates #amd_3dnow to LAME.lame_set_asm_optimizations" do
|
201
|
-
LAME.
|
201
|
+
expect(LAME).to receive(:lame_set_asm_optimizations).with(global_flags, :AMD_3DNOW, 1)
|
202
202
|
asm_optimization.amd_3dnow = true
|
203
203
|
end
|
204
204
|
|
205
205
|
it "delegates #sse to LAME.lame_set_asm_optimizations" do
|
206
|
-
LAME.
|
206
|
+
expect(LAME).to receive(:lame_set_asm_optimizations).with(global_flags, :SSE, 1)
|
207
207
|
asm_optimization.sse = true
|
208
208
|
end
|
209
209
|
end
|
@@ -215,37 +215,37 @@ module LAME
|
|
215
215
|
it { should delegate(:write_automatic).to(:write_id3tag_automatic) }
|
216
216
|
|
217
217
|
before do
|
218
|
-
LAME.
|
218
|
+
allow(LAME).to receive(:id3tag_init)
|
219
219
|
end
|
220
220
|
|
221
221
|
it "delegates #v2= to LAME.id3tag_add_v2" do
|
222
|
-
LAME.
|
222
|
+
expect(LAME).to receive(:id3tag_add_v2).with(global_flags)
|
223
223
|
id3.v2 = true
|
224
224
|
end
|
225
225
|
|
226
226
|
it "delegates #v1_only= to LAME.id3tag_v1_only" do
|
227
|
-
LAME.
|
227
|
+
expect(LAME).to receive(:id3tag_v1_only).with(global_flags)
|
228
228
|
id3.v1_only = true
|
229
229
|
end
|
230
230
|
|
231
231
|
it "delegates #v2_only= to LAME.id3tag_v2_only" do
|
232
|
-
LAME.
|
232
|
+
expect(LAME).to receive(:id3tag_v2_only).with(global_flags)
|
233
233
|
id3.v2_only = true
|
234
234
|
end
|
235
235
|
|
236
236
|
it "delegates #v1_space= to LAME.id3tag_v1_space" do
|
237
|
-
LAME.
|
237
|
+
expect(LAME).to receive(:id3tag_space_v1).with(global_flags)
|
238
238
|
id3.v1_space = true
|
239
239
|
end
|
240
240
|
|
241
241
|
it "delegates #v2_padding= to LAME.id3tag_pad_v2" do
|
242
|
-
LAME.
|
242
|
+
expect(LAME).to receive(:id3tag_pad_v2).with(global_flags)
|
243
243
|
id3.v2_padding = true
|
244
244
|
end
|
245
245
|
|
246
246
|
it "delegates #v2_padding_size= to LAME.id3tag_set_pad" do
|
247
|
-
value =
|
248
|
-
LAME.
|
247
|
+
value = double
|
248
|
+
expect(LAME).to receive(:id3tag_set_pad).with(global_flags, value)
|
249
249
|
id3.v2_padding_size = value
|
250
250
|
end
|
251
251
|
|
@@ -253,10 +253,10 @@ module LAME
|
|
253
253
|
[ :title, :artist, :album, :year, :comment ].each do |field|
|
254
254
|
|
255
255
|
it "sets the #{field} with string buffer" do
|
256
|
-
LAME.
|
257
|
-
flags.
|
258
|
-
string_buffer.
|
259
|
-
string_buffer.get_string(0).
|
256
|
+
expect(LAME).to receive(:"id3tag_set_#{field}") do |flags, string_buffer|
|
257
|
+
expect(flags).to eql global_flags
|
258
|
+
expect(string_buffer).to be_a(::FFI::MemoryPointer)
|
259
|
+
expect(string_buffer.get_string(0)).to eql "Some #{field}"
|
260
260
|
end
|
261
261
|
id3.send(:"#{field}=", "Some #{field}")
|
262
262
|
end
|
@@ -264,37 +264,37 @@ module LAME
|
|
264
264
|
end
|
265
265
|
|
266
266
|
it "sets the track" do
|
267
|
-
LAME.
|
268
|
-
flags.
|
269
|
-
value.
|
267
|
+
expect(LAME).to receive(:"id3tag_set_track") do |flags, value|
|
268
|
+
expect(flags).to eql global_flags
|
269
|
+
expect(value).to eql 42
|
270
270
|
end
|
271
271
|
id3.track = 42
|
272
272
|
end
|
273
273
|
|
274
274
|
it "sets the genre by name" do
|
275
|
-
LAME.
|
276
|
-
flags.
|
277
|
-
value.
|
278
|
-
value.get_string(0).
|
275
|
+
expect(LAME).to receive(:id3tag_set_genre) do |flags, value|
|
276
|
+
expect(flags).to eql global_flags
|
277
|
+
expect(value).to be_a(::FFI::MemoryPointer)
|
278
|
+
expect(value.get_string(0)).to eql "147"
|
279
279
|
end
|
280
280
|
id3.genre = "SynthPop"
|
281
281
|
end
|
282
282
|
|
283
283
|
it "sets the genre by id" do
|
284
|
-
LAME.
|
285
|
-
flags.
|
286
|
-
value.
|
287
|
-
value.get_string(0).
|
284
|
+
expect(LAME).to receive(:id3tag_set_genre) do |flags, value|
|
285
|
+
expect(flags).to eql global_flags
|
286
|
+
expect(value).to be_a(::FFI::MemoryPointer)
|
287
|
+
expect(value.get_string(0)).to eql "81"
|
288
288
|
end
|
289
289
|
|
290
290
|
id3.genre = 81
|
291
291
|
end
|
292
292
|
|
293
293
|
it "sets non-standard genre name" do
|
294
|
-
LAME.
|
295
|
-
flags.
|
296
|
-
value.
|
297
|
-
value.get_string(0).
|
294
|
+
expect(LAME).to receive(:id3tag_set_genre) do |flags, value|
|
295
|
+
expect(flags).to eql global_flags
|
296
|
+
expect(value).to be_a(::FFI::MemoryPointer)
|
297
|
+
expect(value.get_string(0)).to eql "Ruby FFI Rock"
|
298
298
|
end
|
299
299
|
id3.genre = "Ruby FFI Rock"
|
300
300
|
end
|
@@ -312,23 +312,23 @@ module LAME
|
|
312
312
|
it { should delegate(:msfix) }
|
313
313
|
|
314
314
|
it "delegates #reservoir= to LAME.lame_set_disable_reservoir" do
|
315
|
-
LAME.
|
315
|
+
expect(LAME).to receive(:lame_set_disable_reservoir).with(global_flags, 1)
|
316
316
|
quantization.reservoir = false
|
317
317
|
end
|
318
318
|
|
319
319
|
it "delegates #reservoir to LAME.lame_get_disable_reservoir" do
|
320
|
-
LAME.
|
320
|
+
expect(LAME).to receive(:lame_get_disable_reservoir).with(global_flags)
|
321
321
|
quantization.reservoir
|
322
322
|
end
|
323
323
|
|
324
324
|
it "delegates #reservoir? to LAME.lame_get_disable_reservoir" do
|
325
|
-
LAME.
|
325
|
+
expect(LAME).to receive(:lame_get_disable_reservoir).with(global_flags)
|
326
326
|
quantization.reservoir?
|
327
327
|
end
|
328
328
|
|
329
329
|
it "converts the return value 0 for #reservoir? to false" do
|
330
|
-
LAME.
|
331
|
-
quantization.reservoir
|
330
|
+
allow(LAME).to receive(:lame_get_disable_reservoir).and_return(0)
|
331
|
+
expect(quantization.reservoir?).to be_falsy
|
332
332
|
end
|
333
333
|
end
|
334
334
|
|
@@ -365,23 +365,23 @@ module LAME
|
|
365
365
|
it { should delegate(:athaa_sensitivity) }
|
366
366
|
|
367
367
|
it "delegates #ath= to LAME.lame_set_noATH" do
|
368
|
-
LAME.
|
368
|
+
expect(LAME).to receive(:lame_set_noATH).with(global_flags, 1)
|
369
369
|
psycho_acoustics.ath = false
|
370
370
|
end
|
371
371
|
|
372
372
|
it "delegates #ath to LAME.lame_get_noATH" do
|
373
|
-
LAME.
|
373
|
+
expect(LAME).to receive(:lame_get_noATH).with(global_flags)
|
374
374
|
psycho_acoustics.ath
|
375
375
|
end
|
376
376
|
|
377
377
|
it "delegates #ath? to LAME.lame_get_noATH" do
|
378
|
-
LAME.
|
378
|
+
expect(LAME).to receive(:lame_get_noATH).with(global_flags)
|
379
379
|
psycho_acoustics.ath?
|
380
380
|
end
|
381
381
|
|
382
382
|
it "converts the return value 0 for #ath? to true" do
|
383
|
-
LAME.
|
384
|
-
psycho_acoustics.ath
|
383
|
+
allow(LAME).to receive(:lame_get_noATH).and_return(0)
|
384
|
+
expect(psycho_acoustics.ath?).to be_truthy
|
385
385
|
end
|
386
386
|
end
|
387
387
|
|