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.

103 lines
2.9KB

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