Class: Opus::Encoder
- Inherits:
-
Object
- Object
- Opus::Encoder
- Defined in:
- lib/opus-ruby/encoder.rb
Instance Attribute Summary collapse
-
#bitrate ⇒ Object
Returns the value of attribute bitrate.
-
#channels ⇒ Object
readonly
Returns the value of attribute channels.
-
#frame_size ⇒ Object
readonly
Returns the value of attribute frame_size.
-
#sample_rate ⇒ Object
readonly
Returns the value of attribute sample_rate.
-
#vbr_rate ⇒ Object
Returns the value of attribute vbr_rate.
Instance Method Summary collapse
- #destroy ⇒ Object
- #encode(data, size) ⇒ Object
-
#initialize(sample_rate, frame_size, channels) ⇒ Encoder
constructor
A new instance of Encoder.
- #reset ⇒ Object
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
#bitrate ⇒ Object
Returns the value of attribute bitrate.
3 4 5 |
# File 'lib/opus-ruby/encoder.rb', line 3 def bitrate @bitrate end |
#channels ⇒ Object (readonly)
Returns the value of attribute channels.
3 4 5 |
# File 'lib/opus-ruby/encoder.rb', line 3 def channels @channels end |
#frame_size ⇒ Object (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_rate ⇒ Object (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_rate ⇒ Object
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
#destroy ⇒ Object
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 |
#reset ⇒ Object
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 |