diff --git a/modules/juce_audio_formats/codecs/juce_CoreAudioFormat.cpp b/modules/juce_audio_formats/codecs/juce_CoreAudioFormat.cpp index 950f922f97..5d0c2785ac 100644 --- a/modules/juce_audio_formats/codecs/juce_CoreAudioFormat.cpp +++ b/modules/juce_audio_formats/codecs/juce_CoreAudioFormat.cpp @@ -340,7 +340,10 @@ struct CoreAudioFormatMetatdata class CoreAudioReader : public AudioFormatReader { public: - CoreAudioReader (InputStream* inp) : AudioFormatReader (inp, coreAudioFormatName) + using StreamKind = CoreAudioFormat::StreamKind; + + CoreAudioReader (InputStream* inp, StreamKind streamKind) + : AudioFormatReader (inp, coreAudioFormatName) { usesFloatingPointData = true; bitsPerSample = 32; @@ -353,7 +356,7 @@ public: nullptr, // write needs to be null to avoid permissions errors &getSizeCallback, nullptr, // setSize needs to be null to avoid permissions errors - 0, // AudioFileTypeID inFileTypeHint + toAudioFileTypeID (streamKind), &audioFileID); if (status == noErr) { @@ -556,16 +559,50 @@ private: return noErr; } + static AudioFileTypeID toAudioFileTypeID (StreamKind kind) + { + switch (kind) + { + case StreamKind::kAiff: return kAudioFileAIFFType; + case StreamKind::kAifc: return kAudioFileAIFCType; + case StreamKind::kWave: return kAudioFileWAVEType; + case StreamKind::kSoundDesigner2: return kAudioFileSoundDesigner2Type; + case StreamKind::kNext: return kAudioFileNextType; + case StreamKind::kMp3: return kAudioFileMP3Type; + case StreamKind::kMp2: return kAudioFileMP2Type; + case StreamKind::kMp1: return kAudioFileMP1Type; + case StreamKind::kAc3: return kAudioFileAC3Type; + case StreamKind::kAacAdts: return kAudioFileAAC_ADTSType; + case StreamKind::kMpeg4: return kAudioFileMPEG4Type; + case StreamKind::kM4a: return kAudioFileM4AType; + case StreamKind::kM4b: return kAudioFileM4BType; + case StreamKind::kCaf: return kAudioFileCAFType; + case StreamKind::k3gp: return kAudioFile3GPType; + case StreamKind::k3gp2: return kAudioFile3GP2Type; + case StreamKind::kAmr: return kAudioFileAMRType; + + case StreamKind::kNone: break; + } + + return {}; + } + JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (CoreAudioReader) }; //============================================================================== CoreAudioFormat::CoreAudioFormat() - : AudioFormat (coreAudioFormatName, findFileExtensionsForCoreAudioCodecs()) + : CoreAudioFormat (StreamKind::kNone) +{ +} + +CoreAudioFormat::CoreAudioFormat (StreamKind kind) + : AudioFormat (coreAudioFormatName, findFileExtensionsForCoreAudioCodecs()), + streamKind (kind) { } -CoreAudioFormat::~CoreAudioFormat() {} +CoreAudioFormat::~CoreAudioFormat() = default; Array CoreAudioFormat::getPossibleSampleRates() { return {}; } Array CoreAudioFormat::getPossibleBitDepths() { return {}; } @@ -577,7 +614,7 @@ bool CoreAudioFormat::canDoMono() { return true; } AudioFormatReader* CoreAudioFormat::createReaderFor (InputStream* sourceStream, bool deleteStreamIfOpeningFails) { - std::unique_ptr r (new CoreAudioReader (sourceStream)); + std::unique_ptr r (new CoreAudioReader (sourceStream, streamKind)); if (r->ok) return r.release(); diff --git a/modules/juce_audio_formats/codecs/juce_CoreAudioFormat.h b/modules/juce_audio_formats/codecs/juce_CoreAudioFormat.h index 12db618f0a..60c9e54a9b 100644 --- a/modules/juce_audio_formats/codecs/juce_CoreAudioFormat.h +++ b/modules/juce_audio_formats/codecs/juce_CoreAudioFormat.h @@ -42,10 +42,38 @@ namespace juce class JUCE_API CoreAudioFormat : public AudioFormat { public: + /** File type hints. */ + enum class StreamKind + { + kNone, + kAiff, + kAifc, + kWave, + kSoundDesigner2, + kNext, + kMp3, + kMp2, + kMp1, + kAc3, + kAacAdts, + kMpeg4, + kM4a, + kM4b, + kCaf, + k3gp, + k3gp2, + kAmr, + }; + //============================================================================== /** Creates a format object. */ CoreAudioFormat(); + /** Creates a format object and provides a hint as to the format of data + to be read or written. + */ + explicit CoreAudioFormat (StreamKind); + /** Destructor. */ ~CoreAudioFormat() override; @@ -78,6 +106,8 @@ public: using AudioFormat::createWriterFor; private: + StreamKind streamKind = StreamKind::kNone; + JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (CoreAudioFormat) };