Files
SimpleRemoter/build.cmd
T
yuanyuanxiangandDeepSeek-V4.1-Flash 3ae54c808e Fix(audio): keep audio packets block-aligned end to end
waveOut only converts whole 65-byte GSM610 blocks; a trailing partial block is
dropped, never carried over. Windows hosts record into a 1000-byte buffer but
the driver fills only 975 (15 blocks) - the last 25 bytes are stale heap the
driver never wrote. Clients ship all 1000 bytes anyway, so PlayBuffer has to
truncate each packet to whole blocks and throw that tail away.

Accumulating the remainder across packets instead - the first attempt at this
fix - inserted 25 bytes of garbage every 1000 bytes and shifted the block
boundary, turning voice monitoring of existing Windows clients into pure noise
while Android stayed fine. Both symptoms are the same "per packet" versus
"across packets" opposition, and per packet is the one that matches the wire.

So the invariant is: one packet carries a whole number of 65-byte blocks, and
nothing is ever carried into the next packet. Windows hosts satisfy it for
free. Android now packs 15 blocks (975 bytes) and pads the rest with zeros to
keep the 1000-byte length that older controllers expect - see AudioHandler.h.

GetRecordBuffer keeps returning the full 1000 bytes on purpose: shortening the
packet would make a v1.4.2 controller memcpy m_ulBufferLength and read past the
end, which is real garbage rather than harmless stale bytes.

Measured against the real waveOut API with a 2 s 1 kHz tone (3250 bytes = 50
blocks = 16000 samples): one 3250-byte buffer played 16000 samples, four
1000-byte buffers played 15360 (25 bytes lost per packet), four 975-byte
buffers played 16000. The encoder was never at fault - the same libgsm WAV49
stream decodes through Windows ACM with a correlation of 0.9999 when handed
over whole.

Also check WHDR_INQUEUE before reusing a header and honour the waveOutWrite
return value, since the old code dropped data silently on WAVERR_BUSY; size the
playback buffers for the largest packet; and unprepare the waveOut headers in
the destructor, which was unpreparing the waveIn headers after they had already
been freed.

Android APKs built before this commit still send unaligned 1000-byte packets
and will sound noisy against this controller - rebuild the APK.

Co-Authored-By: DeepSeek-V4.1-Flash
2026-11-15 17:05:41 +01:00

79 lines
3.1 KiB
Batchfile

@echo off
:: SimpleRemoter Quick Build Script
:: Usage: build.cmd [release|debug] [x64|x86|all] [server|clean|publish|go-server|server-linux|serverd|client] [-name NAME]
:: go-server Build Go fallback server only - Bin\YamaGo_x64.exe
:: go-server publish Same, plus UPX --best compression
:: server-linux Cross-compile Go server for Linux - Bin\server_linux_amd64
:: serverd Debug server only (x64) - Bin\Yama_x64d.exe
:: client Debug client (x64) - x64\Debug\ghost.exe
:: -name NAME Server output name, writes Bin\NAME_x64.exe instead of
:: Bin\Yama_x64.exe. Use it to build while the Release
:: server is running and Bin\Yama_x64.exe is locked:
:: build.cmd server -name YamaTest
:: Applies to server / serverd / publish.
::
:: NOTE: keep this file pure ASCII. cmd reads .cmd as the OEM code page (936
:: here), so UTF-8 text can swallow the following newline and merge the next
:: command into a comment line - which then turns its ">" into a redirect.
setlocal enabledelayedexpansion
:: Capture the script directory before any shift: shift moves %0 along with
:: %1..%9, after which %~dp0 resolves to the current directory instead.
set SCRIPT_DIR=%~dp0
set CONFIG=Release
set PLATFORM=x64
set EXTRA_ARGS=
set SERVER_NAME=
:parse_args
if "%~1"=="" goto :run
if /i "%~1"=="release" (set CONFIG=Release& shift& goto :parse_args)
if /i "%~1"=="debug" (set CONFIG=Debug& shift& goto :parse_args)
if /i "%~1"=="x64" (set PLATFORM=x64& shift& goto :parse_args)
if /i "%~1"=="x86" (set PLATFORM=x86& shift& goto :parse_args)
if /i "%~1"=="all" (set PLATFORM=all& shift& goto :parse_args)
if /i "%~1"=="server" (set EXTRA_ARGS=!EXTRA_ARGS! -ServerOnly& shift& goto :parse_args)
if /i "%~1"=="clean" (set EXTRA_ARGS=!EXTRA_ARGS! -Clean& shift& goto :parse_args)
if /i "%~1"=="publish" (set EXTRA_ARGS=!EXTRA_ARGS! -Publish& shift& goto :parse_args)
if /i "%~1"=="go-server" (set EXTRA_ARGS=!EXTRA_ARGS! -GoServer& shift& goto :parse_args)
if /i "%~1"=="server-linux" (set EXTRA_ARGS=!EXTRA_ARGS! -GoServerLinux& shift& goto :parse_args)
:: Debug presets: serverd = debug server x64 only, client = debug ghost x64 only
if /i "%~1"=="serverd" (set CONFIG=Debug& set PLATFORM=x64& set EXTRA_ARGS=!EXTRA_ARGS! -ServerOnly& shift& goto :parse_args)
if /i "%~1"=="client" (set CONFIG=Debug& set PLATFORM=x64& set EXTRA_ARGS=!EXTRA_ARGS! -ClientOnly& shift& goto :parse_args)
if /i "%~1"=="-name" (
if "%~2"=="" (
echo ERROR: -name needs a value, e.g. build.cmd server -name YamaTest
exit /b 1
)
set SERVER_NAME=%~2
shift
shift
goto :parse_args
)
echo Unknown argument: %~1
shift
goto :parse_args
:run
echo.
echo Building SimpleRemoter: %CONFIG% ^| %PLATFORM%
if not "%SERVER_NAME%"=="" echo Server name: %SERVER_NAME%
echo.
set NAME_ARG=
if not "%SERVER_NAME%"=="" set NAME_ARG=-ServerName "%SERVER_NAME%"
powershell -ExecutionPolicy Bypass -File "%SCRIPT_DIR%build.ps1" -Config %CONFIG% -Platform %PLATFORM% %EXTRA_ARGS% %NAME_ARG%
if %errorlevel% neq 0 (
echo.
echo Build FAILED!
pause
exit /b 1
)
echo.
pause