From 6344cd549a9a2d17737374b990e253bb2220a39a Mon Sep 17 00:00:00 2001 From: jules Date: Sun, 15 Oct 2017 10:16:03 +0100 Subject: [PATCH] Some tidying up in the audio codec classes --- .../codecs/juce_AiffAudioFormat.cpp | 118 ++--- .../codecs/juce_CoreAudioFormat.cpp | 65 ++- .../codecs/juce_FlacAudioFormat.cpp | 88 ++-- .../codecs/juce_LAMEEncoderAudioFormat.cpp | 11 +- .../codecs/juce_MP3AudioFormat.cpp | 491 +++++++++--------- .../codecs/juce_OggVorbisAudioFormat.cpp | 91 ++-- .../codecs/juce_WavAudioFormat.cpp | 52 +- .../codecs/juce_WindowsMediaAudioFormat.cpp | 25 +- 8 files changed, 432 insertions(+), 509 deletions(-) diff --git a/modules/juce_audio_formats/codecs/juce_AiffAudioFormat.cpp b/modules/juce_audio_formats/codecs/juce_AiffAudioFormat.cpp index f3c8c8053d..f8d4cc0885 100644 --- a/modules/juce_audio_formats/codecs/juce_AiffAudioFormat.cpp +++ b/modules/juce_audio_formats/codecs/juce_AiffAudioFormat.cpp @@ -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 (block.getData()); + auto& inst = *static_cast (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 (mb.getData()); - const char* dataEnd = data + mb.getSize(); + auto* data = static_cast (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 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 - 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 AiffAudioFormat::getPossibleSampleRates() { diff --git a/modules/juce_audio_formats/codecs/juce_CoreAudioFormat.cpp b/modules/juce_audio_formats/codecs/juce_CoreAudioFormat.cpp index 72d0aa9740..dc74af2e97 100644 --- a/modules/juce_audio_formats/codecs/juce_CoreAudioFormat.cpp +++ b/modules/juce_audio_formats/codecs/juce_CoreAudioFormat.cpp @@ -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 (audioDataBlock.getData()); + auto* data = static_cast (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 (numChannels)) return channelSet; + if (channelSet.size() == static_cast (numChannels)) + return channelSet; return AudioFormatReader::getChannelLayout(); } - bool ok; + bool ok = false; private: AudioFileID audioFileID; @@ -532,7 +532,7 @@ private: AudioStreamBasicDescription destinationAudioFormat; MemoryBlock audioDataBlock; HeapBlock bufferList; - int64 lastReadPosition; + int64 lastReadPosition = 0; HeapBlock channelMap; static SInt64 getSizeCallback (void* inClientData) @@ -540,17 +540,12 @@ private: return static_cast (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 (inClientData); - + auto* reader = static_cast (inClientData); reader->input->setPosition (inPosition); *actualCount = (UInt32) reader->input->read (buffer, (int) requestCount); - return noErr; } @@ -565,8 +560,8 @@ CoreAudioFormat::CoreAudioFormat() CoreAudioFormat::~CoreAudioFormat() {} -Array CoreAudioFormat::getPossibleSampleRates() { return Array(); } -Array CoreAudioFormat::getPossibleBitDepths() { return Array(); } +Array CoreAudioFormat::getPossibleSampleRates() { return {}; } +Array 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), diff --git a/modules/juce_audio_formats/codecs/juce_FlacAudioFormat.cpp b/modules/juce_audio_formats/codecs/juce_FlacAudioFormat.cpp index 8f92d26c04..99f8609dbd 100644 --- a/modules/juce_audio_formats/codecs/juce_FlacAudioFormat.cpp +++ b/modules/juce_audio_formats/codecs/juce_FlacAudioFormat.cpp @@ -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 (reservoir.getWritePointer(i)); + auto* dest = reinterpret_cast (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 (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 (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 (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 (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 (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 (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 (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 (client_data)->output->getPosition(); - return FLAC__STREAM_ENCODER_TELL_STATUS_OK; + *absolute_byte_offset = (FlacNamespace::FLAC__uint64) static_cast (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 (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 FlacAudioFormat::getPossibleSampleRates() { diff --git a/modules/juce_audio_formats/codecs/juce_LAMEEncoderAudioFormat.cpp b/modules/juce_audio_formats/codecs/juce_LAMEEncoderAudioFormat.cpp index 01b39ea247..171fbbed2d 100644 --- a/modules/juce_audio_formats/codecs/juce_LAMEEncoderAudioFormat.cpp +++ b/modules/juce_audio_formats/codecs/juce_LAMEEncoderAudioFormat.cpp @@ -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 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); diff --git a/modules/juce_audio_formats/codecs/juce_MP3AudioFormat.cpp b/modules/juce_audio_formats/codecs/juce_MP3AudioFormat.cpp index 4761577129..8eb4cf9c3b 100644 --- a/modules/juce_audio_formats/codecs/juce_MP3AudioFormat.cpp +++ b/modules/juce_audio_formats/codecs/juce_MP3AudioFormat.cpp @@ -386,7 +386,7 @@ struct VBRTagData const int sampleRateIndex = (data[2] >> 2) & 3; const int mode = (data[3] >> 6) & 3; - static const int bitRates[3][16] = + static const short bitRates[3][16] = { { 0, 8, 16, 24, 32, 40, 48, 56, 64, 80, 96, 112, 128, 144, 160, -1 }, // MPEG2 { 0, 32, 40, 48, 56, 64, 80, 96, 112, 128, 160, 192, 224, 256, 320, -1 }, // MPEG1 @@ -451,7 +451,7 @@ struct VBRTagData unsigned int flags, frames, bytes; private: - static bool isVbrTag (const uint8* const d) noexcept + static bool isVbrTag (const uint8* d) noexcept { return (d[0] == 'X' && d[1] == 'i' && d[2] == 'n' && d[3] == 'g') || (d[0] == 'I' && d[1] == 'n' && d[2] == 'f' && d[3] == 'o'); @@ -477,17 +477,17 @@ struct MP3Frame }; static const AllocationTable* const tables[] = { allocTable0, allocTable1, allocTable2, allocTable3, allocTable4 }; - static const int limits[] = { 27, 30, 8, 12, 30 }; + static const int8 limits[] = { 27, 30, 8, 12, 30 }; const int index = lsf ? 4 : translate[sampleRateIndex][2 - numChannels][bitrateIndex]; - layer2SubBandLimit = limits [index]; - allocationTable = tables [index]; + layer2SubBandLimit = limits[index]; + allocationTable = tables[index]; } int getFrequency() const noexcept { const int frequencies[] = { 44100, 48000, 32000, 22050, 24000, 16000, 11025, 12000, 8000 }; - return frequencies [sampleRateIndex]; + return frequencies[sampleRateIndex]; } void decodeHeader (const uint32 header) @@ -509,7 +509,7 @@ struct MP3Frame //emphasis = header & 3; numChannels = (mode == 3) ? 1 : 2; - static const int frameSizes [2][3][16] = + static const int frameSizes[2][3][16] = { { { 0, 32, 64, 96, 128, 160, 192, 224, 256, 288, 320, 352, 384, 416, 448 }, { 0, 32, 48, 56, 64, 80, 96, 112, 128, 160, 192, 224, 256, 320, 384 }, @@ -563,9 +563,9 @@ struct Constants { switch (d1) { - case 3: return &group3tab [3 * jmin (index, 3u * 3u * 3u)]; - case 5: return &group5tab [3 * jmin (index, 5u * 5u * 5u)]; - case 9: return &group9tab [3 * jmin (index, 9u * 9u * 9u)]; + case 3: return &group3tab[3 * jmin (index, 3u * 3u * 3u)]; + case 5: return &group5tab[3 * jmin (index, 5u * 5u * 5u)]; + case 9: return &group9tab[3 * jmin (index, 9u * 9u * 9u)]; default: break; } @@ -595,9 +595,9 @@ private: int mapbuf1[9][156]; int mapbuf2[9][44]; float cos64[16], cos32[8], cos16[4], cos8[2], cos4[1]; - uint8 group3tab [32 * 3]; - uint8 group5tab [128 * 3]; - uint8 group9tab [1024 * 3]; + uint8 group3tab[32 * 3]; + uint8 group5tab[128 * 3]; + uint8 group9tab[1024 * 3]; void initDecodeTables() { @@ -885,9 +885,9 @@ struct Layer3SideInfo for (; sb != 0; --sb, xr1 += 10) { - const float* cs = constants.antiAliasingCs; - const float* ca = constants.antiAliasingCa; - float* xr2 = xr1; + auto* cs = constants.antiAliasingCs; + auto* ca = constants.antiAliasingCa; + auto* xr2 = xr1; for (int ss = 7; ss >= 0; --ss) { @@ -898,16 +898,17 @@ struct Layer3SideInfo } } - void doIStereo (float xrBuffer[2][32][18], const int* const scaleFactors, - const int sampleRate, const bool msStereo, const int lsf) const noexcept + void doIStereo (float xrBuffer[2][32][18], const int* scaleFactors, + int sampleRate, bool msStereo, int lsf) const noexcept { float (*xr) [32 * 18] = (float (*) [32 * 18]) xrBuffer; - const BandInfoStruct& bi = bandInfo[sampleRate]; + auto& bi = bandInfo[sampleRate]; const float* tabl1, *tabl2; if (lsf != 0) { - const int p = scaleFactorCompression & 1; + auto p = scaleFactorCompression & 1; + if (msStereo) { tabl1 = constants.pow1_2[p]; @@ -944,13 +945,14 @@ struct Layer3SideInfo for (; sfb < 12; ++sfb) { - const int p = scaleFactors[sfb * 3 + lwin - mixedBlockFlag]; + auto p = scaleFactors[sfb * 3 + lwin - mixedBlockFlag]; + if (p != 7) { - const float t1 = tabl1[p]; - const float t2 = tabl2[p]; + auto t1 = tabl1[p]; + auto t2 = tabl2[p]; int sb = bi.shortDiff[sfb]; - uint32 index = (uint32) sb + lwin; + auto index = (uint32) sb + lwin; for (; sb > 0; --sb, index += 3) { @@ -961,14 +963,14 @@ struct Layer3SideInfo } } - const int p = scaleFactors[11 * 3 + lwin - mixedBlockFlag]; + auto p = scaleFactors[11 * 3 + lwin - mixedBlockFlag]; if (p != 7) { - const float t1 = tabl1[p]; - const float t2 = tabl2[p]; + auto t1 = tabl1[p]; + auto t2 = tabl2[p]; int sb = bi.shortDiff[12]; - uint32 index = (uint32) sb + lwin; + auto index = (uint32) sb + lwin; for (; sb > 0; --sb, index += 3) { @@ -986,12 +988,12 @@ struct Layer3SideInfo for (uint32 sfb = maxBandl; sfb < 8; ++sfb) { int sb = bi.longDiff[sfb]; - const int p = scaleFactors[sfb]; + auto p = scaleFactors[sfb]; if (p != 7) { - const float t1 = tabl1[p]; - const float t2 = tabl2[p]; + auto t1 = tabl1[p]; + auto t2 = tabl2[p]; for (; sb > 0; --sb, ++index) { @@ -1012,12 +1014,12 @@ struct Layer3SideInfo for (uint32 sfb = maxBandl; sfb < 21; ++sfb) { int sb = bi.longDiff[sfb]; - const int p = scaleFactors[sfb]; + auto p = scaleFactors[sfb]; if (p != 7) { - const float t1 = tabl1[p]; - const float t2 = tabl2[p]; + auto t1 = tabl1[p]; + auto t2 = tabl2[p]; for (; sb > 0; --sb, ++index) { @@ -1030,10 +1032,11 @@ struct Layer3SideInfo index += sb; } - const int p = scaleFactors[20]; + auto p = scaleFactors[20]; + if (p != 7) { - const float t1 = tabl1[p], t2 = tabl2[p]; + auto t1 = tabl1[p], t2 = tabl2[p]; for (int sb = bi.longDiff[21]; sb > 0; --sb, ++index) { @@ -1065,37 +1068,31 @@ struct Layer3SideInfo //============================================================================== namespace DCT { - enum { SBLIMIT = 32 }; + enum { subBandLimit = 32 }; static const float cos6_1 = 0.866025388f; static const float cos6_2 = 0.5f; static const float cos9[] = { 1.0f, 0.98480773f, 0.939692616f, 0.866025388f, 0.766044438f, 0.642787635f, 0.5f, 0.342020154f, 0.173648179f }; static const float cos36[] = { 0.501909912f, 0.517638087f, 0.551688969f, 0.610387266f, 0.707106769f, 0.871723413f, 1.18310082f, 1.93185163f, 5.73685646f }; static const float cos12[] = { 0.517638087f, 0.707106769f, 1.93185163f }; - inline void dct36_0 (const int v, float* const ts, float* const out1, float* const out2, - const float* const wintab, float sum0, const float sum1) noexcept + inline void dct36_0 (int v, float* ts, float* out1, float* out2, const float* wintab, float sum0, float sum1) noexcept { - const float tmp = sum0 + sum1; + auto tmp = sum0 + sum1; out2[9 + v] = tmp * wintab[27 + v]; out2[8 - v] = tmp * wintab[26 - v]; sum0 -= sum1; - ts[SBLIMIT * (8 - v)] = out1[8 - v] + sum0 * wintab[8 - v]; - ts[SBLIMIT * (9 + v)] = out1[9 + v] + sum0 * wintab[9 + v]; + ts[subBandLimit * (8 - v)] = out1[8 - v] + sum0 * wintab[8 - v]; + ts[subBandLimit * (9 + v)] = out1[9 + v] + sum0 * wintab[9 + v]; } - inline void dct36_1 (const int v, float* const ts, float* const out1, float* const out2, const float* const wintab, - const float tmp1a, const float tmp1b, const float tmp2a, const float tmp2b) noexcept + inline void dct36_12 (int v1, int v2, float* ts, float* out1, float* out2, const float* wintab, + float tmp1a, float tmp1b, float tmp2a, float tmp2b) noexcept { - dct36_0 (v, ts, out1, out2, wintab, tmp1a + tmp2a, (tmp1b + tmp2b) * cos36[v]); + dct36_0 (v1, ts, out1, out2, wintab, tmp1a + tmp2a, (tmp1b + tmp2b) * cos36[v1]); + dct36_0 (v2, ts, out1, out2, wintab, tmp2a - tmp1a, (tmp2b - tmp1b) * cos36[v2]); } - inline void dct36_2 (const int v, float* const ts, float* const out1, float* const out2, const float* const wintab, - const float tmp1a, const float tmp1b, const float tmp2a, const float tmp2b) noexcept - { - dct36_0 (v, ts, out1, out2, wintab, tmp2a - tmp1a, (tmp2b - tmp1b) * cos36[v]); - } - - static void dct36 (float* const in, float* const out1, float* const out2, const float* const wintab, float* const ts) noexcept + static void dct36 (float* in, float* out1, float* out2, const float* wintab, float* ts) noexcept { in[17] += in[16]; in[16] += in[15]; in[15] += in[14]; in[14] += in[13]; in[13] += in[12]; in[12] += in[11]; in[11] += in[10]; in[10] += in[9]; in[9] += in[8]; in[8] += in[7]; @@ -1103,63 +1100,51 @@ namespace DCT in[2] += in[1]; in[1] += in[0]; in[17] += in[15]; in[15] += in[13]; in[13] += in[11]; in[11] += in[9]; in[9] += in[7]; in[7] += in[5]; in[5] += in[3]; in[3] += in[1]; - const float ta33 = in[6] * cos9[3]; - const float ta66 = in[12] * cos9[6]; - const float tb33 = in[7] * cos9[3]; - const float tb66 = in[13] * cos9[6]; + auto ta33 = in[6] * cos9[3]; + auto ta66 = in[12] * cos9[6]; + auto tb33 = in[7] * cos9[3]; + auto tb66 = in[13] * cos9[6]; - { - const float tmp1a = in[2] * cos9[1] + ta33 + in[10] * cos9[5] + in[14] * cos9[7]; - const float tmp1b = in[3] * cos9[1] + tb33 + in[11] * cos9[5] + in[15] * cos9[7]; - const float tmp2a = in[0] + in[4] * cos9[2] + in[8] * cos9[4] + ta66 + in[16] * cos9[8]; - const float tmp2b = in[1] + in[5] * cos9[2] + in[9] * cos9[4] + tb66 + in[17] * cos9[8]; - dct36_1 (0, ts, out1, out2, wintab, tmp1a, tmp1b, tmp2a, tmp2b); - dct36_2 (8, ts, out1, out2, wintab, tmp1a, tmp1b, tmp2a, tmp2b); - } + dct36_12 (0, 8, ts, out1, out2, wintab, + in[2] * cos9[1] + ta33 + in[10] * cos9[5] + in[14] * cos9[7], + in[3] * cos9[1] + tb33 + in[11] * cos9[5] + in[15] * cos9[7], + in[0] + in[4] * cos9[2] + in[8] * cos9[4] + ta66 + in[16] * cos9[8], + in[1] + in[5] * cos9[2] + in[9] * cos9[4] + tb66 + in[17] * cos9[8]); - { - const float tmp1a = (in[2] - in[10] - in[14]) * cos9[3]; - const float tmp1b = (in[3] - in[11] - in[15]) * cos9[3]; - const float tmp2a = (in[4] - in[8] - in[16]) * cos9[6] - in[12] + in[0]; - const float tmp2b = (in[5] - in[9] - in[17]) * cos9[6] - in[13] + in[1]; - dct36_1 (1, ts, out1, out2, wintab, tmp1a, tmp1b, tmp2a, tmp2b); - dct36_2 (7, ts, out1, out2, wintab, tmp1a, tmp1b, tmp2a, tmp2b); - } + dct36_12 (1, 7, ts, out1, out2, wintab, + (in[2] - in[10] - in[14]) * cos9[3], + (in[3] - in[11] - in[15]) * cos9[3], + (in[4] - in[8] - in[16]) * cos9[6] - in[12] + in[0], + (in[5] - in[9] - in[17]) * cos9[6] - in[13] + in[1]); - { - const float tmp1a = in[2] * cos9[5] - ta33 - in[10] * cos9[7] + in[14] * cos9[1]; - const float tmp1b = in[3] * cos9[5] - tb33 - in[11] * cos9[7] + in[15] * cos9[1]; - const float tmp2a = in[0] - in[4] * cos9[8] - in[8] * cos9[2] + ta66 + in[16] * cos9[4]; - const float tmp2b = in[1] - in[5] * cos9[8] - in[9] * cos9[2] + tb66 + in[17] * cos9[4]; - dct36_1 (2, ts, out1, out2, wintab, tmp1a, tmp1b, tmp2a, tmp2b); - dct36_2 (6, ts, out1, out2, wintab, tmp1a, tmp1b, tmp2a, tmp2b); - } + dct36_12 (2, 6, ts, out1, out2, wintab, + in[2] * cos9[5] - ta33 - in[10] * cos9[7] + in[14] * cos9[1], + in[3] * cos9[5] - tb33 - in[11] * cos9[7] + in[15] * cos9[1], + in[0] - in[4] * cos9[8] - in[8] * cos9[2] + ta66 + in[16] * cos9[4], + in[1] - in[5] * cos9[8] - in[9] * cos9[2] + tb66 + in[17] * cos9[4]); - { - const float tmp1a = in[2] * cos9[7] - ta33 + in[10] * cos9[1] - in[14] * cos9[5]; - const float tmp1b = in[3] * cos9[7] - tb33 + in[11] * cos9[1] - in[15] * cos9[5]; - const float tmp2a = in[0] - in[4] * cos9[4] + in[8] * cos9[8] + ta66 - in[16] * cos9[2]; - const float tmp2b = in[1] - in[5] * cos9[4] + in[9] * cos9[8] + tb66 - in[17] * cos9[2]; - dct36_1 (3, ts, out1, out2, wintab, tmp1a, tmp1b, tmp2a, tmp2b); - dct36_2 (5, ts, out1, out2, wintab, tmp1a, tmp1b, tmp2a, tmp2b); - } + dct36_12 (3, 5, ts, out1, out2, wintab, + in[2] * cos9[7] - ta33 + in[10] * cos9[1] - in[14] * cos9[5], + in[3] * cos9[7] - tb33 + in[11] * cos9[1] - in[15] * cos9[5], + in[0] - in[4] * cos9[4] + in[8] * cos9[8] + ta66 - in[16] * cos9[2], + in[1] - in[5] * cos9[4] + in[9] * cos9[8] + tb66 - in[17] * cos9[2]); - const float sum0 = in[0] - in[4] + in[8] - in[12] + in[16]; - const float sum1 = (in[1] - in[5] + in[9] - in[13] + in[17]) * cos36[4]; - dct36_0 (4, ts, out1, out2, wintab, sum0, sum1); + dct36_0 (4, ts, out1, out2, wintab, + in[0] - in[4] + in[8] - in[12] + in[16], + (in[1] - in[5] + in[9] - in[13] + in[17]) * cos36[4]); } struct DCT12Inputs { float in0, in1, in2, in3, in4, in5; - inline DCT12Inputs (const float* const in) noexcept + inline DCT12Inputs (const float* in) noexcept { - in5 = in[5*3] + (in4 = in[4*3]); - in4 += (in3 = in[3*3]); - in3 += (in2 = in[2*3]); - in2 += (in1 = in[1*3]); - in1 += (in0 = in[0*3]); + in5 = in[5 * 3] + (in4 = in[4 * 3]); + in4 += (in3 = in[3 * 3]); + in3 += (in2 = in[2 * 3]); + in2 += (in1 = in[1 * 3]); + in1 += (in0 = in[0 * 3]); in5 += in3; in3 += in1; in2 *= cos6_1; in3 *= cos6_1; @@ -1177,53 +1162,53 @@ namespace DCT } }; - static void dct12 (const float* in, float* const out1, float* const out2, const float* wi, float* ts) noexcept + static void dct12 (const float* in, float* out1, float* out2, const float* wi, float* ts) noexcept { { ts[0] = out1[0]; - ts[SBLIMIT * 1] = out1[1]; - ts[SBLIMIT * 2] = out1[2]; - ts[SBLIMIT * 3] = out1[3]; - ts[SBLIMIT * 4] = out1[4]; - ts[SBLIMIT * 5] = out1[5]; + ts[subBandLimit * 1] = out1[1]; + ts[subBandLimit * 2] = out1[2]; + ts[subBandLimit * 3] = out1[3]; + ts[subBandLimit * 4] = out1[4]; + ts[subBandLimit * 5] = out1[5]; DCT12Inputs inputs (in); { - float tmp1 = (inputs.in0 - inputs.in4); - const float tmp2 = (inputs.in1 - inputs.in5) * cos12[1]; - const float tmp0 = tmp1 + tmp2; + auto tmp1 = (inputs.in0 - inputs.in4); + auto tmp2 = (inputs.in1 - inputs.in5) * cos12[1]; + auto tmp0 = tmp1 + tmp2; tmp1 -= tmp2; - ts[16 * SBLIMIT] = out1[16] + tmp0 * wi[10]; - ts[13 * SBLIMIT] = out1[13] + tmp0 * wi[7]; - ts[7 * SBLIMIT] = out1[7] + tmp1 * wi[1]; - ts[10 * SBLIMIT] = out1[10] + tmp1 * wi[4]; + ts[16 * subBandLimit] = out1[16] + tmp0 * wi[10]; + ts[13 * subBandLimit] = out1[13] + tmp0 * wi[7]; + ts[7 * subBandLimit] = out1[7] + tmp1 * wi[1]; + ts[10 * subBandLimit] = out1[10] + tmp1 * wi[4]; } inputs.process(); - ts[17 * SBLIMIT] = out1[17] + inputs.in2 * wi[11]; - ts[12 * SBLIMIT] = out1[12] + inputs.in2 * wi[6]; - ts[14 * SBLIMIT] = out1[14] + inputs.in3 * wi[8]; - ts[15 * SBLIMIT] = out1[15] + inputs.in3 * wi[9]; + ts[17 * subBandLimit] = out1[17] + inputs.in2 * wi[11]; + ts[12 * subBandLimit] = out1[12] + inputs.in2 * wi[6]; + ts[14 * subBandLimit] = out1[14] + inputs.in3 * wi[8]; + ts[15 * subBandLimit] = out1[15] + inputs.in3 * wi[9]; - ts[6 * SBLIMIT] = out1[6] + inputs.in0 * wi[0]; - ts[11 * SBLIMIT] = out1[11] + inputs.in0 * wi[5]; - ts[8 * SBLIMIT] = out1[8] + inputs.in4 * wi[2]; - ts[9 * SBLIMIT] = out1[9] + inputs.in4 * wi[3]; + ts[6 * subBandLimit] = out1[6] + inputs.in0 * wi[0]; + ts[11 * subBandLimit] = out1[11] + inputs.in0 * wi[5]; + ts[8 * subBandLimit] = out1[8] + inputs.in4 * wi[2]; + ts[9 * subBandLimit] = out1[9] + inputs.in4 * wi[3]; } { DCT12Inputs inputs (++in); - float tmp1 = (inputs.in0 - inputs.in4); - const float tmp2 = (inputs.in1 - inputs.in5) * cos12[1]; - const float tmp0 = tmp1 + tmp2; + auto tmp1 = (inputs.in0 - inputs.in4); + auto tmp2 = (inputs.in1 - inputs.in5) * cos12[1]; + auto tmp0 = tmp1 + tmp2; tmp1 -= tmp2; out2[4] = tmp0 * wi[10]; out2[1] = tmp0 * wi[7]; - ts[13 * SBLIMIT] += tmp1 * wi[1]; - ts[16 * SBLIMIT] += tmp1 * wi[4]; + ts[13 * subBandLimit] += tmp1 * wi[1]; + ts[16 * subBandLimit] += tmp1 * wi[4]; inputs.process(); @@ -1231,19 +1216,19 @@ namespace DCT out2[0] = inputs.in2 * wi[6]; out2[2] = inputs.in3 * wi[8]; out2[3] = inputs.in3 * wi[9]; - ts[12 * SBLIMIT] += inputs.in0 * wi[0]; - ts[17 * SBLIMIT] += inputs.in0 * wi[5]; - ts[14 * SBLIMIT] += inputs.in4 * wi[2]; - ts[15 * SBLIMIT] += inputs.in4 * wi[5 - 2]; + ts[12 * subBandLimit] += inputs.in0 * wi[0]; + ts[17 * subBandLimit] += inputs.in0 * wi[5]; + ts[14 * subBandLimit] += inputs.in4 * wi[2]; + ts[15 * subBandLimit] += inputs.in4 * wi[5 - 2]; } { DCT12Inputs inputs (++in); out2[12] = out2[13] = out2[14] = out2[15] = out2[16] = out2[17] = 0; - float tmp1 = (inputs.in0 - inputs.in4); - const float tmp2 = (inputs.in1 - inputs.in5) * cos12[1]; - const float tmp0 = tmp1 + tmp2; + auto tmp1 = (inputs.in0 - inputs.in4); + auto tmp2 = (inputs.in1 - inputs.in5) * cos12[1]; + auto tmp0 = tmp1 + tmp2; tmp1 -= tmp2; out2[10] = tmp0 * wi[10]; @@ -1264,10 +1249,12 @@ namespace DCT } } - static void dct64 (float* const out0, float* const out1, float* const b1, float* const b2, const float* const samples) noexcept + static void dct64 (float* out0, float* out1, const float* samples) noexcept { + float b1[32], b2[32]; + { - const float* const costab = constants.cosTables[0]; + auto* costab = constants.cosTables[0]; b1[0x00] = samples[0x00] + samples[0x1F]; b1[0x1F] = (samples[0x00] - samples[0x1F]) * costab[0x0]; b1[0x01] = samples[0x01] + samples[0x1E]; b1[0x1E] = (samples[0x01] - samples[0x1E]) * costab[0x1]; b1[0x02] = samples[0x02] + samples[0x1D]; b1[0x1D] = (samples[0x02] - samples[0x1D]) * costab[0x2]; @@ -1287,7 +1274,7 @@ namespace DCT } { - const float* const costab = constants.cosTables[1]; + auto* costab = constants.cosTables[1]; b2[0x00] = b1[0x00] + b1[0x0F]; b2[0x0F] = (b1[0x00] - b1[0x0F]) * costab[0]; b2[0x01] = b1[0x01] + b1[0x0E]; b2[0x0E] = (b1[0x01] - b1[0x0E]) * costab[1]; b2[0x02] = b1[0x02] + b1[0x0D]; b2[0x0D] = (b1[0x02] - b1[0x0D]) * costab[2]; @@ -1307,7 +1294,7 @@ namespace DCT } { - const float* const costab = constants.cosTables[2]; + auto* costab = constants.cosTables[2]; b1[0x00] = b2[0x00] + b2[0x07]; b1[0x07] = (b2[0x00] - b2[0x07]) * costab[0]; b1[0x01] = b2[0x01] + b2[0x06]; b1[0x06] = (b2[0x01] - b2[0x06]) * costab[1]; b1[0x02] = b2[0x02] + b2[0x05]; b1[0x05] = (b2[0x02] - b2[0x05]) * costab[2]; @@ -1327,8 +1314,8 @@ namespace DCT } { - const float cos0 = constants.cosTables[3][0]; - const float cos1 = constants.cosTables[3][1]; + auto cos0 = constants.cosTables[3][0]; + auto cos1 = constants.cosTables[3][1]; b2[0x00] = b1[0x00] + b1[0x03]; b2[0x03] = (b1[0x00] - b1[0x03]) * cos0; b2[0x01] = b1[0x01] + b1[0x02]; b2[0x02] = (b1[0x01] - b1[0x02]) * cos1; b2[0x04] = b1[0x04] + b1[0x07]; b2[0x07] = (b1[0x07] - b1[0x04]) * cos0; @@ -1348,7 +1335,7 @@ namespace DCT } { - const float cos0 = constants.cosTables[4][0]; + auto cos0 = constants.cosTables[4][0]; b1[0x00] = b2[0x00] + b2[0x01]; b1[0x01] = (b2[0x00] - b2[0x01]) * cos0; b1[0x02] = b2[0x02] + b2[0x03]; b1[0x03] = (b2[0x03] - b2[0x02]) * cos0; b1[0x02] += b1[0x03]; b1[0x04] = b2[0x04] + b2[0x05]; b1[0x05] = (b2[0x04] - b2[0x05]) * cos0; @@ -1389,29 +1376,21 @@ namespace DCT b1[0x1B] += b1[0x1F]; out1[0x10 * 9] = b1[0x13] + b1[0x1B]; out1[0x10 * 11] = b1[0x1B] + b1[0x17]; out1[0x10 * 13] = b1[0x17] + b1[0x1F]; out1[0x10 * 15] = b1[0x1F]; } - - static void dct64 (float* const a, float* const b, const float* const c) noexcept - { - float temp[64]; - dct64 (a, b, temp, temp + 32, c); - } } //============================================================================== struct MP3Stream { - MP3Stream (InputStream& source) - : stream (source, 8192), - numFrames (0), currentFrameIndex (0), vbrHeaderFound (false) + MP3Stream (InputStream& source) : stream (source, 8192) { reset(); } - int decodeNextBlock (float* const out0, float* const out1, int& done) + int decodeNextBlock (float* out0, float* out1, int& done) { if (! headerParsed) { - int nextFrameOffset = scanForNextFrameHeader (false); + auto nextFrameOffset = scanForNextFrameHeader (false); if (lastFrameSize == -1 || needToSyncBitStream) { @@ -1427,10 +1406,9 @@ struct MP3Stream if (nextFrameOffset > 0) { - int size; wasFreeFormat = false; needToSyncBitStream = true; - size = (int) (bufferPointer - (bufferSpace[bufferSpaceIndex] + 512)); + auto size = (int) (bufferPointer - (bufferSpace[bufferSpaceIndex] + 512)); if (size > 2880) { @@ -1438,7 +1416,7 @@ struct MP3Stream bufferPointer = bufferSpace[bufferSpaceIndex] + 512; } - const int toSkip = (size + nextFrameOffset) - 2880; + auto toSkip = (size + nextFrameOffset) - 2880; if (toSkip > 0) { @@ -1477,7 +1455,7 @@ struct MP3Stream if (frame.crc16FollowsHeader) getBits (16); - const int bits = jmax (0, decodeLayer3SideInfo()); + auto bits = jmax (0, decodeLayer3SideInfo()); dataSize = (bits + 7) / 8; if (! isFreeFormat) @@ -1525,7 +1503,7 @@ struct MP3Stream } else { - const int nextFrameOffset = scanForNextFrameHeader (true); + auto nextFrameOffset = scanForNextFrameHeader (true); wasFreeFormat = isFreeFormat; @@ -1547,7 +1525,7 @@ struct MP3Stream if (bytes > 0) { - const int toSkip = bytes - 512; + auto toSkip = bytes - 512; if (toSkip > 0) { @@ -1574,7 +1552,7 @@ struct MP3Stream while (frameIndex >= frameStreamPositions.size() * storedStartPosInterval) { int dummy = 0; - const int result = decodeNextBlock (nullptr, nullptr, dummy); + auto result = decodeNextBlock (nullptr, nullptr, dummy); if (result < 0) return false; @@ -1594,8 +1572,8 @@ struct MP3Stream MP3Frame frame; VBRTagData vbrTagData; BufferedInputStream stream; - int numFrames, currentFrameIndex; - bool vbrHeaderFound; + int numFrames = 0, currentFrameIndex = 0; + bool vbrHeaderFound = false; private: bool headerParsed, sideParsed, dataParsed, needToSyncBitStream; @@ -1645,9 +1623,9 @@ private: uint8 scaleFactor[32][2][3]; }; - static bool isValidHeader (const uint32 header, const int oldLayer) noexcept + static bool isValidHeader (uint32 header, int oldLayer) noexcept { - const int newLayer = 4 - ((header >> 17) & 3); + int newLayer = 4 - ((header >> 17) & 3); return (header & 0xffe00000) == 0xffe00000 && newLayer != 4 @@ -1662,7 +1640,7 @@ private: if (lastFrameSize < 0 && backstep > 0) return false; - const uint8* oldBuffer = bufferSpace[1 - bufferSpaceIndex] + 512; + auto* oldBuffer = bufferSpace[1 - bufferSpaceIndex] + 512; bufferPointer -= backstep; if (backstep != 0) @@ -1672,7 +1650,7 @@ private: return true; } - uint32 getBits (const int numBits) noexcept + uint32 getBits (int numBits) noexcept { if (numBits <= 0 || bufferPointer == nullptr) return 0; @@ -1687,14 +1665,14 @@ private: uint32 getOneBit() noexcept { - const uint8 result = (uint8) (*bufferPointer << bitIndex); + auto result = (uint8) (*bufferPointer << bitIndex); ++bitIndex; bufferPointer += (bitIndex >> 3); bitIndex &= 7; return result >> 7; } - uint32 getBitsUnchecked (const int numBits) noexcept + uint32 getBitsUnchecked (int numBits) noexcept { const uint32 result = ((((bufferPointer[0] << 8) | bufferPointer[1]) << bitIndex) & 0xffff) >> (16 - numBits); bitIndex += numBits; @@ -1703,12 +1681,12 @@ private: return result; } - inline uint8 getBitsUint8 (const int numBits) noexcept { return (uint8) getBitsUnchecked (numBits); } - inline uint16 getBitsUint16 (const int numBits) noexcept { return (uint16) getBitsUnchecked (numBits); } + inline uint8 getBitsUint8 (int numBits) noexcept { return (uint8) getBitsUnchecked (numBits); } + inline uint16 getBitsUint16 (int numBits) noexcept { return (uint16) getBitsUnchecked (numBits); } - int scanForNextFrameHeader (const bool checkTypeAgainstLastFrame) noexcept + int scanForNextFrameHeader (bool checkTypeAgainstLastFrame) noexcept { - const int64 oldPos = stream.getPosition(); + auto oldPos = stream.getPosition(); int offset = -3; uint32 header = 0; @@ -1755,7 +1733,7 @@ private: void readVBRHeader() { - int64 oldPos = stream.getPosition(); + auto oldPos = stream.getPosition(); uint8 xing[194]; stream.read (xing, sizeof (xing)); @@ -1770,12 +1748,12 @@ private: stream.setPosition (oldPos); } - void decodeLayer1Frame (float* const pcm0, float* const pcm1, int& samplesDone) noexcept + void decodeLayer1Frame (float* pcm0, float* pcm1, int& samplesDone) noexcept { float fraction[2][32]; SideInfoLayer1 si; layer1Step1 (si); - const int single = (frame.numChannels == 1 || frame.single == 3) ? 0 : frame.single; + auto single = (frame.numChannels == 1 || frame.single == 3) ? 0 : frame.single; if (single >= 0) { @@ -1795,19 +1773,20 @@ private: } } - void decodeLayer2Frame (float* const pcm0, float* const pcm1, int& samplesDone) + void decodeLayer2Frame (float* pcm0, float* pcm1, int& samplesDone) { float fraction[2][4][32]; frame.selectLayer2Table(); SideInfoLayer2 si; layer2Step1 (si); - const int single = (frame.numChannels == 1 || frame.single == 3) ? 0 : frame.single; + auto single = (frame.numChannels == 1 || frame.single == 3) ? 0 : frame.single; if (single >= 0) { for (int i = 0; i < 12; ++i) { layer2Step2 (si, i >> 2, fraction); + for (int j = 0; j < 3; ++j) synthesise (fraction[single][j], 0, pcm0, samplesDone); } @@ -1817,13 +1796,14 @@ private: for (int i = 0; i < 12; ++i) { layer2Step2 (si, i >> 2, fraction); + for (int j = 0; j < 3; ++j) synthesiseStereo (fraction[0][j], fraction[1][j], pcm0, pcm1, samplesDone); } } } - void decodeLayer3Frame (float* const pcm0, float* const pcm1, int& samplesDone) noexcept + void decodeLayer3Frame (float* pcm0, float* pcm1, int& samplesDone) noexcept { if (! rollBackBufferPointer ((int) sideinfo.mainDataStart)) return; @@ -1838,9 +1818,9 @@ private: for (int gr = 0; gr < granules; ++gr) { { - Layer3SideInfo::Info& granule = sideinfo.ch[0].gr[gr]; - const int part2bits = frame.lsf ? getLayer3ScaleFactors2 (scaleFactors[0], granule, 0) - : getLayer3ScaleFactors1 (scaleFactors[0], granule); + auto& granule = sideinfo.ch[0].gr[gr]; + auto part2bits = frame.lsf ? getLayer3ScaleFactors2 (scaleFactors[0], granule, 0) + : getLayer3ScaleFactors1 (scaleFactors[0], granule); if (layer3DequantizeSample (hybridIn[0], scaleFactors[0], granule, frame.sampleRateIndex, part2bits)) return; @@ -1848,9 +1828,9 @@ private: if (frame.numChannels == 2) { - Layer3SideInfo::Info& granule = sideinfo.ch[1].gr[gr]; - const int part2bits = frame.lsf ? getLayer3ScaleFactors2 (scaleFactors[1], granule, iStereo) - : getLayer3ScaleFactors1 (scaleFactors[1], granule); + auto& granule = sideinfo.ch[1].gr[gr]; + auto part2bits = frame.lsf ? getLayer3ScaleFactors2 (scaleFactors[1], granule, iStereo) + : getLayer3ScaleFactors1 (scaleFactors[1], granule); if (layer3DequantizeSample (hybridIn[1], scaleFactors[1], granule, frame.sampleRateIndex, part2bits)) return; @@ -1859,10 +1839,10 @@ private: { for (int i = 0; i < 32 * 18; ++i) { - const float tmp0 = ((const float*) hybridIn[0]) [i]; - const float tmp1 = ((const float*) hybridIn[1]) [i]; - ((float*) hybridIn[1]) [i] = tmp0 - tmp1; - ((float*) hybridIn[0]) [i] = tmp0 + tmp1; + auto tmp0 = ((const float*) hybridIn[0])[i]; + auto tmp1 = ((const float*) hybridIn[1])[i]; + ((float*) hybridIn[1])[i] = tmp0 - tmp1; + ((float*) hybridIn[0])[i] = tmp0 + tmp1; } } @@ -1881,8 +1861,9 @@ private: { case 3: { - float* in0 = (float*) hybridIn[0]; - const float* in1 = (const float*) hybridIn[1]; + auto* in0 = (float*) hybridIn[0]; + auto* in1 = (const float*) hybridIn[1]; + for (int i = 0; i < (int) (18 * granule.maxb); ++i, ++in0) *in0 = (*in0 + *in1++); } @@ -1890,8 +1871,9 @@ private: case 1: { - float* in0 = (float*) hybridIn[0]; - const float* in1 = (const float*) hybridIn[1]; + auto* in0 = (float*) hybridIn[0]; + auto* in1 = (const float*) hybridIn[1]; + for (int i = 0; i < (int) (18 * granule.maxb); ++i) *in0++ = *in1++; } @@ -1901,7 +1883,7 @@ private: for (int ch = 0; ch < numChans; ++ch) { - const Layer3SideInfo::Info& granule = sideinfo.ch[ch].gr[gr]; + auto& granule = sideinfo.ch[ch].gr[gr]; granule.doAntialias (hybridIn[ch]); layer3Hybrid (hybridIn[ch], hybridOut[ch], ch, granule); } @@ -2017,14 +1999,14 @@ private: zerostruct (si); const int sblimit = frame.layer2SubBandLimit; const int jsbound = (frame.mode == 1) ? (frame.modeExt << 2) + 4 : frame.layer2SubBandLimit; - const AllocationTable* allocTable = frame.allocationTable; + auto* allocTable = frame.allocationTable; uint8 scfsi[32][2]; if (frame.numChannels == 2) { for (int i = 0; i < jsbound; ++i) { - const int16 step = allocTable->bits; + auto step = allocTable->bits; allocTable += (static_cast (1) << step); si.allocation[i][0] = getBitsUint8 (step); si.allocation[i][1] = getBitsUint8 (step); @@ -2032,8 +2014,8 @@ private: for (int i = jsbound; i < sblimit; ++i) { - const int16 step = allocTable->bits; - const uint8 b0 = getBitsUint8 (step); + auto step = allocTable->bits; + auto b0 = getBitsUint8 (step); allocTable += (static_cast (1) << step); si.allocation[i][0] = b0; si.allocation[i][1] = b0; @@ -2098,22 +2080,21 @@ private: void layer2Step2 (SideInfoLayer2& si, const int gr, float fraction[2][4][32]) noexcept { - const AllocationTable* allocTable = frame.allocationTable; + auto* allocTable = frame.allocationTable; const int jsbound = (frame.mode == 1) ? (frame.modeExt << 2) + 4 : frame.layer2SubBandLimit; for (int i = 0; i < jsbound; ++i) { - const int16 step = allocTable->bits; + auto step = allocTable->bits; for (int ch = 0; ch < frame.numChannels; ++ch) { - const uint8 ba = si.allocation[i][ch]; - if (ba != 0) + if (auto ba = si.allocation[i][ch]) { - const uint8 x1 = jmin ((uint8) 63, si.scaleFactor[i][ch][gr]); - const AllocationTable* const alloc2 = allocTable + ba; - const int16 k = jmin ((int16) 16, alloc2->bits); - const int16 d1 = alloc2->d; + auto x1 = jmin ((uint8) 63, si.scaleFactor[i][ch][gr]); + auto* alloc2 = allocTable + ba; + auto k = jmin ((int16) 16, alloc2->bits); + auto d1 = alloc2->d; if (d1 < 0) { @@ -2124,7 +2105,7 @@ private: } else { - const uint8* const tab = constants.getGroupTable (d1, getBits (k)); + auto* tab = constants.getGroupTable (d1, getBits (k)); fraction[ch][0][i] = (float) constants.muls[tab[0]][x1]; fraction[ch][1][i] = (float) constants.muls[tab[1]][x1]; fraction[ch][2][i] = (float) constants.muls[tab[2]][x1]; @@ -2141,25 +2122,25 @@ private: for (int i = jsbound; i < frame.layer2SubBandLimit; ++i) { - const int16 step = allocTable->bits; - const uint8 ba = si.allocation[i][0]; + auto step = allocTable->bits; + auto ba = si.allocation[i][0]; if (ba != 0) { - const AllocationTable* const alloc2 = allocTable + ba; + auto* alloc2 = allocTable + ba; int16 k = alloc2->bits; int16 d1 = alloc2->d; k = (k <= 16) ? k : 16; if (d1 < 0) { - const int v0 = (int) getBits (k); - const int v1 = (int) getBits (k); - const int v2 = (int) getBits (k); + auto v0 = (int) getBits (k); + auto v1 = (int) getBits (k); + auto v2 = (int) getBits (k); for (int ch = 0; ch < frame.numChannels; ++ch) { - const uint8 x1 = jmin ((uint8) 63, si.scaleFactor[i][ch][gr]); + auto x1 = jmin ((uint8) 63, si.scaleFactor[i][ch][gr]); const double cm = constants.muls[k][x1]; fraction[ch][0][i] = (float) ((v0 + d1) * cm); fraction[ch][1][i] = (float) ((v1 + d1) * cm); @@ -2168,14 +2149,14 @@ private: } else { - const uint8* const tab = constants.getGroupTable (d1, getBits (k)); - const uint8 k0 = tab[0]; - const uint8 k1 = tab[1]; - const uint8 k2 = tab[2]; + auto* tab = constants.getGroupTable (d1, getBits (k)); + auto k0 = tab[0]; + auto k1 = tab[1]; + auto k2 = tab[2]; for (int ch = 0; ch < frame.numChannels; ++ch) { - const uint8 x1 = jmin ((uint8) 63, si.scaleFactor[i][ch][gr]); + auto x1 = jmin ((uint8) 63, si.scaleFactor[i][ch][gr]); fraction[ch][0][i] = (float) constants.muls[k0][x1]; fraction[ch][1][i] = (float) constants.muls[k1][x1]; fraction[ch][2][i] = (float) constants.muls[k2][x1]; @@ -2187,6 +2168,7 @@ private: fraction[0][0][i] = fraction[0][1][i] = fraction[0][2][i] = 0; fraction[1][0][i] = fraction[1][1][i] = fraction[1][2][i] = 0; } + allocTable += (static_cast (1) << step); } @@ -2211,7 +2193,7 @@ private: { for (int ch = 0; ch < stereo; ++ch) { - Layer3SideInfo::Info& granule = sideinfo.ch[ch].gr[gr]; + auto& granule = sideinfo.ch[ch].gr[gr]; granule.part2_3Length = getBits (12); granule.bigValues = jmin (288u, getBitsUnchecked (9)); @@ -2272,7 +2254,7 @@ private: for (int ch = 0; ch < stereo; ++ch) { - Layer3SideInfo::Info& granule = sideinfo.ch[ch].gr[0]; + auto& granule = sideinfo.ch[ch].gr[0]; granule.part2_3Length = getBits (12); granule.bigValues = jmin (288u, getBitsUnchecked (9)); @@ -2421,8 +2403,8 @@ private: { { 6, 9, 9, 9 }, { 6, 9, 12, 6 }, { 15, 18, 0, 0 }, { 6, 15, 12, 0 }, { 6, 12, 9, 6 }, { 6, 18, 9, 0 } } }; - uint32 len = iStereo ? constants.iLength2 [granule.scaleFactorCompression >> 1] - : constants.nLength2 [granule.scaleFactorCompression]; + uint32 len = iStereo ? constants.iLength2[granule.scaleFactorCompression >> 1] + : constants.nLength2[granule.scaleFactorCompression]; granule.preflag = (len >> 15) & 1; @@ -2435,9 +2417,9 @@ private: } const uint8* const data = scaleTable[n][(len >> 12) & 7]; - int i, numBits = 0; + int numBits = 0; - for (i = 0; i < 4; ++i) + for (int i = 0; i < 4; ++i) { int num = len & 7; len >>= 3; @@ -2457,7 +2439,8 @@ private: } n = (n << 1) + 1; - for (i = 0; i < n; ++i) + + for (int i = 0; i < n; ++i) *scf++ = 0; return numBits; @@ -2466,14 +2449,14 @@ private: bool layer3DequantizeSample (float xr[32][18], int* scf, Layer3SideInfo::Info& granule, int sampleRate, int part2bits) noexcept { const uint32 shift = 1 + granule.scaleFactorScale; - float* xrpnt = (float*) xr; - int part2remain = (int) granule.part2_3Length - part2bits; + auto* xrpnt = (float*) xr; + auto part2remain = (int) granule.part2_3Length - part2bits; zeromem (xrpnt, sizeof (float) * (size_t) (&xr[32][0] - xrpnt)); - const int bv = (int) granule.bigValues; - const int region1 = (int) granule.region1Start; - const int region2 = (int) granule.region2Start; + auto bv = (int) granule.bigValues; + auto region1 = (int) granule.region1Start; + auto region2 = (int) granule.region2Start; int l3 = ((576 >> 1) - bv) >> 1; int l[3]; @@ -2514,19 +2497,19 @@ private: { max[3] = -1; max[0] = max[1] = max[2] = 2; - map = constants.map [sampleRate][0]; - mapEnd = constants.mapEnd [sampleRate][0]; + map = constants.map [sampleRate][0]; + mapEnd = constants.mapEnd[sampleRate][0]; } else { max[0] = max[1] = max[2] = max[3] = -1; - map = constants.map [sampleRate][1]; - mapEnd = constants.mapEnd [sampleRate][1]; + map = constants.map [sampleRate][1]; + mapEnd = constants.mapEnd[sampleRate][1]; } for (int i = 0; i < 2; ++i) { - const BitsToTableMap* h = huffmanTables1 + granule.tableSelect[i]; + auto* h = huffmanTables1 + granule.tableSelect[i]; for (int lp = l[i]; lp != 0; --lp, --mc) { @@ -2550,7 +2533,7 @@ private: } } - const int16* val = h->table; + auto* val = h->table; while ((y = *val++) < 0) { @@ -2603,8 +2586,8 @@ private: for (; l3 && (part2remain > 0); --l3) { - const BitsToTableMap* h = huffmanTables2 + granule.count1TableSelect; - const int16* val = h->table; + auto* h = huffmanTables2 + granule.count1TableSelect; + auto* val = h->table; int16 a; while ((a = *val++) < 0) @@ -2616,6 +2599,7 @@ private: } --part2remain; + if (getOneBit()) val -= a; } @@ -2649,6 +2633,7 @@ private: if ((a & (8 >> i))) { max[lwin] = cb; + if (part2remain == 0) break; @@ -2691,25 +2676,25 @@ private: static const int pretab1[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 3, 3, 3, 2, 0 }; static const int pretab2[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; - const int* pretab = (const int*) (granule.preflag ? pretab1 : pretab2); + auto* pretab = (const int*) (granule.preflag ? pretab1 : pretab2); int max = -1, cb = 0, mc = 0; - int* map = constants.map [sampleRate][2]; + auto* map = constants.map[sampleRate][2]; float v = 0; for (int i = 0; i < 3; ++i) { - const BitsToTableMap* h = huffmanTables1 + granule.tableSelect[i]; + auto* h = huffmanTables1 + granule.tableSelect[i]; for (int lp = l[i]; lp != 0; --lp, --mc) { if (mc == 0) { mc = *map++; - v = granule.pow2gain [((*scf++) + (*pretab++)) << shift]; + v = granule.pow2gain[((*scf++) + (*pretab++)) << shift]; cb = *map++; } - const int16* val = h->table; + auto* val = h->table; int y; while ((y = *val++) < 0) @@ -2757,8 +2742,8 @@ private: for (; l3 && part2remain > 0; --l3) { - const BitsToTableMap* h = huffmanTables2 + granule.count1TableSelect; - const int16* values = h->table; + auto* h = huffmanTables2 + granule.count1TableSelect; + auto* values = h->table; int16 a; while ((a = *values++) < 0) @@ -2770,6 +2755,7 @@ private: } --part2remain; + if (getOneBit()) values -= a; } @@ -2782,7 +2768,7 @@ private: { mc = *map++; cb = *map++; - v = granule.pow2gain [((*scf++) + (*pretab++)) << shift]; + v = granule.pow2gain[((*scf++) + (*pretab++)) << shift]; } --mc; } @@ -2824,7 +2810,7 @@ private: void layer3Hybrid (float fsIn[32][18], float tsOut[18][32], int ch, const Layer3SideInfo::Info& granule) noexcept { - float* ts = (float*) tsOut; + auto* ts = (float*) tsOut; float* rawout1, *rawout2; int sb = 0; @@ -2846,7 +2832,8 @@ private: ts += 2; } - const uint32 bt = granule.blockType; + auto bt = granule.blockType; + if (bt == 2) { for (; sb < (int) granule.maxb; sb += 2, ts += 2, rawout1 += 36, rawout2 += 36) @@ -2876,18 +2863,18 @@ private: void synthesiseStereo (const float* bandPtr0, const float* bandPtr1, float* out0, float* out1, int& samplesDone) noexcept { - int dummy = samplesDone; + auto dummy = samplesDone; synthesise (bandPtr0, 0, out0, dummy); synthesise (bandPtr1, 1, out1, samplesDone); } - void synthesise (const float* bandPtr, const int channel, float* out, int& samplesDone) + void synthesise (const float* bandPtr, int channel, float* out, int& samplesDone) { out += samplesDone; const int bo = channel == 0 ? ((synthBo - 1) & 15) : synthBo; float (*buf)[0x110] = synthBuffers[channel]; float* b0; - int j, bo1 = bo; + auto bo1 = bo; if (bo & 1) { @@ -2904,9 +2891,9 @@ private: synthBo = bo; const float* window = constants.decodeWin + 16 - bo1; - for (j = 16; j != 0; --j, b0 += 16, window += 32) + for (int j = 16; j != 0; --j, b0 += 16, window += 32) { - float sum = window[0] * b0[0]; sum -= window[1] * b0[1]; + auto sum = window[0] * b0[0]; sum -= window[1] * b0[1]; sum += window[2] * b0[2]; sum -= window[3] * b0[3]; sum += window[4] * b0[4]; sum -= window[5] * b0[5]; sum += window[6] * b0[6]; sum -= window[7] * b0[7]; @@ -2918,7 +2905,7 @@ private: } { - float sum = window[0] * b0[0]; sum += window[2] * b0[2]; + auto sum = window[0] * b0[0]; sum += window[2] * b0[2]; sum += window[4] * b0[4]; sum += window[6] * b0[6]; sum += window[8] * b0[8]; sum += window[10] * b0[10]; sum += window[12] * b0[12]; sum += window[14] * b0[14]; @@ -2927,9 +2914,9 @@ private: window += bo1 << 1; } - for (j = 15; j != 0; --j, b0 -= 16, window -= 32) + for (int j = 15; j != 0; --j, b0 -= 16, window -= 32) { - float sum = -window[-1] * b0[0]; sum -= window[-2] * b0[1]; + auto sum = -window[-1] * b0[0]; sum -= window[-2] * b0[1]; sum -= window[-3] * b0[2]; sum -= window[-4] * b0[3]; sum -= window[-5] * b0[4]; sum -= window[-6] * b0[5]; sum -= window[-7] * b0[6]; sum -= window[-8] * b0[7]; @@ -3044,7 +3031,7 @@ private: MP3Stream stream; int64 currentPosition; enum { decodedDataSize = 1152 }; - float decoded0 [decodedDataSize], decoded1 [decodedDataSize]; + float decoded0[decodedDataSize], decoded1[decodedDataSize]; int decodedStart, decodedEnd; void createEmptyDecodedData() noexcept diff --git a/modules/juce_audio_formats/codecs/juce_OggVorbisAudioFormat.cpp b/modules/juce_audio_formats/codecs/juce_OggVorbisAudioFormat.cpp index 0a2737bcab..5d7c1a5f8b 100644 --- a/modules/juce_audio_formats/codecs/juce_OggVorbisAudioFormat.cpp +++ b/modules/juce_audio_formats/codecs/juce_OggVorbisAudioFormat.cpp @@ -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 (datasource); + auto* in = static_cast (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 (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 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 r (createReaderFor (in, true)); - - if (r != nullptr) + if (ScopedPointer 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) { diff --git a/modules/juce_audio_formats/codecs/juce_WavAudioFormat.cpp b/modules/juce_audio_formats/codecs/juce_WavAudioFormat.cpp index 34bbc494ef..86e43fd3c6 100644 --- a/modules/juce_audio_formats/codecs/juce_WavAudioFormat.cpp +++ b/modules/juce_audio_formats/codecs/juce_WavAudioFormat.cpp @@ -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) diff --git a/modules/juce_audio_formats/codecs/juce_WindowsMediaAudioFormat.cpp b/modules/juce_audio_formats/codecs/juce_WindowsMediaAudioFormat.cpp index 3167ff3d0d..e685742038 100644 --- a/modules/juce_audio_formats/codecs/juce_WindowsMediaAudioFormat.cpp +++ b/modules/juce_audio_formats/codecs/juce_WindowsMediaAudioFormat.cpp @@ -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 (addBytesToPointer (buffer.getData(), offsetInBuffer * stride)); - const int numToDo = jmin (numSamples, (int) (bufferedRange.getLength() - offsetInBuffer)); + auto offsetInBuffer = (int) (startSampleInFile - bufferedRange.getStart()); + auto* rawData = static_cast (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 (mediaType->pbFormat); + auto* inputFormat = reinterpret_cast (mediaType->pbFormat); sampleRate = inputFormat->nSamplesPerSec; numChannels = inputFormat->nChannels; @@ -328,8 +329,8 @@ WindowsMediaAudioFormat::WindowsMediaAudioFormat() WindowsMediaAudioFormat::~WindowsMediaAudioFormat() {} -Array WindowsMediaAudioFormat::getPossibleSampleRates() { return Array(); } -Array WindowsMediaAudioFormat::getPossibleBitDepths() { return Array(); } +Array WindowsMediaAudioFormat::getPossibleSampleRates() { return {}; } +Array WindowsMediaAudioFormat::getPossibleBitDepths() { return {}; } bool WindowsMediaAudioFormat::canDoStereo() { return true; } bool WindowsMediaAudioFormat::canDoMono() { return true; }