f@0
|
1 #ifndef STK_WVOUT_H
|
f@0
|
2 #define STK_WVOUT_H
|
f@0
|
3
|
f@0
|
4 #include "Stk.h"
|
f@0
|
5
|
f@0
|
6 namespace stk {
|
f@0
|
7
|
f@0
|
8 /***************************************************/
|
f@0
|
9 /*! \class WvOut
|
f@0
|
10 \brief STK audio output abstract base class.
|
f@0
|
11
|
f@0
|
12 This class provides common functionality for a variety of audio
|
f@0
|
13 data output subclasses.
|
f@0
|
14
|
f@0
|
15 Currently, WvOut is non-interpolating and the output rate is
|
f@0
|
16 always Stk::sampleRate().
|
f@0
|
17
|
f@0
|
18 by Perry R. Cook and Gary P. Scavone, 1995--2014.
|
f@0
|
19 */
|
f@0
|
20 /***************************************************/
|
f@0
|
21
|
f@0
|
22 class WvOut : public Stk
|
f@0
|
23 {
|
f@0
|
24 public:
|
f@0
|
25
|
f@0
|
26 //! Default constructor.
|
f@0
|
27 WvOut( void ) : frameCounter_(0), clipping_(false) {};
|
f@0
|
28
|
f@0
|
29 //! Return the number of sample frames output.
|
f@0
|
30 unsigned long getFrameCount( void ) const { return frameCounter_; };
|
f@0
|
31
|
f@0
|
32 //! Return the number of seconds of data output.
|
f@0
|
33 StkFloat getTime( void ) const { return (StkFloat) frameCounter_ / Stk::sampleRate(); };
|
f@0
|
34
|
f@0
|
35 //! Returns \c true if clipping has been detected during output since instantiation or the last reset.
|
f@0
|
36 bool clipStatus( void ) { return clipping_; };
|
f@0
|
37
|
f@0
|
38 //! Reset the clipping status to \c false.
|
f@0
|
39 void resetClipStatus( void ) { clipping_ = false; };
|
f@0
|
40
|
f@0
|
41 //! Output a single sample to all channels in a sample frame.
|
f@0
|
42 /*!
|
f@0
|
43 An StkError is thrown if an output error occurs.
|
f@0
|
44 */
|
f@0
|
45 virtual void tick( const StkFloat sample ) = 0;
|
f@0
|
46
|
f@0
|
47 //! Output the StkFrames data.
|
f@0
|
48 virtual void tick( const StkFrames& frames ) = 0;
|
f@0
|
49
|
f@0
|
50 protected:
|
f@0
|
51
|
f@0
|
52 // Check for sample clipping and clamp.
|
f@0
|
53 StkFloat& clipTest( StkFloat& sample );
|
f@0
|
54
|
f@0
|
55 StkFrames data_;
|
f@0
|
56 unsigned long frameCounter_;
|
f@0
|
57 bool clipping_;
|
f@0
|
58
|
f@0
|
59 };
|
f@0
|
60
|
f@0
|
61 inline StkFloat& WvOut :: clipTest( StkFloat& sample )
|
f@0
|
62 {
|
f@0
|
63 bool clip = false;
|
f@0
|
64 if ( sample > 1.0 ) {
|
f@0
|
65 sample = 1.0;
|
f@0
|
66 clip = true;
|
f@0
|
67 }
|
f@0
|
68 else if ( sample < -1.0 ) {
|
f@0
|
69 sample = -1.0;
|
f@0
|
70 clip = true;
|
f@0
|
71 }
|
f@0
|
72
|
f@0
|
73 if ( clip == true && clipping_ == false ) {
|
f@0
|
74 // First occurrence of clipping since instantiation or reset.
|
f@0
|
75 clipping_ = true;
|
f@0
|
76 oStream_ << "WvOut: data value(s) outside +-1.0 detected ... clamping at outer bound!";
|
f@0
|
77 handleError( StkError::WARNING );
|
f@0
|
78 }
|
f@0
|
79
|
f@0
|
80 return sample;
|
f@0
|
81 }
|
f@0
|
82
|
f@0
|
83 } // stk namespace
|
f@0
|
84
|
f@0
|
85 #endif
|