fix(dmr): normalize voice audio and lock bandwidth

This commit is contained in:
2026-07-14 20:14:50 +03:00
parent bac0b7612e
commit 9755378586
5 changed files with 27 additions and 15 deletions
+10 -1
View File
@@ -187,6 +187,9 @@ const
DMR_SYNC_MASK = LongWord($00FFFFFF);
DMR_SYNC_HOLD_MS = 500;
DMR_SYNC_MAX_ERRORS = 2;
// mbelib's floating-point API retains the signed 16-bit PCM scale. EWSDR's
// audio outputs use normalized floating point, where full scale is +/-1.0.
DMR_PCM_SCALE = 1.0 / 32768.0;
DMR_SUPERFRAME_SAMPLES = DMR_INPUT_RATE * 360 div 1000;
DMR_SYNC_CADENCE_TOLERANCE = DMR_SAMPLES_PER_SYM * 3;
@@ -771,7 +774,7 @@ var
Frames: TDMRAMBEFrames;
PCM: array[0..DMR_PCM_SAMPLES - 1] of Single;
MbeResult: TDMRMbeResult;
Slot, FrameIndex, RC: Integer;
Slot, FrameIndex, SampleIndex, RC: Integer;
NowTick: QWord;
begin
if (FMbe = nil) or (FLastSyncTick = 0) or
@@ -818,6 +821,12 @@ begin
end;
Inc(FVoiceFrameCount);
if MbeResult.ErrorsTotal > 0 then Inc(FVoiceErrorCount, MbeResult.ErrorsTotal);
for SampleIndex := 0 to High(PCM) do
begin
PCM[SampleIndex] := PCM[SampleIndex] * DMR_PCM_SCALE;
if PCM[SampleIndex] > 1.0 then PCM[SampleIndex] := 1.0
else if PCM[SampleIndex] < -1.0 then PCM[SampleIndex] := -1.0;
end;
if Assigned(FOnAudio) then FOnAudio(PCM, Length(PCM));
end;
end;