celt-ruby 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +17 -0
- data/.rvmrc +1 -0
- data/Gemfile +4 -0
- data/README.rdoc +45 -0
- data/Rakefile +2 -0
- data/celt-ruby.gemspec +19 -0
- data/lib/celt-ruby.rb +47 -0
- data/lib/celt-ruby/encoder.rb +48 -0
- data/lib/celt-ruby/version.rb +3 -0
- metadata +66 -0
data/.gitignore
ADDED
data/.rvmrc
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
rvm use --create ruby-1.9.3-p0@celt_ruby_gem
|
data/Gemfile
ADDED
data/README.rdoc
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
celt-ruby
|
2
|
+
http://www.github.com/perrym5/celt-ruby
|
3
|
+
|
4
|
+
== DESCRIPTION:
|
5
|
+
|
6
|
+
CELT-Ruby is a Ruby Gem for working with the CELT Audio Codec.
|
7
|
+
CELT-Ruby uses the Ruby-FFI extension to wrap the native CELT library code.
|
8
|
+
This means that you must have CELT installed in order for this gem to work.
|
9
|
+
|
10
|
+
== FEATURES:
|
11
|
+
|
12
|
+
This gem was designed to fill a specific role in another one of my projects.
|
13
|
+
As a result, the feature set is relatively small compared to the native libraries.
|
14
|
+
However, I will accept any pull requests with additional functionality should someone need it.
|
15
|
+
|
16
|
+
What this library can do:
|
17
|
+
* Encode raw audio to CELT
|
18
|
+
|
19
|
+
== REQUIREMENTS:
|
20
|
+
|
21
|
+
* Ruby >= 1.9.2
|
22
|
+
* CELT 0.7 Library
|
23
|
+
|
24
|
+
== INSTALL:
|
25
|
+
|
26
|
+
[sudo] gem install celt-ruby
|
27
|
+
|
28
|
+
== USAGE:
|
29
|
+
|
30
|
+
# Create new encoder with a sample rate of 48 kHz, a frame size of 480 bytes and 1 channel
|
31
|
+
encoder = Celt::Encoder.new 48000, 480, 1
|
32
|
+
# Set the prediction request to 0
|
33
|
+
encoder.prediction_request = 0
|
34
|
+
# Set the VBR rate to 60,000
|
35
|
+
encoder.vbr_rate = 60000
|
36
|
+
|
37
|
+
# Return the bitstream version for this version of CELT
|
38
|
+
encoder.bitstream_version
|
39
|
+
|
40
|
+
# Encode some raw audio
|
41
|
+
compressed_size = [@encoder.vbr_rate / 800, 127].min
|
42
|
+
encoded = encoder.encode(raw_audio, compressed_size)
|
43
|
+
|
44
|
+
# Safely destroy encoder
|
45
|
+
encoder.destroy
|
data/Rakefile
ADDED
data/celt-ruby.gemspec
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/celt-ruby/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["Matthew Perry"]
|
6
|
+
gem.email = ["perrym5@rpi.edu"]
|
7
|
+
gem.description = %q{Ruby FFI Gem for the CELT Audio Codec}
|
8
|
+
gem.summary = %q{Ruby FFI wrapper for the CELT Audio Codec C library for low latency audio encoding}
|
9
|
+
gem.homepage = ""
|
10
|
+
|
11
|
+
gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
12
|
+
gem.files = `git ls-files`.split("\n")
|
13
|
+
gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
14
|
+
gem.name = "celt-ruby"
|
15
|
+
gem.require_paths = ["lib"]
|
16
|
+
gem.version = Celt::VERSION
|
17
|
+
|
18
|
+
gem.add_dependency "ffi"
|
19
|
+
end
|
data/lib/celt-ruby.rb
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'ffi'
|
2
|
+
require 'celt-ruby/version'
|
3
|
+
require 'celt-ruby/encoder'
|
4
|
+
|
5
|
+
module Celt
|
6
|
+
extend FFI::Library
|
7
|
+
|
8
|
+
ffi_lib 'celt0'
|
9
|
+
|
10
|
+
module Constants
|
11
|
+
CELT_OK = 0
|
12
|
+
CELT_BAD_ARG = -1
|
13
|
+
CELT_INVALID_MODE = -2
|
14
|
+
CELT_INTERNAL_ERROR = -3
|
15
|
+
CELT_CORRUPTED_DATA = -4
|
16
|
+
CELT_UNIMPLEMENTED = -5
|
17
|
+
CELT_INVALID_STATE = -6
|
18
|
+
CELT_ALLOC_FAIL = -7
|
19
|
+
CELT_GET_MODE_REQUEST = 1
|
20
|
+
CELT_SET_COMPLEXITY_REQUEST = 2
|
21
|
+
CELT_SET_PREDICTION_REQUEST = 4
|
22
|
+
CELT_SET_VBR_RATE_REQUEST = 6
|
23
|
+
CELT_RESET_STATE_REQUEST = 8
|
24
|
+
CELT_GET_FRAME_SIZE = 1000
|
25
|
+
CELT_GET_LOOKAHEAD = 1001
|
26
|
+
CELT_GET_SAMPLE_RATE = 1003
|
27
|
+
CELT_GET_BITSTREAM_VERSION = 2000
|
28
|
+
end
|
29
|
+
|
30
|
+
attach_function :celt_mode_create, [:int32, :int, :pointer], :pointer
|
31
|
+
attach_function :celt_mode_destroy, [:pointer], :void
|
32
|
+
attach_function :celt_mode_info, [:pointer, :int, :pointer], :int
|
33
|
+
|
34
|
+
attach_function :celt_encoder_create, [:pointer, :int, :pointer], :pointer
|
35
|
+
attach_function :celt_encoder_destroy, [:pointer], :void
|
36
|
+
attach_function :celt_encode_float, [:pointer, :pointer, :pointer, :pointer, :int], :int
|
37
|
+
attach_function :celt_encode, [:pointer, :pointer, :pointer, :pointer, :int], :int
|
38
|
+
attach_function :celt_encoder_ctl, [:pointer, :int, :varargs], :int
|
39
|
+
|
40
|
+
attach_function :celt_decoder_create, [:pointer, :int, :pointer], :pointer
|
41
|
+
attach_function :celt_decoder_destroy, [:pointer], :void
|
42
|
+
attach_function :celt_decode_float, [:pointer, :pointer, :int, :pointer], :int
|
43
|
+
attach_function :celt_decode, [:pointer, :pointer, :int, :pointer], :int
|
44
|
+
attach_function :celt_decoder_ctl, [:pointer, :int, :varargs], :int
|
45
|
+
|
46
|
+
attach_function :celt_strerror, [:int], :pointer
|
47
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
module Celt
|
2
|
+
class Encoder
|
3
|
+
attr_reader :sample_rate, :frame_size, :channels,
|
4
|
+
:prediction_request, :vbr_rate
|
5
|
+
|
6
|
+
def initialize(sample_rate, frame_size, channels)
|
7
|
+
@sample_rate = sample_rate
|
8
|
+
@frame_size = frame_size
|
9
|
+
@channels = channels
|
10
|
+
|
11
|
+
@mode = Celt.celt_mode_create sample_rate, frame_size, nil
|
12
|
+
@encoder = Celt.celt_encoder_create @mode, channels, nil
|
13
|
+
end
|
14
|
+
|
15
|
+
def destroy
|
16
|
+
Celt.celt_encoder_destroy @encoder
|
17
|
+
Celt.celt_mode_destroy @mode
|
18
|
+
end
|
19
|
+
|
20
|
+
def bitstream_version
|
21
|
+
bv = FFI::MemoryPointer.new :int32
|
22
|
+
Celt.celt_mode_info @mode, Celt::Constants::CELT_GET_BITSTREAM_VERSION, bv
|
23
|
+
bv.read_int32
|
24
|
+
end
|
25
|
+
|
26
|
+
def prediction_request=(value)
|
27
|
+
@prediction_request = value
|
28
|
+
v_ptr = FFI::MemoryPointer.new :int
|
29
|
+
v_ptr.put_int 0, value
|
30
|
+
Celt.celt_encoder_ctl @encoder, Celt::Constants::CELT_SET_PREDICTION_REQUEST, :pointer, v_ptr
|
31
|
+
end
|
32
|
+
|
33
|
+
def vbr_rate=(value)
|
34
|
+
@vbr_rate = value
|
35
|
+
v_ptr = FFI::MemoryPointer.new :int
|
36
|
+
v_ptr.put_int 0, value
|
37
|
+
Celt.celt_encoder_ctl @encoder, Celt::Constants::CELT_SET_VBR_RATE_REQUEST, :pointer, v_ptr
|
38
|
+
end
|
39
|
+
|
40
|
+
def encode(data, size)
|
41
|
+
out = FFI::MemoryPointer.new :char, data.size + 1
|
42
|
+
buf = FFI::MemoryPointer.new :char, data.size + 1
|
43
|
+
buf.put_string 0, data
|
44
|
+
len = Celt.celt_encode @encoder, buf, nil, out, size
|
45
|
+
out.read_string_length len
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
metadata
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: celt-ruby
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Matthew Perry
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-04-26 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: ffi
|
16
|
+
requirement: &15396360 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *15396360
|
25
|
+
description: Ruby FFI Gem for the CELT Audio Codec
|
26
|
+
email:
|
27
|
+
- perrym5@rpi.edu
|
28
|
+
executables: []
|
29
|
+
extensions: []
|
30
|
+
extra_rdoc_files: []
|
31
|
+
files:
|
32
|
+
- .gitignore
|
33
|
+
- .rvmrc
|
34
|
+
- Gemfile
|
35
|
+
- README.rdoc
|
36
|
+
- Rakefile
|
37
|
+
- celt-ruby.gemspec
|
38
|
+
- lib/celt-ruby.rb
|
39
|
+
- lib/celt-ruby/encoder.rb
|
40
|
+
- lib/celt-ruby/version.rb
|
41
|
+
homepage: ''
|
42
|
+
licenses: []
|
43
|
+
post_install_message:
|
44
|
+
rdoc_options: []
|
45
|
+
require_paths:
|
46
|
+
- lib
|
47
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
48
|
+
none: false
|
49
|
+
requirements:
|
50
|
+
- - ! '>='
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: '0'
|
53
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
54
|
+
none: false
|
55
|
+
requirements:
|
56
|
+
- - ! '>='
|
57
|
+
- !ruby/object:Gem::Version
|
58
|
+
version: '0'
|
59
|
+
requirements: []
|
60
|
+
rubyforge_project:
|
61
|
+
rubygems_version: 1.8.10
|
62
|
+
signing_key:
|
63
|
+
specification_version: 3
|
64
|
+
summary: Ruby FFI wrapper for the CELT Audio Codec C library for low latency audio
|
65
|
+
encoding
|
66
|
+
test_files: []
|