flac: Fix channel order for mono files.
authorErik de Castro Lopo <erikd@mega-nerd.com>
Sat, 28 Jun 2014 11:45:50 +0000 (21:45 +1000)
committerErik de Castro Lopo <erikd@mega-nerd.com>
Sat, 28 Jun 2014 12:25:18 +0000 (22:25 +1000)
* 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>

src/flac/decode.c
src/flac/encode.c

index 23c6819..266a160 100644 (file)
@@ -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;
index 34760fa..9852ff1 100644 (file)
@@ -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) {