Re: [RFC] dB range compound

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



At Mon, 04 Sep 2006 13:40:13 +0100,
James Courtier-Dutton wrote:
> 
> Takashi Iwai wrote:
> > Hi,
> > 
> > I found that some hardwares require the combination of dB scale
> > ranges.  For example, es1938 has volume controls with two curves,
> > e.g. the volume step in the value 0-8 is 3 dB while it's 1.5 dB in the
> > values 8-15.
> > 
> > The patch below introduces a new TLV type, DB_RANGE, to implement
> > the compound dB scales.  It can contain one or more child TLVs,
> > together with min and max values for each.
> > 
> > The first patch is for the kernel and the second for alsa-lib.
> > 
> > Any comments?
> > 
> > 
> > Takashi
> > 
> +static int do_convert_to_dB(unsigned int *tlv, long rangemin, long
> rangemax,
> +			    long volume, long *db_gain)
> +{
> +	switch (tlv[0]) {
> +	case SND_CTL_TLVT_DB_RANGE: {
> +		unsigned int pos, len;
> +		len = tlv[1] / sizeof(int);
> +		pos = 2;
> 
> Be careful with this len limit in the while loop. I suggest adding a
> further comparison to limit the loop to a constant size:
> e.g.
> while (pos + 4 <= len && (pos + 4 < MAX_BUFFER_SIZE) ) {
> There are similar cases elsewhere in the patch.

Yes, it'd be safer.  Will fix them.

> 
> +		while (pos + 4 <= len) {
> +			rangemin = (int)tlv[pos];
> +			rangemax = (int)tlv[pos + 1];
> +			if (volume >= rangemin && volume <= rangemax)
> +				return do_convert_to_dB(tlv + pos + 2,
> +							rangemin, rangemax,
> +							volume, db_gain);
> +			pos += tlv[pos + 3] + 4;
> +		}
>  		return -EINVAL;
> 
> 
> Apart from that, It looks OK to me.
> 
> With regard to this control actually being to separate register in the
> chip, I think it might be nice to implement two separate controls
> between kernel and alsa-lib, but add some TLV tag to link the two
> controls together so that they appear as one. This will save code size
> in the kernel.

Agreed, this should really depend on the implementation.
In the case of es1938, however, it's clearly a single control (just
the dB scale curve is non-linear).


Thanks,

Takashi

-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Alsa-devel mailing list
Alsa-devel@xxxxxxxxxxxxxxxxxxxxx
https://lists.sourceforge.net/lists/listinfo/alsa-devel

[Index of Archives]     [ALSA User]     [Linux Audio Users]     [Kernel Archive]     [Asterisk PBX]     [Photo Sharing]     [Linux Sound]     [Video 4 Linux]     [Gimp]     [Yosemite News]

  Powered by Linux