The JUCE cross-platform C++ framework, with DISTRHO/KXStudio specific changes
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.

320 lines
26KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2022 - Raw Material Software Limited
  5. JUCE is an open source library subject to commercial or open-source
  6. licensing.
  7. By using JUCE, you agree to the terms of both the JUCE 7 End-User License
  8. Agreement and JUCE Privacy Policy.
  9. End User License Agreement: www.juce.com/juce-7-licence
  10. Privacy Policy: www.juce.com/juce-privacy-policy
  11. Or: You may also use this code under the terms of the GPL v3 (see
  12. www.gnu.org/licenses).
  13. JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
  14. EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
  15. DISCLAIMED.
  16. ==============================================================================
  17. */
  18. namespace juce
  19. {
  20. //==============================================================================
  21. /**
  22. Reads and Writes WAV format audio files.
  23. @see AudioFormat
  24. @tags{Audio}
  25. */
  26. class JUCE_API WavAudioFormat : public AudioFormat
  27. {
  28. public:
  29. //==============================================================================
  30. /** Creates a format object. */
  31. WavAudioFormat();
  32. /** Destructor. */
  33. ~WavAudioFormat() override;
  34. //==============================================================================
  35. // BWAV chunk properties:
  36. static const char* const bwavDescription; /**< Metadata property name used in BWAV chunks. */
  37. static const char* const bwavOriginator; /**< Metadata property name used in BWAV chunks. */
  38. static const char* const bwavOriginatorRef; /**< Metadata property name used in BWAV chunks. */
  39. static const char* const bwavOriginationDate; /**< Metadata property name used in BWAV chunks. The format should be: yyyy-mm-dd */
  40. static const char* const bwavOriginationTime; /**< Metadata property name used in BWAV chunks. The format should be: format is: hh-mm-ss */
  41. static const char* const bwavCodingHistory; /**< Metadata property name used in BWAV chunks. */
  42. /** Metadata property name used in BWAV chunks.
  43. This is the number of samples from the start of an edit that the
  44. file is supposed to begin at. Seems like an obvious mistake to
  45. only allow a file to occur in an edit once, but that's the way
  46. it is..
  47. @see AudioFormatReader::metadataValues, createWriterFor
  48. */
  49. static const char* const bwavTimeReference;
  50. /** Utility function to fill out the appropriate metadata for a BWAV file.
  51. This just makes it easier than using the property names directly, and it
  52. fills out the time and date in the right format.
  53. */
  54. static StringPairArray createBWAVMetadata (const String& description,
  55. const String& originator,
  56. const String& originatorRef,
  57. Time dateAndTime,
  58. int64 timeReferenceSamples,
  59. const String& codingHistory);
  60. //==============================================================================
  61. // 'acid' chunk properties:
  62. static const char* const acidOneShot; /**< Metadata property name used in acid chunks. */
  63. static const char* const acidRootSet; /**< Metadata property name used in acid chunks. */
  64. static const char* const acidStretch; /**< Metadata property name used in acid chunks. */
  65. static const char* const acidDiskBased; /**< Metadata property name used in acid chunks. */
  66. static const char* const acidizerFlag; /**< Metadata property name used in acid chunks. */
  67. static const char* const acidRootNote; /**< Metadata property name used in acid chunks. */
  68. static const char* const acidBeats; /**< Metadata property name used in acid chunks. */
  69. static const char* const acidDenominator; /**< Metadata property name used in acid chunks. */
  70. static const char* const acidNumerator; /**< Metadata property name used in acid chunks. */
  71. static const char* const acidTempo; /**< Metadata property name used in acid chunks. */
  72. //==============================================================================
  73. // INFO chunk properties:
  74. static const char* const riffInfoArchivalLocation; /**< Metadata property name used in INFO chunks. */
  75. static const char* const riffInfoArtist; /**< Metadata property name used in INFO chunks. */
  76. static const char* const riffInfoBaseURL; /**< Metadata property name used in INFO chunks. */
  77. static const char* const riffInfoCinematographer; /**< Metadata property name used in INFO chunks. */
  78. static const char* const riffInfoComment; /**< Metadata property name used in INFO chunks. */
  79. static const char* const riffInfoComment2; /**< Metadata property name used in INFO chunks. */
  80. static const char* const riffInfoComments; /**< Metadata property name used in INFO chunks. */
  81. static const char* const riffInfoCommissioned; /**< Metadata property name used in INFO chunks. */
  82. static const char* const riffInfoCopyright; /**< Metadata property name used in INFO chunks. */
  83. static const char* const riffInfoCostumeDesigner; /**< Metadata property name used in INFO chunks. */
  84. static const char* const riffInfoCountry; /**< Metadata property name used in INFO chunks. */
  85. static const char* const riffInfoCropped; /**< Metadata property name used in INFO chunks. */
  86. static const char* const riffInfoDateCreated; /**< Metadata property name used in INFO chunks. */
  87. static const char* const riffInfoDateTimeOriginal; /**< Metadata property name used in INFO chunks. */
  88. static const char* const riffInfoDefaultAudioStream; /**< Metadata property name used in INFO chunks. */
  89. static const char* const riffInfoDimension; /**< Metadata property name used in INFO chunks. */
  90. static const char* const riffInfoDirectory; /**< Metadata property name used in INFO chunks. */
  91. static const char* const riffInfoDistributedBy; /**< Metadata property name used in INFO chunks. */
  92. static const char* const riffInfoDotsPerInch; /**< Metadata property name used in INFO chunks. */
  93. static const char* const riffInfoEditedBy; /**< Metadata property name used in INFO chunks. */
  94. static const char* const riffInfoEighthLanguage; /**< Metadata property name used in INFO chunks. */
  95. static const char* const riffInfoEncodedBy; /**< Metadata property name used in INFO chunks. */
  96. static const char* const riffInfoEndTimecode; /**< Metadata property name used in INFO chunks. */
  97. static const char* const riffInfoEngineer; /**< Metadata property name used in INFO chunks. */
  98. static const char* const riffInfoFifthLanguage; /**< Metadata property name used in INFO chunks. */
  99. static const char* const riffInfoFirstLanguage; /**< Metadata property name used in INFO chunks. */
  100. static const char* const riffInfoFourthLanguage; /**< Metadata property name used in INFO chunks. */
  101. static const char* const riffInfoGenre; /**< Metadata property name used in INFO chunks. */
  102. static const char* const riffInfoKeywords; /**< Metadata property name used in INFO chunks. */
  103. static const char* const riffInfoLanguage; /**< Metadata property name used in INFO chunks. */
  104. static const char* const riffInfoLength; /**< Metadata property name used in INFO chunks. */
  105. static const char* const riffInfoLightness; /**< Metadata property name used in INFO chunks. */
  106. static const char* const riffInfoLocation; /**< Metadata property name used in INFO chunks. */
  107. static const char* const riffInfoLogoIconURL; /**< Metadata property name used in INFO chunks. */
  108. static const char* const riffInfoLogoURL; /**< Metadata property name used in INFO chunks. */
  109. static const char* const riffInfoMedium; /**< Metadata property name used in INFO chunks. */
  110. static const char* const riffInfoMoreInfoBannerImage; /**< Metadata property name used in INFO chunks. */
  111. static const char* const riffInfoMoreInfoBannerURL; /**< Metadata property name used in INFO chunks. */
  112. static const char* const riffInfoMoreInfoText; /**< Metadata property name used in INFO chunks. */
  113. static const char* const riffInfoMoreInfoURL; /**< Metadata property name used in INFO chunks. */
  114. static const char* const riffInfoMusicBy; /**< Metadata property name used in INFO chunks. */
  115. static const char* const riffInfoNinthLanguage; /**< Metadata property name used in INFO chunks. */
  116. static const char* const riffInfoNumberOfParts; /**< Metadata property name used in INFO chunks. */
  117. static const char* const riffInfoOrganisation; /**< Metadata property name used in INFO chunks. */
  118. static const char* const riffInfoPart; /**< Metadata property name used in INFO chunks. */
  119. static const char* const riffInfoProducedBy; /**< Metadata property name used in INFO chunks. */
  120. static const char* const riffInfoProductName; /**< Metadata property name used in INFO chunks. */
  121. static const char* const riffInfoProductionDesigner; /**< Metadata property name used in INFO chunks. */
  122. static const char* const riffInfoProductionStudio; /**< Metadata property name used in INFO chunks. */
  123. static const char* const riffInfoRate; /**< Metadata property name used in INFO chunks. */
  124. static const char* const riffInfoRated; /**< Metadata property name used in INFO chunks. */
  125. static const char* const riffInfoRating; /**< Metadata property name used in INFO chunks. */
  126. static const char* const riffInfoRippedBy; /**< Metadata property name used in INFO chunks. */
  127. static const char* const riffInfoSecondaryGenre; /**< Metadata property name used in INFO chunks. */
  128. static const char* const riffInfoSecondLanguage; /**< Metadata property name used in INFO chunks. */
  129. static const char* const riffInfoSeventhLanguage; /**< Metadata property name used in INFO chunks. */
  130. static const char* const riffInfoSharpness; /**< Metadata property name used in INFO chunks. */
  131. static const char* const riffInfoSixthLanguage; /**< Metadata property name used in INFO chunks. */
  132. static const char* const riffInfoSoftware; /**< Metadata property name used in INFO chunks. */
  133. static const char* const riffInfoSoundSchemeTitle; /**< Metadata property name used in INFO chunks. */
  134. static const char* const riffInfoSource; /**< Metadata property name used in INFO chunks. */
  135. static const char* const riffInfoSourceFrom; /**< Metadata property name used in INFO chunks. */
  136. static const char* const riffInfoStarring_ISTR; /**< Metadata property name used in INFO chunks. */
  137. static const char* const riffInfoStarring_STAR; /**< Metadata property name used in INFO chunks. */
  138. static const char* const riffInfoStartTimecode; /**< Metadata property name used in INFO chunks. */
  139. static const char* const riffInfoStatistics; /**< Metadata property name used in INFO chunks. */
  140. static const char* const riffInfoSubject; /**< Metadata property name used in INFO chunks. */
  141. static const char* const riffInfoTapeName; /**< Metadata property name used in INFO chunks. */
  142. static const char* const riffInfoTechnician; /**< Metadata property name used in INFO chunks. */
  143. static const char* const riffInfoThirdLanguage; /**< Metadata property name used in INFO chunks. */
  144. static const char* const riffInfoTimeCode; /**< Metadata property name used in INFO chunks. */
  145. static const char* const riffInfoTitle; /**< Metadata property name used in INFO chunks. */
  146. static const char* const riffInfoTrackNo; /**< Metadata property name used in INFO chunks. */
  147. static const char* const riffInfoTrackNumber; /**< Metadata property name used in INFO chunks. */
  148. static const char* const riffInfoURL; /**< Metadata property name used in INFO chunks. */
  149. static const char* const riffInfoVegasVersionMajor; /**< Metadata property name used in INFO chunks. */
  150. static const char* const riffInfoVegasVersionMinor; /**< Metadata property name used in INFO chunks. */
  151. static const char* const riffInfoVersion; /**< Metadata property name used in INFO chunks. */
  152. static const char* const riffInfoWatermarkURL; /**< Metadata property name used in INFO chunks. */
  153. static const char* const riffInfoWrittenBy; /**< Metadata property name used in INFO chunks. */
  154. static const char* const riffInfoYear; /**< Metadata property name used in INFO chunks. */
  155. //==============================================================================
  156. // ASWG chunk properties:
  157. static const char* const aswgContentType; /**< Metadata property name used in ASWG/iXML chunks. */
  158. static const char* const aswgProject; /**< Metadata property name used in ASWG/iXML chunks. */
  159. static const char* const aswgOriginator; /**< Metadata property name used in ASWG/iXML chunks. */
  160. static const char* const aswgOriginatorStudio; /**< Metadata property name used in ASWG/iXML chunks. */
  161. static const char* const aswgNotes; /**< Metadata property name used in ASWG/iXML chunks. */
  162. static const char* const aswgSession; /**< Metadata property name used in ASWG/iXML chunks. */
  163. static const char* const aswgState; /**< Metadata property name used in ASWG/iXML chunks. */
  164. static const char* const aswgEditor; /**< Metadata property name used in ASWG/iXML chunks. */
  165. static const char* const aswgMixer; /**< Metadata property name used in ASWG/iXML chunks. */
  166. static const char* const aswgFxChainName; /**< Metadata property name used in ASWG/iXML chunks. */
  167. static const char* const aswgChannelConfig; /**< Metadata property name used in ASWG/iXML chunks. */
  168. static const char* const aswgAmbisonicFormat; /**< Metadata property name used in ASWG/iXML chunks. */
  169. static const char* const aswgAmbisonicChnOrder; /**< Metadata property name used in ASWG/iXML chunks. */
  170. static const char* const aswgAmbisonicNorm; /**< Metadata property name used in ASWG/iXML chunks. */
  171. static const char* const aswgMicType; /**< Metadata property name used in ASWG/iXML chunks. */
  172. static const char* const aswgMicConfig; /**< Metadata property name used in ASWG/iXML chunks. */
  173. static const char* const aswgMicDistance; /**< Metadata property name used in ASWG/iXML chunks. */
  174. static const char* const aswgRecordingLoc; /**< Metadata property name used in ASWG/iXML chunks. */
  175. static const char* const aswgIsDesigned; /**< Metadata property name used in ASWG/iXML chunks. */
  176. static const char* const aswgRecEngineer; /**< Metadata property name used in ASWG/iXML chunks. */
  177. static const char* const aswgRecStudio; /**< Metadata property name used in ASWG/iXML chunks. */
  178. static const char* const aswgImpulseLocation; /**< Metadata property name used in ASWG/iXML chunks. */
  179. static const char* const aswgCategory; /**< Metadata property name used in ASWG/iXML chunks. */
  180. static const char* const aswgSubCategory; /**< Metadata property name used in ASWG/iXML chunks. */
  181. static const char* const aswgCatId; /**< Metadata property name used in ASWG/iXML chunks. */
  182. static const char* const aswgUserCategory; /**< Metadata property name used in ASWG/iXML chunks. */
  183. static const char* const aswgUserData; /**< Metadata property name used in ASWG/iXML chunks. */
  184. static const char* const aswgVendorCategory; /**< Metadata property name used in ASWG/iXML chunks. */
  185. static const char* const aswgFxName; /**< Metadata property name used in ASWG/iXML chunks. */
  186. static const char* const aswgLibrary; /**< Metadata property name used in ASWG/iXML chunks. */
  187. static const char* const aswgCreatorId; /**< Metadata property name used in ASWG/iXML chunks. */
  188. static const char* const aswgSourceId; /**< Metadata property name used in ASWG/iXML chunks. */
  189. static const char* const aswgRmsPower; /**< Metadata property name used in ASWG/iXML chunks. */
  190. static const char* const aswgLoudness; /**< Metadata property name used in ASWG/iXML chunks. */
  191. static const char* const aswgLoudnessRange; /**< Metadata property name used in ASWG/iXML chunks. */
  192. static const char* const aswgMaxPeak; /**< Metadata property name used in ASWG/iXML chunks. */
  193. static const char* const aswgSpecDensity; /**< Metadata property name used in ASWG/iXML chunks. */
  194. static const char* const aswgZeroCrossRate; /**< Metadata property name used in ASWG/iXML chunks. */
  195. static const char* const aswgPapr; /**< Metadata property name used in ASWG/iXML chunks. */
  196. static const char* const aswgText; /**< Metadata property name used in ASWG/iXML chunks. */
  197. static const char* const aswgEfforts; /**< Metadata property name used in ASWG/iXML chunks. */
  198. static const char* const aswgEffortType; /**< Metadata property name used in ASWG/iXML chunks. */
  199. static const char* const aswgProjection; /**< Metadata property name used in ASWG/iXML chunks. */
  200. static const char* const aswgLanguage; /**< Metadata property name used in ASWG/iXML chunks. */
  201. static const char* const aswgTimingRestriction; /**< Metadata property name used in ASWG/iXML chunks. */
  202. static const char* const aswgCharacterName; /**< Metadata property name used in ASWG/iXML chunks. */
  203. static const char* const aswgCharacterGender; /**< Metadata property name used in ASWG/iXML chunks. */
  204. static const char* const aswgCharacterAge; /**< Metadata property name used in ASWG/iXML chunks. */
  205. static const char* const aswgCharacterRole; /**< Metadata property name used in ASWG/iXML chunks. */
  206. static const char* const aswgActorName; /**< Metadata property name used in ASWG/iXML chunks. */
  207. static const char* const aswgActorGender; /**< Metadata property name used in ASWG/iXML chunks. */
  208. static const char* const aswgDirector; /**< Metadata property name used in ASWG/iXML chunks. */
  209. static const char* const aswgDirection; /**< Metadata property name used in ASWG/iXML chunks. */
  210. static const char* const aswgFxUsed; /**< Metadata property name used in ASWG/iXML chunks. */
  211. static const char* const aswgUsageRights; /**< Metadata property name used in ASWG/iXML chunks. */
  212. static const char* const aswgIsUnion; /**< Metadata property name used in ASWG/iXML chunks. */
  213. static const char* const aswgAccent; /**< Metadata property name used in ASWG/iXML chunks. */
  214. static const char* const aswgEmotion; /**< Metadata property name used in ASWG/iXML chunks. */
  215. static const char* const aswgComposor; /**< Metadata property name used in ASWG/iXML chunks. */
  216. static const char* const aswgArtist; /**< Metadata property name used in ASWG/iXML chunks. */
  217. static const char* const aswgSongTitle; /**< Metadata property name used in ASWG/iXML chunks. */
  218. static const char* const aswgGenre; /**< Metadata property name used in ASWG/iXML chunks. */
  219. static const char* const aswgSubGenre; /**< Metadata property name used in ASWG/iXML chunks. */
  220. static const char* const aswgProducer; /**< Metadata property name used in ASWG/iXML chunks. */
  221. static const char* const aswgMusicSup; /**< Metadata property name used in ASWG/iXML chunks. */
  222. static const char* const aswgInstrument; /**< Metadata property name used in ASWG/iXML chunks. */
  223. static const char* const aswgMusicPublisher; /**< Metadata property name used in ASWG/iXML chunks. */
  224. static const char* const aswgRightsOwner; /**< Metadata property name used in ASWG/iXML chunks. */
  225. static const char* const aswgIsSource; /**< Metadata property name used in ASWG/iXML chunks. */
  226. static const char* const aswgIsLoop; /**< Metadata property name used in ASWG/iXML chunks. */
  227. static const char* const aswgIntensity; /**< Metadata property name used in ASWG/iXML chunks. */
  228. static const char* const aswgIsFinal; /**< Metadata property name used in ASWG/iXML chunks. */
  229. static const char* const aswgOrderRef; /**< Metadata property name used in ASWG/iXML chunks. */
  230. static const char* const aswgIsOst; /**< Metadata property name used in ASWG/iXML chunks. */
  231. static const char* const aswgIsCinematic; /**< Metadata property name used in ASWG/iXML chunks. */
  232. static const char* const aswgIsLicensed; /**< Metadata property name used in ASWG/iXML chunks. */
  233. static const char* const aswgIsDiegetic; /**< Metadata property name used in ASWG/iXML chunks. */
  234. static const char* const aswgMusicVersion; /**< Metadata property name used in ASWG/iXML chunks. */
  235. static const char* const aswgIsrcId; /**< Metadata property name used in ASWG/iXML chunks. */
  236. static const char* const aswgTempo; /**< Metadata property name used in ASWG/iXML chunks. */
  237. static const char* const aswgTimeSig; /**< Metadata property name used in ASWG/iXML chunks. */
  238. static const char* const aswgInKey; /**< Metadata property name used in ASWG/iXML chunks. */
  239. static const char* const aswgBillingCode; /**< Metadata property name used in ASWG/iXML chunks. */
  240. static const char* const aswgVersion; /**< Metadata property name used in ASWG/iXML chunks. */
  241. //==============================================================================
  242. /** Metadata property name used when reading an ISRC code from an AXML chunk. */
  243. [[deprecated ("This string is identical to riffInfoSource, making it impossible to differentiate between the two")]]
  244. static const char* const ISRC;
  245. /** Metadata property name used when reading and writing ISRC codes to/from AXML chunks. */
  246. static const char* const internationalStandardRecordingCode;
  247. /** Metadata property name used when reading a WAV file with a Tracktion chunk. */
  248. static const char* const tracktionLoopInfo;
  249. //==============================================================================
  250. Array<int> getPossibleSampleRates() override;
  251. Array<int> getPossibleBitDepths() override;
  252. bool canDoStereo() override;
  253. bool canDoMono() override;
  254. bool isChannelLayoutSupported (const AudioChannelSet& channelSet) override;
  255. //==============================================================================
  256. AudioFormatReader* createReaderFor (InputStream* sourceStream,
  257. bool deleteStreamIfOpeningFails) override;
  258. MemoryMappedAudioFormatReader* createMemoryMappedReader (const File&) override;
  259. MemoryMappedAudioFormatReader* createMemoryMappedReader (FileInputStream*) override;
  260. AudioFormatWriter* createWriterFor (OutputStream* streamToWriteTo,
  261. double sampleRateToUse,
  262. unsigned int numberOfChannels,
  263. int bitsPerSample,
  264. const StringPairArray& metadataValues,
  265. int qualityOptionIndex) override;
  266. AudioFormatWriter* createWriterFor (OutputStream* streamToWriteTo,
  267. double sampleRateToUse,
  268. const AudioChannelSet& channelLayout,
  269. int bitsPerSample,
  270. const StringPairArray& metadataValues,
  271. int qualityOptionIndex) override;
  272. using AudioFormat::createWriterFor;
  273. //==============================================================================
  274. /** Utility function to replace the metadata in a wav file with a new set of values.
  275. If possible, this cheats by overwriting just the metadata region of the file, rather
  276. than by copying the whole file again.
  277. */
  278. bool replaceMetadataInFile (const File& wavFile, const StringPairArray& newMetadata);
  279. private:
  280. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (WavAudioFormat)
  281. };
  282. } // namespace juce