diff --git a/QuanshengDock/Audio/Sound.cs b/QuanshengDock/Audio/Sound.cs index bd3af51..67d94cc 100644 --- a/QuanshengDock/Audio/Sound.cs +++ b/QuanshengDock/Audio/Sound.cs @@ -3,6 +3,7 @@ using QuanshengDock.General; using QuanshengDock.View; using System; +using System.CodeDom; using System.Collections.Generic; using System.ComponentModel; using System.Diagnostics; @@ -32,6 +33,8 @@ public static class Sound private static SineStream? sineStream2 = null; private static readonly ViewModel volume = VM.Get("Volume"); + private static readonly ViewModel boost = VM.Get("Boost"); + private static readonly ViewModel micLevel = VM.Get("MicLevel"); private static readonly ViewModel passthrough = VM.Get("Passthrough"); private static readonly ViewModel latency = VM.Get("AudioLatency"); private static readonly ViewModel buffers = VM.Get("AudioBuffers"); @@ -125,6 +128,30 @@ public static void StartTone2(int outputID, int toneFreq) } } + private static double AmplifyPCM16(byte[] buffer, int len, double amp) + { + double lev = 0.0; + unsafe + { + fixed(byte* bptr = buffer) + { + short* shorts = (short*)bptr; + len >>= 1; + for (int i = 0; i < len; i++) + { + double d = (shorts[i] * amp).Clamp(short.MinValue, short.MaxValue); + if (d > 0) + { + d /= 327.68; + if (d > lev) lev = d; + } + shorts[i] = (short)d; + } + } + } + return lev; + } + public static void Start() { using (radioRxAudio) @@ -190,6 +217,8 @@ public static void Start() { if (txPassthrough.BufferedDuration.TotalSeconds > latency.Value / 500.0) txPassthrough.ClearBuffer(); + micFilter[micCnt++ % micFilter.Length] = AmplifyPCM16(e.Buffer, e.BytesRecorded, boost.Value); + micLevel.Value = micFilter.Average(); txPassthrough.AddSamples(e.Buffer, 0, e.BytesRecorded); }; radioTxAudio.Play(); @@ -198,8 +227,11 @@ public static void Start() catch { } } } + private static double[] micFilter = new double[3]; + private static int micCnt = 0; } + public class SineStream : WaveStream { private readonly WaveFormat format; diff --git a/QuanshengDock/Data/Context.cs b/QuanshengDock/Data/Context.cs index d966ab8..76ed5e9 100644 --- a/QuanshengDock/Data/Context.cs +++ b/QuanshengDock/Data/Context.cs @@ -47,6 +47,10 @@ public class Context public ViewModel VSize { get; } = new(1.0, nameof(VSize)); public ViewModel FStretch { get; } = new(0.23, nameof(FStretch)); public ViewModel Volume { get; } = new(0.75, nameof(Volume), true); + public ViewModel Boost { get; } = new(1.0, nameof(Boost), true); + public ViewModel MicLevel { get; } = new(1.0, nameof(MicLevel)); + public ViewModel MicBarHeight { get; } = new(20.0, nameof(MicBarHeight)); + public ViewModel MicBarShown { get; } = new(true, nameof(MicBarHeight), true); public ViewModel LCDFont { get; } = new(nameof(LCDFont)); public ViewModel LCDBoldFont { get; } = new(nameof(LCDBoldFont)); public ViewModel LCDFontName { get; } = new("Consolas", nameof(LCDFontName), true); @@ -216,6 +220,7 @@ public Context() SpecSteps.ForceUpdate++; WaterfallCol1.ForceUpdate++; + MicBarHeight.SetConverter(() => MicBarShown.Value ? 20.0 : 0.0, MicBarShown); TaskBar.SetConverter(() => Title.Value.Length > 0 ? Title.Value : "QD", Title); XWatchName.SetConverter(() => XWatch.Value?" WR":string.Empty, XWatch); XScanLCD.SetConverter(() => BusyXVFO.Value ? "SCAN" : string.Empty, BusyXVFO); diff --git a/QuanshengDock/ExtendedVFO/XVFO.cs b/QuanshengDock/ExtendedVFO/XVFO.cs index 443d7a7..085302d 100644 --- a/QuanshengDock/ExtendedVFO/XVFO.cs +++ b/QuanshengDock/ExtendedVFO/XVFO.cs @@ -15,7 +15,7 @@ namespace QuanshengDock.ExtendedVFO { public enum PttMode { - None=0, Normal = 1, VOX = 2, External = 4 + None = 0, Normal = 1, VOX = 2, External = 4 } public static class XVFO @@ -118,9 +118,12 @@ public static void ToggleMicGain(int dir) micGain.Value = i; } - public static void ToggleVOX() + public static void ToggleVOX(int newVal = -1) { - vox.Value = vox.Value != 0 ? 0 : 1; + if (newVal == -1) + vox.Value = vox.Value != 0 ? 0 : 1; + else + vox.Value = newVal; VOX.Init(); } diff --git a/QuanshengDock/MainWindow.xaml b/QuanshengDock/MainWindow.xaml index 8b13e1f..8f9378f 100644 --- a/QuanshengDock/MainWindow.xaml +++ b/QuanshengDock/MainWindow.xaml @@ -112,9 +112,20 @@ + + + + + + + + + + + @@ -131,7 +142,7 @@ - + @@ -179,7 +190,7 @@ - + @@ -334,7 +345,7 @@ - + diff --git a/QuanshengDock/QuanshengDock.csproj b/QuanshengDock/QuanshengDock.csproj index 677e69e..233559f 100644 --- a/QuanshengDock/QuanshengDock.csproj +++ b/QuanshengDock/QuanshengDock.csproj @@ -7,6 +7,7 @@ true True quansheng.ico + true diff --git a/QuanshengDock/Settings/SettingsWindow.xaml b/QuanshengDock/Settings/SettingsWindow.xaml index 3784aaf..857bfad 100644 --- a/QuanshengDock/Settings/SettingsWindow.xaml +++ b/QuanshengDock/Settings/SettingsWindow.xaml @@ -71,6 +71,7 @@ + @@ -104,26 +105,27 @@ - - - - - - - - - - - + + + + + + + + + + + + - + - + by -nicsure- 2024   @@ -136,28 +138,29 @@ - - - - - - - - - + + + + + + + + + + - + - + - + @@ -221,17 +224,18 @@ - - - - - - - - - - - + + + + + + + + + + + + @@ -239,32 +243,32 @@ - - + + - + - + - - + + - - - - - - + + + + + + - + @@ -274,7 +278,7 @@ -