Test filter uses a dB graph to show the response graphically
This commit is contained in:
@@ -23,6 +23,7 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
#include <math.h>
|
||||||
#include "sample.h"
|
#include "sample.h"
|
||||||
#include "debug.h"
|
#include "debug.h"
|
||||||
#include "display.h"
|
#include "display.h"
|
||||||
@@ -118,6 +119,26 @@ const char *debug_amplitude(double level)
|
|||||||
return text;
|
return text;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define level2db(level) (20 * log10(level))
|
||||||
|
|
||||||
|
const char *debug_db(double level_db)
|
||||||
|
{
|
||||||
|
static char text[128];
|
||||||
|
int l;
|
||||||
|
|
||||||
|
strcpy(text, ": . : . : . : . : . : . : . : . : ");
|
||||||
|
if (level_db <= 0.0)
|
||||||
|
return text;
|
||||||
|
l = (int)round(level2db(level_db));
|
||||||
|
if (l > 3)
|
||||||
|
return text;
|
||||||
|
if (l < -48)
|
||||||
|
return text;
|
||||||
|
text[l + 48] = '*';
|
||||||
|
|
||||||
|
return text;
|
||||||
|
}
|
||||||
|
|
||||||
void debug_list_cat(void)
|
void debug_list_cat(void)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
@@ -27,6 +27,7 @@
|
|||||||
void _printdebug(const char *file, const char *function, int line, int cat, int level, int chan, const char *fmt, ...) __attribute__ ((__format__ (__printf__, 7, 8)));
|
void _printdebug(const char *file, const char *function, int line, int cat, int level, int chan, const char *fmt, ...) __attribute__ ((__format__ (__printf__, 7, 8)));
|
||||||
|
|
||||||
const char *debug_amplitude(double level);
|
const char *debug_amplitude(double level);
|
||||||
|
const char *debug_db(double level_db);
|
||||||
|
|
||||||
void debug_list_cat(void);
|
void debug_list_cat(void);
|
||||||
int parse_debug_opt(const char *opt);
|
int parse_debug_opt(const char *opt);
|
||||||
|
@@ -13,31 +13,12 @@
|
|||||||
|
|
||||||
static double get_level(double *samples)
|
static double get_level(double *samples)
|
||||||
{
|
{
|
||||||
#if 0
|
|
||||||
int i;
|
|
||||||
double last = 0, envelope = 0;
|
|
||||||
int up = 0;
|
|
||||||
|
|
||||||
for (i = SAMPLERATE/2; i < SAMPLERATE; i++) {
|
|
||||||
if (last < samples[i]) {
|
|
||||||
up = 1;
|
|
||||||
} else if (last > samples[i]) {
|
|
||||||
if (up) {
|
|
||||||
if (last > envelope)
|
|
||||||
envelope = last;
|
|
||||||
}
|
|
||||||
up = 0;
|
|
||||||
}
|
|
||||||
last = samples[i];
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
int i;
|
int i;
|
||||||
double envelope = 0;
|
double envelope = 0;
|
||||||
for (i = SAMPLERATE/2; i < SAMPLERATE; i++) {
|
for (i = SAMPLERATE/2; i < SAMPLERATE; i++) {
|
||||||
if (samples[i] > envelope)
|
if (samples[i] > envelope)
|
||||||
envelope = samples[i];
|
envelope = samples[i];
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
return envelope;
|
return envelope;
|
||||||
}
|
}
|
||||||
@@ -72,7 +53,7 @@ int main(void)
|
|||||||
gen_samples(samples, (double)i);
|
gen_samples(samples, (double)i);
|
||||||
filter_process(&filter_low, samples, SAMPLERATE);
|
filter_process(&filter_low, samples, SAMPLERATE);
|
||||||
level = get_level(samples);
|
level = get_level(samples);
|
||||||
printf("%4d Hz: %.1f dB", i, level2db(level));
|
printf("%s%4d Hz: %.1f dB", debug_db(level), i, level2db(level));
|
||||||
if (i == 1000)
|
if (i == 1000)
|
||||||
printf(" cutoff\n");
|
printf(" cutoff\n");
|
||||||
else if (i == 2000)
|
else if (i == 2000)
|
||||||
@@ -91,7 +72,7 @@ int main(void)
|
|||||||
gen_samples(samples, (double)i);
|
gen_samples(samples, (double)i);
|
||||||
filter_process(&filter_high, samples, SAMPLERATE);
|
filter_process(&filter_high, samples, SAMPLERATE);
|
||||||
level = get_level(samples);
|
level = get_level(samples);
|
||||||
printf("%4d Hz: %.1f dB", i, level2db(level));
|
printf("%s%4d Hz: %.1f dB", debug_db(level), i, level2db(level));
|
||||||
if (i == 2000)
|
if (i == 2000)
|
||||||
printf(" cutoff\n");
|
printf(" cutoff\n");
|
||||||
else if (i == 1000)
|
else if (i == 1000)
|
||||||
@@ -112,7 +93,7 @@ int main(void)
|
|||||||
filter_process(&filter_low, samples, SAMPLERATE);
|
filter_process(&filter_low, samples, SAMPLERATE);
|
||||||
filter_process(&filter_high, samples, SAMPLERATE);
|
filter_process(&filter_high, samples, SAMPLERATE);
|
||||||
level = get_level(samples);
|
level = get_level(samples);
|
||||||
printf("%4d Hz: %.1f dB", i, level2db(level));
|
printf("%s%4d Hz: %.1f dB", debug_db(level), i, level2db(level));
|
||||||
if (i == 1000)
|
if (i == 1000)
|
||||||
printf(" cutoff high\n");
|
printf(" cutoff high\n");
|
||||||
else if (i == 2000)
|
else if (i == 2000)
|
||||||
|
Reference in New Issue
Block a user