1 #ifndef STK_FILEWVOUT_H
2 #define STK_FILEWVOUT_H
3 
4 #include "WvOut.h"
5 #include "FileWrite.h"
6 
7 namespace stk {
8 
9 /***************************************************/
10 /*! \class FileWvOut
11     \brief STK audio file output class.
12 
13     This class inherits from WvOut.  It provides a "tick-level"
14     interface to the FileWrite class.
15 
16     FileWvOut writes samples to an audio file and supports
17     multi-channel data.  It is important to distinguish the tick()
18     method that outputs a single sample to all channels in a sample
19     frame from the overloaded one that takes a reference to an
20     StkFrames object for multi-channel and/or multi-frame data.
21 
22     See the FileWrite class for a description of the supported audio
23     file formats.
24 
25     Currently, FileWvOut is non-interpolating and the output rate is
26     always Stk::sampleRate().
27 
28     by Perry R. Cook and Gary P. Scavone, 1995--2021.
29 */
30 /***************************************************/
31 
32 class FileWvOut : public WvOut
33 {
34  public:
35 
36   //! Default constructor with optional output buffer size argument.
37   /*!
38     The output buffer size defines the number of frames that are
39     accumulated between writes to disk.
40   */
41   FileWvOut( unsigned int bufferFrames = 1024 );
42 
43   //! Overloaded constructor used to specify a file name, type, and data format with this object.
44   /*!
45     An StkError is thrown for invalid argument values or if an error occurs when initializing the output file.
46   */
47   FileWvOut( std::string fileName,
48              unsigned int nChannels = 1,
49              FileWrite::FILE_TYPE type = FileWrite::FILE_WAV,
50              Stk::StkFormat format = STK_SINT16,
51              unsigned int bufferFrames = 1024 );
52 
53   //! Class destructor.
54   virtual ~FileWvOut();
55 
56   //! Open a new file with the specified parameters.
57   /*!
58     If a file was previously open, it will be closed.  An StkError
59     will be thrown if any of the specified arguments are invalid or a
60     file error occurs during opening.
61   */
62   void openFile( std::string fileName,
63                  unsigned int nChannels,
64                  FileWrite::FILE_TYPE type,
65                  Stk::StkFormat format );
66 
67   //! Close a file if one is open.
68   /*!
69     Any data remaining in the internal buffer will be written to
70     the file before closing.
71   */
72   void closeFile( void );
73 
74   //! Output a single sample to all channels in a sample frame.
75   /*!
76     An StkError is thrown if an output error occurs.
77   */
78   void tick( const StkFloat sample );
79 
80   //! Output the StkFrames data.
81   /*!
82     An StkError will be thrown if an output error occurs.  An
83     StkError will also be thrown if _STK_DEBUG_ is defined during
84     compilation and there is an incompatability between the number of
85     channels in the FileWvOut object and that in the StkFrames object.
86   */
87   void tick( const StkFrames& frames );
88 
89  protected:
90 
91   void incrementFrame( void );
92 
93   FileWrite file_;
94   unsigned int bufferFrames_;
95   unsigned int bufferIndex_;
96   unsigned int iData_;
97 
98 };
99 
100 } // stk namespace
101 
102 #endif
103