mirror of
https://github.com/juce-framework/JUCE.git
synced 2026-01-10 23:44:24 +00:00
Some tidying up in the audio codec classes
This commit is contained in:
parent
f9d5f0eff5
commit
6344cd549a
8 changed files with 432 additions and 509 deletions
|
|
@ -104,7 +104,7 @@ namespace AiffFileHelpers
|
|||
if (values.getAllKeys().contains ("MidiUnityNote", true))
|
||||
{
|
||||
block.setSize ((sizeof (InstChunk) + 3) & ~(size_t) 3, true);
|
||||
InstChunk& inst = *static_cast<InstChunk*> (block.getData());
|
||||
auto& inst = *static_cast<InstChunk*> (block.getData());
|
||||
|
||||
inst.baseNote = getValue8 (values, "MidiUnityNote", "60");
|
||||
inst.detune = getValue8 (values, "Detune", "0");
|
||||
|
|
@ -238,8 +238,8 @@ namespace AiffFileHelpers
|
|||
|
||||
StringArray tagsArray;
|
||||
|
||||
const char* data = static_cast<const char*> (mb.getData());
|
||||
const char* dataEnd = data + mb.getSize();
|
||||
auto* data = static_cast<const char*> (mb.getData());
|
||||
auto* dataEnd = data + mb.getSize();
|
||||
|
||||
while (data < dataEnd)
|
||||
{
|
||||
|
|
@ -247,7 +247,7 @@ namespace AiffFileHelpers
|
|||
|
||||
if (isValidTag (data))
|
||||
{
|
||||
const String tag = String (CharPointer_UTF8 (data), CharPointer_UTF8 (dataEnd));
|
||||
auto tag = String (CharPointer_UTF8 (data), CharPointer_UTF8 (dataEnd));
|
||||
isGenre = isAppleGenre (tag);
|
||||
tagsArray.add (tag);
|
||||
}
|
||||
|
|
@ -276,22 +276,14 @@ namespace AiffFileHelpers
|
|||
const String noteString ("CueNote");
|
||||
const String identifierString ("Identifier");
|
||||
|
||||
const StringArray& keys = values.getAllKeys();
|
||||
|
||||
for (int i = 0; i < keys.size(); ++i)
|
||||
for (auto& key : values.getAllKeys())
|
||||
{
|
||||
const String key (keys[i]);
|
||||
|
||||
if (key.startsWith (noteString))
|
||||
continue; // zero identifier IS valid in a COMT chunk
|
||||
|
||||
if (key.startsWith (cueString) && key.contains (identifierString))
|
||||
{
|
||||
const int value = values.getValue (key, "-1").getIntValue();
|
||||
|
||||
if (value == 0)
|
||||
if (values.getValue (key, "-1").getIntValue() == 0)
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
|
|
@ -299,16 +291,15 @@ namespace AiffFileHelpers
|
|||
|
||||
static void create (MemoryBlock& block, const StringPairArray& values)
|
||||
{
|
||||
const int numCues = values.getValue ("NumCuePoints", "0").getIntValue();
|
||||
auto numCues = values.getValue ("NumCuePoints", "0").getIntValue();
|
||||
|
||||
if (numCues > 0)
|
||||
{
|
||||
MemoryOutputStream out (block, false);
|
||||
|
||||
out.writeShortBigEndian ((short) numCues);
|
||||
|
||||
const int numCueLabels = values.getValue ("NumCueLabels", "0").getIntValue();
|
||||
const int idOffset = metaDataContainsZeroIdentifiers (values) ? 1 : 0; // can't have zero IDs in AIFF
|
||||
auto numCueLabels = values.getValue ("NumCueLabels", "0").getIntValue();
|
||||
auto idOffset = metaDataContainsZeroIdentifiers (values) ? 1 : 0; // can't have zero IDs in AIFF
|
||||
|
||||
#if JUCE_DEBUG
|
||||
Array<int> identifiers;
|
||||
|
|
@ -316,21 +307,21 @@ namespace AiffFileHelpers
|
|||
|
||||
for (int i = 0; i < numCues; ++i)
|
||||
{
|
||||
const String prefixCue ("Cue" + String (i));
|
||||
const int identifier = idOffset + values.getValue (prefixCue + "Identifier", "1").getIntValue();
|
||||
auto prefixCue = "Cue" + String (i);
|
||||
auto identifier = idOffset + values.getValue (prefixCue + "Identifier", "1").getIntValue();
|
||||
|
||||
#if JUCE_DEBUG
|
||||
jassert (! identifiers.contains (identifier));
|
||||
identifiers.add (identifier);
|
||||
#endif
|
||||
|
||||
const int offset = values.getValue (prefixCue + "Offset", "0").getIntValue();
|
||||
String label ("CueLabel" + String (i));
|
||||
auto offset = values.getValue (prefixCue + "Offset", "0").getIntValue();
|
||||
auto label = "CueLabel" + String (i);
|
||||
|
||||
for (int labelIndex = 0; labelIndex < numCueLabels; ++labelIndex)
|
||||
{
|
||||
const String prefixLabel ("CueLabel" + String (labelIndex));
|
||||
const int labelIdentifier = idOffset + values.getValue (prefixLabel + "Identifier", "1").getIntValue();
|
||||
auto prefixLabel = "CueLabel" + String (labelIndex);
|
||||
auto labelIdentifier = idOffset + values.getValue (prefixLabel + "Identifier", "1").getIntValue();
|
||||
|
||||
if (labelIdentifier == identifier)
|
||||
{
|
||||
|
|
@ -342,7 +333,7 @@ namespace AiffFileHelpers
|
|||
out.writeShortBigEndian ((short) identifier);
|
||||
out.writeIntBigEndian (offset);
|
||||
|
||||
const size_t labelLength = jmin ((size_t) 254, label.getNumBytesAsUTF8()); // seems to need null terminator even though it's a pstring
|
||||
auto labelLength = jmin ((size_t) 254, label.getNumBytesAsUTF8()); // seems to need null terminator even though it's a pstring
|
||||
out.writeByte ((char) labelLength + 1);
|
||||
out.write (label.toUTF8(), labelLength);
|
||||
out.writeByte (0);
|
||||
|
|
@ -359,7 +350,7 @@ namespace AiffFileHelpers
|
|||
{
|
||||
static void create (MemoryBlock& block, const StringPairArray& values)
|
||||
{
|
||||
const int numNotes = values.getValue ("NumCueNotes", "0").getIntValue();
|
||||
auto numNotes = values.getValue ("NumCueNotes", "0").getIntValue();
|
||||
|
||||
if (numNotes > 0)
|
||||
{
|
||||
|
|
@ -368,14 +359,14 @@ namespace AiffFileHelpers
|
|||
|
||||
for (int i = 0; i < numNotes; ++i)
|
||||
{
|
||||
const String prefix ("CueNote" + String (i));
|
||||
auto prefix = "CueNote" + String (i);
|
||||
|
||||
out.writeIntBigEndian (values.getValue (prefix + "TimeStamp", "0").getIntValue());
|
||||
out.writeShortBigEndian ((short) values.getValue (prefix + "Identifier", "0").getIntValue());
|
||||
|
||||
const String comment (values.getValue (prefix + "Text", String()));
|
||||
auto comment = values.getValue (prefix + "Text", String());
|
||||
auto commentLength = jmin (comment.getNumBytesAsUTF8(), (size_t) 65534);
|
||||
|
||||
const size_t commentLength = jmin (comment.getNumBytesAsUTF8(), (size_t) 65534);
|
||||
out.writeShortBigEndian ((short) commentLength + 1);
|
||||
out.write (comment.toUTF8(), commentLength);
|
||||
out.writeByte (0);
|
||||
|
|
@ -399,10 +390,10 @@ public:
|
|||
|
||||
if (input->readInt() == chunkName ("FORM"))
|
||||
{
|
||||
const int len = input->readIntBigEndian();
|
||||
const int64 end = input->getPosition() + len;
|
||||
auto len = input->readIntBigEndian();
|
||||
auto end = input->getPosition() + len;
|
||||
auto nextType = input->readInt();
|
||||
|
||||
const int nextType = input->readInt();
|
||||
if (nextType == chunkName ("AIFF") || nextType == chunkName ("AIFC"))
|
||||
{
|
||||
bool hasGotVer = false;
|
||||
|
|
@ -411,15 +402,15 @@ public:
|
|||
|
||||
while (input->getPosition() < end)
|
||||
{
|
||||
const int type = input->readInt();
|
||||
const uint32 length = (uint32) input->readIntBigEndian();
|
||||
const int64 chunkEnd = input->getPosition() + length;
|
||||
auto type = input->readInt();
|
||||
auto length = (uint32) input->readIntBigEndian();
|
||||
auto chunkEnd = input->getPosition() + length;
|
||||
|
||||
if (type == chunkName ("FVER"))
|
||||
{
|
||||
hasGotVer = true;
|
||||
auto ver = input->readIntBigEndian();
|
||||
|
||||
const int ver = input->readIntBigEndian();
|
||||
if (ver != 0 && ver != (int) 0xa2805140)
|
||||
break;
|
||||
}
|
||||
|
|
@ -441,7 +432,7 @@ public:
|
|||
|| (byte0 == 0x40 && sampleRateBytes[1] > 0x1C))
|
||||
break;
|
||||
|
||||
unsigned int sampRate = ByteOrder::bigEndianInt (sampleRateBytes + 2);
|
||||
auto sampRate = ByteOrder::bigEndianInt (sampleRateBytes + 2);
|
||||
sampRate >>= (16414 - ByteOrder::bigEndianShort (sampleRateBytes));
|
||||
sampleRate = (int) sampRate;
|
||||
|
||||
|
|
@ -453,7 +444,7 @@ public:
|
|||
}
|
||||
else
|
||||
{
|
||||
const int compType = input->readInt();
|
||||
auto compType = input->readInt();
|
||||
|
||||
if (compType == chunkName ("NONE") || compType == chunkName ("twos"))
|
||||
{
|
||||
|
|
@ -479,13 +470,13 @@ public:
|
|||
{
|
||||
hasGotData = true;
|
||||
|
||||
const int offset = input->readIntBigEndian();
|
||||
auto offset = input->readIntBigEndian();
|
||||
dataChunkStart = input->getPosition() + 4 + offset;
|
||||
lengthInSamples = (bytesPerFrame > 0) ? jmin (lengthInSamples, ((int64) length) / (int64) bytesPerFrame) : 0;
|
||||
}
|
||||
else if (type == chunkName ("MARK"))
|
||||
{
|
||||
const uint16 numCues = (uint16) input->readShortBigEndian();
|
||||
auto numCues = (uint16) input->readShortBigEndian();
|
||||
|
||||
// these two are always the same for AIFF-read files
|
||||
metadataValues.set ("NumCuePoints", String (numCues));
|
||||
|
|
@ -493,9 +484,9 @@ public:
|
|||
|
||||
for (uint16 i = 0; i < numCues; ++i)
|
||||
{
|
||||
uint16 identifier = (uint16) input->readShortBigEndian();
|
||||
uint32 offset = (uint32) input->readIntBigEndian();
|
||||
uint8 stringLength = (uint8) input->readByte();
|
||||
auto identifier = (uint16) input->readShortBigEndian();
|
||||
auto offset = (uint32) input->readIntBigEndian();
|
||||
auto stringLength = (uint8) input->readByte();
|
||||
MemoryBlock textBlock;
|
||||
input->readIntoMemoryBlock (textBlock, stringLength);
|
||||
|
||||
|
|
@ -505,30 +496,30 @@ public:
|
|||
if ((stringLength & 1) == 0)
|
||||
input->readByte();
|
||||
|
||||
const String prefixCue ("Cue" + String (i));
|
||||
auto prefixCue = "Cue" + String (i);
|
||||
metadataValues.set (prefixCue + "Identifier", String (identifier));
|
||||
metadataValues.set (prefixCue + "Offset", String (offset));
|
||||
|
||||
const String prefixLabel ("CueLabel" + String (i));
|
||||
auto prefixLabel = "CueLabel" + String (i);
|
||||
metadataValues.set (prefixLabel + "Identifier", String (identifier));
|
||||
metadataValues.set (prefixLabel + "Text", textBlock.toString());
|
||||
}
|
||||
}
|
||||
else if (type == chunkName ("COMT"))
|
||||
{
|
||||
const uint16 numNotes = (uint16) input->readShortBigEndian();
|
||||
auto numNotes = (uint16) input->readShortBigEndian();
|
||||
metadataValues.set ("NumCueNotes", String (numNotes));
|
||||
|
||||
for (uint16 i = 0; i < numNotes; ++i)
|
||||
{
|
||||
uint32 timestamp = (uint32) input->readIntBigEndian();
|
||||
uint16 identifier = (uint16) input->readShortBigEndian(); // may be zero in this case
|
||||
uint16 stringLength = (uint16) input->readShortBigEndian();
|
||||
auto timestamp = (uint32) input->readIntBigEndian();
|
||||
auto identifier = (uint16) input->readShortBigEndian(); // may be zero in this case
|
||||
auto stringLength = (uint16) input->readShortBigEndian();
|
||||
|
||||
MemoryBlock textBlock;
|
||||
input->readIntoMemoryBlock (textBlock, stringLength + (stringLength & 1));
|
||||
|
||||
const String prefix ("CueNote" + String (i));
|
||||
auto prefix = "CueNote" + String (i);
|
||||
metadataValues.set (prefix + "TimeStamp", String (timestamp));
|
||||
metadataValues.set (prefix + "Identifier", String (identifier));
|
||||
metadataValues.set (prefix + "Text", textBlock.toString());
|
||||
|
|
@ -609,7 +600,7 @@ public:
|
|||
}
|
||||
|
||||
template <typename Endianness>
|
||||
static void copySampleData (unsigned int bitsPerSample, const bool usesFloatingPointData,
|
||||
static void copySampleData (unsigned int bitsPerSample, bool usesFloatingPointData,
|
||||
int* const* destSamples, int startOffsetInDestBuffer, int numDestChannels,
|
||||
const void* sourceData, int numChannels, int numSamples) noexcept
|
||||
{
|
||||
|
|
@ -677,7 +668,7 @@ public:
|
|||
if (writeFailed)
|
||||
return false;
|
||||
|
||||
const size_t bytes = numChannels * (size_t) numSamples * bitsPerSample / 8;
|
||||
auto bytes = numChannels * (size_t) numSamples * bitsPerSample / 8;
|
||||
tempBlock.ensureSize (bytes, false);
|
||||
|
||||
switch (bitsPerSample)
|
||||
|
|
@ -722,10 +713,10 @@ private:
|
|||
// to be able to seek back to write the header
|
||||
jassert (couldSeekOk);
|
||||
|
||||
const int headerLen = (int) (54 + (markChunk.getSize() > 0 ? markChunk.getSize() + 8 : 0)
|
||||
+ (comtChunk.getSize() > 0 ? comtChunk.getSize() + 8 : 0)
|
||||
+ (instChunk.getSize() > 0 ? instChunk.getSize() + 8 : 0));
|
||||
int audioBytes = (int) (lengthInSamples * ((bitsPerSample * numChannels) / 8));
|
||||
auto headerLen = (int) (54 + (markChunk.getSize() > 0 ? markChunk.getSize() + 8 : 0)
|
||||
+ (comtChunk.getSize() > 0 ? comtChunk.getSize() + 8 : 0)
|
||||
+ (instChunk.getSize() > 0 ? instChunk.getSize() + 8 : 0));
|
||||
auto audioBytes = (int) (lengthInSamples * ((bitsPerSample * numChannels) / 8));
|
||||
audioBytes += (audioBytes & 1);
|
||||
|
||||
output->writeInt (chunkName ("FORM"));
|
||||
|
|
@ -737,7 +728,7 @@ private:
|
|||
output->writeIntBigEndian ((int) lengthInSamples);
|
||||
output->writeShortBigEndian ((short) bitsPerSample);
|
||||
|
||||
uint8 sampleRateBytes[10] = { 0 };
|
||||
uint8 sampleRateBytes[10] = {};
|
||||
|
||||
if (sampleRate <= 1)
|
||||
{
|
||||
|
|
@ -758,8 +749,8 @@ private:
|
|||
else
|
||||
{
|
||||
int n = (int) sampleRate;
|
||||
|
||||
int i;
|
||||
|
||||
for (i = 0; i <= 32 ; ++i)
|
||||
{
|
||||
if ((n & mask) != 0)
|
||||
|
|
@ -849,7 +840,7 @@ public:
|
|||
|
||||
void getSample (int64 sample, float* result) const noexcept override
|
||||
{
|
||||
const int num = (int) numChannels;
|
||||
auto num = (int) numChannels;
|
||||
|
||||
if (map == nullptr || ! mappedSection.contains (sample))
|
||||
{
|
||||
|
|
@ -937,13 +928,8 @@ private:
|
|||
};
|
||||
|
||||
//==============================================================================
|
||||
AiffAudioFormat::AiffAudioFormat() : AudioFormat (aiffFormatName, ".aiff .aif")
|
||||
{
|
||||
}
|
||||
|
||||
AiffAudioFormat::~AiffAudioFormat()
|
||||
{
|
||||
}
|
||||
AiffAudioFormat::AiffAudioFormat() : AudioFormat (aiffFormatName, ".aiff .aif") {}
|
||||
AiffAudioFormat::~AiffAudioFormat() {}
|
||||
|
||||
Array<int> AiffAudioFormat::getPossibleSampleRates()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -145,7 +145,7 @@ struct CoreAudioFormatMetatdata
|
|||
//==============================================================================
|
||||
static StringPairArray parseMidiChunk (InputStream& input, int64 size)
|
||||
{
|
||||
const int64 originalPosition = input.getPosition();
|
||||
auto originalPosition = input.getPosition();
|
||||
|
||||
MemoryBlock midiBlock;
|
||||
input.readIntoMemoryBlock (midiBlock, (ssize_t) size);
|
||||
|
|
@ -172,12 +172,12 @@ struct CoreAudioFormatMetatdata
|
|||
MidiMessageSequence tempoEvents;
|
||||
midiFile.findAllTempoEvents (tempoEvents);
|
||||
|
||||
const int numTempoEvents = tempoEvents.getNumEvents();
|
||||
auto numTempoEvents = tempoEvents.getNumEvents();
|
||||
MemoryOutputStream tempoSequence;
|
||||
|
||||
for (int i = 0; i < numTempoEvents; ++i)
|
||||
{
|
||||
const double tempo = getTempoFromTempoMetaEvent (tempoEvents.getEventPointer (i));
|
||||
auto tempo = getTempoFromTempoMetaEvent (tempoEvents.getEventPointer (i));
|
||||
|
||||
if (tempo > 0.0)
|
||||
{
|
||||
|
|
@ -197,11 +197,11 @@ struct CoreAudioFormatMetatdata
|
|||
{
|
||||
if (holder != nullptr)
|
||||
{
|
||||
const MidiMessage& midiMessage = holder->message;
|
||||
auto& midiMessage = holder->message;
|
||||
|
||||
if (midiMessage.isTempoMetaEvent())
|
||||
{
|
||||
const double tempoSecondsPerQuarterNote = midiMessage.getTempoSecondsPerQuarterNote();
|
||||
auto tempoSecondsPerQuarterNote = midiMessage.getTempoSecondsPerQuarterNote();
|
||||
|
||||
if (tempoSecondsPerQuarterNote > 0.0)
|
||||
return 60.0 / tempoSecondsPerQuarterNote;
|
||||
|
|
@ -215,7 +215,7 @@ struct CoreAudioFormatMetatdata
|
|||
{
|
||||
MidiMessageSequence timeSigEvents;
|
||||
midiFile.findAllTimeSigEvents (timeSigEvents);
|
||||
const int numTimeSigEvents = timeSigEvents.getNumEvents();
|
||||
auto numTimeSigEvents = timeSigEvents.getNumEvents();
|
||||
|
||||
MemoryOutputStream timeSigSequence;
|
||||
|
||||
|
|
@ -242,15 +242,15 @@ struct CoreAudioFormatMetatdata
|
|||
{
|
||||
MidiMessageSequence keySigEvents;
|
||||
midiFile.findAllKeySigEvents (keySigEvents);
|
||||
const int numKeySigEvents = keySigEvents.getNumEvents();
|
||||
auto numKeySigEvents = keySigEvents.getNumEvents();
|
||||
|
||||
MemoryOutputStream keySigSequence;
|
||||
|
||||
for (int i = 0; i < numKeySigEvents; ++i)
|
||||
{
|
||||
const MidiMessage& message (keySigEvents.getEventPointer (i)->message);
|
||||
const int key = jlimit (0, 14, message.getKeySignatureNumberOfSharpsOrFlats() + 7);
|
||||
const bool isMajor = message.isKeySignatureMajorKey();
|
||||
auto& message (keySigEvents.getEventPointer (i)->message);
|
||||
auto key = jlimit (0, 14, message.getKeySignatureNumberOfSharpsOrFlats() + 7);
|
||||
bool isMajor = message.isKeySignatureMajorKey();
|
||||
|
||||
static const char* majorKeys[] = { "Cb", "Gb", "Db", "Ab", "Eb", "Bb", "F", "C", "G", "D", "A", "E", "B", "F#", "C#" };
|
||||
static const char* minorKeys[] = { "Ab", "Eb", "Bb", "F", "C", "G", "D", "A", "E", "B", "F#", "C#", "G#", "D#", "A#" };
|
||||
|
|
@ -276,7 +276,7 @@ struct CoreAudioFormatMetatdata
|
|||
static StringPairArray parseInformationChunk (InputStream& input)
|
||||
{
|
||||
StringPairArray infoStrings;
|
||||
const uint32 numEntries = (uint32) input.readIntBigEndian();
|
||||
auto numEntries = (uint32) input.readIntBigEndian();
|
||||
|
||||
for (uint32 i = 0; i < numEntries; ++i)
|
||||
infoStrings.set (input.readString(), input.readString());
|
||||
|
|
@ -287,7 +287,7 @@ struct CoreAudioFormatMetatdata
|
|||
//==============================================================================
|
||||
static bool read (InputStream& input, StringPairArray& metadataValues)
|
||||
{
|
||||
const int64 originalPos = input.getPosition();
|
||||
auto originalPos = input.getPosition();
|
||||
|
||||
const FileHeader cafFileHeader (input);
|
||||
const bool isCafFile = cafFileHeader.fileType == chunkName ("caff");
|
||||
|
|
@ -342,9 +342,7 @@ struct CoreAudioFormatMetatdata
|
|||
class CoreAudioReader : public AudioFormatReader
|
||||
{
|
||||
public:
|
||||
CoreAudioReader (InputStream* const inp)
|
||||
: AudioFormatReader (inp, coreAudioFormatName),
|
||||
ok (false), lastReadPosition (0)
|
||||
CoreAudioReader (InputStream* inp) : AudioFormatReader (inp, coreAudioFormatName)
|
||||
{
|
||||
usesFloatingPointData = true;
|
||||
bitsPerSample = 32;
|
||||
|
|
@ -476,11 +474,11 @@ public:
|
|||
|
||||
while (numSamples > 0)
|
||||
{
|
||||
const int numThisTime = jmin (8192, numSamples);
|
||||
const size_t numBytes = sizeof (float) * (size_t) numThisTime;
|
||||
auto numThisTime = jmin (8192, numSamples);
|
||||
auto numBytes = sizeof (float) * (size_t) numThisTime;
|
||||
|
||||
audioDataBlock.ensureSize (numBytes * numChannels, false);
|
||||
float* data = static_cast<float*> (audioDataBlock.getData());
|
||||
auto* data = static_cast<float*> (audioDataBlock.getData());
|
||||
|
||||
for (int j = (int) numChannels; --j >= 0;)
|
||||
{
|
||||
|
|
@ -490,14 +488,15 @@ public:
|
|||
data += numThisTime;
|
||||
}
|
||||
|
||||
UInt32 numFramesToRead = (UInt32) numThisTime;
|
||||
OSStatus status = ExtAudioFileRead (audioFileRef, &numFramesToRead, bufferList);
|
||||
auto numFramesToRead = (UInt32) numThisTime;
|
||||
auto status = ExtAudioFileRead (audioFileRef, &numFramesToRead, bufferList);
|
||||
|
||||
if (status != noErr)
|
||||
return false;
|
||||
|
||||
for (int i = numDestChannels; --i >= 0;)
|
||||
{
|
||||
int* dest = destSamples[(i < (int) numChannels ? channelMap[i] : i)];
|
||||
auto* dest = destSamples[(i < (int) numChannels ? channelMap[i] : i)];
|
||||
|
||||
if (dest != nullptr)
|
||||
{
|
||||
|
|
@ -518,12 +517,13 @@ public:
|
|||
|
||||
AudioChannelSet getChannelLayout() override
|
||||
{
|
||||
if (channelSet.size() == static_cast<int> (numChannels)) return channelSet;
|
||||
if (channelSet.size() == static_cast<int> (numChannels))
|
||||
return channelSet;
|
||||
|
||||
return AudioFormatReader::getChannelLayout();
|
||||
}
|
||||
|
||||
bool ok;
|
||||
bool ok = false;
|
||||
|
||||
private:
|
||||
AudioFileID audioFileID;
|
||||
|
|
@ -532,7 +532,7 @@ private:
|
|||
AudioStreamBasicDescription destinationAudioFormat;
|
||||
MemoryBlock audioDataBlock;
|
||||
HeapBlock<AudioBufferList> bufferList;
|
||||
int64 lastReadPosition;
|
||||
int64 lastReadPosition = 0;
|
||||
HeapBlock<int> channelMap;
|
||||
|
||||
static SInt64 getSizeCallback (void* inClientData)
|
||||
|
|
@ -540,17 +540,12 @@ private:
|
|||
return static_cast<CoreAudioReader*> (inClientData)->input->getTotalLength();
|
||||
}
|
||||
|
||||
static OSStatus readCallback (void* inClientData,
|
||||
SInt64 inPosition,
|
||||
UInt32 requestCount,
|
||||
void* buffer,
|
||||
UInt32* actualCount)
|
||||
static OSStatus readCallback (void* inClientData, SInt64 inPosition, UInt32 requestCount,
|
||||
void* buffer, UInt32* actualCount)
|
||||
{
|
||||
CoreAudioReader* const reader = static_cast<CoreAudioReader*> (inClientData);
|
||||
|
||||
auto* reader = static_cast<CoreAudioReader*> (inClientData);
|
||||
reader->input->setPosition (inPosition);
|
||||
*actualCount = (UInt32) reader->input->read (buffer, (int) requestCount);
|
||||
|
||||
return noErr;
|
||||
}
|
||||
|
||||
|
|
@ -565,8 +560,8 @@ CoreAudioFormat::CoreAudioFormat()
|
|||
|
||||
CoreAudioFormat::~CoreAudioFormat() {}
|
||||
|
||||
Array<int> CoreAudioFormat::getPossibleSampleRates() { return Array<int>(); }
|
||||
Array<int> CoreAudioFormat::getPossibleBitDepths() { return Array<int>(); }
|
||||
Array<int> CoreAudioFormat::getPossibleSampleRates() { return {}; }
|
||||
Array<int> CoreAudioFormat::getPossibleBitDepths() { return {}; }
|
||||
|
||||
bool CoreAudioFormat::canDoStereo() { return true; }
|
||||
bool CoreAudioFormat::canDoMono() { return true; }
|
||||
|
|
@ -789,7 +784,7 @@ private:
|
|||
DEFINE_CHANNEL_LAYOUT_DFL_ENTRY (kAudioChannelLayoutTag_AAC_7_1_C),
|
||||
DEFINE_CHANNEL_LAYOUT_DFL_ENTRY (kAudioChannelLayoutTag_AAC_Octagonal),
|
||||
DEFINE_CHANNEL_LAYOUT_DFL_ENTRY (kAudioChannelLayoutTag_TMH_10_2_std),
|
||||
// DEFINE_CHANNEL_LAYOUT_DFL_ENTRY (kAudioChannelLayoutTag_TMH_10_2_full), no indicatoin on how to handle this tag
|
||||
// DEFINE_CHANNEL_LAYOUT_DFL_ENTRY (kAudioChannelLayoutTag_TMH_10_2_full), no indication on how to handle this tag
|
||||
DEFINE_CHANNEL_LAYOUT_DFL_ENTRY (kAudioChannelLayoutTag_AC3_1_0_1),
|
||||
DEFINE_CHANNEL_LAYOUT_DFL_ENTRY (kAudioChannelLayoutTag_AC3_3_0),
|
||||
DEFINE_CHANNEL_LAYOUT_DFL_ENTRY (kAudioChannelLayoutTag_AC3_3_1),
|
||||
|
|
|
|||
|
|
@ -171,21 +171,15 @@ static const char* const flacFormatName = "FLAC file";
|
|||
class FlacReader : public AudioFormatReader
|
||||
{
|
||||
public:
|
||||
FlacReader (InputStream* const in)
|
||||
: AudioFormatReader (in, flacFormatName),
|
||||
reservoirStart (0),
|
||||
samplesInReservoir (0),
|
||||
scanningForLength (false)
|
||||
FlacReader (InputStream* in) : AudioFormatReader (in, flacFormatName)
|
||||
{
|
||||
using namespace FlacNamespace;
|
||||
lengthInSamples = 0;
|
||||
|
||||
decoder = FLAC__stream_decoder_new();
|
||||
decoder = FlacNamespace::FLAC__stream_decoder_new();
|
||||
|
||||
ok = FLAC__stream_decoder_init_stream (decoder,
|
||||
readCallback_, seekCallback_, tellCallback_, lengthCallback_,
|
||||
eofCallback_, writeCallback_, metadataCallback_, errorCallback_,
|
||||
this) == FLAC__STREAM_DECODER_INIT_STATUS_OK;
|
||||
this) == FlacNamespace::FLAC__STREAM_DECODER_INIT_STATUS_OK;
|
||||
|
||||
if (ok)
|
||||
{
|
||||
|
|
@ -198,7 +192,7 @@ public:
|
|||
scanningForLength = true;
|
||||
FLAC__stream_decoder_process_until_end_of_stream (decoder);
|
||||
scanningForLength = false;
|
||||
const int64 tempLength = lengthInSamples;
|
||||
auto tempLength = lengthInSamples;
|
||||
|
||||
FLAC__stream_decoder_reset (decoder);
|
||||
FLAC__stream_decoder_process_until_end_of_metadata (decoder);
|
||||
|
|
@ -226,8 +220,6 @@ public:
|
|||
bool readSamples (int** destSamples, int numDestChannels, int startOffsetInDestBuffer,
|
||||
int64 startSampleInFile, int numSamples) override
|
||||
{
|
||||
using namespace FlacNamespace;
|
||||
|
||||
if (! ok)
|
||||
return false;
|
||||
|
||||
|
|
@ -236,8 +228,8 @@ public:
|
|||
if (startSampleInFile >= reservoirStart
|
||||
&& startSampleInFile < reservoirStart + samplesInReservoir)
|
||||
{
|
||||
const int num = (int) jmin ((int64) numSamples,
|
||||
reservoirStart + samplesInReservoir - startSampleInFile);
|
||||
auto num = (int) jmin ((int64) numSamples,
|
||||
reservoirStart + samplesInReservoir - startSampleInFile);
|
||||
|
||||
jassert (num > 0);
|
||||
|
||||
|
|
@ -264,7 +256,7 @@ public:
|
|||
// accurately than this. Probably fixed in newer versions of the library, though.
|
||||
reservoirStart = (int) (startSampleInFile & ~511);
|
||||
samplesInReservoir = 0;
|
||||
FLAC__stream_decoder_seek_absolute (decoder, (FLAC__uint64) reservoirStart);
|
||||
FLAC__stream_decoder_seek_absolute (decoder, (FlacNamespace::FLAC__uint64) reservoirStart);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
@ -299,19 +291,19 @@ public:
|
|||
if (numSamples > reservoir.getNumSamples())
|
||||
reservoir.setSize ((int) numChannels, numSamples, false, false, true);
|
||||
|
||||
const unsigned int bitsToShift = 32 - bitsPerSample;
|
||||
auto bitsToShift = 32 - bitsPerSample;
|
||||
|
||||
for (int i = 0; i < (int) numChannels; ++i)
|
||||
{
|
||||
const FlacNamespace::FLAC__int32* src = buffer[i];
|
||||
|
||||
auto* src = buffer[i];
|
||||
int n = i;
|
||||
|
||||
while (src == 0 && n > 0)
|
||||
src = buffer [--n];
|
||||
|
||||
if (src != nullptr)
|
||||
{
|
||||
int* const dest = reinterpret_cast<int*> (reservoir.getWritePointer(i));
|
||||
auto* dest = reinterpret_cast<int*> (reservoir.getWritePointer(i));
|
||||
|
||||
for (int j = 0; j < numSamples; ++j)
|
||||
dest[j] = src[j] << bitsToShift;
|
||||
|
|
@ -325,30 +317,26 @@ public:
|
|||
//==============================================================================
|
||||
static FlacNamespace::FLAC__StreamDecoderReadStatus readCallback_ (const FlacNamespace::FLAC__StreamDecoder*, FlacNamespace::FLAC__byte buffer[], size_t* bytes, void* client_data)
|
||||
{
|
||||
using namespace FlacNamespace;
|
||||
*bytes = (size_t) static_cast<const FlacReader*> (client_data)->input->read (buffer, (int) *bytes);
|
||||
return FLAC__STREAM_DECODER_READ_STATUS_CONTINUE;
|
||||
return FlacNamespace::FLAC__STREAM_DECODER_READ_STATUS_CONTINUE;
|
||||
}
|
||||
|
||||
static FlacNamespace::FLAC__StreamDecoderSeekStatus seekCallback_ (const FlacNamespace::FLAC__StreamDecoder*, FlacNamespace::FLAC__uint64 absolute_byte_offset, void* client_data)
|
||||
{
|
||||
using namespace FlacNamespace;
|
||||
static_cast<const FlacReader*> (client_data)->input->setPosition ((int) absolute_byte_offset);
|
||||
return FLAC__STREAM_DECODER_SEEK_STATUS_OK;
|
||||
return FlacNamespace::FLAC__STREAM_DECODER_SEEK_STATUS_OK;
|
||||
}
|
||||
|
||||
static FlacNamespace::FLAC__StreamDecoderTellStatus tellCallback_ (const FlacNamespace::FLAC__StreamDecoder*, FlacNamespace::FLAC__uint64* absolute_byte_offset, void* client_data)
|
||||
{
|
||||
using namespace FlacNamespace;
|
||||
*absolute_byte_offset = (uint64) static_cast<const FlacReader*> (client_data)->input->getPosition();
|
||||
return FLAC__STREAM_DECODER_TELL_STATUS_OK;
|
||||
return FlacNamespace::FLAC__STREAM_DECODER_TELL_STATUS_OK;
|
||||
}
|
||||
|
||||
static FlacNamespace::FLAC__StreamDecoderLengthStatus lengthCallback_ (const FlacNamespace::FLAC__StreamDecoder*, FlacNamespace::FLAC__uint64* stream_length, void* client_data)
|
||||
{
|
||||
using namespace FlacNamespace;
|
||||
*stream_length = (uint64) static_cast<const FlacReader*> (client_data)->input->getTotalLength();
|
||||
return FLAC__STREAM_DECODER_LENGTH_STATUS_OK;
|
||||
return FlacNamespace::FLAC__STREAM_DECODER_LENGTH_STATUS_OK;
|
||||
}
|
||||
|
||||
static FlacNamespace::FLAC__bool eofCallback_ (const FlacNamespace::FLAC__StreamDecoder*, void* client_data)
|
||||
|
|
@ -361,9 +349,8 @@ public:
|
|||
const FlacNamespace::FLAC__int32* const buffer[],
|
||||
void* client_data)
|
||||
{
|
||||
using namespace FlacNamespace;
|
||||
static_cast<FlacReader*> (client_data)->useSamples (buffer, (int) frame->header.blocksize);
|
||||
return FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE;
|
||||
return FlacNamespace::FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE;
|
||||
}
|
||||
|
||||
static void metadataCallback_ (const FlacNamespace::FLAC__StreamDecoder*,
|
||||
|
|
@ -380,8 +367,8 @@ public:
|
|||
private:
|
||||
FlacNamespace::FLAC__StreamDecoder* decoder;
|
||||
AudioSampleBuffer reservoir;
|
||||
int reservoirStart, samplesInReservoir;
|
||||
bool ok, scanningForLength;
|
||||
int reservoirStart = 0, samplesInReservoir = 0;
|
||||
bool ok = false, scanningForLength = false;
|
||||
|
||||
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (FlacReader)
|
||||
};
|
||||
|
|
@ -391,12 +378,11 @@ private:
|
|||
class FlacWriter : public AudioFormatWriter
|
||||
{
|
||||
public:
|
||||
FlacWriter (OutputStream* const out, double rate, uint32 numChans, uint32 bits, int qualityOptionIndex)
|
||||
FlacWriter (OutputStream* out, double rate, uint32 numChans, uint32 bits, int qualityOptionIndex)
|
||||
: AudioFormatWriter (out, flacFormatName, rate, numChans, bits),
|
||||
streamStartPos (output != nullptr ? jmax (output->getPosition(), 0ll) : 0ll)
|
||||
{
|
||||
using namespace FlacNamespace;
|
||||
encoder = FLAC__stream_encoder_new();
|
||||
encoder = FlacNamespace::FLAC__stream_encoder_new();
|
||||
|
||||
if (qualityOptionIndex > 0)
|
||||
FLAC__stream_encoder_set_compression_level (encoder, (uint32) jmin (8, qualityOptionIndex));
|
||||
|
|
@ -412,7 +398,7 @@ public:
|
|||
ok = FLAC__stream_encoder_init_stream (encoder,
|
||||
encodeWriteCallback, encodeSeekCallback,
|
||||
encodeTellCallback, encodeMetadataCallback,
|
||||
this) == FLAC__STREAM_ENCODER_INIT_STATUS_OK;
|
||||
this) == FlacNamespace::FLAC__STREAM_ENCODER_INIT_STATUS_OK;
|
||||
}
|
||||
|
||||
~FlacWriter()
|
||||
|
|
@ -434,7 +420,6 @@ public:
|
|||
//==============================================================================
|
||||
bool write (const int** samplesToWrite, int numSamples) override
|
||||
{
|
||||
using namespace FlacNamespace;
|
||||
if (! ok)
|
||||
return false;
|
||||
|
||||
|
|
@ -452,7 +437,7 @@ public:
|
|||
if (samplesToWrite[i] == nullptr)
|
||||
break;
|
||||
|
||||
int* const destData = temp.get() + i * (size_t) numSamples;
|
||||
auto* destData = temp.get() + i * (size_t) numSamples;
|
||||
channels[i] = destData;
|
||||
|
||||
for (int j = 0; j < numSamples; ++j)
|
||||
|
|
@ -462,7 +447,7 @@ public:
|
|||
samplesToWrite = const_cast<const int**> (channels.get());
|
||||
}
|
||||
|
||||
return FLAC__stream_encoder_process (encoder, (const FLAC__int32**) samplesToWrite, (unsigned) numSamples) != 0;
|
||||
return FLAC__stream_encoder_process (encoder, (const FlacNamespace::FLAC__int32**) samplesToWrite, (unsigned) numSamples) != 0;
|
||||
}
|
||||
|
||||
bool writeData (const void* const data, const int size) const
|
||||
|
|
@ -520,26 +505,23 @@ public:
|
|||
unsigned int /*current_frame*/,
|
||||
void* client_data)
|
||||
{
|
||||
using namespace FlacNamespace;
|
||||
return static_cast<FlacWriter*> (client_data)->writeData (buffer, (int) bytes)
|
||||
? FLAC__STREAM_ENCODER_WRITE_STATUS_OK
|
||||
: FLAC__STREAM_ENCODER_WRITE_STATUS_FATAL_ERROR;
|
||||
? FlacNamespace::FLAC__STREAM_ENCODER_WRITE_STATUS_OK
|
||||
: FlacNamespace::FLAC__STREAM_ENCODER_WRITE_STATUS_FATAL_ERROR;
|
||||
}
|
||||
|
||||
static FlacNamespace::FLAC__StreamEncoderSeekStatus encodeSeekCallback (const FlacNamespace::FLAC__StreamEncoder*, FlacNamespace::FLAC__uint64, void*)
|
||||
{
|
||||
using namespace FlacNamespace;
|
||||
return FLAC__STREAM_ENCODER_SEEK_STATUS_UNSUPPORTED;
|
||||
return FlacNamespace::FLAC__STREAM_ENCODER_SEEK_STATUS_UNSUPPORTED;
|
||||
}
|
||||
|
||||
static FlacNamespace::FLAC__StreamEncoderTellStatus encodeTellCallback (const FlacNamespace::FLAC__StreamEncoder*, FlacNamespace::FLAC__uint64* absolute_byte_offset, void* client_data)
|
||||
{
|
||||
using namespace FlacNamespace;
|
||||
if (client_data == nullptr)
|
||||
return FLAC__STREAM_ENCODER_TELL_STATUS_UNSUPPORTED;
|
||||
return FlacNamespace::FLAC__STREAM_ENCODER_TELL_STATUS_UNSUPPORTED;
|
||||
|
||||
*absolute_byte_offset = (FLAC__uint64) static_cast<FlacWriter*> (client_data)->output->getPosition();
|
||||
return FLAC__STREAM_ENCODER_TELL_STATUS_OK;
|
||||
*absolute_byte_offset = (FlacNamespace::FLAC__uint64) static_cast<FlacWriter*> (client_data)->output->getPosition();
|
||||
return FlacNamespace::FLAC__STREAM_ENCODER_TELL_STATUS_OK;
|
||||
}
|
||||
|
||||
static void encodeMetadataCallback (const FlacNamespace::FLAC__StreamEncoder*, const FlacNamespace::FLAC__StreamMetadata* metadata, void* client_data)
|
||||
|
|
@ -547,7 +529,7 @@ public:
|
|||
static_cast<FlacWriter*> (client_data)->writeMetaData (metadata);
|
||||
}
|
||||
|
||||
bool ok;
|
||||
bool ok = false;
|
||||
|
||||
private:
|
||||
FlacNamespace::FLAC__StreamEncoder* encoder;
|
||||
|
|
@ -558,14 +540,8 @@ private:
|
|||
|
||||
|
||||
//==============================================================================
|
||||
FlacAudioFormat::FlacAudioFormat()
|
||||
: AudioFormat (flacFormatName, ".flac")
|
||||
{
|
||||
}
|
||||
|
||||
FlacAudioFormat::~FlacAudioFormat()
|
||||
{
|
||||
}
|
||||
FlacAudioFormat::FlacAudioFormat() : AudioFormat (flacFormatName, ".flac") {}
|
||||
FlacAudioFormat::~FlacAudioFormat() {}
|
||||
|
||||
Array<int> FlacAudioFormat::getPossibleSampleRates()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -38,12 +38,11 @@ public:
|
|||
int bitsPerSample, const StringPairArray& metadata)
|
||||
: AudioFormatWriter (destStream, formatName, sampleRate,
|
||||
numberOfChannels, (unsigned int) bitsPerSample),
|
||||
vbrLevel (vbr), cbrBitrate (cbr),
|
||||
tempWav (".wav")
|
||||
vbrLevel (vbr), cbrBitrate (cbr)
|
||||
{
|
||||
WavAudioFormat wavFormat;
|
||||
|
||||
if (FileOutputStream* out = tempWav.getFile().createOutputStream())
|
||||
if (auto* out = tempWav.getFile().createOutputStream())
|
||||
{
|
||||
writer = wavFormat.createWriterFor (out, sampleRate, numChannels,
|
||||
bitsPerSample, metadata, 0);
|
||||
|
|
@ -77,7 +76,7 @@ public:
|
|||
|
||||
void addMetadataArg (const StringPairArray& metadata, const char* key, const char* lameFlag)
|
||||
{
|
||||
const String value (metadata.getValue (key, String()));
|
||||
auto value = metadata.getValue (key, {});
|
||||
|
||||
if (value.isNotEmpty())
|
||||
{
|
||||
|
|
@ -104,7 +103,7 @@ public:
|
|||
|
||||
private:
|
||||
int vbrLevel, cbrBitrate;
|
||||
TemporaryFile tempWav;
|
||||
TemporaryFile tempWav { ".wav" };
|
||||
ScopedPointer<AudioFormatWriter> writer;
|
||||
StringArray args;
|
||||
|
||||
|
|
@ -114,7 +113,7 @@ private:
|
|||
|
||||
if (cp.start (processArgs))
|
||||
{
|
||||
const String childOutput (cp.readAllProcessOutput());
|
||||
auto childOutput = cp.readAllProcessOutput();
|
||||
DBG (childOutput); ignoreUnused (childOutput);
|
||||
|
||||
cp.waitForProcessToFinish (10000);
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -111,12 +111,8 @@ const char* const OggVorbisAudioFormat::id3trackNumber = "id3trackNumber";
|
|||
class OggReader : public AudioFormatReader
|
||||
{
|
||||
public:
|
||||
OggReader (InputStream* const inp)
|
||||
: AudioFormatReader (inp, oggFormatName),
|
||||
reservoirStart (0),
|
||||
samplesInReservoir (0)
|
||||
OggReader (InputStream* inp) : AudioFormatReader (inp, oggFormatName)
|
||||
{
|
||||
using namespace OggVorbisNamespace;
|
||||
sampleRate = 0;
|
||||
usesFloatingPointData = true;
|
||||
|
||||
|
|
@ -125,13 +121,13 @@ public:
|
|||
callbacks.close_func = &oggCloseCallback;
|
||||
callbacks.tell_func = &oggTellCallback;
|
||||
|
||||
const int err = ov_open_callbacks (input, &ovFile, 0, 0, callbacks);
|
||||
auto err = ov_open_callbacks (input, &ovFile, 0, 0, callbacks);
|
||||
|
||||
if (err == 0)
|
||||
{
|
||||
vorbis_info* info = ov_info (&ovFile, -1);
|
||||
auto* info = ov_info (&ovFile, -1);
|
||||
|
||||
vorbis_comment* const comment = ov_comment (&ovFile, -1);
|
||||
auto* comment = ov_comment (&ovFile, -1);
|
||||
addMetadataItem (comment, "ENCODER", OggVorbisAudioFormat::encoderName);
|
||||
addMetadataItem (comment, "TITLE", OggVorbisAudioFormat::id3title);
|
||||
addMetadataItem (comment, "ARTIST", OggVorbisAudioFormat::id3artist);
|
||||
|
|
@ -152,12 +148,12 @@ public:
|
|||
|
||||
~OggReader()
|
||||
{
|
||||
OggVorbisNamespace::ov_clear (&ovFile);
|
||||
ov_clear (&ovFile);
|
||||
}
|
||||
|
||||
void addMetadataItem (OggVorbisNamespace::vorbis_comment* comment, const char* name, const char* metadataName)
|
||||
{
|
||||
if (const char* value = vorbis_comment_query (comment, name, 0))
|
||||
if (auto* value = vorbis_comment_query (comment, name, 0))
|
||||
metadataValues.set (metadataName, value);
|
||||
}
|
||||
|
||||
|
|
@ -167,13 +163,13 @@ public:
|
|||
{
|
||||
while (numSamples > 0)
|
||||
{
|
||||
const int numAvailable = (int) (reservoirStart + samplesInReservoir - startSampleInFile);
|
||||
auto numAvailable = (int) (reservoirStart + samplesInReservoir - startSampleInFile);
|
||||
|
||||
if (startSampleInFile >= reservoirStart && numAvailable > 0)
|
||||
{
|
||||
// got a few samples overlapping, so use them before seeking..
|
||||
|
||||
const int numToUse = jmin (numSamples, numAvailable);
|
||||
auto numToUse = jmin (numSamples, numAvailable);
|
||||
|
||||
for (int i = jmin (numDestChannels, reservoir.getNumChannels()); --i >= 0;)
|
||||
if (destSamples[i] != nullptr)
|
||||
|
|
@ -193,22 +189,21 @@ public:
|
|||
|| startSampleInFile + numSamples > reservoirStart + samplesInReservoir)
|
||||
{
|
||||
// buffer miss, so refill the reservoir
|
||||
int bitStream = 0;
|
||||
|
||||
reservoirStart = jmax (0, (int) startSampleInFile);
|
||||
samplesInReservoir = reservoir.getNumSamples();
|
||||
|
||||
if (reservoirStart != (int) OggVorbisNamespace::ov_pcm_tell (&ovFile))
|
||||
OggVorbisNamespace::ov_pcm_seek (&ovFile, reservoirStart);
|
||||
if (reservoirStart != (int) ov_pcm_tell (&ovFile))
|
||||
ov_pcm_seek (&ovFile, reservoirStart);
|
||||
|
||||
int bitStream = 0;
|
||||
int offset = 0;
|
||||
int numToRead = samplesInReservoir;
|
||||
|
||||
while (numToRead > 0)
|
||||
{
|
||||
float** dataIn = nullptr;
|
||||
auto samps = ov_read_float (&ovFile, &dataIn, numToRead, &bitStream);
|
||||
|
||||
const long samps = OggVorbisNamespace::ov_read_float (&ovFile, &dataIn, numToRead, &bitStream);
|
||||
if (samps <= 0)
|
||||
break;
|
||||
|
||||
|
|
@ -244,7 +239,7 @@ public:
|
|||
|
||||
static int oggSeekCallback (void* datasource, OggVorbisNamespace::ogg_int64_t offset, int whence)
|
||||
{
|
||||
InputStream* const in = static_cast<InputStream*> (datasource);
|
||||
auto* in = static_cast<InputStream*> (datasource);
|
||||
|
||||
if (whence == SEEK_CUR)
|
||||
offset += in->getPosition();
|
||||
|
|
@ -269,7 +264,7 @@ private:
|
|||
OggVorbisNamespace::OggVorbis_File ovFile;
|
||||
OggVorbisNamespace::ov_callbacks callbacks;
|
||||
AudioSampleBuffer reservoir;
|
||||
int reservoirStart, samplesInReservoir;
|
||||
int reservoirStart = 0, samplesInReservoir = 0;
|
||||
|
||||
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (OggReader)
|
||||
};
|
||||
|
|
@ -278,20 +273,14 @@ private:
|
|||
class OggWriter : public AudioFormatWriter
|
||||
{
|
||||
public:
|
||||
OggWriter (OutputStream* const out,
|
||||
const double sampleRate_,
|
||||
const unsigned int numChannels_,
|
||||
const unsigned int bitsPerSample_,
|
||||
const int qualityIndex,
|
||||
const StringPairArray& metadata)
|
||||
: AudioFormatWriter (out, oggFormatName, sampleRate_, numChannels_, bitsPerSample_),
|
||||
ok (false)
|
||||
OggWriter (OutputStream* out, double rate,
|
||||
unsigned int numChans, unsigned int bitsPerSamp,
|
||||
int qualityIndex, const StringPairArray& metadata)
|
||||
: AudioFormatWriter (out, oggFormatName, rate, numChans, bitsPerSamp)
|
||||
{
|
||||
using namespace OggVorbisNamespace;
|
||||
|
||||
vorbis_info_init (&vi);
|
||||
|
||||
if (vorbis_encode_init_vbr (&vi, (int) numChannels_, (int) sampleRate_,
|
||||
if (vorbis_encode_init_vbr (&vi, (int) numChans, (int) rate,
|
||||
jlimit (0.0f, 1.0f, qualityIndex * 0.1f)) == 0)
|
||||
{
|
||||
vorbis_comment_init (&vc);
|
||||
|
|
@ -310,10 +299,7 @@ public:
|
|||
|
||||
ogg_stream_init (&os, Random::getSystemRandom().nextInt());
|
||||
|
||||
ogg_packet header;
|
||||
ogg_packet header_comm;
|
||||
ogg_packet header_code;
|
||||
|
||||
OggVorbisNamespace::ogg_packet header, header_comm, header_code;
|
||||
vorbis_analysis_headerout (&vd, &vc, &header, &header_comm, &header_code);
|
||||
|
||||
ogg_stream_packetin (&os, &header);
|
||||
|
|
@ -335,7 +321,6 @@ public:
|
|||
|
||||
~OggWriter()
|
||||
{
|
||||
using namespace OggVorbisNamespace;
|
||||
if (ok)
|
||||
{
|
||||
// write a zero-length packet to show ogg that we're finished..
|
||||
|
|
@ -362,8 +347,6 @@ public:
|
|||
{
|
||||
if (ok)
|
||||
{
|
||||
using namespace OggVorbisNamespace;
|
||||
|
||||
if (numSamples > 0)
|
||||
{
|
||||
const double gain = 1.0 / 0x80000000u;
|
||||
|
|
@ -371,13 +354,13 @@ public:
|
|||
|
||||
for (int i = (int) numChannels; --i >= 0;)
|
||||
{
|
||||
float* const dst = vorbisBuffer[i];
|
||||
const int* const src = samplesToWrite [i];
|
||||
|
||||
if (src != nullptr && dst != nullptr)
|
||||
if (auto* dst = vorbisBuffer[i])
|
||||
{
|
||||
for (int j = 0; j < numSamples; ++j)
|
||||
dst[j] = (float) (src[j] * gain);
|
||||
if (const int* src = samplesToWrite [i])
|
||||
{
|
||||
for (int j = 0; j < numSamples; ++j)
|
||||
dst[j] = (float) (src[j] * gain);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -390,8 +373,6 @@ public:
|
|||
|
||||
void writeSamples (int numSamples)
|
||||
{
|
||||
using namespace OggVorbisNamespace;
|
||||
|
||||
vorbis_analysis_wrote (&vd, numSamples);
|
||||
|
||||
while (vorbis_analysis_blockout (&vd, &vb) == 1)
|
||||
|
|
@ -418,7 +399,7 @@ public:
|
|||
}
|
||||
}
|
||||
|
||||
bool ok;
|
||||
bool ok = false;
|
||||
|
||||
private:
|
||||
OggVorbisNamespace::ogg_stream_state os;
|
||||
|
|
@ -431,7 +412,7 @@ private:
|
|||
|
||||
void addMetadata (const StringPairArray& metadata, const char* name, const char* vorbisName)
|
||||
{
|
||||
const String s (metadata [name]);
|
||||
auto s = metadata [name];
|
||||
|
||||
if (s.isNotEmpty())
|
||||
vorbis_comment_add_tag (&vc, vorbisName, const_cast<char*> (s.toRawUTF8()));
|
||||
|
|
@ -469,7 +450,7 @@ bool OggVorbisAudioFormat::canDoStereo() { return true; }
|
|||
bool OggVorbisAudioFormat::canDoMono() { return true; }
|
||||
bool OggVorbisAudioFormat::isCompressed() { return true; }
|
||||
|
||||
AudioFormatReader* OggVorbisAudioFormat::createReaderFor (InputStream* in, const bool deleteStreamIfOpeningFails)
|
||||
AudioFormatReader* OggVorbisAudioFormat::createReaderFor (InputStream* in, bool deleteStreamIfOpeningFails)
|
||||
{
|
||||
ScopedPointer<OggReader> r (new OggReader (in));
|
||||
|
||||
|
|
@ -508,22 +489,20 @@ StringArray OggVorbisAudioFormat::getQualityOptions()
|
|||
|
||||
int OggVorbisAudioFormat::estimateOggFileQuality (const File& source)
|
||||
{
|
||||
if (FileInputStream* const in = source.createInputStream())
|
||||
if (auto* in = source.createInputStream())
|
||||
{
|
||||
ScopedPointer<AudioFormatReader> r (createReaderFor (in, true));
|
||||
|
||||
if (r != nullptr)
|
||||
if (ScopedPointer<AudioFormatReader> r = createReaderFor (in, true))
|
||||
{
|
||||
const double lengthSecs = r->lengthInSamples / r->sampleRate;
|
||||
const int approxBitsPerSecond = (int) (source.getSize() * 8 / lengthSecs);
|
||||
auto lengthSecs = r->lengthInSamples / r->sampleRate;
|
||||
auto approxBitsPerSecond = (int) (source.getSize() * 8 / lengthSecs);
|
||||
|
||||
const StringArray qualities (getQualityOptions());
|
||||
auto qualities = getQualityOptions();
|
||||
int bestIndex = 0;
|
||||
int bestDiff = 10000;
|
||||
|
||||
for (int i = qualities.size(); --i >= 0;)
|
||||
{
|
||||
const int diff = std::abs (qualities[i].getIntValue() - approxBitsPerSecond);
|
||||
auto diff = std::abs (qualities[i].getIntValue() - approxBitsPerSecond);
|
||||
|
||||
if (diff < bestDiff)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@ StringPairArray WavAudioFormat::createBWAVMetadata (const String& description,
|
|||
const String& originator,
|
||||
const String& originatorRef,
|
||||
Time date,
|
||||
const int64 timeReferenceSamples,
|
||||
int64 timeReferenceSamples,
|
||||
const String& codingHistory)
|
||||
{
|
||||
StringPairArray m;
|
||||
|
|
@ -200,7 +200,7 @@ namespace WavFileHelpers
|
|||
MemoryBlock data (roundUpSize (sizeof (BWAVChunk) + values[WavAudioFormat::bwavCodingHistory].getNumBytesAsUTF8()));
|
||||
data.fillWith (0);
|
||||
|
||||
BWAVChunk* b = (BWAVChunk*) data.getData();
|
||||
auto* b = (BWAVChunk*) data.getData();
|
||||
|
||||
// Allow these calls to overwrite an extra byte at the end, which is fine as long
|
||||
// as they get called in the right order..
|
||||
|
|
@ -683,14 +683,14 @@ namespace WavFileHelpers
|
|||
if (infoLength <= 0)
|
||||
return;
|
||||
|
||||
for (int i = 0; i < numElementsInArray (types); ++i)
|
||||
for (auto& type : types)
|
||||
{
|
||||
if (isMatchingTypeIgnoringCase (infoType, types[i]))
|
||||
if (isMatchingTypeIgnoringCase (infoType, type))
|
||||
{
|
||||
MemoryBlock mb;
|
||||
input.readIntoMemoryBlock (mb, (ssize_t) infoLength);
|
||||
values.set (types[i], String::createStringFromData ((const char*) mb.getData(),
|
||||
(int) mb.getSize()));
|
||||
values.set (type, String::createStringFromData ((const char*) mb.getData(),
|
||||
(int) mb.getSize()));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
@ -724,8 +724,8 @@ namespace WavFileHelpers
|
|||
out.writeInt (chunkName ("INFO"));
|
||||
bool anyParamsDefined = false;
|
||||
|
||||
for (int i = 0; i < numElementsInArray (types); ++i)
|
||||
if (writeValue (values, out, types[i]))
|
||||
for (auto& type : types)
|
||||
if (writeValue (values, out, type))
|
||||
anyParamsDefined = true;
|
||||
|
||||
return anyParamsDefined ? out.getMemoryBlock() : MemoryBlock();
|
||||
|
|
@ -1096,7 +1096,7 @@ public:
|
|||
}
|
||||
else if (chunkType == chunkName ("LIST"))
|
||||
{
|
||||
const int subChunkType = input->readInt();
|
||||
auto subChunkType = input->readInt();
|
||||
|
||||
if (subChunkType == chunkName ("info") || subChunkType == chunkName ("INFO"))
|
||||
{
|
||||
|
|
@ -1106,9 +1106,9 @@ public:
|
|||
{
|
||||
while (input->getPosition() < chunkEnd)
|
||||
{
|
||||
const int adtlChunkType = input->readInt();
|
||||
const uint32 adtlLength = (uint32) input->readInt();
|
||||
const int64 adtlChunkEnd = input->getPosition() + (adtlLength + (adtlLength & 1));
|
||||
auto adtlChunkType = input->readInt();
|
||||
auto adtlLength = (uint32) input->readInt();
|
||||
auto adtlChunkEnd = input->getPosition() + (adtlLength + (adtlLength & 1));
|
||||
|
||||
if (adtlChunkType == chunkName ("labl") || adtlChunkType == chunkName ("note"))
|
||||
{
|
||||
|
|
@ -1119,8 +1119,8 @@ public:
|
|||
else if (adtlChunkType == chunkName ("note"))
|
||||
prefix << "CueNote" << cueNoteIndex++;
|
||||
|
||||
const uint32 identifier = (uint32) input->readInt();
|
||||
const int stringLength = (int) adtlLength - 4;
|
||||
auto identifier = (uint32) input->readInt();
|
||||
auto stringLength = (int) adtlLength - 4;
|
||||
|
||||
MemoryBlock textBlock;
|
||||
input->readIntoMemoryBlock (textBlock, stringLength);
|
||||
|
|
@ -1130,15 +1130,15 @@ public:
|
|||
}
|
||||
else if (adtlChunkType == chunkName ("ltxt"))
|
||||
{
|
||||
const String prefix ("CueRegion" + String (cueRegionIndex++));
|
||||
const uint32 identifier = (uint32) input->readInt();
|
||||
const uint32 sampleLength = (uint32) input->readInt();
|
||||
const uint32 purpose = (uint32) input->readInt();
|
||||
const uint16 country = (uint16) input->readInt();
|
||||
const uint16 language = (uint16) input->readInt();
|
||||
const uint16 dialect = (uint16) input->readInt();
|
||||
const uint16 codePage = (uint16) input->readInt();
|
||||
const uint32 stringLength = adtlLength - 20;
|
||||
auto prefix = "CueRegion" + String (cueRegionIndex++);
|
||||
auto identifier = (uint32) input->readInt();
|
||||
auto sampleLength = (uint32) input->readInt();
|
||||
auto purpose = (uint32) input->readInt();
|
||||
auto country = (uint16) input->readInt();
|
||||
auto language = (uint16) input->readInt();
|
||||
auto dialect = (uint16) input->readInt();
|
||||
auto codePage = (uint16) input->readInt();
|
||||
auto stringLength = adtlLength - 20;
|
||||
|
||||
MemoryBlock textBlock;
|
||||
input->readIntoMemoryBlock (textBlock, (int) stringLength);
|
||||
|
|
@ -1199,8 +1199,8 @@ public:
|
|||
const int tempBufSize = 480 * 3 * 4; // (keep this a multiple of 3)
|
||||
char tempBuffer[tempBufSize];
|
||||
|
||||
const int numThisTime = jmin (tempBufSize / bytesPerFrame, numSamples);
|
||||
const int bytesRead = input->read (tempBuffer, numThisTime * bytesPerFrame);
|
||||
auto numThisTime = jmin (tempBufSize / bytesPerFrame, numSamples);
|
||||
auto bytesRead = input->read (tempBuffer, numThisTime * bytesPerFrame);
|
||||
|
||||
if (bytesRead < numThisTime * bytesPerFrame)
|
||||
{
|
||||
|
|
@ -1332,7 +1332,7 @@ public:
|
|||
if (writeFailed)
|
||||
return false;
|
||||
|
||||
const size_t bytes = numChannels * (size_t) numSamples * bitsPerSample / 8;
|
||||
auto bytes = numChannels * (size_t) numSamples * bitsPerSample / 8;
|
||||
tempBlock.ensureSize (bytes, false);
|
||||
|
||||
switch (bitsPerSample)
|
||||
|
|
|
|||
|
|
@ -48,7 +48,7 @@ public:
|
|||
|
||||
JUCE_COMRESULT Read (void* dest, ULONG numBytes, ULONG* bytesRead)
|
||||
{
|
||||
const int numRead = source.read (dest, numBytes);
|
||||
auto numRead = source.read (dest, numBytes);
|
||||
|
||||
if (bytesRead != nullptr)
|
||||
*bytesRead = numRead;
|
||||
|
|
@ -58,7 +58,7 @@ public:
|
|||
|
||||
JUCE_COMRESULT Seek (LARGE_INTEGER position, DWORD origin, ULARGE_INTEGER* resultPosition)
|
||||
{
|
||||
int64 newPos = (int64) position.QuadPart;
|
||||
auto newPos = (int64) position.QuadPart;
|
||||
|
||||
if (origin == STREAM_SEEK_CUR)
|
||||
{
|
||||
|
|
@ -66,7 +66,8 @@ public:
|
|||
}
|
||||
else if (origin == STREAM_SEEK_END)
|
||||
{
|
||||
const int64 len = source.getTotalLength();
|
||||
auto len = source.getTotalLength();
|
||||
|
||||
if (len < 0)
|
||||
return E_NOTIMPL;
|
||||
|
||||
|
|
@ -89,8 +90,8 @@ public:
|
|||
{
|
||||
char buffer [1024];
|
||||
|
||||
const int numToCopy = (int) jmin ((int64) sizeof (buffer), (int64) numBytes);
|
||||
const int numRead = source.read (buffer, numToCopy);
|
||||
auto numToCopy = (int) jmin ((int64) sizeof (buffer), (int64) numBytes);
|
||||
auto numRead = source.read (buffer, numToCopy);
|
||||
|
||||
if (numRead <= 0)
|
||||
break;
|
||||
|
|
@ -225,15 +226,15 @@ public:
|
|||
}
|
||||
}
|
||||
|
||||
const int offsetInBuffer = (int) (startSampleInFile - bufferedRange.getStart());
|
||||
const int16* const rawData = static_cast<const int16*> (addBytesToPointer (buffer.getData(), offsetInBuffer * stride));
|
||||
const int numToDo = jmin (numSamples, (int) (bufferedRange.getLength() - offsetInBuffer));
|
||||
auto offsetInBuffer = (int) (startSampleInFile - bufferedRange.getStart());
|
||||
auto* rawData = static_cast<const int16*> (addBytesToPointer (buffer.getData(), offsetInBuffer * stride));
|
||||
auto numToDo = jmin (numSamples, (int) (bufferedRange.getLength() - offsetInBuffer));
|
||||
|
||||
for (int i = 0; i < numDestChannels; ++i)
|
||||
{
|
||||
jassert (destSamples[i] != nullptr);
|
||||
|
||||
const int srcChan = jmin (i, (int) numChannels - 1);
|
||||
auto srcChan = jmin (i, (int) numChannels - 1);
|
||||
const int16* src = rawData + srcChan;
|
||||
int* const dst = destSamples[i] + startOffsetInDestBuffer;
|
||||
|
||||
|
|
@ -301,7 +302,7 @@ private:
|
|||
|
||||
if (mediaType->majortype == WMMEDIATYPE_Audio)
|
||||
{
|
||||
const WAVEFORMATEX* const inputFormat = reinterpret_cast<WAVEFORMATEX*> (mediaType->pbFormat);
|
||||
auto* inputFormat = reinterpret_cast<WAVEFORMATEX*> (mediaType->pbFormat);
|
||||
|
||||
sampleRate = inputFormat->nSamplesPerSec;
|
||||
numChannels = inputFormat->nChannels;
|
||||
|
|
@ -328,8 +329,8 @@ WindowsMediaAudioFormat::WindowsMediaAudioFormat()
|
|||
|
||||
WindowsMediaAudioFormat::~WindowsMediaAudioFormat() {}
|
||||
|
||||
Array<int> WindowsMediaAudioFormat::getPossibleSampleRates() { return Array<int>(); }
|
||||
Array<int> WindowsMediaAudioFormat::getPossibleBitDepths() { return Array<int>(); }
|
||||
Array<int> WindowsMediaAudioFormat::getPossibleSampleRates() { return {}; }
|
||||
Array<int> WindowsMediaAudioFormat::getPossibleBitDepths() { return {}; }
|
||||
|
||||
bool WindowsMediaAudioFormat::canDoStereo() { return true; }
|
||||
bool WindowsMediaAudioFormat::canDoMono() { return true; }
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue