2
* SpanDSP - a series of DSP components for telephony
4
* gsm0610_preprocess.c - GSM 06.10 full rate speech codec.
6
* Written by Steve Underwood <steveu@coppice.org>
8
* Copyright (C) 2006 Steve Underwood
10
* All rights reserved.
12
* This program is free software; you can redistribute it and/or modify
13
* it under the terms of the GNU General Public License as published by
14
* the Free Software Foundation; either version 2 of the License, or
15
* (at your option) any later version.
17
* This program is distributed in the hope that it will be useful,
18
* but WITHOUT ANY WARRANTY; without even the implied warranty of
19
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20
* GNU General Public License for more details.
22
* You should have received a copy of the GNU General Public License
23
* along with this program; if not, write to the Free Software
24
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26
* This code is based on the widely used GSM 06.10 code available from
27
* http://kbs.cs.tu-berlin.de/~jutta/toast.html
29
* $Id: gsm0610_preprocess.c,v 1.4 2006/06/13 13:29:46 steveu Exp $
43
#include "spandsp/telephony.h"
44
#include "spandsp/dc_restore.h"
45
#include "spandsp/gsm0610.h"
47
#include "gsm0610_local.h"
50
4.2.0 .. 4.2.3 PREPROCESSING SECTION
52
After A-law to linear conversion (or directly from the
53
A to D converter) the following scaling is assumed for
54
input to the RPE-LTP algorithm:
56
in: 0.1.....................12
57
S.v.v.v.v.v.v.v.v.v.v.v.v.*.*.*
59
Where S is the sign bit, v a valid bit, and * a "don't care" bit.
60
The original signal is called sop[..]
62
out: 0.1................... 12
63
S.S.v.v.v.v.v.v.v.v.v.v.v.v.0.0
66
void gsm0610_preprocess(gsm0610_state_t *s, const int16_t amp[GSM0610_FRAME_LEN], int16_t so[GSM0610_FRAME_LEN])
76
#if !defined(__GNUC__)
84
for (k = 0; k < GSM0610_FRAME_LEN; k++)
86
/* 4.2.1 Downscaling of the input signal */
87
SO = (amp[k] >> 1) & ~3;
89
assert(SO >= -0x4000); // downscaled by
90
assert(SO <= 0x3FFC); // previous routine.
92
/* 4.2.2 Offset compensation */
94
/* This part implements a high-pass filter and requires extended
95
arithmetic precision for the recursive part of this filter.
96
The input of this procedure is the array so[0...159] and the
97
output the array sof[ 0...159 ].
99
/* Compute the non-recursive part */
103
assert(s1 != INT16_MIN);
105
/* Compute the recursive part */
109
/* Perform a 31 by 16 bits multiplication */
110
#if defined(__GNUC__)
111
L_z2 = ((int64_t) L_z2*32735 + 0x4000) >> 15;
112
/* Alternate (ANSI) version of below line does slightly different rounding:
113
* L_temp = L_z2 >> 9;
114
* L_temp += L_temp >> 5;
115
* L_temp = (++L_temp) >> 1;
116
* L_z2 = L_z2 - L_temp;
118
L_z2 = gsm_l_add(L_z2, L_s2);
120
/* This does L_z2 = L_z2 * 0x7FD5/0x8000 + L_s2 */
121
msp = (int16_t) (L_z2 >> 15);
122
lsp = (int16_t) (L_z2 - ((int32_t) msp << 15));
124
L_s2 += gsm_mult_r(lsp, 32735);
125
L_temp = (int32_t) msp*32735;
126
L_z2 = gsm_l_add(L_temp, L_s2);
129
/* Compute sof[k] with rounding */
130
L_temp = gsm_l_add(L_z2, 16384);
132
/* 4.2.3 Preemphasis */
133
msp = gsm_mult_r(mp, -28180);
134
mp = (int16_t) (L_temp >> 15);
135
so[k] = gsm_add(mp, msp);
143
/*- End of function --------------------------------------------------------*/
144
/*- End of file ------------------------------------------------------------*/