aboutsummaryrefslogtreecommitdiffstats
path: root/libavcodec/audiodsp.c
diff options
context:
space:
mode:
authorMichael Niedermayer <michaelni@gmx.at>2014-06-22 17:58:28 +0200
committerMichael Niedermayer <michaelni@gmx.at>2014-06-22 17:58:28 +0200
commit99497b4683e5054bcdc5b6802a27d717df9e04f3 (patch)
tree130022374c1a92b72288272bd0927ae6ac7d825b /libavcodec/audiodsp.c
parent0dae193d3ecf5d0dc687f5ad708419bf7600de9a (diff)
parent9a9e2f1c8aa4539a261625145e5c1f46a8106ac2 (diff)
downloadffmpeg-99497b4683e5054bcdc5b6802a27d717df9e04f3.tar.gz
Merge commit '9a9e2f1c8aa4539a261625145e5c1f46a8106ac2'
* commit '9a9e2f1c8aa4539a261625145e5c1f46a8106ac2': dsputil: Split audio operations off into a separate context Conflicts: configure libavcodec/takdec.c libavcodec/x86/Makefile libavcodec/x86/dsputil.asm libavcodec/x86/dsputil_init.c libavcodec/x86/dsputil_mmx.c libavcodec/x86/dsputil_x86.h Merged-by: Michael Niedermayer <michaelni@gmx.at>
Diffstat (limited to 'libavcodec/audiodsp.c')
-rw-r--r--libavcodec/audiodsp.c118
1 files changed, 118 insertions, 0 deletions
diff --git a/libavcodec/audiodsp.c b/libavcodec/audiodsp.c
new file mode 100644
index 0000000000..85b5a74947
--- /dev/null
+++ b/libavcodec/audiodsp.c
@@ -0,0 +1,118 @@
+/*
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include <stdint.h>
+
+#include "libavutil/attributes.h"
+#include "libavutil/common.h"
+#include "audiodsp.h"
+
+static inline uint32_t clipf_c_one(uint32_t a, uint32_t mini,
+ uint32_t maxi, uint32_t maxisign)
+{
+ if (a > mini)
+ return mini;
+ else if ((a ^ (1U << 31)) > maxisign)
+ return maxi;
+ else
+ return a;
+}
+
+static void vector_clipf_c_opposite_sign(float *dst, const float *src,
+ float *min, float *max, int len)
+{
+ int i;
+ uint32_t mini = *(uint32_t *) min;
+ uint32_t maxi = *(uint32_t *) max;
+ uint32_t maxisign = maxi ^ (1U << 31);
+ uint32_t *dsti = (uint32_t *) dst;
+ const uint32_t *srci = (const uint32_t *) src;
+
+ for (i = 0; i < len; i += 8) {
+ dsti[i + 0] = clipf_c_one(srci[i + 0], mini, maxi, maxisign);
+ dsti[i + 1] = clipf_c_one(srci[i + 1], mini, maxi, maxisign);
+ dsti[i + 2] = clipf_c_one(srci[i + 2], mini, maxi, maxisign);
+ dsti[i + 3] = clipf_c_one(srci[i + 3], mini, maxi, maxisign);
+ dsti[i + 4] = clipf_c_one(srci[i + 4], mini, maxi, maxisign);
+ dsti[i + 5] = clipf_c_one(srci[i + 5], mini, maxi, maxisign);
+ dsti[i + 6] = clipf_c_one(srci[i + 6], mini, maxi, maxisign);
+ dsti[i + 7] = clipf_c_one(srci[i + 7], mini, maxi, maxisign);
+ }
+}
+
+static void vector_clipf_c(float *dst, const float *src,
+ float min, float max, int len)
+{
+ int i;
+
+ if (min < 0 && max > 0) {
+ vector_clipf_c_opposite_sign(dst, src, &min, &max, len);
+ } else {
+ for (i = 0; i < len; i += 8) {
+ dst[i] = av_clipf(src[i], min, max);
+ dst[i + 1] = av_clipf(src[i + 1], min, max);
+ dst[i + 2] = av_clipf(src[i + 2], min, max);
+ dst[i + 3] = av_clipf(src[i + 3], min, max);
+ dst[i + 4] = av_clipf(src[i + 4], min, max);
+ dst[i + 5] = av_clipf(src[i + 5], min, max);
+ dst[i + 6] = av_clipf(src[i + 6], min, max);
+ dst[i + 7] = av_clipf(src[i + 7], min, max);
+ }
+ }
+}
+
+static int32_t scalarproduct_int16_c(const int16_t *v1, const int16_t *v2,
+ int order)
+{
+ int res = 0;
+
+ while (order--)
+ res += *v1++ **v2++;
+
+ return res;
+}
+
+static void vector_clip_int32_c(int32_t *dst, const int32_t *src, int32_t min,
+ int32_t max, unsigned int len)
+{
+ do {
+ *dst++ = av_clip(*src++, min, max);
+ *dst++ = av_clip(*src++, min, max);
+ *dst++ = av_clip(*src++, min, max);
+ *dst++ = av_clip(*src++, min, max);
+ *dst++ = av_clip(*src++, min, max);
+ *dst++ = av_clip(*src++, min, max);
+ *dst++ = av_clip(*src++, min, max);
+ *dst++ = av_clip(*src++, min, max);
+ len -= 8;
+ } while (len > 0);
+}
+
+av_cold void ff_audiodsp_init(AudioDSPContext *c)
+{
+ c->scalarproduct_int16 = scalarproduct_int16_c;
+ c->vector_clip_int32 = vector_clip_int32_c;
+ c->vector_clipf = vector_clipf_c;
+
+ if (ARCH_ARM)
+ ff_audiodsp_init_arm(c);
+ if (ARCH_PPC)
+ ff_audiodsp_init_ppc(c);
+ if (ARCH_X86)
+ ff_audiodsp_init_x86(c);
+}