]> git.alsa-project.org Git - alsa-plugins.git/commitdiff
Misc fixes for upmix plugin
authorTakashi Iwai <tiwai@suse.de>
Thu, 6 Apr 2006 15:41:46 +0000 (17:41 +0200)
committerTakashi Iwai <tiwai@suse.de>
Thu, 6 Apr 2006 15:41:46 +0000 (17:41 +0200)
- Add channel option to specify the output channels explicitly
- Fix 6-channel input

doc/upmix.txt
mix/pcm_upmix.c

index b8a6da4e554d233abf4d664bbf6da72db10ea07f..56720a42dd5f2962a56c43114b7441e62d4463e0 100644 (file)
@@ -1,10 +1,10 @@
 UPMIX PLUGIN
 ============
 
-The upmix plugin is an easy-to-use plugin for upmixing from 1 or 2
-channel stream to 4 or 6-channel stream.  The number of channels to be
-expanded is determined by the slave PCM.  For example, the following
-PCM defines upmixing to 5.1 from 2-6 channels input:
+The upmix plugin is an easy-to-use plugin for upmixing to 4 or
+6-channel stream.  The number of channels to be expanded is determined
+by the slave PCM or explicitly via channel option.  For example, the
+following PCM defines upmixing to 5.1 from 1-6 channels input:
 
        pcm.upmix51 {
                type upmix
@@ -22,12 +22,23 @@ option in msec.  For example, to set 10ms delay in the above case:
        pcm.upmix51 {
                type upmix
                slave.pcm "surround51"
-               channels 6
                delay 10
        }
 
 As default, 15ms delay is used.
 
+The channel option specifies the number of channels of output.  Either
+4 or 6 channels are supported.  When 0 is passed, the plugin tries 4
+or 6 channels appropriately suitable for the slave pcm.  The channel
+option is useful if the slave PCM has no strict input condition (like
+plug or route plugin).
+
+       pcm.myupmix {
+               type upmix
+               slave.pcm "something"
+               channels 6
+       }
+
 The center and LFE channels are the average of sum of left and right
 signals.
 
index ed8d041578d20bc9f566fea9f304b48cb042c66e..9ca5bf4e4b7485ecf7186cb33e237cec04ca1d0a 100644 (file)
@@ -290,8 +290,10 @@ static int upmix_init(snd_pcm_extplug_t *ext)
 
        stype = (ext->slave_channels == 6) ? 1 : 0;
        ctype = ext->channels - 1;
-       if (ctype < 0 || ctype >= 5)
+       if (ctype < 0 || ctype > 5) {
+               SNDERR("Invalid channel numbers for upmix: %d", ctype + 1);
                return -EINVAL;
+       }
        mix->upmix = do_upmix[ctype][stype];
 
        if (mix->delay_ms) {
@@ -327,6 +329,7 @@ SND_PCM_PLUGIN_DEFINE_FUNC(upmix)
        snd_pcm_upmix_t *mix;
        snd_config_t *sconf = NULL;
        static unsigned int chlist[2] = {4, 6};
+       unsigned int channels = 0;
        int delay = 10;
        int err;
 
@@ -350,6 +353,20 @@ SND_PCM_PLUGIN_DEFINE_FUNC(upmix)
                        }
                        delay = val;
                }
+               if (strcmp(id, "channels") == 0) {
+                       long val;
+                       err = snd_config_get_integer(n, &val);
+                       if (err < 0) {
+                               SNDERR("Invalid value for %s", id);
+                               return err;
+                       }
+                       channels = val;
+                       if (channels != 4 && channels != 6 && channels != 0) {
+                               SNDERR("channels must be 4, 6 or 0");
+                               return -EINVAL;
+                       }
+                       continue;
+               }
                SNDERR("Unknown field %s", id);
                return -EINVAL;
        }
@@ -382,9 +399,14 @@ SND_PCM_PLUGIN_DEFINE_FUNC(upmix)
        snd_pcm_extplug_set_param_minmax(&mix->ext,
                                         SND_PCM_EXTPLUG_HW_CHANNELS,
                                         1, 6);
-       snd_pcm_extplug_set_slave_param_list(&mix->ext,
-                                            SND_PCM_EXTPLUG_HW_CHANNELS,
-                                            2, chlist);
+       if (channels)
+               snd_pcm_extplug_set_slave_param_minmax(&mix->ext,
+                                                      SND_PCM_EXTPLUG_HW_CHANNELS,
+                                                      channels, channels);
+       else
+               snd_pcm_extplug_set_slave_param_list(&mix->ext,
+                                                    SND_PCM_EXTPLUG_HW_CHANNELS,
+                                                    2, chlist);
        snd_pcm_extplug_set_param(&mix->ext, SND_PCM_EXTPLUG_HW_FORMAT,
                                  SND_PCM_FORMAT_S16);
        snd_pcm_extplug_set_slave_param(&mix->ext, SND_PCM_EXTPLUG_HW_FORMAT,