f@0: #ifndef STK_RTWVOUT_H f@0: #define STK_RTWVOUT_H f@0: f@0: #include "WvOut.h" f@0: #include "RtAudio.h" f@0: #include "Mutex.h" f@0: f@0: namespace stk { f@0: f@0: /***************************************************/ f@0: /*! \class RtWvOut f@0: \brief STK realtime audio (blocking) output class. f@0: f@0: This class provides a simplified interface to RtAudio for realtime f@0: audio output. It is a subclass of WvOut. This class makes use of f@0: RtAudio's callback functionality by creating a large ring-buffer f@0: into which data is written. This class should not be used when f@0: low-latency is desired. f@0: f@0: RtWvOut supports multi-channel data in interleaved format. It is f@0: important to distinguish the tick() method that outputs a single f@0: sample to all channels in a sample frame from the overloaded one f@0: that takes a reference to an StkFrames object for multi-channel f@0: and/or multi-frame data. f@0: f@0: by Perry R. Cook and Gary P. Scavone, 1995--2014. f@0: */ f@0: /***************************************************/ f@0: f@0: class RtWvOut : public WvOut f@0: { f@0: public: f@0: f@0: //! Default constructor. f@0: /*! f@0: The default \e device argument value (zero) will select the f@0: default output device on your system. The first device enumerated f@0: by the underlying audio API is specified with a value of one. The f@0: default buffer size of RT_BUFFER_SIZE is defined in Stk.h. An f@0: StkError will be thrown if an error occurs duing instantiation. f@0: */ f@0: RtWvOut( unsigned int nChannels = 1, StkFloat sampleRate = Stk::sampleRate(), f@0: int device = 0, int bufferFrames = RT_BUFFER_SIZE, int nBuffers = 20 ); f@0: f@0: //! Class destructor. f@0: ~RtWvOut(); f@0: f@0: //! Start the audio output stream. f@0: /*! f@0: The stream is started automatically, if necessary, when a f@0: tick() method is called. f@0: */ f@0: void start( void ); f@0: f@0: //! Stop the audio output stream. f@0: /*! f@0: It may be necessary to use this method to avoid undesireable f@0: audio buffer cycling if you wish to temporarily stop audio output. f@0: */ f@0: void stop( void ); f@0: f@0: //! Output a single sample to all channels in a sample frame. f@0: /*! f@0: If the device is "stopped", it is "started". f@0: */ f@0: void tick( const StkFloat sample ); f@0: f@0: //! Output the StkFrames data. f@0: /*! f@0: If the device is "stopped", it is "started". The number of f@0: channels in the StkFrames argument must equal the number of f@0: channels specified during instantiation. However, this is only f@0: checked if _STK_DEBUG_ is defined during compilation, in which f@0: case an incompatibility will trigger an StkError exception. f@0: */ f@0: void tick( const StkFrames& frames ); f@0: f@0: // This function is not intended for general use but must be f@0: // public for access from the audio callback function. f@0: int readBuffer( void *buffer, unsigned int frameCount ); f@0: f@0: protected: f@0: f@0: RtAudio dac_; f@0: Mutex mutex_; f@0: bool stopped_; f@0: unsigned int readIndex_; f@0: unsigned int writeIndex_; f@0: long framesFilled_; f@0: unsigned int status_; // running = 0, emptying buffer = 1, finished = 2 f@0: f@0: }; f@0: f@0: } // stk namespace f@0: f@0: #endif