summaryrefslogtreecommitdiffstats
path: root/gst-libs
diff options
context:
space:
mode:
authorThomas Vander Stichele <thomas@apestaart.org>2001-12-21 10:12:38 +0000
committerThomas Vander Stichele <thomas@apestaart.org>2001-12-21 10:12:38 +0000
commit2504f9e1b4ba28ab02f5f7c238952e62cbdebd15 (patch)
treec9f67e93578515f82a395de0c3d36a6796b33eab /gst-libs
parent99b237bf25dfe13d4d398832c114174f8355d8ac (diff)
downloadgst-plugins-bad-2504f9e1b4ba28ab02f5f7c238952e62cbdebd15.tar.gz
gst-plugins-bad-2504f9e1b4ba28ab02f5f7c238952e62cbdebd15.tar.bz2
gst-plugins-bad-2504f9e1b4ba28ab02f5f7c238952e62cbdebd15.zip
audio library
Original commit message from CVS: audio library
Diffstat (limited to 'gst-libs')
-rw-r--r--gst-libs/audio/Makefile.am14
-rw-r--r--gst-libs/audio/gstaudio.c152
-rw-r--r--gst-libs/audio/gstaudio.h109
3 files changed, 275 insertions, 0 deletions
diff --git a/gst-libs/audio/Makefile.am b/gst-libs/audio/Makefile.am
new file mode 100644
index 00000000..20a53764
--- /dev/null
+++ b/gst-libs/audio/Makefile.am
@@ -0,0 +1,14 @@
+filterdir = $(libdir)/gst
+
+filter_LTLIBRARIES = libgstaudio.la
+
+libgstaudio_la_SOURCES = gstaudio.c
+
+libgstaudioincludedir = $(includedir)/gst/libs/gstaudio
+libgstaudioinclude_HEADERS = gstaudio.h
+
+libgstaudio_la_LIBADD = $(GST_LIBS)
+libgstaudio_la_CFLAGS = $(GST_CFLAGS) -finline-functions -ffast-math
+# FIXME is this needed?
+## from merge, kept for reference
+## libgstaudio_la_CFLAGS = -O2 $(FOMIT_FRAME_POINTER) -finline-functions -ffast-math $(GLIB_CFLAGS) $(XML_CFLAGS) $(GST_CFLAGS)
diff --git a/gst-libs/audio/gstaudio.c b/gst-libs/audio/gstaudio.c
new file mode 100644
index 00000000..c18d6c6e
--- /dev/null
+++ b/gst-libs/audio/gstaudio.c
@@ -0,0 +1,152 @@
+/* Gnome-Streamer
+ * Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#include "gstaudio.h"
+
+int
+gst_audio_frame_byte_size (GstPad* pad)
+{
+/* calculate byte size of an audio frame
+ * this should be moved closer to the gstreamer core
+ * and be implemented for every mime type IMO
+ * returns 0 if there's an error, or the byte size if everything's ok
+ */
+
+ int width = 0;
+ int channels = 0;
+
+ GstCaps *caps = NULL;
+
+ /* get caps of pad */
+ caps = GST_PAD_CAPS (pad);
+
+ if (caps == NULL)
+ /* ERROR: could not get caps of pad */
+ return 0;
+
+ width = gst_caps_get_int (caps, "width");
+ channels = gst_caps_get_int (caps, "channels");
+ return (width / 8) * channels;
+}
+
+long
+gst_audio_frame_length (GstPad* pad, GstBuffer* buf)
+/* calculate length of buffer in frames
+ * this should be moved closer to the gstreamer core
+ * and be implemented for every mime type IMO
+ * returns 0 if there's an error, or the number of frames if everything's ok
+ */
+{
+ int frame_byte_size = 0;
+
+ frame_byte_size = gst_audio_frame_byte_size (pad);
+ if (frame_byte_size == 0)
+ /* error */
+ return 0;
+ /* FIXME: this function assumes the buffer size to be a whole multiple
+ * of the frame byte size
+ */
+ return GST_BUFFER_SIZE (buf) / frame_byte_size;
+}
+
+long
+gst_audio_frame_rate (GstPad *pad)
+/*
+ * calculate frame rate (based on caps of pad)
+ * returns 0 if failed, rate if success
+ */
+{
+ GstCaps *caps = NULL;
+
+ /* get caps of pad */
+ caps = GST_PAD_CAPS (pad);
+
+ if (caps == NULL)
+ /* ERROR: could not get caps of pad */
+ return 0;
+ else
+ return gst_caps_get_int (caps, "rate");
+}
+
+double
+gst_audio_length (GstPad* pad, GstBuffer* buf)
+{
+/* calculate length in seconds
+ * of audio buffer buf
+ * based on capabilities of pad
+ */
+
+ long bytes = 0;
+ int width = 0;
+ int channels = 0;
+ long rate = 0L;
+
+ double length;
+
+ GstCaps *caps = NULL;
+
+ /* get caps of pad */
+ caps = GST_PAD_CAPS (pad);
+ if (caps == NULL)
+ {
+ /* ERROR: could not get caps of pad */
+ length = 0.0;
+ }
+ else
+ {
+ bytes = GST_BUFFER_SIZE (buf);
+ width = gst_caps_get_int (caps, "width");
+ channels = gst_caps_get_int (caps, "channels");
+ rate = gst_caps_get_int (caps, "rate");
+
+ length = (bytes * 8.0) / (double) (rate * channels * width);
+ }
+ return length;
+}
+
+long
+gst_audio_highest_sample_value (GstPad* pad)
+/* calculate highest possible sample value
+ * based on capabilities of pad
+ */
+{
+ gboolean is_signed = FALSE;
+ gint width = 0;
+ GstCaps *caps = NULL;
+
+ caps = GST_PAD_CAPS (pad);
+ // FIXME : Please change this to a better warning method !
+ if (caps == NULL)
+ printf ("WARNING: gstaudio: could not get caps of pad !\n");
+ width = gst_caps_get_int (caps, "width");
+ is_signed = gst_caps_get_boolean (caps, "signed");
+ if (is_signed) --width;
+ /* example : 16 bit, signed : samples between -32768 and 32767 */
+ return ((long) (1 << width));
+}
+
+gboolean
+gst_audio_is_buffer_framed (GstPad* pad, GstBuffer* buf)
+/* check if the buffer size is a whole multiple of the frame size */
+{
+ if (GST_BUFFER_SIZE (buf) % gst_audio_frame_byte_size (pad) == 0)
+ return TRUE;
+ else
+ return FALSE;
+}
diff --git a/gst-libs/audio/gstaudio.h b/gst-libs/audio/gstaudio.h
new file mode 100644
index 00000000..09ef3ec7
--- /dev/null
+++ b/gst-libs/audio/gstaudio.h
@@ -0,0 +1,109 @@
+/* Gnome-Streamer
+ * Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
+ * Library <2001> Thomas Vander Stichele <thomas@apestaart.org>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#include <gst/gst.h>
+
+/* for people that are looking at this source: the purpose of these defines is
+ * to make GstCaps a bit easier, in that you don't have to know all of the
+ * properties that need to be defined. you can just use these macros. currently
+ * (8/01) the only plugins that use these are the passthrough, speed, volume,
+ * and [de]interleave plugins. so. these are for convenience only, and do not
+ * specify the 'limits' of gstreamer. you might also use these definitions as a
+ * base for making your own caps, if need be.
+ *
+ * for example, to make a source pad that can output mono streams of either
+ * float or int:
+
+ template = gst_padtemplate_new
+ ("sink", GST_PAD_SINK, GST_PAD_ALWAYS,
+ gst_caps_append(gst_caps_new ("sink_int", "audio/raw",
+ GST_AUDIO_INT_PAD_TEMPLATE_PROPS),
+ gst_caps_new ("sink_float", "audio/raw",
+ GST_AUDIO_FLOAT_MONO_PAD_TEMPLATE_PROPS)),
+ NULL);
+
+ srcpad = gst_pad_new_from_template(template,"src");
+
+ * Andy Wingo, 18 August 2001 */
+
+#define GST_AUDIO_INT_PAD_TEMPLATE_PROPS \
+ gst_props_new (\
+ "format", GST_PROPS_STRING ("int"),\
+ "law", GST_PROPS_INT (0),\
+ "endianness", GST_PROPS_INT (G_BYTE_ORDER),\
+ "signed", GST_PROPS_LIST (\
+ GST_PROPS_BOOLEAN (TRUE),\
+ GST_PROPS_BOOLEAN(FALSE)\
+ ),\
+ "width", GST_PROPS_LIST (GST_PROPS_INT(8), GST_PROPS_INT(16)),\
+ "depth", GST_PROPS_LIST (GST_PROPS_INT(8), GST_PROPS_INT(16)),\
+ "rate", GST_PROPS_INT_RANGE (4000, 96000),\
+ "channels", GST_PROPS_INT_RANGE (1, G_MAXINT),\
+ NULL)
+
+#define GST_AUDIO_INT_MONO_PAD_TEMPLATE_PROPS \
+ gst_props_new (\
+ "format", GST_PROPS_STRING ("int"),\
+ "law", GST_PROPS_INT (0),\
+ "endianness", GST_PROPS_INT (G_BYTE_ORDER),\
+ "signed", GST_PROPS_LIST (\
+ GST_PROPS_BOOLEAN (TRUE),\
+ GST_PROPS_BOOLEAN(FALSE)\
+ ),\
+ "width", GST_PROPS_LIST (GST_PROPS_INT(8), GST_PROPS_INT(16)),\
+ "depth", GST_PROPS_LIST (GST_PROPS_INT(8), GST_PROPS_INT(16)),\
+ "rate", GST_PROPS_INT_RANGE (4000, 96000),\
+ "channels", GST_PROPS_INT (1),\
+ NULL)
+
+#define GST_AUDIO_FLOAT_MONO_PAD_TEMPLATE_PROPS \
+ gst_props_new (\
+ "format", GST_PROPS_STRING ("float"),\
+ "layout", GST_PROPS_STRING ("gfloat"),\
+ "intercept", GST_PROPS_FLOAT (0.0),\
+ "slope", GST_PROPS_FLOAT (1.0),\
+ "rate", GST_PROPS_INT_RANGE (4000, 96000),\
+ "channels", GST_PROPS_INT (1),\
+ NULL)
+
+/*
+ * this library defines and implements some helper functions for audio
+ * handling
+ */
+
+/* get byte size of audio frame (based on caps of pad */
+int gst_audio_frame_byte_size (GstPad* pad);
+
+/* get length in frames of buffer */
+long gst_audio_frame_length (GstPad* pad, GstBuffer* buf);
+
+/* get frame rate based on caps */
+long gst_audio_frame_rate (GstPad *pad);
+
+/* calculate length in seconds of audio buffer buf based on caps of pad */
+double gst_audio_length (GstPad* pad, GstBuffer* buf);
+
+/* calculate highest possible sample value based on capabilities of pad */
+long gst_audio_highest_sample_value (GstPad* pad);
+
+/* check if the buffer size is a whole multiple of the frame size */
+gboolean gst_audio_is_buffer_framed (GstPad* pad, GstBuffer* buf);
+
+