class Opus::Decoder
Attributes
channels[R]
frame_size[R]
sample_rate[R]
Public Class Methods
new( sample_rate, frame_size, channels )
click to toggle source
# File lib/opus-ruby/decoder.rb, line 33 def initialize( sample_rate, frame_size, channels ) @sample_rate = sample_rate @frame_size = frame_size @channels = channels @decoder = Opus.opus_decoder_create sample_rate, channels, nil end
Public Instance Methods
decode( data )
click to toggle source
# File lib/opus-ruby/decoder.rb, line 49 def decode( data ) len = data.size packet = FFI::MemoryPointer.new :char, len + 1 packet.put_string 0, data max_size = @frame_size * @channels * 2 # Was getting buffer_too_small errors without the 2 decoded = FFI::MemoryPointer.new :short, max_size + 1 frame_size = Opus.opus_decode @decoder, packet, len, decoded, max_size, 0 # The times 2 is very important and caused much grief prior to an IRC # chat with the Opus devs. Just remember a short is 2 bytes... Seems so # simple now... return decoded.read_string_length frame_size * 2 end
destroy()
click to toggle source
# File lib/opus-ruby/decoder.rb, line 41 def destroy Opus.opus_decoder_destroy @decoder end
reset()
click to toggle source
# File lib/opus-ruby/decoder.rb, line 45 def reset Opus.opus_decoder_ctl @decoder, Opus::Constants::OPUS_RESET_STATE, :pointer, nil end