mirror of
https://github.com/claunia/flac.git
synced 2025-12-16 18:54:26 +00:00
flac: Fix channel order for mono files.
* The default channel mask for mono files was 0x0001 (front left) but it makes more sense to use 0x0004 (front center) for such files. * Also FLAC will accept not only mono WAV files with 0x0001 mask, but also with 0x0002 (requested at https://sourceforge.net/p/flac/bugs/390/) and 0x0004 (e.g. SoX creates mono files with this mask). * The comment about channel support was updated. * The error message "Use --channel-map=none option to store channels in current order; FLAC files must also be decoded with --channel-map=none to restore correct order." is misleading: FLAC never changes the order of channels. Decoding with this options also sets the channel mask of the resulting WAV file to 0. Without this option the mask is equal to the value of WAVEFORMATEXTENSIBLE_CHANNEL_MASK tag. Patch-from: lvqcl <lvqcl.mail@gmail.com>
This commit is contained in:
@@ -339,7 +339,7 @@ FLAC__bool DecoderSession_process(DecoderSession *d)
|
||||
/* only the channel mask must be set if it was not already picked up from the WAVEFORMATEXTENSIBLE_CHANNEL_MASK tag */
|
||||
if(!d->channel_map_none && d->channel_mask == 0) {
|
||||
if(d->channels == 1) {
|
||||
d->channel_mask = 0x0001;
|
||||
d->channel_mask = 0x0004;
|
||||
}
|
||||
else if(d->channels == 2) {
|
||||
d->channel_mask = 0x0003;
|
||||
|
||||
@@ -428,14 +428,14 @@ static FLAC__bool get_sample_info_wave(EncoderSession *e, encode_options_t optio
|
||||
/* for mono/stereo and unassigned channels, we fake the mask */
|
||||
if(channel_mask == 0) {
|
||||
if(channels == 1)
|
||||
channel_mask = 0x0001;
|
||||
channel_mask = 0x0004;
|
||||
else if(channels == 2)
|
||||
channel_mask = 0x0003;
|
||||
}
|
||||
/* set channel mapping */
|
||||
/* FLAC order follows SMPTE and WAVEFORMATEXTENSIBLE but with fewer channels, which are: */
|
||||
/* front left, front right, center, LFE, back left, back right, surround left, surround right */
|
||||
/* the default mapping is sufficient for 1-6 channels and 7-8 are currently unspecified anyway */
|
||||
/* front left, front right, front center, LFE, back left, back right, back center, side left, side right */
|
||||
/* the default mapping is sufficient for 1-8 channels */
|
||||
#if 0
|
||||
/* @@@ example for dolby/vorbis order, for reference later in case it becomes important */
|
||||
if(
|
||||
@@ -472,7 +472,9 @@ static FLAC__bool get_sample_info_wave(EncoderSession *e, encode_options_t optio
|
||||
#else
|
||||
if(
|
||||
options.channel_map_none ||
|
||||
channel_mask == 0x0001 || /* 1 channel: (mono) */
|
||||
channel_mask == 0x0001 || /* 1 channel: front left */
|
||||
channel_mask == 0x0002 || /* 1 channel: front right */
|
||||
channel_mask == 0x0004 || /* 1 channel: mono or front center */
|
||||
channel_mask == 0x0003 || /* 2 channels: front left, front right */
|
||||
channel_mask == 0x0007 || /* 3 channels: front left, front right, front center */
|
||||
channel_mask == 0x0033 || /* 4 channels: front left, front right, back left, back right */
|
||||
@@ -488,7 +490,7 @@ static FLAC__bool get_sample_info_wave(EncoderSession *e, encode_options_t optio
|
||||
}
|
||||
#endif
|
||||
else {
|
||||
flac__utils_printf(stderr, 1, "%s: ERROR: WAVEFORMATEXTENSIBLE chunk with unsupported channel mask=0x%04X\n\nUse --channel-map=none option to store channels in current order; FLAC files\nmust also be decoded with --channel-map=none to restore correct order.\n", e->inbasefilename, (unsigned)channel_mask);
|
||||
flac__utils_printf(stderr, 1, "%s: ERROR: WAVEFORMATEXTENSIBLE chunk with unsupported channel mask=0x%04X\n\nUse --channel-map=none option to encode the input\n", e->inbasefilename, (unsigned)channel_mask);
|
||||
return false;
|
||||
}
|
||||
if(!options.channel_map_none) {
|
||||
|
||||
Reference in New Issue
Block a user