mirror of
https://github.com/thestk/stk
synced 2026-02-07 09:46:16 +00:00
Version 4.4.0
This commit is contained in:
committed by
Stephen Sinclair
parent
d199342e86
commit
eccd8c9981
@@ -1,3 +1,10 @@
|
||||
#ifndef STK_WVOUT_H
|
||||
#define STK_WVOUT_H
|
||||
|
||||
#include "Stk.h"
|
||||
|
||||
namespace stk {
|
||||
|
||||
/***************************************************/
|
||||
/*! \class WvOut
|
||||
\brief STK audio output abstract base class.
|
||||
@@ -5,42 +12,25 @@
|
||||
This class provides common functionality for a variety of audio
|
||||
data output subclasses.
|
||||
|
||||
WvOut supports multi-channel data. It is important to distinguish
|
||||
the tick() methods, which output single samples to all channels in
|
||||
a sample frame, from the tickFrame() methods, which take a pointer
|
||||
or reference to multi-channel sample frame data.
|
||||
|
||||
Both interleaved and non-interleaved data is supported via the use
|
||||
of StkFrames objects.
|
||||
|
||||
Currently, WvOut is non-interpolating and the output rate is
|
||||
always Stk::sampleRate().
|
||||
|
||||
by Perry R. Cook and Gary P. Scavone, 1995 - 2007.
|
||||
by Perry R. Cook and Gary P. Scavone, 1995 - 2009.
|
||||
*/
|
||||
/***************************************************/
|
||||
|
||||
#ifndef STK_WVOUT_H
|
||||
#define STK_WVOUT_H
|
||||
|
||||
#include "Stk.h"
|
||||
#include <vector>
|
||||
|
||||
class WvOut : public Stk
|
||||
{
|
||||
public:
|
||||
|
||||
//! Default constructor.
|
||||
WvOut();
|
||||
|
||||
//! Class destructor.
|
||||
virtual ~WvOut();
|
||||
WvOut( void ) : frameCounter_(0), clipping_(false) {};
|
||||
|
||||
//! Return the number of sample frames output.
|
||||
unsigned long getFrameCount( void ) const;
|
||||
unsigned long getFrameCount( void ) const { return frameCounter_; };
|
||||
|
||||
//! Return the number of seconds of data output.
|
||||
StkFloat getTime( void ) const;
|
||||
StkFloat getTime( void ) const { return (StkFloat) frameCounter_ / Stk::sampleRate(); };
|
||||
|
||||
//! Returns \c true if clipping has been detected during output since instantiation or the last reset.
|
||||
bool clipStatus( void ) { return clipping_; };
|
||||
@@ -52,34 +42,10 @@ class WvOut : public Stk
|
||||
/*!
|
||||
An StkError is thrown if an output error occurs.
|
||||
*/
|
||||
void tick( const StkFloat sample );
|
||||
|
||||
//! Output a channel of the StkFrames object to all channels of the WvOut object.
|
||||
/*!
|
||||
The \c channel argument should be 0 or greater (the first
|
||||
channel is specified by 0). An StkError will be thrown if an
|
||||
output error occurs or if the \c channel argument is equal to or
|
||||
greater than the number of channels in the StkFrames object.
|
||||
*/
|
||||
void tick( const StkFrames& frames, unsigned int channel = 0 );
|
||||
|
||||
//! Output the StkFrames data.
|
||||
/*!
|
||||
An StkError will be thrown if an output error occurs or if
|
||||
there is an incompatability between the number of channels in the
|
||||
WvOut object and that in the StkFrames object.
|
||||
*/
|
||||
void tickFrame( const StkFrames& frames );
|
||||
virtual void tick( const StkFloat sample ) = 0;
|
||||
|
||||
protected:
|
||||
|
||||
// These abstract functions must be implemented in all subclasses.
|
||||
// They are used to get around a C++ problem with overloaded virtual
|
||||
// functions.
|
||||
virtual void computeSample( const StkFloat sample ) = 0;
|
||||
|
||||
virtual void computeFrames( const StkFrames& frames ) = 0;
|
||||
|
||||
// Check for sample clipping and clamp.
|
||||
StkFloat& clipTest( StkFloat& sample );
|
||||
|
||||
@@ -89,4 +55,28 @@ class WvOut : public Stk
|
||||
|
||||
};
|
||||
|
||||
inline StkFloat& WvOut :: clipTest( StkFloat& sample )
|
||||
{
|
||||
bool clip = false;
|
||||
if ( sample > 1.0 ) {
|
||||
sample = 1.0;
|
||||
clip = true;
|
||||
}
|
||||
else if ( sample < -1.0 ) {
|
||||
sample = -1.0;
|
||||
clip = true;
|
||||
}
|
||||
|
||||
if ( clip == true && clipping_ == false ) {
|
||||
// First occurrence of clipping since instantiation or reset.
|
||||
clipping_ = true;
|
||||
errorString_ << "WvOut: data value(s) outside +-1.0 detected ... clamping at outer bound!";
|
||||
handleError( StkError::WARNING );
|
||||
}
|
||||
|
||||
return sample;
|
||||
}
|
||||
|
||||
} // stk namespace
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user