Add drum detection for channel A in live capture
- DrumDetector.cs: 3-band onset detection (kick/snare/brass) with adaptive thresholds, per-sub-tick timing within 100ms frames - Kick: low-band onset, 150ms deep thump - Snare: broadband (mid+high) onset, 50ms mid punch - Brass: high-only onset, 10ms buzzy - Priority: kick > snare > brass when multiple hit same sub-tick - Intensity = max (100) on hit, 0 on silence — user limiter scales down - MusicAnalyzer: add BuildMelodyFrame for chB only (pitch+energy) - LiveCapture: chA now from DrumDetector, chB unchanged (melody) - Sub-tick mapping: FFT window position → 0-3 within each 100ms tick
This commit is contained in:
@@ -79,6 +79,33 @@ public static class MusicAnalyzer
|
||||
public readonly List<double> MelodyFreqSamples = new();
|
||||
}
|
||||
|
||||
public static WaveFrame BuildMelodyFrame(TickFeature tf, double maxMelodyEnergy)
|
||||
{
|
||||
double avgEnergy = tf.MelodyCount > 0 ? tf.MelodyEnergy / tf.MelodyCount : 0;
|
||||
double normalizedEnergy = maxMelodyEnergy > 0 ? avgEnergy / maxMelodyEnergy : 0;
|
||||
int melodyIntensity = (int)Math.Round(normalizedEnergy * 80);
|
||||
melodyIntensity = Math.Clamp(melodyIntensity, 0, 100);
|
||||
|
||||
double weightedFreq = 0;
|
||||
double totalWeight = 0;
|
||||
foreach (var f in tf.MelodyFreqSamples)
|
||||
{
|
||||
weightedFreq += f * f;
|
||||
totalWeight += f;
|
||||
}
|
||||
double avgMelodyHz = totalWeight > 0 ? weightedFreq / totalWeight : 500;
|
||||
int estimsMs = MapPitchToPeriod(avgMelodyHz);
|
||||
|
||||
var intB = new[]
|
||||
{
|
||||
(byte)melodyIntensity, (byte)melodyIntensity,
|
||||
(byte)melodyIntensity, (byte)melodyIntensity
|
||||
};
|
||||
var freqB = Freq.Compress4(new[] { estimsMs, estimsMs, estimsMs, estimsMs });
|
||||
|
||||
return new WaveFrame(freqB, intB);
|
||||
}
|
||||
|
||||
public static (WaveFrame chA, WaveFrame chB) BuildWaveFrame(TickFeature tf, double maxFlux, double maxMelodyEnergy)
|
||||
{
|
||||
const int rhythmFreqMs = 150;
|
||||
|
||||
Reference in New Issue
Block a user