opus-ruby 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: fca9e603f46d71ec76f1754d72e57f4330d6b891
4
+ data.tar.gz: 777e900ed821b7e9df95e1b80d69c6f0fe22bcd9
5
+ SHA512:
6
+ metadata.gz: 5513a93a70ff8b21125dd6c318409ec48f3fb15cc56d5e3a6f6bdcb237cfcb708eb33797f07c7a632f799f03a8943bda698f7854ba7c2192f2712b625fb28707
7
+ data.tar.gz: 3a55dce53e1c7eb09832a9dd4479f137bea576fcef35956768babf2f24ccb2e10c814207e33f21c0bfc0a752ac7e70d0b5f3e9664c43da2c7ac7cd0b452daa1d
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.ruby-gemset ADDED
@@ -0,0 +1 @@
1
+ opus_ruby_gem
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ ruby-2.1.0
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in opus-ruby.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Matthew Perry
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,42 @@
1
+ # opus-ruby
2
+
3
+ OPUS-Ruby is a Ruby Gem for working with the OPUS Audio Codec.
4
+ OPUS-Ruby uses the Ruby-FFI extension to wrap the native OPUS library code.
5
+ This means that you must have OPUS installed in order for this gem to work.
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ gem 'opus-ruby'
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install opus-ruby
20
+
21
+ ## Usage
22
+
23
+ # Create new encoder with a sample rate of 48 kHz, a frame size of 480 bytes and 1 channel
24
+ encoder = Opus::Encoder.new 48000, 480, 1
25
+ # Set the bitrate to 32 kbit/s
26
+ encoder.bitrate = 32000
27
+ # Set the VBR rate to 0 (CBR)
28
+ encoder.vbr_rate = 0
29
+
30
+ # Encode some raw audio
31
+ encoded = encoder.encode(raw_audio, 960)
32
+
33
+ # Safely destroy encoder
34
+ encoder.destroy
35
+
36
+ ## Contributing
37
+
38
+ 1. Fork it
39
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
40
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
41
+ 4. Push to the branch (`git push origin my-new-feature`)
42
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/lib/opus-ruby.rb ADDED
@@ -0,0 +1,44 @@
1
+ require 'ffi'
2
+ require 'opus-ruby/version'
3
+ require 'opus-ruby/encoder'
4
+
5
+ module Opus
6
+ extend FFI::Library
7
+
8
+ ffi_lib 'opus'
9
+
10
+ module Constants
11
+ OPUS_OK = 0
12
+ OPUS_BAD_ARG = -1
13
+ OPUS_BUFFER_TOO_SMALL = -2
14
+ OPUS_INTERNAL_ERROR = -3
15
+ OPUS_INVALID_PACKET = -4
16
+ OPUS_UNIMPLEMENTED = -5
17
+ OPUS_INVALID_STATE = -6
18
+ OPUS_ALLOC_FAIL = -7
19
+ OPUS_APPLICATION_VOIP = 2048
20
+ OPUS_APPLICATION_AUDIO = 2049
21
+ OPUS_APPLICATION_RESTRICTED_LOWDELAY = 2051
22
+ OPUS_SIGNAL_VOICE = 3001
23
+ OPUS_SIGNAL_MUSIC = 3002
24
+ OPUS_SET_BITRATE_REQUEST = 4002
25
+ OPUS_SET_VBR_REQUEST = 4006
26
+ OPUS_RESET_STATE = 4028
27
+ end
28
+
29
+ attach_function :opus_encoder_get_size, [:int], :int
30
+ attach_function :opus_encoder_create, [:int32, :int, :int, :pointer], :pointer
31
+ attach_function :opus_encoder_init, [:pointer, :int32, :int, :int], :int
32
+ attach_function :opus_encode, [:pointer, :pointer, :int, :pointer, :int32], :int32
33
+ attach_function :opus_encode_float, [:pointer, :pointer, :int, :pointer, :int32], :int32
34
+ attach_function :opus_encoder_destroy, [:pointer], :void
35
+ attach_function :opus_encoder_ctl, [:pointer, :int, :varargs], :int
36
+
37
+ attach_function :opus_decoder_get_size, [:int], :int
38
+ attach_function :opus_decoder_create, [:int32, :int, :pointer], :pointer
39
+ attach_function :opus_decoder_init, [:pointer, :int32, :int], :int
40
+ attach_function :opus_decode, [:pointer, :pointer, :int32, :pointer, :int, :int], :int
41
+ attach_function :opus_decode_float, [:pointer, :pointer, :int32, :pointer, :int, :int], :int
42
+ attach_function :opus_decoder_ctl, [:pointer, :int, :varargs], :int
43
+ attach_function :opus_decoder_destroy, [:pointer], :void
44
+ end
@@ -0,0 +1,40 @@
1
+ module Opus
2
+ class Encoder
3
+ attr_reader :sample_rate, :frame_size, :channels,
4
+ :vbr_rate, :bitrate
5
+
6
+ def initialize(sample_rate, frame_size, channels)
7
+ @sample_rate = sample_rate
8
+ @frame_size = frame_size
9
+ @channels = channels
10
+
11
+ @encoder = Opus.opus_encoder_create sample_rate, channels, Constants::OPUS_APPLICATION_AUDIO, nil
12
+ end
13
+
14
+ def destroy
15
+ Opus.opus_encoder_destroy @encoder
16
+ end
17
+
18
+ def reset
19
+ Opus.opus_encoder_ctl @encoder, Opus::Constants::OPUS_RESET_STATE, :pointer, nil
20
+ end
21
+
22
+ def vbr_rate=(value)
23
+ @vbr_rate = value
24
+ Opus.opus_encoder_ctl @encoder, Opus::Constants::OPUS_SET_VBR_REQUEST, :int32, value
25
+ end
26
+
27
+ def bitrate=(value)
28
+ @bitrate = value
29
+ Opus.opus_encoder_ctl @encoder, Opus::Constants::OPUS_SET_BITRATE_REQUEST, :int32, value
30
+ end
31
+
32
+ def encode(data, size)
33
+ out = FFI::MemoryPointer.new :char, data.size + 1
34
+ buf = FFI::MemoryPointer.new :char, data.size + 1
35
+ buf.put_string 0, data
36
+ len = Opus.opus_encode @encoder, buf, @frame_size, out, size
37
+ out.read_string_length len
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,3 @@
1
+ module Opus
2
+ VERSION = "0.0.1"
3
+ end
data/opus-ruby.gemspec ADDED
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'opus-ruby/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "opus-ruby"
8
+ spec.version = Opus::VERSION
9
+ spec.authors = ["Matthew Perry"]
10
+ spec.email = ["muffinman616@gmail.com"]
11
+ spec.description = %q{Ruby FFI Gem for the OPUS Audio Codec}
12
+ spec.summary = %q{Ruby FFI wrapper for the OPUS Audio Codec C library for audio encoding}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake"
23
+
24
+ spec.add_dependency "ffi"
25
+ end
metadata ADDED
@@ -0,0 +1,97 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: opus-ruby
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Matthew Perry
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-02-23 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: ffi
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: Ruby FFI Gem for the OPUS Audio Codec
56
+ email:
57
+ - muffinman616@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - ".ruby-gemset"
64
+ - ".ruby-version"
65
+ - Gemfile
66
+ - LICENSE.txt
67
+ - README.md
68
+ - Rakefile
69
+ - lib/opus-ruby.rb
70
+ - lib/opus-ruby/encoder.rb
71
+ - lib/opus-ruby/version.rb
72
+ - opus-ruby.gemspec
73
+ homepage: ''
74
+ licenses:
75
+ - MIT
76
+ metadata: {}
77
+ post_install_message:
78
+ rdoc_options: []
79
+ require_paths:
80
+ - lib
81
+ required_ruby_version: !ruby/object:Gem::Requirement
82
+ requirements:
83
+ - - ">="
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ required_rubygems_version: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ requirements: []
92
+ rubyforge_project:
93
+ rubygems_version: 2.2.2
94
+ signing_key:
95
+ specification_version: 4
96
+ summary: Ruby FFI wrapper for the OPUS Audio Codec C library for audio encoding
97
+ test_files: []