You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

86 lines
2.1KB

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