📄 au88x0_eq.c
字号:
static voidvortex_EqHw_Program10Band(vortex_t * vortex, auxxEqCoeffSet_t * coefset){ vortex_EqHw_SetTimeConsts(vortex, 0xc, 0x7fe0); vortex_EqHw_SetLeftCoefs(vortex, coefset->LeftCoefs); vortex_EqHw_SetRightCoefs(vortex, coefset->RightCoefs); vortex_EqHw_SetLeftGainsCurrent(vortex, coefset->LeftGains); vortex_EqHw_SetRightGainsTarget(vortex, coefset->RightGains); vortex_EqHw_SetLeftGainsTarget(vortex, coefset->LeftGains); vortex_EqHw_SetRightGainsCurrent(vortex, coefset->RightGains);}/* Read all EQ peaks. (think VU meter) */static void vortex_EqHw_GetTenBandLevels(vortex_t * vortex, u16 peaks[]){ eqhw_t *eqhw = &(vortex->eq.this04); int i; if (eqhw->this04 <= 0) return; for (i = 0; i < eqhw->this04; i++) peaks[i] = hwread(vortex->mmio, 0x2B024 + i * 0x30); for (i = 0; i < eqhw->this04; i++) peaks[i + eqhw->this04] = hwread(vortex->mmio, 0x2B204 + i * 0x30);}/* CEqlzr.s */static int vortex_Eqlzr_GetLeftGain(vortex_t * vortex, u16 index, u16 * gain){ eqlzr_t *eq = &(vortex->eq); if (eq->this28) { *gain = eq->this130[index]; return 0; } return 1;}static void vortex_Eqlzr_SetLeftGain(vortex_t * vortex, u16 index, u16 gain){ eqlzr_t *eq = &(vortex->eq); if (eq->this28 == 0) return; eq->this130[index] = gain; if (eq->this54) return; vortex_EqHw_SetLeftGainsSingleTarget(vortex, index, gain);}static int vortex_Eqlzr_GetRightGain(vortex_t * vortex, u16 index, u16 * gain){ eqlzr_t *eq = &(vortex->eq); if (eq->this28) { *gain = eq->this130[index + eq->this10]; return 0; } return 1;}static void vortex_Eqlzr_SetRightGain(vortex_t * vortex, u16 index, u16 gain){ eqlzr_t *eq = &(vortex->eq); if (eq->this28 == 0) return; eq->this130[index + eq->this10] = gain; if (eq->this54) return; vortex_EqHw_SetRightGainsSingleTarget(vortex, index, gain);}#if 0static intvortex_Eqlzr_GetAllBands(vortex_t * vortex, u16 * gains, unsigned long *cnt){ eqlzr_t *eq = &(vortex->eq); int si = 0; if (eq->this10 == 0) return 1; { if (vortex_Eqlzr_GetLeftGain(vortex, si, &gains[si])) return 1; if (vortex_Eqlzr_GetRightGain (vortex, si, &gains[si + eq->this10])) return 1; si++; } while (eq->this10 > si) ; *cnt = si * 2; return 0;}#endifstatic int vortex_Eqlzr_SetAllBandsFromActiveCoeffSet(vortex_t * vortex){ eqlzr_t *eq = &(vortex->eq); vortex_EqHw_SetLeftGainsTarget(vortex, eq->this130); vortex_EqHw_SetRightGainsTarget(vortex, &(eq->this130[eq->this10])); return 0;}static intvortex_Eqlzr_SetAllBands(vortex_t * vortex, u16 gains[], unsigned long count){ eqlzr_t *eq = &(vortex->eq); int i; if (((eq->this10) * 2 != count) || (eq->this28 == 0)) return 1; for (i = 0; i < count; i++) { eq->this130[i] = gains[i]; } if (eq->this54) return 0; return vortex_Eqlzr_SetAllBandsFromActiveCoeffSet(vortex);}static voidvortex_Eqlzr_SetA3dBypassGain(vortex_t * vortex, unsigned long a, unsigned long b){ eqlzr_t *eq = &(vortex->eq); int eax, ebx; eq->this58 = a; eq->this5c = b; if (eq->this54) eax = eq->this0e; else eax = eq->this0a; ebx = (eax * eq->this58) >> 0x10; eax = (eax * eq->this5c) >> 0x10; vortex_EqHw_SetA3DBypassGain(vortex, ebx, eax);}static void vortex_Eqlzr_ProgramA3dBypassGain(vortex_t * vortex){ eqlzr_t *eq = &(vortex->eq); int eax, ebx; if (eq->this54) eax = eq->this0e; else eax = eq->this0a; ebx = (eax * eq->this58) >> 0x10; eax = (eax * eq->this5c) >> 0x10; vortex_EqHw_SetA3DBypassGain(vortex, ebx, eax);}static void vortex_Eqlzr_ShutDownA3d(vortex_t * vortex){ if (vortex != NULL) vortex_EqHw_ZeroA3DIO(vortex);}static void vortex_Eqlzr_SetBypass(vortex_t * vortex, long bp){ eqlzr_t *eq = &(vortex->eq); if ((eq->this28) && (bp == 0)) { /* EQ enabled */ vortex_Eqlzr_SetAllBandsFromActiveCoeffSet(vortex); vortex_EqHw_SetBypassGain(vortex, eq->this08, eq->this08); } else { /* EQ disabled. */ vortex_EqHw_SetLeftGainsTarget(vortex, (u16 *) (eq->this14)); vortex_EqHw_SetRightGainsTarget(vortex, (u16 *) (eq->this14)); vortex_EqHw_SetBypassGain(vortex, eq->this0c, eq->this0c); } vortex_Eqlzr_ProgramA3dBypassGain(vortex);}static void vortex_Eqlzr_ReadAndSetActiveCoefSet(vortex_t * vortex){ eqlzr_t *eq = &(vortex->eq); /* Set EQ BiQuad filter coeficients */ memcpy(&(eq->coefset), &asEqCoefsNormal, sizeof(auxxEqCoeffSet_t)); /* Set EQ Band gain levels and dump into hardware registers. */ vortex_Eqlzr_SetAllBands(vortex, eq_gains_normal, eq->this10 * 2);}static int vortex_Eqlzr_GetAllPeaks(vortex_t * vortex, u16 * peaks, int *count){ eqlzr_t *eq = &(vortex->eq); if (eq->this10 == 0) return 1; *count = eq->this10 * 2; vortex_EqHw_GetTenBandLevels(vortex, peaks); return 0;}#if 0static auxxEqCoeffSet_t *vortex_Eqlzr_GetActiveCoefSet(vortex_t * vortex){ eqlzr_t *eq = &(vortex->eq); return (&(eq->coefset));}#endifstatic void vortex_Eqlzr_init(vortex_t * vortex){ eqlzr_t *eq = &(vortex->eq); /* Object constructor */ //eq->this04 = 0; eq->this08 = 0; /* Bypass gain with EQ in use. */ eq->this0a = 0x5999; eq->this0c = 0x5999; /* Bypass gain with EQ disabled. */ eq->this0e = 0x5999; eq->this10 = 0xa; /* 10 eq frequency bands. */ eq->this04.this04 = eq->this10; eq->this28 = 0x1; /* if 1 => Allow read access to this130 (gains) */ eq->this54 = 0x0; /* if 1 => Dont Allow access to hardware (gains) */ eq->this58 = 0xffff; eq->this5c = 0xffff; /* Set gains. */ memset(eq->this14, 0, 2 * 10); /* Actual init. */ vortex_EqHw_ZeroState(vortex); vortex_EqHw_SetSampleRate(vortex, 0x11); vortex_Eqlzr_ReadAndSetActiveCoefSet(vortex); vortex_EqHw_Program10Band(vortex, &(eq->coefset)); vortex_Eqlzr_SetBypass(vortex, eq->this54); vortex_Eqlzr_SetA3dBypassGain(vortex, 0, 0); vortex_EqHw_Enable(vortex);}static void vortex_Eqlzr_shutdown(vortex_t * vortex){ vortex_Eqlzr_ShutDownA3d(vortex); vortex_EqHw_ProgramPipe(vortex); vortex_EqHw_Disable(vortex);}/* ALSA interface *//* Control interface */static intsnd_vortex_eqtoggle_info(snd_kcontrol_t * kcontrol, snd_ctl_elem_info_t * uinfo){ uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN; uinfo->count = 1; uinfo->value.integer.min = 0; uinfo->value.integer.max = 1; return 0;}static intsnd_vortex_eqtoggle_get(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol){ vortex_t *vortex = snd_kcontrol_chip(kcontrol); eqlzr_t *eq = &(vortex->eq); //int i = kcontrol->private_value; ucontrol->value.integer.value[0] = eq->this54 ? 0 : 1; return 0;}static intsnd_vortex_eqtoggle_put(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol){ vortex_t *vortex = snd_kcontrol_chip(kcontrol); eqlzr_t *eq = &(vortex->eq); //int i = kcontrol->private_value; eq->this54 = ucontrol->value.integer.value[0] ? 0 : 1; vortex_Eqlzr_SetBypass(vortex, eq->this54); return 1; /* Allways changes */}static snd_kcontrol_new_t vortex_eqtoggle_kcontrol __devinitdata = { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = "EQ Enable", .index = 0, .access = SNDRV_CTL_ELEM_ACCESS_READWRITE, .private_value = 0, .info = snd_vortex_eqtoggle_info, .get = snd_vortex_eqtoggle_get, .put = snd_vortex_eqtoggle_put};static intsnd_vortex_eq_info(snd_kcontrol_t * kcontrol, snd_ctl_elem_info_t * uinfo){ uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; uinfo->count = 2; uinfo->value.integer.min = 0x0000; uinfo->value.integer.max = 0x7fff; return 0;}static intsnd_vortex_eq_get(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol){ vortex_t *vortex = snd_kcontrol_chip(kcontrol); int i = kcontrol->private_value; u16 gainL, gainR; vortex_Eqlzr_GetLeftGain(vortex, i, &gainL); vortex_Eqlzr_GetRightGain(vortex, i, &gainR); ucontrol->value.integer.value[0] = gainL; ucontrol->value.integer.value[1] = gainR; return 0;}static intsnd_vortex_eq_put(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol){ vortex_t *vortex = snd_kcontrol_chip(kcontrol); int changed = 0, i = kcontrol->private_value; u16 gainL, gainR; vortex_Eqlzr_GetLeftGain(vortex, i, &gainL); vortex_Eqlzr_GetRightGain(vortex, i, &gainR); if (gainL != ucontrol->value.integer.value[0]) { vortex_Eqlzr_SetLeftGain(vortex, i, ucontrol->value.integer.value[0]); changed = 1; } if (gainR != ucontrol->value.integer.value[1]) { vortex_Eqlzr_SetRightGain(vortex, i, ucontrol->value.integer.value[1]); changed = 1; } return changed;}static snd_kcontrol_new_t vortex_eq_kcontrol __devinitdata = { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = " .", .index = 0, .access = SNDRV_CTL_ELEM_ACCESS_READWRITE, .private_value = 0, .info = snd_vortex_eq_info, .get = snd_vortex_eq_get, .put = snd_vortex_eq_put};static intsnd_vortex_peaks_info(snd_kcontrol_t * kcontrol, snd_ctl_elem_info_t * uinfo){ uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; uinfo->count = 20; uinfo->value.integer.min = 0x0000; uinfo->value.integer.max = 0x7fff; return 0;}static intsnd_vortex_peaks_get(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol){ vortex_t *vortex = snd_kcontrol_chip(kcontrol); int i, count; u16 peaks[20]; vortex_Eqlzr_GetAllPeaks(vortex, peaks, &count); if (count != 20) { printk(KERN_ERR "vortex: peak count error 20 != %d \n", count); return -1; } for (i = 0; i < 20; i++) ucontrol->value.integer.value[i] = peaks[i]; return 0;}static snd_kcontrol_new_t vortex_levels_kcontrol __devinitdata = { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = "EQ Peaks", .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE, .info = snd_vortex_peaks_info, .get = snd_vortex_peaks_get,};/* EQ band gain labels. */static char *EqBandLabels[10] __devinitdata = { "EQ0 31Hz\0", "EQ1 63Hz\0", "EQ2 125Hz\0", "EQ3 250Hz\0", "EQ4 500Hz\0", "EQ5 1KHz\0", "EQ6 2KHz\0", "EQ7 4KHz\0", "EQ8 8KHz\0", "EQ9 16KHz\0",};/* ALSA driver entry points. Init and exit. */static int vortex_eq_init(vortex_t * vortex){ snd_kcontrol_t *kcontrol; int err, i; vortex_Eqlzr_init(vortex); if ((kcontrol = snd_ctl_new1(&vortex_eqtoggle_kcontrol, vortex)) == NULL) return -ENOMEM; kcontrol->private_value = 0; if ((err = snd_ctl_add(vortex->card, kcontrol)) < 0) return err; /* EQ gain controls */ for (i = 0; i < 10; i++) { if ((kcontrol = snd_ctl_new1(&vortex_eq_kcontrol, vortex)) == NULL) return -ENOMEM; strcpy(kcontrol->id.name, EqBandLabels[i]); kcontrol->private_value = i; if ((err = snd_ctl_add(vortex->card, kcontrol)) < 0) return err; //vortex->eqctrl[i] = kcontrol; } /* EQ band levels */ if ((kcontrol = snd_ctl_new1(&vortex_levels_kcontrol, vortex)) == NULL) return -ENOMEM; if ((err = snd_ctl_add(vortex->card, kcontrol)) < 0) return err; return 0;}static int vortex_eq_free(vortex_t * vortex){ /* //FIXME: segfault because vortex->eqctrl[i] == 4 int i; for (i=0; i<10; i++) { if (vortex->eqctrl[i]) snd_ctl_remove(vortex->card, vortex->eqctrl[i]); } */ vortex_Eqlzr_shutdown(vortex); return 0;}/* End */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -