Class: Ogg::Codecs::Vorbis
- Inherits:
-
Object
- Object
- Ogg::Codecs::Vorbis
- Extended by:
- VorbisComments
- Defined in:
- lib/ogg/codecs/vorbis.rb
Class Method Summary collapse
-
.decode_headers(reader) ⇒ Object
consume header and tag pages, return array of two hashes, info and tags.
- .extract_info(packet) ⇒ Object
-
.match?(header_packet) ⇒ Boolean
return true/false based on whether the header packet belongs to us.
-
.replace_tags(reader, writer, new_tags, vendor) ⇒ Object
consume pages with old tags/setup packets and rewrite newtags,setup packets return the number of pages written.
Methods included from VorbisComments
binary_size, pack_comments, unpack_comments
Class Method Details
.decode_headers(reader) ⇒ Object
consume header and tag pages, return array of two hashes, info and tags
11 12 13 14 15 16 |
# File 'lib/ogg/codecs/vorbis.rb', line 11 def decode_headers(reader) init_pkt, tag_pkt, _ = reader.read_packets(3) # init_pkt, tag_pkt, setup_pkt info = extract_info(init_pkt) info[:tag], info[:tag_vendor] = unpack_comments(tag_pkt, "\003vorbis") info end |
.extract_info(packet) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/ogg/codecs/vorbis.rb', line 25 def extract_info(packet) _, #vorbis_string, _, # vorbis_version, channels, samplerate, upper_bitrate, nominal_bitrate, lower_bitrate = packet.unpack("a7VCV4") if nominal_bitrate == 0 if (upper_bitrate == 2**32 - 1) || (lower_bitrate == 2**32 - 1) nominal_bitrate = 0 else nominal_bitrate = ( upper_bitrate + lower_bitrate) / 2 end end return { :channels => channels, :samplerate => samplerate, :nominal_bitrate => nominal_bitrate } end |
.match?(header_packet) ⇒ Boolean
return true/false based on whether the header packet belongs to us
6 7 8 |
# File 'lib/ogg/codecs/vorbis.rb', line 6 def match?(header_packet) header_packet.start_with?("\001vorbis") end |
.replace_tags(reader, writer, new_tags, vendor) ⇒ Object
consume pages with old tags/setup packets and rewrite newtags,setup packets return the number of pages written
20 21 22 23 |
# File 'lib/ogg/codecs/vorbis.rb', line 20 def (reader, writer, , vendor) _, setup_pkt = reader.read_packets(2) # tag_pkt, setup_pkt writer.write_packets(0, pack_comments(, vendor, "\003vorbis"), setup_pkt) end |