From 79110aae25ff28b0a2142feaeb194d8ec2846b5e Mon Sep 17 00:00:00 2001 From: hogliux Date: Mon, 31 Jul 2017 12:49:19 +0100 Subject: [PATCH] WavAudioFormatWriter: Fixed an issue where wav files with large channel counts could no longer be created --- .../codecs/juce_WavAudioFormat.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/modules/juce_audio_formats/codecs/juce_WavAudioFormat.cpp b/modules/juce_audio_formats/codecs/juce_WavAudioFormat.cpp index 5c2cd44644..304772fd8a 100644 --- a/modules/juce_audio_formats/codecs/juce_WavAudioFormat.cpp +++ b/modules/juce_audio_formats/codecs/juce_WavAudioFormat.cpp @@ -1353,9 +1353,10 @@ private: const size_t bytesPerFrame = numChannels * bitsPerSample / 8; uint64 audioDataSize = bytesPerFrame * lengthInSamples; + auto channelMask = getChannelMaskFromChannelLayout (channelLayout); const bool isRF64 = (bytesWritten >= 0x100000000LL); - const bool isWaveFmtEx = isRF64 || (numChannels > 2); + const bool isWaveFmtEx = isRF64 || (channelMask != 0); int64 riffChunkSize = (int64) (4 /* 'RIFF' */ + 8 + 40 /* WAVEFORMATEX */ + 8 + audioDataSize + (audioDataSize & 1) @@ -1431,7 +1432,7 @@ private: { output->writeShort (22); // cbSize (size of the extension) output->writeShort ((short) bitsPerSample); // wValidBitsPerSample - output->writeInt (getChannelMaskFromChannelLayout (channelLayout)); + output->writeInt (channelMask); const ExtensibleWavSubFormat& subFormat = bitsPerSample < 32 ? pcmFormat : IEEEFloatFormat; @@ -1475,6 +1476,9 @@ private: static int getChannelMaskFromChannelLayout (const AudioChannelSet& channelLayout) { + if (channelLayout.isDiscreteLayout() || channelLayout == AudioChannelSet::mono()) + return 0; + auto channels = channelLayout.getChannelTypes(); auto wavChannelMask = 0; @@ -1610,6 +1614,10 @@ bool WavAudioFormat::isChannelLayoutSupported (const AudioChannelSet& channelSet { auto channelTypes = channelSet.getChannelTypes(); + // When + if (channelSet.isDiscreteLayout()) + return true; + // WAV supports all channel types from left ... topRearRight for (auto channel : channelTypes) if (channel < AudioChannelSet::left || channel > AudioChannelSet::topRearRight)