Home   Information   Classes   Download   Usage   Mail List   Requirements   Links   FAQ   Tutorial


Public Member Functions | List of all members
stk::RtWvIn Class Reference

STK realtime audio (blocking) input class. More...

#include <RtWvIn.h>

Inheritance diagram for stk::RtWvIn:
stk::WvIn stk::Stk

Public Member Functions

 RtWvIn (unsigned int nChannels=1, StkFloat sampleRate=Stk::sampleRate(), int device=0, int bufferFrames=RT_BUFFER_SIZE, int nBuffers=20)
 Default constructor. More...
 
 ~RtWvIn ()
 Class destructor.
 
void start (void)
 Start the audio input stream. More...
 
void stop (void)
 Stop the audio input stream. More...
 
StkFloat lastOut (unsigned int channel=0)
 Return the specified channel value of the last computed frame. More...
 
StkFloat tick (unsigned int channel=0)
 Compute a sample frame and return the specified channel value. More...
 
StkFramestick (StkFrames &frames)
 Fill the StkFrames argument with computed frames and return the same reference. More...
 
- Public Member Functions inherited from stk::WvIn
unsigned int channelsOut (void) const
 Return the number of audio channels in the data or stream.
 
const StkFrameslastFrame (void) const
 Return an StkFrames reference to the last computed sample frame. More...
 
- Public Member Functions inherited from stk::Stk
void ignoreSampleRateChange (bool ignore=true)
 A function to enable/disable the automatic updating of class data when the STK sample rate changes. More...
 

Additional Inherited Members

- Static Public Member Functions inherited from stk::Stk
static StkFloat sampleRate (void)
 Static method that returns the current STK sample rate.
 
static void setSampleRate (StkFloat rate)
 Static method that sets the STK sample rate. More...
 
static std::string rawwavePath (void)
 Static method that returns the current rawwave path.
 
static void setRawwavePath (std::string path)
 Static method that sets the STK rawwave path.
 
static void swap16 (unsigned char *ptr)
 Static method that byte-swaps a 16-bit data type.
 
static void swap32 (unsigned char *ptr)
 Static method that byte-swaps a 32-bit data type.
 
static void swap64 (unsigned char *ptr)
 Static method that byte-swaps a 64-bit data type.
 
static void sleep (unsigned long milliseconds)
 Static cross-platform method to sleep for a number of milliseconds.
 
static bool inRange (StkFloat value, StkFloat min, StkFloat max)
 Static method to check whether a value is within a specified range.
 
static void handleError (const char *message, StkError::Type type)
 Static function for error reporting and handling using c-strings.
 
static void handleError (std::string message, StkError::Type type)
 Static function for error reporting and handling using c++ strings.
 
static void showWarnings (bool status)
 Toggle display of WARNING and STATUS messages.
 
static void printErrors (bool status)
 Toggle display of error messages before throwing exceptions.
 
- Static Public Attributes inherited from stk::Stk
static const StkFormat STK_SINT8
 
static const StkFormat STK_SINT16
 
static const StkFormat STK_SINT24
 
static const StkFormat STK_SINT32
 
static const StkFormat STK_FLOAT32
 
static const StkFormat STK_FLOAT64
 
- Protected Member Functions inherited from stk::Stk
 Stk (void)
 Default constructor.
 
virtual ~Stk (void)
 Class destructor.
 
virtual void sampleRateChanged (StkFloat newRate, StkFloat oldRate)
 This function should be implemented in subclasses that depend on the sample rate.
 
void addSampleRateAlert (Stk *ptr)
 Add class pointer to list for sample rate change notification.
 
void removeSampleRateAlert (Stk *ptr)
 Remove class pointer from list for sample rate change notification.
 
void handleError (StkError::Type type) const
 Internal function for error reporting that assumes message in oStream_ variable.
 

Detailed Description

STK realtime audio (blocking) input class.

This class provides a simplified interface to RtAudio for realtime audio input. It is a subclass of WvIn. This class makes use of RtAudio's callback functionality by creating a large ring-buffer from which data is read. This class should not be used when low-latency is desired.

RtWvIn supports multi-channel data in both interleaved and non-interleaved formats. It is important to distinguish the tick() method that computes a single frame (and returns only the specified sample of a multi-channel frame) from the overloaded one that takes an StkFrames object for multi-channel and/or multi-frame data.

by Perry R. Cook and Gary P. Scavone, 1995–2014.

Constructor & Destructor Documentation

stk::RtWvIn::RtWvIn ( unsigned int  nChannels = 1,
StkFloat  sampleRate = Stk::sampleRate(),
int  device = 0,
int  bufferFrames = RT_BUFFER_SIZE,
int  nBuffers = 20 
)

Default constructor.

The default device argument value (zero) will select the default input device on your system. The first device enumerated by the underlying audio API is specified with a value of one. The default buffer size of RT_BUFFER_SIZE is defined in Stk.h. An StkError will be thrown if an error occurs duing instantiation.

Member Function Documentation

void stk::RtWvIn::start ( void  )

Start the audio input stream.

The stream is started automatically, if necessary, when a tick() or tickFrame() method is called.

void stk::RtWvIn::stop ( void  )

Stop the audio input stream.

It may be necessary to use this method to avoid audio underflow problems if you wish to temporarily stop audio input.

StkFloat stk::RtWvIn::lastOut ( unsigned int  channel = 0)
inline

Return the specified channel value of the last computed frame.

For multi-channel files, use the lastFrame() function to get all values from the last computed frame. If the device is stopped, the returned value is 0.0. The channel argument must be less than the number of channels in the audio stream (the first channel is specified by 0). However, range checking is only performed if STK_DEBUG is defined during compilation, in which case an out-of-range value will trigger an StkError exception.

112 {
113 #if defined(_STK_DEBUG_)
114  if ( channel >= data_.channels() ) {
115  oStream_ << "RtWvIn::lastOut(): channel argument and audio stream are incompatible!";
116  handleError( StkError::FUNCTION_ARGUMENT );
117  }
118 #endif
119 
120  return lastFrame_[channel];
121 }
StkFloat stk::RtWvIn::tick ( unsigned int  channel = 0)
virtual

Compute a sample frame and return the specified channel value.

For multi-channel files, use the lastFrame() function to get all values from the computed frame. If the device is "stopped", it is "started". The channel argument must be less than the number of channels in the audio stream (the first channel is specified by 0). However, range checking is only performed if STK_DEBUG is defined during compilation, in which case an out-of-range value will trigger an StkError exception.

Implements stk::WvIn.

StkFrames& stk::RtWvIn::tick ( StkFrames frames)
virtual

Fill the StkFrames argument with computed frames and return the same reference.

If the device is "stopped", it is "started". The number of channels in the StkFrames argument must equal the number of channels specified during instantiation. However, this is only checked if STK_DEBUG is defined during compilation, in which case an incompatibility will trigger an StkError exception.

Implements stk::WvIn.


The documentation for this class was generated from the following file:

The Synthesis ToolKit in C++ (STK)
©1995--2014 Perry R. Cook and Gary P. Scavone. All Rights Reserved.