using System.Text.Json;
namespace VoiceCat.App.Models;
///
/// User's send-side voice input preferences — transmission mode, VAD sensitivity, mic input
/// gain, and the push-to-talk key. Persisted to %AppData%\VoiceCat\voice.json, same pattern as
/// and FeedbackSettings: a missing or corrupt file yields defaults
/// rather than throwing. Slider-position values are stored as-is so MainForm can restore the
/// TrackBars directly.
///
public sealed class VoiceSettings
{
/// Transmission mode: 0 = voice activation, 1 = push-to-talk, 2 = always on
/// (matches Interop's VcInputMode).
public int InputMode { get; set; } = 0;
/// VAD sensitivity slider position, 1–100 (default mirrors the designer's 76).
public int VadThresholdSlider { get; set; } = 76;
/// Microphone input gain slider position, 0–300 percent (100 = unity).
public int MicGain { get; set; } = 100;
/// Send-side mic noise reduction (RNNoise) toggle. MIC stream only, mono only;
/// denoises captured mic PCM before input gain and VAD/PTT gate so everyone hears the
/// cleaned signal. Independent of the per-listener receive-side NR.
public bool MicNoiseReduction { get; set; } = false;
/// Capture the mic in stereo (interleaved L/R) instead of mono. Off by default. Real
/// stereo only reaches the wire on a stereo channel; on a mono channel the core folds the mic
/// to mono. Applied when the capture device next starts (Join Voice or an audio restart).
public bool StereoMic { get; set; } = false;
/// Push-to-talk key, stored as the integer value of System.Windows.Forms.Keys.
public int PttKey { get; set; } = (int)Keys.F8;
/// Saved device ID from the last session; null means use the system default.
public string? InputDeviceId { get; set; } = null;
/// Whether the secondary "aux" outgoing stream is enabled. The aux stream is a
/// second hardware input device the client captures itself and feeds to the core via
/// vc_stream_feed_pcm (kind = AUX_DEVICE, external_feed). Lets a user transmit e.g. mic +
/// a line-in at once.
public bool AuxEnabled { get; set; } = false;
/// WASAPI endpoint id of the aux capture device; null = system default capture
/// device. NOTE: this is a WASAPI device id (from ),
/// NOT a core/miniaudio id — the aux device is opened client-side, so the two id spaces differ.
public string? AuxDeviceId { get; set; } = null;
/// Aux input volume slider position, 0–300 percent (100 = unity). Applied client-side
/// to the captured PCM before feeding (the core's input gain is mic-only and global).
public int AuxGain { get; set; } = 100;
private static readonly JsonSerializerOptions JsonOptions = new() { WriteIndented = true };
private static string AppDataDir => Path.Combine(
Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "VoiceCat");
private static string FilePath => Path.Combine(AppDataDir, "voice.json");
public static VoiceSettings Load()
{
try
{
if (!File.Exists(FilePath)) return new VoiceSettings();
string json = File.ReadAllText(FilePath);
return JsonSerializer.Deserialize(json) ?? new VoiceSettings();
}
catch
{
return new VoiceSettings();
}
}
public void Save()
{
Directory.CreateDirectory(AppDataDir);
File.WriteAllText(FilePath, JsonSerializer.Serialize(this, JsonOptions));
}
}