hornetseye-alsa 0.1.0

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/ext/alsaoutput.hh ADDED
@@ -0,0 +1,68 @@
1
+ /* HornetsEye - Computer Vision with Ruby
2
+ Copyright (C) 2006, 2007, 2008, 2009, 2010 Jan Wedekind
3
+
4
+ This program is free software: you can redistribute it and/or modify
5
+ it under the terms of the GNU General Public License as published by
6
+ the Free Software Foundation, either version 3 of the License, or
7
+ (at your option) any later version.
8
+
9
+ This program is distributed in the hope that it will be useful,
10
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ GNU General Public License for more details.
13
+
14
+ You should have received a copy of the GNU General Public License
15
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
16
+ #ifndef ALSAOUTPUT_HH
17
+ #define ALSAOUTPUT_HH
18
+
19
+ #include <alsa/asoundlib.h>
20
+ #include <string>
21
+ #include "rubyinc.hh"
22
+ #include "error.hh"
23
+ #include "sequence.hh"
24
+
25
+ class AlsaOutput
26
+ {
27
+ public:
28
+ AlsaOutput( const std::string &pcmName = "default:0",
29
+ unsigned int rate = 48000, unsigned int channels = 2,
30
+ int periods = 2, int frames = 1024 ) throw (Error);
31
+ virtual ~AlsaOutput(void);
32
+ void close(void);
33
+ void write( SequencePtr sequence ) throw (Error);
34
+ void drop(void) throw (Error);
35
+ void drain(void) throw (Error);
36
+ unsigned int rate(void);
37
+ unsigned int channels(void);
38
+ unsigned int frames(void);
39
+ int avail(void) throw (Error);
40
+ int delay(void) throw (Error);
41
+ void prepare(void) throw (Error);
42
+ static VALUE cRubyClass;
43
+ static VALUE registerRubyClass( VALUE rbModule );
44
+ static void deleteRubyObject( void *ptr );
45
+ static VALUE wrapNew( VALUE rbClass, VALUE rbPCMName, VALUE rbRate,
46
+ VALUE rbChannels, VALUE rbPeriods, VALUE rbFrames );
47
+ static VALUE wrapClose( VALUE rbSelf );
48
+ static VALUE wrapWrite( VALUE rbSelf, VALUE rbSequence );
49
+ static VALUE wrapDrop( VALUE rbSelf );
50
+ static VALUE wrapDrain( VALUE rbSelf );
51
+ static VALUE wrapRate( VALUE rbSelf );
52
+ static VALUE wrapChannels( VALUE rbSelf );
53
+ static VALUE wrapFrames( VALUE rbSelf );
54
+ static VALUE wrapAvail( VALUE rbSelf );
55
+ static VALUE wrapDelay( VALUE rbSelf );
56
+ static VALUE wrapPrepare( VALUE rbSelf );
57
+ protected:
58
+ snd_pcm_t *m_pcmHandle;
59
+ std::string m_pcmName;
60
+ unsigned int m_rate;
61
+ unsigned int m_channels;
62
+ snd_pcm_uframes_t m_frames;
63
+ };
64
+
65
+ typedef boost::shared_ptr< AlsaOutput > AlsaOutputPtr;
66
+
67
+ #endif
68
+
data/ext/error.hh ADDED
@@ -0,0 +1,50 @@
1
+ /* HornetsEye - Computer Vision with Ruby
2
+ Copyright (C) 2006, 2007, 2008, 2009, 2010 Jan Wedekind
3
+
4
+ This program is free software: you can redistribute it and/or modify
5
+ it under the terms of the GNU General Public License as published by
6
+ the Free Software Foundation, either version 3 of the License, or
7
+ (at your option) any later version.
8
+
9
+ This program is distributed in the hope that it will be useful,
10
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ GNU General Public License for more details.
13
+
14
+ You should have received a copy of the GNU General Public License
15
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
16
+ #ifndef ERROR_HH
17
+ #define ERROR_HH
18
+
19
+ #include <exception>
20
+ #include <sstream>
21
+
22
+ class Error: public std::exception
23
+ {
24
+ public:
25
+ Error(void) {}
26
+ Error( Error &e ): std::exception( e )
27
+ { m_message << e.m_message.str(); }
28
+ virtual ~Error(void) throw() {}
29
+ template< typename T >
30
+ std::ostream &operator<<( const T &t )
31
+ { m_message << t; return m_message; }
32
+ std::ostream &operator<<( std::ostream& (*__pf)(std::ostream&) )
33
+ { (*__pf)( m_message ); return m_message; }
34
+ virtual const char* what(void) const throw() {
35
+ temp = m_message.str();
36
+ return temp.c_str();
37
+ }
38
+ protected:
39
+ std::ostringstream m_message;
40
+ mutable std::string temp;
41
+ };
42
+
43
+ #define ERRORMACRO( condition, class, params, message ) \
44
+ if ( !( condition ) ) { \
45
+ class _e params; \
46
+ _e << message; \
47
+ throw _e; \
48
+ };
49
+
50
+ #endif
data/ext/init.cc ADDED
@@ -0,0 +1,38 @@
1
+ /* HornetsEye - Computer Vision with Ruby
2
+ Copyright (C) 2006, 2007, 2008, 2009, 2010 Jan Wedekind
3
+
4
+ This program is free software: you can redistribute it and/or modify
5
+ it under the terms of the GNU General Public License as published by
6
+ the Free Software Foundation, either version 3 of the License, or
7
+ (at your option) any later version.
8
+
9
+ This program is distributed in the hope that it will be useful,
10
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ GNU General Public License for more details.
13
+
14
+ You should have received a copy of the GNU General Public License
15
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
16
+ #include "alsaoutput.hh"
17
+
18
+ #ifdef WIN32
19
+ #define DLLEXPORT __declspec(dllexport)
20
+ #define DLLLOCAL
21
+ #else
22
+ #define DLLEXPORT __attribute__ ((visibility("default")))
23
+ #define DLLLOCAL __attribute__ ((visibility("hidden")))
24
+ #endif
25
+
26
+ extern "C" DLLEXPORT void Init_hornetseye_alsa(void);
27
+
28
+ extern "C" {
29
+
30
+ void Init_hornetseye_alsa(void)
31
+ {
32
+ rb_require( "multiarray" );
33
+ VALUE rbHornetseye = rb_define_module( "Hornetseye" );
34
+ AlsaOutput::registerRubyClass( rbHornetseye );
35
+ rb_require( "hornetseye_alsa_ext.rb" );
36
+ }
37
+
38
+ }
data/ext/rubyinc.hh ADDED
@@ -0,0 +1,54 @@
1
+ /* HornetsEye - Computer Vision with Ruby
2
+ Copyright (C) 2006, 2007 Jan Wedekind
3
+
4
+ This program is free software: you can redistribute it and/or modify
5
+ it under the terms of the GNU General Public License as published by
6
+ the Free Software Foundation, either version 3 of the License, or
7
+ (at your option) any later version.
8
+
9
+ This program is distributed in the hope that it will be useful,
10
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ GNU General Public License for more details.
13
+
14
+ You should have received a copy of the GNU General Public License
15
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
16
+ #ifndef HORNETSEYE_RUBYINC_HH
17
+ #define HORNETSEYE_RUBYINC_HH
18
+
19
+ #ifdef RSHIFT
20
+ #undef RSHIFT
21
+ #endif
22
+
23
+ #define gettimeofday rubygettimeofday
24
+ #define timezone rubygettimezone
25
+ #include <ruby.h>
26
+ // #include <version.h>
27
+ #undef timezone
28
+ #undef gettimeofday
29
+ #ifdef read
30
+ #undef read
31
+ #endif
32
+ #ifdef write
33
+ #undef write
34
+ #endif
35
+ #ifdef RGB
36
+ #undef RGB
37
+ #endif
38
+
39
+ #ifndef RUBY_VERSION_NUMBER
40
+ #define RUBY_VERSION_NUMBER ( RUBY_VERSION_MAJOR * 10000 + \
41
+ RUBY_VERSION_MINOR * 100 + \
42
+ RUBY_VERSION_TEENY )
43
+ #endif
44
+
45
+ #ifndef RUBY_METHOD_FUNC
46
+ #define RUBY_METHOD_FUNC(func) ((VALUE (*)(ANYARGS))func)
47
+ #endif
48
+
49
+ #ifndef xfree
50
+ #define xfree free
51
+ #endif
52
+
53
+ #endif
54
+
data/ext/sequence.cc ADDED
@@ -0,0 +1,50 @@
1
+ /* HornetsEye - Computer Vision with Ruby
2
+ Copyright (C) 2006, 2007, 2008, 2009, 2010 Jan Wedekind
3
+
4
+ This program is free software: you can redistribute it and/or modify
5
+ it under the terms of the GNU General Public License as published by
6
+ the Free Software Foundation, either version 3 of the License, or
7
+ (at your option) any later version.
8
+
9
+ This program is distributed in the hope that it will be useful,
10
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ GNU General Public License for more details.
13
+
14
+ You should have received a copy of the GNU General Public License
15
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
16
+ #include "sequence.hh"
17
+
18
+ using namespace std;
19
+
20
+ Sequence::Sequence( int size ):
21
+ m_sequence( Qnil )
22
+ {
23
+ VALUE mModule = rb_define_module( "Hornetseye" );
24
+ VALUE cMalloc = rb_define_class_under( mModule, "Malloc", rb_cObject );
25
+ VALUE cSequence = rb_define_class_under( mModule, "Sequence", rb_cObject );
26
+ VALUE rbSize = INT2NUM( size );
27
+ VALUE rbMemory = rb_funcall( cMalloc, rb_intern( "new" ), 1, rbSize );
28
+ m_sequence = rb_funcall( cSequence, rb_intern( "import" ), 3,
29
+ rb_const_get( mModule, rb_intern( "UBYTE" ) ),
30
+ rbMemory, rbSize );
31
+ }
32
+
33
+ int Sequence::size(void)
34
+ {
35
+ return NUM2INT( rb_funcall( m_sequence, rb_intern( "size" ), 0 ) );
36
+ }
37
+
38
+ char *Sequence::data(void)
39
+ {
40
+ VALUE rbMemory = rb_funcall( m_sequence, rb_intern( "memory" ), 0 );
41
+ char *ptr;
42
+ Data_Get_Struct( rbMemory, char, ptr );
43
+ return ptr;
44
+ }
45
+
46
+ void Sequence::markRubyMember(void)
47
+ {
48
+ rb_gc_mark( m_sequence );
49
+ }
50
+
data/ext/sequence.hh ADDED
@@ -0,0 +1,39 @@
1
+ /* HornetsEye - Computer Vision with Ruby
2
+ Copyright (C) 2006, 2007, 2008, 2009, 2010 Jan Wedekind
3
+
4
+ This program is free software: you can redistribute it and/or modify
5
+ it under the terms of the GNU General Public License as published by
6
+ the Free Software Foundation, either version 3 of the License, or
7
+ (at your option) any later version.
8
+
9
+ This program is distributed in the hope that it will be useful,
10
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ GNU General Public License for more details.
13
+
14
+ You should have received a copy of the GNU General Public License
15
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
16
+ #ifndef SEQUENCE_HH
17
+ #define SEQUENCE_HH
18
+
19
+ #include <boost/smart_ptr.hpp>
20
+ #include "rubyinc.hh"
21
+ #include <string>
22
+
23
+ class Sequence
24
+ {
25
+ public:
26
+ Sequence( int size );
27
+ Sequence( VALUE rbSequence ): m_sequence( rbSequence ) {}
28
+ virtual ~Sequence(void) {}
29
+ int size(void);
30
+ char *data(void);
31
+ VALUE rubyObject(void) { return m_sequence; }
32
+ void markRubyMember(void);
33
+ protected:
34
+ VALUE m_sequence;
35
+ };
36
+
37
+ typedef boost::shared_ptr< Sequence > SequencePtr;
38
+
39
+ #endif
@@ -0,0 +1,52 @@
1
+ # hornetseye-alsa - Play audio data using libalsa
2
+ # Copyright (C) 2010 Jan Wedekind
3
+ #
4
+ # This program is free software: you can redistribute it and/or modify
5
+ # it under the terms of the GNU General Public License as published by
6
+ # the Free Software Foundation, either version 3 of the License, or
7
+ # (at your option) any later version.
8
+ #
9
+ # This program is distributed in the hope that it will be useful,
10
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ # GNU General Public License for more details.
13
+ #
14
+ # You should have received a copy of the GNU General Public License
15
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
16
+
17
+ # Namespace of Hornetseye computer vision library
18
+ module Hornetseye
19
+
20
+ class AlsaOutput
21
+
22
+ class << self
23
+
24
+ alias_method :orig_new, :new
25
+
26
+ def new( pcm_name = 'default:0', rate = 48000, channels = 2, periods = 2,
27
+ frames = 1024 )
28
+ orig_new pcm_name, rate, channels, periods, frames
29
+ end
30
+
31
+ end
32
+
33
+ alias_method :orig_write, :write
34
+
35
+ def write( frame )
36
+ if frame.typecode != SINT
37
+ raise "Audio data must be of type SINT (but was #{frame.typecode})"
38
+ end
39
+ if frame.dimension != 2
40
+ raise "Audio frame must have two dimensions (but had #{frame.dimension})"
41
+ end
42
+ if frame.shape.first != channels
43
+ raise "Audio frame must have #{channels} channel(s) but had " +
44
+ "#{frame.shape.first}"
45
+ end
46
+ orig_write Sequence( UBYTE, 2 * frame.size ).new( frame.memory )
47
+ end
48
+
49
+ end
50
+
51
+ end
52
+
@@ -0,0 +1,17 @@
1
+ # hornetseye-alsa - Play audio data using libalsa
2
+ # Copyright (C) 2010 Jan Wedekind
3
+ #
4
+ # This program is free software: you can redistribute it and/or modify
5
+ # it under the terms of the GNU General Public License as published by
6
+ # the Free Software Foundation, either version 3 of the License, or
7
+ # (at your option) any later version.
8
+ #
9
+ # This program is distributed in the hope that it will be useful,
10
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ # GNU General Public License for more details.
13
+ #
14
+ # You should have received a copy of the GNU General Public License
15
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
16
+ require 'hornetseye-alsa/alsaoutput'
17
+
metadata ADDED
@@ -0,0 +1,131 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: hornetseye-alsa
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 1
8
+ - 0
9
+ version: 0.1.0
10
+ platform: ruby
11
+ authors:
12
+ - Jan Wedekind
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-10-19 00:00:00 +01:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: malloc
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ~>
27
+ - !ruby/object:Gem::Version
28
+ segments:
29
+ - 1
30
+ - 2
31
+ version: "1.2"
32
+ type: :runtime
33
+ version_requirements: *id001
34
+ - !ruby/object:Gem::Dependency
35
+ name: multiarray
36
+ prerelease: false
37
+ requirement: &id002 !ruby/object:Gem::Requirement
38
+ none: false
39
+ requirements:
40
+ - - ~>
41
+ - !ruby/object:Gem::Version
42
+ segments:
43
+ - 0
44
+ - 11
45
+ version: "0.11"
46
+ type: :runtime
47
+ version_requirements: *id002
48
+ - !ruby/object:Gem::Dependency
49
+ name: hornetseye-frame
50
+ prerelease: false
51
+ requirement: &id003 !ruby/object:Gem::Requirement
52
+ none: false
53
+ requirements:
54
+ - - ~>
55
+ - !ruby/object:Gem::Version
56
+ segments:
57
+ - 0
58
+ - 7
59
+ version: "0.7"
60
+ type: :runtime
61
+ version_requirements: *id003
62
+ - !ruby/object:Gem::Dependency
63
+ name: rake
64
+ prerelease: false
65
+ requirement: &id004 !ruby/object:Gem::Requirement
66
+ none: false
67
+ requirements:
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ segments:
71
+ - 0
72
+ version: "0"
73
+ type: :development
74
+ version_requirements: *id004
75
+ description: This Ruby extension provides an interface for playing audio data using ALSA.
76
+ email: jan@wedesoft.de
77
+ executables: []
78
+
79
+ extensions:
80
+ - Rakefile
81
+ extra_rdoc_files: []
82
+
83
+ files:
84
+ - Rakefile
85
+ - README.md
86
+ - COPYING
87
+ - .document
88
+ - lib/hornetseye-alsa/alsaoutput.rb
89
+ - lib/hornetseye_alsa_ext.rb
90
+ - ext/init.cc
91
+ - ext/sequence.cc
92
+ - ext/alsaoutput.cc
93
+ - ext/sequence.hh
94
+ - ext/rubyinc.hh
95
+ - ext/error.hh
96
+ - ext/alsaoutput.hh
97
+ has_rdoc: yard
98
+ homepage: http://wedesoft.github.com/hornetseye-alsa/
99
+ licenses: []
100
+
101
+ post_install_message:
102
+ rdoc_options:
103
+ - --no-private
104
+ require_paths:
105
+ - lib
106
+ - ext
107
+ required_ruby_version: !ruby/object:Gem::Requirement
108
+ none: false
109
+ requirements:
110
+ - - ">="
111
+ - !ruby/object:Gem::Version
112
+ segments:
113
+ - 0
114
+ version: "0"
115
+ required_rubygems_version: !ruby/object:Gem::Requirement
116
+ none: false
117
+ requirements:
118
+ - - ">="
119
+ - !ruby/object:Gem::Version
120
+ segments:
121
+ - 0
122
+ version: "0"
123
+ requirements: []
124
+
125
+ rubyforge_project: hornetseye
126
+ rubygems_version: 1.3.7
127
+ signing_key:
128
+ specification_version: 3
129
+ summary: Play audio data using libalsa
130
+ test_files: []
131
+