summaryrefslogtreecommitdiff
path: root/apps/codecs
diff options
context:
space:
mode:
Diffstat (limited to 'apps/codecs')
-rw-r--r--apps/codecs/adx.c119
-rw-r--r--apps/codecs/lib/SOURCES2
-rw-r--r--apps/codecs/lib/fixedpoint.h126
-rw-r--r--apps/codecs/spc.c1
4 files changed, 119 insertions, 129 deletions
diff --git a/apps/codecs/adx.c b/apps/codecs/adx.c
index e23b3d4f80..cc36f6a908 100644
--- a/apps/codecs/adx.c
+++ b/apps/codecs/adx.c
@@ -21,7 +21,6 @@
21#include "codeclib.h" 21#include "codeclib.h"
22#include "inttypes.h" 22#include "inttypes.h"
23#include "math.h" 23#include "math.h"
24#include "fixedpoint.h"
25 24
26CODEC_HEADER 25CODEC_HEADER
27 26
@@ -42,6 +41,124 @@ const long cutoff = 500;
42 41
43static int16_t samples[WAV_CHUNK_SIZE] IBSS_ATTR; 42static int16_t samples[WAV_CHUNK_SIZE] IBSS_ATTR;
44 43
44/* fixed point stuff from apps/plugins/lib/fixedpoint.c */
45
46/* Inverse gain of circular cordic rotation in s0.31 format. */
47static const long cordic_circular_gain = 0xb2458939; /* 0.607252929 */
48
49/* Table of values of atan(2^-i) in 0.32 format fractions of pi where pi = 0xffffffff / 2 */
50static const unsigned long atan_table[] = {
51 0x1fffffff, /* +0.785398163 (or pi/4) */
52 0x12e4051d, /* +0.463647609 */
53 0x09fb385b, /* +0.244978663 */
54 0x051111d4, /* +0.124354995 */
55 0x028b0d43, /* +0.062418810 */
56 0x0145d7e1, /* +0.031239833 */
57 0x00a2f61e, /* +0.015623729 */
58 0x00517c55, /* +0.007812341 */
59 0x0028be53, /* +0.003906230 */
60 0x00145f2e, /* +0.001953123 */
61 0x000a2f98, /* +0.000976562 */
62 0x000517cc, /* +0.000488281 */
63 0x00028be6, /* +0.000244141 */
64 0x000145f3, /* +0.000122070 */
65 0x0000a2f9, /* +0.000061035 */
66 0x0000517c, /* +0.000030518 */
67 0x000028be, /* +0.000015259 */
68 0x0000145f, /* +0.000007629 */
69 0x00000a2f, /* +0.000003815 */
70 0x00000517, /* +0.000001907 */
71 0x0000028b, /* +0.000000954 */
72 0x00000145, /* +0.000000477 */
73 0x000000a2, /* +0.000000238 */
74 0x00000051, /* +0.000000119 */
75 0x00000028, /* +0.000000060 */
76 0x00000014, /* +0.000000030 */
77 0x0000000a, /* +0.000000015 */
78 0x00000005, /* +0.000000007 */
79 0x00000002, /* +0.000000004 */
80 0x00000001, /* +0.000000002 */
81 0x00000000, /* +0.000000001 */
82 0x00000000, /* +0.000000000 */
83};
84
85/**
86 * Implements sin and cos using CORDIC rotation.
87 *
88 * @param phase has range from 0 to 0xffffffff, representing 0 and
89 * 2*pi respectively.
90 * @param cos return address for cos
91 * @return sin of phase, value is a signed value from LONG_MIN to LONG_MAX,
92 * representing -1 and 1 respectively.
93 */
94static long fsincos(unsigned long phase, long *cos)
95{
96 int32_t x, x1, y, y1;
97 unsigned long z, z1;
98 int i;
99
100 /* Setup initial vector */
101 x = cordic_circular_gain;
102 y = 0;
103 z = phase;
104
105 /* The phase has to be somewhere between 0..pi for this to work right */
106 if (z < 0xffffffff / 4) {
107 /* z in first quadrant, z += pi/2 to correct */
108 x = -x;
109 z += 0xffffffff / 4;
110 } else if (z < 3 * (0xffffffff / 4)) {
111 /* z in third quadrant, z -= pi/2 to correct */
112 z -= 0xffffffff / 4;
113 } else {
114 /* z in fourth quadrant, z -= 3pi/2 to correct */
115 x = -x;
116 z -= 3 * (0xffffffff / 4);
117 }
118
119 /* Each iteration adds roughly 1-bit of extra precision */
120 for (i = 0; i < 31; i++) {
121 x1 = x >> i;
122 y1 = y >> i;
123 z1 = atan_table[i];
124
125 /* Decided which direction to rotate vector. Pivot point is pi/2 */
126 if (z >= 0xffffffff / 4) {
127 x -= y1;
128 y += x1;
129 z -= z1;
130 } else {
131 x += y1;
132 y -= x1;
133 z += z1;
134 }
135 }
136
137 if (cos)
138 *cos = x;
139
140 return y;
141}
142
143/**
144 * Fixed point square root via Newton-Raphson.
145 * @param a square root argument.
146 * @param fracbits specifies number of fractional bits in argument.
147 * @return Square root of argument in same fixed point format as input.
148 */
149static long fsqrt(long a, unsigned int fracbits)
150{
151 long b = a/2 + (1 << fracbits); /* initial approximation */
152 unsigned n;
153 const unsigned iterations = 8; /* bumped up from 4 as it wasn't
154 nearly enough for 28 fractional bits */
155
156 for (n = 0; n < iterations; ++n)
157 b = (b + (long)(((long long)(a) << fracbits)/b))/2;
158
159 return b;
160}
161
45/* this is the codec entry point */ 162/* this is the codec entry point */
46enum codec_status codec_main(void) 163enum codec_status codec_main(void)
47{ 164{
diff --git a/apps/codecs/lib/SOURCES b/apps/codecs/lib/SOURCES
index a1730f656a..cbb8e60372 100644
--- a/apps/codecs/lib/SOURCES
+++ b/apps/codecs/lib/SOURCES
@@ -1,6 +1,6 @@
1#if CONFIG_CODEC == SWCODEC /* software codec platforms */ 1#if CONFIG_CODEC == SWCODEC /* software codec platforms */
2codeclib.c 2codeclib.c
3../../fixedpoint.c 3
4 4
5mdct2.c 5mdct2.c
6#ifdef CPU_ARM 6#ifdef CPU_ARM
diff --git a/apps/codecs/lib/fixedpoint.h b/apps/codecs/lib/fixedpoint.h
deleted file mode 100644
index 54ece27080..0000000000
--- a/apps/codecs/lib/fixedpoint.h
+++ /dev/null
@@ -1,126 +0,0 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id: fixedpoint.h -1 $
9 *
10 * Copyright (C) 2006 Jens Arnold
11 *
12 * Fixed point library for plugins
13 *
14 * This program is free software; you can redistribute it and/or
15 * modify it under the terms of the GNU General Public License
16 * as published by the Free Software Foundation; either version 2
17 * of the License, or (at your option) any later version.
18 *
19 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
20 * KIND, either express or implied.
21 *
22 ****************************************************************************/
23
24#ifndef _FIXEDPOINT_H
25#define _FIXEDPOINT_H
26
27#include <inttypes.h>
28
29/** TAKEN FROM apps/dsp.h */
30/* A bunch of fixed point assembler helper macros */
31#if defined(CPU_COLDFIRE)
32/* These macros use the Coldfire EMAC extension and need the MACSR flags set
33 * to fractional mode with no rounding.
34 */
35
36/* Multiply two S.31 fractional integers and return the sign bit and the
37 * 31 most significant bits of the result.
38 */
39#define FRACMUL(x, y) \
40({ \
41 long t; \
42 asm ("mac.l %[a], %[b], %%acc0\n\t" \
43 "movclr.l %%acc0, %[t]\n\t" \
44 : [t] "=r" (t) : [a] "r" (x), [b] "r" (y)); \
45 t; \
46})
47
48/* Multiply two S.31 fractional integers, and return the 32 most significant
49 * bits after a shift left by the constant z. NOTE: Only works for shifts of
50 * 1 to 8 on Coldfire!
51 */
52#define FRACMUL_SHL(x, y, z) \
53({ \
54 long t, t2; \
55 asm ("mac.l %[a], %[b], %%acc0\n\t" \
56 "moveq.l %[d], %[t]\n\t" \
57 "move.l %%accext01, %[t2]\n\t" \
58 "and.l %[mask], %[t2]\n\t" \
59 "lsr.l %[t], %[t2]\n\t" \
60 "movclr.l %%acc0, %[t]\n\t" \
61 "asl.l %[c], %[t]\n\t" \
62 "or.l %[t2], %[t]\n\t" \
63 : [t] "=&d" (t), [t2] "=&d" (t2) \
64 : [a] "r" (x), [b] "r" (y), [mask] "d" (0xff), \
65 [c] "i" ((z)), [d] "i" (8 - (z))); \
66 t; \
67})
68
69#elif defined(CPU_ARM)
70
71/* Multiply two S.31 fractional integers and return the sign bit and the
72 * 31 most significant bits of the result.
73 */
74#define FRACMUL(x, y) \
75({ \
76 long t, t2; \
77 asm ("smull %[t], %[t2], %[a], %[b]\n\t" \
78 "mov %[t2], %[t2], asl #1\n\t" \
79 "orr %[t], %[t2], %[t], lsr #31\n\t" \
80 : [t] "=&r" (t), [t2] "=&r" (t2) \
81 : [a] "r" (x), [b] "r" (y)); \
82 t; \
83})
84
85/* Multiply two S.31 fractional integers, and return the 32 most significant
86 * bits after a shift left by the constant z.
87 */
88#define FRACMUL_SHL(x, y, z) \
89({ \
90 long t, t2; \
91 asm ("smull %[t], %[t2], %[a], %[b]\n\t" \
92 "mov %[t2], %[t2], asl %[c]\n\t" \
93 "orr %[t], %[t2], %[t], lsr %[d]\n\t" \
94 : [t] "=&r" (t), [t2] "=&r" (t2) \
95 : [a] "r" (x), [b] "r" (y), \
96 [c] "M" ((z) + 1), [d] "M" (31 - (z))); \
97 t; \
98})
99
100#else
101
102#define FRACMUL(x, y) (long) (((((long long) (x)) * ((long long) (y))) >> 31))
103#define FRACMUL_SHL(x, y, z) \
104((long)(((((long long) (x)) * ((long long) (y))) >> (31 - (z)))))
105
106#endif
107
108#define DIV64(x, y, z) (long)(((long long)(x) << (z))/(y))
109
110
111/** TAKEN FROM ORIGINAL fixedpoint.h */
112/* fast unsigned multiplication (16x16bit->32bit or 32x32bit->32bit,
113 * whichever is faster for the architecture) */
114#ifdef CPU_ARM
115#define FMULU(a, b) ((uint32_t) (((uint32_t) (a)) * ((uint32_t) (b))))
116#else /* SH1, coldfire */
117#define FMULU(a, b) ((uint32_t) (((uint16_t) (a)) * ((uint16_t) (b))))
118#endif
119
120long fsincos(unsigned long phase, long *cos);
121long fsqrt(long a, unsigned int fracbits);
122long cos_int(int val);
123long sin_int(int val);
124long flog(int x);
125
126#endif
diff --git a/apps/codecs/spc.c b/apps/codecs/spc.c
index d5313bfa47..6ceb704c7c 100644
--- a/apps/codecs/spc.c
+++ b/apps/codecs/spc.c
@@ -26,7 +26,6 @@
26/* DSP Based on Brad Martin's OpenSPC DSP emulator */ 26/* DSP Based on Brad Martin's OpenSPC DSP emulator */
27/* tag reading from sexyspc by John Brawn (John_Brawn@yahoo.com) and others */ 27/* tag reading from sexyspc by John Brawn (John_Brawn@yahoo.com) and others */
28#include "codeclib.h" 28#include "codeclib.h"
29#include "fixedpoint.h"
30#include "libspc/spc_codec.h" 29#include "libspc/spc_codec.h"
31#include "libspc/spc_profiler.h" 30#include "libspc/spc_profiler.h"
32 31