📄 eq.c
字号:
//5-band eq, sampling rate 192000, band 0, level 8: 0x0000200d, 0xffffc013, 0x00001fdf, 0x00001fed, //5-band eq, sampling rate 192000, band 0, level 10: 0x0000200e, 0xffffc00f, 0x00001fe2, 0x00001ff1, //5-band eq, sampling rate 192000, band 0, level 12: 0x0000200f, 0xffffc00c, 0x00001fe5, 0x00001ff5, //5-band eq, sampling rate 192000, band 1, level -12: 0x00001fca, 0xffffc090, 0x00001fa7, 0x00001f72, //5-band eq, sampling rate 192000, band 1, level -10: 0x00001fce, 0xffffc094, 0x00001fa0, 0x00001f6f, //5-band eq, sampling rate 192000, band 1, level -8: 0x00001fd2, 0xffffc09a, 0x00001f96, 0x00001f68, //5-band eq, sampling rate 192000, band 1, level -6: 0x00001fd7, 0xffffc0a6, 0x00001f85, 0x00001f5c, //5-band eq, sampling rate 192000, band 1, level -4: 0x00001fdc, 0xffffc0c2, 0x00001f64, 0x00001f40, //5-band eq, sampling rate 192000, band 1, level -2: 0x00001fe1, 0xffffc12a, 0x00001ef6, 0x00001ed8, //5-band eq, sampling rate 192000, band 1, level 2: 0x0000201e, 0xffffc0ee, 0x00001ef5, 0x00001f14, //5-band eq, sampling rate 192000, band 1, level 4: 0x00002023, 0xffffc07c, 0x00001f63, 0x00001f86, //5-band eq, sampling rate 192000, band 1, level 6: 0x00002028, 0xffffc055, 0x00001f84, 0x00001fad, //5-band eq, sampling rate 192000, band 1, level 8: 0x0000202d, 0xffffc03f, 0x00001f95, 0x00001fc3, //5-band eq, sampling rate 192000, band 1, level 10: 0x00002031, 0xffffc031, 0x00001f9f, 0x00001fd1, //5-band eq, sampling rate 192000, band 1, level 12: 0x00002034, 0xffffc027, 0x00001fa6, 0x00001fdc, //5-band eq, sampling rate 192000, band 2, level -12: 0x00001f97, 0xffffc121, 0x00001f50, 0x00001ee8, //5-band eq, sampling rate 192000, band 2, level -10: 0x00001f9d, 0xffffc128, 0x00001f43, 0x00001ee0, //5-band eq, sampling rate 192000, band 2, level -8: 0x00001fa5, 0xffffc135, 0x00001f2e, 0x00001ed4, //5-band eq, sampling rate 192000, band 2, level -6: 0x00001faf, 0xffffc14d, 0x00001f0c, 0x00001ebc, //5-band eq, sampling rate 192000, band 2, level -4: 0x00001fba, 0xffffc183, 0x00001ecb, 0x00001e86, //5-band eq, sampling rate 192000, band 2, level -2: 0x00001fc4, 0xffffc24e, 0x00001df6, 0x00001dbb, //5-band eq, sampling rate 192000, band 2, level 2: 0x0000203b, 0xffffc1da, 0x00001df3, 0x00001e2f, //5-band eq, sampling rate 192000, band 2, level 4: 0x00002046, 0xffffc0fa, 0x00001ec9, 0x00001f0f, //5-band eq, sampling rate 192000, band 2, level 6: 0x00002051, 0xffffc0ad, 0x00001f0a, 0x00001f5b, //5-band eq, sampling rate 192000, band 2, level 8: 0x0000205a, 0xffffc082, 0x00001f2c, 0x00001f87, //5-band eq, sampling rate 192000, band 2, level 10: 0x00002062, 0xffffc065, 0x00001f40, 0x00001fa3, //5-band eq, sampling rate 192000, band 2, level 12: 0x00002069, 0xffffc051, 0x00001f4e, 0x00001fb8, //5-band eq, sampling rate 192000, band 3, level -12: 0x00001e11, 0xffffc5f1, 0x00001cc6, 0x00001ad8, //5-band eq, sampling rate 192000, band 3, level -10: 0x00001e31, 0xffffc610, 0x00001c86, 0x00001ab8, //5-band eq, sampling rate 192000, band 3, level -8: 0x00001e58, 0xffffc647, 0x00001c28, 0x00001a81, //5-band eq, sampling rate 192000, band 3, level -6: 0x00001e86, 0xffffc6ae, 0x00001b91, 0x00001a18, //5-band eq, sampling rate 192000, band 3, level -4: 0x00001ebe, 0xffffc792, 0x00001a73, 0x00001932, //5-band eq, sampling rate 192000, band 3, level -2: 0x00001ef8, 0xffffcaba, 0x00001706, 0x000015ff, //5-band eq, sampling rate 192000, band 3, level 2: 0x0000210f, 0xffffc8f5, 0x000016ba, 0x000017ca, //5-band eq, sampling rate 192000, band 3, level 4: 0x0000214e, 0xffffc544, 0x00001a39, 0x00001b87, //5-band eq, sampling rate 192000, band 3, level 6: 0x0000218a, 0xffffc3eb, 0x00001b5a, 0x00001ce5, //5-band eq, sampling rate 192000, band 3, level 8: 0x000021be, 0xffffc322, 0x00001bf3, 0x00001db1, //5-band eq, sampling rate 192000, band 3, level 10: 0x000021e9, 0xffffc29a, 0x00001c51, 0x00001e3b, //5-band eq, sampling rate 192000, band 3, level 12: 0x0000220d, 0xffffc237, 0x00001c91, 0x00001e9f, //5-band eq, sampling rate 192000, band 4, level -12: 0x00001e11, 0xffffc729, 0x00001cc6, 0x00001ad8, //5-band eq, sampling rate 192000, band 4, level -10: 0x00001e31, 0xffffc748, 0x00001c86, 0x00001ab8, //5-band eq, sampling rate 192000, band 4, level -8: 0x00001e58, 0xffffc77d, 0x00001c28, 0x00001a81, //5-band eq, sampling rate 192000, band 4, level -6: 0x00001e86, 0xffffc7e3, 0x00001b91, 0x00001a18, //5-band eq, sampling rate 192000, band 4, level -4: 0x00001ebe, 0xffffc8c1, 0x00001a73, 0x00001932, //5-band eq, sampling rate 192000, band 4, level -2: 0x00001ef8, 0xffffcbd8, 0x00001706, 0x000015ff, //5-band eq, sampling rate 192000, band 4, level 2: 0x0000210f, 0xffffca1d, 0x000016ba, 0x000017ca, //5-band eq, sampling rate 192000, band 4, level 4: 0x0000214e, 0xffffc680, 0x00001a39, 0x00001b87, //5-band eq, sampling rate 192000, band 4, level 6: 0x0000218a, 0xffffc52e, 0x00001b5a, 0x00001ce5, //5-band eq, sampling rate 192000, band 4, level 8: 0x000021be, 0xffffc469, 0x00001bf3, 0x00001db1, //5-band eq, sampling rate 192000, band 4, level 10: 0x000021e9, 0xffffc3e4, 0x00001c51, 0x00001e3b, //5-band eq, sampling rate 192000, band 4, level 12: 0x0000220d, 0xffffc384, 0x00001c91, 0x00001e9f, };int modify_3_band_eq(int *level_in_db, int sampling_rate){ int ii; if (eq_state == NULL) { eq_state = (struct eq_parameter_struct *)malloc(sizeof(struct eq_parameter_struct)); if (eq_state == NULL) return -1; eq_state->number_of_bands = 3; for (ii = 0; ii < eq_state->number_of_bands; ii++) { eq_state->prev_value[ii] = 45; /* a nonsense non-zero value to get it going the first time */ } } for (ii = 0; ii < eq_state->number_of_bands; ii++) { if (eq_state->prev_value[ii] != level_in_db[ii]) { /* even db only */ int level = level_in_db[ii] < 0 ? (level_in_db[ii]/2) + 6 : (level_in_db[ii]/2) + 5; int *coef = &filter_presets_3_bandEQ[(sampling_rate * 12 * 4 * 3) + (ii * 4 * 12) + (level * 4)]; if ((level_in_db[ii] == 0) || (level_in_db[ii] == -1) || (level_in_db[ii] == 1)) { eq_state->filter_handle_left[ii].delay1 = 0; eq_state->filter_handle_right[ii].delay1 = 0; eq_state->filter_handle_left[ii].delay2 = 0; eq_state->filter_handle_right[ii].delay2 = 0; eq_state->filter_handle_left[ii].b0 = FILT_UNITY; eq_state->filter_handle_right[ii].b0 = FILT_UNITY; eq_state->filter_handle_left[ii].b1 = 0; eq_state->filter_handle_right[ii].b1 = 0; eq_state->filter_handle_left[ii].b2 = 0; eq_state->filter_handle_right[ii].b2 = 0; eq_state->filter_handle_left[ii].a1 = 0; eq_state->filter_handle_right[ii].a1 = 0; eq_state->filter_handle_left[ii].a2 = 0; eq_state->filter_handle_right[ii].a2 = 0; } else { eq_state->filter_handle_left[ii].delay1 = 0; eq_state->filter_handle_right[ii].delay1 = 0; eq_state->filter_handle_left[ii].delay2 = 0; eq_state->filter_handle_right[ii].delay2 = 0; eq_state->filter_handle_left[ii].b0 = coef[0]; eq_state->filter_handle_right[ii].b0 = coef[0]; eq_state->filter_handle_left[ii].b1 = coef[1]; eq_state->filter_handle_right[ii].b1 = coef[1]; eq_state->filter_handle_left[ii].b2 = coef[2]; eq_state->filter_handle_right[ii].b2 = coef[2]; eq_state->filter_handle_left[ii].a1 = coef[1]; eq_state->filter_handle_right[ii].a1 = coef[1]; eq_state->filter_handle_left[ii].a2 = coef[3]; eq_state->filter_handle_right[ii].a2 = coef[3]; } DPRINTF(("[3Beq%d]: %d\n", ii, level_in_db[ii])); DPRINTF(("b0 %x, b1 %x, b2 %x, a1 %x, a2 %x\n", eq_state->filter_handle_left[ii].b0, eq_state->filter_handle_left[ii].b1, eq_state->filter_handle_left[ii].b2, eq_state->filter_handle_left[ii].a1, eq_state->filter_handle_left[ii].a2)); eq_state->prev_value[ii] = level_in_db[ii]; } } return 0;}int modify_5_band_eq(int *level_in_db, int sampling_rate){ int ii; if (eq_state == NULL) { eq_state = (struct eq_parameter_struct *)malloc(sizeof(struct eq_parameter_struct)); if (eq_state == NULL) return -1; eq_state->number_of_bands = 5; for (ii = 0; ii < eq_state->number_of_bands; ii++) { eq_state->prev_value[ii] = 45; /* a nonsense non-zero value to get it going the first time */ } } for (ii = 0; ii < eq_state->number_of_bands; ii++) { if (eq_state->prev_value[ii] != level_in_db[ii]) { /* even db only */ int level = level_in_db[ii] < 0 ? (level_in_db[ii]/2) + 6 : (level_in_db[ii]/2) + 5; int *coef = &filter_presets_5_bandEQ[(sampling_rate * 12 * 4 * 5) + (ii * 4 * 12) + (level * 4)]; if ((level_in_db[ii] == 0) || (level_in_db[ii] == -1) || (level_in_db[ii] == 1)) { eq_state->filter_handle_left[ii].delay1 = 0; eq_state->filter_handle_right[ii].delay1 = 0; eq_state->filter_handle_left[ii].delay2 = 0; eq_state->filter_handle_right[ii].delay2 = 0; eq_state->filter_handle_left[ii].b0 = FILT_UNITY; eq_state->filter_handle_right[ii].b0 = FILT_UNITY; eq_state->filter_handle_left[ii].b1 = 0; eq_state->filter_handle_right[ii].b1 = 0; eq_state->filter_handle_left[ii].b2 = 0; eq_state->filter_handle_right[ii].b2 = 0; eq_state->filter_handle_left[ii].a1 = 0; eq_state->filter_handle_right[ii].a1 = 0; eq_state->filter_handle_left[ii].a2 = 0; eq_state->filter_handle_right[ii].a2 = 0; } else { eq_state->filter_handle_left[ii].delay1 = 0; eq_state->filter_handle_right[ii].delay1 = 0; eq_state->filter_handle_left[ii].delay2 = 0; eq_state->filter_handle_right[ii].delay2 = 0; eq_state->filter_handle_left[ii].b0 = coef[0]; eq_state->filter_handle_right[ii].b0 = coef[0]; eq_state->filter_handle_left[ii].b1 = coef[1]; eq_state->filter_handle_right[ii].b1 = coef[1]; eq_state->filter_handle_left[ii].b2 = coef[2]; eq_state->filter_handle_right[ii].b2 = coef[2]; eq_state->filter_handle_left[ii].a1 = coef[1]; eq_state->filter_handle_right[ii].a1 = coef[1]; eq_state->filter_handle_left[ii].a2 = coef[3]; eq_state->filter_handle_right[ii].a2 = coef[3]; } DPRINTF(("[5Beq%d]: %d\n", ii, level_in_db[ii])); DPRINTF(("b0 %x, b1 %x, b2 %x, a1 %x, a2 %x\n", eq_state->filter_handle_left[ii].b0, eq_state->filter_handle_left[ii].b1, eq_state->filter_handle_left[ii].b2, eq_state->filter_handle_left[ii].a1, eq_state->filter_handle_left[ii].a2)); eq_state->prev_value[ii] = level_in_db[ii]; } } return 0;}/* Shift right 13 to match the preload in the filter coefficients when FILT_UNITY is 0x2000 *//* Integer version of Transposed Direct Form II */#define do_process_filter(pFilter, in) {\ int input = (int)in;\ if (pFilter.b0 != FILT_UNITY)\ {\ int output = (pFilter.delay1 + (input * pFilter.b0)) >> 13; \ pFilter.delay1 = pFilter.delay2 + (input * pFilter.b1) - (output * pFilter.a1);\ pFilter.delay2 = (input * pFilter.b2) - (output * pFilter.a2);\ in = (short)saturate16(output);\ }\}void multi_band_eq(short *stereo_stream, int length) /* assumes stereo 16-bit Left/Right */{ int ii, jj; if (eq_state == NULL) return; for (jj = 0; jj < length; jj+=2) { for (ii = 0; ii < eq_state->number_of_bands; ii++) { do_process_filter(eq_state->filter_handle_left[ii], stereo_stream[jj]); do_process_filter(eq_state->filter_handle_right[ii], stereo_stream[jj+1]); } }}void close_multi_band_eq(void){ if (eq_state != NULL) free(eq_state); eq_state = NULL;}#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -