summaryrefslogtreecommitdiffstats
path: root/gst-libs/gst/floatcast
diff options
context:
space:
mode:
authorSteve Baker <steve@stevebaker.org>2002-04-26 09:21:14 +0000
committerSteve Baker <steve@stevebaker.org>2002-04-26 09:21:14 +0000
commit893b1ebd1aef84816587c87df665aacd2cdd316e (patch)
treeb10312cf9eef450fffc3fd99c587b047432c730d /gst-libs/gst/floatcast
parentda2189b3d2fad32fa05b7c976f367f7cd73d7c13 (diff)
downloadgst-plugins-bad-893b1ebd1aef84816587c87df665aacd2cdd316e.tar.gz
gst-plugins-bad-893b1ebd1aef84816587c87df665aacd2cdd316e.tar.bz2
gst-plugins-bad-893b1ebd1aef84816587c87df665aacd2cdd316e.zip
adds functions gst_cast_float and gst_cast_double. Will use lrint and lrintf if available and a pure c rounding macro...
Original commit message from CVS: adds functions gst_cast_float and gst_cast_double. Will use lrint and lrintf if available and a pure c rounding macro if not. This is where optimised asm alternatives can be placed - omega, this means you! However you have to prove that your asm version is faster than lrintf ;)
Diffstat (limited to 'gst-libs/gst/floatcast')
-rw-r--r--gst-libs/gst/floatcast/floatcast.h54
1 files changed, 54 insertions, 0 deletions
diff --git a/gst-libs/gst/floatcast/floatcast.h b/gst-libs/gst/floatcast/floatcast.h
new file mode 100644
index 00000000..3a232b76
--- /dev/null
+++ b/gst-libs/gst/floatcast/floatcast.h
@@ -0,0 +1,54 @@
+/* GStreamer
+ * Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
+ * Library <2002> Steve Baker <stevebaker_org@yahoo.co.uk>
+ *
+ * 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.
+ */
+
+#ifndef __FLOATCAST_H__
+#define __FLOATCAST_H__
+
+#include <config.h>
+
+#if (HAVE_LRINT && HAVE_LRINTF)
+
+ /* These defines enable functionality introduced with the 1999 ISO C
+ ** standard. They must be defined before the inclusion of math.h to
+ ** engage them. If optimisation is enabled, these functions will be
+ ** inlined. With optimisation switched off, you have to link in the
+ ** maths library using -lm.
+ */
+
+ #define _ISOC9X_SOURCE 1
+ #define _ISOC99_SOURCE 1
+
+ #define __USE_ISOC9X 1
+ #define __USE_ISOC99 1
+
+ #include <math.h>
+
+ #define gst_cast_float(x) ((gint)lrintf(x))
+ #define gst_cast_double(x) ((gint)lrint(x))
+
+#else
+ /* use a standard c cast, but do rounding correctly */
+ #define gst_cast_float(x) ((x)>=0?(gint)((x)+0.5):(gint)((x)-0.5))
+ #define gst_cast_double(x) ((x)>=0?(gint)((x)+0.5):(gint)((x)-0.5))
+
+#endif
+
+#endif /* __FLOATCAST_H__ */
+