Pd++  0.01
A pure C++ implementation of Pure Data objects
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
FileWrite.h
1 #ifndef STK_FILEWRITE_H
2 #define STK_FILEWRITE_H
3 
4 #include "Stk.h"
5 
6 namespace stk {
7 
8 /***************************************************/
9 /*! \class FileWrite
10  \brief STK audio file output class.
11 
12  This class provides output support for various
13  audio file formats.
14 
15  FileWrite writes samples to an audio file. It supports
16  multi-channel data.
17 
18  FileWrite currently supports uncompressed WAV, AIFF, AIFC, SND
19  (AU), MAT-file (Matlab), and STK RAW file formats. Signed integer
20  (8-, 16-, 24-, and 32-bit) and floating- point (32- and 64-bit)
21  data types are supported. STK RAW files use 16-bit integers by
22  definition. MAT-files will always be written as 64-bit floats.
23  If a data type specification does not match the specified file
24  type, the data type will automatically be modified. Compressed
25  data types are not supported.
26 
27  by Perry R. Cook and Gary P. Scavone, 1995--2014.
28 */
29 /***************************************************/
30 
31 class FileWrite : public Stk
32 {
33  public:
34 
35  typedef unsigned long FILE_TYPE;
36 
37  static const FILE_TYPE FILE_RAW; /*!< STK RAW file type. */
38  static const FILE_TYPE FILE_WAV; /*!< WAV file type. */
39  static const FILE_TYPE FILE_SND; /*!< SND (AU) file type. */
40  static const FILE_TYPE FILE_AIF; /*!< AIFF file type. */
41  static const FILE_TYPE FILE_MAT; /*!< Matlab MAT-file type. */
42 
43  //! Default constructor.
44  FileWrite( void );
45 
46  //! Overloaded constructor used to specify a file name, type, and data format with this object.
47  /*!
48  An StkError is thrown for invalid argument values or if an error occurs when initializing the output file.
49  */
50  FileWrite( std::string fileName, unsigned int nChannels = 1, FILE_TYPE type = FILE_WAV, Stk::StkFormat format = STK_SINT16 );
51 
52  //! Class destructor.
53  virtual ~FileWrite();
54 
55  //! Create a file of the specified type and name and output samples to it in the given data format.
56  /*!
57  An StkError is thrown for invalid argument values or if an error occurs when initializing the output file.
58  */
59  void open( std::string fileName, unsigned int nChannels = 1,
60  FileWrite::FILE_TYPE type = FILE_WAV, Stk::StkFormat format = STK_SINT16 );
61 
62  //! If a file is open, write out samples in the queue and then close it.
63  void close( void );
64 
65  //! Returns \e true if a file is currently open.
66  bool isOpen( void );
67 
68  //! Write sample frames from the StkFrames object to the file.
69  /*!
70  An StkError will be thrown if the number of channels in the
71  StkFrames argument does not agree with the number of channels
72  specified when opening the file.
73  */
74  void write( StkFrames& buffer );
75 
76  protected:
77 
78  // Write STK RAW file header.
79  bool setRawFile( std::string fileName );
80 
81  // Write WAV file header.
82  bool setWavFile( std::string fileName );
83 
84  // Close WAV file, updating the header.
85  void closeWavFile( void );
86 
87  // Write SND (AU) file header.
88  bool setSndFile( std::string fileName );
89 
90  // Close SND file, updating the header.
91  void closeSndFile( void );
92 
93  // Write AIFF file header.
94  bool setAifFile( std::string fileName );
95 
96  // Close AIFF file, updating the header.
97  void closeAifFile( void );
98 
99  // Write MAT-file header.
100  bool setMatFile( std::string fileName );
101 
102  // Close MAT-file, updating the header.
103  void closeMatFile( void );
104 
105  FILE *fd_;
106  FILE_TYPE fileType_;
107  StkFormat dataType_;
108  unsigned int channels_;
109  unsigned long frameCounter_;
110  bool byteswap_;
111 
112 };
113 
114 } // stk namespace
115 
116 #endif
STK audio file output class.
Definition: FileWrite.h:31
static const FILE_TYPE FILE_MAT
Definition: FileWrite.h:41
virtual ~FileWrite()
Class destructor.
Definition: FileWrite.cpp:114
The STK namespace.
Definition: FileRead.cpp:41
static const FILE_TYPE FILE_RAW
Definition: FileWrite.h:37
void open(std::string fileName, unsigned int nChannels=1, FileWrite::FILE_TYPE type=FILE_WAV, Stk::StkFormat format=STK_SINT16)
Create a file of the specified type and name and output samples to it in the given data format...
Definition: FileWrite.cpp:143
bool isOpen(void)
Returns true if a file is currently open.
Definition: FileWrite.cpp:137
void close(void)
If a file is open, write out samples in the queue and then close it.
Definition: FileWrite.cpp:119
An STK class to handle vectorized audio data.
Definition: Stk.h:272
STK base class.
Definition: Stk.h:132
void write(StkFrames &buffer)
Write sample frames from the StkFrames object to the file.
Definition: FileWrite.cpp:712
FileWrite(void)
Default constructor.
Definition: FileWrite.cpp:103
static const StkFormat STK_SINT16
Definition: Stk.h:138
static const FILE_TYPE FILE_AIF
Definition: FileWrite.h:40
static const FILE_TYPE FILE_WAV
Definition: FileWrite.h:38
static const FILE_TYPE FILE_SND
Definition: FileWrite.h:39