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
This commit is contained in:
1 parent
d987941e57
commit
3ae54c808e
5 files changed
+190
-36
No files matched your search
@@ -1,5 +1,5 @@
|
||||
# SimpleRemoter Build Script
|
||||
# Usage: .\build.ps1 [-Config Release|Debug] [-Platform x64|x86|all] [-ServerOnly] [-ClientOnly] [-Clean] [-Publish]
|
||||
# Usage: .\build.ps1 [-Config Release|Debug] [-Platform x64|x86|all] [-ServerOnly] [-ClientOnly] [-Clean] [-Publish] [-ServerName NAME]
|
||||
#
|
||||
# Requirements:
|
||||
# - Visual Studio 2019 or 2022
|
||||
@@ -19,7 +19,12 @@ param(
|
||||
[switch]$Clean, # Clean before build
|
||||
[switch]$Publish, # Publish mode: rebuild all deps + x64 Release + UPX compress
|
||||
[switch]$GoServer, # Build Go fallback server (server/go) -> Bin/YamaGo_x64.exe
|
||||
[switch]$GoServerLinux # Cross-compile the Go server for Linux -> Bin/server_linux_amd64
|
||||
[switch]$GoServerLinux, # Cross-compile the Go server for Linux -> Bin/server_linux_amd64
|
||||
|
||||
# 服务端输出名,默认 Yama(-> Bin\Yama_x64.exe)。vcxproj 里输出名是
|
||||
# $(SolutionDir)Bin\$(TargetName)_<platform><ext>,所以这里覆盖 TargetName 即可。
|
||||
# 用途:Release 服务端正在运行、Bin\Yama_x64.exe 被占用时,编译到另一个名字。
|
||||
[string]$ServerName = ""
|
||||
)
|
||||
|
||||
$ErrorActionPreference = "Stop"
|
||||
@@ -28,6 +33,23 @@ $rootDir = $PSScriptRoot
|
||||
$binDir = Join-Path $rootDir "Bin"
|
||||
$upxPath = Join-Path $rootDir "server\2015Remote\res\3rd\upx.exe"
|
||||
|
||||
# 服务端输出名。vcxproj 把输出写成 $(SolutionDir)Bin\$(TargetName)_<platform><ext>,
|
||||
# 覆盖 TargetName 就能换文件名,不用改工程。默认仍是 Yama -> Bin\Yama_x64.exe,
|
||||
# 行为与以前一致;指定别的名字主要是为了在 Release 服务端运行中
|
||||
# (Bin\Yama_x64.exe 被独占)时还能编译。
|
||||
if ($ServerName) {
|
||||
if ($ServerName -notmatch '^[A-Za-z0-9][A-Za-z0-9_.-]*$') {
|
||||
Write-Host "ERROR: invalid -ServerName '$ServerName'." -ForegroundColor Red
|
||||
Write-Host " Use letters, digits, underscore, dot or dash, and do not start with a symbol." -ForegroundColor Yellow
|
||||
exit 1
|
||||
}
|
||||
if ($ClientOnly) {
|
||||
Write-Host "WARNING: -ServerName does not apply to -ClientOnly (client output is always ghost.exe), ignored." -ForegroundColor Yellow
|
||||
$ServerName = ""
|
||||
}
|
||||
}
|
||||
$serverTargetName = if ($ServerName) { $ServerName } else { "Yama" }
|
||||
|
||||
# Build Go fallback server. No-op (with warning) if Go compiler is not installed.
|
||||
# When -Compress is set, run UPX --best on the output (mirrors C++ publish flow).
|
||||
function Build-GoServer {
|
||||
@@ -289,7 +311,9 @@ function Build-Project {
|
||||
[string]$Project,
|
||||
[string]$Configuration,
|
||||
[string]$Platform,
|
||||
[bool]$ForceClean = $false
|
||||
[bool]$ForceClean = $false,
|
||||
# 额外传给 MSBuild 的 /p: 属性,例如 /p:TargetName=YamaTest
|
||||
[string[]]$ExtraProps = @()
|
||||
)
|
||||
|
||||
# Solution uses x86/x64, projects use Win32/x64 - MSBuild needs solution platform names
|
||||
@@ -307,6 +331,10 @@ function Build-Project {
|
||||
"/v:minimal" # Minimal verbosity
|
||||
)
|
||||
|
||||
if ($ExtraProps.Count -gt 0) {
|
||||
$buildArgs += $ExtraProps
|
||||
}
|
||||
|
||||
if ($Clean -or $ForceClean) {
|
||||
# Use :Rebuild target for single project rebuild
|
||||
$buildArgs[1] = "/t:${Project}:Rebuild"
|
||||
@@ -407,6 +435,9 @@ Write-Host " Config: $Config" -ForegroundColor Cyan
|
||||
Write-Host " Platform: $Platform" -ForegroundColor Cyan
|
||||
Write-Host " VS: $vsYear" -ForegroundColor Cyan
|
||||
Write-Host " Clean: $Clean" -ForegroundColor Cyan
|
||||
if ($ServerName) {
|
||||
Write-Host " Server: $serverTargetName" -ForegroundColor Cyan
|
||||
}
|
||||
if ($Publish) {
|
||||
Write-Host " UPX: Yes" -ForegroundColor Cyan
|
||||
}
|
||||
@@ -426,10 +457,15 @@ if (-not $ServerOnly) {
|
||||
}
|
||||
|
||||
Write-Host ""
|
||||
Write-Host "Step 2: Building server (Yama)..." -ForegroundColor Magenta
|
||||
Write-Host "Step 2: Building server ($serverTargetName)..." -ForegroundColor Magenta
|
||||
|
||||
# 指定了 -ServerName 就覆盖 TargetName,让输出落到 Bin\<名称>_x64.exe,
|
||||
# 从而绕开正在运行的 Bin\Yama_x64.exe(被独占时链接会报 LNK1104)。
|
||||
$serverMsBuildProps = @()
|
||||
if ($ServerName) { $serverMsBuildProps += "/p:TargetName=$ServerName" }
|
||||
|
||||
foreach ($plat in $platforms) {
|
||||
Build-Project -Project $serverProject -Configuration $Config -Platform $plat -ForceClean $Publish
|
||||
Build-Project -Project $serverProject -Configuration $Config -Platform $plat -ForceClean $Publish -ExtraProps $serverMsBuildProps
|
||||
}
|
||||
|
||||
# UPX compression in Publish mode
|
||||
@@ -438,7 +474,7 @@ if ($Publish) {
|
||||
Write-Host ""
|
||||
Write-Host "Step 3: UPX compression..." -ForegroundColor Magenta
|
||||
|
||||
$binPath = Join-Path (Join-Path $rootDir "Bin") "Yama_x64.exe"
|
||||
$binPath = Join-Path (Join-Path $rootDir "Bin") "${serverTargetName}_x64.exe"
|
||||
|
||||
if (-not (Test-Path $upxPath)) {
|
||||
Write-Host "ERROR: UPX not found at $upxPath" -ForegroundColor Red
|
||||
@@ -490,13 +526,13 @@ if ($finalOutput) {
|
||||
# Check both possible output locations (project has custom OutputFile)
|
||||
$suffix = if ($plat -eq "x86") { "_x86" } else { "_x64" }
|
||||
if ($Config -eq "Debug") { $suffix += "d" }
|
||||
$binPath = Join-Path (Join-Path $rootDir "Bin") "Yama$suffix.exe"
|
||||
$binPath = Join-Path (Join-Path $rootDir "Bin") "${serverTargetName}${suffix}.exe"
|
||||
|
||||
$outDir = if ($plat -eq "x86") { "Release" } else { "x64\Release" }
|
||||
if ($Config -eq "Debug") {
|
||||
$outDir = if ($plat -eq "x86") { "Debug" } else { "x64\Debug" }
|
||||
}
|
||||
$stdPath = Join-Path (Join-Path $rootDir $outDir) "Yama.exe"
|
||||
$stdPath = Join-Path (Join-Path $rootDir $outDir) "${serverTargetName}.exe"
|
||||
|
||||
# Prefer Bin output, fallback to standard path
|
||||
$outPath = if (Test-Path $binPath) { $binPath } elseif (Test-Path $stdPath) { $stdPath } else { $null }
|
||||
|
||||
Reference in new issue
Block a user