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