From be8b64f630782b1348e00ab239e7ada73e03e34d Mon Sep 17 00:00:00 2001
From: sin365 <353374337@qq.com>
Date: Thu, 16 Oct 2025 15:49:08 +0800
Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E5=96=84AudioDSP=E5=8F=AF=E9=80=89?=
=?UTF-8?q?=E8=AE=BE=E7=BD=AE=E9=87=87=E6=A0=B7=E7=8E=87=EF=BC=8CEssgee?=
=?UTF-8?q?=E8=AE=BE=E7=BD=AE=E6=AD=A3=E7=A1=AE=E9=87=87=E6=A0=B7=E7=8E=87?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../UEssgeeInterface/UEGSoundPlayer.cs | 2 +-
.../AppMain/Emulator/NesEmulator/AudioProvider.cs | 2 +-
.../StoicGooseInterface/SGSoundPlayer.cs | 2 +-
.../Assets/Script/AppMain/MonoCom/AudioMgr.cs | 14 ++++++++------
4 files changed, 11 insertions(+), 9 deletions(-)
diff --git a/AxibugEmuOnline.Client/Assets/Script/AppMain/Emulator/EssgeeEmulator/UEssgeeInterface/UEGSoundPlayer.cs b/AxibugEmuOnline.Client/Assets/Script/AppMain/Emulator/EssgeeEmulator/UEssgeeInterface/UEGSoundPlayer.cs
index 449f660d..8d445e57 100644
--- a/AxibugEmuOnline.Client/Assets/Script/AppMain/Emulator/EssgeeEmulator/UEssgeeInterface/UEGSoundPlayer.cs
+++ b/AxibugEmuOnline.Client/Assets/Script/AppMain/Emulator/EssgeeEmulator/UEssgeeInterface/UEGSoundPlayer.cs
@@ -34,7 +34,7 @@ public class UEGSoundPlayer : MonoBehaviour, AxiAudioPull
private void OnEnable()
{
- App.audioMgr.RegisterStream(nameof(UEssgee), AudioSettings.outputSampleRate, this);
+ App.audioMgr.RegisterStream(nameof(UEssgee), sampleRate, this);
}
void OnDisable()
diff --git a/AxibugEmuOnline.Client/Assets/Script/AppMain/Emulator/NesEmulator/AudioProvider.cs b/AxibugEmuOnline.Client/Assets/Script/AppMain/Emulator/NesEmulator/AudioProvider.cs
index e4b95a87..3ce01c65 100644
--- a/AxibugEmuOnline.Client/Assets/Script/AppMain/Emulator/NesEmulator/AudioProvider.cs
+++ b/AxibugEmuOnline.Client/Assets/Script/AppMain/Emulator/NesEmulator/AudioProvider.cs
@@ -37,7 +37,7 @@ namespace AxibugEmuOnline.Client
private void OnEnable()
{
- App.audioMgr.RegisterStream(nameof(NesEmulator), AudioSettings.outputSampleRate, this);
+ App.audioMgr.RegisterStream(nameof(NesEmulator), null, this);
}
void OnDisable()
diff --git a/AxibugEmuOnline.Client/Assets/Script/AppMain/Emulator/StoicGooseEmulator/StoicGooseInterface/SGSoundPlayer.cs b/AxibugEmuOnline.Client/Assets/Script/AppMain/Emulator/StoicGooseEmulator/StoicGooseInterface/SGSoundPlayer.cs
index 1445b1e9..c42d2a3e 100644
--- a/AxibugEmuOnline.Client/Assets/Script/AppMain/Emulator/StoicGooseEmulator/StoicGooseInterface/SGSoundPlayer.cs
+++ b/AxibugEmuOnline.Client/Assets/Script/AppMain/Emulator/StoicGooseEmulator/StoicGooseInterface/SGSoundPlayer.cs
@@ -47,7 +47,7 @@ public class SGSoundPlayer : MonoBehaviour, AxiAudioPull
private void OnEnable()
{
- App.audioMgr.RegisterStream(nameof(UStoicGoose), AudioSettings.outputSampleRate, this);
+ App.audioMgr.RegisterStream(nameof(UStoicGoose), null, this);
}
void OnDisable()
diff --git a/AxibugEmuOnline.Client/Assets/Script/AppMain/MonoCom/AudioMgr.cs b/AxibugEmuOnline.Client/Assets/Script/AppMain/MonoCom/AudioMgr.cs
index e0da865c..1283c426 100644
--- a/AxibugEmuOnline.Client/Assets/Script/AppMain/MonoCom/AudioMgr.cs
+++ b/AxibugEmuOnline.Client/Assets/Script/AppMain/MonoCom/AudioMgr.cs
@@ -78,7 +78,7 @@ namespace AxibugEmuOnline.Client
//函数仅处理设备变化的情况,非设备变化不再本函数处理,避免核心采样率变化和本处循环调用
if (deviceWasChanged)
{
- ResetAudioCfg();
+ ResetAudioCfg(AudioSettings.outputSampleRate);
//AudioConfiguration config = AudioSettings.GetConfiguration();
//AudioSettings.Reset(config);
//TODO 重新播放音效,但是DSP不用,若有UI BGM,后续 这里加重播
@@ -119,20 +119,22 @@ namespace AxibugEmuOnline.Client
///
/// 通道标识符 (e.g., "NES", "MAME")
/// 该通道的原始采样率
- public void RegisterStream(string channelId, int inputSampleRate, AxiAudioPull audioPullHandle)
+ public void RegisterStream(string channelId, int? inputSampleRate, AxiAudioPull audioPullHandle)
{
_audioStreams = null;
- _audioStreams = new AudioStreamData(channelId, inputSampleRate, audioPullHandle);
- ResetAudioCfg();
+ _audioStreams = new AudioStreamData(channelId,
+ inputSampleRate.HasValue ? inputSampleRate.Value : AudioSettings.outputSampleRate
+ , audioPullHandle);
+ ResetAudioCfg(inputSampleRate);
}
- private void ResetAudioCfg()
+ private void ResetAudioCfg(int? inputSampleRate)
{
// 获取当前音频配置
AudioConfiguration config = AudioSettings.GetConfiguration();
// 设置目标音频配置
- config.sampleRate = 48000; // 采样率为 44100Hz
+ config.sampleRate = inputSampleRate.HasValue ? inputSampleRate.Value : 48000; // 采样率为 44100Hz
config.numRealVoices = 32; // 设置最大音频源数量(可选)
config.numVirtualVoices = 512; // 设置虚拟音频源数量(可选)
config.dspBufferSize = 1024; // 设置 DSP 缓冲区大小(可选)