Nota — a free DAW for macOS, Windows and Linux. No subscription, no account — just open it and make music.
C# audioaudio-unitavaloniacpp20cross-platformdawdigital-audio-workstationdspjucelinux-audiomcp-servermidimusicmusic-productionpiano-rollplugin-hostsequencersynthesizervstvst3
Add cpu and sound check
Egor Khindikaynen045daebcd5cb
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex e37f02e6..de0c29c9 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -18,6 +18,12 @@ Entry categories: `Added`, `Changed`, `Fixed`, `Removed`.## [Unreleased]+### Added+- Preferences → Audio: **Play test tone** plays a 440 Hz sine through the master so you can+ check the output, and **CPU check** measures the audio load for 5 seconds and tells you+ whether the current buffer size leaves enough headroom. The test tone now fades in and out+ instead of clicking.+### Changed- The audio engine now has its own version (starting at 0.2.5, shown in About) instead of afixed 0.1.0; it's bumped with each release that changes the engine.diff --git a/src/managed/Nota.App/PreferencesWindow.cs b/src/managed/Nota.App/PreferencesWindow.csindex 43dc8531..bd13f6ad 100644--- a/src/managed/Nota.App/PreferencesWindow.cs+++ b/src/managed/Nota.App/PreferencesWindow.cs@@ -6,7 +6,8 @@// Audio device / sample-rate / buffer are persisted natively (audio.json) and// applied by restarting the backend (MainWindowViewModel.ApplyAudioSettings);// toolbar side persists via SettingsViewModel; scan folders via the catalog.-// Test-tone / CPU-check are flagged (NaBadge) — not wired.+// Test: a 440 Hz sine through the master (toggle; stopped when the pane or window+// goes away) and a 5 s CPU check sampling the live DSP load + dropout count.using System;using System.Collections.Generic;@@ -62,6 +63,11 @@ public sealed class PreferencesWindow : NotaWindowprivate bool _loading;private TextBlock? _audioStatus;+ private const double TestToneHz = 440;+ private const int CpuCheckTicks = 50; // × 100 ms = 5 s+ private bool _toneOn;+ private DispatcherTimer? _cpuTimer;+private readonly ContentControl _content = new();private readonly List<Border> _navItems = new();@@ -92,11 +98,13 @@ public sealed class PreferencesWindow : NotaWindowgrid.Children.Add(_content);SetBody(grid);+ Closed += (_, _) => StopTests();Select(0);}private void Select(int index){+ StopTests(); // the Audio pane is rebuilt on every visit — don't leave a tone / check orphanedfor (int i = 0; i < _navItems.Count; i++){bool on = i == index;@@ -191,18 +199,92 @@ public sealed class PreferencesWindow : NotaWindowbody.Children.Add(DividerLine());body.Children.Add(SectionLabel("TEST"));- var testTone = DisabledChip("Play test tone");- var cpu = DisabledChip("CPU check");- body.Children.Add(new StackPanel- {- Orientation = Orientation.Horizontal, Spacing = 10, VerticalAlignment = VerticalAlignment.Center,- Children = { testTone, new NaBadge { Kind = NaBadgeKind.NA }, cpu, new NaBadge { Kind = NaBadgeKind.NA } },- });+ body.Children.Add(TestToneRow(engine));+ body.Children.Add(CpuCheckRow(engine));_loading = false;return body;}+ private Control TestToneRow(IAudioEngine engine)+ {+ var button = new Button { Content = "Play test tone", MinWidth = 120 };+ var note = Caption($"{TestToneHz:0}\u2009Hz sine at −14\u2009dBFS, through the master.");+ button.Click += (_, _) =>+ {+ SetTone(!_toneOn);+ button.Content = _toneOn ? "Stop test tone" : "Play test tone";+ button.Classes.Set("primary", _toneOn);+ };+ return TestRow("Output check", button, note);+ }++ private void SetTone(bool on)+ {+ if (_main is null || _toneOn == on) return;+ _toneOn = on;+ if (on) _main.Engine.SetFrequency((float)TestToneHz);+ _main.Engine.SetTestTone(on);+ }++ // Samples the smoothed DSP load (render time / block budget) every 100 ms for 5 s and+ // counts dropouts over the same window, then gives a verdict for the current buffer size.+ private Control CpuCheckRow(IAudioEngine engine)+ {+ var button = new Button { Content = "CPU check", MinWidth = 120 };+ var result = Caption("Measures audio-thread load for 5\u2009s — play your project for a real-world figure.");+ button.Click += (_, _) =>+ {+ if (_cpuTimer is not null) return;+ if (engine.NegotiatedSampleRate <= 0)+ {+ result.Text = "Audio device not running.";+ result.Foreground = NotaPalette.Danger;+ return;+ }+ button.IsEnabled = false;+ result.Foreground = TextTertiary;+ int ticks = 0, xrunsStart = engine.XrunCount;+ double sum = 0, peak = 0;+ _cpuTimer = new DispatcherTimer { Interval = TimeSpan.FromMilliseconds(100) };+ _cpuTimer.Tick += (_, _) =>+ {+ double load = Math.Clamp(engine.CpuLoad, 0, 1);+ sum += load; peak = Math.Max(peak, load); ticks++;+ if (ticks < CpuCheckTicks)+ {+ result.Text = $"Measuring… {(CpuCheckTicks - ticks + 9) / 10}\u2009s · now {load * 100:0}\u2009%";+ return;+ }+ StopCpuCheck();+ button.IsEnabled = true;+ int xruns = Math.Max(0, engine.XrunCount - xrunsStart);+ var (verdict, brush) = peak > 0.9 || xruns > 0+ ? ("overloaded — raise the buffer size", NotaPalette.Danger)+ : peak > 0.7+ ? ("close to the limit — consider a larger buffer", NotaPalette.Warning)+ : ("plenty of headroom", Success);+ result.Text = $"Avg {sum / ticks * 100:0}\u2009% · peak {peak * 100:0}\u2009% · {xruns} dropout{(xruns == 1 ? "" : "s")} — {verdict}";+ result.Foreground = brush;+ };+ result.Text = "Measuring… 5\u2009s";+ _cpuTimer.Start();+ };+ return TestRow("Performance", button, result);+ }++ private void StopCpuCheck()+ {+ _cpuTimer?.Stop();+ _cpuTimer = null;+ }++ private void StopTests()+ {+ SetTone(false);+ StopCpuCheck();+ }+private void Apply(){if (_loading || _main is null) return;@@ -667,13 +749,18 @@ public sealed class PreferencesWindow : NotaWindow// ---- helpers ----------------------------------------------------------- private Border DisabledChip(string text) => new()+ // Label · button · caption; the caption gets the remaining width so a long result wraps.+ private static Control TestRow(string label, Button button, TextBlock caption){- // Disabled (almanac § States): panel ground, hairline edge, Ink 6 — no opacity.- Background = NotaPalette.Panel, BorderBrush = NotaPalette.GraphBorder, BorderThickness = new Thickness(1), CornerRadius = NotaRadius.Tile,- Padding = new Thickness(12, 4), VerticalAlignment = VerticalAlignment.Center,- Child = new TextBlock { Text = text, FontSize = 11, Foreground = NotaPalette.TextDisabled },- };+ var grid = new Grid { ColumnDefinitions = new ColumnDefinitions("130,Auto,*") };+ grid.Children.Add(new TextBlock { Text = label, FontSize = 11, Foreground = TextSecondary, VerticalAlignment = VerticalAlignment.Center });+ Grid.SetColumn(button, 1);+ grid.Children.Add(button);+ caption.Margin = new Thickness(10, 0, 0, 0);+ Grid.SetColumn(caption, 2);+ grid.Children.Add(caption);+ return grid;+ }private static TextBlock SectionLabel(string text) => new(){diff --git a/src/native/nota.engine/src/Engine.h b/src/native/nota.engine/src/Engine.hindex 5c3a7fc5..fccc8c02 100644--- a/src/native/nota.engine/src/Engine.h+++ b/src/native/nota.engine/src/Engine.h@@ -1076,6 +1076,7 @@ private:bool toneEnabled_ = false;float frequency_ = 440.0f;double tonePhase_ = 0.0;+ float toneLevel_ = 0.0f; // 0..1 fade so start/stop don't clickint64_t lastBeatEmitted_ = -1;int clickRemaining_ = 0;double clickPhase_ = 0.0;diff --git a/src/native/nota.engine/src/Engine_Render.cpp b/src/native/nota.engine/src/Engine_Render.cppindex 89a95262..4677e010 100644--- a/src/native/nota.engine/src/Engine_Render.cpp+++ b/src/native/nota.engine/src/Engine_Render.cpp@@ -1194,10 +1194,13 @@ void Engine::renderMetronome(float* out, int32_t numFrames, double blockStartSamvoid Engine::renderTone(float* out, int32_t numFrames) {const double sr = transport_.sampleRate();- if (!toneEnabled_ || sr <= 0.0) { tonePhase_ = 0.0; return; }+ const float target = toneEnabled_ ? 1.0f : 0.0f;+ if (sr <= 0.0 || (target == 0.0f && toneLevel_ == 0.0f)) { tonePhase_ = 0.0; return; }const double inc = kTwoPi * static_cast<double>(frequency_) / sr;+ const float step = static_cast<float>(1.0 / (sr * 0.01)); // ~10 ms fade in/outfor (int32_t i = 0; i < numFrames; ++i) {- const float s = static_cast<float>(std::sin(tonePhase_)) * kToneGain;+ toneLevel_ = target > toneLevel_ ? std::min(target, toneLevel_ + step) : std::max(target, toneLevel_ - step);+ const float s = static_cast<float>(std::sin(tonePhase_)) * kToneGain * toneLevel_;out[i * 2] += s; out[i * 2 + 1] += s;tonePhase_ += inc;if (tonePhase_ >= kTwoPi) tonePhase_ -= kTwoPi;