1 /***************************************************/
2 /*! \class WvIn
3     \brief STK audio input abstract base class.
4 
5     This class provides common functionality for a variety of audio
6     data input subclasses.
7 
8     WvIn supports multi-channel data.  It is important to distinguish
9     the tick() methods, which return samples produced by averaging
10     across sample frames, from the tickFrame() methods, which return
11     references or pointers to multi-channel sample frames.
12 
13     Both interleaved and non-interleaved data is supported via the use
14     of StkFrames objects.
15 
16     by Perry R. Cook and Gary P. Scavone, 1995 - 2005.
17 */
18 /***************************************************/
19 
20 #ifndef STK_WVIN_H
21 #define STK_WVIN_H
22 
23 #include "Stk.h"
24 #include <vector>
25 
26 namespace Nyq
27 {
28 
29 class WvIn : public Stk
30 {
31 public:
32   //! Default constructor.
33   WvIn();
34 
35   //! Class destructor.
36   virtual ~WvIn();
37 
38   //! Return the number of audio channels in the data.
getChannels(void)39   unsigned int getChannels( void ) const { return data_.channels(); };
40 
41   //! Return the average across the last output sample frame.
42   /*!
43     If no file data is loaded, the returned value is 0.0.
44   */
45   StkFloat lastOut( void ) const;
46 
47   //! Return an StkFrames reference to the last output sample frame.
48   /*!
49     If no file data is loaded, an empty container is returned.
50    */
lastFrame(void)51   const StkFrames& lastFrame( void ) const { return lastOutputs_; };
52 
53   //! Read out the average across one sample frame of data.
54   /*!
55     If no file data is loaded, the returned value is 0.0.
56   */
57   StkFloat tick( void );
58 
59   //! Fill a channel of the StkFrames object with averaged sample frames.
60   /*!
61     The \c channel argument should be zero or greater (the first
62     channel is specified by 0).  An StkError will be thrown if the \c
63     channel argument is greater than or equal to the number of
64     channels in the StkFrames object.  If no file data is loaded, the
65     container is filled with zeroes.
66   */
67   StkFrames& tick( StkFrames& frames, unsigned int channel = 0 );
68 
69   //! Fill the StkFrames argument with data and return the same reference.
70   /*!
71     An StkError will be thrown if there is an incompatability
72     between the number of channels in the loaded data and that in the
73     StkFrames argument.  If no file data is loaded, the container is
74     filled with zeroes.
75   */
76   StkFrames& tickFrame( StkFrames& frames );
77 
78 protected:
79 
80   // This abstract function must be implemented in all subclasses.
81   // It is used to get around a C++ problem with overloaded virtual
82   // functions.
83   virtual void computeFrame( void ) = 0;
84 
85   StkFrames data_;
86   StkFrames lastOutputs_;
87 
88 };
89 
90 } // namespace Nyq
91 
92 #endif
93