~ubuntu-branches/ubuntu/saucy/iaxmodem/saucy

« back to all changes in this revision

Viewing changes to lib/spandsp/src/gsm0610_preprocess.c

  • Committer: Bazaar Package Importer
  • Author(s): Julien BLACHE
  • Date: 2006-10-28 10:54:55 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20061028105455-qdnaih9tmq0uc29w
Tags: 0.1.15~dfsg-1
* New upstream release.
* debian/rules:
  + Use new ~dfsg versionning scheme.
  + Do not remove config.* in get-orig-source.
* debian/patches/11_build_configure-stamp.dpatch:
  + Updated.
* debian/iaxmodem.init:
  + Added LSB header.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * SpanDSP - a series of DSP components for telephony
 
3
 *
 
4
 * gsm0610_preprocess.c - 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 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.
 
16
 *
 
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.
 
21
 *
 
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.
 
25
 *
 
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
 
28
 *
 
29
 * $Id: gsm0610_preprocess.c,v 1.4 2006/06/13 13:29:46 steveu Exp $
 
30
 */
 
31
 
 
32
/*! \file */
 
33
 
 
34
#ifdef HAVE_CONFIG_H
 
35
#include <config.h>
 
36
#endif
 
37
 
 
38
#include <assert.h>
 
39
#include <inttypes.h>
 
40
#include <tgmath.h>
 
41
#include <stdlib.h>
 
42
 
 
43
#include "spandsp/telephony.h"
 
44
#include "spandsp/dc_restore.h"
 
45
#include "spandsp/gsm0610.h"
 
46
 
 
47
#include "gsm0610_local.h"
 
48
 
 
49
/*
 
50
    4.2.0 .. 4.2.3  PREPROCESSING SECTION
 
51
    
 
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:
 
55
  
 
56
    in:  0.1.....................12
 
57
         S.v.v.v.v.v.v.v.v.v.v.v.v.*.*.*
 
58
  
 
59
    Where S is the sign bit, v a valid bit, and * a "don't care" bit.
 
60
    The original signal is called sop[..]
 
61
  
 
62
    out:   0.1................... 12 
 
63
         S.S.v.v.v.v.v.v.v.v.v.v.v.v.0.0
 
64
*/
 
65
 
 
66
void gsm0610_preprocess(gsm0610_state_t *s, const int16_t amp[GSM0610_FRAME_LEN], int16_t so[GSM0610_FRAME_LEN])
 
67
{
 
68
    int16_t z1;
 
69
    int16_t mp;
 
70
    int16_t s1;
 
71
    int16_t msp;
 
72
    int16_t SO;
 
73
    int32_t L_z2;
 
74
    int32_t L_s2;
 
75
    int32_t L_temp;
 
76
#if !defined(__GNUC__)
 
77
    int16_t lsp;
 
78
#endif
 
79
    int k;
 
80
 
 
81
    z1 = s->z1;
 
82
    L_z2 = s->L_z2;
 
83
    mp = s->mp;
 
84
    for (k = 0;  k < GSM0610_FRAME_LEN;  k++)
 
85
    {
 
86
        /* 4.2.1   Downscaling of the input signal */
 
87
        SO = (amp[k] >> 1) & ~3;
 
88
 
 
89
        assert(SO >= -0x4000); // downscaled by
 
90
        assert(SO <=  0x3FFC); // previous routine.
 
91
 
 
92
        /* 4.2.2   Offset compensation */
 
93
 
 
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 ].
 
98
        */
 
99
        /* Compute the non-recursive part */
 
100
        s1 = SO - z1;
 
101
        z1 = SO;
 
102
 
 
103
        assert(s1 != INT16_MIN);
 
104
 
 
105
        /* Compute the recursive part */
 
106
        L_s2 = s1;
 
107
        L_s2 <<= 15;
 
108
 
 
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;
 
117
         */
 
118
        L_z2 = gsm_l_add(L_z2, L_s2);
 
119
#else
 
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));
 
123
 
 
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);
 
127
#endif
 
128
 
 
129
        /* Compute sof[k] with rounding */
 
130
        L_temp = gsm_l_add(L_z2, 16384);
 
131
 
 
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);
 
136
    }
 
137
    /*endfor*/
 
138
 
 
139
    s->z1 = z1;
 
140
    s->L_z2 = L_z2;
 
141
    s->mp = mp;
 
142
}
 
143
/*- End of function --------------------------------------------------------*/
 
144
/*- End of file ------------------------------------------------------------*/