flac: Use WAVEFORMATEXTENSIBLE when bps != (8|16)

When decoding to WAV, the legacy wFormatTag of WAVE_FORMAT_PCM should
only be used if the bitwidth is 8 or 16. For all other bitwidths,
use WAVEFORMATEXTENSIBLE.

Two of the test programs/scripts also needed updating.
This commit is contained in:
Erik de Castro Lopo 2017-05-27 16:07:35 +10:00
parent b762a20ace
commit bb75073428
3 changed files with 3 additions and 7 deletions

View File

@ -582,7 +582,7 @@ FLAC__bool write_iff_headers(FILE *f, DecoderSession *decoder_session, FLAC__uin
(format == FORMAT_WAVE || format == FORMAT_WAVE64 || format == FORMAT_RF64) &&
(
(decoder_session->channel_mask != 0 && decoder_session->channel_mask != 0x0004 && decoder_session->channel_mask != 0x0003) ||
decoder_session->bps%8 ||
(decoder_session->bps != 8 && decoder_session->bps != 16) ||
decoder_session->channels > 2
);
const FLAC__uint64 data_size = samples * decoder_session->channels * ((decoder_session->bps+7)/8);

View File

@ -718,11 +718,7 @@ foo:
/* flavor is: 0:WAVE, 1:RF64, 2:WAVE64 */
static FLAC__bool generate_wav(const char *filename, unsigned sample_rate, unsigned channels, unsigned bps, unsigned samples, FLAC__bool strict, int flavor)
{
const FLAC__bool waveformatextensible = strict && (channels > 2 || (bps%8));
/* ^^^^^^^
* (bps%8) allows 24 bps which is technically supposed to be WAVEFORMATEXTENSIBLE but we
* write 24bps as WAVEFORMATEX since it's unambiguous and matches how flac writes it
*/
const FLAC__bool waveformatextensible = strict && (channels > 2 || (bps != 8 && bps != 16));
const unsigned bytes_per_sample = (bps+7)/8;
const unsigned shift = (bps%8)? 8 - (bps%8) : 0;

View File

@ -40,7 +40,7 @@ my $bigdatasize = $bigsamples * $bps * $channels;
my $padding = int($bigdatasize & 1); # for aiff/wave/rf64 chunk alignment
my $padding8 = 8 - int($bigdatasize & 7); $padding8 = 0 if $padding8 == 8; # for wave64 alignment
# wave-ish file needs to be WAVEFORMATEXTENSIBLE?
my $wavx = ($format eq 'wave' || $format eq 'wave64' || $format eq 'rf64') && ($channels > 2);
my $wavx = ($format eq 'wave' || $format eq 'wave64' || $format eq 'rf64') && ($channels > 2 || ($bps != 8 && $bps != 16));
# write header