Permalink
Browse files

Added sample parameter to AlsaInput#read

  • Loading branch information...
wedesoft committed Nov 14, 2010
1 parent ef97aa6 commit 04fe9185df1b087bcb7a484bc487caf86502f608
Showing with 11 additions and 9 deletions.
  1. +6 −5 ext/alsainput.cc
  2. +2 −2 ext/alsainput.hh
  3. +3 −2 lib/hornetseye-alsa/alsainput.rb
View
@@ -78,10 +78,11 @@ void AlsaInput::close(void)
};
}
-SequencePtr AlsaInput::read(void) throw (Error)
+SequencePtr AlsaInput::read( int samples ) throw (Error)
{
ERRORMACRO( m_pcmHandle != NULL, Error, , "PCM device \"" << m_pcmName
<< "\" is not open. Did you call \"close\" before?" );
+ int n = samples * 2 * m_channels;
#if 0
int n = frame->size() / ( 2 * m_channels );
int err;
@@ -94,7 +95,7 @@ SequencePtr AlsaInput::read(void) throw (Error)
ERRORMACRO( n == err, Error, , "Only managed to write " << err << " of " << n
<< " frames to PCM device \"" << m_pcmName << "\"" );
#endif
- SequencePtr sequence( new Sequence( 1024 ) );
+ SequencePtr sequence( new Sequence( n ) );
return sequence;
}
@@ -123,7 +124,7 @@ VALUE AlsaInput::registerRubyClass( VALUE rbModule )
rb_define_singleton_method( cRubyClass, "new",
RUBY_METHOD_FUNC( wrapNew ), 5 );
rb_define_method( cRubyClass, "close", RUBY_METHOD_FUNC( wrapClose ), 0 );
- rb_define_method( cRubyClass, "read", RUBY_METHOD_FUNC( wrapRead ), 0 );
+ rb_define_method( cRubyClass, "read", RUBY_METHOD_FUNC( wrapRead ), 1 );
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 );
@@ -158,12 +159,12 @@ VALUE AlsaInput::wrapClose( VALUE rbSelf )
return rbSelf;
}
-VALUE AlsaInput::wrapRead( VALUE rbSelf )
+VALUE AlsaInput::wrapRead( VALUE rbSelf, VALUE rbSamples )
{
VALUE rbRetVal = Qnil;
try {
AlsaInputPtr *self; Data_Get_Struct( rbSelf, AlsaInputPtr, self );
- SequencePtr sequence( (*self)->read() );
+ SequencePtr sequence( (*self)->read( NUM2INT( rbSamples ) ) );
rbRetVal = sequence->rubyObject();
} catch ( exception &e ) {
rb_raise( rb_eRuntimeError, "%s", e.what() );
View
@@ -30,7 +30,7 @@ public:
int periods = 16, snd_pcm_uframes_t frames = 1024 ) throw (Error);
virtual ~AlsaInput(void);
void close(void);
- SequencePtr read(void) throw (Error);
+ SequencePtr read( int samples ) throw (Error);
unsigned int rate(void);
unsigned int channels(void);
void prepare(void) throw (Error);
@@ -40,7 +40,7 @@ public:
static VALUE wrapNew( VALUE rbClass, VALUE rbPCMName, VALUE rbRate,
VALUE rbChannels, VALUE rbPeriods, VALUE rbFrames );
static VALUE wrapClose( VALUE rbSelf );
- static VALUE wrapRead( VALUE rbSelf );
+ static VALUE wrapRead( VALUE rbSelf, VALUE rbSamples );
static VALUE wrapRate( VALUE rbSelf );
static VALUE wrapChannels( VALUE rbSelf );
static VALUE wrapPrepare( VALUE rbSelf );
@@ -32,8 +32,9 @@ def new( pcm_name = 'default:0', rate = 48000, channels = 2, periods = 16,
alias_method :orig_read, :read
- def read
- orig_read
+ def read( samples )
+ Hornetseye::MultiArray( SINT, channels, samples ).
+ new orig_read( samples ).memory
end
end

0 comments on commit 04fe918

Please sign in to comment.