Files
client/scripts/lib/app-audio-tone.ps1
T
omar e6464bc4ed feat: checkpoint account-free client workflows and source-matched UI
Preserve accumulated client implementation since v0.1.4, including local identities, multi-server state, chat, administration, audio and streaming controls. Refine official-source layout, original artwork, responsive composer overflow, settings navigation and chat scroll anchoring.

Current verification: Node suite passes; isolated packaged chat and responsive control smokes pass without device capture. Native core is reused, not rebuilt in this pass. Strict whole-screen visual parity remains incomplete; no 1:1 or cross-platform acceptance claim. Local checkpoint only; no release or push.
2026-11-01 19:43:18 +03:00

54 lines
3.3 KiB
PowerShell

param(
[ValidateRange(100, 10000)][int]$Frequency = 440,
[ValidateRange(-1, 65535)][int]$DeviceId = -1,
[switch]$IsolatedEndpointConfirmed
)
$ErrorActionPreference = 'Stop'
if ($DeviceId -lt 0 -or -not $IsolatedEndpointConfirmed) {
throw 'No isolated test endpoint confirmed. Refusing audible/default-output tone playback.'
}
# DeviceId must identify an explicitly confirmed nonphysical/isolated test endpoint.
# Never selects the default endpoint, changes volume, or changes OS routing.
Add-Type -TypeDefinition @'
using System;
using System.Runtime.InteropServices;
public static class AppAudioTone {
[StructLayout(LayoutKind.Sequential, Pack=2)] struct Format {
public ushort tag, channels; public uint rate, bytes; public ushort align, bits, extra;
}
[StructLayout(LayoutKind.Sequential)] struct Header {
public IntPtr data; public uint length, recorded; public UIntPtr user; public uint flags, loops; public IntPtr next; public UIntPtr reserved;
}
[DllImport("winmm.dll")] static extern uint waveOutOpen(out IntPtr handle, uint device, ref Format format, IntPtr callback, IntPtr instance, uint flags);
[DllImport("winmm.dll")] static extern uint waveOutPrepareHeader(IntPtr handle, IntPtr header, uint size);
[DllImport("winmm.dll")] static extern uint waveOutWrite(IntPtr handle, IntPtr header, uint size);
[DllImport("winmm.dll")] static extern uint waveOutReset(IntPtr handle);
[DllImport("winmm.dll")] static extern uint waveOutUnprepareHeader(IntPtr handle, IntPtr header, uint size);
[DllImport("winmm.dll")] static extern uint waveOutClose(IntPtr handle);
static void Check(uint code) { if(code != 0) throw new Exception("waveOut error " + code); }
public static void Run(int frequency, uint deviceId) {
const int rate = 48000, frames = rate * 60;
short[] pcm = new short[frames * 2];
for(int i = 0; i < frames; i++) { short sample = (short)(327 * Math.Sin(2 * Math.PI * frequency * i / rate)); pcm[i*2] = sample; pcm[i*2+1] = sample; }
GCHandle memory = GCHandle.Alloc(pcm, GCHandleType.Pinned);
IntPtr device = IntPtr.Zero, header = IntPtr.Zero;
uint size = (uint)Marshal.SizeOf(typeof(Header)); bool prepared = false;
try {
Format format = new Format { tag=1, channels=2, rate=rate, bytes=rate*4, align=4, bits=16, extra=0 };
Check(waveOutOpen(out device, deviceId, ref format, IntPtr.Zero, IntPtr.Zero, 0));
header = Marshal.AllocHGlobal((int)size);
Marshal.StructureToPtr(new Header { data=memory.AddrOfPinnedObject(), length=(uint)(pcm.Length*2) }, header, false);
Check(waveOutPrepareHeader(device, header, size)); prepared=true;
Check(waveOutWrite(device, header, size));
Console.WriteLine("{\"ready\":true,\"pid\":" + System.Diagnostics.Process.GetCurrentProcess().Id + ",\"frequency\":" + frequency + "}"); Console.Out.Flush();
Console.Read();
} finally {
if(device != IntPtr.Zero) { waveOutReset(device); if(prepared) waveOutUnprepareHeader(device, header, size); waveOutClose(device); }
if(header != IntPtr.Zero) Marshal.FreeHGlobal(header);
memory.Free();
}
}
}
'@
[AppAudioTone]::Run($Frequency, [uint32]$DeviceId)