lib/mp3file/mp3_file.rb in mp3file-1.1.4 vs lib/mp3file/mp3_file.rb in mp3file-1.1.5

- old
+ new

@@ -198,19 +198,27 @@ if uniq_brs.size == 1 @bitrate = uniq_brs.first / 1000 end @num_frames = frame_headers.size else - # Use the Xing header to make the VBR / CBR call. Assume that - # Xing headers, when present in a CBR file, are called "Info". - @vbr = @xing_header.nil? || @xing_header.name == "Xing" + # Use the presence and name of the Xing header to make the VBR + # / CBR call. Assume that Xing headers, when present in a CBR + # file, are called "Info". + @vbr = !@xing_header.nil? && @xing_header.name == "Xing" end + # puts "@num_frames = #{@num_frames.inspect}" + # puts "@xing_header = #{@xing_header.inspect}" + # puts "@audio_size = #{@audio_size.inspect}" + # puts "@first_header size = #{@first_header.frame_size.inspect}" + # Find the number of frames. Prefer the actual frame count we # did (if we scanned all the frames) over the Xing # header. Prefer the Xing header over file size math. - @num_frames = @num_frames || (@xing_header && @xing_header.frames) || (@audio_size / @first_header.frame_size) + @num_frames = @num_frames || + (@xing_header && (@xing_header.frames + 1)) || + (@audio_size / @first_header.frame_size) # Figure out the total samples and the time duration. @total_samples = @num_frames * @first_header.samples @length = @total_samples.to_f / @samplerate.to_f @@ -218,9 +226,12 @@ # calculation, either using the Xing header's idea of the file # size or the one we found. if @vbr @bitrate = ((@xing_header && @xing_header.bytes) || @audio_size) / @length.to_f * 8 / 1000 end + + # puts "@vbr = #{@vbr.inspect}" + # puts "@bitrate = #{@bitrate.inspect}" @file.close end def get_next_header(file, offset = nil)