aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPřemysl Eric Janouch <p@janouch.name>2021-07-05 23:42:51 +0200
committerPřemysl Eric Janouch <p@janouch.name>2021-07-05 23:42:51 +0200
commit66bc3f1c2ccb1407ec09d6339c41577fcea0ce67 (patch)
treedbd43191d335c7b1806538cf5ce91c4759d25426
parent0646cea12690900ed7bcf5dbdcfb5a058a202cba (diff)
downloadnncmpp-66bc3f1c2ccb1407ec09d6339c41577fcea0ce67.tar.gz
nncmpp-66bc3f1c2ccb1407ec09d6339c41577fcea0ce67.tar.xz
nncmpp-66bc3f1c2ccb1407ec09d6339c41577fcea0ce67.zip
Expand the comment on spectrum frequency filtering
-rw-r--r--nncmpp.c13
1 files changed, 11 insertions, 2 deletions
diff --git a/nncmpp.c b/nncmpp.c
index 61c109f..9902d9d 100644
--- a/nncmpp.c
+++ b/nncmpp.c
@@ -769,9 +769,18 @@ spectrum_init (struct spectrum *s, char *format, int bars, struct error **e)
// Discard frequencies above 20 kHz, which take up a constant ratio
// of all bins, given by the sampling rate. A more practical/efficient
- // solution would be to just handle 96/192/... kHz as bitshifts.
+ // solution would be to just handle 96/192/... kHz rates as bitshifts.
//
- // Trying to filter out sub-20 Hz frequencies would be even more wasteful.
+ // Filtering out sub-20 Hz frequencies would be even more wasteful than
+ // this wild DFT size, so we don't even try. While we may just shift
+ // the lowest used bin easily within the extra range provided by this
+ // extension (the Nyquist is usually above 22 kHz, and it hardly matters
+ // if we go a bit beyond 20 kHz in the last bin), for a small number of bars
+ // the first bin already includes audible frequencies, and even for larger
+ // numbers it wouldn't be too accurate. An exact solution would require
+ // having the amount of bins be strictly a factor of Nyquist / 20 (stemming
+ // from the equation 20 = Nyquist / bins). Since log2(44100 / 2 / 20) > 10,
+ // it would be fairly expensive, and somewhat slowly updating. Always.
double audible_ratio = s->sampling_rate / 2. / 20000;
s->bins = ceil (necessary_bins * MAX (audible_ratio, 1));
s->useful_bins = s->bins / 2;