annotate stk/include/RtWvOut.h @ 0:4606bd505630 tip

first import
author Fiore Martin <f.martin@qmul.ac.uk>
date Sat, 13 Jun 2015 15:08:10 +0100
parents
children
rev   line source
f@0 1 #ifndef STK_RTWVOUT_H
f@0 2 #define STK_RTWVOUT_H
f@0 3
f@0 4 #include "WvOut.h"
f@0 5 #include "RtAudio.h"
f@0 6 #include "Mutex.h"
f@0 7
f@0 8 namespace stk {
f@0 9
f@0 10 /***************************************************/
f@0 11 /*! \class RtWvOut
f@0 12 \brief STK realtime audio (blocking) output class.
f@0 13
f@0 14 This class provides a simplified interface to RtAudio for realtime
f@0 15 audio output. It is a subclass of WvOut. This class makes use of
f@0 16 RtAudio's callback functionality by creating a large ring-buffer
f@0 17 into which data is written. This class should not be used when
f@0 18 low-latency is desired.
f@0 19
f@0 20 RtWvOut supports multi-channel data in interleaved format. It is
f@0 21 important to distinguish the tick() method that outputs a single
f@0 22 sample to all channels in a sample frame from the overloaded one
f@0 23 that takes a reference to an StkFrames object for multi-channel
f@0 24 and/or multi-frame data.
f@0 25
f@0 26 by Perry R. Cook and Gary P. Scavone, 1995--2014.
f@0 27 */
f@0 28 /***************************************************/
f@0 29
f@0 30 class RtWvOut : public WvOut
f@0 31 {
f@0 32 public:
f@0 33
f@0 34 //! Default constructor.
f@0 35 /*!
f@0 36 The default \e device argument value (zero) will select the
f@0 37 default output device on your system. The first device enumerated
f@0 38 by the underlying audio API is specified with a value of one. The
f@0 39 default buffer size of RT_BUFFER_SIZE is defined in Stk.h. An
f@0 40 StkError will be thrown if an error occurs duing instantiation.
f@0 41 */
f@0 42 RtWvOut( unsigned int nChannels = 1, StkFloat sampleRate = Stk::sampleRate(),
f@0 43 int device = 0, int bufferFrames = RT_BUFFER_SIZE, int nBuffers = 20 );
f@0 44
f@0 45 //! Class destructor.
f@0 46 ~RtWvOut();
f@0 47
f@0 48 //! Start the audio output stream.
f@0 49 /*!
f@0 50 The stream is started automatically, if necessary, when a
f@0 51 tick() method is called.
f@0 52 */
f@0 53 void start( void );
f@0 54
f@0 55 //! Stop the audio output stream.
f@0 56 /*!
f@0 57 It may be necessary to use this method to avoid undesireable
f@0 58 audio buffer cycling if you wish to temporarily stop audio output.
f@0 59 */
f@0 60 void stop( void );
f@0 61
f@0 62 //! Output a single sample to all channels in a sample frame.
f@0 63 /*!
f@0 64 If the device is "stopped", it is "started".
f@0 65 */
f@0 66 void tick( const StkFloat sample );
f@0 67
f@0 68 //! Output the StkFrames data.
f@0 69 /*!
f@0 70 If the device is "stopped", it is "started". The number of
f@0 71 channels in the StkFrames argument must equal the number of
f@0 72 channels specified during instantiation. However, this is only
f@0 73 checked if _STK_DEBUG_ is defined during compilation, in which
f@0 74 case an incompatibility will trigger an StkError exception.
f@0 75 */
f@0 76 void tick( const StkFrames& frames );
f@0 77
f@0 78 // This function is not intended for general use but must be
f@0 79 // public for access from the audio callback function.
f@0 80 int readBuffer( void *buffer, unsigned int frameCount );
f@0 81
f@0 82 protected:
f@0 83
f@0 84 RtAudio dac_;
f@0 85 Mutex mutex_;
f@0 86 bool stopped_;
f@0 87 unsigned int readIndex_;
f@0 88 unsigned int writeIndex_;
f@0 89 long framesFilled_;
f@0 90 unsigned int status_; // running = 0, emptying buffer = 1, finished = 2
f@0 91
f@0 92 };
f@0 93
f@0 94 } // stk namespace
f@0 95
f@0 96 #endif