~ubuntu-branches/ubuntu/maverick/sflphone/maverick

« back to all changes in this revision

Viewing changes to sflphone-common/src/audio/codecs/gsmcodec.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Francois Marier
  • Date: 2010-06-03 15:59:46 UTC
  • Revision ID: james.westby@ubuntu.com-20100603155946-ybe8d8o8zx8lp0m8
Tags: upstream-0.9.8.3
ImportĀ upstreamĀ versionĀ 0.9.8.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 *  Copyright (C) 2004, 2005, 2006, 2009, 2008, 2009, 2010 Savoir-Faire Linux Inc.
 
3
 *  Author: Yan Morin <yan.morin@savoirfairelinux.com>
 
4
 *  Author:  Laurielle Lea <laurielle.lea@savoirfairelinux.com>
 
5
 *
 
6
 *  This program is free software; you can redistribute it and/or modify
 
7
 *  it under the terms of the GNU General Public License as published by
 
8
 *  the Free Software Foundation; either version 3 of the License, or
 
9
 *  (at your option) any later version.
 
10
 *
 
11
 *  This program is distributed in the hope that it will be useful,
 
12
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
14
 *  GNU General Public License for more details.
 
15
 *
 
16
 *  You should have received a copy of the GNU General Public License
 
17
 *  along with this program; if not, write to the Free Software
 
18
 *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
19
 *
 
20
 *  Additional permission under GNU GPL version 3 section 7:
 
21
 *
 
22
 *  If you modify this program, or any covered work, by linking or
 
23
 *  combining it with the OpenSSL project's OpenSSL library (or a
 
24
 *  modified version of that library), containing parts covered by the
 
25
 *  terms of the OpenSSL or SSLeay licenses, Savoir-Faire Linux Inc.
 
26
 *  grants you additional permission to convey the resulting work.
 
27
 *  Corresponding Source for a non-source form of such a combination
 
28
 *  shall include the source code for the parts of OpenSSL used as well
 
29
 *  as that of the covered work.
 
30
 */
 
31
 
 
32
 
 
33
#include "audiocodec.h"
 
34
extern "C"
 
35
{
 
36
#include <gsm/gsm.h>
 
37
}
 
38
 
 
39
/**
 
40
 * GSM audio codec C++ class (over gsm/gsm.h)
 
41
 */
 
42
 
 
43
class Gsm : public AudioCodec
 
44
{
 
45
 
 
46
    public:
 
47
        // _payload should be 3
 
48
        Gsm (int payload=3) : AudioCodec (payload, "GSM"), _decode_gsmhandle (NULL), _encode_gsmhandle (NULL) {
 
49
            _clockRate = 8000;
 
50
            _frameSize = 160; // samples, 20 ms at 8kHz
 
51
            _channel = 1;
 
52
            _bitrate = 13.3;
 
53
            _bandwidth = 29.2;
 
54
 
 
55
            if (! (_decode_gsmhandle = gsm_create()))
 
56
                printf ("ERROR: decode_gsm_create");
 
57
 
 
58
            if (! (_encode_gsmhandle = gsm_create()))
 
59
                printf ("AudioCodec: ERROR: encode_gsm_create");
 
60
        }
 
61
 
 
62
        Gsm (const Gsm&);
 
63
 
 
64
        Gsm& operator= (const Gsm&);
 
65
 
 
66
        virtual ~Gsm (void) {
 
67
            gsm_destroy (_decode_gsmhandle);
 
68
            gsm_destroy (_encode_gsmhandle);
 
69
        }
 
70
 
 
71
        virtual int     codecDecode     (short * dst, unsigned char * src, unsigned int size) {
 
72
            // _debug("Decoded by gsm ");
 
73
            (void) size;
 
74
 
 
75
            if (gsm_decode (_decode_gsmhandle, (gsm_byte*) src, (gsm_signal*) dst) < 0)
 
76
                printf ("ERROR: gsm_decode");
 
77
 
 
78
            return 320;
 
79
        }
 
80
 
 
81
        virtual int     codecEncode     (unsigned char * dst, short * src, unsigned int size) {
 
82
 
 
83
            // _debug("Encoded by gsm ");
 
84
            (void) size;
 
85
            gsm_encode (_encode_gsmhandle, (gsm_signal*) src, (gsm_byte*) dst);
 
86
            return 33;
 
87
        }
 
88
 
 
89
    private:
 
90
        gsm _decode_gsmhandle;
 
91
        gsm _encode_gsmhandle;
 
92
};
 
93
 
 
94
extern "C" AudioCodec* create()
 
95
{
 
96
    return new Gsm (3);
 
97
}
 
98
 
 
99
extern "C" void destroy (AudioCodec* a)
 
100
{
 
101
    delete a;
 
102
}