From a80237d09f739acc3443761cc1ca0f3450925a33 Mon Sep 17 00:00:00 2001 From: liwei1dao Date: Sat, 9 May 2026 19:27:09 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=8A=E4=BC=A0=E4=BC=9A=E8=AE=AE=E8=AE=B0?= =?UTF-8?q?=E5=BD=95=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../meeting_record_controller.dart | 24 +++++++++++-------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/lib/modules/meeting/controllers/meeting_record_controller.dart b/lib/modules/meeting/controllers/meeting_record_controller.dart index f3827c7bd..9f21ac28b 100644 --- a/lib/modules/meeting/controllers/meeting_record_controller.dart +++ b/lib/modules/meeting/controllers/meeting_record_controller.dart @@ -771,22 +771,26 @@ class MeetingRecordController extends GetxController waveformController.notifyListeners(); } - /// 计算音频数据的振幅 + /// 计算音频数据的振幅。 + /// + /// 输入是小端 PCM_S16LE 字节流,可能是 mono 或 stereo 交织(LRLR)。 + /// 这里按"每个 16-bit 样本"遍历(步长 2 字节),不区分声道,把所有样本一起求 RMS: + /// - mono:等价于全采样能量 + /// - stereo:L 和 R 都纳入计算,得到双方组合能量;任一边说话都能体现在波形里 + /// + /// 之前用 `i += 4` 想做 2× 跳跃采样减计算量,但碰到 stereo 时变成"只读 L 跳过 R", + /// 导致通话录音的图谱只反映本端(自己),听不到对端的波形——已修。 double _calculateAmplitude(Uint8List audioData) { if (audioData.isEmpty) return 0.0; - // 使用RMS (Root Mean Square) 算法,更准确反映音频能量 double sumSquares = 0.0; int sampleCount = 0; - for (int i = 0; i < audioData.length; i += 4) { - // 跳跃采样,减少计算量 - if (i + 1 < audioData.length) { - final int sample = (audioData[i + 1] << 8) | audioData[i]; - final int signedSample = sample > 32767 ? sample - 65536 : sample; - sumSquares += (signedSample * signedSample); - sampleCount++; - } + for (int i = 0; i + 1 < audioData.length; i += 2) { + final int sample = (audioData[i + 1] << 8) | audioData[i]; + final int signedSample = sample > 32767 ? sample - 65536 : sample; + sumSquares += (signedSample * signedSample); + sampleCount++; } if (sampleCount == 0) return 0.0;