DELAY_APPLY 配置参数

本文介绍了如何使用DELAY_APPLY配置参数来控制RS辅助服务器应用日志前的等待时间。通过设置此参数,可以实现错误数据库修改的快速恢复,并强调了LOG_STAGING_DIR配置的重要性。

使用 DELAY_APPLY 配置参数来配置 RS 辅助服务器应用日志之前等待指定的时间期 间。 onconfig.std 值

DELAY_APPLY 0

缺省值

0

0 = 应用日志

后跟时间单位的整数:

例如,1H 设置延迟一个小时。

number: 1-999 = 等待的天数、分钟数、小时数或秒数。

time_unit: D、H、M或S,此处 D = 天,H = 小时,M = 分钟,S = 秒。 这些值不区分大 小写。 生效

编辑 onconfig 文件并重启数据库服务器后。

当您通过运行 onmode -wf 命令在 onconfig 文件中动态地重置该值时。

当您通过运行 onmode -wm 命令重置内存中的该值时。

用法

延迟日志文件的应用允许您通过从 RS 辅助服务器恢复数据来快速恢复错误的数据库修 改。当设置 DELAY_APPLY 的值时,您必须还要设置 LOG_STAGING_DIR。如果配置 DELAY_APPLY 而未将 LOG_STAGING_DIR 设置为一个有效且安全的目录,则服务器不 可初始化。

您必须通过设置 LOG_STAGING_DIR 配置参数来指定一个日志文件的有效并安全位置。 在 RS 辅助服务器上处理完最后的检查点之后,清除 GBase 8s staging 目录中的日志。 要看到有关发送到为 RS 辅助服务器设置的 GBase 8s log-staging 目录的数据信息,请在 RS 辅助服务器上运行 onstat -g rss verbose 命令。

如果写 GBase 8s staging 文件失败,则 RS 辅助服务器发出事件报警 40007。 如果远程独立辅助(RSS)服务器的 DELAY_APPLY 配置参数设置为一个非 0 的值,则 服务器不可用集群事务协调。

profile=pro server.port=8090 db.datasource.url=jdbc:mysql://192.168.143.33:3306/uat_buscenter?allowMultiQueries=true&zeroDateTimeBehavior=convertToNull&userUnicode=true&characterEncoding=utf8&autoReconnect=true&useSSL=false&serverTimezone=Asia/Shanghai db.datasource.username=uat-u-buscenter db.datasource.password=uat-u-buscenter20230822 #redis db.redis.hostName=wte427f5-6379.zwha46ju-yanshihuanjing db.redis.port=6379 db.redis.database=1 db.redis.password= #ldap ldap.base=dc=talkweb ldap.url=ldap://139.9.208.102:489 ldap.userDn=cn=root,dc=talkweb ldap.password=Talkweb#Ldap2021 #邮箱后缀 MAIL_SUFFIX=@talkweb.com.cn MAIL_SEND_PASSWORD=N TEST_MAIL_SEND_PASSWORD=N #消息发送MQ接口地址 MQ_SEND_ADDRESS=http://9098.wt4899a8.zwha46ju.dev-paas.talkweb.com.cn/it-mqserver/mq/api/send ORG_PRODUCER_ID=2wXcxbJe USER_PRODUCER_ID=6OSrIWFl LEGAL_PRODUCER_ID=YZHZtAp3 ROLE_PRODUCER_ID=8y9snlkS mail.user.queue.id=780cc04c082841398a677968a0cf8bf0 it.fs.root=/uploadfile/files wpsapi.url=http://10.1.1.49:28091/ com.it.log.level=info SWAGGER_ROOT=com.it.businesscenter.server api.key=wx69c288447345e7ae ###单点登陆 api.login.secret=v-qdNjWQir3rAflnZ_bilfaTdwz41h_jxAUuE1k4AekWfqKHCYlXJ1WT9uMqRRpZ ###新邮件提醒 api.unread_statis.secret=zEFGujT_djbtWyngBGW3wYJZZjW4r_Oinzj1EFQIGh-R4XqZe2JLUSg0543uS69I ##通讯录 api.messagebox.secret=BsIrET7jXbhx5RAYtzYFmHAauSZ0fmd1pIiJPCPo6Qf2GTGdPxiwPuo5gbvQ8zZ4 logging.path=/usr/local/talkyun/buscenter/server/logs push.eas=Y MY_PRI_KEY_FILE_PATH=/usr/local/talkyun/buscenter/server/myprikey.txt xjkp.webservice.sysSynchroSetOrgWebService=http://oa.hnxjkp.com/sys/webservice/sysSynchroSetOrgWebService?wsdl xjkp.webservice.sysSynchroGetOrgWebService=http://oa.hnxjkp.com/sys/webservice/sysSynchroGetOrgWebService?wsdl xjkp.webservice.user=chencheng xjkp.webservice.password=Hnxjkp2020 push.xjkp=N hik.push=Y ribbon.enabled=true ribbon.ReadTimeout=3000000 ribbon.ConnectTimeout=20000 todo.mobile.processkeys=EXPENSE_QUOTA,EXPENSE_PURCHASE_PAYMENT,EXPENSE_LOAN,EXPENSE_COMPREHENSIVE,EXPENSE_HOSPITALITY,EXPENSE_TRAVEL,CRM_CONTRACT_BILLING,CRM_LEND_DELAY,CRM_SO_APPLY,SALES_INVOICE_APPLY,SALES_CONTRACT_CREATION,SALES_CONTRACT_CHANGE,SALES_CONTRACT_ARCHIVE,CONTROL_TRAVEL_APPLY,27e19aa80cf49041730b676062abf6a0be04,fbc2d2500bc2d04c1c0900e0060e89f6ea60,CRM_BORROW_GOODS,CRM_RETURN_GOODS,CRM_BUSINESS_BARGAIN,CRM_BUSINESS_SUBMIT,CRM_BOM_APPLY,CRM_MATERIEL_BUDGET,CRM_BUSINESS_PROJECT,CRM_PRICE_SHEET,CRM_SALES_CONTRACT,CRM_CONTRACT_FILING,CRM_CUSTOMER_AUTHENTICATION,CRM_CONTRACT_MODIFY,BMS_NICHE_APPLY,BMS_NICHE_CHANGE,BMS_NICHE_BUILD_PROJECT,BMS_NICHE_PROJECT_CHANGE,BMS_NICHE_PROJECT_CLOSE,NICHE_PROJECT_MANAGER_CHANGE,NICHE_PROJECT_TIME_CHANGE,BMS_BIZCASE_APPLY,BMS_BIZCASE_CHAGE,BMS_GENERAL_CONTRACT,BMS_OTHER_CONTRACT,BMS_OTHER_SALE_CONTRACT,BMS_COMMON_CONTRACT,BMS_CONTRACT_INVOICE,BMS_CONTRACT_SCREEN,Process_PMS_DRA,Process_PMS_DRB,Process_PMS_DR1,Process_PMS_DR2,Process_PMS_DR3,Process_PMS_DR4,PMS_PROJECT_MilePost_Close,PROJECT_MANAGER_CHANGE,PROJECT_TIME_CHANGE,EXPECT_CONTRACT_SIGN_TIME_CHANGE,PMS_CreatDeliverProject,PMS_DELIVER_PROJECT_CHANGE,PMS_DELIVER_PROJECT_CLOSE,PMS_RD_PROJECT,PMS_RD_PROJECT_CHANGE,PMS_AFFAIRS_PROJECT,PMS_AFFAIRS_PROJECT_CHANGE,PMS_RD_PROJECT_CLOSE,PMS_PROJECT_PLAN,PMS_PROJECT_SCHEME_CHANGE,travel_reimbursement,entertain_reimbursement,synthesize_reimbursement,quota_reimbursement,process_travel_apply,process_entertain_apply,borrowing_apply,repayment_apply,payment_notice,meal-ticket-apply,ADMIN_SEAL_AFFIX_APPLY,ADMIN_SEAL_BORROW_APPLY,asset_apply,asset_entry,ADMIN_VEHICLE_USE_APPLY,admin_vehicle_borrow_apply,ADMIN_EXHIBITION_HALL_APPLY,Process_WOS_WOH,LEAVE_APPLY_NEW,UNUSUAL_APPLY_NEW,WORK_ORVER_new,TRAVEL_APPLY_NEW,OFFICIAL_new,process_hr_leave_office,process_hr_leave_offiec_join,process_hr_dept_transfer_2023,SRM_GPC_DM,financial_travel_apply,1280ba10-81a0-11ed-9945-9d0a59b1654f,06809a20-142c-11eb-82e4-cf3436e1a0ad,7f26f4810f765048130a9e30b6cccf845783,ca4a387e0aa78048be08abd05a84abffa34e,b61015fd0fbe604b730812d0d01a268e8f83,6f4fcd7d0142104d390963008ff917f510e2,ca9cf7990ff1e046810986e0d1a8ab6d823f,5e0bafb0-2259-11eb-ae88-d7beee1f9730,cd755cf607f5204d3b086e50ff1e6b093859,b52f5e300884404f550badf052d182c7302b,552600d0-9ed5-11ed-9506-736ba961e6df,8ac84d90-9edc-11ed-80ae-e72f110c1c4a,335d1c80-9edb-11ed-bbd8-8524eb7ba3fd,1b978b550305a046b609ec5070027a513b52,cd669a06004540411e09b57057ef1a305463,daf6c4620cc1904bd70a7e3073dfe5c7f22b,681fad3b04e670466b0b92c0c7d46e2b2697,749daeb80958904abb0aaa9054ee4f4cc65c,7901fdc0-1f6e-11ec-8573-fdeb426fe613,ADMINS_GUESTROOM_APPLY,0b9a4110-4a37-11ef-8f39-774ab9970b95,SALES_CUSTOMER_HANDOVER,SALES_CUSTOMER_CLAIM,SALES_CUSTOMER_BLACKLIST,SALES_CUSTOMER_AUTHENTICATION,SALES_CHANNEL_CONSULT,SALES_CHANNEL_AUTHENTICATION,SALES_CHANNEL_HANDOVER,CRM_IOU_HANDOVER,CRM_CONTRACT_HANDOVER,CRM_CLOSE_BUSINESS,EHR_PERSONNEL_TRANSFER,EHR_YC_DIMISSION_HANDOVER_PROCESS,EHR_DIMISSION_HANDOVER_PROCESS,EHR_DIMISSION_APPLY_PROCESS,EHR_TRIAL_PERIOD_GOAL_SET,EHR_TRIAL_PERIOD_PROCESS_APPRAISAL,EHR_TRIAL_PERIOD_FORMAL_APPRAISAL,EHR_YC_TRIAL_PERIOD_FORMAL_APPRAISAL,4440f520-795a-11ef-81a5-85cac0a065df
06-20
DEFAULT_REWARD_HYPERPARAMS = { # 1. 奖励组件权重(含事故场景自适应调整) "weight": { "peak": { # 高峰时段:优先降低延误与等待 "delay_wait": 0.45, "queue": 0.15, "approach": 0.15, "travel": 0.15, "coordination": 0.10 # 区域协同权重(高峰保持原设计) }, "non_peak": { # 非高峰时段:提升协同与通行权重 "delay_wait": 0.35, "queue": 0.15, "approach": 0.15, "travel": 0.20, "coordination": 0.20 # 【优化】非高峰协同权重从0.15→0.20 }, "accident_adjust": { # 【优化】事故时多指标放大(原单一系数→字典) "queue": 1.5, # 排队权重放大 "delay_wait": 1.2 # 延误-等待权重也放大 } }, # 2. 天气影响系数(保持原设计) "weather_impact": { 0: {"delay": 1.0, "waiting": 1.0, "queue": 1.0, "travel": 1.0, "coord": 1.0}, 1: {"delay": 1.15, "waiting": 1.1, "queue": 1.15, "travel": 0.85, "coord": 1.15}, 2: {"delay": 1.35, "waiting": 1.25, "queue": 1.35, "travel": 0.75, "coord": 1.35}, 3: {"delay": 1.5, "waiting": 1.4, "queue": 1.5, "travel": 0.65, "coord": 1.5} }, # 3. 平滑与归一化参数(保持原设计) "smoothing": { "alpha": 0.3, "ema_decay": 0.8, "sigmoid_sensitivity": 0.8 }, # 4. 通行奖励参数(保持原设计) "travel_reward": { "distance_scale": 100.0, "base_entry_reward": 5.0, "max_completed_reward": 5, "count_bonus_max": 0.3, "potential_value_coeff": 0.5 }, # 5. 拥堵判断与奖励(新增区域拥堵参数) "congestion": { "global_congest_threshold": 5.0, "approach_congest_threshold": 0.5, "queue_drop_steps": 2, "congest_relief_bonus": 0.05, "relief_rate_coeff": 0.03, "region_congest_threshold": 0.5, # 【新增】区域拥堵阈值 "region_congest_penalty_scale": 1.5 # 【新增】区域拥堵时惩罚放大系数 }, # 6. 区域协调参数(提升协同奖励权重) "coordination": { "base_penalty_weight": 0.1, "synergy_bonus_weight": 0.1 # 【优化】协同奖励权重从0.05→0.1 }, # 7. 动态基线参数(保持原设计) "base_reward": { "initial": 0.2, "decay_steps": 1000, "decay_max_ratio": 0.15 }, # 8. 日志配置(保持原设计) "log": { "print_interval": 100 }, # 9. 车型权重(保持原设计) "vehicle_type_weight": { 1: 1.0, 2: 1.5, 3: 1.2, 4: 0.8, 5: 0.5, "default": 1.0 }, # 10. 【新增】事故延误惩罚参数 "accident_delay": { "threshold": 15.0, # 事故场景下延误超阈值(秒) "penalty": 0.05 # 额外扣除的奖励 } } def calculate_travel_reward(junction_id, fp, vehicles, invalid_lanes, config): cfg = config["travel_reward"] total_distance = 0.0 total_potential_value = 0.0 valid_count = 0 completed_count = 0 rewarded_completed = set() vehicle_dict = {v["v_id"]: v for v in vehicles} current_v_ids = set(vehicle_dict.keys()) vehicle_type_weight = config["vehicle_type_weight"] junction_metrics = fp.junction_metrics.get(junction_id, {}) completed_vehicles = junction_metrics.get("completed_vehicles", set()) for v_id, distance in fp.vehicle_distance_store.items(): if v_id not in current_v_ids or v_id not in vehicle_dict: continue vehicle = vehicle_dict[v_id] if (vehicle.get("target_junction") == junction_id and (on_enter_lane(vehicle, invalid_lanes) or in_junction(vehicle)) and v_id not in completed_vehicles): if vehicle.get("lane") in invalid_lanes or fp.vehicle_status.get(v_id, 1) != 0: continue v_config_id = vehicle.get("v_config_id") if not v_config_id: weight = vehicle_type_weight["default"] else: vehicle_config = fp.vehicle_configs.get(v_config_id, {}) v_type = vehicle_config.get("v_type", "default") weight = vehicle_type_weight.get(v_type, vehicle_type_weight["default"]) total_distance += (distance / cfg["distance_scale"]) * weight valid_count += 1 position = vehicle.get("position_in_lane", {}) distance_to_stop = position.get("y", 50.0) potential_value = max(0.0, (50.0 - distance_to_stop) / 50.0) * cfg["potential_value_coeff"] total_potential_value += potential_value * weight if v_id in completed_vehicles and v_id not in rewarded_completed: if completed_count < cfg["max_completed_reward"]: total_distance += cfg["base_entry_reward"] * 2 completed_count += 1 rewarded_completed.add(v_id) total_reward_value = total_distance + total_potential_value total_count = valid_count + completed_count if total_count <= 0: return 0.1 else: avg_value = total_reward_value / total_count count_bonus = min(cfg["count_bonus_max"], total_count * 0.01) return np.tanh(avg_value + count_bonus) def reward_shaping(_obs, _extra_info, act, agent, config=None): cfg = config or DEFAULT_REWARD_HYPERPARAMS fp = agent.preprocess junction_ids = fp.get_sorted_junction_ids() rewards = {j_id: {'total': 0.0, 'components': {}} for j_id in junction_ids} frame_state = _obs.get("framestate", {}) vehicles = frame_state.get("vehicles", []) fp.update_traffic_info(_obs, _extra_info) all_junction_waiting = fp.get_all_junction_waiting_time(vehicles) if vehicles else {} invalid_lanes = fp.get_invalid_lanes() global_avg_queue = fp.get_all_avg_queue() is_global_congested = global_avg_queue > cfg["congestion"]["global_congest_threshold"] weather = fp.get_weather() weather_map = {0: "晴", 1: "雨", 2: "雪", 3: "雾"} weather_name = weather_map.get(weather, "未知") weather_factors = cfg["weather_impact"].get(weather, cfg["weather_impact"][0]) is_peak = fp.is_peak_hour() weight_key = "peak" if is_peak else "non_peak" if not hasattr(agent, 'prev_metrics'): agent.prev_metrics = {} for j_id in junction_ids: capacity = fp.get_junction_capacity(j_id) agent.prev_metrics[j_id] = { "avg_delay_wait": 8.0 + capacity * 0.015, "avg_queue": 2.0 + capacity * 0.002, "travel_reward": 0.0, "prev_queue": 0.0 } if not hasattr(agent, 'ema_delay_wait'): agent.ema_delay_wait = {j_id: 0.0 for j_id in junction_ids} if not hasattr(agent, 'prev_approach_congestion'): agent.prev_approach_congestion = {j_id: 0.0 for j_id in junction_ids} if not hasattr(agent, 'prev_metrics_trend'): agent.prev_metrics_trend = { j_id: {"queue": []} for j_id in junction_ids } def sigmoid_scale(x, sensitivity=None): sens = sensitivity or cfg["smoothing"]["sigmoid_sensitivity"] x_clamped = np.clip(x, -1000, 1000) return 2.0 / (1 + np.exp(-sens * x_clamped)) - 1.0 for j_id in junction_ids: junction = fp.junction_dict.get(j_id, {}) if not junction: rewards[j_id]['total'] = 0.0 continue signal_id = junction.get("signal", "") capacity = fp.get_junction_capacity(j_id) region_id = fp.get_region(j_id) region_id = region_id if region_id is not None else -1 enter_lanes = junction.get("cached_enter_lanes", []) valid_enter_lanes = [lane for lane in enter_lanes if lane not in invalid_lanes] is_accident = len(valid_enter_lanes) < len(enter_lanes) # 1. 延误-等待综合奖励 current_avg_delay = fp.get_junction_avg_delay(j_id) current_avg_waiting = all_junction_waiting.get(j_id, 0.0) current_avg_delay_wait = (current_avg_delay + current_avg_waiting) / 2 agent.ema_delay_wait[j_id] = ( cfg["smoothing"]["ema_decay"] * agent.ema_delay_wait[j_id] + (1 - cfg["smoothing"]["ema_decay"]) * current_avg_delay_wait ) current_smoothed = agent.ema_delay_wait[j_id] prev_avg_delay_wait = agent.prev_metrics[j_id]["avg_delay_wait"] delay_wait_delta = prev_avg_delay_wait - current_smoothed delay_wait_change = delay_wait_delta / max(1.0, current_avg_delay_wait) * 10 delay_wait_reward = cfg["weight"][weight_key]["delay_wait"] * sigmoid_scale(delay_wait_change) delay_wait_reward *= weather_factors["delay"] rewards[j_id]['components']['delay_wait'] = delay_wait_reward # 2. 排队奖励(事故适配+速率奖励) current_avg_queue = fp.get_junction_avg_queue(j_id) prev_avg_queue = agent.prev_metrics[j_id]["avg_queue"] prev_prev_queue = agent.prev_metrics[j_id]["prev_queue"] queue_delta = prev_avg_queue - current_avg_queue normalized_queue = current_avg_queue / max(1.0, capacity) queue_delta_normalized = queue_delta / max(1.0, capacity) queue_reward = ( cfg["weight"][weight_key]["queue"] * sigmoid_scale(queue_delta_normalized * 5.0) + weather_factors["queue"] * sigmoid_scale(normalized_queue, sensitivity=2.0) ) agent.prev_metrics_trend[j_id]["queue"].append(current_avg_queue) if len(agent.prev_metrics_trend[j_id]["queue"]) > cfg["congestion"]["queue_drop_steps"]: agent.prev_metrics_trend[j_id]["queue"].pop(0) if len(agent.prev_metrics_trend[j_id]["queue"]) == cfg["congestion"]["queue_drop_steps"]: if all( agent.prev_metrics_trend[j_id]["queue"][i] > agent.prev_metrics_trend[j_id]["queue"][i+1] for i in range(cfg["congestion"]["queue_drop_steps"] - 1) ): queue_reward += cfg["congestion"]["congest_relief_bonus"] relief_rate = agent.prev_metrics_trend[j_id]["queue"][0] - current_avg_queue rate_bonus = relief_rate * cfg["congestion"]["relief_rate_coeff"] queue_reward += rate_bonus # 事故场景:同时放大排队和延误-等待权重 + 延误超阈值惩罚 if is_accident: queue_reward *= cfg["weight"]["accident_adjust"].get("queue", 1.0) delay_wait_reward *= cfg["weight"]["accident_adjust"].get("delay_wait", 1.0) if current_avg_delay > cfg["accident_delay"]["threshold"]: delay_wait_reward -= cfg["accident_delay"]["penalty"] rewards[j_id]['components']['queue'] = queue_reward rewards[j_id]['components']['delay_wait'] = delay_wait_reward # 同步更新delay_wait # 3. 进口道奖励 phase_remaining = fp.get_phase_remaining_time(signal_id) if signal_id else 0 approach_queue = sum(len(fp.lane_volume.get(lane, [])) for lane in valid_enter_lanes) total_possible_queue = sum(fp.get_lane_capacity(lane) for lane in valid_enter_lanes) demand_ratio = approach_queue / (total_possible_queue + 1e-5) if total_possible_queue > 0 else 0.5 approach_reward = cfg["weight"][weight_key]["approach"] * (demand_ratio + 0.1) * max(0.0, 1 - phase_remaining / 5) approach_reward *= 1.0 / weather_factors["delay"] if hasattr(fp, 'lane_congestion'): approach_congestion = [fp.lane_congestion.get(lane, 0.0) for lane in valid_enter_lanes] avg_approach_congestion = np.mean(approach_congestion) if approach_congestion else 0.0 if (avg_approach_congestion < cfg["congestion"]["approach_congest_threshold"] and agent.prev_approach_congestion[j_id] >= cfg["congestion"]["approach_congest_threshold"]): approach_reward += cfg["congestion"]["congest_relief_bonus"] agent.prev_approach_congestion[j_id] = avg_approach_congestion rewards[j_id]['components']['approach'] = approach_reward # 4. 通行奖励 travel_reward = calculate_travel_reward( junction_id=j_id, fp=fp, vehicles=vehicles, invalid_lanes=invalid_lanes, config=cfg ) travel_reward *= weather_factors["travel"] rewards[j_id]['components']['travel'] = cfg["weight"][weight_key]["travel"] * travel_reward # 5. 区域协调奖励(区域拥堵时放大惩罚) coordination_penalty = 0.0 if region_id != -1 and hasattr(fp, 'region_dict'): region_dict = getattr(fp, 'region_dict', {}) region_junctions = region_dict.get(region_id, []) if len(region_junctions) > 1: region_avg_queue = fp.get_region_avg_queue(region_id) queue_deviation = abs(current_avg_queue - region_avg_queue) region_cap = fp.get_region_capacity(region_id) region_congestion = region_avg_queue / max(1.0, region_cap) if region_cap > 0 else 0.0 # 区域拥堵时放大协同惩罚 region_scale = cfg["congestion"]["region_congest_penalty_scale"] if region_congestion > cfg["congestion"]["region_congest_threshold"] else 1.0 coordination_factor = (1.0 + 2.0 * min(1.0, region_congestion)) * weather_factors["coord"] * region_scale coordination_penalty = -cfg["coordination"]["base_penalty_weight"] * coordination_factor * sigmoid_scale(queue_deviation, sensitivity=0.5) queue_diffs = [] for j_near in region_junctions: if j_near == j_id: continue near_queue = fp.get_junction_avg_queue(j_near) queue_diffs.append(abs(current_avg_queue - near_queue)) if queue_diffs: avg_queue_diff = np.mean(queue_diffs) coordination_penalty += cfg["coordination"]["synergy_bonus_weight"] * sigmoid_scale(-avg_queue_diff, sensitivity=0.1) rewards[j_id]['components']['coordination'] = cfg["weight"][weight_key]["coordination"] * coordination_penalty # 6. 总奖励计算(事故时多指标权重调整) weight_set = cfg["weight"][weight_key].copy() if is_accident: scaled_keys = ["queue", "delay_wait"] original_weights = {k: weight_set[k] for k in scaled_keys} total_scale = sum(original_weights[k] * cfg["weight"]["accident_adjust"].get(k, 1.0) for k in scaled_keys) original_total = sum(original_weights.values()) scale_ratio = total_scale / original_total other_weight_sum = sum(w for k, w in weight_set.items() if k not in scaled_keys) if other_weight_sum > 0: adjust_ratio = (sum(weight_set.values()) * scale_ratio - sum(original_weights[k] * cfg["weight"]["accident_adjust"].get(k, 1.0) for k in scaled_keys)) / other_weight_sum for k in weight_set: if k not in scaled_keys: weight_set[k] *= adjust_ratio weight_sum = sum(weight_set.values()) or 1.0 normalized_weights = {k: v / weight_sum for k, v in weight_set.items()} base_reward = cfg["base_reward"]["initial"] if hasattr(agent, 'train_step'): decay_ratio = min(agent.train_step / cfg["base_reward"]["decay_steps"], 1.0) base_reward -= cfg["base_reward"]["decay_max_ratio"] * cfg["base_reward"]["initial"] * decay_ratio total_reward = base_reward + sum( normalized_weights[k] * rewards[j_id]['components'][k] for k in normalized_weights ) rewards[j_id]['total'] = np.clip(total_reward, -1.0, 1.0) # 7. 更新历史缓存 agent.prev_metrics[j_id] = { "avg_delay_wait": cfg["smoothing"]["alpha"] * current_avg_delay_wait + (1 - cfg["smoothing"]["alpha"]) * prev_avg_delay_wait, "avg_queue": cfg["smoothing"]["alpha"] * current_avg_queue + (1 - cfg["smoothing"]["alpha"]) * prev_avg_queue, "travel_reward": cfg["smoothing"]["alpha"] * travel_reward + (1 - cfg["smoothing"]["alpha"]) * agent.prev_metrics[j_id]["travel_reward"], "prev_queue": prev_avg_queue } if (hasattr(agent, 'train_step') and agent.train_step % cfg["log"]["print_interval"] == 0 and hasattr(agent, 'logger')): for j_id in junction_ids: comp = rewards[j_id]['components'] region_id = fp.get_region(j_id) region_id = region_id if region_id is not None else -1 region_cap = fp.get_region_capacity(region_id) region_congestion = fp.get_region_avg_queue(region_id) / max(1.0, region_cap) if region_cap > 0 else 0.0 enter_lanes = fp.junction_dict.get(j_id, {}).get("cached_enter_lanes", []) valid_enter_lanes = [lane for lane in enter_lanes if lane not in invalid_lanes] is_accident = len(valid_enter_lanes) < len(enter_lanes) agent.logger.info( f"Step {agent.train_step} | Junc {j_id} (Region {region_id}) - " f"DelayWait: {comp['delay_wait']:.2f}, Queue: {comp['queue']:.2f}, " f"Approach: {comp['approach']:.2f}, Travel: {comp['travel']:.2f}, " f"Coord: {comp['coordination']:.2f} | " f"Congestion: {region_congestion:.2f}, Peak: {is_peak}, Weather: {weather_name} " f"(Factors: D:{weather_factors['delay']}, Q:{weather_factors['queue']}) | " f"Accident: {is_accident}, Total: {rewards[j_id]['total']:.2f}" ) return tuple(rewards[j_id]['total'] for j_id in junction_ids)检查此奖励函数的奖励与惩罚平衡性上是否合理?
09-08
/** * Copyright (C) 2024 TP-Link. All rights reserved. */ #include <stdio.h> #include <unistd.h> #include <math.h> #include "audio_aec.h" #include "ams_common.h" #define AEC_STATE_SWITCH_GAIN 1.0f #define AEC_STATE_SWITCH_GAIN_SQUARE 1.0f int aec_module_init(AEC_CONTEXT *p_context, int sample_rate, int use_timestamp, AEC3_SYS_CONFIG *EX_ctrl_para) { if (!p_context) { return -1; } memset(p_context, 0, sizeof(AEC_CONTEXT)); p_context->sample_rate = sample_rate; p_context->use_timestamp = use_timestamp; p_context->mic_timestamp = 0; p_context->spk_timestamp = 0; p_context->current_delay_f = 0; p_context->current_delay_pt = 0; /* 外开 */ p_context->current_delay_near = 40; /* 外开 */ memset(p_context->far_history, 0, sizeof(short) * D_RINGBUF_MAX_LEN); p_context->far_maxlen = D_RINGBUF_MAX_LEN; p_context->far_top = 0; /* added, nearend process */ memset(p_context->mic_history, 0, sizeof(short) * D_RINGBUF_MAX_LEN); p_context->mic_maxlen = D_RINGBUF_MAX_LEN; p_context->mic_top = 0; /* ringbuffer初始化 */ p_context->mic_ringbuf = audio_ring_buffer_init(D_RINGBUF_MAX_LEN); p_context->spk_ringbuf = audio_ring_buffer_init(D_RINGBUF_MAX_LEN); p_context->out_ringbuf = audio_ring_buffer_init(D_RINGBUF_MAX_LEN); p_context->post_gain = 1.0f; /* 外开,aec3的后增益 */ p_context->aec3_live_support_switch = 0; /* 外开,aec3支持直播模式的兼容性开关 */ p_context->aec3_dt_support_switch = 1; /* 外开,aec3支持双讲模式的兼容性开关 */ p_context->aec_state_switch_gain = 1.0f; /* 外开,应调为直播双讲模式切换时的幅值变化倍数 */ p_context->aec_state_switch_gain_square = p_context->aec_state_switch_gain * p_context->aec_state_switch_gain; p_context->R_aec_state_switch_gain = 1.0f / p_context->aec_state_switch_gain; p_context->R_aec_state_switch_gain_square = 1.0f / p_context->aec_state_switch_gain_square; memset(p_context->spk_buf_zero, 0, 2 * sizeof(short) * D_AEC_FRAME_LEN_WB); /* 初始化spk_buf_zero */ if (SAMPLE_RATE_NB == sample_rate) { p_context->aec_frame_len = D_AEC_FRAME_LEN; p_context->aec_fir_len = D_AEC_FILTER_LEN; } else if (SAMPLE_RATE_WB == sample_rate) { p_context->aec_frame_len = D_AEC_FRAME_LEN_WB; p_context->aec_fir_len = D_AEC_FILTER_LEN_WB; } else { p_context->aec_frame_len = D_AEC_FRAME_LEN; p_context->aec_fir_len = D_AEC_FILTER_LEN; } p_context->st = speex_echo_state_init(p_context->aec_frame_len, p_context->aec_fir_len); p_context->den = speex_preprocess_state_init(p_context->aec_frame_len, p_context->sample_rate); speex_echo_ctl(p_context->st, SPEEX_ECHO_SET_SAMPLING_RATE, &(p_context->sample_rate)); speex_preprocess_ctl(p_context->den, SPEEX_PREPROCESS_SET_ECHO_STATE, p_context->st); p_context->vad_for_agc_enable = 0; p_context->vad_list = (float *)calloc(D_INPUT_FRAME_MAX_LEN, sizeof(float)); /* 使用外开参数 */ speex_EXpara_apply(p_context, EX_ctrl_para); return 0; } void aec_state_switch(AEC_CONTEXT *p_context, SpeexEchoState *st, SpeexPreprocessState *den) /* 直播双讲模式切换 */ { float aec_state_switch_gain = p_context->aec_state_switch_gain; float aec_state_switch_gain_square = p_context->aec_state_switch_gain_square; float R_aec_state_switch_gain = p_context->R_aec_state_switch_gain; float R_aec_state_switch_gain_square = p_context->R_aec_state_switch_gain_square; int flag = st->old_aec_enable - st->aec_enable; if (flag == -1) /* 切换到双讲模式 */ { int i, M, N; N = st->window_size; M = st->M; st->cancel_count = 0; st->sum_adapt = 0; st->saturated = 0; st->echo_clipping_flag = 0; st->NLP_flag = 0; st->screwed_up = 0; memset(st->e, 0, N * sizeof(float)); memset(st->x, 0, N * sizeof(float)); memset(st->X, 0, N * (M + 1) * sizeof(float)); memset(st->input_buf, 0, N * sizeof(float)); memset(st->input_buf_win, 0, N * sizeof(float)); memset(st->y, 0, st->frame_size * sizeof(float)); memset(st->last_y, 0, st->frame_size * sizeof(float)); memset(st->last_echo, 0, st->frame_size * sizeof(float)); memset(st->INPUT, 0, st->frame_size * sizeof(float)); memset(st->Y, 0, st->frame_size * sizeof(float)); memset(st->E, 0, N * sizeof(float)); st->Davg1 = 0; st->Davg2 = 0; st->Dvar1 = 0; st->Dvar2 = 0; memset(st->power, 0, (st->frame_size + 1) * sizeof(float)); memset(st->Eh, 0, (st->frame_size + 1) * sizeof(float)); memset(st->Yh, 0, (st->frame_size + 1) * sizeof(float)); for (i = 0; i <= st->frame_size; i++) { st->power_1[i] = 1.0; } float sum = 0; /* Ratio of ~10 between adaptation rate of first and last block */ float decay = exp(-2.4 / st->M); st->prop[0] = 0.7; sum = st->prop[0]; for (i = 1; i < st->M; i++) { st->prop[i] = st->prop[i - 1] * decay; sum += st->prop[i]; } for (i = st->M - 1; i >= 0; i--) { st->prop[i] = 0.8f * st->prop[i] / sum; } memset(st->memD, 0, 1 * sizeof(float)); memset(st->memE, 0, 1 * sizeof(float)); memset(st->memX, 0, 1 * sizeof(float)); st->adapted = 0; st->Pey = st->Pyy = 1.0; st->converage_count = 0; memset(p_context->far_history, 0, sizeof(short) * D_RINGBUF_MAX_LEN); p_context->far_top = 0; tp_audio_ring_bufer_reset(p_context->spk_ringbuf); #ifdef TWO_PATH st->Davg1 = st->Davg2 = 0; st->Dvar1 = st->Dvar2 = 0.0; #endif for (i = 0; i < 2; i++) { st->notch_mem[i] *= R_aec_state_switch_gain; } for (i = 0; i < N; i++) { den->frame[i] *= R_aec_state_switch_gain; den->ft[i] *= R_aec_state_switch_gain; } for (i = 0; i < (int)(N / 2); i++) { den->noise[i] *= R_aec_state_switch_gain_square; den->old_ps[i] *= R_aec_state_switch_gain_square; den->S[i] *= R_aec_state_switch_gain_square; den->Smin[i] *= R_aec_state_switch_gain_square; den->Stmp[i] *= R_aec_state_switch_gain_square; den->inbuf[i] *= R_aec_state_switch_gain; den->outbuf[i] *= R_aec_state_switch_gain; den->noise_CNG[i] = den->noise[i]; /* CNG更新慢,且在直播模式停止更新,因此在切换时直接赋值 */ } } else if (flag == 1) { /* 切换到直播模式 */ int i, N; N = den->ps_size; for (i = 0; i < 2; i++) { st->notch_mem[i] *= aec_state_switch_gain; } for (i = 0; i < 2 * N; i++) { den->frame[i] *= aec_state_switch_gain; den->ft[i] *= aec_state_switch_gain; } for (i = 0; i < N; i++) { den->ps[i] *= aec_state_switch_gain_square; den->noise[i] *= aec_state_switch_gain_square; den->old_ps[i] *= aec_state_switch_gain_square; den->S[i] *= aec_state_switch_gain_square; den->Smin[i] *= aec_state_switch_gain_square; den->Stmp[i] *= aec_state_switch_gain_square; den->inbuf[i] *= aec_state_switch_gain; den->outbuf[i] *= aec_state_switch_gain; } } return; } int aec_module_process(AEC_CONTEXT * p_context) { if (!p_context) { return -1; } #ifdef DUMP_RAWDATA_SUPPORT FILE *mic_file = NULL, *spk_file = NULL, *aec_file = NULL, *out_file = NULL, *motor_state_file = NULL, *aec_state_file = NULL; if (access("/tmp/mnt/harddisk_1/audio_stream", 0) == 0) { mic_file = fopen("/tmp/mnt/harddisk_1/audio_stream/mic.pcm", "a+"); spk_file = fopen("/tmp/mnt/harddisk_1/audio_stream/spk.pcm", "a+"); aec_file = fopen("/tmp/mnt/harddisk_1/audio_stream/aec.pcm", "a+"); out_file = fopen("/tmp/mnt/harddisk_1/audio_stream/out.pcm", "a+"); motor_state_file = fopen("/tmp/mnt/harddisk_1/audio_stream/motor_state.pcm", "a+"); aec_state_file = fopen("/tmp/mnt/harddisk_1/audio_stream/aec_state.pcm", "a+"); } #endif int ret = 0; aec_state_switch(p_context, p_context->st, p_context->den); /* 状态切换时,更新参数 */ /* step 1: 时延估计 */ if (p_context->st->aec_enable) /* 判断回声消除是否开启 */ { /* 1.1 spk数据入队 */ if (p_context->far_top + p_context->sdata_len <= p_context->far_maxlen) { memcpy(&(p_context->far_history[p_context->far_top]), p_context->spk_buf_ptr, sizeof(short) * p_context->sdata_len); p_context->far_top += p_context->sdata_len; } else { unsigned int head_len = p_context->far_top + p_context->sdata_len - p_context->far_maxlen; unsigned int tail_len = p_context->sdata_len - head_len; memcpy(&(p_context->far_history[p_context->far_top]), p_context->spk_buf_ptr, sizeof(short) * tail_len); memcpy(&(p_context->far_history[0]), &(p_context->spk_buf_ptr[tail_len]), sizeof(short) * head_len); p_context->far_top = head_len; } } /* nearend process */ /* 近端数据入队 */ if (p_context->mic_top + p_context->sdata_len <= p_context->mic_maxlen) { memcpy(&(p_context->mic_history[p_context->mic_top]), p_context->mic_buf_ptr, sizeof(short) * p_context->sdata_len); p_context->mic_top += p_context->sdata_len; } else { unsigned int head_len = p_context->mic_top + p_context->sdata_len - p_context->mic_maxlen; unsigned int tail_len = p_context->sdata_len - head_len; memcpy(&(p_context->mic_history[p_context->mic_top]), p_context->mic_buf_ptr, sizeof(short) * tail_len); memcpy(&(p_context->mic_history[0]), &(p_context->mic_buf_ptr[tail_len]), sizeof(short) * head_len); p_context->mic_top = head_len; } /* 1.2 时延估计 */ S32 current_delay_pt = 0; S32 current_delay_near = 0; if (p_context->st->aec_enable) { p_context->current_delay_f = 0; if (p_context->use_timestamp) { U64 time_diff_us = 0; if (p_context->mic_timestamp > p_context->spk_timestamp) { time_diff_us = p_context->mic_timestamp - p_context->spk_timestamp; } // 从帧长,采样率倒推时间 S32 sample_rate = p_context->sample_rate; S32 frame_length = p_context->aec_frame_len; S32 delay_points = (S32)(time_diff_us / (1.0 * 1000000 / sample_rate)); p_context->current_delay_f = (int)(delay_points / frame_length); /* 传来的时间戳异常,倾向于无时延 */ if (p_context->current_delay_f > D_MAX_DELAY_F) { p_context->current_delay_f = 0; } } else { /* TODO: 使用算法计算时延。和aqi/aec/aec算法中的相同,待移植 */ } current_delay_pt = p_context->current_delay_f * p_context->aec_frame_len; } /* 1.3 从far_history中取出参考信号 */ current_delay_pt = p_context->current_delay_pt; memset(p_context->ref_buf, 0 , D_INPUT_FRAME_MAX_LEN * sizeof(short)); if (p_context->st->aec_enable) { if (p_context->far_top - current_delay_pt - p_context->sdata_len > 0) { memcpy(p_context->ref_buf, &(p_context->far_history[p_context->far_top - current_delay_pt - p_context->sdata_len]), sizeof(short) * p_context->sdata_len); } else { unsigned int tail_len = p_context->sdata_len - (p_context->far_top - current_delay_pt); if (tail_len < p_context->sdata_len) { memcpy(p_context->ref_buf, &(p_context->far_history[p_context->far_maxlen - tail_len]), sizeof(short) * tail_len); memcpy(&(p_context->ref_buf[tail_len]), p_context->far_history, sizeof(short) * (p_context->sdata_len - tail_len)); } else { memcpy(p_context->ref_buf, &(p_context->far_history[p_context->far_maxlen - tail_len]), sizeof(short) * p_context->sdata_len); } } } /* nearend process */ current_delay_near = p_context->current_delay_near; memset(p_context->mic_buf, 0 , D_INPUT_FRAME_MAX_LEN * sizeof(short)); if (p_context->mic_top - current_delay_near - p_context->sdata_len > 0) { memcpy(p_context->mic_buf, &(p_context->mic_history[p_context->mic_top - current_delay_near - p_context->sdata_len]), sizeof(short) * p_context->sdata_len); } else { unsigned int tail_len = p_context->sdata_len - (p_context->mic_top - current_delay_near); if (tail_len < p_context->sdata_len) { memcpy(p_context->mic_buf, &(p_context->mic_history[p_context->mic_maxlen - tail_len]), sizeof(short) * tail_len); memcpy(&(p_context->mic_buf[tail_len]), p_context->mic_history, sizeof(short) * (p_context->sdata_len - tail_len)); } else { memcpy(p_context->mic_buf, &(p_context->mic_history[p_context->mic_maxlen - tail_len]), sizeof(short) * p_context->sdata_len); } } /* step 2: mic,ref信号存入缓存 */ unsigned int write_elements = 0; write_elements = audio_ring_buffer_set_data(p_context->mic_ringbuf, p_context->mic_buf, p_context->sdata_len); if (write_elements < p_context->sdata_len) { AMS_ERROR("write buf error"); ret = -1; goto AEC_DESTROY; } if (p_context->st->aec_enable) { audio_ring_buffer_set_data(p_context->spk_ringbuf, p_context->ref_buf, p_context->sdata_len); } /* step 3: aec */ int frames = (int)(audio_ring_buffer_used_space(p_context->mic_ringbuf) / p_context->aec_frame_len); for (int i = 0; i < frames; i++) { audio_ring_buffer_get_data(p_context->mic_ringbuf, p_context->mic_tmp, p_context->aec_frame_len); if (p_context->st->aec_enable) { audio_ring_buffer_get_data(p_context->spk_ringbuf, p_context->spk_tmp, p_context->aec_frame_len); } speex_echo_cancellation(p_context->st, p_context->mic_tmp, p_context->spk_tmp, p_context->out_tmp); #ifdef DUMP_RAWDATA_SUPPORT short motor_state_tmp[1] = { 0 }; motor_state_tmp[0] = p_context->den->motor_state; short aec_state_tmp[1] = { 0 }; aec_state_tmp[0] = p_context->st->aec_enable; if (mic_file && spk_file && aec_file && motor_state_file && aec_state_file) { fwrite(p_context->mic_tmp, sizeof(short), p_context->aec_frame_len, mic_file); fwrite(p_context->spk_tmp, sizeof(short), p_context->aec_frame_len, spk_file); fwrite(p_context->out_tmp, sizeof(short), p_context->aec_frame_len, aec_file); fwrite(motor_state_tmp, sizeof(short), 1, motor_state_file); fwrite(aec_state_tmp, sizeof(short), 1, aec_state_file); } #endif if (COMPUTATION_NS_BARK_ENABLE & p_context->st->computation_simplification) { speex_preprocess_run_bark(p_context->den, p_context->out_tmp); } else { speex_preprocess_run(p_context->den, p_context->out_tmp); } p_context->vad_for_agc_enable = VAD_FOR_AGC_MODE_ON & p_context->den->special_mode; if (p_context->vad_for_agc_enable) { for (int j = i * p_context->aec_frame_len; j < (i + 1) * p_context->aec_frame_len; j++) { p_context->vad_list[j] = p_context->den->vad; } } speex_post_gain(p_context, p_context->out_tmp); #ifdef DUMP_RAWDATA_SUPPORT if (out_file) { fwrite(p_context->out_tmp, sizeof(short), p_context->aec_frame_len, out_file); } #endif /* out_tmp */ write_elements = audio_ring_buffer_set_data(p_context->out_ringbuf, p_context->out_tmp, p_context->aec_frame_len); if (write_elements < p_context->aec_frame_len) { AMS_ERROR("write buf error"); ret = -1; goto AEC_DESTROY; } } /* step 4: 输出 */ write_elements = audio_ring_buffer_used_space(p_context->out_ringbuf); if (write_elements < p_context->sdata_len) { memset(p_context->out_buf_ptr, 0, sizeof(short) * p_context->sdata_len); } else { audio_ring_buffer_get_data(p_context->out_ringbuf, p_context->out_buf_ptr, p_context->sdata_len); } AEC_DESTROY: #ifdef DUMP_RAWDATA_SUPPORT if (mic_file) { fclose(mic_file); } if (spk_file) { fclose(spk_file); } if (aec_file) { fclose(aec_file); } if (out_file) { fclose(out_file); } if (motor_state_file) { fclose(motor_state_file); } if (aec_state_file) { fclose(aec_state_file); } #endif return ret; } /***************************************************************************** * Function: aec_module_deinit() * Description: aec资源释放 * Input: p_context -- aec参数信息 * Output: 无 * Return: 无 *****************************************************************************/ void aec_module_deinit(AEC_CONTEXT *p_context) { if (p_context) { audio_ring_buffer_deinit(p_context->mic_ringbuf); audio_ring_buffer_deinit(p_context->spk_ringbuf); audio_ring_buffer_deinit(p_context->out_ringbuf); speex_echo_state_destroy(p_context->st); speex_preprocess_state_destroy(p_context->den); free(p_context->vad_list); p_context->vad_list = NULL; } } void speex_post_gain(AEC_CONTEXT *p_context, short *x) { int i; float x_tmp; float post_gain = p_context->post_gain; for (i = 0; i < p_context->aec_frame_len; i++) { x_tmp = (float)(x[i]); x_tmp *= post_gain; x_tmp = MIN32(x_tmp, 32767); x_tmp = MAX32(x_tmp, -32767); x[i] = (short)x_tmp; } } void speex_EXpara_apply(AEC_CONTEXT *p_context, AEC3_SYS_CONFIG *EX_ctrl_para) { /* audio aec */ p_context->current_delay_near = EX_ctrl_para->mic_delay_preset; /* mdf */ p_context->st->ref_res_thr = EX_ctrl_para->ref_res_thr; p_context->st->ref_nlp_thr = EX_ctrl_para->ref_nlp_thr; p_context->st->ref_saturate_thr = EX_ctrl_para->ref_saturate_thr; p_context->st->leak_estimate_enabled = EX_ctrl_para->leak_estimate_enabled; p_context->st->leak_value_unadapted = EX_ctrl_para->leak_value_unadapted; p_context->st->leak_value_clipping = EX_ctrl_para->leak_value_clipping; p_context->st->leak_value_slight = EX_ctrl_para->leak_value_slight; p_context->st->saturate_gain = EX_ctrl_para->saturate_gain; p_context->st->residual_gain = EX_ctrl_para->residual_gain; p_context->st->min_leak = EX_ctrl_para->min_leak; /* preprocess */ p_context->den->denoise_enabled = EX_ctrl_para->denoise_mode; p_context->den->nlp_cutoff = EX_ctrl_para->nlp_cutoff; p_context->den->nlp_hnle_thr = EX_ctrl_para->nlp_hnle_thr; p_context->den->nlp_highfreq_suppress = EX_ctrl_para->nlp_highfreq_suppress; /* 第二次更新参数 */ /* audio aec */ p_context->current_delay_pt = EX_ctrl_para->spk_delay_preset; p_context->post_gain = EX_ctrl_para->post_gain; p_context->aec3_live_support_switch = EX_ctrl_para->aec3_live_support_switch; p_context->aec3_dt_support_switch = EX_ctrl_para->aec3_dt_support_switch; p_context->aec_state_switch_gain = EX_ctrl_para->aec_state_switch_gain; p_context->aec_state_switch_gain_square = p_context->aec_state_switch_gain * p_context->aec_state_switch_gain; p_context->R_aec_state_switch_gain = 1.0f / p_context->aec_state_switch_gain; p_context->R_aec_state_switch_gain_square = 1.0f / p_context->aec_state_switch_gain_square; /* mdf */ p_context->st->notch_radius = EX_ctrl_para->notch_radius; p_context->st->mic_saturate_thr = EX_ctrl_para->mic_saturate_thr; p_context->st->res_hangover = EX_ctrl_para->res_hangover; p_context->st->nlp_hangover = EX_ctrl_para->nlp_hangover; p_context->st->saturated_hangover = EX_ctrl_para->saturated_hangover; /* preprocess */ p_context->den->special_mode = EX_ctrl_para->special_mode; p_context->den->min_range = EX_ctrl_para->min_range; p_context->den->vad_enabled = EX_ctrl_para->vad_enabled; p_context->den->speech_prob_start = EX_ctrl_para->speech_prob_start; p_context->den->speech_prob_continue = EX_ctrl_para->speech_prob_continue; p_context->den->noise_suppress = EX_ctrl_para->noise_suppress; p_context->den->echo_suppress = EX_ctrl_para->echo_suppress; p_context->den->echo_suppress_active = EX_ctrl_para->echo_suppress_active; p_context->den->overdrive = EX_ctrl_para->overdrive; p_context->den->alpha_z_noise = EX_ctrl_para->alpha_z_noise; p_context->den->alpha_z_speech = EX_ctrl_para->alpha_z_speech; p_context->den->beta_z_noise = EX_ctrl_para->beta_z_noise; p_context->den->beta_z_speech = EX_ctrl_para->beta_z_speech; p_context->den->use_hypergeom_speech = EX_ctrl_para->use_hypergeom_speech; /* 第三次更新参数(电机降噪参数) */ /* preprocess */ p_context->den->min_range_motor = EX_ctrl_para->min_range_motor; p_context->den->motor_suppress = EX_ctrl_para->motor_suppress; p_context->den->motor_highfreq_clipping_thr = EX_ctrl_para->motor_highfreq_clipping_thr; p_context->den->motor_harmonic_suppress_freq = EX_ctrl_para->motor_harmonic_suppress_freq; p_context->den->motor_nonstationary_numb = EX_ctrl_para->motor_nonstationary_numb; p_context->den->motor_first_used_numb = EX_ctrl_para->motor_first_used_numb; /* 第四次更新参数(解决初状态回声收敛) */ if (EX_ctrl_para->aec3_para_version > 3) { /* mdf */ p_context->st->erl = EX_ctrl_para->erl; p_context->st->erl_square = p_context->st->erl * p_context->st->erl; p_context->st->sxx_af_init_adapt_thr = EX_ctrl_para->sxx_af_init_adapt_thr; p_context->st->miu_fix = EX_ctrl_para->miu_fix; p_context->st->miu_max_init = EX_ctrl_para->miu_max_init; p_context->st->miu_max_init = MIN32(90.0f, p_context->st->miu_max_init); } /* 第五次更新参数 */ /* preprocess */ if (EX_ctrl_para->aec3_para_version > 4) { p_context->den->noise_update_thr = EX_ctrl_para->noise_update_thr; p_context->den->noise_update_speed = EX_ctrl_para->noise_update_speed; p_context->den->motor_noise_update_thr_low = EX_ctrl_para->motor_noise_update_thr_low; p_context->den->motor_noise_update_thr_high = EX_ctrl_para->motor_noise_update_thr_high; p_context->den->motor_noise_update_speed_low = EX_ctrl_para->motor_noise_update_speed_low; p_context->den->motor_noise_update_speed_high = EX_ctrl_para->motor_noise_update_speed_high; p_context->den->motor_end_nonstationary_numb = EX_ctrl_para->motor_end_nonstationary_numb; p_context->den->motor_overestimate_numb = EX_ctrl_para->motor_overestimate_numb; p_context->den->motor_overestimate_weight = EX_ctrl_para->motor_overestimate_weight; p_context->den->energy_vad_thr = EX_ctrl_para->energy_vad_thr; p_context->den->speech_prob_vad_thr = EX_ctrl_para->speech_prob_vad_thr; p_context->den->abrupt_noise_determination_thr = EX_ctrl_para->abrupt_noise_determination_thr; p_context->den->flatness_vad_thr = EX_ctrl_para->flatness_vad_thr; p_context->den->cepstrum_range_min = EX_ctrl_para->cepstrum_range_min; p_context->den->cepstrum_range_max = EX_ctrl_para->cepstrum_range_max; p_context->den->cepstrum_vad_thr = EX_ctrl_para->cepstrum_vad_thr; p_context->den->cepstrum_res_max = EX_ctrl_para->cepstrum_res_max; p_context->den->abrupt_noise_count_thr = EX_ctrl_para->abrupt_noise_count_thr; p_context->den->abrupt_noise_convergence_numb = EX_ctrl_para->abrupt_noise_convergence_numb; p_context->den->min_range_CNG = EX_ctrl_para->min_range_CNG; p_context->den->noise_update_thr_CNG = EX_ctrl_para->noise_update_thr_CNG; p_context->den->noise_update_speed_CNG = EX_ctrl_para->noise_update_speed_CNG; } else { p_context->den->motor_end_nonstationary_numb = EX_ctrl_para->motor_nonstationary_numb; p_context->den->motor_overestimate_numb = EX_ctrl_para->motor_nonstationary_numb; p_context->den->motor_overestimate_weight = 1; } /* 第六次更新参数 */ if (EX_ctrl_para->aec3_para_version > 5) { /* mdf */ p_context->st->computation_simplification = EX_ctrl_para->computation_simplification; /* preprocess */ p_context->den->add_white_noise = EX_ctrl_para->add_white_noise; } } 这段代码面它是怎么根据motor_state来调整降噪策略的
09-20
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值