class Ogg::Codecs::Opus

Public Class Methods

decode_headers(reader) click to toggle source

consume header and tag pages, return array of two hashes, info and tags

# File lib/ogg/codecs/opus.rb, line 11
def decode_headers(reader)
  init_pkt, tag_pkt = reader.read_packets(2) # init_pkt, tag_pkt
  info = extract_info(init_pkt)
  info[:tag], info[:tag_vendor] = unpack_comments(tag_pkt, "OpusTags")
  info
end
extract_info(packet) click to toggle source
# File lib/ogg/codecs/opus.rb, line 25
def extract_info(packet)
  _, # opus magic signature
  _, # opus_version,
  channels,
  _, # pre skip
  _, # samplerate,
  _, # output gain
  _ = packet.unpack("a8CCvVvC") # channel map
  
  return { :channels => channels, :samplerate => 48000 }
end
match?(header_packet) click to toggle source

return true/false based on whether the header packet belongs to us

# File lib/ogg/codecs/opus.rb, line 6
def match?(header_packet)
  header_packet.start_with?("OpusHead")
end
replace_tags(reader, writer, new_tags, vendor) click to toggle source

consume pages with old tags/setup packets and rewrite newtags,setup packets return the number of pages written

# File lib/ogg/codecs/opus.rb, line 20
def replace_tags(reader, writer, new_tags, vendor)
  _ = reader.read_packets(1) # tag_packet
  writer.write_packets(0, pack_comments(new_tags, vendor, "OpusTags"))
end