Audio plugin host https://kx.studio/carla
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.

135 lines
5.4KB

  1. /*
  2. ==============================================================================
  3. This file is part of the Water library.
  4. Copyright (c) 2015 ROLI Ltd.
  5. Copyright (C) 2018 Filipe Coelho <falktx@falktx.com>
  6. Permission is granted to use this software under the terms of either:
  7. a) the GPL v2 (or any later version)
  8. b) the Affero GPL v3
  9. Details of these licenses can be found at: www.gnu.org/licenses
  10. Water is distributed in the hope that it will be useful, but WITHOUT ANY
  11. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  12. A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  13. ==============================================================================
  14. */
  15. #ifndef WATER_AUDIOFORMAT_H_INCLUDED
  16. #define WATER_AUDIOFORMAT_H_INCLUDED
  17. #include "../text/StringArray.h"
  18. namespace water {
  19. //==============================================================================
  20. /**
  21. Subclasses of AudioFormat are used to read and write different audio
  22. file formats.
  23. @see AudioFormatReader, AudioFormatWriter, WavAudioFormat, AiffAudioFormat
  24. */
  25. class AudioFormat
  26. {
  27. public:
  28. //==============================================================================
  29. /** Destructor. */
  30. virtual ~AudioFormat();
  31. //==============================================================================
  32. /** Returns the name of this format.
  33. e.g. "WAV file" or "AIFF file"
  34. */
  35. const String& getFormatName() const;
  36. /** Returns all the file extensions that might apply to a file of this format.
  37. The first item will be the one that's preferred when creating a new file.
  38. So for a wav file this might just return ".wav"; for an AIFF file it might
  39. return two items, ".aif" and ".aiff"
  40. */
  41. const StringArray& getFileExtensions() const;
  42. //==============================================================================
  43. /** Returns true if this the given file can be read by this format.
  44. Subclasses shouldn't do too much work here, just check the extension or
  45. file type. The base class implementation just checks the file's extension
  46. against one of the ones that was registered in the constructor.
  47. */
  48. virtual bool canHandleFile (const File& fileToTest);
  49. /** Returns a set of sample rates that the format can read and write. */
  50. virtual Array<int> getPossibleSampleRates() = 0;
  51. /** Returns a set of bit depths that the format can read and write. */
  52. virtual Array<int> getPossibleBitDepths() = 0;
  53. /** Returns true if the format can do 2-channel audio. */
  54. virtual bool canDoStereo() = 0;
  55. /** Returns true if the format can do 1-channel audio. */
  56. virtual bool canDoMono() = 0;
  57. /** Returns true if the format uses compressed data. */
  58. virtual bool isCompressed();
  59. /** Returns a list of different qualities that can be used when writing.
  60. Non-compressed formats will just return an empty array, but for something
  61. like Ogg-Vorbis or MP3, it might return a list of bit-rates, etc.
  62. When calling createWriterFor(), an index from this array is passed in to
  63. tell the format which option is required.
  64. */
  65. virtual StringArray getQualityOptions();
  66. //==============================================================================
  67. /** Tries to create an object that can read from a stream containing audio
  68. data in this format.
  69. The reader object that is returned can be used to read from the stream, and
  70. should then be deleted by the caller.
  71. @param sourceStream the stream to read from - the AudioFormatReader object
  72. that is returned will delete this stream when it no longer
  73. needs it.
  74. @param deleteStreamIfOpeningFails if no reader can be created, this determines whether this method
  75. should delete the stream object that was passed-in. (If a valid
  76. reader is returned, it will always be in charge of deleting the
  77. stream, so this parameter is ignored)
  78. @see AudioFormatReader
  79. */
  80. virtual AudioFormatReader* createReaderFor (InputStream* sourceStream,
  81. bool deleteStreamIfOpeningFails) = 0;
  82. protected:
  83. /** Creates an AudioFormat object.
  84. @param formatName this sets the value that will be returned by getFormatName()
  85. @param fileExtensions an array of file extensions - these will be returned by getFileExtensions()
  86. */
  87. AudioFormat (String formatName, StringArray fileExtensions);
  88. /** Creates an AudioFormat object.
  89. @param formatName this sets the value that will be returned by getFormatName()
  90. @param fileExtensions a whitespace-separated list of file extensions - these will
  91. be returned by getFileExtensions()
  92. */
  93. AudioFormat (StringRef formatName, StringRef fileExtensions);
  94. private:
  95. //==============================================================================
  96. String formatName;
  97. StringArray fileExtensions;
  98. };
  99. }
  100. #endif // WATER_AUDIOFORMAT_H_INCLUDED