mirror of
https://git.vladimir.cc/vladimir/ewsdr.git
synced 2026-08-25 19:45:09 +00:00
Optimize web audio mic path: remove redundant copy and heap alloc
WebOnMic: drop intermediate Singles[] array, read PSingle directly. PushAudio: replace per-frame SetLength/array of Byte with pre-allocated FWsAudioBuf field — eliminates heap allocation from the DSP thread. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
+4
-5
@@ -172,6 +172,7 @@ type
|
||||
FOpusBuf: array[0..OPUS_FRAME_SAMP-1] of Single;
|
||||
FOpusBufPos: Integer;
|
||||
FOpusOut: array[0..3999] of Byte;
|
||||
FWsAudioBuf: array[0..4000] of Byte; // 1 байт типа + до 4000 байт Opus
|
||||
FOpusReady: Boolean;
|
||||
// Opus decoder — для RX TX-mic аудио от браузера
|
||||
FOpusDec: POpusDecoder;
|
||||
@@ -1429,7 +1430,6 @@ procedure TWebServer.PushAudio(const Samples: PSingle; Count: Integer);
|
||||
var
|
||||
HasWs: Boolean;
|
||||
i, n, Enc: Integer;
|
||||
Pkt: array of Byte;
|
||||
begin
|
||||
if not FRunning then Exit;
|
||||
FClientLock.Enter;
|
||||
@@ -1454,10 +1454,9 @@ begin
|
||||
@FOpusOut[0], SizeOf(FOpusOut));
|
||||
if Enc > 0 then
|
||||
begin
|
||||
SetLength(Pkt, 1 + Enc);
|
||||
Pkt[0] := WS_MSG_AUDIO;
|
||||
Move(FOpusOut[0], Pkt[1], Enc);
|
||||
BroadcastBinary(Pkt[0], Length(Pkt));
|
||||
FWsAudioBuf[0] := WS_MSG_AUDIO;
|
||||
Move(FOpusOut[0], FWsAudioBuf[1], Enc);
|
||||
BroadcastBinary(FWsAudioBuf[0], 1 + Enc);
|
||||
end;
|
||||
FOpusBufPos := 0;
|
||||
end;
|
||||
|
||||
Reference in New Issue
Block a user