summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTim-Philipp Müller <tim@centricular.net>2005-07-21 16:37:30 +0000
committerTim-Philipp Müller <tim@centricular.net>2005-07-21 16:37:30 +0000
commit2f99c988d85da3bd6f917324312de6f60152ccc6 (patch)
treef7866005b7d6e7ae8f1518e1b290457aafa243c2
parent59a14a7a1037425fa0f90f648e44f2add10d7f6b (diff)
downloadgst-plugins-bad-2f99c988d85da3bd6f917324312de6f60152ccc6.tar.gz
gst-plugins-bad-2f99c988d85da3bd6f917324312de6f60152ccc6.tar.bz2
gst-plugins-bad-2f99c988d85da3bd6f917324312de6f60152ccc6.zip
gst/spectrum/demo-osssrc.c: Use 32 for the graph since it's the dimension of the drawing window; use proper buffersiz...
Original commit message from CVS: Reviewed by: Tim-Philipp Müller <tim at centricular dot net> * gst/spectrum/demo-osssrc.c: (spectrum_chain), (main): Use 32 for the graph since it's the dimension of the drawing window; use proper buffersize (bytes != samples); connect delete-event to gtk_main_quit. * gst/spectrum/gstspectrum.c: (gst_spectrum_class_init), (gst_spectrum_chain): Specify max. width of 1024 in property param spec; spec_base must be 10 instead of 8, since it's the exponent of the N pased to the FFT (2^10=1024); memcpy the buffer in the mono case (fixes a crash).
-rw-r--r--ChangeLog16
-rw-r--r--gst/spectrum/demo-osssrc.c22
-rw-r--r--gst/spectrum/gstspectrum.c26
3 files changed, 49 insertions, 15 deletions
diff --git a/ChangeLog b/ChangeLog
index aa1440d0..5dfb964d 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,19 @@
+2005-07-21 Paolo Borelli <pborelli at katamail dot com>
+
+ Reviewed by: Tim-Philipp Müller <tim at centricular dot net>
+
+ * gst/spectrum/demo-osssrc.c: (spectrum_chain), (main):
+ Use 32 for the graph since it's the dimension of the
+ drawing window; use proper buffersize (bytes != samples);
+ connect delete-event to gtk_main_quit.
+
+ * gst/spectrum/gstspectrum.c: (gst_spectrum_class_init),
+ (gst_spectrum_chain):
+ Specify max. width of 1024 in property param spec;
+ spec_base must be 10 instead of 8, since it's the
+ exponent of the N pased to the FFT (2^10=1024);
+ memcpy the buffer in the mono case (fixes a crash).
+
2005-07-21 Zaheer Abbas Merali <zaheerabbas at merali dot org>
* configure.ac:
diff --git a/gst/spectrum/demo-osssrc.c b/gst/spectrum/demo-osssrc.c
index b51e8c2a..0312df87 100644
--- a/gst/spectrum/demo-osssrc.c
+++ b/gst/spectrum/demo-osssrc.c
@@ -15,12 +15,12 @@ spectrum_chain (GstElement * sink, GstBuffer * buf, GstPad * pad,
gpointer unused)
{
gint i;
- guchar *data = buf->data;
- GdkRectangle rect = { 0, 0, GST_BUFFER_SIZE (buf), 25 };
+ guchar *data = GST_BUFFER_DATA (buf);
+ GdkRectangle rect = { 0, 0, GST_BUFFER_SIZE (buf), 32 };
gdk_window_begin_paint_rect (drawingarea->window, &rect);
gdk_draw_rectangle (drawingarea->window, drawingarea->style->black_gc,
- TRUE, 0, 0, GST_BUFFER_SIZE (buf), 25);
+ TRUE, 0, 0, GST_BUFFER_SIZE (buf), 32);
for (i = 0; i < GST_BUFFER_SIZE (buf); i++) {
gdk_draw_rectangle (drawingarea->window, drawingarea->style->white_gc,
TRUE, i, 32 - data[i], 1, data[i]);
@@ -33,7 +33,7 @@ main (int argc, char *argv[])
{
GstElement *bin;
GstElement *src, *spectrum, *sink;
-
+ GstCaps *filtercaps;
GtkWidget *appwindow;
gst_init (&argc, &argv);
@@ -42,7 +42,8 @@ main (int argc, char *argv[])
bin = gst_pipeline_new ("bin");
src = gst_element_factory_make (DEFAULT_AUDIOSRC, "src");
- g_object_set (G_OBJECT (src), "buffersize", (gulong) 1024, NULL);
+ g_object_set (G_OBJECT (src), "buffersize", (gulong) 1024 * sizeof (gint16),
+ NULL);
spectrum = gst_element_factory_make ("spectrum", "spectrum");
g_object_set (G_OBJECT (spectrum), "width", 256, NULL);
sink = gst_element_factory_make ("fakesink", "sink");
@@ -50,9 +51,18 @@ main (int argc, char *argv[])
g_signal_connect (sink, "handoff", G_CALLBACK (spectrum_chain), NULL);
gst_bin_add_many (GST_BIN (bin), src, spectrum, sink, NULL);
- gst_element_link_many (src, spectrum, sink, NULL);
+
+ filtercaps =
+ gst_caps_new_simple ("audio/x-raw-int", "rate", G_TYPE_INT, 11025, NULL);
+ if (!gst_element_link_filtered (src, spectrum, filtercaps))
+ g_error ("Linking source to spectrum failed\n");
+ gst_caps_free (filtercaps);
+ if (!gst_element_link (spectrum, sink))
+ g_error ("Linking spectrum to sink failed\n");
appwindow = gtk_window_new (GTK_WINDOW_TOPLEVEL);
+ g_signal_connect (appwindow, "delete-event", G_CALLBACK (gtk_main_quit),
+ NULL);
drawingarea = gtk_drawing_area_new ();
gtk_drawing_area_size (GTK_DRAWING_AREA (drawingarea), 256, 32);
gtk_container_add (GTK_CONTAINER (appwindow), drawingarea);
diff --git a/gst/spectrum/gstspectrum.c b/gst/spectrum/gstspectrum.c
index 37267cfd..c84f0e5b 100644
--- a/gst/spectrum/gstspectrum.c
+++ b/gst/spectrum/gstspectrum.c
@@ -25,6 +25,7 @@
#include "gstspectrum.h"
#define SPECTRUM_DEFAULT_WIDTH 75
+#define SPECTRUM_MAX_WIDTH 1024 /* limited by the current FFT code */
/* elementfactory information */
static GstElementDetails gst_spectrum_details =
@@ -120,7 +121,7 @@ gst_spectrum_class_init (GstSpectrumClass * klass)
gobject_class->set_property = gst_spectrum_set_property;
g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_WIDTH,
- g_param_spec_int ("width", "width", "width", 1, G_MAXINT,
+ g_param_spec_int ("width", "width", "width", 1, SPECTRUM_MAX_WIDTH,
SPECTRUM_DEFAULT_WIDTH, G_PARAM_WRITABLE));
}
@@ -177,6 +178,7 @@ gst_spectrum_chain (GstPad * pad, GstData * _data)
gint spec_base, spec_len;
gint16 *re, *im, *loud;
gint16 *samples;
+ gint samples_n;
gint step, pos, i;
guint8 *spect;
GstBuffer *newbuf;
@@ -188,28 +190,34 @@ gst_spectrum_chain (GstPad * pad, GstData * _data)
spectrum = GST_SPECTRUM (GST_OBJECT_PARENT (pad));
samples = (gint16 *) GST_BUFFER_DATA (buf);
+ samples_n = GST_BUFFER_SIZE (buf) / (spectrum->channels * sizeof (gint16));
- spec_base = 8;
+ spec_base = 10; /* 2^10 = 1024 */
spec_len = 1024;
+ /* zero pad if samples_n < spec_len */
+ re = g_new0 (gint16, spec_len);
im = g_new0 (gint16, spec_len);
+
loud = g_new0 (gint16, spec_len);
if (spectrum->channels == 2) {
- re = g_malloc (spec_len * sizeof (gint16));
- for (i = 0; i < spec_len; i++)
+ for (i = 0; i < MIN (spec_len, samples_n); i++)
re[i] = (samples[(i * 2)] + samples[(i * 2) + 1]) >> 1;
} else {
- re = samples;
+ re = memcpy (re, samples, MIN (spec_len, samples_n) * sizeof (gint16));
}
- gst_spectrum_window (re, spec_len);
+ /* do not apply the window to the zero padding */
+ gst_spectrum_window (re, MIN (spec_len, samples_n));
+
gst_spectrum_fix_fft (re, im, spec_base, FALSE);
gst_spectrum_fix_loud (loud, re, im, spec_len, 0);
- if (re != samples)
- g_free (re);
+
+ g_free (re);
g_free (im);
- step = spec_len / (spectrum->width * 2);
+
+ step = spec_len / spectrum->width;
spect = g_new (guint8, spectrum->width);
for (i = 0, pos = 0; i < spectrum->width; i++, pos += step) {
if (loud[pos] > -60)