UNPKG

dualsense-ts

Version:

The natural interface for your DualSense and DualSense Access controllers, with Typescript

146 lines 5.11 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Audio = void 0; const command_1 = require("../hid/command"); /** Audio control state for the DualSense controller */ class Audio { constructor() { /** Headphone volume (0.0–1.0) */ this._headphoneVolume = 1.0; /** Speaker volume (0.0–1.0) */ this._speakerVolume = 1.0; /** Microphone volume (0.0–1.0) */ this._microphoneVolume = 1.0; /** Audio output routing */ this._output = command_1.AudioOutput.Headphone; /** Microphone processing flags */ this._micFlags = 0; /** Microphone input mode */ this._micMode = command_1.MicMode.Default; /** Speaker preamp gain (0–7) */ this._preampGain = 2; /** Beam forming enabled */ this._beamForming = false; /** Per-subsystem mute flags */ this._muteMask = 0; } /** Get headphone volume as a fraction (0.0–1.0) */ get headphoneVolume() { return this._headphoneVolume; } /** Set headphone volume (0.0–1.0) */ setHeadphoneVolume(volume) { this._headphoneVolume = Math.max(0, Math.min(1, volume)); } /** Get speaker volume as a fraction (0.0–1.0) */ get speakerVolume() { return this._speakerVolume; } /** Set speaker volume (0.0–1.0) */ setSpeakerVolume(volume) { this._speakerVolume = Math.max(0, Math.min(1, volume)); } /** Get microphone volume as a fraction (0.0–1.0) */ get microphoneVolume() { return this._microphoneVolume; } /** Set microphone volume (0.0–1.0) */ setMicrophoneVolume(volume) { this._microphoneVolume = Math.max(0, Math.min(1, volume)); } /** Get audio output routing */ get output() { return this._output; } /** Set audio output routing */ setOutput(output) { this._output = output; } /** Get speaker preamp gain (0–7) */ get preampGain() { return this._preampGain; } /** Set speaker preamp gain (0–7) and optional beam forming */ setPreamp(gain, beamForming) { this._preampGain = Math.max(0, Math.min(7, gain | 0)); if (beamForming !== undefined) { this._beamForming = beamForming; } } /** Whether beam forming is enabled */ get beamForming() { return this._beamForming; } /** Set microphone source */ setMicSelect(source) { this._micSelect = source; } /** Set microphone processing flags (echo cancellation, noise cancellation) */ setMicFlags(flags) { this._micFlags = flags & (command_1.MicFlag.EchoCancellation | command_1.MicFlag.NoiseCancellation); } /** Set microphone input mode */ setMicMode(mode) { this._micMode = mode; } /** Mute the speaker */ muteSpeaker(muted = true) { if (muted) this._muteMask |= command_1.PowerSave.MuteSpeaker; else this._muteMask &= ~command_1.PowerSave.MuteSpeaker; } /** Mute the headphone output */ muteHeadphone(muted = true) { if (muted) this._muteMask |= command_1.PowerSave.MuteHeadphone; else this._muteMask &= ~command_1.PowerSave.MuteHeadphone; } /** Mute the microphone */ muteMicrophone(muted = true) { if (muted) this._muteMask |= command_1.PowerSave.MuteMicrophone; else this._muteMask &= ~command_1.PowerSave.MuteMicrophone; } /** Whether the speaker is muted */ get speakerMuted() { return (this._muteMask & command_1.PowerSave.MuteSpeaker) !== 0; } /** Whether headphone output is muted */ get headphoneMuted() { return (this._muteMask & command_1.PowerSave.MuteHeadphone) !== 0; } /** Whether the microphone is muted */ get microphoneMuted() { return (this._muteMask & command_1.PowerSave.MuteMicrophone) !== 0; } // --- Output loop helpers --- /** Raw headphone volume byte (0x00–0x7F) */ get headphoneVolumeRaw() { return Math.round(this._headphoneVolume * 0x7f); } /** Raw speaker volume byte (0x00–0x64) */ get speakerVolumeRaw() { return Math.round(this._speakerVolume * 0x64); } /** Raw microphone volume byte (0x00–0x40) */ get microphoneVolumeRaw() { return Math.round(this._microphoneVolume * 0x40); } /** Composed audio flags byte */ get audioFlags() { return (this._micSelect ?? 0) | this._micFlags | this._output | this._micMode; } /** Power save mute mask */ get powerSaveFlags() { return this._muteMask; } /** Change-detection key for the output loop */ toKey() { return `${this._headphoneVolume},${this._speakerVolume},${this._microphoneVolume},${this._output},${String(this._micSelect)},${this._micFlags},${String(this._micMode)},${this._preampGain},${String(this._beamForming)},${this._muteMask}`; } } exports.Audio = Audio; //# sourceMappingURL=audio.js.map