Class: Opus::Encoder

Inherits:
Object
  • Object
show all
Defined in:
lib/opus-ruby/encoder.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(sample_rate, frame_size, channels) ⇒ Encoder

Returns a new instance of Encoder.



6
7
8
9
10
11
12
# 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

Instance Attribute Details

#bitrateObject

Returns the value of attribute bitrate.



3
4
5
# File 'lib/opus-ruby/encoder.rb', line 3

def bitrate
  @bitrate
end

#channelsObject (readonly)

Returns the value of attribute channels.



3
4
5
# File 'lib/opus-ruby/encoder.rb', line 3

def channels
  @channels
end

#frame_sizeObject (readonly)

Returns the value of attribute frame_size.



3
4
5
# File 'lib/opus-ruby/encoder.rb', line 3

def frame_size
  @frame_size
end

#sample_rateObject (readonly)

Returns the value of attribute sample_rate.



3
4
5
# File 'lib/opus-ruby/encoder.rb', line 3

def sample_rate
  @sample_rate
end

#vbr_rateObject

Returns the value of attribute vbr_rate.



3
4
5
# File 'lib/opus-ruby/encoder.rb', line 3

def vbr_rate
  @vbr_rate
end

Instance Method Details

#destroyObject



14
15
16
# File 'lib/opus-ruby/encoder.rb', line 14

def destroy
  Opus.opus_encoder_destroy @encoder
end

#encode(data, size) ⇒ Object



32
33
34
35
36
37
38
# 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

#resetObject



18
19
20
# File 'lib/opus-ruby/encoder.rb', line 18

def reset
  Opus.opus_encoder_ctl @encoder, Opus::Constants::OPUS_RESET_STATE, :pointer, nil
end