diff options
author | Michael Sevakis <jethead71@rockbox.org> | 2011-12-04 18:19:39 +0000 |
---|---|---|
committer | Michael Sevakis <jethead71@rockbox.org> | 2011-12-04 18:19:39 +0000 |
commit | a43df152c2adf737208bbeb294a0a13608d3cc43 (patch) | |
tree | c0534198745141699a08d9471303744948e51138 | |
parent | 700e360b612766eb2729597be55c43b5b69bbe7f (diff) | |
download | rockbox-a43df152c2adf737208bbeb294a0a13608d3cc43.tar.gz rockbox-a43df152c2adf737208bbeb294a0a13608d3cc43.zip |
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.h | 1 | ||||
-rw-r--r-- | apps/codecs/libspc/spc_dsp.c | 20 | ||||
-rw-r--r-- | apps/dsp.c | 15 | ||||
-rw-r--r-- | apps/pcmbuf.c | 9 | ||||
-rw-r--r-- | apps/plugin.h | 1 | ||||
-rw-r--r-- | firmware/export/dsp-util.h | 51 | ||||
-rw-r--r-- | firmware/pcm_mixer.c | 8 |
7 files changed, 58 insertions, 47 deletions
diff --git a/apps/codecs.h b/apps/codecs.h index 527c59ac9c..f1e2a51eac 100644 --- a/apps/codecs.h +++ b/apps/codecs.h | |||
@@ -43,6 +43,7 @@ | |||
43 | #include "pcm_record.h" | 43 | #include "pcm_record.h" |
44 | #endif | 44 | #endif |
45 | #include "dsp.h" | 45 | #include "dsp.h" |
46 | #include "dsp-util.h" | ||
46 | #endif | 47 | #endif |
47 | 48 | ||
48 | #include "gcc_extensions.h" | 49 | #include "gcc_extensions.h" |
diff --git a/apps/codecs/libspc/spc_dsp.c b/apps/codecs/libspc/spc_dsp.c index 28e05425fb..6350c4c331 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 ) | |||
57 | } | 57 | } |
58 | } | 58 | } |
59 | 59 | ||
60 | #if ARM_ARCH >= 6 | 60 | #define CLAMP16( n ) clip_sample_16( n ) |
61 | /* if ( n < -32768 ) out = -32768; */ | ||
62 | /* if ( n > 32767 ) out = 32767; */ | ||
63 | #define CLAMP16( n ) \ | ||
64 | ({ \ | ||
65 | asm ("ssat %0, #16, %1" \ | ||
66 | : "=r" ( n ) : "r"( n ) ); \ | ||
67 | n; \ | ||
68 | }) | ||
69 | #else | ||
70 | /* if ( n < -32768 ) out = -32768; */ | ||
71 | /* if ( n > 32767 ) out = 32767; */ | ||
72 | #define CLAMP16( n ) \ | ||
73 | ({ \ | ||
74 | if ( (int16_t) n != n ) \ | ||
75 | n = 0x7FFF ^ (n >> 31); \ | ||
76 | n; \ | ||
77 | }) | ||
78 | #endif | ||
79 | 61 | ||
80 | #if SPC_BRRCACHE | 62 | #if SPC_BRRCACHE |
81 | static void decode_brr( struct Spc_Dsp* this, unsigned start_addr, | 63 | static void decode_brr( struct Spc_Dsp* this, unsigned start_addr, |
diff --git a/apps/dsp.c b/apps/dsp.c index d9c097af66..00de511dd0 100644 --- a/apps/dsp.c +++ b/apps/dsp.c | |||
@@ -19,15 +19,12 @@ | |||
19 | * | 19 | * |
20 | ****************************************************************************/ | 20 | ****************************************************************************/ |
21 | #include "config.h" | 21 | #include "config.h" |
22 | 22 | #include "system.h" | |
23 | #include <stdbool.h> | ||
24 | #include <inttypes.h> | ||
25 | #include <string.h> | ||
26 | #include <sound.h> | 23 | #include <sound.h> |
27 | #include "dsp.h" | 24 | #include "dsp.h" |
25 | #include "dsp-util.h" | ||
28 | #include "eq.h" | 26 | #include "eq.h" |
29 | #include "kernel.h" | 27 | #include "kernel.h" |
30 | #include "system.h" | ||
31 | #include "settings.h" | 28 | #include "settings.h" |
32 | #include "replaygain.h" | 29 | #include "replaygain.h" |
33 | #include "tdspeed.h" | 30 | #include "tdspeed.h" |
@@ -261,14 +258,6 @@ static int32_t release_gain IBSS_ATTR; /* S7.24 format */ | |||
261 | static void compressor_process(int count, int32_t *buf[]); | 258 | static void compressor_process(int count, int32_t *buf[]); |
262 | 259 | ||
263 | 260 | ||
264 | /* Clip sample to signed 16 bit range */ | ||
265 | static inline int32_t clip_sample_16(int32_t sample) | ||
266 | { | ||
267 | if ((int16_t)sample != sample) | ||
268 | sample = 0x7fff ^ (sample >> 31); | ||
269 | return sample; | ||
270 | } | ||
271 | |||
272 | #ifdef HAVE_PITCHSCREEN | 261 | #ifdef HAVE_PITCHSCREEN |
273 | int32_t sound_get_pitch(void) | 262 | int32_t sound_get_pitch(void) |
274 | { | 263 | { |
diff --git a/apps/pcmbuf.c b/apps/pcmbuf.c index 8135a30a36..32e1157132 100644 --- a/apps/pcmbuf.c +++ b/apps/pcmbuf.c | |||
@@ -27,6 +27,7 @@ | |||
27 | #include "pcm.h" | 27 | #include "pcm.h" |
28 | #include "pcm_mixer.h" | 28 | #include "pcm_mixer.h" |
29 | #include "pcmbuf.h" | 29 | #include "pcmbuf.h" |
30 | #include "dsp-util.h" | ||
30 | #include "playback.h" | 31 | #include "playback.h" |
31 | #include "codec_thread.h" | 32 | #include "codec_thread.h" |
32 | 33 | ||
@@ -828,14 +829,6 @@ static size_t crossfade_find_buftail(size_t buffer_rem, size_t buffer_need) | |||
828 | return buffer_rem; | 829 | return buffer_rem; |
829 | } | 830 | } |
830 | 831 | ||
831 | /* Clip sample to signed 16 bit range */ | ||
832 | static FORCE_INLINE int32_t clip_sample_16(int32_t sample) | ||
833 | { | ||
834 | if ((int16_t)sample != sample) | ||
835 | sample = 0x7fff ^ (sample >> 31); | ||
836 | return sample; | ||
837 | } | ||
838 | |||
839 | /* Returns the number of bytes _NOT_ mixed/faded */ | 832 | /* Returns the number of bytes _NOT_ mixed/faded */ |
840 | static int crossfade_mix_fade(int factor, size_t size, void *buf, size_t *out_index, | 833 | static int crossfade_mix_fade(int factor, size_t size, void *buf, size_t *out_index, |
841 | unsigned long elapsed, off_t offset) | 834 | unsigned long elapsed, off_t offset) |
diff --git a/apps/plugin.h b/apps/plugin.h index 0ee37bb4fe..e2b7fe7e11 100644 --- a/apps/plugin.h +++ b/apps/plugin.h | |||
@@ -66,6 +66,7 @@ void* plugin_get_buffer(size_t *buffer_size); | |||
66 | #include "filefuncs.h" | 66 | #include "filefuncs.h" |
67 | #if (CONFIG_CODEC == SWCODEC) | 67 | #if (CONFIG_CODEC == SWCODEC) |
68 | #include "pcm_mixer.h" | 68 | #include "pcm_mixer.h" |
69 | #include "dsp-util.h" | ||
69 | #include "dsp.h" | 70 | #include "dsp.h" |
70 | #include "codecs.h" | 71 | #include "codecs.h" |
71 | #include "playback.h" | 72 | #include "playback.h" |
diff --git a/firmware/export/dsp-util.h b/firmware/export/dsp-util.h new file mode 100644 index 0000000000..76962b527a --- /dev/null +++ b/firmware/export/dsp-util.h | |||
@@ -0,0 +1,51 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id$ | ||
9 | * | ||
10 | * Copyright (C) 2011 by Michael Sevakis | ||
11 | * | ||
12 | * This program is free software; you can redistribute it and/or | ||
13 | * modify it under the terms of the GNU General Public License | ||
14 | * as published by the Free Software Foundation; either version 2 | ||
15 | * of the License, or (at your option) any later version. | ||
16 | * | ||
17 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
18 | * KIND, either express or implied. | ||
19 | * | ||
20 | ****************************************************************************/ | ||
21 | #ifndef DSP_HELPER_H | ||
22 | #define DSP_HELPER_H | ||
23 | |||
24 | /** Clip sample to signed 16 bit range **/ | ||
25 | |||
26 | #ifdef CPU_ARM | ||
27 | #if ARM_ARCH >= 6 | ||
28 | static FORCE_INLINE int32_t clip_sample_16(int32_t sample) | ||
29 | { | ||
30 | int32_t out; | ||
31 | asm ("ssat %0, #16, %1" | ||
32 | : "=r" (out) : "r"(sample)); | ||
33 | return out; | ||
34 | } | ||
35 | #define CLIP_SAMPLE_16_DEFINED | ||
36 | #endif /* ARM_ARCH */ | ||
37 | #endif /* CPU_ARM */ | ||
38 | |||
39 | #ifndef CLIP_SAMPLE_16_DEFINED | ||
40 | /* Generic implementation */ | ||
41 | static FORCE_INLINE int32_t clip_sample_16(int32_t sample) | ||
42 | { | ||
43 | if ((int16_t)sample != sample) | ||
44 | sample = 0x7fff ^ (sample >> 31); | ||
45 | return sample; | ||
46 | } | ||
47 | #endif /* CLIP_SAMPLE_16_DEFINED */ | ||
48 | |||
49 | #undef CLIP_SAMPLE_16_DEFINED | ||
50 | |||
51 | #endif /* DSP_HELPER_H */ | ||
diff --git a/firmware/pcm_mixer.c b/firmware/pcm_mixer.c index c84762938e..817b9a6a3c 100644 --- a/firmware/pcm_mixer.c +++ b/firmware/pcm_mixer.c | |||
@@ -95,13 +95,7 @@ static unsigned int idle_counter = 0; | |||
95 | /** Generic mixing routines **/ | 95 | /** Generic mixing routines **/ |
96 | 96 | ||
97 | #ifndef MIXER_OPTIMIZED_MIX_SAMPLES | 97 | #ifndef MIXER_OPTIMIZED_MIX_SAMPLES |
98 | /* Clip sample to signed 16 bit range */ | 98 | #include "dsp-util.h" /* for clip_sample_16 */ |
99 | static FORCE_INLINE int32_t clip_sample_16(int32_t sample) | ||
100 | { | ||
101 | if ((int16_t)sample != sample) | ||
102 | sample = 0x7fff ^ (sample >> 31); | ||
103 | return sample; | ||
104 | } | ||
105 | 99 | ||
106 | /* Mix channels' samples and apply gain factors */ | 100 | /* Mix channels' samples and apply gain factors */ |
107 | static FORCE_INLINE void mix_samples(uint32_t *out, | 101 | static FORCE_INLINE void mix_samples(uint32_t *out, |