pop noise fix

This commit is contained in:
Steven Dan
2026-03-26 17:17:41 +08:00
parent b7e21b5fc7
commit 5d6cd95ed9

View File

@@ -470,7 +470,7 @@ void button_task(chanend c_hidSendData, chanend cc_mic_level, chanend c_uac_vol,
} }
} }
debug_printf("HTR3236 LED driver wake success 9\n"); debug_printf("HTR3236 LED driver wake success 9\n");
// 设置PWM频率为22kHz (避免可闻噪声) // 设置PWM频率为22kHz (避免可闻噪声)
//htr3236_set_frequency(i2c, HTR3236_FREQ_22KHZ); //htr3236_set_frequency(i2c, HTR3236_FREQ_22KHZ);
unsafe unsafe
@@ -481,7 +481,7 @@ void button_task(chanend c_hidSendData, chanend cc_mic_level, chanend c_uac_vol,
} }
} }
debug_printf("HTR3236 set frequency success 9\n"); debug_printf("HTR3236 set frequency success 9\n");
// 初始化LED控制 // 初始化LED控制
unsafe{led_control_init(&led_ctx, &htr3236_dev, (client interface i2c_master_if)i_i2c_client);} unsafe{led_control_init(&led_ctx, &htr3236_dev, (client interface i2c_master_if)i_i2c_client);}
@@ -804,7 +804,7 @@ void button_task(chanend c_hidSendData, chanend cc_mic_level, chanend c_uac_vol,
p_button_music_mode :> button_music_mode; // 1A p_button_music_mode :> button_music_mode; // 1A
p_button_game_mode :> button_game_mode; // 1L p_button_game_mode :> button_game_mode; // 1L
p_button_ai71_onoff :> button_ai71_onoff; // 1M p_button_ai71_onoff :> button_ai71_onoff; // 1M
p_mic_gain_encoder1 :> mic_encoder1; // 4F2 p_mic_gain_encoder1 :> mic_encoder1; // 4F2
p_mic_gain_encoder2 :> mic_encoder2; // 4E2 p_mic_gain_encoder2 :> mic_encoder2; // 4E2
@@ -1095,8 +1095,8 @@ void button_task(chanend c_hidSendData, chanend cc_mic_level, chanend c_uac_vol,
led_on(&led_ctx, led_l_physical_map[i]); led_on(&led_ctx, led_l_physical_map[i]);
} }
} }
// mic_gain = 0; // mic_gain = 0;
@@ -1125,14 +1125,14 @@ void button_task(chanend c_hidSendData, chanend cc_mic_level, chanend c_uac_vol,
uint8_t rotating = (mic_encoder2 & 0b0100) == 0; // 4E2 uint8_t rotating = (mic_encoder2 & 0b0100) == 0; // 4E2
uint8_t encode_input1 = ((mic_encoder1 & 0b0100) != 0); // 4F2 uint8_t encode_input1 = ((mic_encoder1 & 0b0100) != 0); // 4F2
if(rotating) { if(rotating) {
if(!rotation_active) { if(!rotation_active) {
// 旋转开始 // 旋转开始
prev_encode_input1 = encode_input1; prev_encode_input1 = encode_input1;
sample_count = 1; sample_count = 1;
rotation_active = 1; rotation_active = 1;
// 根据上次方向预判 // 根据上次方向预判
if(fast_rotation_mode) { if(fast_rotation_mode) {
// 快速模式只需要2次采样 // 快速模式只需要2次采样
@@ -1140,14 +1140,14 @@ void button_task(chanend c_hidSendData, chanend cc_mic_level, chanend c_uac_vol,
} }
} else { } else {
sample_count++; sample_count++;
// 动态调整采样次数快速模式用2次普通模式用3次 // 动态调整采样次数快速模式用2次普通模式用3次
uint8_t required_samples = fast_rotation_mode ? 2 : 3; uint8_t required_samples = fast_rotation_mode ? 2 : 3;
if(sample_count >= required_samples) { if(sample_count >= required_samples) {
if(encode_input1 != prev_encode_input1) { if(encode_input1 != prev_encode_input1) {
uint8_t current_dir = encode_input1 ? 1 : 2; uint8_t current_dir = encode_input1 ? 1 : 2;
// 执行音量调节 // 执行音量调节
if(current_dir == 1) { // 顺时针 if(current_dir == 1) { // 顺时针
if((codec_adc_pga_gain_reg_value < NAU88L21_PGA_GAIN_REG_MAX_VALUE) && (flag_mic_mute == 0)) { if((codec_adc_pga_gain_reg_value < NAU88L21_PGA_GAIN_REG_MAX_VALUE) && (flag_mic_mute == 0)) {
@@ -1176,9 +1176,9 @@ void button_task(chanend c_hidSendData, chanend cc_mic_level, chanend c_uac_vol,
g_mic_volume_level = (codec_adc_pga_gain_reg_value <= 37) ? codec_adc_pga_gain_reg_value : 37; g_mic_volume_level = (codec_adc_pga_gain_reg_value <= 37) ? codec_adc_pga_gain_reg_value : 37;
debug_printf("volume down %d\n", codec_adc_pga_gain_reg_value); debug_printf("volume down %d\n", codec_adc_pga_gain_reg_value);
save_value(mic_vol_path, codec_adc_pga_gain_reg_value); save_value(mic_vol_path, codec_adc_pga_gain_reg_value);
uint8_t new_led_count = mic_gain_to_led[codec_adc_pga_gain_reg_value]; uint8_t new_led_count = mic_gain_to_led[codec_adc_pga_gain_reg_value];
// 如果LED数减少关闭减少的那个LED // 如果LED数减少关闭减少的那个LED
if(new_led_count < old_led_count) { if(new_led_count < old_led_count) {
// 关闭的LED索引 = old_led_count - 1 // 关闭的LED索引 = old_led_count - 1
@@ -1187,7 +1187,7 @@ void button_task(chanend c_hidSendData, chanend cc_mic_level, chanend c_uac_vol,
} }
} }
} }
// 检测是否快速旋转 // 检测是否快速旋转
if(current_dir == last_valid_direction) { if(current_dir == last_valid_direction) {
consecutive_same_dir++; consecutive_same_dir++;
@@ -1198,7 +1198,7 @@ void button_task(chanend c_hidSendData, chanend cc_mic_level, chanend c_uac_vol,
consecutive_same_dir = 0; consecutive_same_dir = 0;
fast_rotation_mode = 0; // 方向变化,退出快速模式 fast_rotation_mode = 0; // 方向变化,退出快速模式
} }
last_valid_direction = current_dir; last_valid_direction = current_dir;
rotation_active = 0; rotation_active = 0;
sample_count = 0; sample_count = 0;
@@ -1224,14 +1224,14 @@ void button_task(chanend c_hidSendData, chanend cc_mic_level, chanend c_uac_vol,
uint8_t hp_rotating = ((hp_encoder & 0b00100000) == 0); // 8D5 uint8_t hp_rotating = ((hp_encoder & 0b00100000) == 0); // 8D5
uint8_t hp_encode_input1 = ((hp_encoder & 0b00010000) != 0); // 8D4 uint8_t hp_encode_input1 = ((hp_encoder & 0b00010000) != 0); // 8D4
if(hp_rotating) { if(hp_rotating) {
if(!hp_rotation_active) { if(!hp_rotation_active) {
// 旋转开始 // 旋转开始
hp_prev_encode_input1 = hp_encode_input1; hp_prev_encode_input1 = hp_encode_input1;
hp_sample_count = 1; hp_sample_count = 1;
hp_rotation_active = 1; hp_rotation_active = 1;
// 根据上次方向预判 // 根据上次方向预判
if(hp_fast_rotation_mode) { if(hp_fast_rotation_mode) {
// 快速模式只需要2次采样 // 快速模式只需要2次采样
@@ -1239,14 +1239,14 @@ void button_task(chanend c_hidSendData, chanend cc_mic_level, chanend c_uac_vol,
} }
} else { } else {
hp_sample_count++; hp_sample_count++;
// 动态调整采样次数快速模式用2次普通模式用3次 // 动态调整采样次数快速模式用2次普通模式用3次
uint8_t hp_required_samples = hp_fast_rotation_mode ? 2 : 3; uint8_t hp_required_samples = hp_fast_rotation_mode ? 2 : 3;
if(hp_sample_count >= hp_required_samples) { if(hp_sample_count >= hp_required_samples) {
if(hp_encode_input1 != hp_prev_encode_input1) { if(hp_encode_input1 != hp_prev_encode_input1) {
uint8_t hp_current_dir = hp_encode_input1 ? 1 : 2; uint8_t hp_current_dir = hp_encode_input1 ? 1 : 2;
// 执行音量调节 // 执行音量调节
if(hp_current_dir == 1) { // 顺时针 if(hp_current_dir == 1) { // 顺时针
if(dac_level < DAC_LEVEL_MAX && flag_hp_mute == 0) { if(dac_level < DAC_LEVEL_MAX && flag_hp_mute == 0) {
@@ -1290,7 +1290,7 @@ void button_task(chanend c_hidSendData, chanend cc_mic_level, chanend c_uac_vol,
} }
} }
} }
// 检测是否快速旋转 // 检测是否快速旋转
if(hp_current_dir == hp_last_valid_direction) { if(hp_current_dir == hp_last_valid_direction) {
hp_consecutive_same_dir++; hp_consecutive_same_dir++;
@@ -1301,7 +1301,7 @@ void button_task(chanend c_hidSendData, chanend cc_mic_level, chanend c_uac_vol,
hp_consecutive_same_dir = 0; hp_consecutive_same_dir = 0;
hp_fast_rotation_mode = 0; // 方向变化,退出快速模式 hp_fast_rotation_mode = 0; // 方向变化,退出快速模式
} }
hp_last_valid_direction = hp_current_dir; hp_last_valid_direction = hp_current_dir;
hp_rotation_active = 0; hp_rotation_active = 0;
hp_sample_count = 0; hp_sample_count = 0;
@@ -1617,13 +1617,22 @@ void AudioHwInit()
/* Configures the external audio hardware for the required sample frequency */ /* Configures the external audio hardware for the required sample frequency */
void AudioHwConfig(unsigned samFreq, unsigned mClk, unsigned dsdMode, unsigned sampRes_DAC, unsigned sampRes_ADC) void AudioHwConfig(unsigned samFreq, unsigned mClk, unsigned dsdMode, unsigned sampRes_DAC, unsigned sampRes_ADC)
{ {
static unsigned count = 0;
g_samfreq = samFreq; g_samfreq = samFreq;
{ {
sw_pll_fixed_clock(mClk); sw_pll_fixed_clock(mClk);
} }
p_ctl_mute <: 1;
// 通知tile0 (button_task) 采样率已变化用于配置NAU88C22寄存器 // 通知tile0 (button_task) 采样率已变化用于配置NAU88C22寄存器
unsafe {uc_audiohw <: samFreq; } unsafe {uc_audiohw <: samFreq; }
unsafe {uc_audiohw <: dsdMode; } unsafe {uc_audiohw <: dsdMode; }
}
if (count++ > 0)
{
p_ctl_mute <: 1;
}
else
{
debug_printf("don't unmute at boot\n");
}
}