summaryrefslogtreecommitdiffstats
path: root/gst/spectrum
diff options
context:
space:
mode:
authorSebastian Dröge <slomo@circular-chaos.org>2007-11-06 12:23:35 +0000
committerSebastian Dröge <slomo@circular-chaos.org>2007-11-06 12:23:35 +0000
commitf75f427ec1bed660b20372065c4a93deca9eeaad (patch)
tree2daa65a1c725e14004e4609b9d7ebc4224786062 /gst/spectrum
parent6edf8c43268488ad21d5ba50e02ebc533c6c12f9 (diff)
gst/spectrum/demo-audiotest.c: Use autoaudiosink instead of alsasink and use a sine wave.
Original commit message from CVS: * gst/spectrum/demo-audiotest.c: (main): Use autoaudiosink instead of alsasink and use a sine wave. * gst/spectrum/gstspectrum.c: Fix the magnitude calculation.
Diffstat (limited to 'gst/spectrum')
-rw-r--r--gst/spectrum/gstspectrum.c18
1 files changed, 11 insertions, 7 deletions
diff --git a/gst/spectrum/gstspectrum.c b/gst/spectrum/gstspectrum.c
index d9899b49..f2f654a6 100644
--- a/gst/spectrum/gstspectrum.c
+++ b/gst/spectrum/gstspectrum.c
@@ -517,10 +517,12 @@ process_s##width (GstSpectrum *spectrum, const gint##width *samples) \
\
/* Calculate magnitude in db */ \
for (i = 0; i < spectrum->bands; i++) { \
- gdouble val = (gdouble) freqdata[i].r * (gdouble) freqdata[i].r \
- + (gdouble) freqdata[i].i * (gdouble) freqdata[i].i; \
- val = sqrt (val); \
- val = 20.0 * log10 (val / max); \
+ gdouble val; \
+ val = (gdouble) freqdata[i].r * (gdouble) freqdata[i].r; \
+ val += (gdouble) freqdata[i].i * (gdouble) freqdata[i].i; \
+ val *= nfft; \
+ val /= max*max; \
+ val = 10.0 * log10 (val); \
if (val > spectrum->threshold) \
val -= spectrum->threshold; \
else \
@@ -583,9 +585,11 @@ process_f##width (GstSpectrum *spectrum, const g##type *samples) \
\
/* Calculate magnitude in db */ \
for (i = 0; i < spectrum->bands; i++) { \
- gdouble val = freqdata[i].r * freqdata[i].r + freqdata[i].i * freqdata[i].i; \
- val = sqrt (val); \
- val = 20.0 * log10 (val / nfft); \
+ gdouble val; \
+ val = freqdata[i].r * freqdata[i].r; \
+ val += freqdata[i].i * freqdata[i].i; \
+ val /= nfft; \
+ val = 10.0 * log10 (val); \
if (val > spectrum->threshold) \
val -= spectrum->threshold; \
else \