mirror of
https://github.com/alsa-project/alsa-lib.git
synced 2025-11-03 09:01:52 -05:00
Add dB range information to PCM softvol plugin
Added the dB range information to PCM softvol plugin. Also, fixed the coefficient table to match with the accurate dB step 0.20dB.
This commit is contained in:
parent
d5caee8d36
commit
5c71dd3ee7
2 changed files with 53 additions and 34 deletions
|
|
@ -283,6 +283,8 @@ int snd_ctl_elem_add_integer(snd_ctl_t *ctl, const snd_ctl_elem_id_t *id,
|
||||||
snd_ctl_elem_info_alloca(&info);
|
snd_ctl_elem_info_alloca(&info);
|
||||||
info->id = *id;
|
info->id = *id;
|
||||||
info->type = SND_CTL_ELEM_TYPE_INTEGER;
|
info->type = SND_CTL_ELEM_TYPE_INTEGER;
|
||||||
|
info->access = SNDRV_CTL_ELEM_ACCESS_READWRITE |
|
||||||
|
SNDRV_CTL_ELEM_ACCESS_TLV_READWRITE;
|
||||||
info->count = count;
|
info->count = count;
|
||||||
info->value.integer.min = min;
|
info->value.integer.min = min;
|
||||||
info->value.integer.max = max;
|
info->value.integer.max = max;
|
||||||
|
|
|
||||||
|
|
@ -54,41 +54,41 @@ typedef struct {
|
||||||
#define VOL_SCALE_SHIFT 16
|
#define VOL_SCALE_SHIFT 16
|
||||||
|
|
||||||
#define PRESET_RESOLUTION 256
|
#define PRESET_RESOLUTION 256
|
||||||
#define PRESET_MIN_DB -48.0
|
#define PRESET_MIN_DB -51.0
|
||||||
|
|
||||||
static unsigned short preset_dB_value[PRESET_RESOLUTION] = {
|
static unsigned short preset_dB_value[PRESET_RESOLUTION] = {
|
||||||
0x0000, 0x0104, 0x010a, 0x0110, 0x0116, 0x011c, 0x0122, 0x0129,
|
0x00b8, 0x00bd, 0x00c1, 0x00c5, 0x00ca, 0x00cf, 0x00d4, 0x00d9,
|
||||||
0x012f, 0x0136, 0x013d, 0x0144, 0x014b, 0x0152, 0x015a, 0x0161,
|
0x00de, 0x00e3, 0x00e8, 0x00ed, 0x00f3, 0x00f9, 0x00fe, 0x0104,
|
||||||
0x0169, 0x0171, 0x0179, 0x0181, 0x018a, 0x0193, 0x019c, 0x01a5,
|
0x010a, 0x0111, 0x0117, 0x011e, 0x0124, 0x012b, 0x0132, 0x0139,
|
||||||
0x01ae, 0x01b7, 0x01c1, 0x01cb, 0x01d5, 0x01df, 0x01ea, 0x01f5,
|
0x0140, 0x0148, 0x0150, 0x0157, 0x015f, 0x0168, 0x0170, 0x0179,
|
||||||
0x0200, 0x020b, 0x0216, 0x0222, 0x022e, 0x023b, 0x0247, 0x0254,
|
0x0181, 0x018a, 0x0194, 0x019d, 0x01a7, 0x01b0, 0x01bb, 0x01c5,
|
||||||
0x0261, 0x026e, 0x027c, 0x028a, 0x0298, 0x02a7, 0x02b6, 0x02c5,
|
0x01cf, 0x01da, 0x01e5, 0x01f1, 0x01fc, 0x0208, 0x0214, 0x0221,
|
||||||
0x02d5, 0x02e5, 0x02f5, 0x0306, 0x0317, 0x0328, 0x033a, 0x034c,
|
0x022d, 0x023a, 0x0248, 0x0255, 0x0263, 0x0271, 0x0280, 0x028f,
|
||||||
0x035f, 0x0372, 0x0385, 0x0399, 0x03ad, 0x03c2, 0x03d7, 0x03ed,
|
0x029e, 0x02ae, 0x02be, 0x02ce, 0x02df, 0x02f0, 0x0301, 0x0313,
|
||||||
0x0403, 0x041a, 0x0431, 0x0448, 0x0460, 0x0479, 0x0492, 0x04ac,
|
0x0326, 0x0339, 0x034c, 0x035f, 0x0374, 0x0388, 0x039d, 0x03b3,
|
||||||
0x04c6, 0x04e1, 0x04fd, 0x0519, 0x0535, 0x0553, 0x0571, 0x058f,
|
0x03c9, 0x03df, 0x03f7, 0x040e, 0x0426, 0x043f, 0x0458, 0x0472,
|
||||||
0x05af, 0x05cf, 0x05ef, 0x0611, 0x0633, 0x0656, 0x067a, 0x069e,
|
0x048d, 0x04a8, 0x04c4, 0x04e0, 0x04fd, 0x051b, 0x053a, 0x0559,
|
||||||
0x06c3, 0x06ea, 0x0710, 0x0738, 0x0761, 0x078a, 0x07b5, 0x07e0,
|
0x0579, 0x0599, 0x05bb, 0x05dd, 0x0600, 0x0624, 0x0648, 0x066e,
|
||||||
0x080d, 0x083a, 0x0868, 0x0898, 0x08c8, 0x08fa, 0x092c, 0x0960,
|
0x0694, 0x06bb, 0x06e3, 0x070c, 0x0737, 0x0762, 0x078e, 0x07bb,
|
||||||
0x0995, 0x09cb, 0x0a02, 0x0a3a, 0x0a74, 0x0aae, 0x0aeb, 0x0b28,
|
0x07e9, 0x0818, 0x0848, 0x087a, 0x08ac, 0x08e0, 0x0915, 0x094b,
|
||||||
0x0b67, 0x0ba7, 0x0be9, 0x0c2c, 0x0c70, 0x0cb6, 0x0cfe, 0x0d47,
|
0x0982, 0x09bb, 0x09f5, 0x0a30, 0x0a6d, 0x0aab, 0x0aeb, 0x0b2c,
|
||||||
0x0d92, 0x0dde, 0x0e2d, 0x0e7c, 0x0ece, 0x0f21, 0x0f76, 0x0fce,
|
0x0b6f, 0x0bb3, 0x0bf9, 0x0c40, 0x0c89, 0x0cd4, 0x0d21, 0x0d6f,
|
||||||
0x1027, 0x1081, 0x10de, 0x113d, 0x119f, 0x1202, 0x1267, 0x12cf,
|
0x0dbf, 0x0e11, 0x0e65, 0x0ebb, 0x0f12, 0x0f6c, 0x0fc8, 0x1026,
|
||||||
0x1339, 0x13a5, 0x1414, 0x1485, 0x14f8, 0x156e, 0x15e7, 0x1662,
|
0x1087, 0x10e9, 0x114e, 0x11b5, 0x121f, 0x128b, 0x12fa, 0x136b,
|
||||||
0x16e0, 0x1761, 0x17e5, 0x186b, 0x18f5, 0x1981, 0x1a11, 0x1aa4,
|
0x13df, 0x1455, 0x14ce, 0x154a, 0x15c9, 0x164b, 0x16d0, 0x1758,
|
||||||
0x1b3a, 0x1bd3, 0x1c70, 0x1d10, 0x1db4, 0x1e5b, 0x1f06, 0x1fb4,
|
0x17e4, 0x1872, 0x1904, 0x1999, 0x1a32, 0x1ace, 0x1b6e, 0x1c11,
|
||||||
0x2067, 0x211d, 0x21d8, 0x2297, 0x2359, 0x2420, 0x24ec, 0x25bc,
|
0x1cb9, 0x1d64, 0x1e13, 0x1ec7, 0x1f7e, 0x203a, 0x20fa, 0x21bf,
|
||||||
0x2690, 0x2769, 0x2847, 0x292a, 0x2a12, 0x2aff, 0x2bf1, 0x2ce8,
|
0x2288, 0x2356, 0x2429, 0x2500, 0x25dd, 0x26bf, 0x27a6, 0x2892,
|
||||||
0x2de5, 0x2ee8, 0x2ff0, 0x30fe, 0x3211, 0x332b, 0x344c, 0x3572,
|
0x2984, 0x2a7c, 0x2b79, 0x2c7c, 0x2d85, 0x2e95, 0x2fab, 0x30c7,
|
||||||
0x369f, 0x37d2, 0x390d, 0x3a4e, 0x3b96, 0x3ce6, 0x3e3d, 0x3f9b,
|
0x31ea, 0x3313, 0x3444, 0x357c, 0x36bb, 0x3801, 0x394f, 0x3aa5,
|
||||||
0x4101, 0x426f, 0x43e6, 0x4564, 0x46eb, 0x487a, 0x4a12, 0x4bb3,
|
0x3c02, 0x3d68, 0x3ed6, 0x404d, 0x41cd, 0x4355, 0x44e6, 0x4681,
|
||||||
0x4d5d, 0x4f11, 0x50ce, 0x5295, 0x5466, 0x5642, 0x5827, 0x5a18,
|
0x4826, 0x49d4, 0x4b8c, 0x4d4f, 0x4f1c, 0x50f3, 0x52d6, 0x54c4,
|
||||||
0x5c13, 0x5e19, 0x602b, 0x6249, 0x6472, 0x66a8, 0x68ea, 0x6b39,
|
0x56be, 0x58c3, 0x5ad4, 0x5cf2, 0x5f1c, 0x6153, 0x6398, 0x65e9,
|
||||||
0x6d94, 0x6ffd, 0x7274, 0x74f8, 0x778b, 0x7a2c, 0x7cdc, 0x7f9b,
|
0x6849, 0x6ab7, 0x6d33, 0x6fbf, 0x7259, 0x7503, 0x77bd, 0x7a87,
|
||||||
0x826a, 0x8548, 0x8836, 0x8b35, 0x8e45, 0x9166, 0x9499, 0x97de,
|
0x7d61, 0x804d, 0x834a, 0x8659, 0x897a, 0x8cae, 0x8ff5, 0x934f,
|
||||||
0x9b35, 0x9e9f, 0xa21c, 0xa5ad, 0xa952, 0xad0b, 0xb0da, 0xb4bd,
|
0x96bd, 0x9a40, 0x9dd8, 0xa185, 0xa548, 0xa922, 0xad13, 0xb11b,
|
||||||
0xb8b7, 0xbcc7, 0xc0ee, 0xc52d, 0xc983, 0xcdf1, 0xd279, 0xd71a,
|
0xb53b, 0xb973, 0xbdc5, 0xc231, 0xc6b7, 0xcb58, 0xd014, 0xd4ed,
|
||||||
0xdbd5, 0xe0ab, 0xe59c, 0xeaa9, 0xefd3, 0xf519, 0xfa7d, 0xffff,
|
0xd9e3, 0xdef6, 0xe428, 0xe978, 0xeee8, 0xf479, 0xfa2b, 0xffff,
|
||||||
};
|
};
|
||||||
|
|
||||||
/* (32bit x 16bit) >> 16 */
|
/* (32bit x 16bit) >> 16 */
|
||||||
|
|
@ -548,6 +548,16 @@ static void snd_pcm_softvol_dump(snd_pcm_t *pcm, snd_output_t *out)
|
||||||
snd_pcm_dump(svol->plug.gen.slave, out);
|
snd_pcm_dump(svol->plug.gen.slave, out);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int add_tlv_info(snd_pcm_softvol_t *svol, snd_ctl_elem_info_t *cinfo)
|
||||||
|
{
|
||||||
|
unsigned int tlv[4];
|
||||||
|
tlv[0] = SND_CTL_TLVT_DB_SCALE;
|
||||||
|
tlv[1] = 2 * sizeof(int);
|
||||||
|
tlv[2] = svol->min_dB * 100;
|
||||||
|
tlv[3] = -svol->min_dB * 100 / svol->max_val;
|
||||||
|
return snd_ctl_elem_tlv_write(svol->ctl, &cinfo->id, tlv);
|
||||||
|
}
|
||||||
|
|
||||||
static int add_user_ctl(snd_pcm_softvol_t *svol, snd_ctl_elem_info_t *cinfo, int count)
|
static int add_user_ctl(snd_pcm_softvol_t *svol, snd_ctl_elem_info_t *cinfo, int count)
|
||||||
{
|
{
|
||||||
int err;
|
int err;
|
||||||
|
|
@ -556,6 +566,7 @@ static int add_user_ctl(snd_pcm_softvol_t *svol, snd_ctl_elem_info_t *cinfo, int
|
||||||
err = snd_ctl_elem_add_integer(svol->ctl, &cinfo->id, count, 0, svol->max_val, 0);
|
err = snd_ctl_elem_add_integer(svol->ctl, &cinfo->id, count, 0, svol->max_val, 0);
|
||||||
if (err < 0)
|
if (err < 0)
|
||||||
return err;
|
return err;
|
||||||
|
add_tlv_info(svol, cinfo);
|
||||||
/* set max value as default */
|
/* set max value as default */
|
||||||
for (i = 0; i < count; i++)
|
for (i = 0; i < count; i++)
|
||||||
svol->elem.value.integer.value[i] = svol->max_val;
|
svol->elem.value.integer.value[i] = svol->max_val;
|
||||||
|
|
@ -630,6 +641,12 @@ static int softvol_load_control(snd_pcm_t *pcm, snd_pcm_softvol_t *svol,
|
||||||
SNDERR("Cannot add a control");
|
SNDERR("Cannot add a control");
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
/* check TLV availability */
|
||||||
|
unsigned int tlv[4];
|
||||||
|
err = snd_ctl_elem_tlv_read(svol->ctl, &cinfo->id, tlv, sizeof(tlv));
|
||||||
|
if (err < 0)
|
||||||
|
add_tlv_info(svol, cinfo);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -794,7 +811,7 @@ pcm.name {
|
||||||
[subdevice INT] # subdevice number of the element
|
[subdevice INT] # subdevice number of the element
|
||||||
[count INT] # control channels 1 or 2 (default: 2)
|
[count INT] # control channels 1 or 2 (default: 2)
|
||||||
}
|
}
|
||||||
[min_dB REAL] # minimal dB value (default: -48.0)
|
[min_dB REAL] # minimal dB value (default: -51.0)
|
||||||
[resolution INT] # resolution (default: 256)
|
[resolution INT] # resolution (default: 256)
|
||||||
}
|
}
|
||||||
\endcode
|
\endcode
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue