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.
- checksums.yaml +7 -0
- data/.github/workflows/ci.yml +47 -0
- data/.travis.yml +3 -4
- data/README.md +51 -19
- data/docs/lame-3.101.h +1357 -0
- data/lame.gemspec +2 -1
- data/lib/lame/buffer.rb +1 -1
- data/lib/lame/encoder.rb +10 -11
- data/lib/lame/encoding/interleaved_int_buffer_encoder.rb +15 -0
- data/lib/lame/encoding/long_buffer_encoder.rb +1 -1
- data/lib/lame/encoding/stereo_buffer_encoder.rb +1 -0
- data/lib/lame/ffi/functions.rb +99 -38
- data/lib/lame/ffi.rb +2 -0
- data/lib/lame/version.rb +1 -1
- data/lib/lame.rb +2 -0
- 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 +32 -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 +166 -160
- data/spec/ffi/id3tag_spec.rb +26 -26
- 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 +14 -10
- metadata +58 -67
data/lame.gemspec
CHANGED
|
@@ -24,5 +24,6 @@ Gem::Specification.new do |gem|
|
|
|
24
24
|
gem.add_development_dependency "pry"
|
|
25
25
|
gem.add_development_dependency "wavefile"
|
|
26
26
|
gem.add_development_dependency "ruby-mp3info"
|
|
27
|
-
gem.add_development_dependency "
|
|
27
|
+
gem.add_development_dependency "simplecov", "~> 0.22"
|
|
28
|
+
gem.add_development_dependency "simplecov-lcov", "~> 0.8"
|
|
28
29
|
end
|
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/functions.rb
CHANGED
|
@@ -75,22 +75,22 @@ module LAME
|
|
|
75
75
|
attach_function :lame_get_strict_ISO, [:global_flags], :int
|
|
76
76
|
|
|
77
77
|
# quantization/noise shaping
|
|
78
|
-
attach_function :lame_set_disable_reservoir,
|
|
79
|
-
attach_function :lame_get_disable_reservoir,
|
|
80
|
-
attach_function :lame_set_quant_comp,
|
|
81
|
-
attach_function :lame_get_quant_comp,
|
|
82
|
-
attach_function :lame_set_quant_comp_short,
|
|
83
|
-
attach_function :lame_get_quant_comp_short,
|
|
84
|
-
attach_function :lame_set_experimentalX,
|
|
85
|
-
attach_function :lame_get_experimentalX,
|
|
86
|
-
attach_function :lame_set_experimentalY,
|
|
87
|
-
attach_function :lame_get_experimentalY,
|
|
88
|
-
attach_function :lame_set_experimentalZ,
|
|
89
|
-
attach_function :lame_get_experimentalZ,
|
|
90
|
-
attach_function :lame_set_exp_nspsytune,
|
|
91
|
-
attach_function :lame_get_exp_nspsytune,
|
|
92
|
-
attach_function :lame_set_msfix,
|
|
93
|
-
attach_function :lame_get_msfix,
|
|
78
|
+
attach_function :lame_set_disable_reservoir, [:global_flags, :int], :int
|
|
79
|
+
attach_function :lame_get_disable_reservoir, [:global_flags], :int
|
|
80
|
+
attach_function :lame_set_quant_comp, [:global_flags, :int], :int
|
|
81
|
+
attach_function :lame_get_quant_comp, [:global_flags], :int
|
|
82
|
+
attach_function :lame_set_quant_comp_short, [:global_flags, :int], :int
|
|
83
|
+
attach_function :lame_get_quant_comp_short, [:global_flags], :int
|
|
84
|
+
attach_function :lame_set_experimentalX, [:global_flags, :int], :int
|
|
85
|
+
attach_function :lame_get_experimentalX, [:global_flags], :int
|
|
86
|
+
attach_function :lame_set_experimentalY, [:global_flags, :int], :int
|
|
87
|
+
attach_function :lame_get_experimentalY, [:global_flags], :int
|
|
88
|
+
attach_function :lame_set_experimentalZ, [:global_flags, :int], :int
|
|
89
|
+
attach_function :lame_get_experimentalZ, [:global_flags], :int
|
|
90
|
+
attach_function :lame_set_exp_nspsytune, [:global_flags, :int], :int
|
|
91
|
+
attach_function :lame_get_exp_nspsytune, [:global_flags], :int
|
|
92
|
+
attach_function :native_lame_set_msfix, :lame_set_msfix, [:global_flags, :double], :void
|
|
93
|
+
attach_function :lame_get_msfix, [:global_flags], :float
|
|
94
94
|
|
|
95
95
|
# VBR
|
|
96
96
|
attach_function :lame_set_VBR, [:global_flags, :vbr_mode], :int
|
|
@@ -174,7 +174,7 @@ module LAME
|
|
|
174
174
|
attach_function :get_lame_url, [], :string
|
|
175
175
|
attach_function :get_lame_os_bitness, [], :string
|
|
176
176
|
|
|
177
|
-
attach_function :get_lame_version_numerical, [:global_flags],
|
|
177
|
+
attach_function :get_lame_version_numerical, [:global_flags], :void
|
|
178
178
|
|
|
179
179
|
# TODO: test when we have implemented lame_set_msgf
|
|
180
180
|
attach_function :lame_print_config, [:global_flags], :void
|
|
@@ -191,6 +191,7 @@ module LAME
|
|
|
191
191
|
attach_function :lame_encode_buffer_long, [:global_flags, :buffer_in, :buffer_in, :int, :buffer_out, :int], :int
|
|
192
192
|
attach_function :lame_encode_buffer_long2, [:global_flags, :buffer_in, :buffer_in, :int, :buffer_out, :int], :int
|
|
193
193
|
attach_function :lame_encode_buffer_int, [:global_flags, :buffer_in, :buffer_in, :int, :buffer_out, :int], :int
|
|
194
|
+
attach_function :lame_encode_buffer_interleaved_int, [:global_flags, :buffer_in, :int, :buffer_out, :int], :int
|
|
194
195
|
|
|
195
196
|
# flushing
|
|
196
197
|
attach_function :lame_encode_flush, [:global_flags, :pointer, :int], :int
|
|
@@ -233,27 +234,27 @@ module LAME
|
|
|
233
234
|
|
|
234
235
|
# id3
|
|
235
236
|
callback :genre_callback, [:int, :string, :pointer], :void
|
|
236
|
-
attach_function :id3tag_genre_list,
|
|
237
|
-
attach_function :id3tag_init,
|
|
238
|
-
attach_function :id3tag_add_v2,
|
|
239
|
-
attach_function :id3tag_v1_only,
|
|
240
|
-
attach_function :id3tag_v2_only,
|
|
241
|
-
attach_function :id3tag_space_v1,
|
|
242
|
-
attach_function :id3tag_pad_v2,
|
|
243
|
-
attach_function :id3tag_set_pad,
|
|
244
|
-
attach_function :id3tag_set_title,
|
|
245
|
-
attach_function :id3tag_set_artist,
|
|
246
|
-
attach_function :id3tag_set_album,
|
|
247
|
-
attach_function :id3tag_set_year,
|
|
248
|
-
attach_function :id3tag_set_comment,
|
|
249
|
-
attach_function :id3tag_set_track,
|
|
250
|
-
attach_function :id3tag_set_genre,
|
|
251
|
-
attach_function :id3tag_set_fieldvalue,
|
|
252
|
-
attach_function :id3tag_set_albumart,
|
|
253
|
-
attach_function :lame_get_id3v1_tag,
|
|
254
|
-
attach_function :lame_get_id3v2_tag,
|
|
255
|
-
attach_function :lame_set_write_id3tag_automatic, [:global_flags, :int], :void
|
|
256
|
-
attach_function :lame_get_write_id3tag_automatic,
|
|
237
|
+
attach_function :id3tag_genre_list, [:genre_callback, :pointer], :void
|
|
238
|
+
attach_function :native_id3tag_init, :id3tag_init, [:global_flags], :void
|
|
239
|
+
attach_function :native_id3tag_add_v2, :id3tag_add_v2, [:global_flags], :void
|
|
240
|
+
attach_function :native_id3tag_v1_only, :id3tag_v1_only, [:global_flags], :void
|
|
241
|
+
attach_function :native_id3tag_v2_only, :id3tag_v2_only, [:global_flags], :void
|
|
242
|
+
attach_function :native_id3tag_space_v1, :id3tag_space_v1, [:global_flags], :void
|
|
243
|
+
attach_function :native_id3tag_pad_v2, :id3tag_pad_v2, [:global_flags], :void
|
|
244
|
+
attach_function :native_id3tag_set_pad, :id3tag_set_pad, [:global_flags, :size_t], :void
|
|
245
|
+
attach_function :native_id3tag_set_title, :id3tag_set_title, [:global_flags, :pointer], :void
|
|
246
|
+
attach_function :native_id3tag_set_artist, :id3tag_set_artist, [:global_flags, :pointer], :void
|
|
247
|
+
attach_function :native_id3tag_set_album, :id3tag_set_album, [:global_flags, :pointer], :void
|
|
248
|
+
attach_function :native_id3tag_set_year, :id3tag_set_year, [:global_flags, :pointer], :void
|
|
249
|
+
attach_function :native_id3tag_set_comment, :id3tag_set_comment, [:global_flags, :pointer], :void
|
|
250
|
+
attach_function :id3tag_set_track, [:global_flags, :pointer], :int
|
|
251
|
+
attach_function :id3tag_set_genre, [:global_flags, :pointer], :int
|
|
252
|
+
attach_function :id3tag_set_fieldvalue, [:global_flags, :pointer], :int
|
|
253
|
+
attach_function :id3tag_set_albumart, [:global_flags, :buffer_in, :size_t], :int
|
|
254
|
+
attach_function :lame_get_id3v1_tag, [:global_flags, :buffer_out, :size_t], :size_t
|
|
255
|
+
attach_function :lame_get_id3v2_tag, [:global_flags, :buffer_out, :size_t], :size_t
|
|
256
|
+
attach_function :native_lame_set_write_id3tag_automatic, :lame_set_write_id3tag_automatic, [:global_flags, :int], :void
|
|
257
|
+
attach_function :lame_get_write_id3tag_automatic, [:global_flags], :int
|
|
257
258
|
# experimental id3:
|
|
258
259
|
# attach_function :id3tag_set_textinfo_latin1, [:global_flags, :string, :string], :int
|
|
259
260
|
# attach_function :id3tag_set_comment_latin1, [:global_flags, :string, :string, :string], :int
|
|
@@ -264,6 +265,66 @@ module LAME
|
|
|
264
265
|
# tables
|
|
265
266
|
attach_function :lame_get_bitrate, [:int, :int], :int
|
|
266
267
|
attach_function :lame_get_samplerate, [:int, :int], :int
|
|
268
|
+
end
|
|
269
|
+
|
|
270
|
+
# for truffleruby compatibility, return nil explicitly
|
|
271
|
+
base.singleton_class.class_eval do
|
|
272
|
+
def lame_set_msfix(global_flags, double)
|
|
273
|
+
native_lame_set_msfix(global_flags, double)
|
|
274
|
+
nil
|
|
275
|
+
end
|
|
276
|
+
def id3tag_init(global_flags)
|
|
277
|
+
native_id3tag_init(global_flags)
|
|
278
|
+
nil
|
|
279
|
+
end
|
|
280
|
+
def id3tag_add_v2(global_flags)
|
|
281
|
+
native_id3tag_add_v2(global_flags)
|
|
282
|
+
nil
|
|
283
|
+
end
|
|
284
|
+
def id3tag_v1_only(global_flags)
|
|
285
|
+
native_id3tag_v1_only(global_flags)
|
|
286
|
+
nil
|
|
287
|
+
end
|
|
288
|
+
def id3tag_v2_only(global_flags)
|
|
289
|
+
native_id3tag_v2_only(global_flags)
|
|
290
|
+
nil
|
|
291
|
+
end
|
|
292
|
+
def id3tag_space_v1(global_flags)
|
|
293
|
+
native_id3tag_space_v1(global_flags)
|
|
294
|
+
nil
|
|
295
|
+
end
|
|
296
|
+
def id3tag_pad_v2(global_flags)
|
|
297
|
+
native_id3tag_pad_v2(global_flags)
|
|
298
|
+
nil
|
|
299
|
+
end
|
|
300
|
+
def id3tag_set_pad(global_flags, size_t)
|
|
301
|
+
native_id3tag_set_pad(global_flags, size_t)
|
|
302
|
+
nil
|
|
303
|
+
end
|
|
304
|
+
def id3tag_set_title(global_flags, pointer)
|
|
305
|
+
native_id3tag_set_title(global_flags, pointer)
|
|
306
|
+
nil
|
|
307
|
+
end
|
|
308
|
+
def id3tag_set_artist(global_flags, pointer)
|
|
309
|
+
native_id3tag_set_artist(global_flags, pointer)
|
|
310
|
+
nil
|
|
311
|
+
end
|
|
312
|
+
def id3tag_set_album(global_flags, pointer)
|
|
313
|
+
native_id3tag_set_album(global_flags, pointer)
|
|
314
|
+
nil
|
|
315
|
+
end
|
|
316
|
+
def id3tag_set_year(global_flags, pointer)
|
|
317
|
+
native_id3tag_set_year(global_flags, pointer)
|
|
318
|
+
nil
|
|
319
|
+
end
|
|
320
|
+
def id3tag_set_comment(global_flags, pointer)
|
|
321
|
+
native_id3tag_set_comment(global_flags, pointer)
|
|
322
|
+
nil
|
|
323
|
+
end
|
|
324
|
+
def lame_set_write_id3tag_automatic(global_flags, int)
|
|
325
|
+
native_lame_set_write_id3tag_automatic(global_flags, int)
|
|
326
|
+
nil
|
|
327
|
+
end
|
|
267
328
|
|
|
268
329
|
end
|
|
269
330
|
end
|
data/lib/lame/ffi.rb
CHANGED
data/lib/lame/version.rb
CHANGED
data/lib/lame.rb
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
require "ffi"
|
|
2
|
+
require "forwardable"
|
|
2
3
|
require "lame/version"
|
|
3
4
|
require "lame/ffi"
|
|
4
5
|
require "lame/error"
|
|
@@ -13,6 +14,7 @@ require "lame/encoding/long_buffer_encoder"
|
|
|
13
14
|
require "lame/encoding/interleaved_buffer_encoder"
|
|
14
15
|
require "lame/encoding/interleaved_short_buffer_encoder"
|
|
15
16
|
require "lame/encoding/interleaved_float_buffer_encoder"
|
|
17
|
+
require "lame/encoding/interleaved_int_buffer_encoder"
|
|
16
18
|
require "lame/encoding/flusher"
|
|
17
19
|
require "lame/encoding/id3"
|
|
18
20
|
require "lame/encoding/vbr_info"
|
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
|