lib/mp3file/mp3_file.rb in mp3file-1.0.2 vs lib/mp3file/mp3_file.rb in mp3file-1.0.3
- old
+ new
@@ -54,10 +54,26 @@
def genre
value_from_tags(:genre)
end
+ def each_header
+ file = File.open(@file.path, "rb")
+ offset = @first_header_offset
+
+ file.seek(offset, IO::SEEK_SET)
+ while !file.eof?
+ header = MP3Header.new(file)
+ yield offset, header
+
+ offset = offset + header.frame_size
+ file.seek(offset, IO::SEEK_SET)
+ end
+
+ file.close
+ end
+
private
def value_from_tags(v1_field)
if @id3v1_tag
@id3v1_tag.send(v1_field)
@@ -153,10 +169,10 @@
# Do the VBR length calculation. What to do if we don't have
# both of these pieces of information?
if @xing_header.frames && @xing_header.bytes
@num_frames = @xing_header.frames
@total_samples = @xing_header.frames * @first_header.samples
- @length = total_samples / @samplerate
+ @length = total_samples.to_f / @samplerate.to_f
@bitrate = ((@xing_header.bytes.to_f / @length.to_f) * 8 / 1000).to_i
end
else
# Do the CBR length calculation.
@vbr = false