lame 0.0.2 → 0.0.3
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.
- data/lib/lame/ffi/functions.rb +1 -1
- data/lib/lame/version.rb +1 -1
- data/spec/ffi/encoding_spec.rb +9 -0
- data/spec/integration/decoding_spec.rb +7 -5
- data/spec/integration/encoding_spec.rb +24 -0
- metadata +3 -3
data/lib/lame/ffi/functions.rb
CHANGED
@@ -182,7 +182,7 @@ module LAME
|
|
182
182
|
|
183
183
|
# encoding
|
184
184
|
attach_function :lame_encode_buffer, [:global_flags, :buffer_in, :buffer_in, :int, :buffer_out, :int], :int
|
185
|
-
attach_function :lame_encode_buffer_interleaved, [:global_flags, :buffer_in,
|
185
|
+
attach_function :lame_encode_buffer_interleaved, [:global_flags, :buffer_in, :int, :buffer_out, :int], :int
|
186
186
|
attach_function :lame_encode_buffer_float, [:global_flags, :buffer_in, :buffer_in, :int, :buffer_out, :int], :int
|
187
187
|
attach_function :lame_encode_buffer_ieee_float, [:global_flags, :buffer_in, :buffer_in, :int, :buffer_out, :int], :int
|
188
188
|
attach_function :lame_encode_buffer_interleaved_ieee_float, [:global_flags, :buffer_in, :int, :buffer_out, :int], :int
|
data/lib/lame/version.rb
CHANGED
data/spec/ffi/encoding_spec.rb
CHANGED
@@ -105,6 +105,15 @@ module LAME
|
|
105
105
|
|
106
106
|
context "interleaved" do
|
107
107
|
|
108
|
+
context "short-buffer" do
|
109
|
+
let(:input_type) { :short }
|
110
|
+
|
111
|
+
it "encodes" do
|
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
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
108
117
|
context "ieee float-buffer" do
|
109
118
|
let(:input_type) { :float }
|
110
119
|
|
@@ -24,9 +24,11 @@ describe "Decoding", :slow => true do
|
|
24
24
|
end
|
25
25
|
|
26
26
|
it "decodes an MP3 file" do
|
27
|
+
@debug = false
|
28
|
+
|
27
29
|
# id3
|
28
30
|
id3_length = id3_length(mp3_file)
|
29
|
-
puts "ID3 length: #{id3_length} bytes"
|
31
|
+
puts "ID3 length: #{id3_length} bytes" if @debug
|
30
32
|
mp3_file.read(id3_length)
|
31
33
|
|
32
34
|
# aid TODO (ignored for now)
|
@@ -34,7 +36,7 @@ describe "Decoding", :slow => true do
|
|
34
36
|
# find MP3 sync frame
|
35
37
|
|
36
38
|
mp3_offset = mpeg_audio_offset(mp3_file, id3_length)
|
37
|
-
puts "offset: #{mp3_offset}"
|
39
|
+
puts "offset: #{mp3_offset}" if @debug
|
38
40
|
|
39
41
|
@decode_flags = LAME::FFI::DecodeFlags.new
|
40
42
|
@mp3_data = LAME::FFI::MP3Data.new
|
@@ -46,7 +48,7 @@ describe "Decoding", :slow => true do
|
|
46
48
|
end until @mp3_data.header_parsed?
|
47
49
|
|
48
50
|
# Results:
|
49
|
-
if @mp3_data.header_parsed?
|
51
|
+
if @mp3_data.header_parsed? && @debug
|
50
52
|
puts "stereo: #{@mp3_data[:stereo]}"
|
51
53
|
puts "samplerate: #{@mp3_data[:samplerate]}"
|
52
54
|
puts "bitrate: #{@mp3_data[:bitrate]}"
|
@@ -95,7 +97,7 @@ describe "Decoding", :slow => true do
|
|
95
97
|
|
96
98
|
result = LAME.hip_decode1_headersB(@decode_flags, in_buffer, size, out_left, out_right, @mp3_data, enc_delay, enc_padding)
|
97
99
|
|
98
|
-
if @mp3_data.header_parsed?
|
100
|
+
if @mp3_data.header_parsed? && @debug
|
99
101
|
puts "header parsed @ #{mp3_file.pos}"
|
100
102
|
puts "enc_delay: #{enc_delay.read_array_of_int(1)}"
|
101
103
|
puts "enc_padding: #{enc_padding.read_array_of_int(1)}"
|
@@ -151,7 +153,7 @@ describe "Decoding", :slow => true do
|
|
151
153
|
in_data = mp3_file.read(window_size)
|
152
154
|
|
153
155
|
if LAME::Decoding::MPEGAudioFrameMatcher.new(in_data).match?
|
154
|
-
puts "match offset @ #{offset} : #{in_data.bytes.to_a[0].to_s(2)} #{in_data.bytes.to_a[1].to_s(2)} #{in_data.bytes.to_a[2].to_s(2)} #{in_data.bytes.to_a[3].to_s(2)}"
|
156
|
+
puts "match offset @ #{offset} : #{in_data.bytes.to_a[0].to_s(2)} #{in_data.bytes.to_a[1].to_s(2)} #{in_data.bytes.to_a[2].to_s(2)} #{in_data.bytes.to_a[3].to_s(2)}" if @debug
|
155
157
|
return offset
|
156
158
|
end
|
157
159
|
|
@@ -63,6 +63,30 @@ describe "Encoding", :slow => true do
|
|
63
63
|
# Digest::MD5.hexdigest(File.read(mp3_path_api)).should eql "d1cd92c106e7aac4f5291fd141a19e10"
|
64
64
|
end
|
65
65
|
|
66
|
+
it "encodes a file using interleaved api" do
|
67
|
+
|
68
|
+
encoder = LAME::Encoder.new
|
69
|
+
|
70
|
+
encoder.configure do |config|
|
71
|
+
config.bitrate = 192
|
72
|
+
end
|
73
|
+
|
74
|
+
File.open(mp3_path_api, "wb") do |file|
|
75
|
+
|
76
|
+
wav_reader.each_buffer(encoder.framesize) do |read_buffer|
|
77
|
+
encoder.encode_interleaved_short(read_buffer.samples.flatten) do |mp3|
|
78
|
+
file.write mp3
|
79
|
+
end
|
80
|
+
end
|
81
|
+
encoder.flush do |flush_frame|
|
82
|
+
file.write(flush_frame)
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
# TODO: Need a better way to test output..
|
87
|
+
# Digest::MD5.hexdigest(File.read(mp3_path_api)).should eql "d1cd92c106e7aac4f5291fd141a19e10"
|
88
|
+
end
|
89
|
+
|
66
90
|
# This test serves as an example how to use the LAME API
|
67
91
|
it "encodes a wav file" do
|
68
92
|
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: lame
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.0.
|
5
|
+
version: 0.0.3
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Roel van Dijk
|
@@ -213,7 +213,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
213
213
|
requirements:
|
214
214
|
- - ! '>='
|
215
215
|
- !ruby/object:Gem::Version
|
216
|
-
hash:
|
216
|
+
hash: 220624676423183308
|
217
217
|
segments:
|
218
218
|
- 0
|
219
219
|
version: '0'
|
@@ -222,7 +222,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
222
222
|
requirements:
|
223
223
|
- - ! '>='
|
224
224
|
- !ruby/object:Gem::Version
|
225
|
-
hash:
|
225
|
+
hash: 220624676423183308
|
226
226
|
segments:
|
227
227
|
- 0
|
228
228
|
version: '0'
|