Arduino STK  4.6.2
WvOut.h
1 #ifndef STK_WVOUT_H
2 #define STK_WVOUT_H
3 
4 #include "Stk.h"
5 
6 namespace stk {
7 
8 /***************************************************/
20 /***************************************************/
21 
22 class WvOut : public Stk
23 {
24  public:
25 
27  WvOut( void ) : frameCounter_(0), clipping_(false) {};
28 
30  unsigned long getFrameCount( void ) const { return frameCounter_; };
31 
33  StkFloat getTime( void ) const { return (StkFloat) frameCounter_ / Stk::sampleRate(); };
34 
36  bool clipStatus( void ) { return clipping_; };
37 
39  void resetClipStatus( void ) { clipping_ = false; };
40 
42 
45  virtual void tick( const StkFloat sample ) = 0;
46 
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  handleError("WvOut: data value(s) outside +-1.0 detected ... clamping at outer bound!", StkError::WARNING );
77  }
78 
79  return sample;
80 }
81 
82 } // stk namespace
83 
84 #endif
An STK class to handle vectorized audio data.
Definition: Stk.h:287
STK base class.
Definition: Stk.h:144
static void handleError(const char *message, StkError::Type type)
Static function for error reporting and handling using c-strings.
static StkFloat sampleRate(void)
Static method that returns the current STK sample rate.
Definition: Stk.h:156
STK audio output abstract base class.
Definition: WvOut.h:23
StkFloat getTime(void) const
Return the number of seconds of data output.
Definition: WvOut.h:33
WvOut(void)
Default constructor.
Definition: WvOut.h:27
void resetClipStatus(void)
Reset the clipping status to false.
Definition: WvOut.h:39
virtual void tick(const StkFrames &frames)=0
Output the StkFrames data.
virtual void tick(const StkFloat sample)=0
Output a single sample to all channels in a sample frame.
bool clipStatus(void)
Returns true if clipping has been detected during output since instantiation or the last reset.
Definition: WvOut.h:36
unsigned long getFrameCount(void) const
Return the number of sample frames output.
Definition: WvOut.h:30
The STK namespace.
Definition: ADSR.h:8