Class: Opus::Decoder
- Inherits:
-
Object
- Object
- Opus::Decoder
- Defined in:
- lib/opus-ruby/decoder.rb
Instance Attribute Summary collapse
-
#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.
Instance Method Summary collapse
- #decode(data) ⇒ Object
- #destroy ⇒ Object
-
#initialize(sample_rate, frame_size, channels) ⇒ Decoder
constructor
A new instance of Decoder.
- #reset ⇒ Object
Constructor Details
#initialize(sample_rate, frame_size, channels) ⇒ Decoder
Returns a new instance of Decoder.
33 34 35 36 37 38 39 |
# 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 |
Instance Attribute Details
#channels ⇒ Object (readonly)
Returns the value of attribute channels.
31 32 33 |
# File 'lib/opus-ruby/decoder.rb', line 31 def channels @channels end |
#frame_size ⇒ Object (readonly)
Returns the value of attribute frame_size.
31 32 33 |
# File 'lib/opus-ruby/decoder.rb', line 31 def frame_size @frame_size end |
#sample_rate ⇒ Object (readonly)
Returns the value of attribute sample_rate.
31 32 33 |
# File 'lib/opus-ruby/decoder.rb', line 31 def sample_rate @sample_rate end |
Instance Method Details
#decode(data) ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# 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 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 ⇒ Object
41 42 43 |
# File 'lib/opus-ruby/decoder.rb', line 41 def destroy Opus.opus_decoder_destroy @decoder end |
#reset ⇒ Object
45 46 47 |
# File 'lib/opus-ruby/decoder.rb', line 45 def reset Opus.opus_decoder_ctl @decoder, Opus::Constants::OPUS_RESET_STATE, :pointer, nil end |