mirror of
https://github.com/juce-framework/JUCE.git
synced 2026-01-10 23:44:24 +00:00
CoreAudioFormat: Allow specifying stream kind hints
This commit is contained in:
parent
8bacf8c15c
commit
a62d4c6a5a
2 changed files with 72 additions and 5 deletions
|
|
@ -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() {}
|
||||
CoreAudioFormat::CoreAudioFormat (StreamKind kind)
|
||||
: AudioFormat (coreAudioFormatName, findFileExtensionsForCoreAudioCodecs()),
|
||||
streamKind (kind)
|
||||
{
|
||||
}
|
||||
|
||||
CoreAudioFormat::~CoreAudioFormat() = default;
|
||||
|
||||
Array<int> CoreAudioFormat::getPossibleSampleRates() { return {}; }
|
||||
Array<int> CoreAudioFormat::getPossibleBitDepths() { return {}; }
|
||||
|
|
@ -577,7 +614,7 @@ bool CoreAudioFormat::canDoMono() { return true; }
|
|||
AudioFormatReader* CoreAudioFormat::createReaderFor (InputStream* sourceStream,
|
||||
bool deleteStreamIfOpeningFails)
|
||||
{
|
||||
std::unique_ptr<CoreAudioReader> r (new CoreAudioReader (sourceStream));
|
||||
std::unique_ptr<CoreAudioReader> r (new CoreAudioReader (sourceStream, streamKind));
|
||||
|
||||
if (r->ok)
|
||||
return r.release();
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue