All of lore.kernel.org
 help / color / mirror / Atom feed
From: Peter Ujfalusi <peter.ujfalusi@nokia.com>
To: alsa-devel@alsa-project.org
Cc: ext Mark Brown <broonie@opensource.wolfsonmicro.com>,
	"lrg@slimlogic.co.uk" <lrg@slimlogic.co.uk>
Subject: Re: [PATCH 0/3] ASoC: twl4030/tpa6130a2:	DB_RANGE mapping fixes
Date: Fri, 16 Jul 2010 14:05:40 +0300	[thread overview]
Message-ID: <201007161405.40985.peter.ujfalusi@nokia.com> (raw)
In-Reply-To: <20100716102404.GE18376@sirena.org.uk>

Hi,

On Friday 16 July 2010 13:24:05 ext Mark Brown wrote:
> On Fri, Jul 16, 2010 at 01:17:08PM +0300, Peter Ujfalusi wrote:
> > There were 'holes' in the DB_RANGE and SCALE_ITEM mapping, which results
> > failure, when user space requests dB value in these holes, since alsa-lib
> > will fail to find a range, and can not round the requested dB to raw
> > value.
> > 
> > Fixing the drivers I'm maintaining to correctly fill the tlv struct.
> 
> This seems like a bug in alsa-lib to be honest

I did considered to improve alsa-lib as well, but fixing the 
snd_tlv_convert_from_dB is a bit harder IMHO.

> - it doesn't seem right to specify two values for the indexes at the edge of
> each range,

Sort of.
The tlv struct is a lookup table for the dB mapping.
Query the raw value, and it will return the associated dB.
If you ask for dB value, it will go through the table, and try to find the best 
matching raw value (with up or down rounding).

There are drivers, which using overlapping table:
pci/es1938.c
soc/codecs/wm8753.c
and now the twl, and tpa driver,

The rest is using non overlapping mapping for dB ranges.

> especially when one of those values is going to be inaccurate.

The dB values are matching at the important points (raw values).

Let's see...
We have the following gain control:
0: -10dB
1: -5dB
2: 0dB
3: 2dB
4: 4dB

in non overlapping (A):
static const unsigned int nonoverlapping_tlv[] = {
	TLV_DB_RANGE_HEAD(2),
	0, 2, TLV_DB_SCALE_ITEM(-1000, 500, 0),
	3, 4, TLV_DB_SCALE_ITEM(200, 200, 0),
};

in overlapping (B):
static const unsigned int overlapping_tlv[] = {
	TLV_DB_RANGE_HEAD(2),
	0, 2, TLV_DB_SCALE_ITEM(-1000, 500, 0),
	2, 4, TLV_DB_SCALE_ITEM(0, 200, 0),
};

In both cases, if you query based on raw value, you get the same dB.
In both cases, if you ask for -10, -5, 0, 2, or 4 dB, you get the same raw.
In both case, if you ask for less than -10dB, than you get 0 as raw
In both case, if you ask for bigger than 4dB, than it is not changing the volume 
(I think this is really a bug, it should pick 4).

But right now if you ask for dB in the range 0 .. 2 dB:
A: will not find it, since none of the two SCALE range covers it.
B: will find it and rounds it either up or down. the 0 - 2 dB range is in the
   second SCALE.

I do think that these patches are carrying correct fix...

Probably alsa-lib can be fixed somehow to look in between the ranges, when it is 
looking for certain dB value, but at first look it is not that straight forward.

Thanks,
Péter

  reply	other threads:[~2010-07-16 11:05 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-07-16 10:17 [PATCH 0/3] ASoC: twl4030/tpa6130a2: DB_RANGE mapping fixes Peter Ujfalusi
2010-07-16 10:17 ` [PATCH 1/3] ASoC: TWL4030: Fix DB_RANGE tlv mapping for digital loopback Peter Ujfalusi
2010-07-16 10:17 ` [PATCH 2/3] ASoC: tpa6130a2: Fix DB_RANGE mapping for tpa6130a2 chip Peter Ujfalusi
2010-07-16 10:17 ` [PATCH 3/3] ASoC: tpa6130a2: Fix DB_RANGE mapping for tpa6140a2 chip Peter Ujfalusi
2010-07-16 10:24 ` [PATCH 0/3] ASoC: twl4030/tpa6130a2: DB_RANGE mapping fixes Mark Brown
2010-07-16 11:05   ` Peter Ujfalusi [this message]
2010-07-16 12:33     ` [PATCH 0/3] ASoC: twl4030/tpa6130a2:?DB_RANGE " Mark Brown
2010-07-19  5:57       ` Peter Ujfalusi
2010-07-19  8:51         ` Mark Brown
2010-07-19  9:14           ` Peter Ujfalusi
2010-07-19 10:30             ` Mark Brown
2010-07-19 10:32               ` Peter Ujfalusi
2010-07-19 10:43               ` Peter Ujfalusi
2010-07-19 16:25               ` Takashi Iwai
2010-07-20  5:39                 ` Peter Ujfalusi
2010-07-20  5:42                   ` Takashi Iwai

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=201007161405.40985.peter.ujfalusi@nokia.com \
    --to=peter.ujfalusi@nokia.com \
    --cc=alsa-devel@alsa-project.org \
    --cc=broonie@opensource.wolfsonmicro.com \
    --cc=lrg@slimlogic.co.uk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.