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

« back to all changes in this revision

Viewing changes to sflphone-common/src/audio/sound/tonelist.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
 *
 
5
 *  Inspired by tonegenerator of
 
6
 *   Laurielle Lea <laurielle.lea@savoirfairelinux.com> (2004)
 
7
 *
 
8
 *  This program is free software; you can redistribute it and/or modify
 
9
 *  it under the terms of the GNU General Public License as published by
 
10
 *  the Free Software Foundation; either version 3 of the License, or
 
11
 *  (at your option) any later version.
 
12
 *
 
13
 *  This program is distributed in the hope that it will be useful,
 
14
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
15
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
16
 *  GNU General Public License for more details.
 
17
 *
 
18
 *  You should have received a copy of the GNU General Public License
 
19
 *  along with this program; if not, write to the Free Software
 
20
 *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
21
 *
 
22
 *  Additional permission under GNU GPL version 3 section 7:
 
23
 *
 
24
 *  If you modify this program, or any covered work, by linking or
 
25
 *  combining it with the OpenSSL project's OpenSSL library (or a
 
26
 *  modified version of that library), containing parts covered by the
 
27
 *  terms of the OpenSSL or SSLeay licenses, Savoir-Faire Linux Inc.
 
28
 *  grants you additional permission to convey the resulting work.
 
29
 *  Corresponding Source for a non-source form of such a combination
 
30
 *  shall include the source code for the parts of OpenSSL used as well
 
31
 *  as that of the covered work.
 
32
 */
 
33
#include "tonelist.h"
 
34
 
 
35
ToneList::ToneList() : _nbTone (TONE_NBTONE) ,
 
36
        _nbCountry (TONE_NBCOUNTRY),
 
37
        _defaultCountryId (ZID_NORTH_AMERICA)
 
38
{
 
39
    initToneDefinition();
 
40
}
 
41
 
 
42
ToneList::~ToneList()
 
43
{
 
44
}
 
45
 
 
46
void
 
47
ToneList::initToneDefinition()
 
48
{
 
49
    _toneZone[ZID_NORTH_AMERICA][Tone::TONE_DIALTONE] = "350+440";
 
50
    _toneZone[ZID_NORTH_AMERICA][Tone::TONE_BUSY] = "480+620/500,0/500";
 
51
    _toneZone[ZID_NORTH_AMERICA][Tone::TONE_RINGTONE] = "440+480/2000,0/4000";
 
52
    _toneZone[ZID_NORTH_AMERICA][Tone::TONE_CONGESTION] = "480+620/250,0/250";
 
53
 
 
54
    _toneZone[ZID_FRANCE][Tone::TONE_DIALTONE] = "440";
 
55
    _toneZone[ZID_FRANCE][Tone::TONE_BUSY] = "440/500,0/500";
 
56
    _toneZone[ZID_FRANCE][Tone::TONE_RINGTONE] = "440/1500,0/3500";
 
57
    _toneZone[ZID_FRANCE][Tone::TONE_CONGESTION] = "440/250,0/250";
 
58
 
 
59
    _toneZone[ZID_AUSTRALIA][Tone::TONE_DIALTONE] = "413+438";
 
60
    _toneZone[ZID_AUSTRALIA][Tone::TONE_BUSY] = "425/375,0/375";
 
61
    _toneZone[ZID_AUSTRALIA][Tone::TONE_RINGTONE] =
 
62
        "413+438/400,0/200,413+438/400,0/2000";
 
63
    _toneZone[ZID_AUSTRALIA][Tone::TONE_CONGESTION] = "425/375,0/375,420/375,8/375";
 
64
 
 
65
    _toneZone[ZID_UNITED_KINGDOM][Tone::TONE_DIALTONE] = "350+440";
 
66
    _toneZone[ZID_UNITED_KINGDOM][Tone::TONE_BUSY] = "400/375,0/375";
 
67
    _toneZone[ZID_UNITED_KINGDOM][Tone::TONE_RINGTONE] =
 
68
        "400+450/400,0/200,400+450/400,0/2000";
 
69
    _toneZone[ZID_UNITED_KINGDOM][Tone::TONE_CONGESTION] =
 
70
        "400/400,0/350,400/225,0/525";
 
71
 
 
72
    _toneZone[ZID_SPAIN][Tone::TONE_DIALTONE] = "425";
 
73
    _toneZone[ZID_SPAIN][Tone::TONE_BUSY] = "425/200,0/200";
 
74
    _toneZone[ZID_SPAIN][Tone::TONE_RINGTONE] = "425/1500,0/3000";
 
75
    _toneZone[ZID_SPAIN][Tone::TONE_CONGESTION] =
 
76
        "425/200,0/200,425/200,0/200,425/200,0/600";
 
77
 
 
78
    _toneZone[ZID_ITALY][Tone::TONE_DIALTONE] = "425/600,0/1000,425/200,0/200";
 
79
    _toneZone[ZID_ITALY][Tone::TONE_BUSY] = "425/500,0/500";
 
80
    _toneZone[ZID_ITALY][Tone::TONE_RINGTONE] = "425/1000,0/4000";
 
81
    _toneZone[ZID_ITALY][Tone::TONE_CONGESTION] = "425/200,0/200";
 
82
 
 
83
    _toneZone[ZID_JAPAN][Tone::TONE_DIALTONE] = "400";
 
84
    _toneZone[ZID_JAPAN][Tone::TONE_BUSY] = "400/500,0/500";
 
85
    _toneZone[ZID_JAPAN][Tone::TONE_RINGTONE] = "400+15/1000,0/2000";
 
86
    _toneZone[ZID_JAPAN][Tone::TONE_CONGESTION] = "400/500,0/500";
 
87
}
 
88
 
 
89
std::string
 
90
ToneList::getDefinition (COUNTRYID countryId, Tone::TONEID toneId)
 
91
{
 
92
    if (toneId == Tone::TONE_NULL) {
 
93
        return "";
 
94
    }
 
95
 
 
96
    return _toneZone[countryId][toneId];
 
97
}
 
98
 
 
99
ToneList::COUNTRYID
 
100
ToneList::getCountryId (const std::string& countryName)
 
101
{
 
102
    if (countryName.compare ("North America") == 0) {
 
103
        return ZID_NORTH_AMERICA;
 
104
    } else if (countryName.compare ("France") == 0) {
 
105
        return ZID_FRANCE;
 
106
    } else if (countryName.compare ("Australia") == 0) {
 
107
        return ZID_AUSTRALIA;
 
108
    } else if (countryName.compare ("United Kingdom") == 0) {
 
109
        return ZID_UNITED_KINGDOM;
 
110
    } else if (countryName.compare ("Spain") == 0) {
 
111
        return ZID_SPAIN;
 
112
    } else if (countryName.compare ("Italy") == 0) {
 
113
        return ZID_ITALY;
 
114
    } else if (countryName.compare ("Japan") == 0) {
 
115
        return ZID_JAPAN;
 
116
    } else {
 
117
        return _defaultCountryId; // default, we don't want segmentation fault
 
118
    }
 
119
}
 
120
 
 
121
TelephoneTone::TelephoneTone (const std::string& countryName, unsigned int sampleRate) :
 
122
        _currentTone (Tone::TONE_NULL),
 
123
        _toneList()
 
124
{
 
125
    ToneList::COUNTRYID countryId = _toneList.getCountryId (countryName);
 
126
    _tone[Tone::TONE_DIALTONE] = new Tone (_toneList.getDefinition (countryId, Tone::TONE_DIALTONE), sampleRate);
 
127
    _tone[Tone::TONE_BUSY] = new Tone (_toneList.getDefinition (countryId, Tone::TONE_BUSY), sampleRate);
 
128
    _tone[Tone::TONE_RINGTONE] = new Tone (_toneList.getDefinition (countryId, Tone::TONE_RINGTONE), sampleRate);
 
129
    _tone[Tone::TONE_CONGESTION] = new Tone (_toneList.getDefinition (countryId, Tone::TONE_CONGESTION), sampleRate);
 
130
 
 
131
}
 
132
 
 
133
TelephoneTone::~TelephoneTone()
 
134
{
 
135
    for (int i=0; i<_toneList.getNbTone(); i++) {
 
136
        delete _tone[i];
 
137
        _tone[i] = 0;
 
138
    }
 
139
}
 
140
 
 
141
void
 
142
TelephoneTone::setCurrentTone (Tone::TONEID toneId)
 
143
{
 
144
    if (toneId != Tone::TONE_NULL && _currentTone != toneId) {
 
145
        _tone[toneId]->reset();
 
146
    }
 
147
 
 
148
    _currentTone = toneId;
 
149
}
 
150
 
 
151
Tone*
 
152
TelephoneTone::getCurrentTone()
 
153
{
 
154
    if (_currentTone == Tone::TONE_NULL) {
 
155
        return 0;
 
156
    }
 
157
 
 
158
    return _tone[_currentTone];
 
159
}
 
160
 
 
161
bool
 
162
TelephoneTone::shouldPlay()
 
163
{
 
164
    return ( (_currentTone != Tone::TONE_NULL) ? true : false);
 
165
}
 
166
 
 
167