diff --git a/modules/juce_audio_formats/codecs/juce_WavAudioFormat.cpp b/modules/juce_audio_formats/codecs/juce_WavAudioFormat.cpp index d8e75f242a..e55604bdae 100644 --- a/modules/juce_audio_formats/codecs/juce_WavAudioFormat.cpp +++ b/modules/juce_audio_formats/codecs/juce_WavAudioFormat.cpp @@ -300,32 +300,29 @@ namespace WavFileHelpers MemoryBlock data; const int numLoops = jmin (64, values.getValue ("NumSampleLoops", "0").getIntValue()); - if (numLoops > 0) + data.setSize (roundUpSize (sizeof (SMPLChunk) + (size_t) (jmax (0, numLoops - 1)) * sizeof (SampleLoop)), true); + + auto s = static_cast (data.getData()); + + s->manufacturer = getValue (values, "Manufacturer", "0"); + s->product = getValue (values, "Product", "0"); + s->samplePeriod = getValue (values, "SamplePeriod", "0"); + s->midiUnityNote = getValue (values, "MidiUnityNote", "60"); + s->midiPitchFraction = getValue (values, "MidiPitchFraction", "0"); + s->smpteFormat = getValue (values, "SmpteFormat", "0"); + s->smpteOffset = getValue (values, "SmpteOffset", "0"); + s->numSampleLoops = ByteOrder::swapIfBigEndian ((uint32) numLoops); + s->samplerData = getValue (values, "SamplerData", "0"); + + for (int i = 0; i < numLoops; ++i) { - data.setSize (roundUpSize (sizeof (SMPLChunk) + (size_t) (numLoops - 1) * sizeof (SampleLoop)), true); - - SMPLChunk* const s = static_cast (data.getData()); - - s->manufacturer = getValue (values, "Manufacturer", "0"); - s->product = getValue (values, "Product", "0"); - s->samplePeriod = getValue (values, "SamplePeriod", "0"); - s->midiUnityNote = getValue (values, "MidiUnityNote", "60"); - s->midiPitchFraction = getValue (values, "MidiPitchFraction", "0"); - s->smpteFormat = getValue (values, "SmpteFormat", "0"); - s->smpteOffset = getValue (values, "SmpteOffset", "0"); - s->numSampleLoops = ByteOrder::swapIfBigEndian ((uint32) numLoops); - s->samplerData = getValue (values, "SamplerData", "0"); - - for (int i = 0; i < numLoops; ++i) - { - SampleLoop& loop = s->loops[i]; - loop.identifier = getValue (values, i, "Identifier", "0"); - loop.type = getValue (values, i, "Type", "0"); - loop.start = getValue (values, i, "Start", "0"); - loop.end = getValue (values, i, "End", "0"); - loop.fraction = getValue (values, i, "Fraction", "0"); - loop.playCount = getValue (values, i, "PlayCount", "0"); - } + auto& loop = s->loops[i]; + loop.identifier = getValue (values, i, "Identifier", "0"); + loop.type = getValue (values, i, "Type", "0"); + loop.start = getValue (values, i, "Start", "0"); + loop.end = getValue (values, i, "End", "0"); + loop.fraction = getValue (values, i, "Fraction", "0"); + loop.playCount = getValue (values, i, "PlayCount", "0"); } return data;