f@0: #ifndef STK_WVOUT_H f@0: #define STK_WVOUT_H f@0: f@0: #include "Stk.h" f@0: f@0: namespace stk { f@0: f@0: /***************************************************/ f@0: /*! \class WvOut f@0: \brief STK audio output abstract base class. f@0: f@0: This class provides common functionality for a variety of audio f@0: data output subclasses. f@0: f@0: Currently, WvOut is non-interpolating and the output rate is f@0: always Stk::sampleRate(). f@0: f@0: by Perry R. Cook and Gary P. Scavone, 1995--2014. f@0: */ f@0: /***************************************************/ f@0: f@0: class WvOut : public Stk f@0: { f@0: public: f@0: f@0: //! Default constructor. f@0: WvOut( void ) : frameCounter_(0), clipping_(false) {}; f@0: f@0: //! Return the number of sample frames output. f@0: unsigned long getFrameCount( void ) const { return frameCounter_; }; f@0: f@0: //! Return the number of seconds of data output. f@0: StkFloat getTime( void ) const { return (StkFloat) frameCounter_ / Stk::sampleRate(); }; f@0: f@0: //! Returns \c true if clipping has been detected during output since instantiation or the last reset. f@0: bool clipStatus( void ) { return clipping_; }; f@0: f@0: //! Reset the clipping status to \c false. f@0: void resetClipStatus( void ) { clipping_ = false; }; f@0: f@0: //! Output a single sample to all channels in a sample frame. f@0: /*! f@0: An StkError is thrown if an output error occurs. f@0: */ f@0: virtual void tick( const StkFloat sample ) = 0; f@0: f@0: //! Output the StkFrames data. f@0: virtual void tick( const StkFrames& frames ) = 0; f@0: f@0: protected: f@0: f@0: // Check for sample clipping and clamp. f@0: StkFloat& clipTest( StkFloat& sample ); f@0: f@0: StkFrames data_; f@0: unsigned long frameCounter_; f@0: bool clipping_; f@0: f@0: }; f@0: f@0: inline StkFloat& WvOut :: clipTest( StkFloat& sample ) f@0: { f@0: bool clip = false; f@0: if ( sample > 1.0 ) { f@0: sample = 1.0; f@0: clip = true; f@0: } f@0: else if ( sample < -1.0 ) { f@0: sample = -1.0; f@0: clip = true; f@0: } f@0: f@0: if ( clip == true && clipping_ == false ) { f@0: // First occurrence of clipping since instantiation or reset. f@0: clipping_ = true; f@0: oStream_ << "WvOut: data value(s) outside +-1.0 detected ... clamping at outer bound!"; f@0: handleError( StkError::WARNING ); f@0: } f@0: f@0: return sample; f@0: } f@0: f@0: } // stk namespace f@0: f@0: #endif