* [PATCH 1/2] ALSA: usb-audio: Add a volume scale quirk for AudioQuest DragonFly @ 2015-08-16 12:50 Anssi Hannula 2015-08-16 12:50 ` [PATCH 2/2] ALSA: usb-audio: Add sample rate inquiry " Anssi Hannula 2015-08-17 14:16 ` [PATCH 1/2] ALSA: usb-audio: Add a volume scale " Takashi Iwai 0 siblings, 2 replies; 9+ messages in thread From: Anssi Hannula @ 2015-08-16 12:50 UTC (permalink / raw) To: Takashi Iwai; +Cc: alsa-devel, stable AudioQuest DragonFly DAC reports a volume control range of 0..50 (0x0000..0x0032) which in USB Audio means a range of 0 .. 0.2dB, which is obviously incorrect and causes software using the dB information in e.g. volume sliders to have a massive volume difference in 100..102% range. The actual volume mapping seems to be neither linear volume nor linear dB scale, but instead quite close to the cubic mapping e.g. alsamixer uses, with a range of -53...0 dB. Add a quirk for DragonFly to use a custom dB mapping, based on my measurements, using a 10-item range TLV (so it still fits in alsa-lib MAX_TLV_RANGE_SIZE). Tested on AudioQuest DragonFly HW v1.2. The quirk is only applied if the range is 0..50, so if this gets fixed/changed in later HW revisions it will no longer be applied. Signed-off-by: Anssi Hannula <anssi.hannula@iki.fi> Cc: <stable@vger.kernel.org> --- sound/usb/mixer_quirks.c | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/sound/usb/mixer_quirks.c b/sound/usb/mixer_quirks.c index 337c317ead6f..39d7f34e44e6 100644 --- a/sound/usb/mixer_quirks.c +++ b/sound/usb/mixer_quirks.c @@ -37,6 +37,7 @@ #include <sound/control.h> #include <sound/hwdep.h> #include <sound/info.h> +#include <sound/tlv.h> #include "usbaudio.h" #include "mixer.h" @@ -1733,6 +1734,38 @@ static int snd_microii_controls_create(struct usb_mixer_interface *mixer) return 0; } +static void snd_dragonfly_quirk_db_scale(struct usb_mixer_interface *mixer) +{ + struct usb_mixer_elem_list *list; + struct usb_mixer_elem_info *cval; + static const int unit_id = 7; + + /* approximation using 10 ranges based on output measurement on hw v1.2 */ + static const DECLARE_TLV_DB_RANGE(scale, + 0, 1, TLV_DB_MINMAX_ITEM(-5300, -4970), + 2, 5, TLV_DB_MINMAX_ITEM(-4710, -4160), + 6, 7, TLV_DB_MINMAX_ITEM(-3884, -3710), + 8, 14, TLV_DB_MINMAX_ITEM(-3443, -2560), + 15, 16, TLV_DB_MINMAX_ITEM(-2475, -2324), + 17, 19, TLV_DB_MINMAX_ITEM(-2228, -2031), + 20, 26, TLV_DB_MINMAX_ITEM(-1910, -1393), + 27, 31, TLV_DB_MINMAX_ITEM(-1322, -1032), + 32, 40, TLV_DB_MINMAX_ITEM(-968, -490), + 41, 50, TLV_DB_MINMAX_ITEM(-441, 0), + ); + + for (list = mixer->id_elems[unit_id]; list; list = list->next_id_elem) { + cval = (struct usb_mixer_elem_info *)list; + if (cval->control == UAC_FU_VOLUME && + cval->min == 0 && cval->max == 50) { + usb_audio_info(mixer->chip, "applying DragonFly dB scale quirk\n"); + list->kctl->tlv.p = scale; + list->kctl->vd[0].access |= SNDRV_CTL_ELEM_ACCESS_TLV_READ; + list->kctl->vd[0].access &= ~SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK; + } + } +} + int snd_usb_mixer_apply_create_quirk(struct usb_mixer_interface *mixer) { int err = 0; @@ -1810,6 +1843,10 @@ int snd_usb_mixer_apply_create_quirk(struct usb_mixer_interface *mixer) case USB_ID(0x1235, 0x800c): /* Focusrite Scarlett 18i20 */ err = snd_scarlett_controls_create(mixer); break; + + case USB_ID(0x21b4, 0x0081): /* AudioQuest DragonFly */ + snd_dragonfly_quirk_db_scale(mixer); + break; } return err; -- 2.3.8 ^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH 2/2] ALSA: usb-audio: Add sample rate inquiry quirk for AudioQuest DragonFly 2015-08-16 12:50 [PATCH 1/2] ALSA: usb-audio: Add a volume scale quirk for AudioQuest DragonFly Anssi Hannula @ 2015-08-16 12:50 ` Anssi Hannula 2015-08-17 14:16 ` [PATCH 1/2] ALSA: usb-audio: Add a volume scale " Takashi Iwai 1 sibling, 0 replies; 9+ messages in thread From: Anssi Hannula @ 2015-08-16 12:50 UTC (permalink / raw) To: Takashi Iwai; +Cc: alsa-devel, stable Avoid getting sample rate on AudioQuest DragonFly as it is unsupported and causes noisy "cannot get freq at ep 0x1" messages when playback starts. Signed-off-by: Anssi Hannula <anssi.hannula@iki.fi> Cc: <stable@vger.kernel.org> --- sound/usb/quirks.c | 1 + 1 file changed, 1 insertion(+) diff --git a/sound/usb/quirks.c b/sound/usb/quirks.c index 754e689596a2..078ff58f1ba0 100644 --- a/sound/usb/quirks.c +++ b/sound/usb/quirks.c @@ -1121,6 +1121,7 @@ bool snd_usb_get_sample_rate_quirk(struct snd_usb_audio *chip) case USB_ID(0x045E, 0x0779): /* MS Lifecam HD-3000 */ case USB_ID(0x04D8, 0xFEEA): /* Benchmark DAC1 Pre */ case USB_ID(0x074D, 0x3553): /* Outlaw RR2150 (Micronas UAC3553B) */ + case USB_ID(0x21B4, 0x0081): /* AudioQuest DragonFly */ return true; } return false; -- 2.3.8 ^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [PATCH 1/2] ALSA: usb-audio: Add a volume scale quirk for AudioQuest DragonFly 2015-08-16 12:50 [PATCH 1/2] ALSA: usb-audio: Add a volume scale quirk for AudioQuest DragonFly Anssi Hannula 2015-08-16 12:50 ` [PATCH 2/2] ALSA: usb-audio: Add sample rate inquiry " Anssi Hannula @ 2015-08-17 14:16 ` Takashi Iwai 2015-08-17 16:01 ` Anssi Hannula 1 sibling, 1 reply; 9+ messages in thread From: Takashi Iwai @ 2015-08-17 14:16 UTC (permalink / raw) To: Anssi Hannula; +Cc: alsa-devel, stable On Sun, 16 Aug 2015 14:50:12 +0200, Anssi Hannula wrote: > > AudioQuest DragonFly DAC reports a volume control range of 0..50 > (0x0000..0x0032) which in USB Audio means a range of 0 .. 0.2dB, which > is obviously incorrect and causes software using the dB information in > e.g. volume sliders to have a massive volume difference in 100..102% > range. > > The actual volume mapping seems to be neither linear volume nor linear > dB scale, but instead quite close to the cubic mapping e.g. alsamixer > uses, with a range of -53...0 dB. > > Add a quirk for DragonFly to use a custom dB mapping, based on my > measurements, using a 10-item range TLV (so it still fits in alsa-lib > MAX_TLV_RANGE_SIZE). > > Tested on AudioQuest DragonFly HW v1.2. The quirk is only applied if the > range is 0..50, so if this gets fixed/changed in later HW revisions it > will no longer be applied. > > Signed-off-by: Anssi Hannula <anssi.hannula@iki.fi> > Cc: <stable@vger.kernel.org> > --- > sound/usb/mixer_quirks.c | 37 +++++++++++++++++++++++++++++++++++++ > 1 file changed, 37 insertions(+) > > diff --git a/sound/usb/mixer_quirks.c b/sound/usb/mixer_quirks.c > index 337c317ead6f..39d7f34e44e6 100644 > --- a/sound/usb/mixer_quirks.c > +++ b/sound/usb/mixer_quirks.c > @@ -37,6 +37,7 @@ > #include <sound/control.h> > #include <sound/hwdep.h> > #include <sound/info.h> > +#include <sound/tlv.h> > > #include "usbaudio.h" > #include "mixer.h" > @@ -1733,6 +1734,38 @@ static int snd_microii_controls_create(struct usb_mixer_interface *mixer) > return 0; > } > > +static void snd_dragonfly_quirk_db_scale(struct usb_mixer_interface *mixer) > +{ > + struct usb_mixer_elem_list *list; > + struct usb_mixer_elem_info *cval; > + static const int unit_id = 7; > + > + /* approximation using 10 ranges based on output measurement on hw v1.2 */ > + static const DECLARE_TLV_DB_RANGE(scale, > + 0, 1, TLV_DB_MINMAX_ITEM(-5300, -4970), > + 2, 5, TLV_DB_MINMAX_ITEM(-4710, -4160), > + 6, 7, TLV_DB_MINMAX_ITEM(-3884, -3710), > + 8, 14, TLV_DB_MINMAX_ITEM(-3443, -2560), > + 15, 16, TLV_DB_MINMAX_ITEM(-2475, -2324), > + 17, 19, TLV_DB_MINMAX_ITEM(-2228, -2031), > + 20, 26, TLV_DB_MINMAX_ITEM(-1910, -1393), > + 27, 31, TLV_DB_MINMAX_ITEM(-1322, -1032), > + 32, 40, TLV_DB_MINMAX_ITEM(-968, -490), > + 41, 50, TLV_DB_MINMAX_ITEM(-441, 0), > + ); > + > + for (list = mixer->id_elems[unit_id]; list; list = list->next_id_elem) { > + cval = (struct usb_mixer_elem_info *)list; > + if (cval->control == UAC_FU_VOLUME && > + cval->min == 0 && cval->max == 50) { > + usb_audio_info(mixer->chip, "applying DragonFly dB scale quirk\n"); > + list->kctl->tlv.p = scale; > + list->kctl->vd[0].access |= SNDRV_CTL_ELEM_ACCESS_TLV_READ; > + list->kctl->vd[0].access &= ~SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK; > + } > + } Instead of looking through the list, just hooking at build_feature_ctl() would be simpler in the end, I think. E.g. something like: --- a/sound/usb/mixer.c +++ b/sound/usb/mixer.c @@ -1334,6 +1334,7 @@ static void build_feature_ctl(struct mixer_build *state, void *raw_desc, SNDRV_CTL_ELEM_ACCESS_TLV_READ | SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK; } + mixer_fu_apply_quirk(state->mixer, cval, unitid, kctl); } range = (cval->max - cval->min) / cval->res; ... and the quirk implementation in mixer_quirks.c like static void snd_dragonfly_quirk_db_scale(mixer, kctl) { usb_audio_info(mixer->chip, "applying DragonFly dB scale quirk\n"); kctl->tlv.p = scale; kctl->vd[0].access |= SNDRV_CTL_ELEM_ACCESS_TLV_READ; list->kctl->vd[0].access &= ~SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK; } void mixer_fu_apply_quirk(mixer, cval, unitid, kctl) { switch (mixer->chip->usb_id) { case USB_ID(0x21b4, 0x0081): /* AudioQuest DragonFly */ if (unitid == 7 && cval->min == 0 && cval->max == 50) snd_dragonfly_quirk_db_scale(mixer, kctl); break; } } Takashi ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH 1/2] ALSA: usb-audio: Add a volume scale quirk for AudioQuest DragonFly 2015-08-17 14:16 ` [PATCH 1/2] ALSA: usb-audio: Add a volume scale " Takashi Iwai @ 2015-08-17 16:01 ` Anssi Hannula 2015-08-17 16:20 ` Takashi Iwai 0 siblings, 1 reply; 9+ messages in thread From: Anssi Hannula @ 2015-08-17 16:01 UTC (permalink / raw) To: Takashi Iwai, Yao-Wen Mao; +Cc: alsa-devel, stable Hi, 17.08.2015, 17:16, Takashi Iwai kirjoitti: > On Sun, 16 Aug 2015 14:50:12 +0200, > Anssi Hannula wrote: >> >> AudioQuest DragonFly DAC reports a volume control range of 0..50 >> (0x0000..0x0032) which in USB Audio means a range of 0 .. 0.2dB, which >> is obviously incorrect and causes software using the dB information in >> e.g. volume sliders to have a massive volume difference in 100..102% >> range. >> >> The actual volume mapping seems to be neither linear volume nor linear >> dB scale, but instead quite close to the cubic mapping e.g. alsamixer >> uses, with a range of -53...0 dB. >> >> Add a quirk for DragonFly to use a custom dB mapping, based on my >> measurements, using a 10-item range TLV (so it still fits in alsa-lib >> MAX_TLV_RANGE_SIZE). >> >> Tested on AudioQuest DragonFly HW v1.2. The quirk is only applied if the >> range is 0..50, so if this gets fixed/changed in later HW revisions it >> will no longer be applied. >> >> Signed-off-by: Anssi Hannula <anssi.hannula@iki.fi> >> Cc: <stable@vger.kernel.org> >> --- >> sound/usb/mixer_quirks.c | 37 +++++++++++++++++++++++++++++++++++++ >> 1 file changed, 37 insertions(+) >> >> diff --git a/sound/usb/mixer_quirks.c b/sound/usb/mixer_quirks.c >> index 337c317ead6f..39d7f34e44e6 100644 >> --- a/sound/usb/mixer_quirks.c >> +++ b/sound/usb/mixer_quirks.c >> @@ -37,6 +37,7 @@ >> #include <sound/control.h> >> #include <sound/hwdep.h> >> #include <sound/info.h> >> +#include <sound/tlv.h> >> >> #include "usbaudio.h" >> #include "mixer.h" >> @@ -1733,6 +1734,38 @@ static int snd_microii_controls_create(struct usb_mixer_interface *mixer) >> return 0; >> } >> >> +static void snd_dragonfly_quirk_db_scale(struct usb_mixer_interface *mixer) >> +{ >> + struct usb_mixer_elem_list *list; >> + struct usb_mixer_elem_info *cval; >> + static const int unit_id = 7; >> + >> + /* approximation using 10 ranges based on output measurement on hw v1.2 */ >> + static const DECLARE_TLV_DB_RANGE(scale, >> + 0, 1, TLV_DB_MINMAX_ITEM(-5300, -4970), >> + 2, 5, TLV_DB_MINMAX_ITEM(-4710, -4160), >> + 6, 7, TLV_DB_MINMAX_ITEM(-3884, -3710), >> + 8, 14, TLV_DB_MINMAX_ITEM(-3443, -2560), >> + 15, 16, TLV_DB_MINMAX_ITEM(-2475, -2324), >> + 17, 19, TLV_DB_MINMAX_ITEM(-2228, -2031), >> + 20, 26, TLV_DB_MINMAX_ITEM(-1910, -1393), >> + 27, 31, TLV_DB_MINMAX_ITEM(-1322, -1032), >> + 32, 40, TLV_DB_MINMAX_ITEM(-968, -490), >> + 41, 50, TLV_DB_MINMAX_ITEM(-441, 0), >> + ); >> + >> + for (list = mixer->id_elems[unit_id]; list; list = list->next_id_elem) { >> + cval = (struct usb_mixer_elem_info *)list; >> + if (cval->control == UAC_FU_VOLUME && >> + cval->min == 0 && cval->max == 50) { >> + usb_audio_info(mixer->chip, "applying DragonFly dB scale quirk\n"); >> + list->kctl->tlv.p = scale; >> + list->kctl->vd[0].access |= SNDRV_CTL_ELEM_ACCESS_TLV_READ; >> + list->kctl->vd[0].access &= ~SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK; >> + } >> + } > > Instead of looking through the list, just hooking at > build_feature_ctl() would be simpler in the end, I think. > E.g. something like: > > --- a/sound/usb/mixer.c > +++ b/sound/usb/mixer.c > @@ -1334,6 +1334,7 @@ static void build_feature_ctl(struct mixer_build *state, void *raw_desc, > SNDRV_CTL_ELEM_ACCESS_TLV_READ | > SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK; > } > + mixer_fu_apply_quirk(state->mixer, cval, unitid, kctl); > } > > range = (cval->max - cval->min) / cval->res; > > ... and the quirk implementation in mixer_quirks.c like > > static void snd_dragonfly_quirk_db_scale(mixer, kctl) > { > usb_audio_info(mixer->chip, "applying DragonFly dB scale quirk\n"); > kctl->tlv.p = scale; > kctl->vd[0].access |= SNDRV_CTL_ELEM_ACCESS_TLV_READ; > list->kctl->vd[0].access &= ~SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK; > } > > void mixer_fu_apply_quirk(mixer, cval, unitid, kctl) > { > switch (mixer->chip->usb_id) { > case USB_ID(0x21b4, 0x0081): /* AudioQuest DragonFly */ > if (unitid == 7 && cval->min == 0 && cval->max == 50) > snd_dragonfly_quirk_db_scale(mixer, kctl); > break; > } > } OK, seems like a good idea. However, I just noticed another volume quirk for DragonFly has already been merged since I started looking into this: https://git.kernel.org/cgit/linux/kernel/git/tiwai/sound.git/commit/?id=2d1cb7f658fb9c3ba8f9dab8aca297d4dfdec835 It sets a fixed dB linear range map of 0...50dB via mixer_maps.c, which doesn't seem 100% right to me. While it is much better than the unquirked 0...0.2dB, it causes e.g. pulseaudio mixer to show the nearly inaudible raw 0 as the "base" level. And, unless I made some silly mistake, the volume scale is not actually linear dB AFAICS. Yao-Wen, did you have some basis for the assumption "dB conversion factor is 1" on DragonFly other than that it sounded approximately right? Takashi, should I add removal of that "duplicate" quirk in the same commit (or a separate one)? (assuming my quirk turns out to be actually better/correct, of course) -- Anssi Hannula ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH 1/2] ALSA: usb-audio: Add a volume scale quirk for AudioQuest DragonFly 2015-08-17 16:01 ` Anssi Hannula @ 2015-08-17 16:20 ` Takashi Iwai 2015-12-13 18:49 ` [PATCH 1/2 v2] ALSA: usb-audio: Add a more accurate volume " Anssi Hannula 0 siblings, 1 reply; 9+ messages in thread From: Takashi Iwai @ 2015-08-17 16:20 UTC (permalink / raw) To: Anssi Hannula; +Cc: Yao-Wen Mao, alsa-devel, stable On Mon, 17 Aug 2015 18:01:12 +0200, Anssi Hannula wrote: > > Hi, > > 17.08.2015, 17:16, Takashi Iwai kirjoitti: > > On Sun, 16 Aug 2015 14:50:12 +0200, > > Anssi Hannula wrote: > >> > >> AudioQuest DragonFly DAC reports a volume control range of 0..50 > >> (0x0000..0x0032) which in USB Audio means a range of 0 .. 0.2dB, which > >> is obviously incorrect and causes software using the dB information in > >> e.g. volume sliders to have a massive volume difference in 100..102% > >> range. > >> > >> The actual volume mapping seems to be neither linear volume nor linear > >> dB scale, but instead quite close to the cubic mapping e.g. alsamixer > >> uses, with a range of -53...0 dB. > >> > >> Add a quirk for DragonFly to use a custom dB mapping, based on my > >> measurements, using a 10-item range TLV (so it still fits in alsa-lib > >> MAX_TLV_RANGE_SIZE). > >> > >> Tested on AudioQuest DragonFly HW v1.2. The quirk is only applied if the > >> range is 0..50, so if this gets fixed/changed in later HW revisions it > >> will no longer be applied. > >> > >> Signed-off-by: Anssi Hannula <anssi.hannula@iki.fi> > >> Cc: <stable@vger.kernel.org> > >> --- > >> sound/usb/mixer_quirks.c | 37 +++++++++++++++++++++++++++++++++++++ > >> 1 file changed, 37 insertions(+) > >> > >> diff --git a/sound/usb/mixer_quirks.c b/sound/usb/mixer_quirks.c > >> index 337c317ead6f..39d7f34e44e6 100644 > >> --- a/sound/usb/mixer_quirks.c > >> +++ b/sound/usb/mixer_quirks.c > >> @@ -37,6 +37,7 @@ > >> #include <sound/control.h> > >> #include <sound/hwdep.h> > >> #include <sound/info.h> > >> +#include <sound/tlv.h> > >> > >> #include "usbaudio.h" > >> #include "mixer.h" > >> @@ -1733,6 +1734,38 @@ static int snd_microii_controls_create(struct usb_mixer_interface *mixer) > >> return 0; > >> } > >> > >> +static void snd_dragonfly_quirk_db_scale(struct usb_mixer_interface *mixer) > >> +{ > >> + struct usb_mixer_elem_list *list; > >> + struct usb_mixer_elem_info *cval; > >> + static const int unit_id = 7; > >> + > >> + /* approximation using 10 ranges based on output measurement on hw v1.2 */ > >> + static const DECLARE_TLV_DB_RANGE(scale, > >> + 0, 1, TLV_DB_MINMAX_ITEM(-5300, -4970), > >> + 2, 5, TLV_DB_MINMAX_ITEM(-4710, -4160), > >> + 6, 7, TLV_DB_MINMAX_ITEM(-3884, -3710), > >> + 8, 14, TLV_DB_MINMAX_ITEM(-3443, -2560), > >> + 15, 16, TLV_DB_MINMAX_ITEM(-2475, -2324), > >> + 17, 19, TLV_DB_MINMAX_ITEM(-2228, -2031), > >> + 20, 26, TLV_DB_MINMAX_ITEM(-1910, -1393), > >> + 27, 31, TLV_DB_MINMAX_ITEM(-1322, -1032), > >> + 32, 40, TLV_DB_MINMAX_ITEM(-968, -490), > >> + 41, 50, TLV_DB_MINMAX_ITEM(-441, 0), > >> + ); > >> + > >> + for (list = mixer->id_elems[unit_id]; list; list = list->next_id_elem) { > >> + cval = (struct usb_mixer_elem_info *)list; > >> + if (cval->control == UAC_FU_VOLUME && > >> + cval->min == 0 && cval->max == 50) { > >> + usb_audio_info(mixer->chip, "applying DragonFly dB scale quirk\n"); > >> + list->kctl->tlv.p = scale; > >> + list->kctl->vd[0].access |= SNDRV_CTL_ELEM_ACCESS_TLV_READ; > >> + list->kctl->vd[0].access &= ~SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK; > >> + } > >> + } > > > > Instead of looking through the list, just hooking at > > build_feature_ctl() would be simpler in the end, I think. > > E.g. something like: > > > > --- a/sound/usb/mixer.c > > +++ b/sound/usb/mixer.c > > @@ -1334,6 +1334,7 @@ static void build_feature_ctl(struct mixer_build *state, void *raw_desc, > > SNDRV_CTL_ELEM_ACCESS_TLV_READ | > > SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK; > > } > > + mixer_fu_apply_quirk(state->mixer, cval, unitid, kctl); > > } > > > > range = (cval->max - cval->min) / cval->res; > > > > ... and the quirk implementation in mixer_quirks.c like > > > > static void snd_dragonfly_quirk_db_scale(mixer, kctl) > > { > > usb_audio_info(mixer->chip, "applying DragonFly dB scale quirk\n"); > > kctl->tlv.p = scale; > > kctl->vd[0].access |= SNDRV_CTL_ELEM_ACCESS_TLV_READ; > > list->kctl->vd[0].access &= ~SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK; > > } > > > > void mixer_fu_apply_quirk(mixer, cval, unitid, kctl) > > { > > switch (mixer->chip->usb_id) { > > case USB_ID(0x21b4, 0x0081): /* AudioQuest DragonFly */ > > if (unitid == 7 && cval->min == 0 && cval->max == 50) > > snd_dragonfly_quirk_db_scale(mixer, kctl); > > break; > > } > > } > > OK, seems like a good idea. > > However, I just noticed another volume quirk for DragonFly has already > been merged since I started looking into this: > https://git.kernel.org/cgit/linux/kernel/git/tiwai/sound.git/commit/?id=2d1cb7f658fb9c3ba8f9dab8aca297d4dfdec835 > > It sets a fixed dB linear range map of 0...50dB via mixer_maps.c, which > doesn't seem 100% right to me. While it is much better than the > unquirked 0...0.2dB, it causes e.g. pulseaudio mixer to show the nearly > inaudible raw 0 as the "base" level. And, unless I made some silly > mistake, the volume scale is not actually linear dB AFAICS. > > Yao-Wen, did you have some basis for the assumption "dB conversion > factor is 1" on DragonFly other than that it sounded approximately right? > > Takashi, should I add removal of that "duplicate" quirk in the same > commit (or a separate one)? (assuming my quirk turns out to be actually > better/correct, of course) Yes, it sounds good. thanks, Takashi ^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH 1/2 v2] ALSA: usb-audio: Add a more accurate volume quirk for AudioQuest DragonFly 2015-08-17 16:20 ` Takashi Iwai @ 2015-12-13 18:49 ` Anssi Hannula 2015-12-13 18:49 ` [PATCH 2/2] ALSA: usb-audio: Add sample rate inquiry " Anssi Hannula 2015-12-14 9:41 ` [PATCH 1/2 v2] ALSA: usb-audio: Add a more accurate volume " Takashi Iwai 0 siblings, 2 replies; 9+ messages in thread From: Anssi Hannula @ 2015-12-13 18:49 UTC (permalink / raw) To: tiwai; +Cc: alsa-devel, yaowen, stable AudioQuest DragonFly DAC reports a volume control range of 0..50 (0x0000..0x0032) which in USB Audio means a range of 0 .. 0.2dB, which is obviously incorrect and would cause software using the dB information in e.g. volume sliders to have a massive volume difference in 100..102% range. Commit 2d1cb7f658fb ("ALSA: usb-audio: add dB range mapping for some devices") added a dB range mapping for it with range 0..50 dB. However, the actual volume mapping seems to be neither linear volume nor linear dB scale, but instead quite close to the cubic mapping e.g. alsamixer uses, with a range of approx. -53...0 dB. Replace the previous quirk with a custom dB mapping based on some basic output measurements, using a 10-item range TLV (which will still fit in alsa-lib MAX_TLV_RANGE_SIZE). Tested on AudioQuest DragonFly HW v1.2. The quirk is only applied if the range is 0..50, so if this gets fixed/changed in later HW revisions it will no longer be applied. v2: incorporated Takashi Iwai's suggestion for the quirk application method Signed-off-by: Anssi Hannula <anssi.hannula@iki.fi> Cc: <stable@vger.kernel.org> --- It took a bit longer than expected for me to get back to this, but here goes :) sound/usb/mixer.c | 2 ++ sound/usb/mixer_maps.c | 12 ------------ sound/usb/mixer_quirks.c | 37 +++++++++++++++++++++++++++++++++++++ sound/usb/mixer_quirks.h | 4 ++++ 4 files changed, 43 insertions(+), 12 deletions(-) diff --git a/sound/usb/mixer.c b/sound/usb/mixer.c index f494dced3c11..4f85757009b3 100644 --- a/sound/usb/mixer.c +++ b/sound/usb/mixer.c @@ -1354,6 +1354,8 @@ static void build_feature_ctl(struct mixer_build *state, void *raw_desc, } } + snd_usb_mixer_fu_apply_quirk(state->mixer, cval, unitid, kctl); + range = (cval->max - cval->min) / cval->res; /* * Are there devices with volume range more than 255? I use a bit more diff --git a/sound/usb/mixer_maps.c b/sound/usb/mixer_maps.c index 6a803eff87f7..ddca6547399b 100644 --- a/sound/usb/mixer_maps.c +++ b/sound/usb/mixer_maps.c @@ -348,13 +348,6 @@ static struct usbmix_name_map bose_companion5_map[] = { { 0 } /* terminator */ }; -/* Dragonfly DAC 1.2, the dB conversion factor is 1 instead of 256 */ -static struct usbmix_dB_map dragonfly_1_2_dB = {0, 5000}; -static struct usbmix_name_map dragonfly_1_2_map[] = { - { 7, NULL, .dB = &dragonfly_1_2_dB }, - { 0 } /* terminator */ -}; - /* * Control map entries */ @@ -470,11 +463,6 @@ static struct usbmix_ctl_map usbmix_ctl_maps[] = { .id = USB_ID(0x05a7, 0x1020), .map = bose_companion5_map, }, - { - /* Dragonfly DAC 1.2 */ - .id = USB_ID(0x21b4, 0x0081), - .map = dragonfly_1_2_map, - }, { 0 } /* terminator */ }; diff --git a/sound/usb/mixer_quirks.c b/sound/usb/mixer_quirks.c index fe91184ce832..0ce888dceed0 100644 --- a/sound/usb/mixer_quirks.c +++ b/sound/usb/mixer_quirks.c @@ -37,6 +37,7 @@ #include <sound/control.h> #include <sound/hwdep.h> #include <sound/info.h> +#include <sound/tlv.h> #include "usbaudio.h" #include "mixer.h" @@ -1825,3 +1826,39 @@ void snd_usb_mixer_rc_memory_change(struct usb_mixer_interface *mixer, } } +static void snd_dragonfly_quirk_db_scale(struct usb_mixer_interface *mixer, + struct snd_kcontrol *kctl) +{ + /* Approximation using 10 ranges based on output measurement on hw v1.2. + * This seems close to the cubic mapping e.g. alsamixer uses. */ + static const DECLARE_TLV_DB_RANGE(scale, + 0, 1, TLV_DB_MINMAX_ITEM(-5300, -4970), + 2, 5, TLV_DB_MINMAX_ITEM(-4710, -4160), + 6, 7, TLV_DB_MINMAX_ITEM(-3884, -3710), + 8, 14, TLV_DB_MINMAX_ITEM(-3443, -2560), + 15, 16, TLV_DB_MINMAX_ITEM(-2475, -2324), + 17, 19, TLV_DB_MINMAX_ITEM(-2228, -2031), + 20, 26, TLV_DB_MINMAX_ITEM(-1910, -1393), + 27, 31, TLV_DB_MINMAX_ITEM(-1322, -1032), + 32, 40, TLV_DB_MINMAX_ITEM(-968, -490), + 41, 50, TLV_DB_MINMAX_ITEM(-441, 0), + ); + + usb_audio_info(mixer->chip, "applying DragonFly dB scale quirk\n"); + kctl->tlv.p = scale; + kctl->vd[0].access |= SNDRV_CTL_ELEM_ACCESS_TLV_READ; + kctl->vd[0].access &= ~SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK; +} + +void snd_usb_mixer_fu_apply_quirk(struct usb_mixer_interface *mixer, + struct usb_mixer_elem_info *cval, int unitid, + struct snd_kcontrol *kctl) +{ + switch (mixer->chip->usb_id) { + case USB_ID(0x21b4, 0x0081): /* AudioQuest DragonFly */ + if (unitid == 7 && cval->min == 0 && cval->max == 50) + snd_dragonfly_quirk_db_scale(mixer, kctl); + break; + } +} + diff --git a/sound/usb/mixer_quirks.h b/sound/usb/mixer_quirks.h index bdbfab093816..177c329cd4dd 100644 --- a/sound/usb/mixer_quirks.h +++ b/sound/usb/mixer_quirks.h @@ -9,5 +9,9 @@ void snd_emuusb_set_samplerate(struct snd_usb_audio *chip, void snd_usb_mixer_rc_memory_change(struct usb_mixer_interface *mixer, int unitid); +void snd_usb_mixer_fu_apply_quirk(struct usb_mixer_interface *mixer, + struct usb_mixer_elem_info *cval, int unitid, + struct snd_kcontrol *kctl); + #endif /* SND_USB_MIXER_QUIRKS_H */ -- 2.3.10 ^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH 2/2] ALSA: usb-audio: Add sample rate inquiry quirk for AudioQuest DragonFly 2015-12-13 18:49 ` [PATCH 1/2 v2] ALSA: usb-audio: Add a more accurate volume " Anssi Hannula @ 2015-12-13 18:49 ` Anssi Hannula 2015-12-14 9:42 ` Takashi Iwai 2015-12-14 9:41 ` [PATCH 1/2 v2] ALSA: usb-audio: Add a more accurate volume " Takashi Iwai 1 sibling, 1 reply; 9+ messages in thread From: Anssi Hannula @ 2015-12-13 18:49 UTC (permalink / raw) To: tiwai; +Cc: alsa-devel, yaowen, stable Avoid getting sample rate on AudioQuest DragonFly as it is unsupported and causes noisy "cannot get freq at ep 0x1" messages when playback starts. Signed-off-by: Anssi Hannula <anssi.hannula@iki.fi> Cc: <stable@vger.kernel.org> --- No changes to this one. sound/usb/quirks.c | 1 + 1 file changed, 1 insertion(+) diff --git a/sound/usb/quirks.c b/sound/usb/quirks.c index 7016ad898187..b951d620ba1b 100644 --- a/sound/usb/quirks.c +++ b/sound/usb/quirks.c @@ -1125,6 +1125,7 @@ bool snd_usb_get_sample_rate_quirk(struct snd_usb_audio *chip) case USB_ID(0x045E, 0x0779): /* MS Lifecam HD-3000 */ case USB_ID(0x04D8, 0xFEEA): /* Benchmark DAC1 Pre */ case USB_ID(0x074D, 0x3553): /* Outlaw RR2150 (Micronas UAC3553B) */ + case USB_ID(0x21B4, 0x0081): /* AudioQuest DragonFly */ return true; } return false; -- 2.3.10 ^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [PATCH 2/2] ALSA: usb-audio: Add sample rate inquiry quirk for AudioQuest DragonFly 2015-12-13 18:49 ` [PATCH 2/2] ALSA: usb-audio: Add sample rate inquiry " Anssi Hannula @ 2015-12-14 9:42 ` Takashi Iwai 0 siblings, 0 replies; 9+ messages in thread From: Takashi Iwai @ 2015-12-14 9:42 UTC (permalink / raw) To: Anssi Hannula; +Cc: alsa-devel, yaowen, stable On Sun, 13 Dec 2015 19:49:59 +0100, Anssi Hannula wrote: > > Avoid getting sample rate on AudioQuest DragonFly as it is unsupported > and causes noisy "cannot get freq at ep 0x1" messages when playback > starts. > > Signed-off-by: Anssi Hannula <anssi.hannula@iki.fi> > Cc: <stable@vger.kernel.org> Applied, thanks. Takashi > --- > > No changes to this one. > > > sound/usb/quirks.c | 1 + > 1 file changed, 1 insertion(+) > > diff --git a/sound/usb/quirks.c b/sound/usb/quirks.c > index 7016ad898187..b951d620ba1b 100644 > --- a/sound/usb/quirks.c > +++ b/sound/usb/quirks.c > @@ -1125,6 +1125,7 @@ bool snd_usb_get_sample_rate_quirk(struct snd_usb_audio *chip) > case USB_ID(0x045E, 0x0779): /* MS Lifecam HD-3000 */ > case USB_ID(0x04D8, 0xFEEA): /* Benchmark DAC1 Pre */ > case USB_ID(0x074D, 0x3553): /* Outlaw RR2150 (Micronas UAC3553B) */ > + case USB_ID(0x21B4, 0x0081): /* AudioQuest DragonFly */ > return true; > } > return false; > -- > 2.3.10 > ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH 1/2 v2] ALSA: usb-audio: Add a more accurate volume quirk for AudioQuest DragonFly 2015-12-13 18:49 ` [PATCH 1/2 v2] ALSA: usb-audio: Add a more accurate volume " Anssi Hannula 2015-12-13 18:49 ` [PATCH 2/2] ALSA: usb-audio: Add sample rate inquiry " Anssi Hannula @ 2015-12-14 9:41 ` Takashi Iwai 1 sibling, 0 replies; 9+ messages in thread From: Takashi Iwai @ 2015-12-14 9:41 UTC (permalink / raw) To: Anssi Hannula; +Cc: alsa-devel, yaowen, stable On Sun, 13 Dec 2015 19:49:58 +0100, Anssi Hannula wrote: > > AudioQuest DragonFly DAC reports a volume control range of 0..50 > (0x0000..0x0032) which in USB Audio means a range of 0 .. 0.2dB, which > is obviously incorrect and would cause software using the dB information > in e.g. volume sliders to have a massive volume difference in 100..102% > range. > > Commit 2d1cb7f658fb ("ALSA: usb-audio: add dB range mapping for some > devices") added a dB range mapping for it with range 0..50 dB. > > However, the actual volume mapping seems to be neither linear volume nor > linear dB scale, but instead quite close to the cubic mapping e.g. > alsamixer uses, with a range of approx. -53...0 dB. > > Replace the previous quirk with a custom dB mapping based on some basic > output measurements, using a 10-item range TLV (which will still fit in > alsa-lib MAX_TLV_RANGE_SIZE). > > Tested on AudioQuest DragonFly HW v1.2. The quirk is only applied if the > range is 0..50, so if this gets fixed/changed in later HW revisions it > will no longer be applied. > > v2: incorporated Takashi Iwai's suggestion for the quirk application > method > > Signed-off-by: Anssi Hannula <anssi.hannula@iki.fi> > Cc: <stable@vger.kernel.org> Applied, thanks. Takashi > --- > > It took a bit longer than expected for me to get back to this, but here > goes :) > > > sound/usb/mixer.c | 2 ++ > sound/usb/mixer_maps.c | 12 ------------ > sound/usb/mixer_quirks.c | 37 +++++++++++++++++++++++++++++++++++++ > sound/usb/mixer_quirks.h | 4 ++++ > 4 files changed, 43 insertions(+), 12 deletions(-) > > diff --git a/sound/usb/mixer.c b/sound/usb/mixer.c > index f494dced3c11..4f85757009b3 100644 > --- a/sound/usb/mixer.c > +++ b/sound/usb/mixer.c > @@ -1354,6 +1354,8 @@ static void build_feature_ctl(struct mixer_build *state, void *raw_desc, > } > } > > + snd_usb_mixer_fu_apply_quirk(state->mixer, cval, unitid, kctl); > + > range = (cval->max - cval->min) / cval->res; > /* > * Are there devices with volume range more than 255? I use a bit more > diff --git a/sound/usb/mixer_maps.c b/sound/usb/mixer_maps.c > index 6a803eff87f7..ddca6547399b 100644 > --- a/sound/usb/mixer_maps.c > +++ b/sound/usb/mixer_maps.c > @@ -348,13 +348,6 @@ static struct usbmix_name_map bose_companion5_map[] = { > { 0 } /* terminator */ > }; > > -/* Dragonfly DAC 1.2, the dB conversion factor is 1 instead of 256 */ > -static struct usbmix_dB_map dragonfly_1_2_dB = {0, 5000}; > -static struct usbmix_name_map dragonfly_1_2_map[] = { > - { 7, NULL, .dB = &dragonfly_1_2_dB }, > - { 0 } /* terminator */ > -}; > - > /* > * Control map entries > */ > @@ -470,11 +463,6 @@ static struct usbmix_ctl_map usbmix_ctl_maps[] = { > .id = USB_ID(0x05a7, 0x1020), > .map = bose_companion5_map, > }, > - { > - /* Dragonfly DAC 1.2 */ > - .id = USB_ID(0x21b4, 0x0081), > - .map = dragonfly_1_2_map, > - }, > { 0 } /* terminator */ > }; > > diff --git a/sound/usb/mixer_quirks.c b/sound/usb/mixer_quirks.c > index fe91184ce832..0ce888dceed0 100644 > --- a/sound/usb/mixer_quirks.c > +++ b/sound/usb/mixer_quirks.c > @@ -37,6 +37,7 @@ > #include <sound/control.h> > #include <sound/hwdep.h> > #include <sound/info.h> > +#include <sound/tlv.h> > > #include "usbaudio.h" > #include "mixer.h" > @@ -1825,3 +1826,39 @@ void snd_usb_mixer_rc_memory_change(struct usb_mixer_interface *mixer, > } > } > > +static void snd_dragonfly_quirk_db_scale(struct usb_mixer_interface *mixer, > + struct snd_kcontrol *kctl) > +{ > + /* Approximation using 10 ranges based on output measurement on hw v1.2. > + * This seems close to the cubic mapping e.g. alsamixer uses. */ > + static const DECLARE_TLV_DB_RANGE(scale, > + 0, 1, TLV_DB_MINMAX_ITEM(-5300, -4970), > + 2, 5, TLV_DB_MINMAX_ITEM(-4710, -4160), > + 6, 7, TLV_DB_MINMAX_ITEM(-3884, -3710), > + 8, 14, TLV_DB_MINMAX_ITEM(-3443, -2560), > + 15, 16, TLV_DB_MINMAX_ITEM(-2475, -2324), > + 17, 19, TLV_DB_MINMAX_ITEM(-2228, -2031), > + 20, 26, TLV_DB_MINMAX_ITEM(-1910, -1393), > + 27, 31, TLV_DB_MINMAX_ITEM(-1322, -1032), > + 32, 40, TLV_DB_MINMAX_ITEM(-968, -490), > + 41, 50, TLV_DB_MINMAX_ITEM(-441, 0), > + ); > + > + usb_audio_info(mixer->chip, "applying DragonFly dB scale quirk\n"); > + kctl->tlv.p = scale; > + kctl->vd[0].access |= SNDRV_CTL_ELEM_ACCESS_TLV_READ; > + kctl->vd[0].access &= ~SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK; > +} > + > +void snd_usb_mixer_fu_apply_quirk(struct usb_mixer_interface *mixer, > + struct usb_mixer_elem_info *cval, int unitid, > + struct snd_kcontrol *kctl) > +{ > + switch (mixer->chip->usb_id) { > + case USB_ID(0x21b4, 0x0081): /* AudioQuest DragonFly */ > + if (unitid == 7 && cval->min == 0 && cval->max == 50) > + snd_dragonfly_quirk_db_scale(mixer, kctl); > + break; > + } > +} > + > diff --git a/sound/usb/mixer_quirks.h b/sound/usb/mixer_quirks.h > index bdbfab093816..177c329cd4dd 100644 > --- a/sound/usb/mixer_quirks.h > +++ b/sound/usb/mixer_quirks.h > @@ -9,5 +9,9 @@ void snd_emuusb_set_samplerate(struct snd_usb_audio *chip, > void snd_usb_mixer_rc_memory_change(struct usb_mixer_interface *mixer, > int unitid); > > +void snd_usb_mixer_fu_apply_quirk(struct usb_mixer_interface *mixer, > + struct usb_mixer_elem_info *cval, int unitid, > + struct snd_kcontrol *kctl); > + > #endif /* SND_USB_MIXER_QUIRKS_H */ > > -- > 2.3.10 > ^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2015-12-14 9:42 UTC | newest] Thread overview: 9+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2015-08-16 12:50 [PATCH 1/2] ALSA: usb-audio: Add a volume scale quirk for AudioQuest DragonFly Anssi Hannula 2015-08-16 12:50 ` [PATCH 2/2] ALSA: usb-audio: Add sample rate inquiry " Anssi Hannula 2015-08-17 14:16 ` [PATCH 1/2] ALSA: usb-audio: Add a volume scale " Takashi Iwai 2015-08-17 16:01 ` Anssi Hannula 2015-08-17 16:20 ` Takashi Iwai 2015-12-13 18:49 ` [PATCH 1/2 v2] ALSA: usb-audio: Add a more accurate volume " Anssi Hannula 2015-12-13 18:49 ` [PATCH 2/2] ALSA: usb-audio: Add sample rate inquiry " Anssi Hannula 2015-12-14 9:42 ` Takashi Iwai 2015-12-14 9:41 ` [PATCH 1/2 v2] ALSA: usb-audio: Add a more accurate volume " Takashi Iwai
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).