Skip to content

Commit

Permalink
Rename 'radius' → 'dist'
Browse files Browse the repository at this point in the history
  • Loading branch information
AlekseyMartynov committed Sep 12, 2023
1 parent a85a2d6 commit 6a92b03
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
22 changes: 11 additions & 11 deletions Tagging/PeakFinder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,17 @@ float LogMagnitude

class PeakFinder {
public const int
RADIUS_TIME = 45,
RADIUS_FREQ = 9;
DIST_TIME = 45,
DIST_FREQ = 9;

// Peaks per second in a band
const int RATE = 12;

static readonly IReadOnlyList<int> BAND_FREQS = new[] { 250, 520, 1450, 3500, 5500 };

static readonly int
MIN_BIN = Math.Max(Analysis.FreqToBin(BAND_FREQS.Min()), RADIUS_FREQ),
MAX_BIN = Math.Min(Analysis.FreqToBin(BAND_FREQS.Max()), Analysis.BIN_COUNT - RADIUS_FREQ);
MIN_BIN = Math.Max(Analysis.FreqToBin(BAND_FREQS.Min()), DIST_FREQ),
MAX_BIN = Math.Min(Analysis.FreqToBin(BAND_FREQS.Max()), Analysis.BIN_COUNT - DIST_FREQ);

static readonly float
MIN_MAGN_SQUARED = 1f / 512 / 512,
Expand All @@ -42,8 +42,8 @@ public PeakFinder(Analysis analysis) {
}

void Analysis_StripeAddedCallback() {
if(Analysis.StripeCount > 2 * RADIUS_TIME)
Find(Analysis.StripeCount - RADIUS_TIME - 1);
if(Analysis.StripeCount > 2 * DIST_TIME)
Find(Analysis.StripeCount - DIST_TIME - 1);
}

void Find(int stripe) {
Expand All @@ -52,10 +52,10 @@ void Find(int stripe) {
if(Analysis.GetMagnitudeSquared(stripe, bin) < MIN_MAGN_SQUARED)
continue;

if(!IsPeak(stripe, bin, RADIUS_TIME, 0))
if(!IsPeak(stripe, bin, DIST_TIME, 0))
continue;

if(!IsPeak(stripe, bin, 3, RADIUS_FREQ))
if(!IsPeak(stripe, bin, 3, DIST_FREQ))
continue;

AddPeakAt(stripe, bin);
Expand Down Expand Up @@ -109,10 +109,10 @@ float GetLogMagnitude(int stripe, int bin) {
return 18 * 1024 * (1 - MathF.Log(Analysis.GetMagnitudeSquared(stripe, bin)) / LOG_MIN_MAGN_SQUARED);
}

bool IsPeak(int stripe, int bin, int stripeRadius, int binRadius) {
bool IsPeak(int stripe, int bin, int stripeDist, int binDist) {
var center = Analysis.GetMagnitudeSquared(stripe, bin);
for(var s = -stripeRadius; s <= stripeRadius; s++) {
for(var b = -binRadius; b <= binRadius; b++) {
for(var s = -stripeDist; s <= stripeDist; s++) {
for(var b = -binDist; b <= binDist; b++) {
if(s == 0 && b == 0)
continue;
if(Analysis.GetMagnitudeSquared(stripe + s, bin + b) >= center)
Expand Down
2 changes: 1 addition & 1 deletion Test/SignatureComparisonTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ out var refBands
);

// Official signature has more peaks
// Most of them are at edges < RADIUS_TIME
// Most of them are at edges < DIST_TIME

// Possible explanation for padding in official signature
// start - first chunk completes the FFT window so it is immediately ready for analysis
Expand Down

0 comments on commit 6a92b03

Please sign in to comment.