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. + 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. For example, with the EMU DSPs one control can do 0 dB to -inf gain, and another can to 0 dB to X gain. I was thinking of implementing these in the emu10k1 module, with special code to link the two at the kernel module level, but it might save code duplication if we let alsa-lib do this task. We might be able to do a similar link between mic gain and mic boost switches. James ------------------------------------------------------------------------- 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