summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ChangeLog11
-rw-r--r--gst/spectrum/demo-osssrc.c10
-rw-r--r--gst/spectrum/gstspectrum.c26
-rw-r--r--gst/spectrum/gstspectrum.h1
4 files changed, 31 insertions, 17 deletions
diff --git a/ChangeLog b/ChangeLog
index 30a4f243..17e2a97b 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+2006-09-11 Stefan Kost <ensonic@users.sf.net>
+
+ * gst/spectrum/demo-osssrc.c: (draw_spectrum), (main):
+ Use more defines
+
+ * gst/spectrum/gstspectrum.c: (gst_spectrum_init),
+ (gst_spectrum_dispose), (gst_spectrum_set_caps),
+ (gst_spectrum_transform_ip):
+ * gst/spectrum/gstspectrum.h:
+ Apply some of the spectrum cleanup changes suggested in #348085.
+
2006-09-08 Tim-Philipp Müller <tim at centricular dot net>
* configure.ac:
diff --git a/gst/spectrum/demo-osssrc.c b/gst/spectrum/demo-osssrc.c
index e3d7f7e1..c00db82c 100644
--- a/gst/spectrum/demo-osssrc.c
+++ b/gst/spectrum/demo-osssrc.c
@@ -27,6 +27,8 @@
#define DEFAULT_AUDIOSRC "alsasrc"
#define SPECT_BANDS 256
+#define SPECT_WIDTH (SPECT_BANDS)
+#define SPECT_HEIGHT 64
static GtkWidget *drawingarea = NULL;
@@ -42,17 +44,17 @@ static void
draw_spectrum (guchar * data)
{
gint i;
- GdkRectangle rect = { 0, 0, SPECT_BANDS, 50 };
+ GdkRectangle rect = { 0, 0, SPECT_WIDTH, SPECT_HEIGHT };
if (!drawingarea)
return;
gdk_window_begin_paint_rect (drawingarea->window, &rect);
gdk_draw_rectangle (drawingarea->window, drawingarea->style->black_gc,
- TRUE, 0, 0, SPECT_BANDS, 50);
+ TRUE, 0, 0, SPECT_BANDS, SPECT_HEIGHT);
for (i = 0; i < SPECT_BANDS; i++) {
gdk_draw_rectangle (drawingarea->window, drawingarea->style->white_gc,
- TRUE, i, 64 - data[i], 1, data[i]);
+ TRUE, i, SPECT_HEIGHT - data[i], 1, data[i]);
}
gdk_window_end_paint (drawingarea->window);
}
@@ -120,7 +122,7 @@ main (int argc, char *argv[])
G_CALLBACK (on_window_destroy), NULL);
drawingarea = gtk_drawing_area_new ();
- gtk_widget_set_size_request (drawingarea, SPECT_BANDS, 64);
+ gtk_widget_set_size_request (drawingarea, SPECT_WIDTH, SPECT_HEIGHT);
gtk_container_add (GTK_CONTAINER (appwindow), drawingarea);
gtk_widget_show_all (appwindow);
diff --git a/gst/spectrum/gstspectrum.c b/gst/spectrum/gstspectrum.c
index 35101aff..d03024de 100644
--- a/gst/spectrum/gstspectrum.c
+++ b/gst/spectrum/gstspectrum.c
@@ -213,10 +213,8 @@ gst_spectrum_init (GstSpectrum * spectrum, GstSpectrumClass * g_class)
spectrum->len = 1024; /* 2 ^ (base+1) */
spectrum->loud = g_malloc (spectrum->len * sizeof (gint16));
- spectrum->im = g_malloc (spectrum->len * sizeof (gint16));
- memset (spectrum->im, 0, spectrum->len * sizeof (gint16));
- spectrum->re = g_malloc (spectrum->len * sizeof (gint16));
- memset (spectrum->re, 0, spectrum->len * sizeof (gint16));
+ spectrum->im = g_malloc0 (spectrum->len * sizeof (gint16));
+ spectrum->re = g_malloc0 (spectrum->len * sizeof (gint16));
spectrum->spect = g_malloc (spectrum->bands * sizeof (guchar));
}
@@ -235,6 +233,11 @@ gst_spectrum_dispose (GObject * object)
g_free (spectrum->loud);
g_free (spectrum->spect);
+ spectrum->re = NULL;
+ spectrum->im = NULL;
+ spectrum->loud = NULL;
+ spectrum->spect = NULL;
+
G_OBJECT_CLASS (parent_class)->dispose (object);
}
@@ -335,7 +338,6 @@ gst_spectrum_set_caps (GstBaseTransform * trans, GstCaps * in, GstCaps * out)
structure = gst_caps_get_structure (in, 0);
gst_structure_get_int (structure, "rate", &filter->rate);
- gst_structure_get_int (structure, "width", &filter->width);
gst_structure_get_int (structure, "channels", &filter->channels);
return TRUE;
@@ -397,17 +399,17 @@ gst_spectrum_transform_ip (GstBaseTransform * trans, GstBuffer * in)
GstClockTime blktime =
GST_FRAMES_TO_CLOCK_TIME (spectrum->len, spectrum->rate);
- GST_DEBUG ("transform : %ld bytes", GST_BUFFER_SIZE (in));
+ GST_LOG ("transform : %ld bytes", GST_BUFFER_SIZE (in));
gst_adapter_push (spectrum->adapter, gst_buffer_ref (in));
/* required number of bytes */
- wanted = spectrum->channels * spectrum->len * 2;
+ wanted = spectrum->channels * spectrum->len * sizeof (gint16);
/* FIXME: 4.0 was 2.0 before, but that include the mirrored spectrum */
step = (gfloat) spectrum->len / (spectrum->bands * 4.0);
while (gst_adapter_available (spectrum->adapter) > wanted) {
- GST_DEBUG (" adapter loop");
+ GST_LOG (" adapter loop");
samples = (gint16 *) gst_adapter_take (spectrum->adapter, wanted);
for (i = 0, j = 0; i < spectrum->len; i++) {
@@ -416,14 +418,14 @@ gst_spectrum_transform_ip (GstBaseTransform * trans, GstBuffer * in)
spectrum->re[i] = (gint16) (acc / spectrum->channels);
}
- GST_DEBUG (" fft");
+ GST_LOG (" fft");
gst_spectrum_window (spectrum->re, spectrum->len);
gst_spectrum_fix_fft (spectrum->re, spectrum->im, spectrum->base, FALSE);
gst_spectrum_fix_loud (spectrum->loud, spectrum->re, spectrum->im,
spectrum->len, 0);
- GST_DEBUG (" resampling");
+ GST_LOG (" resampling");
/* resample to requested number of bands */
for (i = 0, pos = 0.0; i < spectrum->bands; i++, pos += step) {
@@ -438,7 +440,7 @@ gst_spectrum_transform_ip (GstBaseTransform * trans, GstBuffer * in)
spect[i] = 0;
}
- GST_DEBUG (" send message?");
+ GST_LOG (" send message?");
//ret = gst_pad_push (spectrum->srcpad, outbuf);
spectrum->num_frames += spectrum->len;
endtime += blktime;
@@ -448,7 +450,7 @@ gst_spectrum_transform_ip (GstBaseTransform * trans, GstBuffer * in)
if (spectrum->message) {
GstMessage *m = gst_spectrum_message_new (spectrum, endtime);
- GST_DEBUG (" sending message");
+ GST_LOG (" sending message");
gst_element_post_message (GST_ELEMENT (spectrum), m);
}
spectrum->num_frames = 0;
diff --git a/gst/spectrum/gstspectrum.h b/gst/spectrum/gstspectrum.h
index 51e2000c..0092f0ba 100644
--- a/gst/spectrum/gstspectrum.h
+++ b/gst/spectrum/gstspectrum.h
@@ -56,7 +56,6 @@ struct _GstSpectrum {
* since last emit */
gint rate; /* caps variables */
- gint width;
gint channels;
/* <private> */