ALSA: emu10k1: various improvements to the DSP-based mixer code
Subsystems (2)
cover ALSA: emu10k1: various improvements to the DSP-based mixer code
Oswald Buddenhagen (14):
ALSA: emu10k1: make tone control switch mono
ALSA: emu10k1: roll up loops in DSP setup code for Audigy
ALSA: emu10k1: fix+optimize E-MU stereo capture DSP code
ALSA: emu10k1: simplify snd_emu10k1_audigy_dsp_convert_32_to_2x16()
ALSA: emu10k1: apply channel delay hack to all E-MU cards
ALSA: emu10k1: simplify tone control switch DSP code
ALSA: emu10k1: properly assert DSP init constraints
ALSA: emu10k1: polish audigy GPR allocation
ALSA: emu10k1: fix non-zero mixer control defaults in highres mode
ALSA: emu10k1: validate min/max values of translated controls
ALSA: emu10k1: omit non-applicable mixer controls for E-MU cards
ALSA: emu10k1: skip mic capture PCM for cards without AC97 codec
ALSA: emu10k1: enable bit-exact playback, part 1: DSP attenuation
ALSA: emu10k1: enable bit-exact playback, part 2: voice attenuation
Documentation/sound/cards/audigy-mixer.rst | 2 +- Documentation/sound/cards/sb-live-mixer.rst | 2 +- include/sound/emu10k1.h | 10 +- include/uapi/sound/emu10k1.h | 8 +- sound/pci/emu10k1/emu10k1.c | 8 +- sound/pci/emu10k1/emufx.c | 763 +++++++++----------- sound/pci/emu10k1/emumixer.c | 15 +- sound/pci/emu10k1/emupcm.c | 4 +- 8 files changed, 369 insertions(+), 443 deletions(-)
Signature · 1 line
2.40.0.152.g15d061e6df
PATCH 1/14 ALSA: emu10k1: make tone control switch mono
It controls the whole surround set, so stereo can't work. As a consequence, only the left channel was paid attention to.
--- sound/pci/emu10k1/emufx.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-)
sound/pci/emu10k1/emufx.c +8 -8
@@ -1543,13 +1543,13 @@ A_OP(icode, &ptr, iMAC0, A_GPR(var), A_GPR(var), A_GPR(vol), A_EXTIN(input))#undef TREBLE_GPRfor (z =0 ; z <8 ; z++) { -A_SWITCH (icode, &ptr, tmp +0 , playback +SND_EMU10K1_PLAYBACK_CHANNELS + z, gpr +0 ); -A_SWITCH_NEG (icode, &ptr, tmp +1 , gpr +0 ); +A_SWITCH (icode, &ptr, tmp +0 , playback +SND_EMU10K1_PLAYBACK_CHANNELS + z, gpr); +A_SWITCH_NEG (icode, &ptr, tmp +1 , gpr);A_SWITCH (icode, &ptr, tmp +1 , playback + z, tmp +1 );A_OP (icode, &ptr, iACC3,A_GPR (playback +SND_EMU10K1_PLAYBACK_CHANNELS + z),A_GPR (tmp +0 ),A_GPR (tmp +1 ),A_C_00000000 ); } -snd_emu10k1_init_stereo_onoff_control (controls + nctl++,"Tone Control - Switch" , gpr,0 ); - gpr +=2 ; +snd_emu10k1_init_mono_onoff_control (controls + nctl++,"Tone Control - Switch" , gpr,0 ); + gpr++;/* Master volume (will be renamed later) */ A_OP (icode, &ptr, iMAC0,A_GPR (playback+0 +SND_EMU10K1_PLAYBACK_CHANNELS ),A_C_00000000 ,A_GPR (gpr),A_GPR (playback+0 +SND_EMU10K1_PLAYBACK_CHANNELS ));
@@ -2263,13 +2263,13 @@ static int _snd_emu10k1_init_efx(struct snd_emu10k1 *emu)#undef TREBLE_GPRfor (z =0 ; z <6 ; z++) { -SWITCH (icode, &ptr, tmp +0 , playback +SND_EMU10K1_PLAYBACK_CHANNELS + z, gpr +0 ); -SWITCH_NEG (icode, &ptr, tmp +1 , gpr +0 ); +SWITCH (icode, &ptr, tmp +0 , playback +SND_EMU10K1_PLAYBACK_CHANNELS + z, gpr); +SWITCH_NEG (icode, &ptr, tmp +1 , gpr);SWITCH (icode, &ptr, tmp +1 , playback + z, tmp +1 );OP (icode, &ptr, iACC3,GPR (playback +SND_EMU10K1_PLAYBACK_CHANNELS + z),GPR (tmp +0 ),GPR (tmp +1 ),C_00000000 ); } -snd_emu10k1_init_stereo_onoff_control (controls + i++,"Tone Control - Switch" , gpr,0 ); - gpr +=2 ; +snd_emu10k1_init_mono_onoff_control (controls + i++,"Tone Control - Switch" , gpr,0 ); + gpr++;/* * Process outputs
Signature · 1 line
2.40.0.152.g15d061e6df
PATCH 2/14 ALSA: emu10k1: roll up loops in DSP setup code for Audigy
In reply to Oswald BuddenhagenThere is no apparent reason for the massive code duplication.
--- sound/pci/emu10k1/emufx.c | 112 +++----------------------------------- 1 file changed, 9 insertions(+), 103 deletions(-)
sound/pci/emu10k1/emufx.c +9 -103
@@ -1552,14 +1552,8 @@ A_OP(icode, &ptr, iMAC0, A_GPR(var), A_GPR(var), A_GPR(vol), A_EXTIN(input)) gpr++;/* Master volume (will be renamed later) */ -A_OP (icode, &ptr, iMAC0,A_GPR (playback+0 +SND_EMU10K1_PLAYBACK_CHANNELS ),A_C_00000000 ,A_GPR (gpr),A_GPR (playback+0 +SND_EMU10K1_PLAYBACK_CHANNELS )); -A_OP (icode, &ptr, iMAC0,A_GPR (playback+1 +SND_EMU10K1_PLAYBACK_CHANNELS ),A_C_00000000 ,A_GPR (gpr),A_GPR (playback+1 +SND_EMU10K1_PLAYBACK_CHANNELS )); -A_OP (icode, &ptr, iMAC0,A_GPR (playback+2 +SND_EMU10K1_PLAYBACK_CHANNELS ),A_C_00000000 ,A_GPR (gpr),A_GPR (playback+2 +SND_EMU10K1_PLAYBACK_CHANNELS )); -A_OP (icode, &ptr, iMAC0,A_GPR (playback+3 +SND_EMU10K1_PLAYBACK_CHANNELS ),A_C_00000000 ,A_GPR (gpr),A_GPR (playback+3 +SND_EMU10K1_PLAYBACK_CHANNELS )); -A_OP (icode, &ptr, iMAC0,A_GPR (playback+4 +SND_EMU10K1_PLAYBACK_CHANNELS ),A_C_00000000 ,A_GPR (gpr),A_GPR (playback+4 +SND_EMU10K1_PLAYBACK_CHANNELS )); -A_OP (icode, &ptr, iMAC0,A_GPR (playback+5 +SND_EMU10K1_PLAYBACK_CHANNELS ),A_C_00000000 ,A_GPR (gpr),A_GPR (playback+5 +SND_EMU10K1_PLAYBACK_CHANNELS )); -A_OP (icode, &ptr, iMAC0,A_GPR (playback+6 +SND_EMU10K1_PLAYBACK_CHANNELS ),A_C_00000000 ,A_GPR (gpr),A_GPR (playback+6 +SND_EMU10K1_PLAYBACK_CHANNELS )); -A_OP (icode, &ptr, iMAC0,A_GPR (playback+7 +SND_EMU10K1_PLAYBACK_CHANNELS ),A_C_00000000 ,A_GPR (gpr),A_GPR (playback+7 +SND_EMU10K1_PLAYBACK_CHANNELS )); +for (z =0 ; z <8 ; z++) +A_OP (icode, &ptr, iMAC0,A_GPR (playback+z+SND_EMU10K1_PLAYBACK_CHANNELS ),A_C_00000000 ,A_GPR (gpr),A_GPR (playback+z+SND_EMU10K1_PLAYBACK_CHANNELS ));snd_emu10k1_init_mono_control (&controls[nctl++],"Wave Master Playback Volume" , gpr,0 ); gpr +=2 ;
@@ -1646,102 +1640,14 @@ A_OP(icode, &ptr, iMAC0, A_GPR(var), A_GPR(var), A_GPR(vol), A_EXTIN(input))dev_dbg(emu->card->dev, "emufx.c: gpr=0x%x, tmp=0x%x\n", gpr, tmp); */ -/* For the EMU1010: How to get 32bit values from the DSP. High 16bits into L, low 16bits into R. */ -/* A_P16VIN(0) is delayed by one sample, -* so all other A_P16VIN channels will need to also be delayed -*/ -/* Left ADC in. 1 of 2 */ snd_emu10k1_audigy_dsp_convert_32_to_2x16 ( icode, &ptr, tmp, bit_shifter16,A_P16VIN (0x0 ),A_FXBUS2 (0 ) ); -/* Right ADC in 1 of 2 */ - gpr_map[gpr++] =0x00000000 ; -/* Delaying by one sample: instead of copying the input -* value A_P16VIN to output A_FXBUS2 as in the first channel, -* we use an auxiliary register, delaying the value by one -* sample -*/ -snd_emu10k1_audigy_dsp_convert_32_to_2x16 ( icode, &ptr, tmp, bit_shifter16,A_GPR (gpr -1 ),A_FXBUS2 (2 ) ); -A_OP (icode, &ptr, iACC3,A_GPR (gpr -1 ),A_P16VIN (0x1 ),A_C_00000000 ,A_C_00000000 ); - gpr_map[gpr++] =0x00000000 ; -snd_emu10k1_audigy_dsp_convert_32_to_2x16 ( icode, &ptr, tmp, bit_shifter16,A_GPR (gpr -1 ),A_FXBUS2 (4 ) ); -A_OP (icode, &ptr, iACC3,A_GPR (gpr -1 ),A_P16VIN (0x2 ),A_C_00000000 ,A_C_00000000 ); - gpr_map[gpr++] =0x00000000 ; -snd_emu10k1_audigy_dsp_convert_32_to_2x16 ( icode, &ptr, tmp, bit_shifter16,A_GPR (gpr -1 ),A_FXBUS2 (6 ) ); -A_OP (icode, &ptr, iACC3,A_GPR (gpr -1 ),A_P16VIN (0x3 ),A_C_00000000 ,A_C_00000000 ); -/* For 96kHz mode */ -/* Left ADC in. 2 of 2 */ - gpr_map[gpr++] =0x00000000 ; -snd_emu10k1_audigy_dsp_convert_32_to_2x16 ( icode, &ptr, tmp, bit_shifter16,A_GPR (gpr -1 ),A_FXBUS2 (0x8 ) ); -A_OP (icode, &ptr, iACC3,A_GPR (gpr -1 ),A_P16VIN (0x4 ),A_C_00000000 ,A_C_00000000 ); -/* Right ADC in 2 of 2 */ - gpr_map[gpr++] =0x00000000 ; -snd_emu10k1_audigy_dsp_convert_32_to_2x16 ( icode, &ptr, tmp, bit_shifter16,A_GPR (gpr -1 ),A_FXBUS2 (0xa ) ); -A_OP (icode, &ptr, iACC3,A_GPR (gpr -1 ),A_P16VIN (0x5 ),A_C_00000000 ,A_C_00000000 ); - gpr_map[gpr++] =0x00000000 ; -snd_emu10k1_audigy_dsp_convert_32_to_2x16 ( icode, &ptr, tmp, bit_shifter16,A_GPR (gpr -1 ),A_FXBUS2 (0xc ) ); -A_OP (icode, &ptr, iACC3,A_GPR (gpr -1 ),A_P16VIN (0x6 ),A_C_00000000 ,A_C_00000000 ); - gpr_map[gpr++] =0x00000000 ; -snd_emu10k1_audigy_dsp_convert_32_to_2x16 ( icode, &ptr, tmp, bit_shifter16,A_GPR (gpr -1 ),A_FXBUS2 (0xe ) ); -A_OP (icode, &ptr, iACC3,A_GPR (gpr -1 ),A_P16VIN (0x7 ),A_C_00000000 ,A_C_00000000 ); -/* Pavel Hofman - we still have voices, A_FXBUS2s, and -* A_P16VINs available - -* let's add 8 more capture channels - total of 16 -*/ - gpr_map[gpr++] =0x00000000 ; -snd_emu10k1_audigy_dsp_convert_32_to_2x16 (icode, &ptr, tmp, - bit_shifter16, -A_GPR (gpr -1 ), -A_FXBUS2 (0x10 )); -A_OP (icode, &ptr, iACC3,A_GPR (gpr -1 ),A_P16VIN (0x8 ), -A_C_00000000 ,A_C_00000000 ); - gpr_map[gpr++] =0x00000000 ; -snd_emu10k1_audigy_dsp_convert_32_to_2x16 (icode, &ptr, tmp, - bit_shifter16, -A_GPR (gpr -1 ), -A_FXBUS2 (0x12 )); -A_OP (icode, &ptr, iACC3,A_GPR (gpr -1 ),A_P16VIN (0x9 ), -A_C_00000000 ,A_C_00000000 ); - gpr_map[gpr++] =0x00000000 ; -snd_emu10k1_audigy_dsp_convert_32_to_2x16 (icode, &ptr, tmp, - bit_shifter16, -A_GPR (gpr -1 ), -A_FXBUS2 (0x14 )); -A_OP (icode, &ptr, iACC3,A_GPR (gpr -1 ),A_P16VIN (0xa ), -A_C_00000000 ,A_C_00000000 ); - gpr_map[gpr++] =0x00000000 ; -snd_emu10k1_audigy_dsp_convert_32_to_2x16 (icode, &ptr, tmp, - bit_shifter16, -A_GPR (gpr -1 ), -A_FXBUS2 (0x16 )); -A_OP (icode, &ptr, iACC3,A_GPR (gpr -1 ),A_P16VIN (0xb ), -A_C_00000000 ,A_C_00000000 ); - gpr_map[gpr++] =0x00000000 ; -snd_emu10k1_audigy_dsp_convert_32_to_2x16 (icode, &ptr, tmp, - bit_shifter16, -A_GPR (gpr -1 ), -A_FXBUS2 (0x18 )); -A_OP (icode, &ptr, iACC3,A_GPR (gpr -1 ),A_P16VIN (0xc ), -A_C_00000000 ,A_C_00000000 ); - gpr_map[gpr++] =0x00000000 ; -snd_emu10k1_audigy_dsp_convert_32_to_2x16 (icode, &ptr, tmp, - bit_shifter16, -A_GPR (gpr -1 ), -A_FXBUS2 (0x1a )); -A_OP (icode, &ptr, iACC3,A_GPR (gpr -1 ),A_P16VIN (0xd ), -A_C_00000000 ,A_C_00000000 ); - gpr_map[gpr++] =0x00000000 ; -snd_emu10k1_audigy_dsp_convert_32_to_2x16 (icode, &ptr, tmp, - bit_shifter16, -A_GPR (gpr -1 ), -A_FXBUS2 (0x1c )); -A_OP (icode, &ptr, iACC3,A_GPR (gpr -1 ),A_P16VIN (0xe ), -A_C_00000000 ,A_C_00000000 ); - gpr_map[gpr++] =0x00000000 ; -snd_emu10k1_audigy_dsp_convert_32_to_2x16 (icode, &ptr, tmp, - bit_shifter16, -A_GPR (gpr -1 ), -A_FXBUS2 (0x1e )); -A_OP (icode, &ptr, iACC3,A_GPR (gpr -1 ),A_P16VIN (0xf ), -A_C_00000000 ,A_C_00000000 ); +/* A_P16VIN(0) is delayed by one sample, so all other A_P16VIN channels +* will need to also be delayed; we use an auxiliary register for that. */ +for (z =1 ; z <0x10 ; z++) { +snd_emu10k1_audigy_dsp_convert_32_to_2x16 ( icode, &ptr, tmp, bit_shifter16,A_GPR (gpr),A_FXBUS2 (z *2 ) ); +A_OP (icode, &ptr, iACC3,A_GPR (gpr),A_P16VIN (z),A_C_00000000 ,A_C_00000000 ); + gpr_map[gpr++] =0x00000000 ; + } }#if 0
Signature · 1 line
2.40.0.152.g15d061e6df
PATCH 3/14 ALSA: emu10k1: fix+optimize E-MU stereo capture DSP code
In reply to Oswald BuddenhagenPresumably, JDC added the seemingly superfluous indirection over the temporary register because without it he'd get only zero readings. However, switching the X and Y operands (or using EMU32 as the A operand in the temporary load) works just fine. Presumably a DSP bug?
The original code was also actually buggy, though: both channels used the left volume control.
--- sound/pci/emu10k1/emufx.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-)
sound/pci/emu10k1/emufx.c +3 -5
@@ -1324,11 +1324,9 @@ A_OP(icode, &ptr, iMAC0, A_GPR(var), A_GPR(var), A_GPR(vol), A_EXTIN(input))/* EMU1010 DSP 0 and DSP 1 Capture */ // The 24 MSB hold the actual value. We implicitly discard the 16 LSB. if (emu->card_capabilities->ca0108_chip) { -/* Note:JCD:No longer bit shift lower 16bits to upper 16bits of 32bit value. */ -A_OP (icode, &ptr, iMACINT0,A_GPR (tmp),A_C_00000000 ,A3_EMU32IN (0x0 ),A_C_00000001 ); -A_OP (icode, &ptr, iMAC0,A_GPR (capture+0 ),A_GPR (capture+0 ),A_GPR (gpr),A_GPR (tmp)); -A_OP (icode, &ptr, iMACINT0,A_GPR (tmp),A_C_00000000 ,A3_EMU32IN (0x1 ),A_C_00000001 ); -A_OP (icode, &ptr, iMAC0,A_GPR (capture+1 ),A_GPR (capture+1 ),A_GPR (gpr),A_GPR (tmp)); +// For unclear reasons, the EMU32IN cannot be the Y operand! +A_OP (icode, &ptr, iMAC0,A_GPR (capture+0 ),A_GPR (capture+0 ),A3_EMU32IN (0x0 ),A_GPR (gpr)); +A_OP (icode, &ptr, iMAC0,A_GPR (capture+1 ),A_GPR (capture+1 ),A3_EMU32IN (0x1 ),A_GPR (gpr+1 )); }else {A_OP (icode, &ptr, iMAC0,A_GPR (capture+0 ),A_GPR (capture+0 ),A_GPR (gpr),A_P16VIN (0x0 ));A_OP (icode, &ptr, iMAC0,A_GPR (capture+1 ),A_GPR (capture+1 ),A_GPR (gpr+1 ),A_P16VIN (0x1 ));
Signature · 1 line
2.40.0.152.g15d061e6df
PATCH 4/14 ALSA: emu10k1: simplify snd_emu10k1_audigy_dsp_convert_32_to_2x16()
In reply to Oswald BuddenhagenInstead of spending lots of instructions on masking and transplanting the sign bit, sidestep the issue by replacing the last bit shift with a wrapping addition to self.
Solution stolen from kX-project, after I pondered other ideas first.
Also, the function really doesn't need to return a constant int value.
--- sound/pci/emu10k1/emufx.c | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-)
sound/pci/emu10k1/emufx.c +13 -13
@@ -1184,20 +1184,22 @@ snd_emu10k1_init_stereo_onoff_control(struct snd_emu10k1_fx8010_control_gpr *ctl* to 2 x 16-bit registers in Audigy - their values are read via DMA. * Conversion is performed by Audigy DSP instructions of FX8010. */ -static int snd_emu10k1_audigy_dsp_convert_32_to_2x16 ( +static void snd_emu10k1_audigy_dsp_convert_32_to_2x16 (struct snd_emu10k1_fx8010_code *icode,u32 *ptr,int tmp,int bit_shifter16,int reg_in,int reg_out) { -A_OP (icode, ptr, iACC3,A_GPR (tmp +1 ), reg_in,A_C_00000000 ,A_C_00000000 ); -A_OP (icode, ptr, iANDXOR,A_GPR (tmp),A_GPR (tmp +1 ),A_GPR (bit_shifter16 -1 ),A_C_00000000 ); -A_OP (icode, ptr, iTSTNEG,A_GPR (tmp +2 ),A_GPR (tmp),A_C_80000000 ,A_GPR (bit_shifter16 -2 )); -A_OP (icode, ptr, iANDXOR,A_GPR (tmp +2 ),A_GPR (tmp +2 ),A_C_80000000 ,A_C_00000000 ); -A_OP (icode, ptr, iANDXOR,A_GPR (tmp),A_GPR (tmp),A_GPR (bit_shifter16 -3 ),A_C_00000000 ); -A_OP (icode, ptr, iMACINT0,A_GPR (tmp),A_C_00000000 ,A_GPR (tmp),A_C_00010000 ); -A_OP (icode, ptr, iANDXOR, reg_out,A_GPR (tmp), A_C_ffffffff,A_GPR (tmp +2 )); -A_OP (icode, ptr, iACC3, reg_out +1 ,A_GPR (tmp +1 ),A_C_00000000 ,A_C_00000000 ); -return 1 ; +// This leaves the low word in place, which is fine, +// as the low bits are completely ignored subsequently. +// reg_out[1] = reg_in +A_OP (icode, ptr, iACC3, reg_out +1 , reg_in,A_C_00000000 ,A_C_00000000 ); +// It is fine to read reg_in multiple times. +// tmp = reg_in << 15 +A_OP (icode, ptr, iMACINT1,A_GPR (tmp),A_C_00000000 , reg_in,A_GPR (bit_shifter16)); +// Left-shift once more. This is a separate step, as the +// signed multiplication would clobber the MSB. +// reg_out[0] = tmp + ((tmp << 31) >> 31) +A_OP (icode, ptr, iMAC3, reg_out,A_GPR (tmp),A_GPR (tmp),A_C_80000000 ); }/*
@@ -1247,10 +1249,8 @@ static int _snd_emu10k1_audigy_init_efx(struct snd_emu10k1 *emu) ptr =0 ; nctl =0 ; gpr = stereo_mix +10 ; - gpr_map[gpr++] =0x00007fff ; - gpr_map[gpr++] =0x00008000 ; - gpr_map[gpr++] =0x0000ffff ; bit_shifter16 = gpr; + gpr_map[gpr++] =0x00008000 ;#if 1 /* PCM front Playback Volume (independent from stereo mix)
Signature · 1 line
2.40.0.152.g15d061e6df
PATCH 5/14 ALSA: emu10k1: apply channel delay hack to all E-MU cards
In reply to Oswald BuddenhagenEvidently, the channel delay bug exists in all E-MU cards; it's in the Hana FPGA program, and was never fixed.
Note that the implementation is somewhat lazy - to localize the code paths, we actually waste a GPR and a DSP instruction by keeping two delay registers for the same physical source.
--- include/sound/emu10k1.h | 1 + sound/pci/emu10k1/emufx.c | 23 ++++++++++++++++++----- 2 files changed, 19 insertions(+), 5 deletions(-)
include/sound/emu10k1.h +1 -0
@@ -1192,6 +1192,7 @@* emumixer.c - snd_emu1010_output_enum_ctls[], snd_emu1010_input_enum_ctls[] */ #define EMU_DST_ALICE2_EMU32_0 0x000f/* 16 EMU32 channels to Alice2 +0 to +0xf */ +/* This channel is delayed by one sample. */ #define EMU_DST_ALICE2_EMU32_1 0x0000/* 16 EMU32 channels to Alice2 +0 to +0xf */ #define EMU_DST_ALICE2_EMU32_2 0x0001/* 16 EMU32 channels to Alice2 +0 to +0xf */ #define EMU_DST_ALICE2_EMU32_3 0x0002/* 16 EMU32 channels to Alice2 +0 to +0xf */
sound/pci/emu10k1/emufx.c +18 -5
@@ -1326,13 +1326,20 @@ A_OP(icode, &ptr, iMAC0, A_GPR(var), A_GPR(var), A_GPR(vol), A_EXTIN(input))if (emu->card_capabilities->ca0108_chip) {// For unclear reasons, the EMU32IN cannot be the Y operand! A_OP (icode, &ptr, iMAC0,A_GPR (capture+0 ),A_GPR (capture+0 ),A3_EMU32IN (0x0 ),A_GPR (gpr)); -A_OP (icode, &ptr, iMAC0,A_GPR (capture+1 ),A_GPR (capture+1 ),A3_EMU32IN (0x1 ),A_GPR (gpr+1 )); +// A3_EMU32IN(0) is delayed by one sample, so all other A3_EMU32IN channels +// need to be delayed as well; we use an auxiliary register for that. +A_OP (icode, &ptr, iMAC0,A_GPR (capture+1 ),A_GPR (capture+1 ),A_GPR (gpr+2 ),A_GPR (gpr+1 )); +A_OP (icode, &ptr, iACC3,A_GPR (gpr+2 ),A3_EMU32IN (0x1 ),A_C_00000000 ,A_C_00000000 ); }else {A_OP (icode, &ptr, iMAC0,A_GPR (capture+0 ),A_GPR (capture+0 ),A_GPR (gpr),A_P16VIN (0x0 )); -A_OP (icode, &ptr, iMAC0,A_GPR (capture+1 ),A_GPR (capture+1 ),A_GPR (gpr+1 ),A_P16VIN (0x1 )); +// A_P16VIN(0) is delayed by one sample, so all other A_P16VIN channels +// need to be delayed as well; we use an auxiliary register for that. +A_OP (icode, &ptr, iMAC0,A_GPR (capture+1 ),A_GPR (capture+1 ),A_GPR (gpr+1 ),A_GPR (gpr+2 )); +A_OP (icode, &ptr, iACC3,A_GPR (gpr+2 ),A_P16VIN (0x1 ),A_C_00000000 ,A_C_00000000 ); }snd_emu10k1_init_stereo_control (&controls[nctl++],"EMU Capture Volume" , gpr,0 ); - gpr +=2 ; + gpr_map[gpr +2 ] =0x00000000 ; + gpr +=3 ; }/* AC'97 Playback Volume - used only for mic (renamed later) */ A_ADD_VOLUME_IN (stereo_mix, gpr,A_EXTIN_AC97_L );
@@ -1624,11 +1631,17 @@ A_OP(icode, &ptr, iMAC0, A_GPR(var), A_GPR(var), A_GPR(vol), A_EXTIN(input))dev_info (emu->card->dev,"EMU2 inputs on\n" );/* Note that the Tina[2] DSPs have 16 more EMU32 inputs which we don't use. */ -for (z =0 ; z <0x10 ; z++) { +snd_emu10k1_audigy_dsp_convert_32_to_2x16 ( + icode, &ptr, tmp, bit_shifter16,A3_EMU32IN (0 ),A_FXBUS2 (0 )); +// A3_EMU32IN(0) is delayed by one sample, so all other A3_EMU32IN channels +// need to be delayed as well; we use an auxiliary register for that. +for (z =1 ; z <0x10 ; z++) {snd_emu10k1_audigy_dsp_convert_32_to_2x16 ( icode, &ptr, tmp, bit_shifter16, -A3_EMU32IN (z), +A_GPR (gpr),A_FXBUS2 (z*2 ) ); +A_OP (icode, &ptr, iACC3,A_GPR (gpr),A3_EMU32IN (z),A_C_00000000 ,A_C_00000000 ); + gpr_map[gpr++] =0x00000000 ; } }else {dev_info (emu->card->dev,"EMU inputs on\n" );
Signature · 1 line
2.40.0.152.g15d061e6df
PATCH 6/14 ALSA: emu10k1: simplify tone control switch DSP code
In reply to Oswald BuddenhagenInstead of using lots of instructions to mix wet and dry signals, simply skip over the whole code block if tone control is disabled. This also allows us doing away with the "shadow" playback channels.
--- sound/pci/emu10k1/emufx.c | 123 ++++++++++++++++---------------------- 1 file changed, 50 insertions(+), 73 deletions(-)
sound/pci/emu10k1/emufx.c +50 -73
@@ -1211,10 +1211,10 @@ static int _snd_emu10k1_audigy_init_efx(struct snd_emu10k1 *emu)int err, z, gpr, nctl;int bit_shifter16;const int playback =10 ; -const int capture = playback + (SND_EMU10K1_PLAYBACK_CHANNELS *2 );/* we reserve 10 voices */ +const int capture = playback +SND_EMU10K1_PLAYBACK_CHANNELS ;/* we reserve 10 voices */ const int stereo_mix = capture +2 ;const int tmp =0x88 ; -u32 ptr; +u32 ptr, ptr_skip;struct snd_emu10k1_fx8010_code *icode =NULL ;struct snd_emu10k1_fx8010_control_gpr *controls =NULL , *ctl;u32 *gpr_map;
@@ -1474,18 +1474,6 @@ A_OP(icode, &ptr, iMAC0, A_GPR(var), A_GPR(var), A_GPR(vol), A_EXTIN(input))/* * Process tone control */ -A_OP (icode, &ptr, iACC3,A_GPR (playback +SND_EMU10K1_PLAYBACK_CHANNELS +0 ),A_GPR (playback +0 ),A_C_00000000 ,A_C_00000000 );/* left */ -A_OP (icode, &ptr, iACC3,A_GPR (playback +SND_EMU10K1_PLAYBACK_CHANNELS +1 ),A_GPR (playback +1 ),A_C_00000000 ,A_C_00000000 );/* right */ -A_OP (icode, &ptr, iACC3,A_GPR (playback +SND_EMU10K1_PLAYBACK_CHANNELS +2 ),A_GPR (playback +2 ),A_C_00000000 ,A_C_00000000 );/* rear left */ -A_OP (icode, &ptr, iACC3,A_GPR (playback +SND_EMU10K1_PLAYBACK_CHANNELS +3 ),A_GPR (playback +3 ),A_C_00000000 ,A_C_00000000 );/* rear right */ -A_OP (icode, &ptr, iACC3,A_GPR (playback +SND_EMU10K1_PLAYBACK_CHANNELS +4 ),A_GPR (playback +4 ),A_C_00000000 ,A_C_00000000 );/* center */ -A_OP (icode, &ptr, iACC3,A_GPR (playback +SND_EMU10K1_PLAYBACK_CHANNELS +5 ),A_GPR (playback +5 ),A_C_00000000 ,A_C_00000000 );/* LFE */ -if (emu->card_capabilities->spk71) { -A_OP (icode, &ptr, iACC3,A_GPR (playback +SND_EMU10K1_PLAYBACK_CHANNELS +6 ),A_GPR (playback +6 ),A_C_00000000 ,A_C_00000000 );/* side left */ -A_OP (icode, &ptr, iACC3,A_GPR (playback +SND_EMU10K1_PLAYBACK_CHANNELS +7 ),A_GPR (playback +7 ),A_C_00000000 ,A_C_00000000 );/* side right */ - } - - ctl = &controls[nctl +0 ]; ctl->id.iface = (__force int )SNDRV_CTL_ELEM_IFACE_MIXER ;strcpy (ctl->id.name,"Tone Control - Bass" );
@@ -1515,12 +1503,19 @@ A_OP(icode, &ptr, iMAC0, A_GPR(var), A_GPR(var), A_GPR(vol), A_EXTIN(input)) controls[nctl +1 ].gpr[z *2 + j] =TREBLE_GPR + z *2 + j; } } + nctl +=2 ; + +A_OP (icode, &ptr, iACC3,A_C_00000000 ,A_GPR (gpr),A_C_00000000 ,A_C_00000000 ); +snd_emu10k1_init_mono_onoff_control (controls + nctl++,"Tone Control - Switch" , gpr,0 ); + gpr++; +A_OP (icode, &ptr, iSKIP,A_GPR_COND ,A_GPR_COND ,A_CC_REG_ZERO ,A_GPR (gpr)); + ptr_skip = ptr;for (z =0 ; z <4 ; z++) {/* front/rear/center-lfe/side */ int j, k, l, d;for (j =0 ; j <2 ; j++) {/* left/right */ k =0xb0 + (z *8 ) + (j *4 ); l =0xe0 + (z *8 ) + (j *4 ); - d = playback +SND_EMU10K1_PLAYBACK_CHANNELS + z *2 + j; + d = playback + z *2 + j;A_OP (icode, &ptr, iMAC0,A_C_00000000 ,A_C_00000000 ,A_GPR (d),A_GPR (BASS_GPR +0 + j));A_OP (icode, &ptr, iMACMV,A_GPR (k+1 ),A_GPR (k),A_GPR (k+1 ),A_GPR (BASS_GPR +4 + j));
@@ -1542,47 +1537,38 @@ A_OP(icode, &ptr, iMAC0, A_GPR(var), A_GPR(var), A_GPR(vol), A_EXTIN(input))break ; } } - nctl +=2 ; + gpr_map[gpr++] = ptr - ptr_skip;#undef BASS_GPR#undef TREBLE_GPR -for (z =0 ; z <8 ; z++) { -A_SWITCH (icode, &ptr, tmp +0 , playback +SND_EMU10K1_PLAYBACK_CHANNELS + z, gpr); -A_SWITCH_NEG (icode, &ptr, tmp +1 , gpr); -A_SWITCH (icode, &ptr, tmp +1 , playback + z, tmp +1 ); -A_OP (icode, &ptr, iACC3,A_GPR (playback +SND_EMU10K1_PLAYBACK_CHANNELS + z),A_GPR (tmp +0 ),A_GPR (tmp +1 ),A_C_00000000 ); - } -snd_emu10k1_init_mono_onoff_control (controls + nctl++,"Tone Control - Switch" , gpr,0 ); - gpr++; -/* Master volume (will be renamed later) */ for (z =0 ; z <8 ; z++) -A_OP (icode, &ptr, iMAC0,A_GPR (playback+z+SND_EMU10K1_PLAYBACK_CHANNELS ),A_C_00000000 ,A_GPR (gpr),A_GPR (playback+z+SND_EMU10K1_PLAYBACK_CHANNELS )); +A_OP (icode, &ptr, iMAC0,A_GPR (playback+z),A_C_00000000 ,A_GPR (gpr),A_GPR (playback+z));snd_emu10k1_init_mono_control (&controls[nctl++],"Wave Master Playback Volume" , gpr,0 ); gpr +=2 ;/* analog speakers */ -A_PUT_STEREO_OUTPUT (A_EXTOUT_AFRONT_L ,A_EXTOUT_AFRONT_R , playback +SND_EMU10K1_PLAYBACK_CHANNELS ); -A_PUT_STEREO_OUTPUT (A_EXTOUT_AREAR_L ,A_EXTOUT_AREAR_R , playback+2 +SND_EMU10K1_PLAYBACK_CHANNELS ); -A_PUT_OUTPUT (A_EXTOUT_ACENTER , playback+4 +SND_EMU10K1_PLAYBACK_CHANNELS ); -A_PUT_OUTPUT (A_EXTOUT_ALFE , playback+5 +SND_EMU10K1_PLAYBACK_CHANNELS ); +A_PUT_STEREO_OUTPUT (A_EXTOUT_AFRONT_L ,A_EXTOUT_AFRONT_R , playback); +A_PUT_STEREO_OUTPUT (A_EXTOUT_AREAR_L ,A_EXTOUT_AREAR_R , playback+2 ); +A_PUT_OUTPUT (A_EXTOUT_ACENTER , playback+4 ); +A_PUT_OUTPUT (A_EXTOUT_ALFE , playback+5 );if (emu->card_capabilities->spk71) -A_PUT_STEREO_OUTPUT (A_EXTOUT_ASIDE_L ,A_EXTOUT_ASIDE_R , playback+6 +SND_EMU10K1_PLAYBACK_CHANNELS ); +A_PUT_STEREO_OUTPUT (A_EXTOUT_ASIDE_L ,A_EXTOUT_ASIDE_R , playback+6 );/* headphone */ -A_PUT_STEREO_OUTPUT (A_EXTOUT_HEADPHONE_L ,A_EXTOUT_HEADPHONE_R , playback +SND_EMU10K1_PLAYBACK_CHANNELS ); +A_PUT_STEREO_OUTPUT (A_EXTOUT_HEADPHONE_L ,A_EXTOUT_HEADPHONE_R , playback);/* digital outputs */ /* A_PUT_STEREO_OUTPUT(A_EXTOUT_FRONT_L, A_EXTOUT_FRONT_R, playback + SND_EMU10K1_PLAYBACK_CHANNELS); */ if (emu->card_capabilities->emu_model) {/* EMU1010 Outputs from PCM Front, Rear, Center, LFE, Side */ dev_info (emu->card->dev,"EMU outputs on\n" );for (z =0 ; z <8 ; z++) {if (emu->card_capabilities->ca0108_chip) { -A_OP (icode, &ptr, iACC3,A3_EMU32OUT (z),A_GPR (playback +SND_EMU10K1_PLAYBACK_CHANNELS + z),A_C_00000000 ,A_C_00000000 ); +A_OP (icode, &ptr, iACC3,A3_EMU32OUT (z),A_GPR (playback + z),A_C_00000000 ,A_C_00000000 ); }else { -A_OP (icode, &ptr, iACC3,A_EMU32OUTL (z),A_GPR (playback +SND_EMU10K1_PLAYBACK_CHANNELS + z),A_C_00000000 ,A_C_00000000 ); +A_OP (icode, &ptr, iACC3,A_EMU32OUTL (z),A_GPR (playback + z),A_C_00000000 ,A_C_00000000 ); } } }
@@ -1598,7 +1584,7 @@ A_OP(icode, &ptr, iMAC0, A_GPR(var), A_GPR(var), A_GPR(vol), A_EXTIN(input))A_OP (icode, &ptr, iANDXOR,A_GPR (tmp +2 ),A_GPR (tmp +2 ),A_GPR (gpr -1 ),A_C_00000000 );A_SWITCH (icode, &ptr, tmp +0 , tmp +2 , gpr + z);A_SWITCH_NEG (icode, &ptr, tmp +1 , gpr + z); -A_SWITCH (icode, &ptr, tmp +1 , playback +SND_EMU10K1_PLAYBACK_CHANNELS + z, tmp +1 ); +A_SWITCH (icode, &ptr, tmp +1 , playback + z, tmp +1 );if ((z==1 ) && (emu->card_capabilities->spdif_bug)) {/* Due to a SPDIF output bug on some Audigy cards, this code delays the Right channel by 1 sample */ dev_info(emu->card->dev,
@@ -1613,13 +1599,13 @@ A_OP(icode, &ptr, iMAC0, A_GPR(var), A_GPR(var), A_GPR(vol), A_EXTIN(input))snd_emu10k1_init_stereo_onoff_control (controls + nctl++,SNDRV_CTL_NAME_IEC958 ("Optical Raw " ,PLAYBACK ,SWITCH ), gpr,0 ); gpr +=2 ; -A_PUT_STEREO_OUTPUT (A_EXTOUT_REAR_L ,A_EXTOUT_REAR_R , playback+2 +SND_EMU10K1_PLAYBACK_CHANNELS ); -A_PUT_OUTPUT (A_EXTOUT_CENTER , playback+4 +SND_EMU10K1_PLAYBACK_CHANNELS ); -A_PUT_OUTPUT (A_EXTOUT_LFE , playback+5 +SND_EMU10K1_PLAYBACK_CHANNELS ); +A_PUT_STEREO_OUTPUT (A_EXTOUT_REAR_L ,A_EXTOUT_REAR_R , playback+2 ); +A_PUT_OUTPUT (A_EXTOUT_CENTER , playback+4 ); +A_PUT_OUTPUT (A_EXTOUT_LFE , playback+5 );/* ADC buffer */ #ifdef EMU10K1_CAPTURE_DIGITAL_OUT -A_PUT_STEREO_OUTPUT (A_EXTOUT_ADC_CAP_L ,A_EXTOUT_ADC_CAP_R , playback +SND_EMU10K1_PLAYBACK_CHANNELS ); +A_PUT_STEREO_OUTPUT (A_EXTOUT_ADC_CAP_L ,A_EXTOUT_ADC_CAP_R , playback);#else A_PUT_OUTPUT (A_EXTOUT_ADC_CAP_L , capture);A_PUT_OUTPUT (A_EXTOUT_ADC_CAP_R , capture+1 );
@@ -1762,7 +1748,7 @@ static void _volume_out(struct snd_emu10k1_fx8010_code *icode, u32 *ptr, u32 dststatic int _snd_emu10k1_init_efx (struct snd_emu10k1 *emu) {int err, i, z, gpr, tmp, playback, capture; -u32 ptr; +u32 ptr, ptr_skip;struct snd_emu10k1_fx8010_code *icode;struct snd_emu10k1_fx8010_pcm_rec *ipcm =NULL ;struct snd_emu10k1_fx8010_control_gpr *controls =NULL , *ctl;
@@ -1805,7 +1791,7 @@ static int _snd_emu10k1_init_efx(struct snd_emu10k1 *emu)/* we have 12 inputs */ playback =SND_EMU10K1_INPUTS ;/* we have 6 playback channels and tone control doubles */ - capture = playback + (SND_EMU10K1_PLAYBACK_CHANNELS *2 ); + capture = playback +SND_EMU10K1_PLAYBACK_CHANNELS ; gpr = capture +SND_EMU10K1_CAPTURE_CHANNELS ; tmp =0x88 ;/* we need 4 temporary GPR */ /* from 0x8c to 0xff is the area for tone control */
@@ -2109,13 +2095,6 @@ static int _snd_emu10k1_init_efx(struct snd_emu10k1 *emu)/* * Process tone control */ -OP (icode, &ptr, iACC3,GPR (playback +SND_EMU10K1_PLAYBACK_CHANNELS +0 ),GPR (playback +0 ),C_00000000 ,C_00000000 );/* left */ -OP (icode, &ptr, iACC3,GPR (playback +SND_EMU10K1_PLAYBACK_CHANNELS +1 ),GPR (playback +1 ),C_00000000 ,C_00000000 );/* right */ -OP (icode, &ptr, iACC3,GPR (playback +SND_EMU10K1_PLAYBACK_CHANNELS +2 ),GPR (playback +2 ),C_00000000 ,C_00000000 );/* rear left */ -OP (icode, &ptr, iACC3,GPR (playback +SND_EMU10K1_PLAYBACK_CHANNELS +3 ),GPR (playback +3 ),C_00000000 ,C_00000000 );/* rear right */ -OP (icode, &ptr, iACC3,GPR (playback +SND_EMU10K1_PLAYBACK_CHANNELS +4 ),GPR (playback +4 ),C_00000000 ,C_00000000 );/* center */ -OP (icode, &ptr, iACC3,GPR (playback +SND_EMU10K1_PLAYBACK_CHANNELS +5 ),GPR (playback +5 ),C_00000000 ,C_00000000 );/* LFE */ - ctl = &controls[i +0 ]; ctl->id.iface = (__force int )SNDRV_CTL_ELEM_IFACE_MIXER ;strcpy (ctl->id.name,"Tone Control - Bass" );
@@ -2147,12 +2126,19 @@ static int _snd_emu10k1_init_efx(struct snd_emu10k1 *emu) controls[i +1 ].gpr[z *2 + j] =TREBLE_GPR + z *2 + j; } } + i +=2 ; + +OP (icode, &ptr, iACC3,C_00000000 ,GPR (gpr),C_00000000 ,C_00000000 ); +snd_emu10k1_init_mono_onoff_control (controls + i++,"Tone Control - Switch" , gpr,0 ); + gpr++; +OP (icode, &ptr, iSKIP,GPR_COND ,GPR_COND ,CC_REG_ZERO ,GPR (gpr)); + ptr_skip = ptr;for (z =0 ; z <3 ; z++) {/* front/rear/center-lfe */ int j, k, l, d;for (j =0 ; j <2 ; j++) {/* left/right */ k =0xa0 + (z *8 ) + (j *4 ); l =0xd0 + (z *8 ) + (j *4 ); - d = playback +SND_EMU10K1_PLAYBACK_CHANNELS + z *2 + j; + d = playback + z *2 + j;OP (icode, &ptr, iMAC0,C_00000000 ,C_00000000 ,GPR (d),GPR (BASS_GPR +0 + j));OP (icode, &ptr, iMACMV,GPR (k+1 ),GPR (k),GPR (k+1 ),GPR (BASS_GPR +4 + j));
@@ -2174,37 +2160,28 @@ static int _snd_emu10k1_init_efx(struct snd_emu10k1 *emu)break ; } } - i +=2 ; + gpr_map[gpr++] = ptr - ptr_skip;#undef BASS_GPR#undef TREBLE_GPR -for (z =0 ; z <6 ; z++) { -SWITCH (icode, &ptr, tmp +0 , playback +SND_EMU10K1_PLAYBACK_CHANNELS + z, gpr); -SWITCH_NEG (icode, &ptr, tmp +1 , gpr); -SWITCH (icode, &ptr, tmp +1 , playback + z, tmp +1 ); -OP (icode, &ptr, iACC3,GPR (playback +SND_EMU10K1_PLAYBACK_CHANNELS + z),GPR (tmp +0 ),GPR (tmp +1 ),C_00000000 ); - } -snd_emu10k1_init_mono_onoff_control (controls + i++,"Tone Control - Switch" , gpr,0 ); - gpr++; -/* * Process outputs */ if (emu->fx8010.extout_mask & ((1 <<EXTOUT_AC97_L )|(1 <<EXTOUT_AC97_R ))) {/* AC'97 Playback Volume */ for (z =0 ; z <2 ; z++) -OP (icode, &ptr, iACC3,EXTOUT (EXTOUT_AC97_L + z),GPR (playback +SND_EMU10K1_PLAYBACK_CHANNELS + z),C_00000000 ,C_00000000 ); +OP (icode, &ptr, iACC3,EXTOUT (EXTOUT_AC97_L + z),GPR (playback + z),C_00000000 ,C_00000000 ); }if (emu->fx8010.extout_mask & ((1 <<EXTOUT_TOSLINK_L )|(1 <<EXTOUT_TOSLINK_R ))) {/* IEC958 Optical Raw Playback Switch */ for (z =0 ; z <2 ; z++) {SWITCH (icode, &ptr, tmp +0 ,8 + z, gpr + z);SWITCH_NEG (icode, &ptr, tmp +1 , gpr + z); -SWITCH (icode, &ptr, tmp +1 , playback +SND_EMU10K1_PLAYBACK_CHANNELS + z, tmp +1 ); +SWITCH (icode, &ptr, tmp +1 , playback + z, tmp +1 );OP (icode, &ptr, iACC3,EXTOUT (EXTOUT_TOSLINK_L + z),GPR (tmp +0 ),GPR (tmp +1 ),C_00000000 );#ifdef EMU10K1_CAPTURE_DIGITAL_OUT OP (icode, &ptr, iACC3,EXTOUT (EXTOUT_ADC_CAP_L + z),GPR (tmp +0 ),GPR (tmp +1 ),C_00000000 );
@@ -2219,9 +2196,9 @@ static int _snd_emu10k1_init_efx(struct snd_emu10k1 *emu)/* Headphone Playback Volume */ for (z =0 ; z <2 ; z++) { -SWITCH (icode, &ptr, tmp +0 , playback +SND_EMU10K1_PLAYBACK_CHANNELS +4 + z, gpr +2 + z); +SWITCH (icode, &ptr, tmp +0 , playback +4 + z, gpr +2 + z);SWITCH_NEG (icode, &ptr, tmp +1 , gpr +2 + z); -SWITCH (icode, &ptr, tmp +1 , playback +SND_EMU10K1_PLAYBACK_CHANNELS + z, tmp +1 ); +SWITCH (icode, &ptr, tmp +1 , playback + z, tmp +1 );OP (icode, &ptr, iACC3,GPR (tmp +0 ),GPR (tmp +0 ),GPR (tmp +1 ),C_00000000 );VOLUME_OUT (icode, &ptr,EXTOUT_HEADPHONE_L + z, tmp +0 , gpr + z); }
@@ -2238,29 +2215,29 @@ static int _snd_emu10k1_init_efx(struct snd_emu10k1 *emu)if (emu->fx8010.extout_mask & ((1 <<EXTOUT_REAR_L )|(1 <<EXTOUT_REAR_R )))for (z =0 ; z <2 ; z++) -OP (icode, &ptr, iACC3,EXTOUT (EXTOUT_REAR_L + z),GPR (playback +SND_EMU10K1_PLAYBACK_CHANNELS +2 + z),C_00000000 ,C_00000000 ); +OP (icode, &ptr, iACC3,EXTOUT (EXTOUT_REAR_L + z),GPR (playback +2 + z),C_00000000 ,C_00000000 );if (emu->fx8010.extout_mask & ((1 <<EXTOUT_AC97_REAR_L )|(1 <<EXTOUT_AC97_REAR_R )))for (z =0 ; z <2 ; z++) -OP (icode, &ptr, iACC3,EXTOUT (EXTOUT_AC97_REAR_L + z),GPR (playback +SND_EMU10K1_PLAYBACK_CHANNELS +2 + z),C_00000000 ,C_00000000 ); +OP (icode, &ptr, iACC3,EXTOUT (EXTOUT_AC97_REAR_L + z),GPR (playback +2 + z),C_00000000 ,C_00000000 );if (emu->fx8010.extout_mask & (1 <<EXTOUT_AC97_CENTER )) {#ifndef EMU10K1_CENTER_LFE_FROM_FRONT -OP (icode, &ptr, iACC3,EXTOUT (EXTOUT_AC97_CENTER ),GPR (playback +SND_EMU10K1_PLAYBACK_CHANNELS +4 ),C_00000000 ,C_00000000 ); -OP (icode, &ptr, iACC3,EXTOUT (EXTOUT_ACENTER ),GPR (playback +SND_EMU10K1_PLAYBACK_CHANNELS +4 ),C_00000000 ,C_00000000 ); +OP (icode, &ptr, iACC3,EXTOUT (EXTOUT_AC97_CENTER ),GPR (playback +4 ),C_00000000 ,C_00000000 ); +OP (icode, &ptr, iACC3,EXTOUT (EXTOUT_ACENTER ),GPR (playback +4 ),C_00000000 ,C_00000000 );#else -OP (icode, &ptr, iACC3,EXTOUT (EXTOUT_AC97_CENTER ),GPR (playback +SND_EMU10K1_PLAYBACK_CHANNELS +0 ),C_00000000 ,C_00000000 ); -OP (icode, &ptr, iACC3,EXTOUT (EXTOUT_ACENTER ),GPR (playback +SND_EMU10K1_PLAYBACK_CHANNELS +0 ),C_00000000 ,C_00000000 ); +OP (icode, &ptr, iACC3,EXTOUT (EXTOUT_AC97_CENTER ),GPR (playback +0 ),C_00000000 ,C_00000000 ); +OP (icode, &ptr, iACC3,EXTOUT (EXTOUT_ACENTER ),GPR (playback +0 ),C_00000000 ,C_00000000 );#endif }if (emu->fx8010.extout_mask & (1 <<EXTOUT_AC97_LFE )) {#ifndef EMU10K1_CENTER_LFE_FROM_FRONT -OP (icode, &ptr, iACC3,EXTOUT (EXTOUT_AC97_LFE ),GPR (playback +SND_EMU10K1_PLAYBACK_CHANNELS +5 ),C_00000000 ,C_00000000 ); -OP (icode, &ptr, iACC3,EXTOUT (EXTOUT_ALFE ),GPR (playback +SND_EMU10K1_PLAYBACK_CHANNELS +5 ),C_00000000 ,C_00000000 ); +OP (icode, &ptr, iACC3,EXTOUT (EXTOUT_AC97_LFE ),GPR (playback +5 ),C_00000000 ,C_00000000 ); +OP (icode, &ptr, iACC3,EXTOUT (EXTOUT_ALFE ),GPR (playback +5 ),C_00000000 ,C_00000000 );#else -OP (icode, &ptr, iACC3,EXTOUT (EXTOUT_AC97_LFE ),GPR (playback +SND_EMU10K1_PLAYBACK_CHANNELS +1 ),C_00000000 ,C_00000000 ); -OP (icode, &ptr, iACC3,EXTOUT (EXTOUT_ALFE ),GPR (playback +SND_EMU10K1_PLAYBACK_CHANNELS +1 ),C_00000000 ,C_00000000 ); +OP (icode, &ptr, iACC3,EXTOUT (EXTOUT_AC97_LFE ),GPR (playback +1 ),C_00000000 ,C_00000000 ); +OP (icode, &ptr, iACC3,EXTOUT (EXTOUT_ALFE ),GPR (playback +1 ),C_00000000 ,C_00000000 );#endif }
Signature · 1 line
2.40.0.152.g15d061e6df
PATCH 7/14 ALSA: emu10k1: properly assert DSP init constraints
In reply to Oswald BuddenhagenIf these are hit, we've already trashed kernel memory by writing past the end of the allocated buffer. There is no recovery from that.
---
v2:
- slightly more verbose description
--- sound/pci/emu10k1/emufx.c | 21 +++++---------------- 1 file changed, 5 insertions(+), 16 deletions(-)
sound/pci/emu10k1/emufx.c +5 -16
@@ -1668,22 +1668,19 @@ A_OP(icode, &ptr, iMAC0, A_GPR(var), A_GPR(var), A_GPR(vol), A_EXTIN(input))* ok, set up done.. */ -if (gpr > tmp) { -snd_BUG (); - err = -EIO ; - goto __err; - } +BUG_ON (gpr > tmp); +BUG_ON (nctl >SND_EMU10K1_GPR_CONTROLS ); +/* clear remaining instruction memory */ while (ptr <0x400 )A_OP (icode, &ptr,0x0f ,0xc0 ,0xc0 ,0xcf ,0xc0 ); icode->gpr_add_control_count = nctl; icode->gpr_add_controls = controls; emu->support_tlv =1 ;/* support TLV */ err =snd_emu10k1_icode_poke (emu, icode, true); emu->support_tlv =0 ;/* clear again */ -__err:kfree (controls); __err_ctrls:kfree (icode->gpr_map);
@@ -2272,16 +2269,8 @@ static int _snd_emu10k1_init_efx(struct snd_emu10k1 *emu) } -if (gpr > tmp) { -snd_BUG (); - err = -EIO ; - goto __err; - } -if (i >SND_EMU10K1_GPR_CONTROLS ) { -snd_BUG (); - err = -EIO ; - goto __err; - } +BUG_ON (gpr > tmp); +BUG_ON (i >SND_EMU10K1_GPR_CONTROLS );/* clear remaining instruction memory */ while (ptr <0x200 )
Signature · 1 line
2.40.0.152.g15d061e6df
Re: [PATCH 07/14] ALSA: emu10k1: properly assert DSP init constraints
Quoted 8 lines · Oswald Buddenhagen
If these are hit, we've already trashed kernel memory by writing past the end of the allocated buffer. There is no recovery from that.
Signed-off-by Oswald Buddenhagen <[email protected]>---
v2:
- slightly more verbose description
Again, this is NAK. First of all, if we really do care the overflow seriously, we should check at each increment instead of after breakage. It shouldn't be too difficult at all.
Second, using BUG_ON() like this case is an overkill. It was clearly stated by Linus in the past a few times (although I can't find the source right now).
thanks,
Takashi
Quoted 56 lines
--- sound/pci/emu10k1/emufx.c | 21 +++++---------------- 1 file changed, 5 insertions(+), 16 deletions(-)sound/pci/emu10k1/emufx.c +5
-16@@ -1668,22 +1668,19 @@ A_OP(icode, &ptr, iMAC0, A_GPR(var), A_GPR(var), A_GPR(vol), A_EXTIN(input))* ok, set up done.. */ -if (gpr > tmp) { -snd_BUG (); - err = -EIO ; - goto __err; - } +BUG_ON (gpr > tmp); +BUG_ON (nctl >SND_EMU10K1_GPR_CONTROLS ); +/* clear remaining instruction memory */ while (ptr <0x400 )A_OP (icode, &ptr,0x0f ,0xc0 ,0xc0 ,0xcf ,0xc0 ); icode->gpr_add_control_count = nctl; icode->gpr_add_controls = controls; emu->support_tlv =1 ;/* support TLV */ err =snd_emu10k1_icode_poke (emu, icode, true); emu->support_tlv =0 ;/* clear again */ -__err:kfree (controls); __err_ctrls:kfree (icode->gpr_map);@@ -2272,16 +2269,8 @@ static int _snd_emu10k1_init_efx(struct snd_emu10k1 *emu) } -if (gpr > tmp) { -snd_BUG (); - err = -EIO ; - goto __err; - } -if (i >SND_EMU10K1_GPR_CONTROLS ) { -snd_BUG (); - err = -EIO ; - goto __err; - } +BUG_ON (gpr > tmp); +BUG_ON (i >SND_EMU10K1_GPR_CONTROLS );/* clear remaining instruction memory */ while (ptr <0x200 )Signature · 1 line
2.40.0.152.g15d061e6df
Re: [PATCH 07/14] ALSA: emu10k1: properly assert DSP init constraints
Quoted 12 lines · Takashi Iwai
Quoted 4 lines · Oswald Buddenhagen
If these are hit, we've already trashed kernel memory by writing past the end of the allocated buffer. There is no recovery from that.
Again, this is NAK.
First of all, if we really do care the overflow seriously, we should check at each increment instead of after breakage. It shouldn't be too difficult at all.
not difficult, but pointless bloat.
Quoted 4 lines
Second, using
BUG_ON()like this case is an overkill. It was clearly stated by Linus in the past a few times (although I can't find the source right now).
you seem to have an irrational aversion against assertions, maybe because linus likes to scream at people.
relevant comments from linus were easy enough to find:
https://yarchive.net/comp/linux/BUG.html
https://lore.kernel.org/all/CA+55aFwyNTLuZgOWMTRuabWobF27ygskuxvFd-P0n-3UNT=0Og@mail.gmail.com/T/#u
and there is also the documentation on BUG() itself.
i don't see anything in either of these that would imply that my use of BUG_ON() is inappropriate. it catches a serious programming error, is easy to prove correct (the scope is a single function), and the only immediate effect is that it will crash the insmod process (though i would expect possible followup effects due to the kernel memory corruption, which is exactly why the assert is there). i have a hard time thinking of a *more* appropriate use for BUG().
regards
Re: [PATCH 07/14] ALSA: emu10k1: properly assert DSP init constraints
Quoted 14 lines · Oswald Buddenhagen
Quoted 12 lines · Takashi Iwai
Quoted 4 lines · Oswald Buddenhagen
If these are hit, we've already trashed kernel memory by writing past the end of the allocated buffer. There is no recovery from that.
Again, this is NAK.
First of all, if we really do care the overflow seriously, we should check at each increment instead of after breakage. It shouldn't be too difficult at all.
Quoted 8 lines
not difficult, but pointless bloat.
Quoted 4 lines
Second, using
BUG_ON()like this case is an overkill. It was clearly stated by Linus in the past a few times (although I can't find the source right now).you seem to have an irrational aversion against assertions, maybe because linus likes to scream at people.
Not because he's screaming but, it's because his opinion is correct regarding this.
Quoted 6 lines
relevant comments from linus were easy enough to find:
https://yarchive.net/comp/linux/BUG.html
https://lore.kernel.org/all/CA+55aFwyNTLuZgOWMTRuabWobF27ygskuxvFd-P0n-3UNT=0Og@mail.gmail.com/T/#uand there is also the documentation on
BUG()itself.
Quoted 7 lines
i don't see anything in either of these that would imply that my use of
BUG_ON()is inappropriate. it catches a serious programming error, is easy to prove correct (the scope is a single function), and the only immediate effect is that it will crash the insmod process (though i would expect possible followup effects due to the kernel memory corruption, which is exactly why the assert is there). i have a hard time thinking of a *more* appropriate use forBUG().
I can't agree here at all. Sorry, but this is still NAK.
The reason why BUG_ON() is bad is that it cannot allow debugging easily. It crashes and locks up, and you may not see what's going on.
Do you want to catch and fix the bug? Then put the check at more proper pint that prevents the real corruption. the check is basically already too late -- it means that you might have already broken someone else's system. If the size matters, it can be a conditional build with CONFIG_SND_DEBUG, for example. But simply replacing and putting BUG_ON() makes little sense.
Of course, it's just my opinion, but I won't change my mind about it. So I'm not going to discuss about this further and waste time.
thanks,
Takashi
PATCH 8/14 ALSA: emu10k1: polish audigy GPR allocation
In reply to Oswald Buddenhagen- Pull ahead all fixed allocations, so we don't rely on the semi- dynamic ones not crossing the arbitrarily determined limit
- Use an enum for the fixed allocations
- Stop arbitrarily wasting registers on unexplained "reservations"
- Don't reserve two regs for the master volume control - it's mono
--- sound/pci/emu10k1/emufx.c | 68 +++++++++++++++++++++------------------ 1 file changed, 36 insertions(+), 32 deletions(-)
sound/pci/emu10k1/emufx.c +36 -32
@@ -1202,18 +1202,31 @@ static void snd_emu10k1_audigy_dsp_convert_32_to_2x16(A_OP (icode, ptr, iMAC3, reg_out,A_GPR (tmp),A_GPR (tmp),A_C_80000000 ); } +#define ENUM_GPR (name, size) name, name ## _dummy = name + (size) - 1 +/* * initial DSP configuration for Audigy */ static int _snd_emu10k1_audigy_init_efx (struct snd_emu10k1 *emu) { -int err, z, gpr, nctl; -int bit_shifter16; -const int playback =10 ; -const int capture = playback +SND_EMU10K1_PLAYBACK_CHANNELS ;/* we reserve 10 voices */ -const int stereo_mix = capture +2 ; -const int tmp =0x88 ; +int err, z, nctl; +enum { + ENUM_GPR(playback, SND_EMU10K1_PLAYBACK_CHANNELS), + ENUM_GPR(stereo_mix, 2), + ENUM_GPR(capture, 2), + ENUM_GPR(bit_shifter16, 1), +// The fixed allocation of these breaks the pattern, but why not. +// Splitting these into left/right is questionable, as it will break +// down for center/lfe. But it works for stereo/quadro, so whatever. + ENUM_GPR(bass_gpr, 2 * 5), // two sides, five coefficients + ENUM_GPR(treble_gpr, 2 * 5), + ENUM_GPR(bass_tmp, SND_EMU10K1_PLAYBACK_CHANNELS * 4), // four delay stages + ENUM_GPR(treble_tmp, SND_EMU10K1_PLAYBACK_CHANNELS * 4), + ENUM_GPR(tmp, 3), + num_static_gprs + }; +int gpr = num_static_gprs;u32 ptr, ptr_skip;struct snd_emu10k1_fx8010_code *icode =NULL ;struct snd_emu10k1_fx8010_control_gpr *controls =NULL , *ctl;
@@ -1248,9 +1261,7 @@ static int _snd_emu10k1_audigy_init_efx(struct snd_emu10k1 *emu)strcpy (icode->name,"Audigy DSP code for ALSA" ); ptr =0 ; nctl =0 ; - gpr = stereo_mix +10 ; - bit_shifter16 = gpr; - gpr_map[gpr++] =0x00008000 ; + gpr_map[bit_shifter16] =0x00008000 ;#if 1 /* PCM front Playback Volume (independent from stereo mix)
@@ -1492,15 +1503,11 @@ A_OP(icode, &ptr, iMAC0, A_GPR(var), A_GPR(var), A_GPR(vol), A_EXTIN(input)) ctl->max =40 ; ctl->value[0 ] = ctl->value[1 ] =20 ; ctl->translation =EMU10K1_GPR_TRANSLATION_TREBLE ; - -#define BASS_GPR 0x8c -#define TREBLE_GPR 0x96 -for (z =0 ; z <5 ; z++) {int j;for (j =0 ; j <2 ; j++) { - controls[nctl +0 ].gpr[z *2 + j] =BASS_GPR + z *2 + j; - controls[nctl +1 ].gpr[z *2 + j] =TREBLE_GPR + z *2 + j; + controls[nctl +0 ].gpr[z *2 + j] = bass_gpr + z *2 + j; + controls[nctl +1 ].gpr[z *2 + j] = treble_gpr + z *2 + j; } } nctl +=2 ;
@@ -1513,40 +1520,37 @@ A_OP(icode, &ptr, iMAC0, A_GPR(var), A_GPR(var), A_GPR(vol), A_EXTIN(input))for (z =0 ; z <4 ; z++) {/* front/rear/center-lfe/side */ int j, k, l, d;for (j =0 ; j <2 ; j++) {/* left/right */ - k =0xb0 + (z *8 ) + (j *4 ); - l =0xe0 + (z *8 ) + (j *4 ); + k = bass_tmp + (z *8 ) + (j *4 ); + l = treble_tmp + (z *8 ) + (j *4 ); d = playback + z *2 + j; -A_OP (icode, &ptr, iMAC0,A_C_00000000 ,A_C_00000000 ,A_GPR (d),A_GPR (BASS_GPR +0 + j)); -A_OP (icode, &ptr, iMACMV,A_GPR (k+1 ),A_GPR (k),A_GPR (k+1 ),A_GPR (BASS_GPR +4 + j)); -A_OP (icode, &ptr, iMACMV,A_GPR (k),A_GPR (d),A_GPR (k),A_GPR (BASS_GPR +2 + j)); -A_OP (icode, &ptr, iMACMV,A_GPR (k+3 ),A_GPR (k+2 ),A_GPR (k+3 ),A_GPR (BASS_GPR +8 + j)); -A_OP (icode, &ptr, iMAC0,A_GPR (k+2 ),A_GPR_ACCU ,A_GPR (k+2 ),A_GPR (BASS_GPR +6 + j)); +A_OP (icode, &ptr, iMAC0,A_C_00000000 ,A_C_00000000 ,A_GPR (d),A_GPR (bass_gpr +0 + j)); +A_OP (icode, &ptr, iMACMV,A_GPR (k+1 ),A_GPR (k),A_GPR (k+1 ),A_GPR (bass_gpr +4 + j)); +A_OP (icode, &ptr, iMACMV,A_GPR (k),A_GPR (d),A_GPR (k),A_GPR (bass_gpr +2 + j)); +A_OP (icode, &ptr, iMACMV,A_GPR (k+3 ),A_GPR (k+2 ),A_GPR (k+3 ),A_GPR (bass_gpr +8 + j)); +A_OP (icode, &ptr, iMAC0,A_GPR (k+2 ),A_GPR_ACCU ,A_GPR (k+2 ),A_GPR (bass_gpr +6 + j));A_OP (icode, &ptr, iACC3,A_GPR (k+2 ),A_GPR (k+2 ),A_GPR (k+2 ),A_C_00000000 ); -A_OP (icode, &ptr, iMAC0,A_C_00000000 ,A_C_00000000 ,A_GPR (k+2 ),A_GPR (TREBLE_GPR +0 + j)); -A_OP (icode, &ptr, iMACMV,A_GPR (l+1 ),A_GPR (l),A_GPR (l+1 ),A_GPR (TREBLE_GPR +4 + j)); -A_OP (icode, &ptr, iMACMV,A_GPR (l),A_GPR (k+2 ),A_GPR (l),A_GPR (TREBLE_GPR +2 + j)); -A_OP (icode, &ptr, iMACMV,A_GPR (l+3 ),A_GPR (l+2 ),A_GPR (l+3 ),A_GPR (TREBLE_GPR +8 + j)); -A_OP (icode, &ptr, iMAC0,A_GPR (l+2 ),A_GPR_ACCU ,A_GPR (l+2 ),A_GPR (TREBLE_GPR +6 + j)); +A_OP (icode, &ptr, iMAC0,A_C_00000000 ,A_C_00000000 ,A_GPR (k+2 ),A_GPR (treble_gpr +0 + j)); +A_OP (icode, &ptr, iMACMV,A_GPR (l+1 ),A_GPR (l),A_GPR (l+1 ),A_GPR (treble_gpr +4 + j)); +A_OP (icode, &ptr, iMACMV,A_GPR (l),A_GPR (k+2 ),A_GPR (l),A_GPR (treble_gpr +2 + j)); +A_OP (icode, &ptr, iMACMV,A_GPR (l+3 ),A_GPR (l+2 ),A_GPR (l+3 ),A_GPR (treble_gpr +8 + j)); +A_OP (icode, &ptr, iMAC0,A_GPR (l+2 ),A_GPR_ACCU ,A_GPR (l+2 ),A_GPR (treble_gpr +6 + j));A_OP (icode, &ptr, iMACINT0,A_GPR (l+2 ),A_C_00000000 ,A_GPR (l+2 ),A_C_00000010 );A_OP (icode, &ptr, iACC3,A_GPR (d),A_GPR (l+2 ),A_C_00000000 ,A_C_00000000 );if (z ==2 )/* center */ break ; } } gpr_map[gpr++] = ptr - ptr_skip; -#undef BASS_GPR -#undef TREBLE_GPR -/* Master volume (will be renamed later) */ for (z =0 ; z <8 ; z++)A_OP (icode, &ptr, iMAC0,A_GPR (playback+z),A_C_00000000 ,A_GPR (gpr),A_GPR (playback+z));snd_emu10k1_init_mono_control (&controls[nctl++],"Wave Master Playback Volume" , gpr,0 ); - gpr +=2 ; + gpr++;/* analog speakers */ A_PUT_STEREO_OUTPUT (A_EXTOUT_AFRONT_L ,A_EXTOUT_AFRONT_R , playback);
@@ -1668,7 +1672,7 @@ A_OP(icode, &ptr, iMAC0, A_GPR(var), A_GPR(var), A_GPR(vol), A_EXTIN(input))* ok, set up done.. */ -BUG_ON (gpr > tmp); +BUG_ON (gpr >512 );BUG_ON (nctl >SND_EMU10K1_GPR_CONTROLS );/* clear remaining instruction memory */
Signature · 1 line
2.40.0.152.g15d061e6df
PATCH 9/14 ALSA: emu10k1: fix non-zero mixer control defaults in highres mode
In reply to Oswald BuddenhagenThe default value needs to be scaled.
--- sound/pci/emu10k1/emufx.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)
sound/pci/emu10k1/emufx.c +5 -3
@@ -1116,40 +1116,42 @@ snd_emu10k1_init_mono_control(struct snd_emu10k1_fx8010_control_gpr *ctl, ctl->id.iface = (__force int )SNDRV_CTL_ELEM_IFACE_MIXER ;strcpy (ctl->id.name, name); ctl->vcount = ctl->count =1 ; - ctl->gpr[0 ] = gpr +0 ; ctl->value[0 ] = defval;if (high_res_gpr_volume) { ctl->min =0 ; ctl->max =0x7fffffff ; ctl->tlv = snd_emu10k1_db_linear; ctl->translation =EMU10K1_GPR_TRANSLATION_NONE ; + defval = defval *0x7fffffffLL /100 ; }else { ctl->min =0 ; ctl->max =100 ; ctl->tlv = snd_emu10k1_db_scale1; ctl->translation =EMU10K1_GPR_TRANSLATION_TABLE100 ; } + ctl->gpr[0 ] = gpr +0 ; ctl->value[0 ] = defval; }static void snd_emu10k1_init_stereo_control (struct snd_emu10k1_fx8010_control_gpr *ctl,const char *name,int gpr,int defval) { ctl->id.iface = (__force int )SNDRV_CTL_ELEM_IFACE_MIXER ;strcpy (ctl->id.name, name); ctl->vcount = ctl->count =2 ; - ctl->gpr[0 ] = gpr +0 ; ctl->value[0 ] = defval; - ctl->gpr[1 ] = gpr +1 ; ctl->value[1 ] = defval;if (high_res_gpr_volume) { ctl->min =0 ; ctl->max =0x7fffffff ; ctl->tlv = snd_emu10k1_db_linear; ctl->translation =EMU10K1_GPR_TRANSLATION_NONE ; + defval = defval *0x7fffffffLL /100 ; }else { ctl->min =0 ; ctl->max =100 ; ctl->tlv = snd_emu10k1_db_scale1; ctl->translation =EMU10K1_GPR_TRANSLATION_TABLE100 ; } + ctl->gpr[0 ] = gpr +0 ; ctl->value[0 ] = defval; + ctl->gpr[1 ] = gpr +1 ; ctl->value[1 ] = defval; } static void
Signature · 1 line
2.40.0.152.g15d061e6df
PATCH 10/14 ALSA: emu10k1: validate min/max values of translated controls
In reply to Oswald BuddenhagenUser space could pass arbitrary ranges, which were uncritically accepted. This could lead to table lookups out of range.
I don't think that this is a security issue, as it only allowed someone with CAP_SYS_ADMIN to crash the kernel, but still.
Setting an invalid translation mode will also be rejected now. That did no harm, but it's still better to detect errors.
--- sound/pci/emu10k1/emufx.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+)
sound/pci/emu10k1/emufx.c +26 -0
@@ -769,6 +769,32 @@ static int snd_emu10k1_verify_controls(struct snd_emu10k1 *emu, err = -EINVAL ; goto __error; } +switch (gctl->translation) { +case EMU10K1_GPR_TRANSLATION_NONE : +break ; +case EMU10K1_GPR_TRANSLATION_TABLE100 : +if (gctl->min !=0 || gctl->max !=100 ) { + err = -EINVAL ; + goto __error; + } +break ; +case EMU10K1_GPR_TRANSLATION_BASS : +case EMU10K1_GPR_TRANSLATION_TREBLE : +if (gctl->min !=0 || gctl->max !=40 ) { + err = -EINVAL ; + goto __error; + } +break ; +case EMU10K1_GPR_TRANSLATION_ONOFF : +if (gctl->min !=0 || gctl->max !=1 ) { + err = -EINVAL ; + goto __error; + } +break ; +default : + err = -EINVAL ; + goto __error; + } }for (i =0 ; i < icode->gpr_list_control_count; i++) {/* FIXME: we need to check the WRITE access */
Signature · 1 line
2.40.0.152.g15d061e6df
PATCH 11/14 ALSA: emu10k1: omit non-applicable mixer controls for E-MU cards
In reply to Oswald BuddenhagenThe E-MU cards don't try very hard to be Sound Blasters. All sound I/O goes through the Hana FPGA, thus making the regular extin/out controls useless. Still showing them just serves to clutter up the interface and confuse the user.
--- sound/pci/emu10k1/emufx.c | 241 +++++++++++++++++++------------------- 1 file changed, 120 insertions(+), 121 deletions(-)
sound/pci/emu10k1/emufx.c +120 -121
@@ -1379,87 +1379,88 @@ A_OP(icode, &ptr, iMAC0, A_GPR(var), A_GPR(var), A_GPR(vol), A_EXTIN(input))snd_emu10k1_init_stereo_control (&controls[nctl++],"EMU Capture Volume" , gpr,0 ); gpr_map[gpr +2 ] =0x00000000 ; gpr +=3 ; + }else { +/* AC'97 Playback Volume - used only for mic (renamed later) */ +A_ADD_VOLUME_IN (stereo_mix, gpr,A_EXTIN_AC97_L ); +A_ADD_VOLUME_IN (stereo_mix+1 , gpr+1 ,A_EXTIN_AC97_R ); +snd_emu10k1_init_stereo_control (&controls[nctl++],"AMic Playback Volume" , gpr,0 ); + gpr +=2 ; +/* AC'97 Capture Volume - used only for mic */ +A_ADD_VOLUME_IN (capture, gpr,A_EXTIN_AC97_L ); +A_ADD_VOLUME_IN (capture+1 , gpr+1 ,A_EXTIN_AC97_R ); +snd_emu10k1_init_stereo_control (&controls[nctl++],"Mic Capture Volume" , gpr,0 ); + gpr +=2 ; + +/* mic capture buffer */ +A_OP (icode, &ptr, iINTERP,A_EXTOUT (A_EXTOUT_MIC_CAP ),A_EXTIN (A_EXTIN_AC97_L ),A_C_40000000 ,A_EXTIN (A_EXTIN_AC97_R )); + +/* Audigy CD Playback Volume */ +A_ADD_VOLUME_IN (stereo_mix, gpr,A_EXTIN_SPDIF_CD_L ); +A_ADD_VOLUME_IN (stereo_mix+1 , gpr+1 ,A_EXTIN_SPDIF_CD_R ); +snd_emu10k1_init_stereo_control (&controls[nctl++], + emu->card_capabilities->ac97_chip ?"Audigy CD Playback Volume" :"CD Playback Volume" , + gpr,0 ); + gpr +=2 ; +/* Audigy CD Capture Volume */ +A_ADD_VOLUME_IN (capture, gpr,A_EXTIN_SPDIF_CD_L ); +A_ADD_VOLUME_IN (capture+1 , gpr+1 ,A_EXTIN_SPDIF_CD_R ); +snd_emu10k1_init_stereo_control (&controls[nctl++], + emu->card_capabilities->ac97_chip ?"Audigy CD Capture Volume" :"CD Capture Volume" , + gpr,0 ); + gpr +=2 ; + +/* Optical SPDIF Playback Volume */ +A_ADD_VOLUME_IN (stereo_mix, gpr,A_EXTIN_OPT_SPDIF_L ); +A_ADD_VOLUME_IN (stereo_mix+1 , gpr+1 ,A_EXTIN_OPT_SPDIF_R ); +snd_emu10k1_init_stereo_control (&controls[nctl++],SNDRV_CTL_NAME_IEC958 ("Optical " ,PLAYBACK ,VOLUME ), gpr,0 ); + gpr +=2 ; +/* Optical SPDIF Capture Volume */ +A_ADD_VOLUME_IN (capture, gpr,A_EXTIN_OPT_SPDIF_L ); +A_ADD_VOLUME_IN (capture+1 , gpr+1 ,A_EXTIN_OPT_SPDIF_R ); +snd_emu10k1_init_stereo_control (&controls[nctl++],SNDRV_CTL_NAME_IEC958 ("Optical " ,CAPTURE ,VOLUME ), gpr,0 ); + gpr +=2 ; + +/* Line2 Playback Volume */ +A_ADD_VOLUME_IN (stereo_mix, gpr,A_EXTIN_LINE2_L ); +A_ADD_VOLUME_IN (stereo_mix+1 , gpr+1 ,A_EXTIN_LINE2_R ); +snd_emu10k1_init_stereo_control (&controls[nctl++], + emu->card_capabilities->ac97_chip ?"Line2 Playback Volume" :"Line Playback Volume" , + gpr,0 ); + gpr +=2 ; +/* Line2 Capture Volume */ +A_ADD_VOLUME_IN (capture, gpr,A_EXTIN_LINE2_L ); +A_ADD_VOLUME_IN (capture+1 , gpr+1 ,A_EXTIN_LINE2_R ); +snd_emu10k1_init_stereo_control (&controls[nctl++], + emu->card_capabilities->ac97_chip ?"Line2 Capture Volume" :"Line Capture Volume" , + gpr,0 ); + gpr +=2 ; + +/* Philips ADC Playback Volume */ +A_ADD_VOLUME_IN (stereo_mix, gpr,A_EXTIN_ADC_L ); +A_ADD_VOLUME_IN (stereo_mix+1 , gpr+1 ,A_EXTIN_ADC_R ); +snd_emu10k1_init_stereo_control (&controls[nctl++],"Analog Mix Playback Volume" , gpr,0 ); + gpr +=2 ; +/* Philips ADC Capture Volume */ +A_ADD_VOLUME_IN (capture, gpr,A_EXTIN_ADC_L ); +A_ADD_VOLUME_IN (capture+1 , gpr+1 ,A_EXTIN_ADC_R ); +snd_emu10k1_init_stereo_control (&controls[nctl++],"Analog Mix Capture Volume" , gpr,0 ); + gpr +=2 ; + +/* Aux2 Playback Volume */ +A_ADD_VOLUME_IN (stereo_mix, gpr,A_EXTIN_AUX2_L ); +A_ADD_VOLUME_IN (stereo_mix+1 , gpr+1 ,A_EXTIN_AUX2_R ); +snd_emu10k1_init_stereo_control (&controls[nctl++], + emu->card_capabilities->ac97_chip ?"Aux2 Playback Volume" :"Aux Playback Volume" , + gpr,0 ); + gpr +=2 ; +/* Aux2 Capture Volume */ +A_ADD_VOLUME_IN (capture, gpr,A_EXTIN_AUX2_L ); +A_ADD_VOLUME_IN (capture+1 , gpr+1 ,A_EXTIN_AUX2_R ); +snd_emu10k1_init_stereo_control (&controls[nctl++], + emu->card_capabilities->ac97_chip ?"Aux2 Capture Volume" :"Aux Capture Volume" , + gpr,0 ); + gpr +=2 ; } -/* AC'97 Playback Volume - used only for mic (renamed later) */ -A_ADD_VOLUME_IN (stereo_mix, gpr,A_EXTIN_AC97_L ); -A_ADD_VOLUME_IN (stereo_mix+1 , gpr+1 ,A_EXTIN_AC97_R ); -snd_emu10k1_init_stereo_control (&controls[nctl++],"AMic Playback Volume" , gpr,0 ); - gpr +=2 ; -/* AC'97 Capture Volume - used only for mic */ -A_ADD_VOLUME_IN (capture, gpr,A_EXTIN_AC97_L ); -A_ADD_VOLUME_IN (capture+1 , gpr+1 ,A_EXTIN_AC97_R ); -snd_emu10k1_init_stereo_control (&controls[nctl++],"Mic Capture Volume" , gpr,0 ); - gpr +=2 ; - -/* mic capture buffer */ -A_OP (icode, &ptr, iINTERP,A_EXTOUT (A_EXTOUT_MIC_CAP ),A_EXTIN (A_EXTIN_AC97_L ),A_C_40000000 ,A_EXTIN (A_EXTIN_AC97_R )); - -/* Audigy CD Playback Volume */ -A_ADD_VOLUME_IN (stereo_mix, gpr,A_EXTIN_SPDIF_CD_L ); -A_ADD_VOLUME_IN (stereo_mix+1 , gpr+1 ,A_EXTIN_SPDIF_CD_R ); -snd_emu10k1_init_stereo_control (&controls[nctl++], - emu->card_capabilities->ac97_chip ?"Audigy CD Playback Volume" :"CD Playback Volume" , - gpr,0 ); - gpr +=2 ; -/* Audigy CD Capture Volume */ -A_ADD_VOLUME_IN (capture, gpr,A_EXTIN_SPDIF_CD_L ); -A_ADD_VOLUME_IN (capture+1 , gpr+1 ,A_EXTIN_SPDIF_CD_R ); -snd_emu10k1_init_stereo_control (&controls[nctl++], - emu->card_capabilities->ac97_chip ?"Audigy CD Capture Volume" :"CD Capture Volume" , - gpr,0 ); - gpr +=2 ; - -/* Optical SPDIF Playback Volume */ -A_ADD_VOLUME_IN (stereo_mix, gpr,A_EXTIN_OPT_SPDIF_L ); -A_ADD_VOLUME_IN (stereo_mix+1 , gpr+1 ,A_EXTIN_OPT_SPDIF_R ); -snd_emu10k1_init_stereo_control (&controls[nctl++],SNDRV_CTL_NAME_IEC958 ("Optical " ,PLAYBACK ,VOLUME ), gpr,0 ); - gpr +=2 ; -/* Optical SPDIF Capture Volume */ -A_ADD_VOLUME_IN (capture, gpr,A_EXTIN_OPT_SPDIF_L ); -A_ADD_VOLUME_IN (capture+1 , gpr+1 ,A_EXTIN_OPT_SPDIF_R ); -snd_emu10k1_init_stereo_control (&controls[nctl++],SNDRV_CTL_NAME_IEC958 ("Optical " ,CAPTURE ,VOLUME ), gpr,0 ); - gpr +=2 ; - -/* Line2 Playback Volume */ -A_ADD_VOLUME_IN (stereo_mix, gpr,A_EXTIN_LINE2_L ); -A_ADD_VOLUME_IN (stereo_mix+1 , gpr+1 ,A_EXTIN_LINE2_R ); -snd_emu10k1_init_stereo_control (&controls[nctl++], - emu->card_capabilities->ac97_chip ?"Line2 Playback Volume" :"Line Playback Volume" , - gpr,0 ); - gpr +=2 ; -/* Line2 Capture Volume */ -A_ADD_VOLUME_IN (capture, gpr,A_EXTIN_LINE2_L ); -A_ADD_VOLUME_IN (capture+1 , gpr+1 ,A_EXTIN_LINE2_R ); -snd_emu10k1_init_stereo_control (&controls[nctl++], - emu->card_capabilities->ac97_chip ?"Line2 Capture Volume" :"Line Capture Volume" , - gpr,0 ); - gpr +=2 ; - -/* Philips ADC Playback Volume */ -A_ADD_VOLUME_IN (stereo_mix, gpr,A_EXTIN_ADC_L ); -A_ADD_VOLUME_IN (stereo_mix+1 , gpr+1 ,A_EXTIN_ADC_R ); -snd_emu10k1_init_stereo_control (&controls[nctl++],"Analog Mix Playback Volume" , gpr,0 ); - gpr +=2 ; -/* Philips ADC Capture Volume */ -A_ADD_VOLUME_IN (capture, gpr,A_EXTIN_ADC_L ); -A_ADD_VOLUME_IN (capture+1 , gpr+1 ,A_EXTIN_ADC_R ); -snd_emu10k1_init_stereo_control (&controls[nctl++],"Analog Mix Capture Volume" , gpr,0 ); - gpr +=2 ; - -/* Aux2 Playback Volume */ -A_ADD_VOLUME_IN (stereo_mix, gpr,A_EXTIN_AUX2_L ); -A_ADD_VOLUME_IN (stereo_mix+1 , gpr+1 ,A_EXTIN_AUX2_R ); -snd_emu10k1_init_stereo_control (&controls[nctl++], - emu->card_capabilities->ac97_chip ?"Aux2 Playback Volume" :"Aux Playback Volume" , - gpr,0 ); - gpr +=2 ; -/* Aux2 Capture Volume */ -A_ADD_VOLUME_IN (capture, gpr,A_EXTIN_AUX2_L ); -A_ADD_VOLUME_IN (capture+1 , gpr+1 ,A_EXTIN_AUX2_R ); -snd_emu10k1_init_stereo_control (&controls[nctl++], - emu->card_capabilities->ac97_chip ?"Aux2 Capture Volume" :"Aux Capture Volume" , - gpr,0 ); - gpr +=2 ;/* Stereo Mix Front Playback Volume */ A_OP (icode, &ptr, iMAC0,A_GPR (playback),A_GPR (playback),A_GPR (gpr),A_GPR (stereo_mix));
@@ -1580,60 +1581,58 @@ A_OP(icode, &ptr, iMAC0, A_GPR(var), A_GPR(var), A_GPR(vol), A_EXTIN(input))snd_emu10k1_init_mono_control (&controls[nctl++],"Wave Master Playback Volume" , gpr,0 ); gpr++; -/* analog speakers */ -A_PUT_STEREO_OUTPUT (A_EXTOUT_AFRONT_L ,A_EXTOUT_AFRONT_R , playback); -A_PUT_STEREO_OUTPUT (A_EXTOUT_AREAR_L ,A_EXTOUT_AREAR_R , playback+2 ); -A_PUT_OUTPUT (A_EXTOUT_ACENTER , playback+4 ); -A_PUT_OUTPUT (A_EXTOUT_ALFE , playback+5 ); -if (emu->card_capabilities->spk71) -A_PUT_STEREO_OUTPUT (A_EXTOUT_ASIDE_L ,A_EXTOUT_ASIDE_R , playback+6 ); - -/* headphone */ -A_PUT_STEREO_OUTPUT (A_EXTOUT_HEADPHONE_L ,A_EXTOUT_HEADPHONE_R , playback); - -/* digital outputs */ -/* A_PUT_STEREO_OUTPUT(A_EXTOUT_FRONT_L, A_EXTOUT_FRONT_R, playback + SND_EMU10K1_PLAYBACK_CHANNELS); */ if (emu->card_capabilities->emu_model) {/* EMU1010 Outputs from PCM Front, Rear, Center, LFE, Side */ dev_info (emu->card->dev,"EMU outputs on\n" );for (z =0 ; z <8 ; z++) {if (emu->card_capabilities->ca0108_chip) {A_OP (icode, &ptr, iACC3,A3_EMU32OUT (z),A_GPR (playback + z),A_C_00000000 ,A_C_00000000 ); }else {A_OP (icode, &ptr, iACC3,A_EMU32OUTL (z),A_GPR (playback + z),A_C_00000000 ,A_C_00000000 ); } } - } + }else { +/* analog speakers */ +A_PUT_STEREO_OUTPUT (A_EXTOUT_AFRONT_L ,A_EXTOUT_AFRONT_R , playback); +A_PUT_STEREO_OUTPUT (A_EXTOUT_AREAR_L ,A_EXTOUT_AREAR_R , playback+2 ); +A_PUT_OUTPUT (A_EXTOUT_ACENTER , playback+4 ); +A_PUT_OUTPUT (A_EXTOUT_ALFE , playback+5 ); +if (emu->card_capabilities->spk71) +A_PUT_STEREO_OUTPUT (A_EXTOUT_ASIDE_L ,A_EXTOUT_ASIDE_R , playback+6 ); -/* IEC958 Optical Raw Playback Switch */ - gpr_map[gpr++] =0 ; - gpr_map[gpr++] =0x1008 ; - gpr_map[gpr++] =0xffff0000 ; -for (z =0 ; z <2 ; z++) { -A_OP (icode, &ptr, iMAC0,A_GPR (tmp +2 ),A_FXBUS (FXBUS_PT_LEFT + z),A_C_00000000 ,A_C_00000000 ); -A_OP (icode, &ptr, iSKIP,A_GPR_COND ,A_GPR_COND ,A_GPR (gpr -2 ),A_C_00000001 ); -A_OP (icode, &ptr, iACC3,A_GPR (tmp +2 ),A_C_00000000 ,A_C_00010000 ,A_GPR (tmp +2 )); -A_OP (icode, &ptr, iANDXOR,A_GPR (tmp +2 ),A_GPR (tmp +2 ),A_GPR (gpr -1 ),A_C_00000000 ); -A_SWITCH (icode, &ptr, tmp +0 , tmp +2 , gpr + z); -A_SWITCH_NEG (icode, &ptr, tmp +1 , gpr + z); -A_SWITCH (icode, &ptr, tmp +1 , playback + z, tmp +1 ); -if ((z==1 ) && (emu->card_capabilities->spdif_bug)) { -/* Due to a SPDIF output bug on some Audigy cards, this code delays the Right channel by 1 sample */ -dev_info (emu->card->dev, -"Installing spdif_bug patch: %s\n" , - emu->card_capabilities->name); -A_OP (icode, &ptr, iACC3,A_EXTOUT (A_EXTOUT_FRONT_L + z),A_GPR (gpr -3 ),A_C_00000000 ,A_C_00000000 ); -A_OP (icode, &ptr, iACC3,A_GPR (gpr -3 ),A_GPR (tmp +0 ),A_GPR (tmp +1 ),A_C_00000000 ); - }else { -A_OP (icode, &ptr, iACC3,A_EXTOUT (A_EXTOUT_FRONT_L + z),A_GPR (tmp +0 ),A_GPR (tmp +1 ),A_C_00000000 ); +/* headphone */ +A_PUT_STEREO_OUTPUT (A_EXTOUT_HEADPHONE_L ,A_EXTOUT_HEADPHONE_R , playback); + +/* IEC958 Optical Raw Playback Switch */ + gpr_map[gpr++] =0 ; + gpr_map[gpr++] =0x1008 ; + gpr_map[gpr++] =0xffff0000 ; +for (z =0 ; z <2 ; z++) { +A_OP (icode, &ptr, iMAC0,A_GPR (tmp +2 ),A_FXBUS (FXBUS_PT_LEFT + z),A_C_00000000 ,A_C_00000000 ); +A_OP (icode, &ptr, iSKIP,A_GPR_COND ,A_GPR_COND ,A_GPR (gpr -2 ),A_C_00000001 ); +A_OP (icode, &ptr, iACC3,A_GPR (tmp +2 ),A_C_00000000 ,A_C_00010000 ,A_GPR (tmp +2 )); +A_OP (icode, &ptr, iANDXOR,A_GPR (tmp +2 ),A_GPR (tmp +2 ),A_GPR (gpr -1 ),A_C_00000000 ); +A_SWITCH (icode, &ptr, tmp +0 , tmp +2 , gpr + z); +A_SWITCH_NEG (icode, &ptr, tmp +1 , gpr + z); +A_SWITCH (icode, &ptr, tmp +1 , playback + z, tmp +1 ); +if ((z==1 ) && (emu->card_capabilities->spdif_bug)) { +/* Due to a SPDIF output bug on some Audigy cards, this code delays the Right channel by 1 sample */ +dev_info (emu->card->dev, +"Installing spdif_bug patch: %s\n" , + emu->card_capabilities->name); +A_OP (icode, &ptr, iACC3,A_EXTOUT (A_EXTOUT_FRONT_L + z),A_GPR (gpr -3 ),A_C_00000000 ,A_C_00000000 ); +A_OP (icode, &ptr, iACC3,A_GPR (gpr -3 ),A_GPR (tmp +0 ),A_GPR (tmp +1 ),A_C_00000000 ); + }else { +A_OP (icode, &ptr, iACC3,A_EXTOUT (A_EXTOUT_FRONT_L + z),A_GPR (tmp +0 ),A_GPR (tmp +1 ),A_C_00000000 ); + } } +snd_emu10k1_init_stereo_onoff_control (controls + nctl++,SNDRV_CTL_NAME_IEC958 ("Optical Raw " ,PLAYBACK ,SWITCH ), gpr,0 ); + gpr +=2 ; + +A_PUT_STEREO_OUTPUT (A_EXTOUT_REAR_L ,A_EXTOUT_REAR_R , playback+2 ); +A_PUT_OUTPUT (A_EXTOUT_CENTER , playback+4 ); +A_PUT_OUTPUT (A_EXTOUT_LFE , playback+5 ); } -snd_emu10k1_init_stereo_onoff_control (controls + nctl++,SNDRV_CTL_NAME_IEC958 ("Optical Raw " ,PLAYBACK ,SWITCH ), gpr,0 ); - gpr +=2 ; - -A_PUT_STEREO_OUTPUT (A_EXTOUT_REAR_L ,A_EXTOUT_REAR_R , playback+2 ); -A_PUT_OUTPUT (A_EXTOUT_CENTER , playback+4 ); -A_PUT_OUTPUT (A_EXTOUT_LFE , playback+5 );/* ADC buffer */ #ifdef EMU10K1_CAPTURE_DIGITAL_OUT
Signature · 1 line
2.40.0.152.g15d061e6df
PATCH 12/14 ALSA: emu10k1: skip mic capture PCM for cards without AC97 codec
In reply to Oswald BuddenhagenThe microphone capture device is a feature of the AC97 codec, so its availability should be coupled to the presence of that codec.
---
This patch needs to be applied on top of the patch titled "ALSA:
emu10k1: omit non-applicable mixer controls for E-MU cards".
--- sound/pci/emu10k1/emu10k1.c | 8 +++++--- sound/pci/emu10k1/emufx.c | 26 ++++++++++++++------------ 2 files changed, 19 insertions(+), 15 deletions(-)
sound/pci/emu10k1/emu10k1.c +5 -3
@@ -107,9 +107,11 @@ static int snd_card_emu10k1_probe(struct pci_dev *pci, err =snd_emu10k1_pcm (emu,0 );if (err <0 )return err; - err =snd_emu10k1_pcm_mic (emu,1 ); -if (err <0 ) -return err; +if (emu->card_capabilities->ac97_chip) { + err =snd_emu10k1_pcm_mic (emu,1 ); +if (err <0 ) +return err; + } err =snd_emu10k1_pcm_efx (emu,2 );if (err <0 )return err;
sound/pci/emu10k1/emufx.c +14 -12
@@ -1380,19 +1380,21 @@ A_OP(icode, &ptr, iMAC0, A_GPR(var), A_GPR(var), A_GPR(vol), A_EXTIN(input)) gpr_map[gpr +2 ] =0x00000000 ; gpr +=3 ; }else { -/* AC'97 Playback Volume - used only for mic (renamed later) */ -A_ADD_VOLUME_IN (stereo_mix, gpr,A_EXTIN_AC97_L ); -A_ADD_VOLUME_IN (stereo_mix+1 , gpr+1 ,A_EXTIN_AC97_R ); -snd_emu10k1_init_stereo_control (&controls[nctl++],"AMic Playback Volume" , gpr,0 ); - gpr +=2 ; -/* AC'97 Capture Volume - used only for mic */ -A_ADD_VOLUME_IN (capture, gpr,A_EXTIN_AC97_L ); -A_ADD_VOLUME_IN (capture+1 , gpr+1 ,A_EXTIN_AC97_R ); -snd_emu10k1_init_stereo_control (&controls[nctl++],"Mic Capture Volume" , gpr,0 ); - gpr +=2 ; +if (emu->card_capabilities->ac97_chip) { +/* AC'97 Playback Volume - used only for mic (renamed later) */ +A_ADD_VOLUME_IN (stereo_mix, gpr,A_EXTIN_AC97_L ); +A_ADD_VOLUME_IN (stereo_mix+1 , gpr+1 ,A_EXTIN_AC97_R ); +snd_emu10k1_init_stereo_control (&controls[nctl++],"AMic Playback Volume" , gpr,0 ); + gpr +=2 ; +/* AC'97 Capture Volume - used only for mic */ +A_ADD_VOLUME_IN (capture, gpr,A_EXTIN_AC97_L ); +A_ADD_VOLUME_IN (capture+1 , gpr+1 ,A_EXTIN_AC97_R ); +snd_emu10k1_init_stereo_control (&controls[nctl++],"Mic Capture Volume" , gpr,0 ); + gpr +=2 ; -/* mic capture buffer */ -A_OP (icode, &ptr, iINTERP,A_EXTOUT (A_EXTOUT_MIC_CAP ),A_EXTIN (A_EXTIN_AC97_L ),A_C_40000000 ,A_EXTIN (A_EXTIN_AC97_R )); +/* mic capture buffer */ +A_OP (icode, &ptr, iINTERP,A_EXTOUT (A_EXTOUT_MIC_CAP ),A_EXTIN (A_EXTIN_AC97_L ),A_C_40000000 ,A_EXTIN (A_EXTIN_AC97_R )); + }/* Audigy CD Playback Volume */ A_ADD_VOLUME_IN (stereo_mix, gpr,A_EXTIN_SPDIF_CD_L );
Signature · 1 line
2.40.0.152.g15d061e6df
PATCH 13/14 ALSA: emu10k1: enable bit-exact playback, part 1: DSP attenuation
In reply to Oswald BuddenhagenFractional multiplication with the maximal value 2^31-1 causes some tiny distortion. Instead, we want to multiply with the full 2^31. The catch is of course that this cannot be represented in the DSP's signed 32 bit registers.
One way to deal with this is to encode 1.0 as a negative number and special-case it. As a matter of fact, the SbLive! code path already contained such code, though the controls never actually exercised it.
A more efficient approach is to use negative values, which actually extend to -2^31. Accordingly, for all the volume adjustments we now use the MAC1 instruction which negates the X operand.
The range of the controls in highres mode is extended downwards, so -1 is the new zero/mute. At maximal excursion, real zero is not mute any more, but I don't think anyone will notice this behavior change. ;-)
That also required making the min/max/values in the control structs signed. This technically changes the user space interface, but it seems implausible that someone would notice - the numbers were actually treated as if they were signed anyway (and in the actual mixer iface they _are_). And without this change, the min value didn't even make sense in the first place (and no-one noticed, because it was always 0).
--- include/sound/emu10k1.h | 6 +- include/uapi/sound/emu10k1.h | 8 ++- sound/pci/emu10k1/emufx.c | 119 +++++++++++++++++------------------ 3 files changed, 64 insertions(+), 69 deletions(-)
include/sound/emu10k1.h +3 -3
@@ -1511,9 +1511,9 @@ struct snd_emu10k1_fx8010_ctl {unsigned int vcount;unsigned int count;/* count of GPR (1..16) */ unsigned short gpr[32 ];/* GPR number(s) */ -unsigned int value[32 ]; -unsigned int min;/* minimum range */ -unsigned int max;/* maximum range */ +int value[32 ]; +int min;/* minimum range */ +int max;/* maximum range */ unsigned int translation;/* translation type (EMU10K1_GPR_TRANSLATION*) */ struct snd_kcontrol *kcontrol; };
include/uapi/sound/emu10k1.h +5 -3
@@ -308,6 +308,8 @@ struct snd_emu10k1_fx8010_info {#define EMU10K1_GPR_TRANSLATION_BASS 2#define EMU10K1_GPR_TRANSLATION_TREBLE 3#define EMU10K1_GPR_TRANSLATION_ONOFF 4 +#define EMU10K1_GPR_TRANSLATION_NEGATE 5 +#define EMU10K1_GPR_TRANSLATION_NEG_TABLE100 6enum emu10k1_ctl_elem_iface {EMU10K1_CTL_ELEM_IFACE_MIXER =2 ,/* virtual mixer device */
@@ -328,9 +330,9 @@ struct snd_emu10k1_fx8010_control_gpr {unsigned int vcount;/* visible count */ unsigned int count;/* count of GPR (1..16) */ unsigned short gpr[32 ];/* GPR number(s) */ -unsigned int value[32 ];/* initial values */ -unsigned int min;/* minimum range */ -unsigned int max;/* maximum range */ +int value[32 ];/* initial values */ +int min;/* minimum range */ +int max;/* maximum range */ unsigned int translation;/* translation type (EMU10K1_GPR_TRANSLATION*) */ const unsigned int *tlv; };
sound/pci/emu10k1/emufx.c +56 -63
293 lines not on this page · raw message
Signature · 1 line
2.40.0.152.g15d061e6df
PATCH 14/14 ALSA: emu10k1: enable bit-exact playback, part 2: voice attenuation
In reply to Oswald BuddenhagenThe voice volume is a raw fractional multiplier that can't actually represent 1.0. To still enable real pass-through, we now set the volume to 0.5 (which results in no loss of precision, as the FX bus provides fractional values) and scale up the samples in DSP code.
To maintain backwards compatibility with existing configuration files, we rescale the values in the mixer controls. The range is extended upwards from 0xffff to 0x1fffd, which actually introduces the possibility of specifying an amplification.
There is still a minor incompatibility with user space, namely if someone loaded custom DSP code. They'll just get half the volume, so this doesn't seem like a big deal.
--- Documentation/sound/cards/audigy-mixer.rst | 2 +- Documentation/sound/cards/sb-live-mixer.rst | 2 +- include/sound/emu10k1.h | 3 +++ sound/pci/emu10k1/emufx.c | 30 ++++++++++++--------- sound/pci/emu10k1/emumixer.c | 15 ++++++----- sound/pci/emu10k1/emupcm.c | 4 +-- 6 files changed, 34 insertions(+), 22 deletions(-)
Documentation/sound/cards/audigy-mixer.rst +1 -1
@@ -227,7 +227,7 @@ PCM stream related controls name='EMU10K1 PCM Volume',index 0-31 ------------------------------------ -Channel volume attenuation in range 0-0xffff. The maximum value (no +Channel volume attenuation in range 0-0x1fffd. The middle value (no attenuation) is default. The channel mapping for three values is as follows:
Documentation/sound/cards/sb-live-mixer.rst +1 -1
@@ -258,7 +258,7 @@ PCM stream related controls ``name='EMU10K1 PCM Volume',index 0-31`` ---------------------------------------- -Channel volume attenuation in range 0-0xffff. The maximum value (no +Channel volume attenuation in range 0-0x1fffd. The middle value (no attenuation) is default. The channel mapping for three values is as follows:
include/sound/emu10k1.h +3 -0
@@ -396,6 +396,7 @@#define PTRX_FXSENDAMOUNT_B_MASK 0x000000ff/* Linear level of channel output sent to FX send bus B */ #define PTRX_FXSENDAMOUNT_B 0x08000001 +// Note: the volumes are raw multpliers, so real 100% is impossible. #define CVCF 0x02/* Current volume and filter cutoff register */ #define CVCF_CURRENTVOL_MASK 0xffff0000/* Current linear volume of specified channel */ #define CVCF_CURRENTVOL 0x10100002
@@ -1480,6 +1481,8 @@ struct snd_emu10k1_pcm_mixer {/* mono, left, right x 8 sends (4 on emu10k1) */ unsigned char send_routing[3 ][8 ];unsigned char send_volume[3 ][8 ]; +// 0x8000 is neutral. The mixer code rescales it to 0xffff to maintain +// backwards compatibility with user space. unsigned short attn[3 ];struct snd_emu10k1_pcm *epcm; };
sound/pci/emu10k1/emufx.c +18 -12
@@ -1361,7 +1361,13 @@ static int _snd_emu10k1_audigy_init_efx(struct snd_emu10k1 *emu)A_OP (icode, &ptr, iMAC1,A_GPR (capture+1 ),A_GPR (capture+1 ),A_GPR (gpr+1 ),A_FXBUS (FXBUS_MIDI_RIGHT ));snd_emu10k1_init_stereo_control (&controls[nctl++],"Synth Capture Volume" , gpr,0 ); gpr +=2 ; - + +// We need to double the volume, as we configure the voices for half volume, +// which is necessary for bit-identical reproduction. + {static_assert (stereo_mix == playback +SND_EMU10K1_PLAYBACK_CHANNELS ); } +for (z =0 ; z <SND_EMU10K1_PLAYBACK_CHANNELS +2 ; z++) +A_OP (icode, &ptr, iACC3,A_GPR (playback + z),A_GPR (playback + z),A_GPR (playback + z),A_C_00000000 ); +/* * inputs */
@@ -1822,18 +1828,18 @@ static int _snd_emu10k1_init_efx(struct snd_emu10k1 *emu)/* * Process FX Buses */ -OP (icode, &ptr, iMACINT0,GPR (0 ),C_00000000 ,FXBUS (FXBUS_PCM_LEFT ),C_00000004 ); -OP (icode, &ptr, iMACINT0,GPR (1 ),C_00000000 ,FXBUS (FXBUS_PCM_RIGHT ),C_00000004 ); -OP (icode, &ptr, iMACINT0,GPR (2 ),C_00000000 ,FXBUS (FXBUS_MIDI_LEFT ),C_00000004 ); -OP (icode, &ptr, iMACINT0,GPR (3 ),C_00000000 ,FXBUS (FXBUS_MIDI_RIGHT ),C_00000004 ); -OP (icode, &ptr, iMACINT0,GPR (4 ),C_00000000 ,FXBUS (FXBUS_PCM_LEFT_REAR ),C_00000004 ); -OP (icode, &ptr, iMACINT0,GPR (5 ),C_00000000 ,FXBUS (FXBUS_PCM_RIGHT_REAR ),C_00000004 ); -OP (icode, &ptr, iMACINT0,GPR (6 ),C_00000000 ,FXBUS (FXBUS_PCM_CENTER ),C_00000004 ); -OP (icode, &ptr, iMACINT0,GPR (7 ),C_00000000 ,FXBUS (FXBUS_PCM_LFE ),C_00000004 ); +OP (icode, &ptr, iMACINT0,GPR (0 ),C_00000000 ,FXBUS (FXBUS_PCM_LEFT ),C_00000008 ); +OP (icode, &ptr, iMACINT0,GPR (1 ),C_00000000 ,FXBUS (FXBUS_PCM_RIGHT ),C_00000008 ); +OP (icode, &ptr, iMACINT0,GPR (2 ),C_00000000 ,FXBUS (FXBUS_MIDI_LEFT ),C_00000008 ); +OP (icode, &ptr, iMACINT0,GPR (3 ),C_00000000 ,FXBUS (FXBUS_MIDI_RIGHT ),C_00000008 ); +OP (icode, &ptr, iMACINT0,GPR (4 ),C_00000000 ,FXBUS (FXBUS_PCM_LEFT_REAR ),C_00000008 ); +OP (icode, &ptr, iMACINT0,GPR (5 ),C_00000000 ,FXBUS (FXBUS_PCM_RIGHT_REAR ),C_00000008 ); +OP (icode, &ptr, iMACINT0,GPR (6 ),C_00000000 ,FXBUS (FXBUS_PCM_CENTER ),C_00000008 ); +OP (icode, &ptr, iMACINT0,GPR (7 ),C_00000000 ,FXBUS (FXBUS_PCM_LFE ),C_00000008 );OP (icode, &ptr, iMACINT0,GPR (8 ),C_00000000 ,C_00000000 ,C_00000000 );/* S/PDIF left */ OP (icode, &ptr, iMACINT0,GPR (9 ),C_00000000 ,C_00000000 ,C_00000000 );/* S/PDIF right */ -OP (icode, &ptr, iMACINT0,GPR (10 ),C_00000000 ,FXBUS (FXBUS_PCM_LEFT_FRONT ),C_00000004 ); -OP (icode, &ptr, iMACINT0,GPR (11 ),C_00000000 ,FXBUS (FXBUS_PCM_RIGHT_FRONT ),C_00000004 ); +OP (icode, &ptr, iMACINT0,GPR (10 ),C_00000000 ,FXBUS (FXBUS_PCM_LEFT_FRONT ),C_00000008 ); +OP (icode, &ptr, iMACINT0,GPR (11 ),C_00000000 ,FXBUS (FXBUS_PCM_RIGHT_FRONT ),C_00000008 );/* Raw S/PDIF PCM */ ipcm->substream =0 ;
@@ -1927,7 +1933,7 @@ static int _snd_emu10k1_init_efx(struct snd_emu10k1 *emu)/* Wave Center/LFE Playback Volume */ OP (icode, &ptr, iACC3,GPR (tmp +0 ),FXBUS (FXBUS_PCM_LEFT ),FXBUS (FXBUS_PCM_RIGHT ),C_00000000 ); -OP (icode, &ptr, iMACINT0,GPR (tmp +0 ),C_00000000 ,GPR (tmp +0 ),C_00000002 ); +OP (icode, &ptr, iMACINT0,GPR (tmp +0 ),C_00000000 ,GPR (tmp +0 ),C_00000004 );VOLUME (icode, &ptr, playback +4 , tmp +0 , gpr);snd_emu10k1_init_mono_control (controls + i++,"Wave Center Playback Volume" , gpr++,0 );VOLUME (icode, &ptr, playback +5 , tmp +0 , gpr);
sound/pci/emu10k1/emumixer.c +9 -6
@@ -1352,7 +1352,7 @@ static int snd_emu10k1_attn_info(struct snd_kcontrol *kcontrol, struct snd_ctl_e uinfo->type =SNDRV_CTL_ELEM_TYPE_INTEGER ; uinfo->count =3 ; uinfo->value.integer.min =0 ; - uinfo->value.integer.max =0xffff ; + uinfo->value.integer.max =0x1fffd ;return 0 ; }
@@ -1365,7 +1365,7 @@ static int snd_emu10k1_attn_get(struct snd_kcontrol *kcontrol,int idx;for (idx =0 ; idx <3 ; idx++) - ucontrol->value.integer.value[idx] = mix->attn[idx]; + ucontrol->value.integer.value[idx] = mix->attn[idx] *0xffffU /0x8000U ;return 0 ; }
@@ -1380,7 +1380,8 @@ static int snd_emu10k1_attn_put(struct snd_kcontrol *kcontrol,spin_lock_irqsave (&emu->reg_lock, flags);for (idx =0 ; idx <3 ; idx++) { - val = ucontrol->value.integer.value[idx] &0xffff ; +unsigned uval = ucontrol->value.integer.value[idx] &0x1ffff ; + val = uval *0x8000U /0xffffU ;if (mix->attn[idx] != val) { mix->attn[idx] = val; change =1 ;
@@ -1547,32 +1548,34 @@ static int snd_emu10k1_efx_attn_info(struct snd_kcontrol *kcontrol, struct snd_c uinfo->type =SNDRV_CTL_ELEM_TYPE_INTEGER ; uinfo->count =1 ; uinfo->value.integer.min =0 ; - uinfo->value.integer.max =0xffff ; + uinfo->value.integer.max =0x1fffd ;return 0 ; }static int snd_emu10k1_efx_attn_get (struct snd_kcontrol *kcontrol,struct snd_ctl_elem_value *ucontrol) {struct snd_emu10k1 *emu =snd_kcontrol_chip (kcontrol);struct snd_emu10k1_pcm_mixer *mix = &emu->efx_pcm_mixer[snd_ctl_get_ioffidx (kcontrol, &ucontrol->id)]; - ucontrol->value.integer.value[0 ] = mix->attn[0 ]; + ucontrol->value.integer.value[0 ] = mix->attn[0 ] *0xffffU /0x8000U ;return 0 ; }static int snd_emu10k1_efx_attn_put (struct snd_kcontrol *kcontrol,struct snd_ctl_elem_value *ucontrol) {unsigned long flags;struct snd_emu10k1 *emu =snd_kcontrol_chip (kcontrol);int ch =snd_ctl_get_ioffidx (kcontrol, &ucontrol->id);struct snd_emu10k1_pcm_mixer *mix = &emu->efx_pcm_mixer[ch];int change =0 , val; +unsigned uval;spin_lock_irqsave (&emu->reg_lock, flags); - val = ucontrol->value.integer.value[0 ] &0xffff ; + uval = ucontrol->value.integer.value[0 ] &0x1ffff ; + val = uval *0x8000U /0xffffU ;if (mix->attn[0 ] != val) { mix->attn[0 ] = val; change =1 ;
sound/pci/emu10k1/emupcm.c +2 -2
@@ -1049,7 +1049,7 @@ static int snd_emu10k1_efx_playback_open(struct snd_pcm_substream *substream) mix->send_routing[0 ][0 ] = i;memset (&mix->send_volume,0 ,sizeof (mix->send_volume)); mix->send_volume[0 ][0 ] =255 ; - mix->attn[0 ] =0xffff ; + mix->attn[0 ] =0x8000 ; mix->epcm = epcm;snd_emu10k1_pcm_efx_mixer_notify (emu, i,1 ); }
@@ -1098,7 +1098,7 @@ static int snd_emu10k1_playback_open(struct snd_pcm_substream *substream)memset (&mix->send_volume,0 ,sizeof (mix->send_volume)); mix->send_volume[0 ][0 ] = mix->send_volume[0 ][1 ] = mix->send_volume[1 ][0 ] = mix->send_volume[2 ][1 ] =255 ; - mix->attn[0 ] = mix->attn[1 ] = mix->attn[2 ] =0xffff ; + mix->attn[0 ] = mix->attn[1 ] = mix->attn[2 ] =0x8000 ; mix->epcm = epcm;snd_emu10k1_pcm_mixer_notify (emu, substream->number,1 );return 0 ;
Signature · 1 line
2.40.0.152.g15d061e6df
Quoted 17 lines · Oswald Buddenhagen
Oswald Buddenhagen (14):
ALSA: emu10k1: make tone control switch mono
ALSA: emu10k1: roll up loops in DSP setup code for Audigy
ALSA: emu10k1: fix+optimize E-MU stereo capture DSP code
ALSA: emu10k1: simplifysnd_emu10k1_audigy_dsp_convert_32_to_2x16()
ALSA: emu10k1: apply channel delay hack to all E-MU cards
ALSA: emu10k1: simplify tone control switch DSP code
ALSA: emu10k1: properly assert DSP init constraints
ALSA: emu10k1: polish audigy GPR allocation
ALSA: emu10k1: fix non-zero mixer control defaults in highres mode
ALSA: emu10k1: validate min/max values of translated controls
ALSA: emu10k1: omit non-applicable mixer controls for E-MU cards
ALSA: emu10k1: skip mic capture PCM for cards without AC97 codec
ALSA: emu10k1: enable bit-exact playback, part 1: DSP attenuation
ALSA: emu10k1: enable bit-exact playback, part 2: voice attenuation
So I applied partially, only the patches from 1 to 6 for now. Except for the patch 7, it looks good and I'll happily apply after resubmission.
thanks,
Takashi