sample rate report

This commit is contained in:
Steven Dan
2026-03-26 15:51:33 +08:00
parent 80d3dda19d
commit 8a1af892aa
5 changed files with 112 additions and 7 deletions

View File

@@ -138,7 +138,7 @@ set(APP_COMPILER_FLAGS_fact ${SW_USB_FACT_FLAGS} -DI2S_CHANS_DAC=2
set(APP_COMPILER_FLAGS_f1_music_uac2 ${SW_USB_AUDIO_FLAGS} -DI2S_CHANS_DAC=2
-DI2S_CHANS_ADC=2
-DMIN_FREQ=48000
-DMIN_FREQ=44100
-DMAX_FREQ=192000
-DF1_MUSIC_UAC2=1
#-DUSE_EX3D

View File

@@ -110,12 +110,20 @@
/*** Defines relating to audio frequencies ***/
/* Master clock defines (in Hz) */
#ifndef MCLK_441
#define MCLK_441 (256*44100) /* 44.1, 88.2 etc */
#if defined(F1_MUSIC_UAC2)
#define MCLK_441 (1024*44100) /* 44.1, 88.2 etc */
#else
#define MCLK_441 (256*48000) /* 44.1, 88.2 etc */
#endif
#endif
#ifndef MCLK_48
#if defined(F1_MUSIC_UAC2)
#define MCLK_48 (1024*48000) /* 48, 96 etc */
#else
#define MCLK_48 (256*48000) /* 48, 96 etc */
#endif
#endif
/* Minumum sample frequency device runs at */
#ifndef MIN_FREQ

View File

@@ -103,6 +103,7 @@ unsigned g_disable_i2c = 0;
unsigned g_dac_mode = 10;
unsigned g_new_dac_mode = 0;
unsigned g_samfreq = 48000;
unsafe chanend uc_audiohw; // tile[1] end: AudioHwConfig → button_task (tile[0])
// 改动原因添加DSD模式全局变量用于HID命令读取采样率和格式信息已去掉DAC采样分辨率
unsigned g_dsd_mode = 0; // DSD模式0=PCM, >0=DSD
unsigned g_gain_mode = 0; // 0: 低阻, 1: 高阻
@@ -295,7 +296,7 @@ enum {IR_OFF=0, IR_GAME=1, IR_MUSIC=2, IR_MOVIE=3, IR_7_1_GAME=4, IR_7_1_MUSIC=5
#endif
unsigned hidSendData_local[HID_MAX_DATA_BYTES / 4];
void button_task(chanend c_hidSendData, chanend cc_mic_level, chanend c_uac_vol)
void button_task(chanend c_hidSendData, chanend cc_mic_level, chanend c_uac_vol, chanend c_audiohw_rx)
{
//hwtimer_t timer = hwtimer_alloc();
unsigned time = 0;
@@ -735,6 +736,51 @@ void button_task(chanend c_hidSendData, chanend cc_mic_level, chanend c_uac_vol)
break;
}
case c_audiohw_rx :> unsigned new_samfreq:
{
// 采样率变化通知来自AudioHwConfig (tile[1])通过uc_audiohw专用通道传递
unsigned new_dsd_mode;
c_audiohw_rx :> new_dsd_mode;
debug_printf("SampRate->tile0: %uHz dsd=%u\n", new_samfreq, new_dsd_mode);
switch (new_samfreq) {
case 192000:
case 176400:
unsafe { NAU88C22_REGWRITE(0x0003, 0x00D0, (client interface i2c_master_if)i_i2c_client); }
unsafe { NAU88C22_REGWRITE(0x002B, 0x4000, (client interface i2c_master_if)i_i2c_client); }
unsafe { NAU88C22_REGWRITE(0x002C, 0x0082, (client interface i2c_master_if)i_i2c_client); }
break;
case 96000:
case 88200:
unsafe { NAU88C22_REGWRITE(0x0003, 0x0092, (client interface i2c_master_if)i_i2c_client); }
unsafe { NAU88C22_REGWRITE(0x002B, 0x4001, (client interface i2c_master_if)i_i2c_client); }
unsafe { NAU88C22_REGWRITE(0x002C, 0x0082, (client interface i2c_master_if)i_i2c_client); }
break;
case 44100:
case 48000:
default:
unsafe { NAU88C22_REGWRITE(0x0003, 0x0053, (client interface i2c_master_if)i_i2c_client); }
unsafe { NAU88C22_REGWRITE(0x002B, 0x4002, (client interface i2c_master_if)i_i2c_client); }
unsafe { NAU88C22_REGWRITE(0x002C, 0x0082, (client interface i2c_master_if)i_i2c_client); }
break;
}
#if HID_CONTROLS > 0
g_hid_status_report_data[0] = 0x77;
g_hid_status_report_data[1] = 0x9F;
g_hid_status_report_data[2] = (unsigned char)(new_samfreq & 0xFF);
g_hid_status_report_data[3] = (unsigned char)((new_samfreq >> 8) & 0xFF);
g_hid_status_report_data[4] = (unsigned char)((new_samfreq >> 16) & 0xFF);
g_hid_status_report_data[5] = (unsigned char)((new_samfreq >> 24) & 0xFF);
g_hid_status_report_data[6] = (unsigned char)new_dsd_mode;
for (int i = 7; i < 63; i++)
g_hid_status_report_data[i] = 0x00;
g_hid_status_report_index = 63;
hidSetChangePending(0x1);
#endif
break;
}
case tmr when timerafter(time) :> void :
{
//hwtimer_change_trigger_time(timer, hwtimer_get_time(timer) + KEY_POLLING_INTERVAL);
@@ -1540,7 +1586,7 @@ void button_task(chanend c_hidSendData, chanend cc_mic_level, chanend c_uac_vol)
}
}
void AudioHwRemote(chanend c_hidSendData, chanend cc_mic_level, chanend c_uac_vol)
void AudioHwRemote(chanend c_hidSendData, chanend cc_mic_level, chanend c_uac_vol, chanend c_audiohw_rx)
{
i2c_master_if i2c[1];
board_setup();
@@ -1548,7 +1594,7 @@ void AudioHwRemote(chanend c_hidSendData, chanend cc_mic_level, chanend c_uac_vo
i2c_master(i2c, 1, p_scl, p_sda, 300);
{
unsafe {i_i2c_client = i2c[0];}
button_task(c_hidSendData, cc_mic_level, c_uac_vol);
button_task(c_hidSendData, cc_mic_level, c_uac_vol, c_audiohw_rx);
}
}
}
@@ -1576,5 +1622,8 @@ void AudioHwConfig(unsigned samFreq, unsigned mClk, unsigned dsdMode, unsigned s
sw_pll_fixed_clock(mClk);
}
p_ctl_mute <: 1;
// 通知tile0 (button_task) 采样率已变化用于配置NAU88C22寄存器
unsafe {uc_audiohw <: samFreq; }
unsafe {uc_audiohw <: dsdMode; }
}

View File

@@ -406,6 +406,10 @@ class EQDesigner(QMainWindow):
self.total_bshift = 0 # 初始化total_bshift为0
self.log_level = LOG_LEVEL_VERBOSE # 设置默认日志级别
# HID通知轮询定时器接收设备主动上报的0x9F采样率变化等通知
self._notification_timer = QTimer(self)
self._notification_timer.timeout.connect(self._poll_hid_notification)
# 创建菜单栏
# 改动原因:添加菜单栏,包含视图菜单用于隐藏/显示左侧面板的各组
self.create_menu_bar()
@@ -644,6 +648,10 @@ class EQDesigner(QMainWindow):
self.get_sample_format_btn.clicked.connect(self.on_get_sample_format)
volume_layout.addRow(self.get_sample_format_btn)
# 采样率状态显示自动从设备主动上报的0x9F通知更新
self.sample_format_status_label = QLabel("当前采样率: 未知")
volume_layout.addRow("采样率状态(0x9F):", self.sample_format_status_label)
left_content_layout.addWidget(volume_group)
# 添加音效模式控制组
@@ -1640,6 +1648,8 @@ eq_mode_data_t sEQ_data_{int(fs)}HZ[NUM_EQ_MODES][NUM_EQ_CHANS] = {{
self.on_get_mode()
self.read_parameters()
log_message(LOG_LEVEL_DEBUG, f"找到设备: {info}", self.log_level)
# 启动HID通知轮询接收设备主动上报0x9F采样率变化等
self._notification_timer.start(200)
def on_debug_changed(self, state):
"""当调试开关状态改变时更新所有滤波器"""
@@ -2453,6 +2463,7 @@ eq_mode_data_t sEQ_data_{int(fs)}HZ[NUM_EQ_MODES][NUM_EQ_CHANS] = {{
log_message(LOG_LEVEL_INFO,
f"采样率和格式信息: 采样率={samfreq}Hz, 格式={format_type}",
self.log_level)
self._update_sample_format_status(samfreq, dsd_mode)
QMessageBox.information(
self,
"采样率和格式信息",
@@ -2470,6 +2481,41 @@ eq_mode_data_t sEQ_data_{int(fs)}HZ[NUM_EQ_MODES][NUM_EQ_CHANS] = {{
except Exception as e:
log_message(LOG_LEVEL_ERROR, f"读取采样率和格式时出错: {str(e)}", self.log_level)
def _update_sample_format_status(self, samfreq, dsd_mode):
"""更新采样率状态标签并同步EQ采样率下拉框"""
format_type = "PCM" if dsd_mode == 0 else f"DSD (模式 {dsd_mode})"
self.sample_format_status_label.setText(f"{samfreq} Hz {format_type}")
# 同步EQ计算用采样率下拉框
idx = self.sample_rate.findText(str(samfreq))
if idx >= 0:
self.sample_rate.blockSignals(True)
self.sample_rate.setCurrentIndex(idx)
self.sample_rate.blockSignals(False)
def _poll_hid_notification(self):
"""轮询HID输入报告处理设备主动上报的0x9F采样率变化通知"""
if self.device_combo.currentData() is None:
return
try:
device_info = self.device_combo.currentData()
h = hid.device()
h.open(device_info['vendor_id'], device_info['product_id'])
h.set_nonblocking(1)
data = h.read(64)
h.close()
if data and len(data) >= 8:
# 0x9F: 采样率变化主动上报 [Report_ID=0x01, 0x77, 0x9F, samfreq(4B LE), dsd_mode]
if data[0] == 0x01 and data[1] == 0x77 and data[2] == 0x9F:
samfreq = data[3] | (data[4] << 8) | (data[5] << 16) | (data[6] << 24)
dsd_mode = data[7]
self._update_sample_format_status(samfreq, dsd_mode)
log_message(LOG_LEVEL_INFO,
f"[0x9F通知] 采样率变化: {samfreq} Hz, "
f"{'PCM' if dsd_mode == 0 else f'DSD({dsd_mode})'}",
self.log_level)
except Exception:
pass
def on_get_led_info(self):
"""获取LED信息发送0x95命令"""
if self.device_combo.currentData() is None:

View File

@@ -431,7 +431,7 @@ extern int dsp_worker_tile(chanend c_dsp_to_ex3d, int worker_id);
//extern int dsp_worker_tile_1(chanend c_dsp_to_ex3d, int worker_id);
extern void ex3d_task();
extern void hid_button_task(chanend cc_mic_level, chanend c_hid, chanend c_hidSendData, chanend c_uac_vol, chanend c_ex3d_hid_cmd);
extern void AudioHwRemote(chanend c_hidSendData, chanend cc_mic_level, chanend c_uac_vol);
extern void AudioHwRemote(chanend c_hidSendData, chanend cc_mic_level, chanend c_uac_vol, chanend c_audiohw_rx);
extern void dnr_dsp_proc_task(void);
extern unsafe chanend uc_dsp_to_ex3d[DSP_WORKER_COUNT];
@@ -534,6 +534,7 @@ int main()
chan c_dsp_to_ex3d[DSP_WORKER_COUNT];
chan cc_mic_level;
chan c_audiohw;
chan c_key; chan c_hidSendData;
chan c_hidRcvData;
chan c_eq_data;
@@ -546,6 +547,7 @@ int main()
on tile[1] : {
par {
unsafe {
uc_audiohw = (chanend)c_audiohw;
hid_button_task(cc_mic_level, c_hidRcvData, c_hidSendData, c_uac_vol, c_ex3d_hid_cmd);
}
#if USE_EX3D == 1
@@ -570,7 +572,7 @@ int main()
#if USE_EX3D == 1
unsafe { key_receiver(c_key); }
#endif
AudioHwRemote(c_hidSendData, cc_mic_level, c_uac_vol);
AudioHwRemote(c_hidSendData, cc_mic_level, c_uac_vol, c_audiohw);
}
}
}