mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-11-03 16:09:39 +00:00
gst/spectrum/demo-osssrc.c: Use more defines
Original commit message from CVS: * 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.
This commit is contained in:
parent
f1163bb16d
commit
ba185a300c
4 changed files with 31 additions and 17 deletions
11
ChangeLog
11
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>
|
2006-09-08 Tim-Philipp Müller <tim at centricular dot net>
|
||||||
|
|
||||||
* configure.ac:
|
* configure.ac:
|
||||||
|
|
|
@ -27,6 +27,8 @@
|
||||||
|
|
||||||
#define DEFAULT_AUDIOSRC "alsasrc"
|
#define DEFAULT_AUDIOSRC "alsasrc"
|
||||||
#define SPECT_BANDS 256
|
#define SPECT_BANDS 256
|
||||||
|
#define SPECT_WIDTH (SPECT_BANDS)
|
||||||
|
#define SPECT_HEIGHT 64
|
||||||
|
|
||||||
static GtkWidget *drawingarea = NULL;
|
static GtkWidget *drawingarea = NULL;
|
||||||
|
|
||||||
|
@ -42,17 +44,17 @@ static void
|
||||||
draw_spectrum (guchar * data)
|
draw_spectrum (guchar * data)
|
||||||
{
|
{
|
||||||
gint i;
|
gint i;
|
||||||
GdkRectangle rect = { 0, 0, SPECT_BANDS, 50 };
|
GdkRectangle rect = { 0, 0, SPECT_WIDTH, SPECT_HEIGHT };
|
||||||
|
|
||||||
if (!drawingarea)
|
if (!drawingarea)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
gdk_window_begin_paint_rect (drawingarea->window, &rect);
|
gdk_window_begin_paint_rect (drawingarea->window, &rect);
|
||||||
gdk_draw_rectangle (drawingarea->window, drawingarea->style->black_gc,
|
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++) {
|
for (i = 0; i < SPECT_BANDS; i++) {
|
||||||
gdk_draw_rectangle (drawingarea->window, drawingarea->style->white_gc,
|
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);
|
gdk_window_end_paint (drawingarea->window);
|
||||||
}
|
}
|
||||||
|
@ -120,7 +122,7 @@ main (int argc, char *argv[])
|
||||||
G_CALLBACK (on_window_destroy), NULL);
|
G_CALLBACK (on_window_destroy), NULL);
|
||||||
|
|
||||||
drawingarea = gtk_drawing_area_new ();
|
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_container_add (GTK_CONTAINER (appwindow), drawingarea);
|
||||||
gtk_widget_show_all (appwindow);
|
gtk_widget_show_all (appwindow);
|
||||||
|
|
||||||
|
|
|
@ -213,10 +213,8 @@ gst_spectrum_init (GstSpectrum * spectrum, GstSpectrumClass * g_class)
|
||||||
spectrum->len = 1024; /* 2 ^ (base+1) */
|
spectrum->len = 1024; /* 2 ^ (base+1) */
|
||||||
|
|
||||||
spectrum->loud = g_malloc (spectrum->len * sizeof (gint16));
|
spectrum->loud = g_malloc (spectrum->len * sizeof (gint16));
|
||||||
spectrum->im = g_malloc (spectrum->len * sizeof (gint16));
|
spectrum->im = g_malloc0 (spectrum->len * sizeof (gint16));
|
||||||
memset (spectrum->im, 0, spectrum->len * sizeof (gint16));
|
spectrum->re = g_malloc0 (spectrum->len * sizeof (gint16));
|
||||||
spectrum->re = g_malloc (spectrum->len * sizeof (gint16));
|
|
||||||
memset (spectrum->re, 0, spectrum->len * sizeof (gint16));
|
|
||||||
spectrum->spect = g_malloc (spectrum->bands * sizeof (guchar));
|
spectrum->spect = g_malloc (spectrum->bands * sizeof (guchar));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -235,6 +233,11 @@ gst_spectrum_dispose (GObject * object)
|
||||||
g_free (spectrum->loud);
|
g_free (spectrum->loud);
|
||||||
g_free (spectrum->spect);
|
g_free (spectrum->spect);
|
||||||
|
|
||||||
|
spectrum->re = NULL;
|
||||||
|
spectrum->im = NULL;
|
||||||
|
spectrum->loud = NULL;
|
||||||
|
spectrum->spect = NULL;
|
||||||
|
|
||||||
G_OBJECT_CLASS (parent_class)->dispose (object);
|
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);
|
structure = gst_caps_get_structure (in, 0);
|
||||||
gst_structure_get_int (structure, "rate", &filter->rate);
|
gst_structure_get_int (structure, "rate", &filter->rate);
|
||||||
gst_structure_get_int (structure, "width", &filter->width);
|
|
||||||
gst_structure_get_int (structure, "channels", &filter->channels);
|
gst_structure_get_int (structure, "channels", &filter->channels);
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
|
@ -397,17 +399,17 @@ gst_spectrum_transform_ip (GstBaseTransform * trans, GstBuffer * in)
|
||||||
GstClockTime blktime =
|
GstClockTime blktime =
|
||||||
GST_FRAMES_TO_CLOCK_TIME (spectrum->len, spectrum->rate);
|
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));
|
gst_adapter_push (spectrum->adapter, gst_buffer_ref (in));
|
||||||
/* required number of bytes */
|
/* 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 */
|
/* FIXME: 4.0 was 2.0 before, but that include the mirrored spectrum */
|
||||||
step = (gfloat) spectrum->len / (spectrum->bands * 4.0);
|
step = (gfloat) spectrum->len / (spectrum->bands * 4.0);
|
||||||
|
|
||||||
while (gst_adapter_available (spectrum->adapter) > wanted) {
|
while (gst_adapter_available (spectrum->adapter) > wanted) {
|
||||||
|
|
||||||
GST_DEBUG (" adapter loop");
|
GST_LOG (" adapter loop");
|
||||||
samples = (gint16 *) gst_adapter_take (spectrum->adapter, wanted);
|
samples = (gint16 *) gst_adapter_take (spectrum->adapter, wanted);
|
||||||
|
|
||||||
for (i = 0, j = 0; i < spectrum->len; i++) {
|
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);
|
spectrum->re[i] = (gint16) (acc / spectrum->channels);
|
||||||
}
|
}
|
||||||
|
|
||||||
GST_DEBUG (" fft");
|
GST_LOG (" fft");
|
||||||
|
|
||||||
gst_spectrum_window (spectrum->re, spectrum->len);
|
gst_spectrum_window (spectrum->re, spectrum->len);
|
||||||
gst_spectrum_fix_fft (spectrum->re, spectrum->im, spectrum->base, FALSE);
|
gst_spectrum_fix_fft (spectrum->re, spectrum->im, spectrum->base, FALSE);
|
||||||
gst_spectrum_fix_loud (spectrum->loud, spectrum->re, spectrum->im,
|
gst_spectrum_fix_loud (spectrum->loud, spectrum->re, spectrum->im,
|
||||||
spectrum->len, 0);
|
spectrum->len, 0);
|
||||||
|
|
||||||
GST_DEBUG (" resampling");
|
GST_LOG (" resampling");
|
||||||
|
|
||||||
/* resample to requested number of bands */
|
/* resample to requested number of bands */
|
||||||
for (i = 0, pos = 0.0; i < spectrum->bands; i++, pos += step) {
|
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;
|
spect[i] = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
GST_DEBUG (" send message?");
|
GST_LOG (" send message?");
|
||||||
//ret = gst_pad_push (spectrum->srcpad, outbuf);
|
//ret = gst_pad_push (spectrum->srcpad, outbuf);
|
||||||
spectrum->num_frames += spectrum->len;
|
spectrum->num_frames += spectrum->len;
|
||||||
endtime += blktime;
|
endtime += blktime;
|
||||||
|
@ -448,7 +450,7 @@ gst_spectrum_transform_ip (GstBaseTransform * trans, GstBuffer * in)
|
||||||
if (spectrum->message) {
|
if (spectrum->message) {
|
||||||
GstMessage *m = gst_spectrum_message_new (spectrum, endtime);
|
GstMessage *m = gst_spectrum_message_new (spectrum, endtime);
|
||||||
|
|
||||||
GST_DEBUG (" sending message");
|
GST_LOG (" sending message");
|
||||||
gst_element_post_message (GST_ELEMENT (spectrum), m);
|
gst_element_post_message (GST_ELEMENT (spectrum), m);
|
||||||
}
|
}
|
||||||
spectrum->num_frames = 0;
|
spectrum->num_frames = 0;
|
||||||
|
|
|
@ -56,7 +56,6 @@ struct _GstSpectrum {
|
||||||
* since last emit */
|
* since last emit */
|
||||||
|
|
||||||
gint rate; /* caps variables */
|
gint rate; /* caps variables */
|
||||||
gint width;
|
|
||||||
gint channels;
|
gint channels;
|
||||||
|
|
||||||
/* <private> */
|
/* <private> */
|
||||||
|
|
Loading…
Reference in a new issue