Mercurial > hg > audiostuff
comparison spandsp-0.0.6pre17/src/gsm0610_local.h @ 4:26cd8f1ef0b1
import spandsp-0.0.6pre17
author | Peter Meerwald <pmeerw@cosy.sbg.ac.at> |
---|---|
date | Fri, 25 Jun 2010 15:50:58 +0200 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
3:c6c5a16ce2f2 | 4:26cd8f1ef0b1 |
---|---|
1 /* | |
2 * SpanDSP - a series of DSP components for telephony | |
3 * | |
4 * gsm0610_local.h - GSM 06.10 full rate speech codec. | |
5 * | |
6 * Written by Steve Underwood <steveu@coppice.org> | |
7 * | |
8 * Copyright (C) 2006 Steve Underwood | |
9 * | |
10 * All rights reserved. | |
11 * | |
12 * This program is free software; you can redistribute it and/or modify | |
13 * it under the terms of the GNU Lesser General Public License version 2.1, | |
14 * as published by the Free Software Foundation. | |
15 * | |
16 * This program is distributed in the hope that it will be useful, | |
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
19 * GNU Lesser General Public License for more details. | |
20 * | |
21 * You should have received a copy of the GNU Lesser General Public | |
22 * License along with this program; if not, write to the Free Software | |
23 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | |
24 * | |
25 * This code is based on the widely used GSM 06.10 code available from | |
26 * http://kbs.cs.tu-berlin.de/~jutta/toast.html | |
27 * | |
28 * $Id: gsm0610_local.h,v 1.15 2009/03/13 15:57:29 steveu Exp $ | |
29 */ | |
30 | |
31 #if !defined(_GSM0610_LOCAL_H_) | |
32 #define _GSM0610_LOCAL_H_ | |
33 | |
34 #define GSM0610_FRAME_LEN 160 | |
35 | |
36 #define GSM0610_MAGIC 0xD | |
37 | |
38 #include "spandsp/private/gsm0610.h" | |
39 | |
40 static __inline__ int16_t gsm_add(int16_t a, int16_t b) | |
41 { | |
42 #if defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__)) | |
43 __asm__ __volatile__( | |
44 " addw %2,%0;\n" | |
45 " jno 0f;\n" | |
46 " movw $0x7fff,%0;\n" | |
47 " adcw $0,%0;\n" | |
48 "0:" | |
49 : "=&r" (a) | |
50 : "0" (a), "ir" (b) | |
51 : "cc" | |
52 ); | |
53 return a; | |
54 #else | |
55 int32_t sum; | |
56 | |
57 sum = (int32_t) a + (int32_t) b; | |
58 return saturate(sum); | |
59 #endif | |
60 } | |
61 /*- End of function --------------------------------------------------------*/ | |
62 | |
63 static __inline__ int32_t gsm_l_add(int32_t a, int32_t b) | |
64 { | |
65 #if defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__)) | |
66 __asm__ __volatile__( | |
67 " addl %2,%0;\n" | |
68 " jno 0f;\n" | |
69 " movl $0x7fffffff,%0;\n" | |
70 " adcl $0,%0;\n" | |
71 "0:" | |
72 : "=&r" (a) | |
73 : "0" (a), "ir" (b) | |
74 : "cc" | |
75 ); | |
76 return a; | |
77 #else | |
78 uint32_t A; | |
79 | |
80 if (a < 0) | |
81 { | |
82 if (b >= 0) | |
83 return a + b; | |
84 /*endif*/ | |
85 A = (uint32_t) -(a + 1) + (uint32_t) -(b + 1); | |
86 return (A >= INT32_MAX) ? INT32_MIN : -(int32_t) A - 2; | |
87 } | |
88 /*endif*/ | |
89 if (b <= 0) | |
90 return a + b; | |
91 /*endif*/ | |
92 A = (uint32_t) a + (uint32_t) b; | |
93 return (A > INT32_MAX) ? INT32_MAX : A; | |
94 #endif | |
95 } | |
96 /*- End of function --------------------------------------------------------*/ | |
97 | |
98 static __inline__ int16_t gsm_sub(int16_t a, int16_t b) | |
99 { | |
100 int32_t diff; | |
101 | |
102 diff = (int32_t) a - (int32_t) b; | |
103 return saturate(diff); | |
104 } | |
105 /*- End of function --------------------------------------------------------*/ | |
106 | |
107 static __inline__ int16_t gsm_mult(int16_t a, int16_t b) | |
108 { | |
109 if (a == INT16_MIN && b == INT16_MIN) | |
110 return INT16_MAX; | |
111 /*endif*/ | |
112 return (int16_t) (((int32_t) a * (int32_t) b) >> 15); | |
113 } | |
114 /*- End of function --------------------------------------------------------*/ | |
115 | |
116 static __inline__ int32_t gsm_l_mult(int16_t a, int16_t b) | |
117 { | |
118 assert (a != INT16_MIN || b != INT16_MIN); | |
119 return ((int32_t) a * (int32_t) b) << 1; | |
120 } | |
121 /*- End of function --------------------------------------------------------*/ | |
122 | |
123 static __inline__ int16_t gsm_mult_r(int16_t a, int16_t b) | |
124 { | |
125 int32_t prod; | |
126 | |
127 if (b == INT16_MIN && a == INT16_MIN) | |
128 return INT16_MAX; | |
129 /*endif*/ | |
130 prod = (int32_t) a * (int32_t) b + 16384; | |
131 prod >>= 15; | |
132 return (int16_t) (prod & 0xFFFF); | |
133 } | |
134 /*- End of function --------------------------------------------------------*/ | |
135 | |
136 static __inline__ int16_t gsm_abs(int16_t a) | |
137 { | |
138 return (a == INT16_MIN) ? INT16_MAX : (int16_t) abs(a); | |
139 } | |
140 /*- End of function --------------------------------------------------------*/ | |
141 | |
142 static __inline__ int16_t gsm_asr(int16_t a, int n) | |
143 { | |
144 if (n >= 16) | |
145 return (int16_t) (-(a < 0)); | |
146 /*endif*/ | |
147 if (n <= -16) | |
148 return 0; | |
149 /*endif*/ | |
150 if (n < 0) | |
151 return (int16_t) (a << -n); | |
152 /*endif*/ | |
153 return (int16_t) (a >> n); | |
154 } | |
155 /*- End of function --------------------------------------------------------*/ | |
156 | |
157 static __inline__ int16_t gsm_asl(int16_t a, int n) | |
158 { | |
159 if (n >= 16) | |
160 return 0; | |
161 /*endif*/ | |
162 if (n <= -16) | |
163 return (int16_t) (-(a < 0)); | |
164 /*endif*/ | |
165 if (n < 0) | |
166 return gsm_asr(a, -n); | |
167 /*endif*/ | |
168 return (int16_t) (a << n); | |
169 } | |
170 /*- End of function --------------------------------------------------------*/ | |
171 | |
172 extern void gsm0610_long_term_predictor(gsm0610_state_t *s, | |
173 int16_t d[40], | |
174 int16_t *dp, /* [-120..-1] d' IN */ | |
175 int16_t e[40], | |
176 int16_t dpp[40], | |
177 int16_t *Nc, | |
178 int16_t *bc); | |
179 | |
180 extern void gsm0610_lpc_analysis(gsm0610_state_t *s, | |
181 int16_t amp[160], | |
182 int16_t LARc[8]); | |
183 | |
184 extern void gsm0610_preprocess(gsm0610_state_t *s, | |
185 const int16_t amp[], | |
186 int16_t so[]); | |
187 | |
188 extern void gsm0610_short_term_analysis_filter(gsm0610_state_t *s, | |
189 int16_t LARc[8], | |
190 int16_t amp[160]); | |
191 | |
192 extern void gsm0610_long_term_synthesis_filtering(gsm0610_state_t *s, | |
193 int16_t Ncr, | |
194 int16_t bcr, | |
195 int16_t erp[40], | |
196 int16_t *drp); /* [-120..-1] IN, [0..40] OUT */ | |
197 | |
198 extern void gsm0610_rpe_decoding(gsm0610_state_t *s, | |
199 int16_t xmaxcr, | |
200 int16_t Mcr, | |
201 int16_t *xMcr, /* [0..12], 3 bits IN */ | |
202 int16_t erp[40]); | |
203 | |
204 extern void gsm0610_rpe_encoding(gsm0610_state_t *s, | |
205 int16_t *e, /* [-5..-1][0..39][40..44] IN/OUT */ | |
206 int16_t *xmaxc, | |
207 int16_t *Mc, | |
208 int16_t xMc[13]); | |
209 | |
210 extern void gsm0610_short_term_synthesis_filter(gsm0610_state_t *s, | |
211 int16_t LARcr[8], | |
212 int16_t drp[40], | |
213 int16_t amp[160]); | |
214 | |
215 extern int16_t gsm0610_norm(int32_t a); | |
216 | |
217 #endif | |
218 | |
219 /*- End of include ---------------------------------------------------------*/ |