class Discord::DCAParser

Overview

Parser for the DCA file format, a simple wrapper around Opus made specifically for Discord bots.

Defined in:

discordcr/dca.cr

Constant Summary

DCA1_MAGIC = "DCA1"

Magic string that identifies a DCA1 file

Constructors

Instance Method Summary

Constructor Detail

def self.new(io : IO, raw = false, strict_metadata : Bool = true) #

Create a new parser. It will read from the given io. If raw is set, the file is assumed to be a DCA0 file, without any metadata. If the file's metadata doesn't conform to the DCA1 specification and strict_metadata is set, then the parsing will fail with an error; if it is not set then the metadata will silently be nil.


[View source]

Instance Method Detail

def metadata : DCA1Mappings::Metadata | Nil #

The parsed metadata, or nil if it could not be parsed.


[View source]
def next_frame(reuse_buffer = false) : Bytes | Nil #

Reads the next frame from the IO. If there is nothing left to read, it will return nil.

If reuse_buffer is true, a large buffer will be allocated once and reused for future calls of this method, reducing the load on the GC and potentially reusing memory use overall; if it is false, a new buffer of just the correct size will be allocated every time. Note that if the buffer is reused, the returned data is only valid until the next call to #next_frame.


[View source]
def parse(&block : Bytes -> ) #

Continually reads frames from the IO until there are none left. Each frame is passed to the given block.


[View source]