Class: Celt::Encoder

Inherits:
Object
  • Object
show all
Defined in:
lib/celt-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
13
# File 'lib/celt-ruby/encoder.rb', line 6

def initialize(sample_rate, frame_size, channels)
  @sample_rate = sample_rate
  @frame_size = frame_size
  @channels = channels

  @mode = Celt.celt_mode_create sample_rate, frame_size, nil
  @encoder = Celt.celt_encoder_create @mode, channels, nil
end

Instance Attribute Details

#channelsObject (readonly)

Returns the value of attribute channels.



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

def channels
  @channels
end

#frame_sizeObject (readonly)

Returns the value of attribute frame_size.



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

def frame_size
  @frame_size
end

#prediction_requestObject

Returns the value of attribute prediction_request.



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

def prediction_request
  @prediction_request
end

#sample_rateObject (readonly)

Returns the value of attribute sample_rate.



3
4
5
# File 'lib/celt-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/celt-ruby/encoder.rb', line 3

def vbr_rate
  @vbr_rate
end

Instance Method Details

#bitstream_versionObject



20
21
22
23
24
# File 'lib/celt-ruby/encoder.rb', line 20

def bitstream_version
  bv = FFI::MemoryPointer.new :int32
  Celt.celt_mode_info @mode, Celt::Constants::CELT_GET_BITSTREAM_VERSION, bv
  bv.read_int32
end

#destroyObject



15
16
17
18
# File 'lib/celt-ruby/encoder.rb', line 15

def destroy
  Celt.celt_encoder_destroy @encoder
  Celt.celt_mode_destroy @mode
end

#encode(data, size) ⇒ Object



40
41
42
43
44
45
46
# File 'lib/celt-ruby/encoder.rb', line 40

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 = Celt.celt_encode @encoder, buf, nil, out, size
  out.read_string_length len
end