hornetseye-alsa 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. data/Rakefile +1 -1
  2. data/ext/alsainput.cc +56 -0
  3. data/ext/alsainput.hh +4 -0
  4. metadata +2 -2
data/Rakefile CHANGED
@@ -7,7 +7,7 @@ require 'rake/loaders/makefile'
7
7
  require 'rbconfig'
8
8
 
9
9
  PKG_NAME = 'hornetseye-alsa'
10
- PKG_VERSION = '0.2.0'
10
+ PKG_VERSION = '0.3.0'
11
11
  CFG = RbConfig::CONFIG
12
12
  CXX = ENV[ 'CXX' ] || 'g++'
13
13
  RB_FILES = FileList[ 'lib/**/*.rb' ]
data/ext/alsainput.cc CHANGED
@@ -105,6 +105,36 @@ unsigned int AlsaInput::channels(void)
105
105
  return m_channels;
106
106
  }
107
107
 
108
+ int AlsaInput::avail(void) throw (Error)
109
+ {
110
+ ERRORMACRO( m_pcmHandle != NULL, Error, , "PCM device \"" << m_pcmName
111
+ << "\" is not open. Did you call \"close\" before?" );
112
+ snd_pcm_sframes_t frames;
113
+ int err = 0;
114
+ while ( ( frames = snd_pcm_avail( m_pcmHandle ) ) < 0 ) {
115
+ err = snd_pcm_recover( m_pcmHandle, frames, 1 );
116
+ ERRORMACRO( err >= 0, Error, , "Error querying number of available frames for "
117
+ "retrieval from PCM device \"" << m_pcmName << "\": "
118
+ << snd_strerror( err ) );
119
+ };
120
+ return frames;
121
+ }
122
+
123
+ int AlsaInput::delay(void) throw (Error)
124
+ {
125
+ ERRORMACRO( m_pcmHandle != NULL, Error, , "PCM device \"" << m_pcmName
126
+ << "\" is not open. Did you call \"close\" before?" );
127
+ snd_pcm_sframes_t frames;
128
+ int err;
129
+ while ( ( err = snd_pcm_delay( m_pcmHandle, &frames ) ) < 0 ) {
130
+ err = snd_pcm_recover( m_pcmHandle, err, 1 );
131
+ ERRORMACRO( err >= 0, Error, , "Error querying number of available frames for "
132
+ "capture on PCM device \"" << m_pcmName << "\": "
133
+ << snd_strerror( err ) );
134
+ };
135
+ return frames;
136
+ }
137
+
108
138
  void AlsaInput::prepare(void) throw (Error)
109
139
  {
110
140
  ERRORMACRO( m_pcmHandle != NULL, Error, , "PCM device \"" << m_pcmName
@@ -123,6 +153,8 @@ VALUE AlsaInput::registerRubyClass( VALUE rbModule )
123
153
  rb_define_method( cRubyClass, "read", RUBY_METHOD_FUNC( wrapRead ), 1 );
124
154
  rb_define_method( cRubyClass, "rate", RUBY_METHOD_FUNC( wrapRate ), 0 );
125
155
  rb_define_method( cRubyClass, "channels", RUBY_METHOD_FUNC( wrapChannels ), 0 );
156
+ rb_define_method( cRubyClass, "avail", RUBY_METHOD_FUNC( wrapAvail ), 0 );
157
+ rb_define_method( cRubyClass, "delay", RUBY_METHOD_FUNC( wrapDelay ), 0 );
126
158
  rb_define_method( cRubyClass, "prepare", RUBY_METHOD_FUNC( wrapPrepare ), 0 );
127
159
  }
128
160
 
@@ -180,6 +212,30 @@ VALUE AlsaInput::wrapChannels( VALUE rbSelf )
180
212
  return UINT2NUM( (*self)->channels() );
181
213
  }
182
214
 
215
+ VALUE AlsaInput::wrapAvail( VALUE rbSelf )
216
+ {
217
+ VALUE rbRetVal = Qnil;
218
+ try {
219
+ AlsaInputPtr *self; Data_Get_Struct( rbSelf, AlsaInputPtr, self );
220
+ rbRetVal = INT2NUM( (*self)->avail() );
221
+ } catch ( exception &e ) {
222
+ rb_raise( rb_eRuntimeError, "%s", e.what() );
223
+ };
224
+ return rbRetVal;
225
+ }
226
+
227
+ VALUE AlsaInput::wrapDelay( VALUE rbSelf )
228
+ {
229
+ VALUE rbRetVal = Qnil;
230
+ try {
231
+ AlsaInputPtr *self; Data_Get_Struct( rbSelf, AlsaInputPtr, self );
232
+ rbRetVal = INT2NUM( (*self)->delay() );
233
+ } catch ( exception &e ) {
234
+ rb_raise( rb_eRuntimeError, "%s", e.what() );
235
+ };
236
+ return rbRetVal;
237
+ }
238
+
183
239
  VALUE AlsaInput::wrapPrepare( VALUE rbSelf )
184
240
  {
185
241
  try {
data/ext/alsainput.hh CHANGED
@@ -33,6 +33,8 @@ public:
33
33
  SequencePtr read( int samples ) throw (Error);
34
34
  unsigned int rate(void);
35
35
  unsigned int channels(void);
36
+ int avail(void) throw (Error);
37
+ int delay(void) throw (Error);
36
38
  void prepare(void) throw (Error);
37
39
  static VALUE cRubyClass;
38
40
  static VALUE registerRubyClass( VALUE rbModule );
@@ -43,6 +45,8 @@ public:
43
45
  static VALUE wrapRead( VALUE rbSelf, VALUE rbSamples );
44
46
  static VALUE wrapRate( VALUE rbSelf );
45
47
  static VALUE wrapChannels( VALUE rbSelf );
48
+ static VALUE wrapAvail( VALUE rbSelf );
49
+ static VALUE wrapDelay( VALUE rbSelf );
46
50
  static VALUE wrapPrepare( VALUE rbSelf );
47
51
  protected:
48
52
  snd_pcm_t *m_pcmHandle;
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 0
7
- - 2
7
+ - 3
8
8
  - 0
9
- version: 0.2.0
9
+ version: 0.3.0
10
10
  platform: ruby
11
11
  authors:
12
12
  - Jan Wedekind