Skip to contentSkip to conversation

ALSA: Tascam US-16x08 DSP mixer quirk

PATCH Superseded OnkelDead 1 participant 1 message Feb 9, 2017 Sound

v4 of 9 Superseded Latest is v9 →

lore
Share & tools
lore

OnkelDead

author
#0 lore raw

PATCH v4 1/1 ALSA: Tascam US-16x08 DSP mixer quirk

Ok, here my result

Quoted 7 lines

Review

Quoted 4 lines
(quoted diff) +4 -0
+#include <linux/slab.h>
+#include <linux/usb.h>
+#include <linux/usb/audio-v2.h>
+#include "linux/kthread.h"

Why kthread? Also why double-quote, not bracket?

Quoted 7 lines

Review

Quoted 4 lines
(quoted diff) +4 -0
+
+#include <sound/core.h>
+#include <sound/control.h>
+#include <asm-generic/errno-base.h>

This looks very wrong. Just include <linux/errno.h> if really needed (I guess you won't).

Indeed! Includes removed

Quoted 4 lines
Quoted 2 lines

+/* wrapper function to send prepared URB buffer to usb device. Return -1
+ * if something went wrong

It's always better to return a negative error code instead of -1.

Now returns correct errno

Quoted 6 lines

Review

Quoted 3 lines
(quoted diff) +3 -0
+    if (err == 0) {
+        store->value[index] = val;
+        elem->cached &= 1 << index;

Do you mean "|="? Otherwise the cache value is set exclusively. (Ditto for all other places.)

Absolutely right, fixed.

Quoted 20 lines
Quoted 9 lines
(quoted diff) +9 -0
+    switch (elem->head.id) {
+    case SND_US16X08_ID_COMP_THRESHOLD:
+        val = store->valThreshold[index];
+        break;
+    case SND_US16X08_ID_COMP_RATIO:
+        val = store->valRatio[index];
+        break;
+    case SND_US16X08_ID_COMP_ATTACK:
+        val = store->valAttack[index];

Review

Quoted 10 lines
(quoted diff) +10 -0
+        break;
+    case SND_US16X08_ID_COMP_RELEASE:
+        val = store->valRelease[index];
+        break;
+    case SND_US16X08_ID_COMP_GAIN:
+        val = store->valGain[index];
+        break;
+    case SND_US16X08_ID_COMP_SWITCH:
+        val = store->valSwitch[index];
+        break;
Quoted 6 lines

Wouldn't it be easier to have something like:

   val_idx = elem_id_to_idx(elem->head.id);
   val = store->values[val_id][index];

A series of switch/case doesn't look good.

Good advise, I've changed the store structs accordingly. More about those shadow stores later.

Quoted 8 lines

Review

Quoted 6 lines
(quoted diff) +6 -0
+    buf[20] = store->low_store->valSwitch[index];
+    buf[17] = store->low_store->valWidth[index];
+    buf[14] = store->low_store->valFreq[index];
+    buf[11] = store->low_store->valdB[index];
+    buf[8] = 0x01;
+    err = snd_us16x08_send_urb(chip, buf, sizeof(eqs_msq));

No error check?

Fixed.

Quoted 7 lines

Review

Quoted 3 lines
(quoted diff) +2 -0
+    /* give time to the device to handle the request */
+    mdelay(15);

Does it have to be mdelay(), not msleep() or its variant? mdelay() with such a long time is usually something wrong.

Quoted 6 lines

Review

Quoted 4 lines
(quoted diff) +4 -0
+/* setup EQ store and assign default values */
+static struct snd_us16x08_eq_store *snd_us16x08_create_eq_store(int band_index)
+{
+    int i = 0;

Superfluous initialization.

Fixed.

Quoted 16 lines

Review

Quoted 11 lines
(quoted diff) +11 -0
+/* suspend/resume */
+
+static void snd_us16x08_resume_route(struct usb_mixer_elem_info *elem)
+{
+    int i;
+    struct snd_us16x08_common *store =
+        (struct snd_us16x08_common *) elem->private_data;
+
+    for (i = 0; i < elem->channels; i++)
+        if (elem->cached & (1 << i))
+            store->value[i] = elem->cache_val[i];

Does it make sense? The resume function resumes the device, and it's not about the memory we manage by ourselves. Usually the resume function writes back the cached value to the device.

Quoted 2 lines

If store->value[] and elem->cache_val[] is always identical, we can drop even store->value[].

A first impression must lead in your concern.
But using those shadow caches is important, cause the device expects multiple control values in a single URB message.
If e.g. the threshold of a compressor got changed, the driver has to send new threshold AND current ratio, attack, release etc. in a single command. I didn't found a solution for cross-mixer-element-cache-access. Any hints ?

I've removed all shadow caches where not needed.

I've remove the resume callback, the device is self powered and has its own suspend/resume mechanism.

Quoted 15 lines
Quoted 4 lines
(quoted diff) +4 -0
+    { /* EQ high gain */
+        .kcontrol_new = &snd_us16x08_eq_gain_ctl,
+        .control_id = SND_US16X08_ID_EQHIGHLEVEL,
+        .type = USB_MIXER_U8,

Review

Quoted 10 lines
(quoted diff) +10 -0
+        .num_channels = 16,
+        .name = "High gain",
+        .freeer = snd_usb_mixer_elem_free
+    },
+    { /* EQ low freq */
+        .kcontrol_new = &snd_us16x08_eq_high_freq_ctl,
+        .control_id = SND_US16X08_ID_EQHIGHFREQ,
+        .type = USB_MIXER_U8,
+        .num_channels = 16,
+        .name = "High freq",
Quoted 1 line

These mixer control names look somehow too ambiguous...

I've tried to keep them short, they are somehow equal to those in the MS control panel I'd lean on.
Still unchanged.

Quoted 11 lines

Review

Quoted 10 lines
(quoted diff) +10 -0
+    struct snd_us16x08_eq_store *eq_high_store =
+        snd_us16x08_create_eq_store(0x04);
+    struct snd_us16x08_eq_all_store *eq_all_store =
+        kmalloc(sizeof(struct snd_us16x08_eq_all_store), GFP_KERNEL);
+
+    /* check for allocation error */
+    if (eq_low_store == NULL || eq_midlow_store == NULL ||
+        eq_midhigh_store == NULL || eq_high_store == NULL ||
+        eq_all_store == NULL)
+        return -ENOMEM;
Quoted 1 line

This leaks the memory. You forgot to release non-NULL ones.

Fixed.

Quoted 11 lines

Review

Quoted 9 lines
(quoted diff) +9 -0
+        /* create bus store */
+        bus_store = snd_us16x08_create_bus_store(0);
+        if (bus_store == NULL)
+            return -ENOMEM;
+
+        /* create channel store */
+        channel_store = snd_us16x08_create_channel_store();
+        if (channel_store == NULL)
+            return -ENOMEM;

Ditto.

Fixed.

Quoted 24 lines
Quoted 24 lines
(quoted diff) +24 -0
+        err = add_new_ctl(mixer, &snd_us16x08_bus_ctl,
+            SND_US16X08_ID_MUTE, USB_MIXER_U8, 1, "Master mute",
+            (void *) bus_store, NULL);
+        if (err < 0)
+            return err;
+
+        err = add_new_ctl(mixer, &snd_us16x08_ch_boolean_ctl,
+            SND_US16X08_ID_PHASE, USB_MIXER_U8, 16, "Phase",
+            (void *) channel_store,
+            snd_usb_mixer_elem_free);
+        if (err < 0)
+            return err;
+
+        err = add_new_ctl(mixer, &snd_us16x08_ch_int_ctl,
+            SND_US16X08_ID_FADER, USB_MIXER_S16, 16, "Fader",
+            (void *) channel_store, NULL);
+        if (err < 0)
+            return err;
+
+        err = add_new_ctl(mixer, &snd_us16x08_ch_boolean_ctl,
+            SND_US16X08_ID_MUTE, USB_MIXER_BOOLEAN, 16, "Mute",
+            (void *) channel_store, NULL);
+
+        if (err < 0)
Quoted 8 lines

Review

Quoted 5 lines
(quoted diff) +5 -0
+            return err;
+
+        err = add_new_ctl(mixer, &snd_us16x08_ch_int_ctl,
+            SND_US16X08_ID_PAN, USB_MIXER_U16, 16, "Pan",
+            (void *) channel_store, NULL);

Can we use a table for registration, too?
This sequence of calls looks... well, a lot of room to optimize

Fixed, tables are in place.

Quoted 11 lines

Review

Quoted 5 lines
(quoted diff) +5 -0
+struct snd_us16x08_eq_store {
+    u8 valdB[SND_US16X08_MAX_CHANNELS];
+    u8 valFreq[SND_US16X08_MAX_CHANNELS];
+    u8 valWidth[SND_US16X08_MAX_CHANNELS];
+    u8 valSwitch[SND_US16X08_MAX_CHANNELS];

Please avoid thisSomething, but use this_something (dB might be an exception, though).
In this case, val prefix can be dropped, too. It's just superfluous.

Quoted 10 lines

Review

Quoted 8 lines
(quoted diff) +8 -0
+struct snd_us16x08_comp_store {
+    u8 valThreshold[SND_US16X08_MAX_CHANNELS];
+    u8 valAttack[SND_US16X08_MAX_CHANNELS];
+    u8 valRelease[SND_US16X08_MAX_CHANNELS];
+    u8 valRatio[SND_US16X08_MAX_CHANNELS];
+    u8 valGain[SND_US16X08_MAX_CHANNELS];
+    u8 valSwitch[SND_US16X08_MAX_CHANNELS];
+};

Ditto.

Fixed.

Add mixer quirk for Tascam US-16x08 usb interface. Even that this an usb compliant device,
the input channels and DSP functions (EQ/Compressor) arn't accessible by default.

---
 sound/usb/Makefile        |    1 +
 sound/usb/mixer_quirks.c  |    5 +
 sound/usb/mixer_us16x08.c | 1425 +++++++++++++++++++++++++++++++++++++++++++++
 sound/usb/mixer_us16x08.h |  122 ++++
 4 files changed, 1553 insertions(+)
 create mode 100644 sound/usb/mixer_us16x08.c
 create mode 100644 sound/usb/mixer_us16x08.h
sound/usb/Makefile +1 -0
index 2d2d122..42cb33b 100644
@@ -10,6 +10,7 @@ snd-usb-audio-objs := 	card.o \
 			mixer.o \
 			mixer_quirks.o \
 			mixer_scarlett.o \
+			mixer_us16x08.o \
 			pcm.o \
 			proc.o \
 			quirks.o \
sound/usb/mixer_quirks.c +5 -0
index 04991b0..4fa0053 100644
@@ -43,6 +43,7 @@
 #include "mixer.h"
 #include "mixer_quirks.h"
 #include "mixer_scarlett.h"
+#include "mixer_us16x08.h"
 #include "helper.h"
 
 extern struct snd_kcontrol_new *snd_usb_feature_unit_ctl;
@@ -1729,6 +1730,10 @@ int snd_usb_mixer_apply_create_quirk(struct usb_mixer_interface *mixer)
 		return err;
 
 	switch (mixer->chip->usb_id) {
+	/* Tascam US-16x08 */
+	case USB_ID(0x0644, 0x8047):
+		err = snd_us16x08_controls_create(mixer);
+		break;
 	case USB_ID(0x041e, 0x3020):
 	case USB_ID(0x041e, 0x3040):
 	case USB_ID(0x041e, 0x3042):
sound/usb/mixer_us16x08.c new file +1425 -0

1,425 lines not on this page · raw message

sound/usb/mixer_us16x08.h new file +122 -0

122 lines not on this page · raw message

Signature · 1 line
2.7.4