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