Commits

Anonymous committed e1653d2

Added channel remapping support to vmixctl

Comments (0)

Files changed (10)

cmd/vmixctl/vmixctl.c

 	fprintf (stdout, "%s attach [attach_options...] devname inputdev\n", cmdname);
 	fprintf (stdout, "%s detach devname\n", cmdname);
 	fprintf (stdout, "%s rate devname samplerate\n", cmdname);
+	fprintf (stdout, "%s remap devname channels\n", cmdname);
 	fprintf (stdout, "\n");
 	fprintf (stdout, "Use ossinfo -a to find out the devname and inputdev parameters\n");
 	fprintf (stdout, "Use ossinfo -a -v2 to find out a suitable sample rate.\n");
 	return 0;
 }
 
+static int
+vmix_remap(int argc, char **argv)
+{
+	int i;
+	int masterfd;
+	int masterdev;
+
+	vmixctl_map_t map;
+
+	if (argc<4)
+	{
+		usage ();
+	}
+
+	masterdev=find_audiodev(argv[2], O_WRONLY, &masterfd);
+	memset (&map, 0, sizeof (map));
+
+	map.masterdev=masterdev;
+	map.map[0]=atoi(argv[3]);
+
+        for (i=4; i<argc; i++)
+	{
+		map.map[i-3] = atoi(argv[i]);
+	}
+
+	if (ioctl(masterfd, VMIXCTL_REMAP, &map)==-1)
+	{
+		perror("VMIXCTL_REMAP");
+		exit(-1);
+	}
+
+	fprintf (stdout, "Virtual mixer map change requested.\n");
+
+	return 0;
+}
+
 int
 main(int argc, char **argv)
 {
 	if (strcmp(argv[1], "rate")==0)
 	   exit(vmix_rate(argc, argv));
 
+	if (strcmp(argv[1], "remap")==0)
+	   exit(vmix_remap(argc, argv));
+
 	usage();
 	exit(0);
 }

cmd/vmixctl/vmixctl.man

 o	vmixctl attach [attach_options...] audiodev [inputdev]
 o	vmixctl detach [attach_options...] audiodev
 o	vmixctl rate audiodev samplerate
+o	vmixctl remap audiodev channels
 
 DESCRIPTION
 The vmixctl program can be used to attach or detach the virtual mixer subsystem
 the "ossinfo -a" command.
 
  ATTACH OPTIONS
-o	-r	Disable recording functionality. By default vmix will suppor
+o	-r	Disable recording functionality. By default vmix will support
 		recording if the master device(s) support it.
 o	-p	Do not preallocate client engines. By default vmix will
 		preallocate first 4 (out of 8) client engines when attaching
 not changeable by vmixctl.
 
  EXAMPLE
-o	vmixctl rate /dev/oss/oss_envy240/pcm0
+o	vmixctl rate /dev/oss/oss_envy240/pcm0 44100
+
+CHANGING THE VMIX CHANNEL MAP
+The vmix subsystem can remap channels, so that all output sent to a channel via
+vmix will end up being played on a different channel. The syntax uses a list of
+channels, where typically 0=default, 1=left, 2=right, 3=center, 4=lfe,
+5=left surround, 6=right surround, 7=left rear and 8=right rear.
+Note that vmix-channels should be set first to Multich if vmix is to recognize
+the extra channels.
+
+ EXAMPLES
+o	vmixctl remap /dev/dsp 2 1 #switch left and right
+o	vmixctl remap /dev/dsp 0 0 0 0 6 5 #switch left and right surround
 
 DETACHING VMIX FROM AN AUDIO DEVICE
 It is possible to detach vmix from an audio device if it causes problems

kernel/framework/include/internal.h

 	int rate;
 } vmixctl_rate_t;
 
+typedef int oss_chninfo[128];
+typedef struct
+{
+	int masterdev;
+	oss_chninfo map;
+} vmixctl_map_t;
+
 #define VMIXCTL_ATTACH		__SIOW ('X', 220, vmixctl_attach_t)
 #define VMIXCTL_DETACH		__SIOW ('X', 221, vmixctl_attach_t)
 #define VMIXCTL_RATE		__SIOW ('X', 222, vmixctl_rate_t)
+#define VMIXCTL_REMAP		__SIOW ('X', 223, vmixctl_map_t)
 
 /*
  * FreeBSD compatibility ioctl

kernel/framework/include/oss_calls.h

 extern int vmix_create_client(void *vmix_mixer);
 extern void vmix_change_devnames(void *vmix_mixer, const char *name);
 extern int vmix_set_master_rate(int masterdev, int rate);
+extern int vmix_set_channel_map(int masterdev, void *map);
 
 /*
  * oss_audio_core.c

kernel/framework/mixer/oss_mixer_core.c

 
 	return 0;
 }
+
+static int
+vmixctl_map_channels(vmixctl_map_t *map)
+{
+	int err;
+
+	if (map->masterdev < 0 || map->masterdev >= num_audio_engines)
+	   return OSS_ENXIO;
+
+	if ((err = vmix_set_channel_map (map->masterdev, &map->map)) < 0)
+	  return err;
+
+	return 0;
+}
 #endif
 
 int
 #endif
       return vmixctl_rate((vmixctl_rate_t*)arg);
       break;
+
+    case VMIXCTL_REMAP:
+#ifdef GET_PROCESS_UID
+	if (GET_PROCESS_UID () != 0)	/* Not root */
+	  return OSS_EINVAL;
+#endif
+      return vmixctl_map_channels((vmixctl_map_t *)arg);
+      break;
+
 #endif
 
 #if 0

kernel/framework/vmix_core/outexport.inc

  */
 #define COPYING4 Copyright (C) Hannu Savolainen and Dev Mazumdar 2006-2007. All rights reserved.
 
-int i, ch;
+int i, ch, och;
 double vol;
 
 vol = vmix_db_table[eng->outvol / 5];
     double vu;
     float *chbuf;
 
+    och = eng->channel_order[ch];
     op = (SAMPLE_TYPE *) outbuf;
-    op += ch;
+    op += och;
 
     chbuf = chbufs[ch];
 
-    vu = eng->vu[ch % 2];
+    vu = eng->vu[och % 2];
     vu = vu / 255.0;
 
     for (i = 0; i < samples; i++)
 	  vu = tmp;
       }
 
-    if (ch < 2)
+    if (och < 2)
       {
 	vu = vu * 255.0;
-	eng->vu[ch] = (int)vu;
+	eng->vu[och] = (int)vu;
       }
   }
 #else

kernel/framework/vmix_core/outexport_int.inc

  */
 #define COPYING4 Copyright (C) Hannu Savolainen and Dev Mazumdar 2006-2007. All rights reserved.
 
-int i, ch;
+int i, ch, och;
 int vol;
 
 #define RANGE_MAX	((1<<24)-1)
     int vu;
     int *chbuf;
 
+    och = eng->channel_order[ch];
     op = (SAMPLE_TYPE *) outbuf;
-    op += ch;
+    op += och;
 
     chbuf = chbufs[ch];
 
-    vu = eng->vu[ch % 2];
+    vu = eng->vu[och % 2];
     vu = vu * 65536;
 
     for (i = 0; i < samples; i++)
 	  vu = tmp;
       }
 
-    if (ch < 2)
+    if (och < 2)
       {
 	vu = vu / 65536;
-	eng->vu[ch] = vu;
+	eng->vu[och] = vu;
       }
   }

kernel/framework/vmix_core/vmix.h

 typedef struct _vmix_mixer_t vmix_mixer_t;
 typedef struct _vmix_portc_t vmix_portc_t;
 typedef struct _vmix_engine_t vmix_engine_t;
+typedef unsigned char vmix_channel_map_t[MAX_PLAY_CHANNELS];
 
 struct _vmix_portc_t		/* Audio device specific data */
 {
   void (*play_mixing_func) (vmix_portc_t * portc, int nsamples);
   void (*rec_mixing_func) (vmix_portc_t * portc, int nsamples);
   int do_src;
+  vmix_channel_map_t channel_order;
 };
 
 #ifdef CONFIG_OSS_VMIX_FLOAT
   int outvol;
   int vu[2];
   int num_active_outputs;
+  vmix_channel_map_t channel_order;
 };
 
 struct _vmix_mixer_t		/* Instance specific data */

kernel/framework/vmix_core/vmix_core.c

 	return create_input_controls (mixer_dev);
 }
 
+static int
+vmix_process_chninfo (vmix_channel_map_t * output, oss_chninfo * input,
+                      int maxchan)
+{
+  int i, val;
+
+  for (i=0; i < sizeof (vmix_channel_map_t); i++)
+    {
+      val = (*input)[i];
+      if ((val <= 0) || (val > maxchan) || (val == i+1))
+       {
+         (*input)[i] = 0;
+         (*output)[i] = i;
+       }
+      else
+       {
+         (*output)[i] = val-1;
+       }
+    }
+  return 0;
+}
+
 /*
  * Audio virtual device routines
  */
   vmix_mixer_t *mixer=NULL;
   int reattach=0;
   int err;
+  int i;
 
   if (vmix_disabled) /* Vmix not available in the system */
      return OSS_EIO;
 #ifndef CONFIG_OSS_VMIX_FLOAT
   mixer->play_engine.outvol -= 3;	/* For overflow protection */
 #endif
+  for (i = 0; i < sizeof (vmix_channel_map_t); i++)
+    mixer->play_engine.channel_order[i] = i;
 
   mixer->masterdev = masterdev;
   mixer->inputdev = inputdev;
 }
 
 int
+vmix_set_channel_map (int masterdev, void * map)
+{
+  vmix_mixer_t *mixer;
+
+  if (masterdev < 0 || masterdev >= num_audio_engines)
+    return OSS_ENXIO;
+
+  mixer = audio_engines[masterdev]->vmix_mixer;
+
+  if (mixer == NULL)
+    return OSS_EPERM;
+
+  return vmix_process_chninfo (&mixer->play_engine.channel_order, map,
+                               mixer->play_engine.channels);
+}
+
+int
 vmix_create_client(void *mixer_)
 {
   int engine_num=-1, i;

kernel/framework/vmix_core/vmix_output.c

       return;
     }
 
+  if (mixer->play_engine.channels > 2)
+    {
+      DDB (cmn_err
+	   (CE_CONT, "Enabling multi channel play mode, %d hw channels\n",
+	    mixer->play_engine.channels));
+    }
+  else if (mixer->play_engine.channels != 2)
+    {
+      cmn_err (CE_WARN,
+	       "Master device doesn't support suitable channel configuration\n");
+
+      return;
+    }
+
   mixer->play_engine.rate =
     oss_audio_set_rate (mixer->masterdev, mixer->rate);
   mixer->rate = mixer->play_engine.rate;
 
   mixer->play_engine.fragsize = dmap->fragment_size;
 
-  if (mixer->play_engine.channels > 2)
-    {
-      DDB (cmn_err
-	   (CE_CONT, "Enabling multi channel play mode, %d hw channels\n",
-	    mixer->play_engine.channels));
-    }
-  else if (mixer->play_engine.channels != 2)
-    {
-      cmn_err (CE_WARN,
-	       "Master device doesn't support suitable channel configuration\n");
-
-      return;
-    }
-
 /* 
  * Determine how many fragments we need to keep filled. 
  */
     }
 
   for (i = 0; i < mixer->play_engine.channels; i++)
-    if (mixer->play_engine.chbufs[i] == NULL)	/* Not allocated yet */
-      {
-	mixer->play_engine.chbufs[i] =
-	  PMALLOC (mixer->master_portc,
-		   CHBUF_SAMPLES * sizeof (vmix_sample_t));
-	if (mixer->play_engine.chbufs[i] == NULL)
-	  {
-	    cmn_err (CE_WARN, "Out of memory\n");
-	    return;
-	  }
-      }
+    {
+      if (mixer->play_engine.chbufs[i] == NULL)	/* Not allocated yet */
+	{
+	  mixer->play_engine.chbufs[i] =
+	    PMALLOC (mixer->master_portc,
+		     CHBUF_SAMPLES * sizeof (vmix_sample_t));
+	  if (mixer->play_engine.chbufs[i] == NULL)
+	    {
+	      cmn_err (CE_WARN, "Out of memory\n");
+	      return;
+	    }
+	}
+
+      if (mixer->play_engine.channel_order[i] >= mixer->play_engine.channels)
+	mixer->play_engine.channel_order[i] = i;
+    }
 
   dmap->audio_callback = vmix_play_callback;	/* Enable conversions */
   dmap->callback_parm = mixer->instance_num;