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.

114 lines
4.8KB

  1. /*
  2. ==============================================================================
  3. This file is part of the dRowAudio JUCE module
  4. Copyright 2004-13 by dRowAudio.
  5. ------------------------------------------------------------------------------
  6. dRowAudio is provided under the terms of The MIT License (MIT):
  7. Permission is hereby granted, free of charge, to any person obtaining a copy
  8. of this software and associated documentation files (the "Software"), to deal
  9. in the Software without restriction, including without limitation the rights
  10. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  11. copies of the Software, and to permit persons to whom the Software is
  12. furnished to do so, subject to the following conditions:
  13. The above copyright notice and this permission notice shall be included in all
  14. copies or substantial portions of the Software.
  15. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  18. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  20. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  21. SOFTWARE.
  22. ==============================================================================
  23. */
  24. #ifndef __DROWAUDIO_AVASSETAUDIOFORMAT_H__
  25. #define __DROWAUDIO_AVASSETAUDIOFORMAT_H__
  26. #if JUCE_IOS || DOXYGEN
  27. //==============================================================================
  28. /**
  29. OSX and iOS only - This uses the AVFoundation framework to read any audio
  30. format that the system has a codec for.
  31. This should be able to understand formats such as mp3, m4a, etc.
  32. Because the underlying AVFoundation framework buffers the reading of the
  33. audio on a background thread already, it shouldn't be necessarry to use your
  34. own BufferingAudioSource (unless of course you need to). The other
  35. side-affect this has is that there can be a slight delay when changing the
  36. track's position. If you need instant acces try looking at the
  37. IOSAudioConverter class.
  38. The easiest way to use this is in conjunction with an AudioPicker.
  39. @code
  40. void MyClass::audioPickerFinished (const Array<void*> mpMediaItems)
  41. {
  42. const String url (AudioPicker::mpMediaItemToAvassetUrl (mpMediaItems[0]));
  43. AVAssetAudioFormat* reader = aVAssetAudioFormat
  44. .createReaderFor (AVAssetAudioFormat::avAssetUrlStringToStream (url);
  45. }
  46. @endcode
  47. @see AudioFormat, AudioPicker, IOSAudioConverter
  48. */
  49. class AVAssetAudioFormat : public AudioFormat
  50. {
  51. public:
  52. //==============================================================================
  53. /** Creates a format object. */
  54. AVAssetAudioFormat();
  55. /** Destructor. */
  56. ~AVAssetAudioFormat();
  57. //==============================================================================
  58. /** Converts an AVAssetURL String to a MemoryInputStream ready to pass to
  59. createReaderFor().
  60. Because we need a common interface to create the AudioFormatReader this
  61. helper method converts an AVAssetURL encoded as a String (such as that
  62. returned by an AudioPicker::mpMediaItemToAvassetUrl) to an InputStream.
  63. The caller is responsible for deleting the stream but this is usually taken
  64. care of by the createReaderFor method.
  65. @see AudioPicker
  66. */
  67. static MemoryInputStream* avAssetUrlStringToStream (const String& avAssetUrlString);
  68. //==============================================================================
  69. Array<int> getPossibleSampleRates();
  70. Array<int> getPossibleBitDepths();
  71. bool canDoStereo();
  72. bool canDoMono();
  73. //==============================================================================
  74. AudioFormatReader* createReaderFor (String assetNSURLAsString);
  75. AudioFormatReader* createReaderFor (InputStream* sourceStream,
  76. bool deleteStreamIfOpeningFails);
  77. AudioFormatWriter* createWriterFor (OutputStream* streamToWriteTo,
  78. double sampleRateToUse,
  79. unsigned int numberOfChannels,
  80. int bitsPerSample,
  81. const StringPairArray& metadataValues,
  82. int qualityOptionIndex);
  83. private:
  84. //==============================================================================
  85. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (AVAssetAudioFormat);
  86. };
  87. #endif
  88. #endif // __DROWAUDIO_AVASSETAUDIOFORMAT_H__