waveinfo 0.0.4 → 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 +4 -4
- data/LICENSE.md +1 -1
- data/README.md +2 -17
- data/bin/waveinfo +1 -1
- data/lib/waveinfo.rb +78 -30
- data/lib/waveinfo/version.rb +1 -1
- data/spec/waveinfo_spec.rb +121 -51
- metadata +16 -17
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3992b0d0d7399d87f208ba8f945ccc5222d17e42
|
4
|
+
data.tar.gz: a2bfac5fb6489d62c3e8d62a18d884adab5e660b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4e94a35da99220464a0aedab63733eaa2d3c080de0ef22ada7fcd5e91f2d06e1b44fcb1d94c573fc6b04e1e1cfb36326f4af6df6ba82b71d2131cf477c54fc9f
|
7
|
+
data.tar.gz: bb01a4c1eeef8a5e7031f4591c95687874c9ef70470d1b8913e9a0d191f61e3041fce4d6fc288f05d323215de0789c35226df5b86b28c9ebbce7a792ab6d2403
|
data/LICENSE.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
The MIT License (MIT)
|
2
2
|
|
3
|
-
Copyright (c) 2009-
|
3
|
+
Copyright (c) 2009-2015 Nicholas J Humfrey
|
4
4
|
|
5
5
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
6
|
of this software and associated documentation files (the "Software"), to deal
|
data/README.md
CHANGED
@@ -26,21 +26,6 @@ Synopsis
|
|
26
26
|
puts "Duration: #{wave.duration} secs"
|
27
27
|
|
28
28
|
|
29
|
-
TODO
|
30
|
-
----
|
31
|
-
|
32
|
-
* Add support for the extensible format which uses GUIDs
|
33
|
-
* Inplement more validity checks
|
34
|
-
- file is shorter than reported chunk size
|
35
|
-
- file is longer than reported chunk size
|
36
|
-
* Implement more chunk types
|
37
|
-
- bext - Broadcast Wave Extention
|
38
|
-
- mext - MPEG audio extension chunk
|
39
|
-
- DISP - Title
|
40
|
-
- cart - CartChunk/aes46-2002
|
41
|
-
- LIST
|
42
|
-
* Test against more weird Wave files
|
43
|
-
|
44
29
|
|
45
30
|
Resources
|
46
31
|
---------
|
@@ -60,6 +45,6 @@ Contact
|
|
60
45
|
-------
|
61
46
|
|
62
47
|
* Author: Nicholas J Humfrey
|
63
|
-
*
|
64
|
-
* Home Page:
|
48
|
+
* Twitter: [@njh](https://twitter.com/njh)
|
49
|
+
* Home Page: https://www.aelius.com/njh/
|
65
50
|
|
data/bin/waveinfo
CHANGED
@@ -11,7 +11,7 @@ end
|
|
11
11
|
ARGV.each do |arg|
|
12
12
|
wave = WaveInfo.new(arg)
|
13
13
|
puts "Filename : #{wave.filename}"
|
14
|
-
puts "Audio Format : #{wave.audio_format} " +
|
14
|
+
puts "Audio Format : #{wave.audio_format} " +
|
15
15
|
sprintf("(0x%2.2x)",wave.audio_format_id)
|
16
16
|
puts "Duration : " + sprintf("%2.2fs", wave.duration)
|
17
17
|
puts "Channels : #{wave.channels}"
|
data/lib/waveinfo.rb
CHANGED
@@ -8,10 +8,10 @@ class WaveInfo
|
|
8
8
|
end
|
9
9
|
self.debug = true
|
10
10
|
|
11
|
-
# Create a new WaveInfo object to get information and metadata about a
|
11
|
+
# Create a new WaveInfo object to get information and metadata about a
|
12
12
|
# Wave file (.wav). 'file' can either be a filename or an IO object.
|
13
13
|
def initialize(file)
|
14
|
-
|
14
|
+
|
15
15
|
# Set default values
|
16
16
|
@audio_format_id = 0
|
17
17
|
@bits_per_sample = nil
|
@@ -21,7 +21,7 @@ class WaveInfo
|
|
21
21
|
@data_size = nil
|
22
22
|
@sample_rate = nil
|
23
23
|
@samples = nil
|
24
|
-
|
24
|
+
|
25
25
|
# What was passed in to us?
|
26
26
|
if file.is_a?(String)
|
27
27
|
@io = File.new(file, 'rb')
|
@@ -34,12 +34,12 @@ class WaveInfo
|
|
34
34
|
read_headers
|
35
35
|
end
|
36
36
|
end
|
37
|
-
|
37
|
+
|
38
38
|
# Return the name of the input file.
|
39
39
|
def filename
|
40
40
|
File.basename(@filepath)
|
41
41
|
end
|
42
|
-
|
42
|
+
|
43
43
|
# Get the identifier of the audio codec (for example PCM would be 1).
|
44
44
|
def audio_format_id
|
45
45
|
@audio_format_id
|
@@ -74,7 +74,7 @@ class WaveInfo
|
|
74
74
|
sprintf("Unknown (0x%2.2x)",@audio_format_id)
|
75
75
|
end
|
76
76
|
end
|
77
|
-
|
77
|
+
|
78
78
|
# Get the number of channels.
|
79
79
|
def channels
|
80
80
|
@channels
|
@@ -99,39 +99,58 @@ class WaveInfo
|
|
99
99
|
def bits_per_sample
|
100
100
|
@bits_per_sample
|
101
101
|
end
|
102
|
-
|
102
|
+
|
103
103
|
# Get the total number of samples.
|
104
104
|
def samples
|
105
105
|
if @samples
|
106
106
|
@samples
|
107
|
-
|
108
|
-
@data_size / @block_align
|
107
|
+
elsif @block_align.to_f.nonzero?
|
108
|
+
@data_size && @block_align ? @data_size / @block_align : 0.0
|
109
|
+
else
|
110
|
+
0.0
|
109
111
|
end
|
110
112
|
end
|
111
|
-
|
113
|
+
|
112
114
|
# Get the length of the audio data (in bytes).
|
113
115
|
def size
|
114
116
|
@data_size
|
115
117
|
end
|
116
|
-
|
118
|
+
|
117
119
|
# Get the duration of the audio (in seconds).
|
118
120
|
def duration
|
119
|
-
|
121
|
+
if sample_rate.to_f.nonzero?
|
122
|
+
sample_rate ? samples.to_f / sample_rate.to_f : 0.0
|
123
|
+
else
|
124
|
+
0.0
|
125
|
+
end
|
120
126
|
end
|
121
127
|
|
128
|
+
|
122
129
|
private
|
123
130
|
|
124
131
|
def read_headers
|
125
132
|
# Read in the chunk header
|
126
|
-
chunk_id = read_fourchar
|
127
|
-
|
128
|
-
|
129
|
-
chunk_format
|
130
|
-
|
131
|
-
|
133
|
+
@chunk_id = read_fourchar
|
134
|
+
@chunk_size = read_longint
|
135
|
+
@chunk_format = read_fourchar
|
136
|
+
raise FileFormatError.new("Chunk format is not 'WAVE'") unless @chunk_format == 'WAVE'
|
137
|
+
|
138
|
+
if @chunk_id == 'RIFF'
|
139
|
+
position = 0xC
|
140
|
+
elsif @chunk_id == 'RF64'
|
141
|
+
# Next sub-chunk *has* to be a 'ds64'
|
142
|
+
subchunk_size = read_ds64_chunk
|
143
|
+
position = 0xC + subchunk_size
|
144
|
+
else
|
145
|
+
raise FileFormatError.new("Primary chunk id is not 'RIFF' or 'RF64'")
|
146
|
+
end
|
147
|
+
|
148
|
+
read_subchunks(position)
|
149
|
+
end
|
150
|
+
|
151
|
+
def read_subchunks(position)
|
132
152
|
# Read in each of the sub-chunks
|
133
|
-
position
|
134
|
-
while(chunk_size-position) > 0 do
|
153
|
+
while(@chunk_size - position) > 0 do
|
135
154
|
subchunk_id = read_fourchar
|
136
155
|
subchunk_size = read_longint
|
137
156
|
case subchunk_id
|
@@ -140,9 +159,15 @@ class WaveInfo
|
|
140
159
|
when 'fact'
|
141
160
|
read_fact_chunk(subchunk_size)
|
142
161
|
when 'data'
|
162
|
+
unless subchunk_size == 0xFFFFFFFF
|
143
163
|
@data_size = subchunk_size
|
164
|
+
end
|
144
165
|
# Skip over the wave data
|
145
|
-
@io.seek(
|
166
|
+
@io.seek(@data_size,IO::SEEK_CUR)
|
167
|
+
when nil
|
168
|
+
# Give up if read fails
|
169
|
+
$stderr.puts "Warning: read error before reaching end of file" if WaveInfo.debug
|
170
|
+
break
|
146
171
|
else
|
147
172
|
pos = sprintf("0x%x", position)
|
148
173
|
$stderr.puts "Warning: unsupported sub-chunk at #{pos}: #{subchunk_id}" if WaveInfo.debug
|
@@ -150,7 +175,7 @@ class WaveInfo
|
|
150
175
|
end
|
151
176
|
position += subchunk_size + 8
|
152
177
|
end
|
153
|
-
|
178
|
+
|
154
179
|
end
|
155
180
|
|
156
181
|
def read_fmt_chunk(size)
|
@@ -160,35 +185,58 @@ class WaveInfo
|
|
160
185
|
@byte_rate = read_longint
|
161
186
|
@block_align = read_shortint
|
162
187
|
@bits_per_sample = read_shortint
|
163
|
-
|
188
|
+
|
164
189
|
# Skip any extra parameters
|
165
190
|
@io.seek(size-16,IO::SEEK_CUR) if size > 16
|
166
191
|
end
|
167
|
-
|
192
|
+
|
168
193
|
def read_fact_chunk(size)
|
169
194
|
# Read in the number of samples
|
170
|
-
|
195
|
+
sample_count = read_longint
|
196
|
+
unless sample_count == 0xFFFFFFFF
|
197
|
+
@samples = sample_count
|
198
|
+
end
|
171
199
|
|
172
200
|
# Skip any extra data
|
173
201
|
@io.seek(size-4,IO::SEEK_CUR) if size > 4
|
174
202
|
end
|
175
|
-
|
203
|
+
|
204
|
+
def read_ds64_chunk
|
205
|
+
subchunk_id = read_fourchar
|
206
|
+
raise FileFormatError.new("First sub-chunk of RF64 file is not 'ds64'") unless subchunk_id == 'ds64'
|
207
|
+
subchunk_size = read_longint
|
208
|
+
|
209
|
+
riff_size_low = read_longint
|
210
|
+
riff_size_high = read_longint
|
211
|
+
data_size_low = read_longint
|
212
|
+
data_size_high = read_longint
|
213
|
+
sample_count_low = read_longint
|
214
|
+
sample_count_high = read_longint
|
215
|
+
|
216
|
+
@data_size = (data_size_high << 32) + data_size_low
|
217
|
+
@samples = (sample_count_high << 32) + sample_count_low
|
218
|
+
@chunk_size = (riff_size_high << 32) + riff_size_low
|
219
|
+
|
220
|
+
# Skip any extra data
|
221
|
+
@io.seek(subchunk_size-24,IO::SEEK_CUR) if subchunk_size > 24
|
222
|
+
end
|
223
|
+
|
176
224
|
def read_fourchar
|
177
225
|
@io.read(4)
|
178
226
|
end
|
179
|
-
|
227
|
+
|
180
228
|
def read_longint
|
181
229
|
bytes = @io.read(4)
|
182
230
|
bytes ? bytes.unpack('V').first : nil
|
183
231
|
end
|
184
|
-
|
232
|
+
|
185
233
|
def read_shortint
|
186
234
|
bytes = @io.read(2)
|
187
235
|
bytes ? bytes.unpack('v').first : nil
|
188
236
|
end
|
189
|
-
|
237
|
+
|
190
238
|
# Exception raised if there is a problem parsing the Wave file
|
191
239
|
class FileFormatError < StandardError
|
192
240
|
end
|
193
|
-
|
241
|
+
|
194
242
|
end
|
data/lib/waveinfo/version.rb
CHANGED
data/spec/waveinfo_spec.rb
CHANGED
@@ -31,19 +31,19 @@ describe WaveInfo do
|
|
31
31
|
it "should get the byte rate right" do
|
32
32
|
expect(@wav.byte_rate).to eq(22050)
|
33
33
|
end
|
34
|
-
|
34
|
+
|
35
35
|
it "should get the block align value right" do
|
36
36
|
expect(@wav.block_align).to eq(2)
|
37
37
|
end
|
38
|
-
|
38
|
+
|
39
39
|
it "should get the bits per sample right" do
|
40
40
|
expect(@wav.bits_per_sample).to eq(16)
|
41
41
|
end
|
42
|
-
|
42
|
+
|
43
43
|
it "should get the audio length in bytes right" do
|
44
44
|
expect(@wav.size).to eq(8820)
|
45
45
|
end
|
46
|
-
|
46
|
+
|
47
47
|
it "should get the number of samples right" do
|
48
48
|
expect(@wav.samples).to eq(4410)
|
49
49
|
end
|
@@ -51,7 +51,7 @@ describe WaveInfo do
|
|
51
51
|
it "should get the audio duration right" do
|
52
52
|
expect(@wav.duration).to eq(0.4)
|
53
53
|
end
|
54
|
-
|
54
|
+
|
55
55
|
it "should know the name of the file read from" do
|
56
56
|
expect(@wav.filename).to eq(File.basename(@filepath))
|
57
57
|
end
|
@@ -82,19 +82,19 @@ describe WaveInfo do
|
|
82
82
|
it "should get the byte rate right" do
|
83
83
|
expect(@wav.byte_rate).to eq(1625)
|
84
84
|
end
|
85
|
-
|
85
|
+
|
86
86
|
it "should get the block align value right" do
|
87
87
|
expect(@wav.block_align).to eq(65)
|
88
88
|
end
|
89
|
-
|
89
|
+
|
90
90
|
it "should get the bits per sample right" do
|
91
91
|
expect(@wav.bits_per_sample).to eq(0)
|
92
92
|
end
|
93
|
-
|
93
|
+
|
94
94
|
it "should get the audio length in bytes right" do
|
95
95
|
expect(@wav.size).to eq(650)
|
96
96
|
end
|
97
|
-
|
97
|
+
|
98
98
|
it "should get the number of samples right" do
|
99
99
|
expect(@wav.samples).to eq(3200)
|
100
100
|
end
|
@@ -102,7 +102,7 @@ describe WaveInfo do
|
|
102
102
|
it "should get the audio duration right" do
|
103
103
|
expect(@wav.duration).to eq(0.4)
|
104
104
|
end
|
105
|
-
|
105
|
+
|
106
106
|
it "should know the name of the file read from" do
|
107
107
|
expect(@wav.filename).to eq(File.basename(@filepath))
|
108
108
|
end
|
@@ -133,19 +133,19 @@ describe WaveInfo do
|
|
133
133
|
it "should get the byte rate right" do
|
134
134
|
expect(@wav.byte_rate).to eq(176400)
|
135
135
|
end
|
136
|
-
|
136
|
+
|
137
137
|
it "should get the block align value right" do
|
138
138
|
expect(@wav.block_align).to eq(4)
|
139
139
|
end
|
140
|
-
|
140
|
+
|
141
141
|
it "should get the bits per sample right" do
|
142
142
|
expect(@wav.bits_per_sample).to eq(16)
|
143
143
|
end
|
144
|
-
|
144
|
+
|
145
145
|
it "should get the audio length in bytes right" do
|
146
146
|
expect(@wav.size).to eq(100000)
|
147
147
|
end
|
148
|
-
|
148
|
+
|
149
149
|
it "should get the number of samples right" do
|
150
150
|
expect(@wav.samples).to eq(25000)
|
151
151
|
end
|
@@ -153,7 +153,7 @@ describe WaveInfo do
|
|
153
153
|
it "should get the audio duration right" do
|
154
154
|
expect((@wav.duration * 1000).to_i).to eq(566)
|
155
155
|
end
|
156
|
-
|
156
|
+
|
157
157
|
it "should know the name of the file read from" do
|
158
158
|
expect(@wav.filename).to eq(File.basename(@filepath))
|
159
159
|
end
|
@@ -184,19 +184,19 @@ describe WaveInfo do
|
|
184
184
|
it "should get the byte rate right" do
|
185
185
|
expect(@wav.byte_rate).to eq(5784)
|
186
186
|
end
|
187
|
-
|
187
|
+
|
188
188
|
it "should get the block align value right" do
|
189
189
|
expect(@wav.block_align).to eq(128)
|
190
190
|
end
|
191
|
-
|
191
|
+
|
192
192
|
it "should get the bits per sample right" do
|
193
193
|
expect(@wav.bits_per_sample).to eq(4)
|
194
194
|
end
|
195
|
-
|
195
|
+
|
196
196
|
it "should get the audio length in bytes right" do
|
197
197
|
expect(@wav.size).to eq(2432)
|
198
198
|
end
|
199
|
-
|
199
|
+
|
200
200
|
it "should get the number of samples right" do
|
201
201
|
expect(@wav.samples).to eq(4410)
|
202
202
|
end
|
@@ -204,7 +204,7 @@ describe WaveInfo do
|
|
204
204
|
it "should get the audio duration right" do
|
205
205
|
expect(@wav.duration).to eq(0.4)
|
206
206
|
end
|
207
|
-
|
207
|
+
|
208
208
|
it "should know the name of the file read from" do
|
209
209
|
expect(@wav.filename).to eq(File.basename(@filepath))
|
210
210
|
end
|
@@ -235,19 +235,19 @@ describe WaveInfo do
|
|
235
235
|
it "should get the byte rate right" do
|
236
236
|
expect(@wav.byte_rate).to eq(11025)
|
237
237
|
end
|
238
|
-
|
238
|
+
|
239
239
|
it "should get the block align value right" do
|
240
240
|
expect(@wav.block_align).to eq(1)
|
241
241
|
end
|
242
|
-
|
242
|
+
|
243
243
|
it "should get the bits per sample right" do
|
244
244
|
expect(@wav.bits_per_sample).to eq(8)
|
245
245
|
end
|
246
|
-
|
246
|
+
|
247
247
|
it "should get the audio length in bytes right" do
|
248
248
|
expect(@wav.size).to eq(4410)
|
249
249
|
end
|
250
|
-
|
250
|
+
|
251
251
|
it "should get the number of samples right" do
|
252
252
|
expect(@wav.samples).to eq(4410)
|
253
253
|
end
|
@@ -255,7 +255,7 @@ describe WaveInfo do
|
|
255
255
|
it "should get the audio duration right" do
|
256
256
|
expect(@wav.duration).to eq(0.4)
|
257
257
|
end
|
258
|
-
|
258
|
+
|
259
259
|
it "should know the name of the file read from" do
|
260
260
|
expect(@wav.filename).to eq(File.basename(@filepath))
|
261
261
|
end
|
@@ -286,19 +286,19 @@ describe WaveInfo do
|
|
286
286
|
it "should get the byte rate right" do
|
287
287
|
expect(@wav.byte_rate).to eq(11025)
|
288
288
|
end
|
289
|
-
|
289
|
+
|
290
290
|
it "should get the block align value right" do
|
291
291
|
expect(@wav.block_align).to eq(1)
|
292
292
|
end
|
293
|
-
|
293
|
+
|
294
294
|
it "should get the bits per sample right" do
|
295
295
|
expect(@wav.bits_per_sample).to eq(8)
|
296
296
|
end
|
297
|
-
|
297
|
+
|
298
298
|
it "should get the audio length in bytes right" do
|
299
299
|
expect(@wav.size).to eq(4410)
|
300
300
|
end
|
301
|
-
|
301
|
+
|
302
302
|
it "should get the number of samples right" do
|
303
303
|
expect(@wav.samples).to eq(4410)
|
304
304
|
end
|
@@ -306,7 +306,7 @@ describe WaveInfo do
|
|
306
306
|
it "should get the audio duration right" do
|
307
307
|
expect(@wav.duration).to eq(0.4)
|
308
308
|
end
|
309
|
-
|
309
|
+
|
310
310
|
it "should know the name of the file read from" do
|
311
311
|
expect(@wav.filename).to eq(File.basename(@filepath))
|
312
312
|
end
|
@@ -337,19 +337,19 @@ describe WaveInfo do
|
|
337
337
|
it "should get the byte rate right" do
|
338
338
|
expect(@wav.byte_rate).to eq(11025)
|
339
339
|
end
|
340
|
-
|
340
|
+
|
341
341
|
it "should get the block align value right" do
|
342
342
|
expect(@wav.block_align).to eq(1)
|
343
343
|
end
|
344
|
-
|
344
|
+
|
345
345
|
it "should get the bits per sample right" do
|
346
346
|
expect(@wav.bits_per_sample).to eq(8)
|
347
347
|
end
|
348
|
-
|
348
|
+
|
349
349
|
it "should get the audio length in bytes right" do
|
350
350
|
expect(@wav.size).to eq(4410)
|
351
351
|
end
|
352
|
-
|
352
|
+
|
353
353
|
it "should get the number of samples right" do
|
354
354
|
expect(@wav.samples).to eq(4410)
|
355
355
|
end
|
@@ -357,7 +357,7 @@ describe WaveInfo do
|
|
357
357
|
it "should get the audio duration right" do
|
358
358
|
expect(@wav.duration).to eq(0.4)
|
359
359
|
end
|
360
|
-
|
360
|
+
|
361
361
|
it "should know the name of the file read from" do
|
362
362
|
expect(@wav.filename).to eq(File.basename(@filepath))
|
363
363
|
end
|
@@ -388,18 +388,69 @@ describe WaveInfo do
|
|
388
388
|
it "should get the byte rate right" do
|
389
389
|
expect(@wav.byte_rate).to eq(5589)
|
390
390
|
end
|
391
|
-
|
391
|
+
|
392
392
|
it "should get the block align value right" do
|
393
393
|
expect(@wav.block_align).to eq(256)
|
394
394
|
end
|
395
|
-
|
395
|
+
|
396
396
|
it "should get the bits per sample right" do
|
397
397
|
expect(@wav.bits_per_sample).to eq(4)
|
398
398
|
end
|
399
|
-
|
399
|
+
|
400
400
|
it "should get the audio length in bytes right" do
|
401
401
|
expect(@wav.size).to eq(2304)
|
402
402
|
end
|
403
|
+
|
404
|
+
it "should get the number of samples right" do
|
405
|
+
expect(@wav.samples).to eq(4410)
|
406
|
+
end
|
407
|
+
|
408
|
+
it "should get the audio duration right" do
|
409
|
+
expect(@wav.duration).to eq(0.4)
|
410
|
+
end
|
411
|
+
|
412
|
+
it "should know the name of the file read from" do
|
413
|
+
expect(@wav.filename).to eq(File.basename(@filepath))
|
414
|
+
end
|
415
|
+
end
|
416
|
+
|
417
|
+
describe "parsing a Mono 11kHz PCM file in the RF64 format" do
|
418
|
+
before :each do
|
419
|
+
@filepath = sample_path('sine_11k_mono_16bit_pcm_rf64')
|
420
|
+
@wav = WaveInfo.new( @filepath )
|
421
|
+
end
|
422
|
+
|
423
|
+
it "should get the audio format id right" do
|
424
|
+
expect(@wav.audio_format_id).to eq(65534)
|
425
|
+
end
|
426
|
+
|
427
|
+
it "should get the audio format name right" do
|
428
|
+
expect(@wav.audio_format).to eq('Extensible wave format')
|
429
|
+
end
|
430
|
+
|
431
|
+
it "should get the number of channels right" do
|
432
|
+
expect(@wav.channels).to eq(1)
|
433
|
+
end
|
434
|
+
|
435
|
+
it "should get the sample rate right" do
|
436
|
+
expect(@wav.sample_rate).to eq(11025)
|
437
|
+
end
|
438
|
+
|
439
|
+
it "should get the byte rate right" do
|
440
|
+
expect(@wav.byte_rate).to eq(22050)
|
441
|
+
end
|
442
|
+
|
443
|
+
it "should get the block align value right" do
|
444
|
+
expect(@wav.block_align).to eq(2)
|
445
|
+
end
|
446
|
+
|
447
|
+
it "should get the bits per sample right" do
|
448
|
+
expect(@wav.bits_per_sample).to eq(16)
|
449
|
+
end
|
450
|
+
|
451
|
+
it "should get the audio length in bytes right" do
|
452
|
+
expect(@wav.size).to eq(8820)
|
453
|
+
end
|
403
454
|
|
404
455
|
it "should get the number of samples right" do
|
405
456
|
expect(@wav.samples).to eq(4410)
|
@@ -414,7 +465,7 @@ describe WaveInfo do
|
|
414
465
|
end
|
415
466
|
end
|
416
467
|
|
417
|
-
describe "parsing a Stereo 96kHz 24bit RF64" do
|
468
|
+
describe "parsing a truncated Stereo 96kHz 24bit RF64" do
|
418
469
|
before :each do
|
419
470
|
@filepath = sample_path('empty_96k_stereo_24bit_rf64')
|
420
471
|
@wav = WaveInfo.new( @filepath )
|
@@ -449,15 +500,15 @@ describe WaveInfo do
|
|
449
500
|
end
|
450
501
|
|
451
502
|
it "should get the audio length in bytes right" do
|
452
|
-
expect(@wav.size).to eq(
|
503
|
+
expect(@wav.size).to eq(4298665680)
|
453
504
|
end
|
454
505
|
|
455
506
|
it "should get the number of samples right" do
|
456
|
-
expect(@wav.samples).to eq(
|
507
|
+
expect(@wav.samples).to eq(716444280)
|
457
508
|
end
|
458
509
|
|
459
510
|
it "should get the audio duration right" do
|
460
|
-
expect(@wav.duration).to eq(
|
511
|
+
expect(@wav.duration).to eq(7462.96125)
|
461
512
|
end
|
462
513
|
|
463
514
|
it "should know the name of the file read from" do
|
@@ -480,31 +531,50 @@ describe WaveInfo do
|
|
480
531
|
data = StringIO.new("RIFF\4\0\0\0WAVE")
|
481
532
|
expect { WaveInfo.new( data ) }.not_to raise_error
|
482
533
|
end
|
483
|
-
|
534
|
+
|
484
535
|
it "should set the audio format name to Unknown for an unknown audio codec" do
|
485
536
|
data = StringIO.new("RIFF\x14\0\0\0WAVEfmt \x0a\0\0\0\xff\x00\x02\0\0\0\0\0\0\0\0\0\0\0\0\0")
|
486
537
|
expect(WaveInfo.new( data ).audio_format).to eq('Unknown (0xff)')
|
487
538
|
end
|
539
|
+
|
540
|
+
it "duration should be zero if WAVE file is valid but has no sub-chunks" do
|
541
|
+
data = StringIO.new("RIFF\4\0\0\0WAVE")
|
542
|
+
expect(WaveInfo.new( data ).duration).to eq(0)
|
543
|
+
end
|
544
|
+
|
545
|
+
it "samples should be zero if WAVE file is valid but has no sub-chunks" do
|
546
|
+
data = StringIO.new("RIFF\4\0\0\0WAVE")
|
547
|
+
expect(WaveInfo.new( data ).samples).to eq(0)
|
548
|
+
end
|
549
|
+
|
488
550
|
end
|
489
551
|
|
490
|
-
describe "
|
491
|
-
|
492
|
-
|
493
|
-
|
552
|
+
describe "WaveInfo.debug" do
|
553
|
+
before :each do
|
554
|
+
$realstderr = $stderr
|
555
|
+
$stderr = StringIO.new
|
556
|
+
@filepath = sample_path('unsupported_subchunk')
|
557
|
+
@wav = WaveInfo.new( @filepath )
|
558
|
+
end
|
559
|
+
|
560
|
+
after :each do
|
561
|
+
$stderr = $realstderr unless $realstderr.nil?
|
562
|
+
end
|
563
|
+
|
564
|
+
it "should default to outputting to stderr" do
|
565
|
+
expect($stderr).to receive(:puts).with("Warning: unsupported sub-chunk at 0x22a0: XYZZ")
|
494
566
|
@wav = WaveInfo.new( @filepath )
|
495
567
|
end
|
496
568
|
|
497
569
|
it "should output to stderr when true" do
|
498
570
|
WaveInfo.debug = true
|
499
|
-
expect($stderr).to receive(:puts).with("Warning: unsupported sub-chunk at
|
500
|
-
@filepath = sample_path('empty_96k_stereo_24bit_rf64')
|
571
|
+
expect($stderr).to receive(:puts).with("Warning: unsupported sub-chunk at 0x22a0: XYZZ")
|
501
572
|
@wav = WaveInfo.new( @filepath )
|
502
573
|
end
|
503
574
|
|
504
575
|
it "should not output to stderr when false" do
|
505
576
|
WaveInfo.debug = false
|
506
|
-
expect($stderr).to_not receive(:puts).with("Warning: unsupported sub-chunk at
|
507
|
-
@filepath = sample_path('empty_96k_stereo_24bit_rf64')
|
577
|
+
expect($stderr).to_not receive(:puts).with("Warning: unsupported sub-chunk at 0x22a0: XYZZ")
|
508
578
|
@wav = WaveInfo.new( @filepath )
|
509
579
|
end
|
510
580
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: waveinfo
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nicholas J Humfrey
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-04-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -16,73 +16,73 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 1.
|
19
|
+
version: '1.16'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 1.
|
26
|
+
version: '1.16'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
33
|
+
version: 10.2.2
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version:
|
40
|
+
version: 10.2.2
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: yard
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
45
|
- - ">="
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: 0.
|
47
|
+
version: 0.9.11
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: 0.
|
54
|
+
version: 0.9.11
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: rspec
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- - "
|
59
|
+
- - ">="
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: 3.
|
61
|
+
version: 3.5.0
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- - "
|
66
|
+
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: 3.
|
68
|
+
version: 3.5.0
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: simplecov
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
73
|
- - ">="
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version:
|
75
|
+
version: 0.9.2
|
76
76
|
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
80
|
- - ">="
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version:
|
82
|
+
version: 0.9.2
|
83
83
|
description: waveinfo is a pure-ruby gem to get the information from the headers of
|
84
84
|
Wave (.wav) files.
|
85
|
-
email:
|
85
|
+
email:
|
86
86
|
executables:
|
87
87
|
- waveinfo
|
88
88
|
extensions: []
|
@@ -114,10 +114,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
114
114
|
version: '0'
|
115
115
|
requirements: []
|
116
116
|
rubyforge_project: waveinfo
|
117
|
-
rubygems_version: 2.
|
117
|
+
rubygems_version: 2.6.14
|
118
118
|
signing_key:
|
119
119
|
specification_version: 4
|
120
120
|
summary: Pure-ruby gem to get the information from the headers of Wave (.wav) files.
|
121
121
|
test_files:
|
122
122
|
- spec/waveinfo_spec.rb
|
123
|
-
has_rdoc:
|