mp3file 1.1.2 → 1.1.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: da11954d17d2192242abc2017940101590ad797b
4
- data.tar.gz: 0018b0f2fabb9aa7582722aaf3c8a1985a004479
3
+ metadata.gz: 7cf86507fcd63fcb962fe2dda0dbd5d2a2ab7663
4
+ data.tar.gz: b5d0ae9444f9f4d5c010f443c1872ad50f3671c7
5
5
  SHA512:
6
- metadata.gz: a0e6fe9ae807f7981faf6332de40a7791666823bd9d55e94ebf2dbf89e16b3cb60dcefb46d603fe17b81fac974247887b379b4972ad8c76683f00c3c6a766246
7
- data.tar.gz: f9e290a4928af6d4de7c68e82aa16913513745cc11c4157549289b3534b9b89e5737447d267abee81aacdeb0d3883a27eb5c3ec166f458d2a1cc603f5392d8e1
6
+ metadata.gz: 7559f2f3edbc7d530eab3c92a604cfb74b079130e53c7d036568c63938325e0f8823c33d864ee746710441006edb1d625bb5051a7a3ea83443cb43e5ce048b4a
7
+ data.tar.gz: 75a97f77e322cac1de9159e4f2106dac88ee675f407816c62782d121bdc8bdd3e4e931a82d7741caecd3106994f1d0f8d2d1ea0a2c2872962b9fd2fbe242d9ef
@@ -198,23 +198,27 @@ module Mp3file
198
198
  if uniq_brs.size == 1
199
199
  @bitrate = uniq_brs.first / 1000
200
200
  end
201
+ @num_frames = frame_headers.size
201
202
  else
202
203
  # Use the Xing header to make the VBR / CBR call. Assume that
203
204
  # Xing headers, when present in a CBR file, are called "Info".
204
205
  @vbr = @xing_header.nil? || @xing_header.name == "Xing"
205
206
  end
206
207
 
207
- if @xing_header && @xing_header.frames && @xing_header.bytes
208
- # Use the Xing header to calculate the duration (and overall bitrate).
209
- @num_frames = @xing_header.frames
210
- @total_samples = @xing_header.frames * @first_header.samples
211
- @length = total_samples.to_f / @samplerate.to_f
212
- @bitrate = ((@xing_header.bytes.to_f / @length.to_f) * 8 / 1000)
213
- else
214
- # Do the CBR length calculation.
215
- @num_frames = @audio_size / @first_header.frame_size
216
- @total_samples = @num_frames * @first_header.samples
217
- @length = @total_samples.to_f / @samplerate.to_f
208
+ # Find the number of frames. Prefer the actual frame count we
209
+ # did (if we scanned all the frames) over the Xing
210
+ # header. Prefer the Xing header over file size math.
211
+ @num_frames = @num_frames || (@xing_header && @xing_header.frames) || (@audio_size / @first_header.frame_size)
212
+
213
+ # Figure out the total samples and the time duration.
214
+ @total_samples = @num_frames * @first_header.samples
215
+ @length = @total_samples.to_f / @samplerate.to_f
216
+
217
+ # If the file looks like it's a VBR file, do an averate bitrate
218
+ # calculation, either using the Xing header's idea of the file
219
+ # size or the one we found.
220
+ if @vbr
221
+ @bitrate = (@xing_header.bytes || @audio_size) / @length.to_f * 8 / 1000
218
222
  end
219
223
 
220
224
  @file.close
@@ -1,3 +1,3 @@
1
1
  module Mp3file
2
- VERSION = "1.1.2"
2
+ VERSION = "1.1.3"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mp3file
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.2
4
+ version: 1.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Watts
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-03-18 00:00:00.000000000 Z
11
+ date: 2016-05-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec