Expanded chord detection, real-time tuning, improved FFT

Expanded chord detection to support 9 chord types (maj, min, sus2, sus4, dim, aug, 7, maj7, min7) with updated scoring and voting logic. Added pitch-filtered FFT path for improved tonal analysis. Introduced real-time, per-mode tuning of detection thresholds (harmonicity, separation, vote consensus) via keyboard shortcuts, with HUD display of current values. Refactored chord display and voting logic to handle expanded chord space. Added thread-safe tuning adjustment and helper methods. Overall, improved flexibility, accuracy, and user control for audio analysis.
This commit is contained in:
Michal Vrba
2026-02-13 21:43:24 +01:00
parent b784e91b22
commit 79c6267196
3 changed files with 343 additions and 61 deletions
+70 -2
View File
@@ -26,6 +26,7 @@ public class Game1 : Game
private AudioFeatures _latestFeatures;
private bool _isPaused;
private bool _showHud = true;
private bool _showLegend = true;
private int _fractalPresetIndex;
private int _fps;
private int _frameCounter;
@@ -138,6 +139,11 @@ public class Game1 : Game
_showHud = !_showHud;
}
if (IsPressed(keyboard, Keys.H))
{
_showLegend = !_showLegend;
}
if (IsPressed(keyboard, Keys.Left))
{
_fractalPresetIndex = Math.Max(0, _fractalPresetIndex - 1);
@@ -156,6 +162,46 @@ public class Game1 : Game
_audioCapture.SwitchMode(_currentInputMode);
}
if (IsPressed(keyboard, Keys.OemOpenBrackets))
{
_audioAnalyzer.AdjustChordHarmonicity(_currentInputMode, -0.01f);
}
if (IsPressed(keyboard, Keys.OemCloseBrackets))
{
_audioAnalyzer.AdjustChordHarmonicity(_currentInputMode, +0.01f);
}
if (IsPressed(keyboard, Keys.OemSemicolon))
{
_audioAnalyzer.AdjustChordSeparation(_currentInputMode, -0.005f);
}
if (IsPressed(keyboard, Keys.OemQuotes))
{
_audioAnalyzer.AdjustChordSeparation(_currentInputMode, +0.005f);
}
if (IsPressed(keyboard, Keys.OemComma))
{
_audioAnalyzer.AdjustNoteVoteConsensus(_currentInputMode, -0.01f);
}
if (IsPressed(keyboard, Keys.OemPeriod))
{
_audioAnalyzer.AdjustNoteVoteConsensus(_currentInputMode, +0.01f);
}
if (IsPressed(keyboard, Keys.OemMinus))
{
_audioAnalyzer.AdjustChordVoteConsensus(_currentInputMode, -0.01f);
}
if (IsPressed(keyboard, Keys.OemPlus))
{
_audioAnalyzer.AdjustChordVoteConsensus(_currentInputMode, +0.01f);
}
_latestFeatures = _audioAnalyzer.GetLatestFeatures();
_fpsElapsed += gameTime.ElapsedGameTime;
_frameCounter++;
@@ -184,6 +230,7 @@ public class Game1 : Game
if (_showHud && _spriteBatch is not null && _hudFont is not null && _pixel is not null)
{
var tuning = _audioAnalyzer.GetTuning(_currentInputMode);
_spriteBatch.Begin(samplerState: SamplerState.PointClamp, blendState: BlendState.AlphaBlend);
string modeText = _currentInputMode == AudioInputMode.Microphone ? "MIC" : "SYS";
_hudFont.DrawText(_spriteBatch, _pixel, "MODE " + modeText + " M SWITCH", 12, 10, 2, Color.White);
@@ -199,7 +246,16 @@ public class Game1 : Game
_hudFont.DrawText(_spriteBatch, _pixel, "PAUSED " + (_isPaused ? "YES" : "NO"), 12, 210, 2, Color.White);
_hudFont.DrawText(_spriteBatch, _pixel, "FPS " + _fps, 12, 230, 2, Color.White);
_hudFont.DrawText(_spriteBatch, _pixel, "QUALITY " + _renderQuality + " 1 2 3", 12, 250, 2, Color.White);
_hudFont.DrawText(_spriteBatch, _pixel, "F OR F11 FULLSCREEN R RESIZE", 12, 270, 2, Color.White);
_hudFont.DrawText(_spriteBatch, _pixel, "F OR F11 FULLSCREEN R RESIZE H HELP", 12, 270, 2, Color.White);
_hudFont.DrawText(_spriteBatch, _pixel, "[ ] HARM " + tuning.ChordHarmonicityThreshold.ToString("0.000"), 12, 290, 2, Color.White);
_hudFont.DrawText(_spriteBatch, _pixel, "; ' SEP " + tuning.ChordSeparationThreshold.ToString("0.000"), 12, 310, 2, Color.White);
_hudFont.DrawText(_spriteBatch, _pixel, ", . NCONS " + tuning.NoteVoteConsensus.ToString("0.000"), 12, 330, 2, Color.White);
_hudFont.DrawText(_spriteBatch, _pixel, "- + CCONS " + tuning.ChordVoteConsensus.ToString("0.000"), 12, 350, 2, Color.White);
if (_showLegend)
{
_hudFont.DrawText(_spriteBatch, _pixel, "LEGEND SPACE PAUSE TAB HUD M INPUT <- -> PRESET", 12, 370, 2, Color.White);
_hudFont.DrawText(_spriteBatch, _pixel, "TUNING [ ] HARM ; ' SEP , . NOTE CONS - + CHORD CONS", 12, 390, 2, Color.White);
}
_spriteBatch.End();
}
@@ -290,7 +346,19 @@ public class Game1 : Game
return "-";
}
return chordType == 1 ? root + " MIN" : root + " MAJ";
return chordType switch
{
0 => root + " MAJ",
1 => root + " MIN",
2 => root + " SUS2",
3 => root + " SUS4",
4 => root + " DIM",
5 => root + " AUG",
6 => root + " 7",
7 => root + " MAJ7",
8 => root + " MIN7",
_ => root + " MAJ"
};
}
private void ToggleFullScreen()