summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Sevakis <jethead71@rockbox.org>2011-12-04 18:19:39 +0000
committerMichael Sevakis <jethead71@rockbox.org>2011-12-04 18:19:39 +0000
commita43df152c2adf737208bbeb294a0a13608d3cc43 (patch)
treec0534198745141699a08d9471303744948e51138
parent700e360b612766eb2729597be55c43b5b69bbe7f (diff)
downloadrockbox-a43df152c2adf737208bbeb294a0a13608d3cc43.zip
rockbox-a43df152c2adf737208bbeb294a0a13608d3cc43.tar.gz
rockbox-a43df152c2adf737208bbeb294a0a13608d3cc43.tar.bz2
rockbox-a43df152c2adf737208bbeb294a0a13608d3cc43.tar.xz
Collect the 16-bit signed range sample clipping routines scattered about, which can be optimized on armv6 and create firmware/export/dsp-util.h (for lack of better place right now).
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@31142 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r--apps/codecs.h1
-rw-r--r--apps/codecs/libspc/spc_dsp.c20
-rw-r--r--apps/dsp.c15
-rw-r--r--apps/pcmbuf.c9
-rw-r--r--apps/plugin.h1
-rw-r--r--firmware/export/dsp-util.h51
-rw-r--r--firmware/pcm_mixer.c8
7 files changed, 58 insertions, 47 deletions
diff --git a/apps/codecs.h b/apps/codecs.h
index 527c59a..f1e2a51 100644
--- a/apps/codecs.h
+++ b/apps/codecs.h
@@ -43,6 +43,7 @@
#include "pcm_record.h"
#endif
#include "dsp.h"
+#include "dsp-util.h"
#endif
#include "gcc_extensions.h"
diff --git a/apps/codecs/libspc/spc_dsp.c b/apps/codecs/libspc/spc_dsp.c
index 28e0542..6350c4c 100644
--- a/apps/codecs/libspc/spc_dsp.c
+++ b/apps/codecs/libspc/spc_dsp.c
@@ -57,25 +57,7 @@ void DSP_write( struct Spc_Dsp* this, int i, int data )
}
}
-#if ARM_ARCH >= 6
-/* if ( n < -32768 ) out = -32768; */
-/* if ( n > 32767 ) out = 32767; */
-#define CLAMP16( n ) \
- ({ \
- asm ("ssat %0, #16, %1" \
- : "=r" ( n ) : "r"( n ) ); \
- n; \
- })
-#else
-/* if ( n < -32768 ) out = -32768; */
-/* if ( n > 32767 ) out = 32767; */
-#define CLAMP16( n ) \
-({ \
- if ( (int16_t) n != n ) \
- n = 0x7FFF ^ (n >> 31); \
- n; \
-})
-#endif
+#define CLAMP16( n ) clip_sample_16( n )
#if SPC_BRRCACHE
static void decode_brr( struct Spc_Dsp* this, unsigned start_addr,
diff --git a/apps/dsp.c b/apps/dsp.c
index d9c097a..00de511 100644
--- a/apps/dsp.c
+++ b/apps/dsp.c
@@ -19,15 +19,12 @@
*
****************************************************************************/
#include "config.h"
-
-#include <stdbool.h>
-#include <inttypes.h>
-#include <string.h>
+#include "system.h"
#include <sound.h>
#include "dsp.h"
+#include "dsp-util.h"
#include "eq.h"
#include "kernel.h"
-#include "system.h"
#include "settings.h"
#include "replaygain.h"
#include "tdspeed.h"
@@ -261,14 +258,6 @@ static int32_t release_gain IBSS_ATTR; /* S7.24 format */
static void compressor_process(int count, int32_t *buf[]);
-/* Clip sample to signed 16 bit range */
-static inline int32_t clip_sample_16(int32_t sample)
-{
- if ((int16_t)sample != sample)
- sample = 0x7fff ^ (sample >> 31);
- return sample;
-}
-
#ifdef HAVE_PITCHSCREEN
int32_t sound_get_pitch(void)
{
diff --git a/apps/pcmbuf.c b/apps/pcmbuf.c
index 8135a30..32e1157 100644
--- a/apps/pcmbuf.c
+++ b/apps/pcmbuf.c
@@ -27,6 +27,7 @@
#include "pcm.h"
#include "pcm_mixer.h"
#include "pcmbuf.h"
+#include "dsp-util.h"
#include "playback.h"
#include "codec_thread.h"
@@ -828,14 +829,6 @@ static size_t crossfade_find_buftail(size_t buffer_rem, size_t buffer_need)
return buffer_rem;
}
-/* Clip sample to signed 16 bit range */
-static FORCE_INLINE int32_t clip_sample_16(int32_t sample)
-{
- if ((int16_t)sample != sample)
- sample = 0x7fff ^ (sample >> 31);
- return sample;
-}
-
/* Returns the number of bytes _NOT_ mixed/faded */
static int crossfade_mix_fade(int factor, size_t size, void *buf, size_t *out_index,
unsigned long elapsed, off_t offset)
diff --git a/apps/plugin.h b/apps/plugin.h
index 0ee37bb..e2b7fe7 100644
--- a/apps/plugin.h
+++ b/apps/plugin.h
@@ -66,6 +66,7 @@ void* plugin_get_buffer(size_t *buffer_size);
#include "filefuncs.h"
#if (CONFIG_CODEC == SWCODEC)
#include "pcm_mixer.h"
+#include "dsp-util.h"
#include "dsp.h"
#include "codecs.h"
#include "playback.h"
diff --git a/firmware/export/dsp-util.h b/firmware/export/dsp-util.h
new file mode 100644
index 0000000..76962b5
--- /dev/null
+++ b/firmware/export/dsp-util.h
@@ -0,0 +1,51 @@
+/***************************************************************************
+ * __________ __ ___.
+ * Open \______ \ ____ ____ | | _\_ |__ _______ ___
+ * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
+ * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
+ * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
+ * \/ \/ \/ \/ \/
+ * $Id$
+ *
+ * Copyright (C) 2011 by Michael Sevakis
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ ****************************************************************************/
+#ifndef DSP_HELPER_H
+#define DSP_HELPER_H
+
+/** Clip sample to signed 16 bit range **/
+
+#ifdef CPU_ARM
+#if ARM_ARCH >= 6
+static FORCE_INLINE int32_t clip_sample_16(int32_t sample)
+{
+ int32_t out;
+ asm ("ssat %0, #16, %1"
+ : "=r" (out) : "r"(sample));
+ return out;
+}
+#define CLIP_SAMPLE_16_DEFINED
+#endif /* ARM_ARCH */
+#endif /* CPU_ARM */
+
+#ifndef CLIP_SAMPLE_16_DEFINED
+/* Generic implementation */
+static FORCE_INLINE int32_t clip_sample_16(int32_t sample)
+{
+ if ((int16_t)sample != sample)
+ sample = 0x7fff ^ (sample >> 31);
+ return sample;
+}
+#endif /* CLIP_SAMPLE_16_DEFINED */
+
+#undef CLIP_SAMPLE_16_DEFINED
+
+#endif /* DSP_HELPER_H */
diff --git a/firmware/pcm_mixer.c b/firmware/pcm_mixer.c
index c847629..817b9a6 100644
--- a/firmware/pcm_mixer.c
+++ b/firmware/pcm_mixer.c
@@ -95,13 +95,7 @@ static unsigned int idle_counter = 0;
/** Generic mixing routines **/
#ifndef MIXER_OPTIMIZED_MIX_SAMPLES
-/* Clip sample to signed 16 bit range */
-static FORCE_INLINE int32_t clip_sample_16(int32_t sample)
-{
- if ((int16_t)sample != sample)
- sample = 0x7fff ^ (sample >> 31);
- return sample;
-}
+#include "dsp-util.h" /* for clip_sample_16 */
/* Mix channels' samples and apply gain factors */
static FORCE_INLINE void mix_samples(uint32_t *out,