From f75f427ec1bed660b20372065c4a93deca9eeaad Mon Sep 17 00:00:00 2001 From: =?utf8?q?Sebastian=20Dr=C3=B6ge?= Date: Tue, 6 Nov 2007 12:23:35 +0000 Subject: [PATCH] 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. --- common | 2 +- gst/spectrum/gstspectrum.c | 18 +++++++++++------- tests/examples/spectrum/demo-audiotest.c | 4 ++-- 3 files changed, 14 insertions(+), 10 deletions(-) diff --git a/common b/common index 34d7d64..423e2ea 160000 --- a/common +++ b/common @@ -1 +1 @@ -Subproject commit 34d7d649b972ea4915611a6ed88f01613bf32777 +Subproject commit 423e2ea96b5f79281f4dd20d734bd968b3d95e89 diff --git a/gst/spectrum/gstspectrum.c b/gst/spectrum/gstspectrum.c index d9899b4..f2f654a 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 \ diff --git a/tests/examples/spectrum/demo-audiotest.c b/tests/examples/spectrum/demo-audiotest.c index 8cc8201..05c9f88 100644 --- a/tests/examples/spectrum/demo-audiotest.c +++ b/tests/examples/spectrum/demo-audiotest.c @@ -28,7 +28,7 @@ #include #include -#define DEFAULT_AUDIOSINK "alsasink" +#define DEFAULT_AUDIOSINK "autoaudiosink" static GtkWidget *drawingarea = NULL; static guint spect_height = 64; @@ -126,7 +126,7 @@ main (int argc, char *argv[]) bin = gst_pipeline_new ("bin"); src = gst_element_factory_make ("audiotestsrc", "src"); - g_object_set (G_OBJECT (src), "wave", 1, NULL); + g_object_set (G_OBJECT (src), "wave", 0, NULL); spectrum = gst_element_factory_make ("spectrum", "spectrum"); g_object_set (G_OBJECT (spectrum), "bands", spect_bands, "threshold", -80, -- 2.7.4