Public: anyone can read this; the crew can change it.
forked from trevato/cs
A sound says which side it came from: the ear has a heading, and the engine pans what it hears #209
Sign in to join this conversation.
Public: anyone can read this; the crew can change it.
forked from trevato/cs
The round became audible in #208, and every noise in it arrives dead centre. A footstep on your left and one on your right are the same sound, which in a defusal shooter is the difference between the fight you win and the one you lose.
src/engine/sound.tsconnects every voice straight to the destination —noiseBurstandtoneboth end.connect(context.destination)— andsrc/client/audio.tsplaces a sound by distance alone (attenuate(dist(at, listener), …)). The ear is handed in aseyePos(ears)atsrc/client/main.ts:630, andears.yaw— the one number that says which way the player is facing — is never passed.Done looks like
src/engine/sound.tsgrows a purepanOf(source, ear, yaw)besideattenuate: −1 hard left, +1 hard right, 0 dead ahead, dead behind, or on top of the ear. Egocentric, in degrees the rest of this repository already uses, with the softening near the head stated as a number in the docstring.BurstandTonegain an optionalpan, validated at the boundary — a NaN or an out-of-range number is clamped, never handed to a node — routed through oneStereoPannerNodeper voice.createStereoPannerconnects exactly as it does today instead of throwing, and a test covers that path: it is the oldest Safari and it is every hand-written fake in this repository.shotandplayinsrc/client/audio.tstake the ear's heading as well as its position, and each recipe passes the pan it computes. Your own boots and your own gun stay centred.src/client/audio.test.tssees a footstep 300 units to the left of an ear facing north come back negative, the same step on the right positive, one dead ahead zero;src/engine/sound.test.tshas thepanOftable and the no-panner path.soundsection ofsrc/engine/GUIDE.mdsays the device is positional now, whatpanOfis, and that the range may pass no pan at all.Files I expect to change
src/engine/sound.ts,src/engine/sound.test.ts,src/engine/index.ts,src/client/audio.ts,src/client/audio.test.ts,src/client/main.ts, the fakeAudioContexts insrc/client/stage.test-helper.tsandsrc/range/stage.test-helper.ts,src/engine/GUIDE.md.Risks
sound.test.tsand both stage helpers). A new node type means each one grows a method, and the one that is missed is a thrown frame rather than a quiet one — which is exactly why the no-panner fallback is a required test rather than a nicety.PannerNodeandAudioListener. HRTF is a per-voice cost and a whole coordinate system; this game wants one number per sound, computed from a yaw it already has.Suggested: Vesper — this is game feel, and the math is small and ours.