class Opus::Encoder

Attributes

bitrate[R]
channels[R]
frame_size[R]
sample_rate[R]
vbr_rate[R]

Public Class Methods

new(sample_rate, frame_size, channels) click to toggle source
# File lib/opus-ruby/encoder.rb, line 6
def initialize(sample_rate, frame_size, channels)
  @sample_rate = sample_rate
  @frame_size = frame_size
  @channels = channels

  @encoder = Opus.opus_encoder_create sample_rate, channels, Constants::OPUS_APPLICATION_AUDIO, nil
end

Public Instance Methods

bitrate=(value) click to toggle source
# File lib/opus-ruby/encoder.rb, line 27
def bitrate=(value)
  @bitrate = value
  Opus.opus_encoder_ctl @encoder, Opus::Constants::OPUS_SET_BITRATE_REQUEST, :int32, value
end
destroy() click to toggle source
# File lib/opus-ruby/encoder.rb, line 14
def destroy
  Opus.opus_encoder_destroy @encoder
end
encode(data, size) click to toggle source
# File lib/opus-ruby/encoder.rb, line 32
def encode(data, size)
  out = FFI::MemoryPointer.new :char, data.size + 1
  buf = FFI::MemoryPointer.new :char, data.size + 1
  buf.put_string 0, data
  len = Opus.opus_encode @encoder, buf, @frame_size, out, size
  out.read_string_length len
end
reset() click to toggle source
# File lib/opus-ruby/encoder.rb, line 18
def reset
  Opus.opus_encoder_ctl @encoder, Opus::Constants::OPUS_RESET_STATE, :pointer, nil
end
vbr_rate=(value) click to toggle source
# File lib/opus-ruby/encoder.rb, line 22
def vbr_rate=(value)
  @vbr_rate = value
  Opus.opus_encoder_ctl @encoder, Opus::Constants::OPUS_SET_VBR_REQUEST, :int32, value
end