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.

117 lines
3.4KB

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