diff options
author | Michael Sevakis <jethead71@rockbox.org> | 2017-09-18 06:00:05 -0400 |
---|---|---|
committer | Michael Sevakis <jethead71@rockbox.org> | 2017-11-21 05:01:14 -0500 |
commit | aced667f48c29a160aa4e5c0a8df037092b28189 (patch) | |
tree | 66e48e4a27daaf36f01d7ff1ed6876a7de38b0c0 /lib | |
parent | 5c9688961ef9166cec5225db50d5f73691d8292d (diff) | |
download | rockbox-aced667f48c29a160aa4e5c0a8df037092b28189.tar.gz rockbox-aced667f48c29a160aa4e5c0a8df037092b28189.zip |
Undo hacks to meant to get around string formatting limitations
The new vuprintf makes unnecessary workarounds due to formatting
limitations. I checked grep output for whatever appeared to fit
but it's possible I missed some instances because they weren't
so obvious.
Also, this means sound settings can dynamically work with any
number of decimals rather than the current assumption of one or
two. Add an ipow() function to help and take advantage of dynamic
field width and precision. Consolidate string formatting of sound
settings.
Change-Id: I46caf534859dfd1916cd440cd25e5206b192fcd8
Diffstat (limited to 'lib')
-rw-r--r-- | lib/fixedpoint/fixedpoint.c | 29 | ||||
-rw-r--r-- | lib/fixedpoint/fixedpoint.h | 2 | ||||
-rw-r--r-- | lib/fixedpoint/fixedpoint.make | 3 |
3 files changed, 31 insertions, 3 deletions
diff --git a/lib/fixedpoint/fixedpoint.c b/lib/fixedpoint/fixedpoint.c index 645419d102..d1307bb248 100644 --- a/lib/fixedpoint/fixedpoint.c +++ b/lib/fixedpoint/fixedpoint.c | |||
@@ -211,6 +211,35 @@ long fp_sqrt(long x, unsigned int fracbits) | |||
211 | return g; | 211 | return g; |
212 | } | 212 | } |
213 | 213 | ||
214 | /* raise an integer to an integer power */ | ||
215 | long ipow(long x, long y) | ||
216 | { | ||
217 | /* y[k] = bit k of y, 0 or 1; k=0...n; n=|_ lg(y) _| | ||
218 | * | ||
219 | * x^y = x^(y[0]*2^0 + y[1]*2^1 + ... + y[n]*2^n) | ||
220 | * = x^(y[0]*2^0) * x^(y[1]*2^1) * ... * x^(y[n]*2^n) | ||
221 | */ | ||
222 | long a = 1; | ||
223 | |||
224 | if (y < 0 && x != -1) | ||
225 | { | ||
226 | a = 0; /* would be < 1 or +inf if x == 0 */ | ||
227 | } | ||
228 | else | ||
229 | { | ||
230 | while (y) | ||
231 | { | ||
232 | if (y & 1) | ||
233 | a *= x; | ||
234 | |||
235 | y /= 2; | ||
236 | x *= x; | ||
237 | } | ||
238 | } | ||
239 | |||
240 | return a; | ||
241 | } | ||
242 | |||
214 | /** | 243 | /** |
215 | * Fixed point sinus using a lookup table | 244 | * Fixed point sinus using a lookup table |
216 | * don't forget to divide the result by 16384 to get the actual sinus value | 245 | * don't forget to divide the result by 16384 to get the actual sinus value |
diff --git a/lib/fixedpoint/fixedpoint.h b/lib/fixedpoint/fixedpoint.h index bc50ff687d..dcd7c8298c 100644 --- a/lib/fixedpoint/fixedpoint.h +++ b/lib/fixedpoint/fixedpoint.h | |||
@@ -85,6 +85,8 @@ long fp14_sin(int val); | |||
85 | long fp16_log(int x); | 85 | long fp16_log(int x); |
86 | long fp16_exp(int x); | 86 | long fp16_exp(int x); |
87 | 87 | ||
88 | long ipow(long x, long y); | ||
89 | |||
88 | /* fast unsigned multiplication (16x16bit->32bit or 32x32bit->32bit, | 90 | /* fast unsigned multiplication (16x16bit->32bit or 32x32bit->32bit, |
89 | * whichever is faster for the architecture) */ | 91 | * whichever is faster for the architecture) */ |
90 | #ifdef CPU_ARM | 92 | #ifdef CPU_ARM |
diff --git a/lib/fixedpoint/fixedpoint.make b/lib/fixedpoint/fixedpoint.make index 0233e9499b..5be0e38ea7 100644 --- a/lib/fixedpoint/fixedpoint.make +++ b/lib/fixedpoint/fixedpoint.make | |||
@@ -13,11 +13,8 @@ FIXEDPOINTLIB_OBJ := $(call c2obj, $(FIXEDPOINTLIB_SRC)) | |||
13 | INCLUDES += -I$(FIXEDPOINTLIB_DIR) | 13 | INCLUDES += -I$(FIXEDPOINTLIB_DIR) |
14 | OTHER_SRC += $(FIXEDPOINTLIB_SRC) | 14 | OTHER_SRC += $(FIXEDPOINTLIB_SRC) |
15 | 15 | ||
16 | # If not SOFTWARECODECS, then only plugins depend upon us | ||
17 | ifdef SOFTWARECODECS | ||
18 | CORE_LIBS += $(FIXEDPOINTLIB) | 16 | CORE_LIBS += $(FIXEDPOINTLIB) |
19 | CORE_GCSECTIONS := yes | 17 | CORE_GCSECTIONS := yes |
20 | endif | ||
21 | 18 | ||
22 | FIXEDPOINTLIB_FLAGS := $(CFLAGS) $(SHARED_CFLAGS) | 19 | FIXEDPOINTLIB_FLAGS := $(CFLAGS) $(SHARED_CFLAGS) |
23 | 20 | ||