Permalink
Browse files

Added AlsaInput#prepare

  • Loading branch information...
1 parent 0f09f24 commit ef97aa605ea65c559c46707893dd757527cd00c6 @wedesoft committed Nov 14, 2010
Showing with 23 additions and 0 deletions.
  1. +21 −0 ext/alsainput.cc
  2. +2 −0 ext/alsainput.hh
View
@@ -108,6 +108,15 @@ unsigned int AlsaInput::channels(void)
return m_channels;
}
+void AlsaInput::prepare(void) throw (Error)
+{
+ ERRORMACRO( m_pcmHandle != NULL, Error, , "PCM device \"" << m_pcmName
+ << "\" is not open. Did you call \"close\" before?" );
+ int err = snd_pcm_prepare( m_pcmHandle );
+ ERRORMACRO( err >= 0, Error, , "Error preparing PCM device \"" << m_pcmName
+ << "\": " << snd_strerror( err ) );
+}
+
VALUE AlsaInput::registerRubyClass( VALUE rbModule )
{
cRubyClass = rb_define_class_under( rbModule, "AlsaInput", rb_cObject );
@@ -117,6 +126,7 @@ VALUE AlsaInput::registerRubyClass( VALUE rbModule )
rb_define_method( cRubyClass, "read", RUBY_METHOD_FUNC( wrapRead ), 0 );
rb_define_method( cRubyClass, "rate", RUBY_METHOD_FUNC( wrapRate ), 0 );
rb_define_method( cRubyClass, "channels", RUBY_METHOD_FUNC( wrapChannels ), 0 );
+ rb_define_method( cRubyClass, "prepare", RUBY_METHOD_FUNC( wrapPrepare ), 0 );
}
void AlsaInput::deleteRubyObject( void *ptr )
@@ -173,3 +183,14 @@ VALUE AlsaInput::wrapChannels( VALUE rbSelf )
return UINT2NUM( (*self)->channels() );
}
+VALUE AlsaInput::wrapPrepare( VALUE rbSelf )
+{
+ try {
+ AlsaInputPtr *self; Data_Get_Struct( rbSelf, AlsaInputPtr, self );
+ (*self)->prepare();
+ } catch ( exception &e ) {
+ rb_raise( rb_eRuntimeError, "%s", e.what() );
+ };
+ return rbSelf;
+}
+
View
@@ -33,6 +33,7 @@ public:
SequencePtr read(void) throw (Error);
unsigned int rate(void);
unsigned int channels(void);
+ void prepare(void) throw (Error);
static VALUE cRubyClass;
static VALUE registerRubyClass( VALUE rbModule );
static void deleteRubyObject( void *ptr );
@@ -42,6 +43,7 @@ public:
static VALUE wrapRead( VALUE rbSelf );
static VALUE wrapRate( VALUE rbSelf );
static VALUE wrapChannels( VALUE rbSelf );
+ static VALUE wrapPrepare( VALUE rbSelf );
protected:
snd_pcm_t *m_pcmHandle;
std::string m_pcmName;

0 comments on commit ef97aa6

Please sign in to comment.