Skip to content

Commit

Permalink
WavAudioFormatWriter: Fixed an issue where wav files with large chann…
Browse files Browse the repository at this point in the history
…el counts could no longer be created
  • Loading branch information
hogliux committed Jul 31, 2017
1 parent 708360e commit 0cf21a4
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions modules/juce_audio_formats/codecs/juce_WavAudioFormat.cpp
Expand Up @@ -1353,9 +1353,10 @@ class WavAudioFormatWriter : public AudioFormatWriter

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)
Expand Down Expand Up @@ -1431,7 +1432,7 @@ class WavAudioFormatWriter : public AudioFormatWriter
{
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;

Expand Down Expand Up @@ -1475,6 +1476,9 @@ class WavAudioFormatWriter : public AudioFormatWriter

static int getChannelMaskFromChannelLayout (const AudioChannelSet& channelLayout)
{
if (channelLayout.isDiscreteLayout() || channelLayout == AudioChannelSet::mono())
return 0;

auto channels = channelLayout.getChannelTypes();
auto wavChannelMask = 0;

Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 0cf21a4

Please sign in to comment.