ffi-portaudio 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/Gemfile ADDED
@@ -0,0 +1,15 @@
1
+ source "http://rubygems.org"
2
+ # Add dependencies required to use your gem here.
3
+ # Example:
4
+ # gem "activesupport", ">= 2.3.5"
5
+
6
+ # Add dependencies to develop your gem here.
7
+ # Include everything needed to run rake, tests, features, etc.
8
+ gem "ffi"
9
+
10
+ group :development do
11
+ gem "shoulda", ">= 0"
12
+ gem "bundler", "~> 1.0.0"
13
+ gem "jeweler", "~> 1.6.4"
14
+ gem "rcov", ">= 0"
15
+ end
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 NANKI Haruo
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,25 @@
1
+ = ffi-portaudio
2
+
3
+ * http://github.com/nanki/ffi-chm
4
+
5
+ Ruby bindings for PortAudio.
6
+
7
+ == Requirements
8
+
9
+ * FFI
10
+ * PortAudio
11
+
12
+ == Copyright
13
+
14
+ Copyright (c) 2011 NANKI Haruo. See LICENSE.txt for further details.
15
+
16
+ == Contributing to ffi-portaudio
17
+
18
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
19
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
20
+ * Fork the project
21
+ * Start a feature/bugfix branch
22
+ * Commit and push until you are happy with your contribution
23
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
24
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
25
+
@@ -0,0 +1,53 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
12
+ require 'rake'
13
+
14
+ require 'jeweler'
15
+ Jeweler::Tasks.new do |gem|
16
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
17
+ gem.name = "ffi-portaudio"
18
+ gem.homepage = "http://github.com/nanki/ffi-portaudio"
19
+ gem.license = "MIT"
20
+ gem.summary = %Q{Ruby bindings for PortAudio.}
21
+ gem.description = %Q{Ruby bindings for PortAudio.}
22
+ gem.email = "nanki@dotswitch.net"
23
+ gem.authors = ["nanki"]
24
+ # dependencies defined in Gemfile
25
+ end
26
+ Jeweler::RubygemsDotOrgTasks.new
27
+
28
+ require 'rake/testtask'
29
+ Rake::TestTask.new(:test) do |test|
30
+ test.libs << 'lib' << 'test'
31
+ test.pattern = 'test/**/test_*.rb'
32
+ test.verbose = true
33
+ end
34
+
35
+ require 'rcov/rcovtask'
36
+ Rcov::RcovTask.new do |test|
37
+ test.libs << 'test'
38
+ test.pattern = 'test/**/test_*.rb'
39
+ test.verbose = true
40
+ test.rcov_opts << '--exclude "gems/*"'
41
+ end
42
+
43
+ task :default => :test
44
+
45
+ require 'rake/rdoctask'
46
+ Rake::RDocTask.new do |rdoc|
47
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
48
+
49
+ rdoc.rdoc_dir = 'rdoc'
50
+ rdoc.title = "ffi-portaudio #{version}"
51
+ rdoc.rdoc_files.include('README*')
52
+ rdoc.rdoc_files.include('lib/**/*.rb')
53
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
@@ -0,0 +1,12 @@
1
+ require 'ffi'
2
+
3
+ module FFI::PortAudio
4
+ VERSION ||= File.read(File.join(File.dirname(__FILE__), '../VERSION')).strip
5
+
6
+ require 'ffi-portaudio/enum'
7
+ require 'ffi-portaudio/struct'
8
+ require 'ffi-portaudio/const'
9
+ require 'ffi-portaudio/api'
10
+
11
+ autoload :Stream, 'ffi-portaudio/stream'
12
+ end
@@ -0,0 +1,53 @@
1
+ module FFI::PortAudio::API
2
+ extend FFI::Library
3
+
4
+ ffi_lib 'portaudio'
5
+
6
+ callback :PaStreamCallback, [:pointer, :pointer, :ulong, PaStreamCallbackTimeInfo.in, :ulong, :pointer], :PaStreamCallbackResult
7
+ callback :PaStreamFinishedCallback, [:pointer], :void
8
+
9
+ attach_function :Pa_GetVersion, [], :int
10
+ attach_function :Pa_GetVersionText, [], :string
11
+ attach_function :Pa_GetErrorText, [:PaErrorCode], :string
12
+ attach_function :Pa_Initialize, [], :PaErrorCode
13
+ attach_function :Pa_Terminate, [], :PaErrorCode
14
+
15
+ attach_function :Pa_GetHostApiCount, [], :int
16
+ attach_function :Pa_GetDefaultHostApi, [], :int
17
+ attach_function :Pa_GetHostApiInfo, [:int], PaHostApiInfo.ptr
18
+ attach_function :Pa_HostApiTypeIdToHostApiIndex, [:PaHostApiTypeId], :int
19
+ attach_function :Pa_HostApiDeviceIndexToDeviceIndex, [:int, :int], :int
20
+
21
+ attach_function :Pa_GetLastHostErrorInfo, [], PaHostErrorInfo.ptr
22
+ attach_function :Pa_GetDeviceCount, [], :int
23
+ attach_function :Pa_GetDefaultInputDevice, [], :int
24
+ attach_function :Pa_GetDefaultOutputDevice, [], :int
25
+ attach_function :Pa_GetDeviceInfo, [:int], PaDeviceInfo.ptr
26
+ attach_function :Pa_IsFormatSupported, [PaStreamParameters.in, PaStreamParameters.in, :double], :PaErrorCode
27
+
28
+ attach_function :Pa_OpenStream, [:pointer, PaStreamParameters.in, PaStreamParameters.in, :double, :ulong, :ulong, :PaStreamCallback, :pointer], :PaErrorCode
29
+ attach_function :Pa_OpenDefaultStream, [:pointer, :PaErrorCode, :PaErrorCode, :ulong, :double, :ulong, :PaStreamCallback, :pointer], :PaErrorCode
30
+ attach_function :Pa_CloseStream, [:pointer], :PaErrorCode
31
+
32
+ attach_function :Pa_SetStreamFinishedCallback, [:pointer, :PaStreamFinishedCallback], :PaErrorCode
33
+
34
+ attach_function :Pa_StartStream, [:pointer], :PaErrorCode
35
+ attach_function :Pa_StopStream, [:pointer], :PaErrorCode
36
+ attach_function :Pa_AbortStream, [:pointer], :PaErrorCode
37
+
38
+ attach_function :Pa_IsStreamStopped, [:pointer], :PaErrorCode
39
+ attach_function :Pa_IsStreamActive, [:pointer], :PaErrorCode
40
+
41
+ attach_function :Pa_GetStreamInfo, [:pointer], PaStreamInfo.ptr
42
+ attach_function :Pa_GetStreamTime, [:pointer], :double
43
+ attach_function :Pa_GetStreamCpuLoad, [:pointer], :double
44
+ attach_function :Pa_GetStreamReadAvailable, [:pointer], :long
45
+ attach_function :Pa_GetStreamWriteAvailable, [:pointer], :long
46
+
47
+ attach_function :Pa_ReadStream, [:pointer, :pointer, :ulong], :PaErrorCode
48
+ attach_function :Pa_WriteStream, [:pointer, :pointer, :ulong], :PaErrorCode
49
+
50
+ attach_function :Pa_GetSampleSize, [:ulong], :PaErrorCode
51
+
52
+ attach_function :Pa_Sleep, [:long], :void
53
+ end
@@ -0,0 +1,30 @@
1
+ module FFI::PortAudio::API
2
+ Float32 = 0x1
3
+ Int32 = 0x2
4
+ Int24 = 0x4
5
+ Int16 = 0x8
6
+ Int8 = 0x10
7
+ UInt8 = 0x20
8
+ CustomFormat = 0x10000
9
+ NonInterleaved = 0x80000000
10
+
11
+ FormatIsSupported = 0
12
+
13
+ FramesPerBufferUnspecified = 0
14
+
15
+ NoDevice = -1
16
+ UseHostApiSpecificDeviceSpecification = -2
17
+
18
+ NoFlag = 0
19
+ ClipOff = 1
20
+ DitherOff = 2
21
+ NeverDropInput = 4
22
+ PrimeOutputBuffersUsingStreamCallback = 8
23
+ PlatformSpecificFlags = 0xFFFF0000
24
+
25
+ InputUnderflow = 0x01
26
+ InputOverflow = 0x02
27
+ OutputUnderflow = 0x04
28
+ OutputOverflow = 0x08
29
+ PrimingOutput = 0x10
30
+ end
@@ -0,0 +1,42 @@
1
+ module FFI::PortAudio::API
2
+ extend FFI::Library
3
+
4
+ enum :PaErrorCode, [
5
+ :paNoError, 0,
6
+ :paNotInitialized, -10000,
7
+ :paUnanticipatedHostError,
8
+ :paInvalidChannelCount,
9
+ :paInvalidSampleRate,
10
+ :paInvalidDevice,
11
+ :paInvalidFlag,
12
+ :paSampleFormatNotSupported,
13
+ :paBadIODeviceCombination,
14
+ :paInsufficientMemory,
15
+ :paBufferTooBig,
16
+ :paBufferTooSmall,
17
+ :paNullCallback,
18
+ :paBadStreamPtr,
19
+ :paTimedOut,
20
+ :paInternalError,
21
+ :paDeviceUnavailable,
22
+ :paIncompatibleHostApiSpecificStreamInfo,
23
+ :paStreamIsStopped,
24
+ :paStreamIsNotStopped,
25
+ :paInputOverflowed,
26
+ :paOutputUnderflowed,
27
+ :paHostApiNotFound,
28
+ :paInvalidHostApi,
29
+ :paCanNotReadFromACallbackStream,
30
+ :paCanNotWriteToACallbackStream,
31
+ :paCanNotReadFromAnOutputOnlyStream,
32
+ :paCanNotWriteToAnInputOnlyStream,
33
+ :paIncompatibleStreamHostApi,
34
+ :paBadBufferPtr]
35
+
36
+ enum :PaHostApiTypeId, [
37
+ :paInDevelopment, :paDirectSound, :paMME, :paASIO, :paSoundManager, :paCoreAudio,
38
+ :paOSS, 7,
39
+ :paALSA, :paAL, :paBeOS, :paWDMKS, :paJACK, :paWASAPI, :paAudioScienceHPI]
40
+
41
+ enum :PaStreamCallbackResult, [:paContinue, :paComplete, :paAbort]
42
+ end
@@ -0,0 +1,19 @@
1
+ class FFI::PortAudio::Stream
2
+ include ::FFI::PortAudio
3
+
4
+ def open(input, output, freq, frames=API::FramesPerBufferUnspecified, flags=API::NoFlag, userdata=nil)
5
+ @input, @output, @freq, @frames, @flags, @userdata = input, output, freq, frames, flags, userdata
6
+ @stream = FFI::Buffer.new :pointer
7
+ API.Pa_OpenStream(@stream, @input, @output, @freq, @frames, @flags, method(:process), @userdata)
8
+ end
9
+
10
+ def process(input, output, frameCount, timeInfo, statusFlags, userData);end
11
+
12
+ def start
13
+ API.Pa_StartStream @stream.read_pointer
14
+ end
15
+
16
+ def close
17
+ API.Pa_CloseStream(@stream)
18
+ end
19
+ end
@@ -0,0 +1,62 @@
1
+ module FFI::PortAudio::API
2
+ class PaHostApiInfo < FFI::Struct
3
+ layout(
4
+ :structVersion, :int,
5
+ :type, :PaHostApiTypeId,
6
+ :name, :string,
7
+ :deviceCount, :int,
8
+ :defaultInputDevice, :int,
9
+ :defaultOutputDevice, :int
10
+ )
11
+ end
12
+
13
+ class PaHostErrorInfo < FFI::Struct
14
+ layout(
15
+ :hostApiType, :PaHostApiTypeId,
16
+ :errorCode, :long,
17
+ :errorText, :string
18
+ )
19
+ end
20
+
21
+ class PaDeviceInfo < FFI::Struct
22
+ layout(
23
+ :structVersion, :int,
24
+ :name, :string,
25
+ :hostApi, :int,
26
+ :maxInputChannels, :int,
27
+ :maxOutputChannels, :int,
28
+ :defaultLowInputLatency, :double,
29
+ :defaultLowOutputLatency, :double,
30
+ :defaultHighInputLatency, :double,
31
+ :defaultHighOutputLatency, :double,
32
+ :defaultSampleRate, :double
33
+ )
34
+ end
35
+
36
+ class PaStreamParameters < FFI::Struct
37
+ layout(
38
+ :device, :int,
39
+ :channelCount, :int,
40
+ :sampleFormat, :ulong,
41
+ :suggestedLatency, :double,
42
+ :hostApiSpecificStreamInfo, :pointer
43
+ )
44
+ end
45
+
46
+ class PaStreamCallbackTimeInfo < FFI::Struct
47
+ layout(
48
+ :inputBufferAdcTime, :double,
49
+ :currentTime, :double,
50
+ :outputBufferDacTime, :double
51
+ )
52
+ end
53
+
54
+ class PaStreamInfo < FFI::Struct
55
+ layout(
56
+ :structVersion, :int,
57
+ :inputLatency, :double,
58
+ :outputLatency, :double,
59
+ :sampleRate, :double
60
+ )
61
+ end
62
+ end
@@ -0,0 +1,18 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ begin
4
+ Bundler.setup(:default, :development)
5
+ rescue Bundler::BundlerError => e
6
+ $stderr.puts e.message
7
+ $stderr.puts "Run `bundle install` to install missing gems"
8
+ exit e.status_code
9
+ end
10
+ require 'test/unit'
11
+ require 'shoulda'
12
+
13
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
14
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
15
+ require 'ffi-portaudio'
16
+
17
+ class Test::Unit::TestCase
18
+ end
@@ -0,0 +1,7 @@
1
+ require 'helper'
2
+
3
+ class TestFfiPortaudio < Test::Unit::TestCase
4
+ should "probably rename this file and start testing for real" do
5
+ flunk "hey buddy, you should probably rename this file and start testing for real"
6
+ end
7
+ end
metadata ADDED
@@ -0,0 +1,119 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ffi-portaudio
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - nanki
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2011-09-24 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: ffi
16
+ requirement: &70202622192620 !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: *70202622192620
25
+ - !ruby/object:Gem::Dependency
26
+ name: shoulda
27
+ requirement: &70202622190760 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: *70202622190760
36
+ - !ruby/object:Gem::Dependency
37
+ name: bundler
38
+ requirement: &70202622189900 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ~>
42
+ - !ruby/object:Gem::Version
43
+ version: 1.0.0
44
+ type: :development
45
+ prerelease: false
46
+ version_requirements: *70202622189900
47
+ - !ruby/object:Gem::Dependency
48
+ name: jeweler
49
+ requirement: &70202622188400 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: 1.6.4
55
+ type: :development
56
+ prerelease: false
57
+ version_requirements: *70202622188400
58
+ - !ruby/object:Gem::Dependency
59
+ name: rcov
60
+ requirement: &70202622186760 !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ! '>='
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
66
+ type: :development
67
+ prerelease: false
68
+ version_requirements: *70202622186760
69
+ description: Ruby bindings for PortAudio.
70
+ email: nanki@dotswitch.net
71
+ executables: []
72
+ extensions: []
73
+ extra_rdoc_files:
74
+ - LICENSE.txt
75
+ - README.rdoc
76
+ files:
77
+ - .document
78
+ - Gemfile
79
+ - LICENSE.txt
80
+ - README.rdoc
81
+ - Rakefile
82
+ - VERSION
83
+ - lib/ffi-portaudio.rb
84
+ - lib/ffi-portaudio/api.rb
85
+ - lib/ffi-portaudio/const.rb
86
+ - lib/ffi-portaudio/enum.rb
87
+ - lib/ffi-portaudio/stream.rb
88
+ - lib/ffi-portaudio/struct.rb
89
+ - test/helper.rb
90
+ - test/test_ffi-portaudio.rb
91
+ homepage: http://github.com/nanki/ffi-portaudio
92
+ licenses:
93
+ - MIT
94
+ post_install_message:
95
+ rdoc_options: []
96
+ require_paths:
97
+ - lib
98
+ required_ruby_version: !ruby/object:Gem::Requirement
99
+ none: false
100
+ requirements:
101
+ - - ! '>='
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ segments:
105
+ - 0
106
+ hash: -1876936708131014168
107
+ required_rubygems_version: !ruby/object:Gem::Requirement
108
+ none: false
109
+ requirements:
110
+ - - ! '>='
111
+ - !ruby/object:Gem::Version
112
+ version: '0'
113
+ requirements: []
114
+ rubyforge_project:
115
+ rubygems_version: 1.8.6
116
+ signing_key:
117
+ specification_version: 3
118
+ summary: Ruby bindings for PortAudio.
119
+ test_files: []