1 /*
2 * Copyright (C) 2008 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 //#define LOG_NDEBUG 0
18 #define LOG_TAG "ToneGenerator"
19
20 #include <math.h>
21 #include <utils/Log.h>
22 #include <cutils/properties.h>
23 #include "media/ToneGenerator.h"
24
25
26 namespace android {
27
28
29 // Descriptors for all available tones (See ToneGenerator::ToneDescriptor class declaration for details)
30 const ToneGenerator::ToneDescriptor ToneGenerator::sToneDescriptors[] = {
31 { .segments = { { .duration = ToneGenerator::TONEGEN_INF, .waveFreq = { 1336, 941, 0 }, 0, 0},
32 { .duration = 0 , .waveFreq = { 0 }, 0, 0}},
33 .repeatCnt = ToneGenerator::TONEGEN_INF,
34 .repeatSegment = 0 }, // TONE_DTMF_0
35 { .segments = { { .duration = ToneGenerator::TONEGEN_INF, .waveFreq = { 1209, 697, 0 }, 0, 0 },
36 { .duration = 0 , .waveFreq = { 0 }, 0, 0}},
37 .repeatCnt = ToneGenerator::TONEGEN_INF,
38 .repeatSegment = 0 }, // TONE_DTMF_1
39 { .segments = { { .duration = ToneGenerator::TONEGEN_INF, .waveFreq = { 1336, 697, 0 }, 0, 0 },
40 { .duration = 0 , .waveFreq = { 0 }, 0, 0}},
41 .repeatCnt = ToneGenerator::TONEGEN_INF,
42 .repeatSegment = 0 }, // TONE_DTMF_2
43 { .segments = { { .duration = ToneGenerator::TONEGEN_INF, .waveFreq = { 1477, 697, 0 }, 0, 0 },
44 { .duration = 0 , .waveFreq = { 0 }, 0, 0}},
45 .repeatCnt = ToneGenerator::TONEGEN_INF,
46 .repeatSegment = 0 }, // TONE_DTMF_3
47 { .segments = { { .duration = ToneGenerator::TONEGEN_INF, .waveFreq = { 1209, 770, 0 }, 0, 0 },
48 { .duration = 0 , .waveFreq = { 0 }, 0, 0}},
49 .repeatCnt = ToneGenerator::TONEGEN_INF,
50 .repeatSegment = 0 }, // TONE_DTMF_4
51 { .segments = { { .duration = ToneGenerator::TONEGEN_INF, .waveFreq = { 1336, 770, 0 }, 0, 0 },
52 { .duration = 0 , .waveFreq = { 0 }, 0, 0}},
53 .repeatCnt = ToneGenerator::TONEGEN_INF,
54 .repeatSegment = 0 }, // TONE_DTMF_5
55 { .segments = { { .duration = ToneGenerator::TONEGEN_INF, .waveFreq = { 1477, 770, 0 }, 0, 0 },
56 { .duration = 0 , .waveFreq = { 0 }, 0, 0}},
57 .repeatCnt = ToneGenerator::TONEGEN_INF,
58 .repeatSegment = 0 }, // TONE_DTMF_6
59 { .segments = { { .duration = ToneGenerator::TONEGEN_INF, .waveFreq = { 1209, 852, 0 }, 0, 0 },
60 { .duration = 0 , .waveFreq = { 0 }, 0, 0}},
61 .repeatCnt = ToneGenerator::TONEGEN_INF,
62 .repeatSegment = 0 }, // TONE_DTMF_7
63 { .segments = { { .duration = ToneGenerator::TONEGEN_INF, .waveFreq = { 1336, 852, 0 }, 0, 0 },
64 { .duration = 0 , .waveFreq = { 0 }, 0, 0}},
65 .repeatCnt = ToneGenerator::TONEGEN_INF,
66 .repeatSegment = 0 }, // TONE_DTMF_8
67 { .segments = { { .duration = ToneGenerator::TONEGEN_INF, .waveFreq = { 1477, 852, 0 }, 0, 0 },
68 { .duration = 0 , .waveFreq = { 0 }, 0, 0}},
69 .repeatCnt = ToneGenerator::TONEGEN_INF,
70 .repeatSegment = 0 }, // TONE_DTMF_9
71 { .segments = { { .duration = ToneGenerator::TONEGEN_INF, .waveFreq = { 1209, 941, 0 }, 0, 0 },
72 { .duration = 0 , .waveFreq = { 0 }, 0, 0}},
73 .repeatCnt = ToneGenerator::TONEGEN_INF,
74 .repeatSegment = 0 }, // TONE_DTMF_S
75 { .segments = { { .duration = ToneGenerator::TONEGEN_INF, .waveFreq = { 1477, 941, 0 }, 0, 0 },
76 { .duration = 0 , .waveFreq = { 0 }, 0, 0}},
77 .repeatCnt = ToneGenerator::TONEGEN_INF,
78 .repeatSegment = 0 }, // TONE_DTMF_P
79 { .segments = { { .duration = ToneGenerator::TONEGEN_INF, .waveFreq = { 1633, 697, 0 }, 0, 0 },
80 { .duration = 0 , .waveFreq = { 0 }, 0, 0}},
81 .repeatCnt = ToneGenerator::TONEGEN_INF,
82 .repeatSegment = 0 }, // TONE_DTMF_A
83 { .segments = { { .duration = ToneGenerator::TONEGEN_INF, .waveFreq = { 1633, 770, 0 }, 0, 0 },
84 { .duration = 0 , .waveFreq = { 0 }, 0, 0}},
85 .repeatCnt = ToneGenerator::TONEGEN_INF,
86 .repeatSegment = 0 }, // TONE_DTMF_B
87 { .segments = { { .duration = ToneGenerator::TONEGEN_INF, .waveFreq = { 1633, 852, 0 }, 0, 0 },
88 { .duration = 0 , .waveFreq = { 0 }, 0, 0}},
89 .repeatCnt = ToneGenerator::TONEGEN_INF,
90 .repeatSegment = 0 }, // TONE_DTMF_C
91 { .segments = { { .duration = ToneGenerator::TONEGEN_INF, .waveFreq = { 1633, 941, 0 }, 0, 0 },
92 { .duration = 0 , .waveFreq = { 0 }, 0, 0}},
93 .repeatCnt = ToneGenerator::TONEGEN_INF,
94 .repeatSegment = 0 }, // TONE_DTMF_D
95 { .segments = { { .duration = ToneGenerator::TONEGEN_INF, .waveFreq = { 425, 0 }, 0, 0 },
96 { .duration = 0 , .waveFreq = { 0 }, 0, 0}},
97 .repeatCnt = ToneGenerator::TONEGEN_INF,
98 .repeatSegment = 0 }, // TONE_SUP_DIAL
99 { .segments = { { .duration = 500 , .waveFreq = { 425, 0 }, 0, 0},
100 { .duration = 500, .waveFreq = { 0 }, 0, 0},
101 { .duration = 0 , .waveFreq = { 0 }, 0, 0}},
102 .repeatCnt = ToneGenerator::TONEGEN_INF,
103 .repeatSegment = 0 }, // TONE_SUP_BUSY
104 { .segments = { { .duration = 200, .waveFreq = { 425, 0 }, 0, 0 },
105 { .duration = 200, .waveFreq = { 0 }, 0, 0 },
106 { .duration = 0 , .waveFreq = { 0 }, 0, 0}},
107 .repeatCnt = ToneGenerator::TONEGEN_INF,
108 .repeatSegment = 0 }, // TONE_SUP_CONGESTION
109 { .segments = { { .duration = 200, .waveFreq = { 425, 0 }, 0, 0 },
110 { .duration = 0 , .waveFreq = { 0 }, 0, 0}},
111 .repeatCnt = 0,
112 .repeatSegment = 0 }, // TONE_SUP_RADIO_ACK
113 { .segments = { { .duration = 200, .waveFreq = { 425, 0 }, 0, 0},
114 { .duration = 200, .waveFreq = { 0 }, 0, 0},
115 { .duration = 0 , .waveFreq = { 0 }, 0, 0}},
116 .repeatCnt = 2,
117 .repeatSegment = 0 }, // TONE_SUP_RADIO_NOTAVAIL
118 { .segments = { { .duration = 330, .waveFreq = { 950, 1400, 1800, 0 }, 0, 0},
119 { .duration = 1000, .waveFreq = { 0 }, 0, 0},
120 { .duration = 0 , .waveFreq = { 0 }, 0, 0}},
121 .repeatCnt = ToneGenerator::TONEGEN_INF,
122 .repeatSegment = 0 }, // TONE_SUP_ERROR
123 { .segments = { { .duration = 200, .waveFreq = { 425, 0 }, 0, 0 },
124 { .duration = 600, .waveFreq = { 0 }, 0, 0 },
125 { .duration = 200, .waveFreq = { 425, 0 }, 0, 0 },
126 { .duration = 3000, .waveFreq = { 0 }, 0, 0 },
127 { .duration = 0 , .waveFreq = { 0 }, 0, 0}},
128 .repeatCnt = ToneGenerator::TONEGEN_INF,
129 .repeatSegment = 0 }, // TONE_SUP_CALL_WAITING
130 { .segments = { { .duration = 1000, .waveFreq = { 425, 0 }, 0, 0 },
131 { .duration = 4000, .waveFreq = { 0 }, 0, 0 },
132 { .duration = 0 , .waveFreq = { 0 }, 0, 0}},
133 .repeatCnt = ToneGenerator::TONEGEN_INF,
134 .repeatSegment = 0 }, // TONE_SUP_RINGTONE
135 { .segments = { { .duration = 40, .waveFreq = { 400, 1200, 0 }, 0, 0 },
136 { .duration = 0 , .waveFreq = { 0 }, 0, 0}},
137 .repeatCnt = 0,
138 .repeatSegment = 0 }, // TONE_PROP_BEEP
139 { .segments = { { .duration = 100, .waveFreq = { 1200, 0 }, 0, 0 },
140 { .duration = 100, .waveFreq = { 0 }, 0, 0 },
141 { .duration = 0 , .waveFreq = { 0 }, 0, 0}},
142 .repeatCnt = 1,
143 .repeatSegment = 0 }, // TONE_PROP_ACK
144 { .segments = { { .duration = 400, .waveFreq = { 300, 400, 500, 0 }, 0, 0 },
145 { .duration = 0 , .waveFreq = { 0 }, 0, 0}},
146 .repeatCnt = 0,
147 .repeatSegment = 0 }, // TONE_PROP_NACK
148 { .segments = { { .duration = 200, .waveFreq = { 400, 1200, 0 }, 0, 0 },
149 { .duration = 0 , .waveFreq = { 0 }, 0, 0}},
150 .repeatCnt = 0,
151 .repeatSegment = 0 }, // TONE_PROP_PROMPT
152 { .segments = { { .duration = 40, .waveFreq = { 400, 1200, 0 }, 0, 0 },
153 { .duration = 200, .waveFreq = { 0 }, 0, 0 },
154 { .duration = 40, .waveFreq = { 400, 1200, 0 }, 0, 0 },
155 { .duration = 0 , .waveFreq = { 0 }, 0, 0}},
156 .repeatCnt = 0,
157 .repeatSegment = 0 }, // TONE_PROP_BEEP2
158 { .segments = { { .duration = 250, .waveFreq = { 440, 0 }, 0, 0 },
159 { .duration = 250, .waveFreq = { 620, 0 }, 0, 0 },
160 { .duration = 0 , .waveFreq = { 0 }, 0, 0 }},
161 .repeatCnt = ToneGenerator::TONEGEN_INF,
162 .repeatSegment = 0 }, // TONE_SUP_INTERCEPT
163 { .segments = { { .duration = 250, .waveFreq = { 440, 0 }, 0, 0 },
164 { .duration = 250, .waveFreq = { 620, 0 }, 0, 0 },
165 { .duration = 0 , .waveFreq = { 0 }, 0, 0}},
166 .repeatCnt = 7,
167 .repeatSegment = 0 }, // TONE_SUP_INTERCEPT_ABBREV
168 { .segments = { { .duration = 250, .waveFreq = { 480, 620, 0 }, 0, 0 },
169 { .duration = 250, .waveFreq = { 0 }, 0, 0 },
170 { .duration = 0 , .waveFreq = { 0 }, 0, 0}},
171 .repeatCnt = 7,
172 .repeatSegment = 0 }, // TONE_SUP_CONGESTION_ABBREV
173 { .segments = { { .duration = 100, .waveFreq = { 350, 440, 0 }, 0, 0 },
174 { .duration = 100, .waveFreq = { 0 }, 0, 0 },
175 { .duration = 0 , .waveFreq = { 0 }, 0, 0}},
176 .repeatCnt = 2,
177 .repeatSegment = 0 }, // TONE_SUP_CONFIRM
178 { .segments = { { .duration = 100, .waveFreq = { 480, 0 }, 0, 0 },
179 { .duration = 100, .waveFreq = { 0 }, 0, 0 },
180 { .duration = 0 , .waveFreq = { 0 }, 0, 0}},
181 .repeatCnt = 3,
182 .repeatSegment = 0 }, // TONE_SUP_PIP
183 { .segments = {{ .duration = ToneGenerator::TONEGEN_INF, .waveFreq = { 425, 0 }, 0, 0},
184 { .duration = 0 , .waveFreq = { 0 }, 0, 0}},
185 .repeatCnt = ToneGenerator::TONEGEN_INF,
186 .repeatSegment = 0 }, // TONE_CDMA_DIAL_TONE_LITE
187 { .segments = { { .duration = 2000, .waveFreq = { 440, 480, 0 }, 0, 0 },
188 { .duration = 4000, .waveFreq = { 0 }, 0, 0 },
189 { .duration = 0 , .waveFreq = { 0 }, 0, 0}},
190 .repeatCnt = ToneGenerator::TONEGEN_INF,
191 .repeatSegment = 0 }, // TONE_CDMA_NETWORK_USA_RINGBACK
192 { .segments = { { .duration = 250, .waveFreq = { 440, 0 }, 0, 0 },
193 { .duration = 250, .waveFreq = { 620, 0 }, 0, 0 },
194 { .duration = 0 , .waveFreq = { 0 }, 0, 0}},
195 .repeatCnt = ToneGenerator::TONEGEN_INF,
196 .repeatSegment = 0 }, // TONE_CDMA_INTERCEPT
197 { .segments = { { .duration = 250, .waveFreq = { 440, 0 }, 0, 0 },
198 { .duration = 250, .waveFreq = { 620, 0 }, 0, 0 },
199 { .duration = 0 , .waveFreq = { 0 }, 0, 0}},
200 .repeatCnt = 0,
201 .repeatSegment = 0 }, // TONE_CDMA_ABBR_INTERCEPT
202 { .segments = { { .duration = 250, .waveFreq = { 480, 620, 0 }, 0, 0 },
203 { .duration = 250, .waveFreq = { 0 }, 0, 0 },
204 { .duration = 0 , .waveFreq = { 0 }, 0, 0}},
205 .repeatCnt = ToneGenerator::TONEGEN_INF,
206 .repeatSegment = 0 }, // TONE_CDMA_REORDER
207 { .segments = { { .duration = 250, .waveFreq = { 480, 620, 0 }, 0, 0 },
208 { .duration = 250, .waveFreq = { 0 }, 0, 0 },
209 { .duration = 0 , .waveFreq = { 0 }, 0, 0}},
210 .repeatCnt = 7,
211 .repeatSegment = 0 }, // TONE_CDMA_ABBR_REORDER
212 { .segments = { { .duration = 500, .waveFreq = { 480, 620, 0 }, 0, 0 },
213 { .duration = 500, .waveFreq = { 0 }, 0, 0 },
214 { .duration = 0 , .waveFreq = { 0 }, 0, 0}},
215 .repeatCnt = ToneGenerator::TONEGEN_INF,
216 .repeatSegment = 0 }, // TONE_CDMA_NETWORK_BUSY
217 { .segments = { { .duration = 100, .waveFreq = { 350, 440, 0 }, 0, 0 },
218 { .duration = 100, .waveFreq = { 0 }, 0, 0 },
219 { .duration = 0 , .waveFreq = { 0 }, 0, 0}},
220 .repeatCnt = 2,
221 .repeatSegment = 0 }, // TONE_CDMA_CONFIRM
222 { .segments = { { .duration = 500, .waveFreq = { 660, 1000, 0 }, 0, 0 },
223 { .duration = 0 , .waveFreq = { 0 }, 0, 0}},
224 .repeatCnt = 0,
225 .repeatSegment = 0 }, // TONE_CDMA_ANSWER
226 { .segments = { { .duration = 300, .waveFreq = { 440, 0 }, 0, 0 },
227 { .duration = 0 , .waveFreq = { 0 }, 0, 0}},
228 .repeatCnt = 0,
229 .repeatSegment = 0 }, // TONE_CDMA_NETWORK_CALLWAITING
230 { .segments = { { .duration = 100, .waveFreq = { 480, 0 }, 0, 0 },
231 { .duration = 100, .waveFreq = { 0 }, 0, 0 },
232 { .duration = 0 , .waveFreq = { 0 }, 0, 0}},
233 .repeatCnt = 3,
234 .repeatSegment = 0 }, // TONE_CDMA_PIP
235
236 { .segments = { { .duration = 32, .waveFreq = { 2091, 0}, 0, 0 },
237 { .duration = 64, .waveFreq = { 2556, 0}, 19, 0},
238 { .duration = 32, .waveFreq = { 2091, 0}, 0, 0},
239 { .duration = 48, .waveFreq = { 2556, 0}, 0, 0},
240 { .duration = 4000, .waveFreq = { 0 }, 0, 0},
241 { .duration = 0, .waveFreq = { 0 }, 0, 0}},
242 .repeatCnt = 0,
243 .repeatSegment = 0 }, // TONE_CDMA_CALL_SIGNAL_ISDN_NORMAL
244 { .segments = { { .duration = 32, .waveFreq = { 2091, 0}, 0, 0 },
245 { .duration = 64, .waveFreq = { 2556, 0}, 7, 0 },
246 { .duration = 32, .waveFreq = { 2091, 0}, 0, 0 },
247 { .duration = 400, .waveFreq = { 0 }, 0, 0 },
248 { .duration = 32, .waveFreq = { 2091, 0}, 0, 0 },
249 { .duration = 64, .waveFreq = { 2556, 0}, 7, 4 },
250 { .duration = 32, .waveFreq = { 2091, 0}, 0, 0 },
251 { .duration = 4000, .waveFreq = { 0 }, 0, 0 },
252 { .duration = 0, .waveFreq = { 0 }, 0, 0 } },
253 .repeatCnt = 0,
254 .repeatSegment = 0 }, // TONE_CDMA_CALL_SIGNAL_ISDN_INTERGROUP
255 { .segments = { { .duration = 32, .waveFreq = { 2091, 0}, 0, 0 },
256 { .duration = 64, .waveFreq = { 2556, 0}, 3, 0 },
257 { .duration = 16, .waveFreq = { 2091, 0}, 0, 0 },
258 { .duration = 200, .waveFreq = { 0 }, 0, 0 },
259 { .duration = 32, .waveFreq = { 2091, 0}, 0, 0 },
260 { .duration = 64, .waveFreq = { 2556, 0}, 3, 4 },
261 { .duration = 16, .waveFreq = { 2091, 0}, 0, 0 },
262 { .duration = 200, .waveFreq = { 0 }, 0, 0 },
263 { .duration = 0, .waveFreq = { 0 }, 0, 0 } },
264 .repeatCnt = 0,
265 .repeatSegment = 0 }, // TONE_CDMA_CALL_SIGNAL_ISDN_SP_PRI
266 { .segments = { { .duration = 0, .waveFreq = { 0 }, 0, 0} },
267 .repeatCnt = 0,
268 .repeatSegment = 0 }, // TONE_CDMA_CALL_SIGNAL_ISDN_PAT3
269 { .segments = { { .duration = 32, .waveFreq = { 2091, 0 }, 0, 0 },
270 { .duration = 64, .waveFreq = { 2556, 0 }, 4, 0 },
271 { .duration = 20, .waveFreq = { 2091, 0 }, 0, 0 },
272 { .duration = 0, .waveFreq = { 0 } , 0, 0 } },
273 .repeatCnt = 0,
274 .repeatSegment = 0 }, // TONE_CDMA_CALL_SIGNAL_ISDN_PING_RING
275 { .segments = { { .duration = 0, .waveFreq = { 0 }, 0, 0} },
276 .repeatCnt = 0,
277 .repeatSegment = 0 }, // TONE_CDMA_CALL_SIGNAL_ISDN_PAT5
278 { .segments = { { .duration = 0, .waveFreq = { 0 }, 0, 0} },
279 .repeatCnt = 0,
280 .repeatSegment = 0 }, // TONE_CDMA_CALL_SIGNAL_ISDN_PAT6
281 { .segments = { { .duration = 0, .waveFreq = { 0 }, 0, 0} },
282 .repeatCnt = 0,
283 .repeatSegment = 0 }, // TONE_CDMA_CALL_SIGNAL_ISDN_PAT7
284
285 { .segments = { { .duration = 25, .waveFreq = { 3700, 0 }, 0, 0 },
286 { .duration = 25, .waveFreq = { 4000, 0 }, 39, 0 },
287 { .duration = 4000, .waveFreq = { 0 }, 0, 0 },
288 { .duration = 0, .waveFreq = { 0 }, 0, 0 } },
289 .repeatCnt = ToneGenerator::TONEGEN_INF,
290 .repeatSegment = 0 }, // TONE_CDMA_HIGH_L
291 { .segments = { { .duration = 25, .waveFreq = { 2600, 0 }, 0, 0 },
292 { .duration = 25, .waveFreq = { 2900, 0 }, 39, 0 },
293 { .duration = 4000, .waveFreq = { 0 }, 0, 0 },
294 { .duration = 0, .waveFreq = { 0 }, 0, 0 } },
295 .repeatCnt = ToneGenerator::TONEGEN_INF,
296 .repeatSegment = 0 }, // TONE_CDMA_MED_L
297 { .segments = { { .duration = 25, .waveFreq = { 1300, 0 }, 0, 0 },
298 { .duration = 25, .waveFreq = { 1450, 0 }, 39, 0 },
299 { .duration = 4000, .waveFreq = { 0 }, 0, 0 },
300 { .duration = 0, .waveFreq = { 0 }, 0, 0 } },
301 .repeatCnt = ToneGenerator::TONEGEN_INF,
302 .repeatSegment = 0 }, // TONE_CDMA_LOW_L
303 { .segments = { { .duration = 25, .waveFreq = { 3700, 0 }, 0, 0 },
304 { .duration = 25, .waveFreq = { 4000, 0 }, 15, 0 },
305 { .duration = 400, .waveFreq = { 0 }, 0, 0 },
306 { .duration = 0, .waveFreq = { 0 }, 0, 0 } },
307 .repeatCnt = ToneGenerator::TONEGEN_INF,
308 .repeatSegment = 0 }, // TONE_CDMA_HIGH_SS
309 { .segments = { { .duration = 25, .waveFreq = { 2600, 0 }, 0, 0 },
310 { .duration = 25, .waveFreq = { 2900, 0 }, 15, 0 },
311 { .duration = 400, .waveFreq = { 0 }, 0, 0 },
312 { .duration = 0, .waveFreq = { 0 }, 0, 0 }},
313 .repeatCnt = ToneGenerator::TONEGEN_INF,
314 .repeatSegment = 0 }, // TONE_CDMA_MED_SS
315 { .segments = { { .duration = 25, .waveFreq = { 1300, 0 }, 0, 0 },
316 { .duration = 25, .waveFreq = { 1450, 0 }, 15, 0 },
317 { .duration = 400, .waveFreq = { 0 }, 0, 0 },
318 { .duration = 0, .waveFreq = { 0 }, 0, 0 }},
319 .repeatCnt = ToneGenerator::TONEGEN_INF,
320 .repeatSegment = 0 }, // TONE_CDMA_LOW_SS
321 { .segments = { { .duration = 25, .waveFreq = { 3700, 0 }, 0, 0 },
322 { .duration = 25, .waveFreq = { 4000, 0 }, 7, 0 },
323 { .duration = 200, .waveFreq = { 0 }, 0, 0 },
324 { .duration = 25, .waveFreq = { 3700, 0 }, 0, 0 },
325 { .duration = 25, .waveFreq = { 4000, 0 }, 7, 3 },
326 { .duration = 200, .waveFreq = { 0 }, 0, 0 },
327 { .duration = 25, .waveFreq = { 3700, 0 }, 0, 0 },
328 { .duration = 25, .waveFreq = { 4000, 0 }, 15, 6 },
329 { .duration = 4000, .waveFreq = { 0 }, 0, 0 },
330 { .duration = 0, .waveFreq = { 0 }, 0, 0 }},
331 .repeatCnt = ToneGenerator::TONEGEN_INF,
332 .repeatSegment = 0 }, // TONE_CDMA_HIGH_SSL
333 { .segments = { { .duration = 25, .waveFreq = { 2600, 0 }, 0, 0 },
334 { .duration = 25, .waveFreq = { 2900, 0 }, 7, 0 },
335 { .duration = 200, .waveFreq = { 0 }, 0, 0 },
336 { .duration = 25, .waveFreq = { 2600, 0 }, 0, 0 },
337 { .duration = 25, .waveFreq = { 2900, 0 }, 7, 3 },
338 { .duration = 200, .waveFreq = { 0 }, 0, 0 },
339 { .duration = 25, .waveFreq = { 2600, 0 }, 0, 0 },
340 { .duration = 25, .waveFreq = { 2900, 0 }, 15, 6 },
341 { .duration = 4000, .waveFreq = { 0 }, 0, 0 },
342 { .duration = 0, .waveFreq = { 0 }, 0, 0 }},
343 .repeatCnt = ToneGenerator::TONEGEN_INF,
344 .repeatSegment = 0 }, // TONE_CDMA_MED_SSL
345 { .segments = { { .duration = 25, .waveFreq = { 1300, 0 }, 0, 0 },
346 { .duration = 25, .waveFreq = { 1450, 0 }, 7, 0 },
347 { .duration = 200, .waveFreq = { 0 }, 0, 0 },
348 { .duration = 25, .waveFreq = { 1300, 0 }, 0, 0 },
349 { .duration = 25, .waveFreq = { 1450, 0 }, 7, 3 },
350 { .duration = 200, .waveFreq = { 0 }, 0, 0 },
351 { .duration = 25, .waveFreq = { 1300, 0 }, 0, 0 },
352 { .duration = 25, .waveFreq = { 1450, 0 }, 15, 6 },
353 { .duration = 4000, .waveFreq = { 0 }, 0, 0 },
354 { .duration = 0, .waveFreq = { 0 }, 0, 0 }},
355 .repeatCnt = ToneGenerator::TONEGEN_INF,
356 .repeatSegment = 0 }, // TONE_CDMA_LOW_SSL
357 { .segments = { { .duration = 25, .waveFreq = { 3700, 0 }, 0, 0 },
358 { .duration = 25, .waveFreq = { 4000, 0 }, 19, 0 },
359 { .duration = 1000, .waveFreq = { 0 }, 0, 0 },
360 { .duration = 25, .waveFreq = { 3700, 0 }, 0, 0 },
361 { .duration = 25, .waveFreq = { 4000, 0 }, 19, 3 },
362 { .duration = 3000, .waveFreq = { 0 }, 0, 0 },
363 { .duration = 0, .waveFreq = { 0 }, 0, 0 }},
364 .repeatCnt = ToneGenerator::TONEGEN_INF,
365 .repeatSegment = 0 }, // TONE_CDMA_HIGH_SS_2
366 { .segments = { { .duration = 25, .waveFreq = { 2600, 0 }, 0, 0 },
367 { .duration = 25, .waveFreq = { 2900, 0 }, 19, 0 },
368 { .duration = 1000, .waveFreq = { 0 }, 0, 0 },
369 { .duration = 25, .waveFreq = { 2600, 0 }, 0, 0 },
370 { .duration = 25, .waveFreq = { 2900, 0 }, 19, 3 },
371 { .duration = 3000, .waveFreq = { 0 }, 0, 0 },
372 { .duration = 0, .waveFreq = { 0 }, 0, 0 }},
373 .repeatCnt = ToneGenerator::TONEGEN_INF,
374 .repeatSegment = 0 }, // TONE_CDMA_MED_SS_2
375 { .segments = { { .duration = 25, .waveFreq = { 1300, 0 }, 0, 0 },
376 { .duration = 25, .waveFreq = { 1450, 0 }, 19, 0 },
377 { .duration = 1000, .waveFreq = { 0 }, 0, 0 },
378 { .duration = 25, .waveFreq = { 1300, 0 }, 0, 0 },
379 { .duration = 25, .waveFreq = { 1450, 0 }, 19, 3 },
380 { .duration = 3000, .waveFreq = { 0 }, 0, 0 },
381 { .duration = 0, .waveFreq = { 0 }, 0, 0 }},
382 .repeatCnt = ToneGenerator::TONEGEN_INF,
383 .repeatSegment = 0 }, // TONE_CDMA_LOW_SS_2
384 { .segments = { { .duration = 25, .waveFreq = { 3700, 0 }, 0, 0 },
385 { .duration = 25, .waveFreq = { 4000, 0 }, 9, 0 },
386 { .duration = 500, .waveFreq = { 0 }, 0, 0 },
387 { .duration = 25, .waveFreq = { 3700, 0 }, 0, 0 },
388 { .duration = 25, .waveFreq = { 4000, 0 }, 19, 3 },
389 { .duration = 500, .waveFreq = { 0 }, 0, 0 },
390 { .duration = 25, .waveFreq = { 3700, 0 }, 0, 0 },
391 { .duration = 25, .waveFreq = { 4000, 0 }, 9, 6 },
392 { .duration = 3000, .waveFreq = { 0 }, 0, 0 },
393 { .duration = 0, .waveFreq = { 0 }, 0, 0 }},
394 .repeatCnt = ToneGenerator::TONEGEN_INF,
395 .repeatSegment = 0 }, // TONE_CDMA_HIGH_SLS
396 { .segments = { { .duration = 25, .waveFreq = { 2600, 0 }, 0, 0 },
397 { .duration = 25, .waveFreq = { 2900, 0 }, 9, 0 },
398 { .duration = 500, .waveFreq = { 0 }, 0, 0 },
399 { .duration = 25, .waveFreq = { 2600, 0 }, 0, 0 },
400 { .duration = 25, .waveFreq = { 2900, 0 }, 19, 3 },
401 { .duration = 500, .waveFreq = { 0 }, 0, 0 },
402 { .duration = 25, .waveFreq = { 2600, 0 }, 0, 0 },
403 { .duration = 25, .waveFreq = { 2900, 0 }, 9, 6 },
404 { .duration = 3000, .waveFreq = { 0 }, 0, 0 },
405 { .duration = 0, .waveFreq = { 0 }, 0, 0 }},
406 .repeatCnt = ToneGenerator::TONEGEN_INF,
407 .repeatSegment = 0 }, // TONE_CDMA_MED_SLS
408 { .segments = { { .duration = 25, .waveFreq = { 1300, 0 }, 0, 0 },
409 { .duration = 25, .waveFreq = { 1450, 0 }, 9, 0 },
410 { .duration = 500, .waveFreq = { 0 }, 0, 0 },
411 { .duration = 25, .waveFreq = { 1300, 0 }, 0, 0 },
412 { .duration = 25, .waveFreq = { 1450, 0 }, 19, 3 },
413 { .duration = 500, .waveFreq = { 0 }, 0, 0 },
414 { .duration = 25, .waveFreq = { 1300, 0 }, 0, 0 },
415 { .duration = 25, .waveFreq = { 1450, 0 }, 9, 6 },
416 { .duration = 3000, .waveFreq = { 0 }, 0, 0 },
417 { .duration = 0, .waveFreq = { 0 }, 0, 0 }},
418 .repeatCnt = ToneGenerator::TONEGEN_INF,
419 .repeatSegment = 0 }, // TONE_CDMA_LOW_SLS
420 { .segments = { { .duration = 25, .waveFreq = { 3700, 0 }, 0, 0 },
421 { .duration = 25, .waveFreq = { 4000, 0 }, 9, 0 },
422 { .duration = 500, .waveFreq = { 0 }, 0, 0 },
423 { .duration = 25, .waveFreq = { 3700, 0 }, 0, 0 },
424 { .duration = 25, .waveFreq = { 4000, 0 }, 9, 3 },
425 { .duration = 500, .waveFreq = { 0 }, 0, 0 },
426 { .duration = 25, .waveFreq = { 3700, 0 }, 0, 0 },
427 { .duration = 25, .waveFreq = { 4000, 0 }, 9, 6 },
428 { .duration = 500, .waveFreq = { 0 }, 0, 0 },
429 { .duration = 25, .waveFreq = { 3700, 0 }, 0, 0 },
430 { .duration = 25, .waveFreq = { 4000, 0 }, 9, 9 },
431 { .duration = 2500, .waveFreq = { 0 }, 0, 0 },
432 { .duration = 0, .waveFreq = { 0 }, 0, 0 }},
433 .repeatCnt = ToneGenerator::TONEGEN_INF,
434 .repeatSegment = 0 }, // TONE_CDMA_HIGH_S_X4
435 { .segments = { { .duration = 25, .waveFreq = { 2600, 0 }, 0, 0 },
436 { .duration = 25, .waveFreq = { 2900, 0 }, 9, 0 },
437 { .duration = 500, .waveFreq = { 0 }, 0, 0 },
438 { .duration = 25, .waveFreq = { 2600, 0 }, 0, 0 },
439 { .duration = 25, .waveFreq = { 2900, 0 }, 9, 3 },
440 { .duration = 500, .waveFreq = { 0 }, 0, 0 },
441 { .duration = 25, .waveFreq = { 2600, 0 }, 0, 0 },
442 { .duration = 25, .waveFreq = { 2900, 0 }, 9, 6 },
443 { .duration = 500, .waveFreq = { 0 }, 0, 0 },
444 { .duration = 25, .waveFreq = { 2600, 0 }, 0, 0 },
445 { .duration = 25, .waveFreq = { 2900, 0 }, 9, 9 },
446 { .duration = 2500, .waveFreq = { 0 }, 0, 0 },
447 { .duration = 0, .waveFreq = { 0 }, 0, 0 }},
448 .repeatCnt = ToneGenerator::TONEGEN_INF,
449 .repeatSegment = 0 }, // TONE_CDMA_MED_S_X4
450 { .segments = { { .duration = 25, .waveFreq = { 1300, 0 }, 0, 0 },
451 { .duration = 25, .waveFreq = { 1450, 0 }, 9, 0 },
452 { .duration = 500, .waveFreq = { 0 }, 0, 0 },
453 { .duration = 25, .waveFreq = { 1300, 0 }, 0, 0 },
454 { .duration = 25, .waveFreq = { 1450, 0 }, 9, 3 },
455 { .duration = 500, .waveFreq = { 0 }, 0, 0 },
456 { .duration = 25, .waveFreq = { 1300, 0 }, 0, 0 },
457 { .duration = 25, .waveFreq = { 1450, 0 }, 9, 6 },
458 { .duration = 500, .waveFreq = { 0 }, 0, 0 },
459 { .duration = 25, .waveFreq = { 1300, 0 }, 0, 0 },
460 { .duration = 25, .waveFreq = { 1450, 0 }, 9, 9 },
461 { .duration = 2500, .waveFreq = { 0 }, 0, 0 },
462 { .duration = 0, .waveFreq = { 0 }, 0, 0 }},
463 .repeatCnt = ToneGenerator::TONEGEN_INF,
464 .repeatSegment = 0 }, // TONE_CDMA_LOW_S_X4
465 { .segments = { { .duration = 25, .waveFreq = { 3700, 0 }, 0, 0 },
466 { .duration = 25, .waveFreq = { 4000, 0 }, 19, 0 },
467 { .duration = 2000, .waveFreq = { 0 }, 0, 0 },
468 { .duration = 0, .waveFreq = { 0 }, 0, 0 }},
469 .repeatCnt = ToneGenerator::TONEGEN_INF,
470 .repeatSegment = 0 }, // TONE_CDMA_HIGH_PBX_L
471 { .segments = { { .duration = 25, .waveFreq = { 2600, 0 }, 0, 0 },
472 { .duration = 25, .waveFreq = { 2900, 0 }, 19, 0 },
473 { .duration = 2000, .waveFreq = { 0 }, 0, 0 },
474 { .duration = 0, .waveFreq = { 0 }, 0, 0 }},
475 .repeatCnt = ToneGenerator::TONEGEN_INF,
476 .repeatSegment = 0 }, // TONE_CDMA_MED_PBX_L
477 { .segments = { { .duration = 25, .waveFreq = { 1300, 0 }, 0, 0 },
478 { .duration = 25, .waveFreq = { 1450, 0 }, 19, 0 },
479 { .duration = 2000, .waveFreq = { 0 }, 0, 0 },
480 { .duration = 0, .waveFreq = { 0 }, 0, 0 }},
481 .repeatCnt = ToneGenerator::TONEGEN_INF,
482 .repeatSegment = 0 }, // TONE_CDMA_LOW_PBX_L
483 { .segments = { { .duration = 25, .waveFreq = { 3700, 0 }, 0, 0 },
484 { .duration = 25, .waveFreq = { 4000, 0 }, 7, 0 },
485 { .duration = 200, .waveFreq = { 0 }, 0, 0 },
486 { .duration = 25, .waveFreq = { 3700, 0 }, 0, 0 },
487 { .duration = 25, .waveFreq = { 4000, 0 }, 7, 3 },
488 { .duration = 2000, .waveFreq = { 0 }, 0, 0 },
489 { .duration = 0, .waveFreq = { 0 }, 0, 0 }},
490 .repeatCnt = ToneGenerator::TONEGEN_INF,
491 .repeatSegment = 0 }, // TONE_CDMA_HIGH_PBX_SS
492 { .segments = { { .duration = 25, .waveFreq = { 2600, 0 }, 0, 0 },
493 { .duration = 25, .waveFreq = { 2900, 0 }, 7, 0 },
494 { .duration = 200, .waveFreq = { 0 }, 0, 0 },
495 { .duration = 25, .waveFreq = { 2600, 0 }, 0, 0 },
496 { .duration = 25, .waveFreq = { 2900, 0 }, 7, 3 },
497 { .duration = 2000, .waveFreq = { 0 }, 0, 0 },
498 { .duration = 0, .waveFreq = { 0 }, 0, 0 }},
499 .repeatCnt = ToneGenerator::TONEGEN_INF,
500 .repeatSegment = 0 }, // TONE_CDMA_MED_PBX_SS
501 { .segments = { { .duration = 25, .waveFreq = { 1300, 0 }, 0, 0 },
502 { .duration = 25, .waveFreq = { 1450, 0 }, 7, 0 },
503 { .duration = 200, .waveFreq = { 0 }, 0, 0 },
504 { .duration = 25, .waveFreq = { 1300, 0 }, 0, 0 },
505 { .duration = 25, .waveFreq = { 1450, 0 }, 7, 3 },
506 { .duration = 2000, .waveFreq = { 0 }, 0, 0 },
507 { .duration = 0, .waveFreq = { 0 }, 0, 0 }},
508 .repeatCnt = ToneGenerator::TONEGEN_INF,
509 .repeatSegment = 0 }, // TONE_CDMA_LOW_PBX_SS
510 { .segments = { { .duration = 25, .waveFreq = { 3700, 0 }, 0, 0 },
511 { .duration = 25, .waveFreq = { 4000, 0 }, 7, 0 },
512 { .duration = 200, .waveFreq = { 0 }, 0, 0 },
513 { .duration = 25, .waveFreq = { 3700, 0 }, 0, 0 },
514 { .duration = 25, .waveFreq = { 4000, 0 }, 7, 3 },
515 { .duration = 200, .waveFreq = { 0 }, 0, 0 },
516 { .duration = 25, .waveFreq = { 3700, 0 }, 0, 0 },
517 { .duration = 25, .waveFreq = { 4000, 0 }, 15, 6 },
518 { .duration = 1000, .waveFreq = { 0 }, 0, 0 },
519 { .duration = 0, .waveFreq = { 0 }, 0, 0 }},
520 .repeatCnt = ToneGenerator::TONEGEN_INF,
521 .repeatSegment = 0 }, // TONE_CDMA_HIGH_PBX_SSL
522 { .segments = { { .duration = 25, .waveFreq = { 2600, 0 }, 0, 0 },
523 { .duration = 25, .waveFreq = { 2900, 0 }, 7, 0 },
524 { .duration = 200, .waveFreq = { 0 }, 0, 0 },
525 { .duration = 25, .waveFreq = { 2600, 0 }, 0, 0 },
526 { .duration = 25, .waveFreq = { 2900, 0 }, 7, 3 },
527 { .duration = 200, .waveFreq = { 0 }, 0, 0 },
528 { .duration = 25, .waveFreq = { 2600, 0 }, 0, 0 },
529 { .duration = 25, .waveFreq = { 2900, 0 }, 15, 6 },
530 { .duration = 1000, .waveFreq = { 0 }, 0, 0 },
531 { .duration = 0, .waveFreq = { 0 }, 0, 0 }},
532 .repeatCnt = ToneGenerator::TONEGEN_INF,
533 .repeatSegment = 0 }, // TONE_CDMA_MED_PBX_SSL
534 { .segments = { { .duration = 25, .waveFreq = { 1300, 0 }, 0, 0 },
535 { .duration = 25, .waveFreq = { 1450, 0 }, 7, 0 },
536 { .duration = 200, .waveFreq = { 0 }, 0, 0 },
537 { .duration = 25, .waveFreq = { 1300, 0 }, 0, 0 },
538 { .duration = 25, .waveFreq = { 1450, 0 }, 7, 3 },
539 { .duration = 200, .waveFreq = { 0 }, 0, 0 },
540 { .duration = 25, .waveFreq = { 1300, 0 }, 0, 0 },
541 { .duration = 25, .waveFreq = { 1450, 0 }, 15, 6 },
542 { .duration = 1000, .waveFreq = { 0 }, 0, 0 },
543 { .duration = 0, .waveFreq = { 0 }, 0, 0 }},
544 .repeatCnt = ToneGenerator::TONEGEN_INF,
545 .repeatSegment = 0 }, // TONE_CDMA_LOW_PBX_SSL
546 { .segments = { { .duration = 25, .waveFreq = { 3700, 0 }, 0, 0 },
547 { .duration = 25, .waveFreq = { 4000, 0 }, 7, 0 },
548 { .duration = 200, .waveFreq = { 0 }, 0, 0 },
549 { .duration = 25, .waveFreq = { 3700, 0 }, 0, 0 },
550 { .duration = 25, .waveFreq = { 4000, 0 }, 15, 3 },
551 { .duration = 200, .waveFreq = { 0 }, 0, 0 },
552 { .duration = 25, .waveFreq = { 3700, 0 }, 0, 0 },
553 { .duration = 25, .waveFreq = { 4000, 0 }, 7, 6 },
554 { .duration = 1000, .waveFreq = { 0 }, 0, 0 },
555 { .duration = 0, .waveFreq = { 0 }, 0, 0 }},
556 .repeatCnt = ToneGenerator::TONEGEN_INF,
557 .repeatSegment = 0 }, // TONE_CDMA_HIGH_PBX_SLS
558 { .segments = { { .duration = 25, .waveFreq = { 2600, 0 }, 0, 0 },
559 { .duration = 25, .waveFreq = { 2900, 0 }, 7, 0 },
560 { .duration = 200, .waveFreq = { 0 }, 0, 0 },
561 { .duration = 25, .waveFreq = { 2600, 0 }, 0, 0 },
562 { .duration = 25, .waveFreq = { 2900, 0 }, 15, 3 },
563 { .duration = 200, .waveFreq = { 0 }, 0, 0 },
564 { .duration = 25, .waveFreq = { 2600, 0 }, 0, 0 },
565 { .duration = 25, .waveFreq = { 2900, 0 }, 7, 6 },
566 { .duration = 1000, .waveFreq = { 0 }, 0, 0 },
567 { .duration = 0, .waveFreq = { 0 }, 0, 0 }},
568 .repeatCnt = ToneGenerator::TONEGEN_INF,
569 .repeatSegment = 0 }, // TONE_CDMA_MED_PBX_SLS
570 { .segments = { { .duration = 25, .waveFreq = { 1300, 0 }, 0, 0 },
571 { .duration = 25, .waveFreq = { 1450, 0 }, 7, 0 },
572 { .duration = 200, .waveFreq = { 0 }, 0, 0 },
573 { .duration = 25, .waveFreq = { 1300, 0 }, 0, 0 },
574 { .duration = 25, .waveFreq = { 1450, 0 }, 15, 3 },
575 { .duration = 200, .waveFreq = { 0 }, 0, 0 },
576 { .duration = 25, .waveFreq = { 1300, 0 }, 0, 0 },
577 { .duration = 25, .waveFreq = { 1450, 0 }, 7, 6 },
578 { .duration = 1000, .waveFreq = { 0 }, 0, 0 },
579 { .duration = 0, .waveFreq = { 0 }, 0, 0 }},
580 .repeatCnt = ToneGenerator::TONEGEN_INF,
581 .repeatSegment = 0 }, // TONE_CDMA_LOW_PBX_SLS
582 { .segments = { { .duration = 25, .waveFreq = { 3700, 0 }, 0, 0 },
583 { .duration = 25, .waveFreq = { 4000, 0 }, 7, 0 },
584 { .duration = 200, .waveFreq = { 0 }, 0, 0 },
585 { .duration = 25, .waveFreq = { 3700, 0 }, 0, 0 },
586 { .duration = 25, .waveFreq = { 4000, 0 }, 7, 3 },
587 { .duration = 200, .waveFreq = { 0 }, 0, 0 },
588 { .duration = 25, .waveFreq = { 3700, 0 }, 0, 0 },
589 { .duration = 25, .waveFreq = { 4000, 0 }, 7, 6 },
590 { .duration = 200, .waveFreq = { 0 }, 0, 0 },
591 { .duration = 25, .waveFreq = { 3700, 0 }, 0, 0 },
592 { .duration = 25, .waveFreq = { 4000, 0 }, 7, 9 },
593 { .duration = 800, .waveFreq = { 0 }, 0, 0 },
594 { .duration = 0, .waveFreq = { 0 }, 0, 0 }},
595 .repeatCnt = ToneGenerator::TONEGEN_INF,
596 .repeatSegment = 0 }, // TONE_CDMA_HIGH_PBX_S_X4
597 { .segments = { { .duration = 25, .waveFreq = { 2600, 0 }, 0, 0 },
598 { .duration = 25, .waveFreq = { 2900, 0 }, 7, 0 },
599 { .duration = 200, .waveFreq = { 0 }, 0, 0 },
600 { .duration = 25, .waveFreq = { 2600, 0 }, 0, 0 },
601 { .duration = 25, .waveFreq = { 2900, 0 }, 7, 3 },
602 { .duration = 200, .waveFreq = { 0 }, 0, 0 },
603 { .duration = 25, .waveFreq = { 2600, 0 }, 0, 0 },
604 { .duration = 25, .waveFreq = { 2900, 0 }, 7, 6 },
605 { .duration = 200, .waveFreq = { 0 }, 0, 0 },
606 { .duration = 25, .waveFreq = { 2600, 0 }, 0, 0 },
607 { .duration = 25, .waveFreq = { 2900, 0 }, 7, 9 },
608 { .duration = 800, .waveFreq = { 0 }, 0, 0 },
609 { .duration = 0, .waveFreq = { 0 }, 0, 0 }},
610 .repeatCnt = ToneGenerator::TONEGEN_INF,
611 .repeatSegment = 0 }, // TONE_CDMA_MED_PBX_S_X4
612 { .segments = { { .duration = 25, .waveFreq = { 1300, 0 }, 0, 0 },
613 { .duration = 25, .waveFreq = { 1450, 0 }, 7, 0 },
614 { .duration = 200, .waveFreq = { 0 }, 0, 0 },
615 { .duration = 25, .waveFreq = { 1300, 0 }, 0, 0 },
616 { .duration = 25, .waveFreq = { 1450, 0 }, 7, 3 },
617 { .duration = 200, .waveFreq = { 0 }, 0, 0 },
618 { .duration = 25, .waveFreq = { 1300, 0 }, 0, 0 },
619 { .duration = 25, .waveFreq = { 1450, 0 }, 7, 6 },
620 { .duration = 200, .waveFreq = { 0 }, 0, 0 },
621 { .duration = 25, .waveFreq = { 1300, 0 }, 0, 0 },
622 { .duration = 25, .waveFreq = { 1450, 0 }, 7, 9 },
623 { .duration = 800, .waveFreq = { 0 }, 0, 0 },
624 { .duration = 0, .waveFreq = { 0 }, 0, 0 }},
625 .repeatCnt = ToneGenerator::TONEGEN_INF,
626 .repeatSegment = 0 }, // TONE_CDMA_LOW_PBX_S_X4
627
628 { .segments = { { .duration = 62, .waveFreq = { 1109, 0 }, 0, 0 },
629 { .duration = 62, .waveFreq = { 784, 0 }, 0, 0 },
630 { .duration = 62, .waveFreq = { 740, 0 }, 0, 0 },
631 { .duration = 62, .waveFreq = { 622, 0 }, 0, 0 },
632 { .duration = 62, .waveFreq = { 1109, 0 }, 0, 0 },
633 { .duration = 0, .waveFreq = { 0 }, 0, 0 } },
634 .repeatCnt = 0,
635 .repeatSegment = 0 }, // TONE_CDMA_ALERT_NETWORK_LITE
636 { .segments = { { .duration = 62, .waveFreq = { 1245, 0 }, 0, 0 },
637 { .duration = 62, .waveFreq = { 659, 0 }, 2, 0 },
638 { .duration = 62, .waveFreq = { 1245, 0 }, 0, 0 },
639 { .duration = 0, .waveFreq = { 0 }, 0, 0 } },
640 .repeatCnt = 0,
641 .repeatSegment = 0 }, // TONE_CDMA_ALERT_AUTOREDIAL_LITE
642 { .segments = { { .duration = 400, .waveFreq = { 1150, 770, 0 }, 0, 0 },
643 { .duration = 0, .waveFreq = { 0 }, 0, 0 } },
644 .repeatCnt = 0,
645 .repeatSegment = 0 }, // TONE_CDMA_ONE_MIN_BEEP
646 { .segments = { { .duration = 120, .waveFreq = { 941, 1477, 0 }, 0, 0 },
647 { .duration = 0, .waveFreq = { 0 }, 0, 0 } },
648 .repeatCnt = 0,
649 .repeatSegment = 0 }, // TONE_CDMA_KEYPAD_VOLUME_KEY_LITE
650 { .segments = { { .duration = 375, .waveFreq = { 587, 0 }, 0, 0 },
651 { .duration = 125, .waveFreq = { 1175, 0 }, 0, 0 },
652 { .duration = 0, .waveFreq = { 0 }, 0, 0 } },
653 .repeatCnt = 0,
654 .repeatSegment = 0 }, // TONE_CDMA_PRESSHOLDKEY_LITE
655 { .segments = { { .duration = 62, .waveFreq = { 587, 0 }, 0, 0 },
656 { .duration = 62, .waveFreq = { 784, 0 }, 0, 0 },
657 { .duration = 62, .waveFreq = { 831, 0 }, 0, 0 },
658 { .duration = 62, .waveFreq = { 784, 0 }, 0, 0 },
659 { .duration = 62, .waveFreq = { 1109, 0 }, 0, 0 },
660 { .duration = 62, .waveFreq = { 784, 0 }, 0, 0 },
661 { .duration = 62, .waveFreq = { 831, 0 }, 0, 0 },
662 { .duration = 62, .waveFreq = { 784, 0 }, 0, 0 },
663 { .duration = 0, .waveFreq = { 0 }, 0, 0 } },
664 .repeatCnt = 0,
665 .repeatSegment = 0 }, // TONE_CDMA_ALERT_INCALL_LITE
666 { .segments = { { .duration = 125, .waveFreq = { 941, 0 }, 0, 0 },
667 { .duration = 10, .waveFreq = { 0 }, 2, 0 },
668 { .duration = 4990, .waveFreq = { 0 }, 0, 0 },
669 { .duration = 0, .waveFreq = { 0 }, 0, 0 } },
670 .repeatCnt = ToneGenerator::TONEGEN_INF,
671 .repeatSegment = 0 }, // TONE_CDMA_EMERGENCY_RINGBACK
672 { .segments = { { .duration = 125, .waveFreq = { 1319, 0 }, 0, 0 },
673 { .duration = 125, .waveFreq = { 0 }, 0, 0 },
674 { .duration = 0, .waveFreq = { 0 }, 0, 0 } },
675 .repeatCnt = 2,
676 .repeatSegment = 0 }, // TONE_CDMA_ALERT_CALL_GUARD
677 { .segments = { { .duration = 125, .waveFreq = { 1047, 0 }, 0, 0 },
678 { .duration = 125, .waveFreq = { 370, 0 }, 0, 0 },
679 { .duration = 0, .waveFreq = { 0 }, 0, 0 } },
680 .repeatCnt = 0,
681 .repeatSegment = 0 }, // TONE_CDMA_SOFT_ERROR_LITE
682 { .segments = { { .duration = 125, .waveFreq = { 1480, 0 }, 0, 0 },
683 { .duration = 125, .waveFreq = { 1397, 0 }, 0, 0 },
684 { .duration = 125, .waveFreq = { 784, 0 }, 0, 0 },
685 { .duration = 0, .waveFreq = { 0 }, 0, 0 } },
686 .repeatCnt = 0,
687 .repeatSegment = 0 }, // TONE_CDMA_CALLDROP_LITE
688
689 { .segments = { { .duration = 500, .waveFreq = { 425, 0 }, 0, 0 },
690 { .duration = 500, .waveFreq = { 0 }, 0, 0 },
691 { .duration = 0, .waveFreq = { 0 }, 0, 0 }},
692 .repeatCnt = 0,
693 .repeatSegment = 0 }, // TONE_CDMA_NETWORK_BUSY_ONE_SHOT
694 { .segments = { { .duration = 400, .waveFreq = { 1150, 770 }, 0, 0 },
695 { .duration = 0, .waveFreq = { 0 }, 0, 0 }},
696 .repeatCnt = 0,
697 .repeatSegment = 0 }, // TONE_CDMA_ABBR_ALERT
698 { .segments = { { .duration = 0, .waveFreq = { 0 }, 0, 0 }},
699 .repeatCnt = 0,
700 .repeatSegment = 0 }, // TONE_CDMA_SIGNAL_OFF
701
702 { .segments = { { .duration = ToneGenerator::TONEGEN_INF, .waveFreq = { 350, 440, 0 }, 0, 0 },
703 { .duration = 0 , .waveFreq = { 0 }, 0, 0}},
704 .repeatCnt = ToneGenerator::TONEGEN_INF,
705 .repeatSegment = 0 }, // TONE_ANSI_DIAL
706 { .segments = { { .duration = 500, .waveFreq = { 480, 620, 0 }, 0, 0 },
707 { .duration = 500, .waveFreq = { 0 }, 0, 0 },
708 { .duration = 0 , .waveFreq = { 0 }, 0, 0}},
709 .repeatCnt = ToneGenerator::TONEGEN_INF,
710 .repeatSegment = 0 }, // TONE_ANSI_BUSY
711 { .segments = { { .duration = 250, .waveFreq = { 480, 620, 0 }, 0, 0 },
712 { .duration = 250, .waveFreq = { 0 }, 0, 0 },
713 { .duration = 0 , .waveFreq = { 0 }, 0, 0}},
714 .repeatCnt = ToneGenerator::TONEGEN_INF,
715 .repeatSegment = 0 }, // TONE_ANSI_CONGESTION
716 { .segments = { { .duration = 300, .waveFreq = { 440, 0 }, 0, 0 },
717 { .duration = 9700, .waveFreq = { 0 }, 0, 0 },
718 { .duration = 100, .waveFreq = { 440, 0 }, 0, 0 },
719 { .duration = 100, .waveFreq = { 0 }, 0, 0 },
720 { .duration = 100, .waveFreq = { 440, 0 }, 0, 0 },
721 { .duration = 0 , .waveFreq = { 0 }, 0, 0}},
722 .repeatCnt = ToneGenerator::TONEGEN_INF,
723 .repeatSegment = 1 }, // TONE_ANSI_CALL_WAITING
724 { .segments = { { .duration = 2000, .waveFreq = { 440, 480, 0 }, 0, 0 },
725 { .duration = 4000, .waveFreq = { 0 }, 0, 0 },
726 { .duration = 0 , .waveFreq = { 0 }, 0, 0}},
727 .repeatCnt = ToneGenerator::TONEGEN_INF,
728 .repeatSegment = 0 }, // TONE_ANSI_RINGTONE
729 { .segments = { { .duration = ToneGenerator::TONEGEN_INF, .waveFreq = { 400, 0 }, 0, 0 },
730 { .duration = 0 , .waveFreq = { 0 }, 0, 0}},
731 .repeatCnt = ToneGenerator::TONEGEN_INF,
732 .repeatSegment = 0 }, // TONE_JAPAN_DIAL
733 { .segments = { { .duration = 500, .waveFreq = { 400, 0 }, 0, 0 },
734 { .duration = 500, .waveFreq = { 0 }, 0, 0 },
735 { .duration = 0 , .waveFreq = { 0 }, 0, 0}},
736 .repeatCnt = ToneGenerator::TONEGEN_INF,
737 .repeatSegment = 0 }, // TONE_JAPAN_BUSY
738 { .segments = { { .duration = 1000, .waveFreq = { 400, 0 }, 0, 0 },
739 { .duration = 2000, .waveFreq = { 0 }, 0, 0 },
740 { .duration = 0 , .waveFreq = { 0 }, 0, 0}},
741 .repeatCnt = ToneGenerator::TONEGEN_INF,
742 .repeatSegment = 0 }, // TONE_JAPAN_RADIO_ACK
743 { .segments = { { .duration = 375, .waveFreq = { 400, 0 }, 0, 0 },
744 { .duration = 375, .waveFreq = { 0 }, 0, 0 },
745 { .duration = 0 , .waveFreq = { 0 }, 0, 0}},
746 .repeatCnt = ToneGenerator::TONEGEN_INF,
747 .repeatSegment = 0 }, // TONE_GB_BUSY
748 { .segments = { { .duration = 400, .waveFreq = { 400, 0 }, 0, 0 },
749 { .duration = 350, .waveFreq = { 0 }, 0, 0 },
750 { .duration = 225, .waveFreq = { 400, 0 }, 0, 0 },
751 { .duration = 525, .waveFreq = { 0 }, 0, 0 },
752 { .duration = 0 , .waveFreq = { 0 }, 0, 0}},
753 .repeatCnt = ToneGenerator::TONEGEN_INF,
754 .repeatSegment = 0 }, // TONE_GB_CONGESTION
755 { .segments = { { .duration = 400, .waveFreq = { 400, 450, 0 }, 0, 0 },
756 { .duration = 200, .waveFreq = { 0 }, 0, 0 },
757 { .duration = 400, .waveFreq = { 400, 450, 0 }, 0, 0 },
758 { .duration = 2000, .waveFreq = { 0 }, 0, 0},
759 { .duration = 0, .waveFreq = { 0 }, 0, 0}},
760 .repeatCnt = ToneGenerator::TONEGEN_INF,
761 .repeatSegment = 0 }, // TONE_GB_RINGTONE
762 { .segments = { { .duration = ToneGenerator::TONEGEN_INF, .waveFreq = { 400, 425, 450, 0 }, 0, 0 },
763 { .duration = 0 , .waveFreq = { 0 }, 0, 0}},
764 .repeatCnt = ToneGenerator::TONEGEN_INF,
765 .repeatSegment = 0 }, // TONE_AUSTRALIA_DIAL
766 { .segments = { { .duration = 400, .waveFreq = { 400, 450, 0 }, 0, 0 },
767 { .duration = 200, .waveFreq = { 0 }, 0, 0 },
768 { .duration = 400, .waveFreq = { 400, 450, 0 }, 0, 0 },
769 { .duration = 2000, .waveFreq = { 0 }, 0, 0},
770 { .duration = 0, .waveFreq = { 0 }, 0, 0}},
771 .repeatCnt = ToneGenerator::TONEGEN_INF,
772 .repeatSegment = 0 }, // TONE_AUSTRALIA_RINGTONE
773 { .segments = { { .duration = 375, .waveFreq = { 425, 0 }, 0, 0 },
774 { .duration = 375, .waveFreq = { 0 }, 0, 0 },
775 { .duration = 0 , .waveFreq = { 0 }, 0, 0}},
776 .repeatCnt = ToneGenerator::TONEGEN_INF,
777 .repeatSegment = 0 }, // TONE_AUSTRALIA_BUSY
778 { .segments = { { .duration = 200, .waveFreq = { 425, 0 }, 0, 0 },
779 { .duration = 200, .waveFreq = { 0 }, 0, 0 },
780 { .duration = 200, .waveFreq = { 425, 0 }, 0, 0 },
781 { .duration = 4400, .waveFreq = { 0 }, 0, 0 },
782 { .duration = 0 , .waveFreq = { 0 }, 0, 0}},
783 .repeatCnt = ToneGenerator::TONEGEN_INF,
784 .repeatSegment = 0 }, // TONE_AUSTRALIA_CALL_WAITING
785 { .segments = { { .duration = 375, .waveFreq = { 425, 0 }, 0, 0 },
786 { .duration = 375, .waveFreq = { 0 }, 0, 0 },
787 { .duration = 0 , .waveFreq = { 0 }, 0, 0}},
788 .repeatCnt = ToneGenerator::TONEGEN_INF,
789 .repeatSegment = 0 }, // TONE_AUSTRALIA_CONGESTION
790 { .segments = { { .duration = 750, .waveFreq = { 425, 0 }, 0, 0 },
791 { .duration = 750, .waveFreq = { 0 }, 0, 0 },
792 { .duration = 0 , .waveFreq = { 0 }, 0, 0}},
793 .repeatCnt = ToneGenerator::TONEGEN_INF,
794 .repeatSegment = 0 }, // TONE_SG_BUSY
795 { .segments = { { .duration = 400, .waveFreq = { 401, 425, 449, 0 }, 0, 0 },
796 { .duration = 200, .waveFreq = { 0 }, 0, 0 },
797 { .duration = 400, .waveFreq = { 401, 425, 449, 0 }, 0, 0 },
798 { .duration = 2000, .waveFreq = { 0 }, 0, 0 },
799 { .duration = 0 , .waveFreq = { 0 }, 0, 0}},
800 .repeatCnt = ToneGenerator::TONEGEN_INF,
801 .repeatSegment = 0 }, // TONE_SG_RINGTONE
802 { .segments = { { .duration = 500, .waveFreq = { 480, 620, 0 }, 0, 0 },
803 { .duration = 500, .waveFreq = { 0 }, 0, 0 },
804 { .duration = 0 , .waveFreq = { 0 }, 0, 0}},
805 .repeatCnt = ToneGenerator::TONEGEN_INF,
806 .repeatSegment = 0 }, // TONE_HK_BUSY
807 { .segments = { { .duration = 400, .waveFreq = { 440, 480, 0 }, 0, 0 },
808 { .duration = 200, .waveFreq = { 0 }, 0, 0 },
809 { .duration = 400, .waveFreq = { 440, 480, 0 }, 0, 0 },
810 { .duration = 3000, .waveFreq = { 0 }, 0, 0 },
811 { .duration = 0 , .waveFreq = { 0 }, 0, 0}},
812 .repeatCnt = ToneGenerator::TONEGEN_INF,
813 .repeatSegment = 0 }, // TONE_HK_RINGTONE
814 { .segments = { { .duration = 400, .waveFreq = { 400, 450, 0 }, 0, 0 },
815 { .duration = 200, .waveFreq = { 0 }, 0, 0 },
816 { .duration = 400, .waveFreq = { 400, 450, 0 }, 0, 0 },
817 { .duration = 2000, .waveFreq = { 0 }, 0, 0},
818 { .duration = 0, .waveFreq = { 0 }, 0, 0}},
819 .repeatCnt = ToneGenerator::TONEGEN_INF,
820 .repeatSegment = 0 }, // TONE_IE_RINGTONE
821 { .segments = { { .duration = 180, .waveFreq = { 425, 0 }, 0, 0 },
822 { .duration = 200, .waveFreq = { 0 }, 0, 0 },
823 { .duration = 200, .waveFreq = { 425, 0 }, 0, 0 },
824 { .duration = 4500, .waveFreq = { 0 }, 0, 0 },
825 { .duration = 0 , .waveFreq = { 0 }, 0, 0}},
826 .repeatCnt = ToneGenerator::TONEGEN_INF,
827 .repeatSegment = 0 }, // TONE_IE_CALL_WAITING
828 { .segments = { { .duration = ToneGenerator::TONEGEN_INF, .waveFreq = { 375, 400, 425, 0 }, 0, 0 },
829 { .duration = 0 , .waveFreq = { 0 }, 0, 0}},
830 .repeatCnt = ToneGenerator::TONEGEN_INF,
831 .repeatSegment = 0 }, // TONE_INDIA_DIAL
832 { .segments = { { .duration = 750, .waveFreq = { 400, 0 }, 0, 0 },
833 { .duration = 750, .waveFreq = { 0 }, 0, 0 },
834 { .duration = 0 , .waveFreq = { 0 }, 0, 0}},
835 .repeatCnt = ToneGenerator::TONEGEN_INF,
836 .repeatSegment = 0 }, // TONE_INDIA_BUSY
837 { .segments = { { .duration = 250, .waveFreq = { 400, 0 }, 0, 0 },
838 { .duration = 250, .waveFreq = { 0 }, 0, 0 },
839 { .duration = 0 , .waveFreq = { 0 }, 0, 0}},
840 .repeatCnt = ToneGenerator::TONEGEN_INF,
841 .repeatSegment = 0 }, // TONE_INDIA_CONGESTION
842 { .segments = { { .duration = 200, .waveFreq = { 400, 0 }, 0, 0 },
843 { .duration = 100, .waveFreq = { 0 }, 0, 0 },
844 { .duration = 200, .waveFreq = { 400, 0 }, 0, 0 },
845 { .duration = 7500, .waveFreq = { 0 }, 0, 0 },
846 { .duration = 0 , .waveFreq = { 0 }, 0, 0}},
847 .repeatCnt = ToneGenerator::TONEGEN_INF,
848 .repeatSegment = 0 }, // TONE_INDIA_CALL_WAITING
849 { .segments = { { .duration = 400, .waveFreq = { 375, 400, 425, 0 }, 0, 0 },
850 { .duration = 200, .waveFreq = { 0 }, 0, 0 },
851 { .duration = 400, .waveFreq = { 375, 400, 425, 0 }, 0, 0 },
852 { .duration = 2000, .waveFreq = { 0 }, 0, 0 },
853 { .duration = 0 , .waveFreq = { 0 }, 0, 0}},
854 .repeatCnt = ToneGenerator::TONEGEN_INF,
855 .repeatSegment = 0 }, // TONE_INDIA_RINGTONE
856 { .segments = { { .duration = 1000, .waveFreq = { 440, 480, 0 }, 0, 0 },
857 { .duration = 2000, .waveFreq = { 0 }, 0, 0 },
858 { .duration = 0 , .waveFreq = { 0 }, 0, 0}},
859 .repeatCnt = ToneGenerator::TONEGEN_INF,
860 .repeatSegment = 0 }, // TONE_TW_RINGTONE
861 };
862
863 // Used by ToneGenerator::getToneForRegion() to convert user specified supervisory tone type
864 // to actual tone for current region.
865 const unsigned char /*tone_type*/ ToneGenerator::sToneMappingTable[NUM_REGIONS-1][NUM_SUP_TONES] = {
866 { // ANSI
867 TONE_ANSI_DIAL, // TONE_SUP_DIAL
868 TONE_ANSI_BUSY, // TONE_SUP_BUSY
869 TONE_ANSI_CONGESTION, // TONE_SUP_CONGESTION
870 TONE_SUP_RADIO_ACK, // TONE_SUP_RADIO_ACK
871 TONE_SUP_RADIO_NOTAVAIL, // TONE_SUP_RADIO_NOTAVAIL
872 TONE_SUP_ERROR, // TONE_SUP_ERROR
873 TONE_ANSI_CALL_WAITING, // TONE_SUP_CALL_WAITING
874 TONE_ANSI_RINGTONE // TONE_SUP_RINGTONE
875 },
876 { // JAPAN
877 TONE_JAPAN_DIAL, // TONE_SUP_DIAL
878 TONE_JAPAN_BUSY, // TONE_SUP_BUSY
879 TONE_SUP_CONGESTION, // TONE_SUP_CONGESTION
880 TONE_JAPAN_RADIO_ACK, // TONE_SUP_RADIO_ACK
881 TONE_SUP_RADIO_NOTAVAIL, // TONE_SUP_RADIO_NOTAVAIL
882 TONE_SUP_ERROR, // TONE_SUP_ERROR
883 TONE_SUP_CALL_WAITING, // TONE_SUP_CALL_WAITING
884 TONE_SUP_RINGTONE // TONE_SUP_RINGTONE
885 },
886 { // GB
887 TONE_ANSI_DIAL, // TONE_SUP_DIAL
888 TONE_GB_BUSY, // TONE_SUP_BUSY
889 TONE_GB_CONGESTION, // TONE_SUP_CONGESTION
890 TONE_SUP_RADIO_ACK, // TONE_SUP_RADIO_ACK
891 TONE_SUP_RADIO_NOTAVAIL, // TONE_SUP_RADIO_NOTAVAIL
892 TONE_SUP_ERROR, // TONE_SUP_ERROR
893 TONE_SUP_CALL_WAITING, // TONE_SUP_CALL_WAITING
894 TONE_GB_RINGTONE // TONE_SUP_RINGTONE
895 },
896 { // AUSTRALIA
897 TONE_AUSTRALIA_DIAL, // TONE_SUP_DIAL
898 TONE_AUSTRALIA_BUSY, // TONE_SUP_BUSY
899 TONE_AUSTRALIA_CONGESTION, // TONE_SUP_CONGESTION
900 TONE_SUP_RADIO_ACK, // TONE_SUP_RADIO_ACK
901 TONE_SUP_RADIO_NOTAVAIL, // TONE_SUP_RADIO_NOTAVAIL
902 TONE_SUP_ERROR, // TONE_SUP_ERROR
903 TONE_AUSTRALIA_CALL_WAITING,// TONE_SUP_CALL_WAITING
904 TONE_AUSTRALIA_RINGTONE // TONE_SUP_RINGTONE
905 },
906 { // SINGAPORE
907 TONE_SUP_DIAL, // TONE_SUP_DIAL
908 TONE_SG_BUSY, // TONE_SUP_BUSY
909 TONE_SUP_CONGESTION, // TONE_SUP_CONGESTION
910 TONE_SUP_RADIO_ACK, // TONE_SUP_RADIO_ACK
911 TONE_SUP_RADIO_NOTAVAIL, // TONE_SUP_RADIO_NOTAVAIL
912 TONE_SUP_ERROR, // TONE_SUP_ERROR
913 TONE_SUP_CALL_WAITING, // TONE_SUP_CALL_WAITING
914 TONE_SG_RINGTONE // TONE_SUP_RINGTONE
915 },
916 { // HONGKONG
917 TONE_SUP_DIAL, // TONE_SUP_DIAL
918 TONE_HK_BUSY, // TONE_SUP_BUSY
919 TONE_SUP_CONGESTION, // TONE_SUP_CONGESTION
920 TONE_SUP_RADIO_ACK, // TONE_SUP_RADIO_ACK
921 TONE_SUP_RADIO_NOTAVAIL, // TONE_SUP_RADIO_NOTAVAIL
922 TONE_SUP_ERROR, // TONE_SUP_ERROR
923 TONE_SUP_CALL_WAITING, // TONE_SUP_CALL_WAITING
924 TONE_HK_RINGTONE // TONE_SUP_RINGTONE
925 },
926 { // IRELAND
927 TONE_SUP_DIAL, // TONE_SUP_DIAL
928 TONE_SUP_BUSY, // TONE_SUP_BUSY
929 TONE_SUP_CONGESTION, // TONE_SUP_CONGESTION
930 TONE_SUP_RADIO_ACK, // TONE_SUP_RADIO_ACK
931 TONE_SUP_RADIO_NOTAVAIL, // TONE_SUP_RADIO_NOTAVAIL
932 TONE_SUP_ERROR, // TONE_SUP_ERROR
933 TONE_IE_CALL_WAITING, // TONE_SUP_CALL_WAITING
934 TONE_IE_RINGTONE // TONE_SUP_RINGTONE
935 },
936 { // INDIA
937 TONE_INDIA_DIAL, // TONE_SUP_DIAL
938 TONE_INDIA_BUSY, // TONE_SUP_BUSY
939 TONE_INDIA_CONGESTION, // TONE_SUP_CONGESTION
940 TONE_SUP_RADIO_ACK, // TONE_SUP_RADIO_ACK
941 TONE_SUP_RADIO_NOTAVAIL, // TONE_SUP_RADIO_NOTAVAIL
942 TONE_SUP_ERROR, // TONE_SUP_ERROR
943 TONE_INDIA_CALL_WAITING, // TONE_SUP_CALL_WAITING
944 TONE_INDIA_RINGTONE // TONE_SUP_RINGTONE
945 },
946 { // TAIWAN
947 TONE_SUP_DIAL, // TONE_SUP_DIAL
948 TONE_SUP_BUSY, // TONE_SUP_BUSY
949 TONE_SUP_CONGESTION, // TONE_SUP_CONGESTION
950 TONE_SUP_RADIO_ACK, // TONE_SUP_RADIO_ACK
951 TONE_SUP_RADIO_NOTAVAIL, // TONE_SUP_RADIO_NOTAVAIL
952 TONE_SUP_ERROR, // TONE_SUP_ERROR
953 TONE_SUP_CALL_WAITING, // TONE_SUP_CALL_WAITING
954 TONE_TW_RINGTONE // TONE_SUP_RINGTONE
955 }
956 };
957
958
959 ////////////////////////////////////////////////////////////////////////////////
960 // ToneGenerator class Implementation
961 ////////////////////////////////////////////////////////////////////////////////
962
963
964 //---------------------------------- public methods ----------------------------
965
966
967 ////////////////////////////////////////////////////////////////////////////////
968 //
969 // Method: ToneGenerator::ToneGenerator()
970 //
971 // Description: Constructor. Initializes the tone sequencer, intantiates required sine wave
972 // generators, instantiates output audio track.
973 //
974 // Input:
975 // streamType: Type of stream used for tone playback
976 // volume: volume applied to tone (0.0 to 1.0)
977 //
978 // Output:
979 // none
980 //
981 ////////////////////////////////////////////////////////////////////////////////
ToneGenerator(audio_stream_type_t streamType,float volume,bool threadCanCallJava)982 ToneGenerator::ToneGenerator(audio_stream_type_t streamType, float volume, bool threadCanCallJava) {
983
984 ALOGV("ToneGenerator constructor: streamType=%d, volume=%f", streamType, volume);
985
986 mState = TONE_IDLE;
987
988 if (AudioSystem::getOutputSamplingRate(&mSamplingRate, streamType) != NO_ERROR) {
989 ALOGE("Unable to marshal AudioFlinger");
990 return;
991 }
992 mThreadCanCallJava = threadCanCallJava;
993 mStreamType = streamType;
994 mVolume = volume;
995 mpToneDesc = NULL;
996 mpNewToneDesc = NULL;
997 // Generate tone by chunks of 20 ms to keep cadencing precision
998 mProcessSize = (mSamplingRate * 20) / 1000;
999
1000 char value[PROPERTY_VALUE_MAX];
1001 if (property_get("gsm.operator.iso-country", value, "") == 0) {
1002 property_get("gsm.sim.operator.iso-country", value, "");
1003 }
1004 // If dual sim device has two SIM cards inserted and is not registerd to any network,
1005 // "," is set to "gsm.operator.iso-country" prop.
1006 // In this case, "gsm.sim.operator.iso-country" prop should be used.
1007 if (strlen(value) == 1 && strstr(value, ",") != NULL) {
1008 property_get("gsm.sim.operator.iso-country", value, "");
1009 }
1010
1011 if (strstr(value, "us") != NULL ||
1012 strstr(value, "ca") != NULL) {
1013 mRegion = ANSI;
1014 } else if (strstr(value, "jp") != NULL) {
1015 mRegion = JAPAN;
1016 } else if (strstr(value, "gb") != NULL) {
1017 mRegion = GB;
1018 } else if (strstr(value, "au") != NULL) {
1019 mRegion = AUSTRALIA;
1020 } else if (strstr(value, "sg") != NULL) {
1021 mRegion = SINGAPORE;
1022 } else if (strstr(value, "hk") != NULL) {
1023 mRegion = HONGKONG;
1024 } else if (strstr(value, "ie") != NULL) {
1025 mRegion = IRELAND;
1026 } else if (strstr(value, "in") != NULL) {
1027 mRegion = INDIA;
1028 } else if (strstr(value, "tw") != NULL) {
1029 mRegion = TAIWAN;
1030 } else {
1031 mRegion = CEPT;
1032 }
1033
1034 if (initAudioTrack()) {
1035 ALOGV("ToneGenerator INIT OK, time: %d", (unsigned int)(systemTime()/1000000));
1036 } else {
1037 ALOGV("!!!ToneGenerator INIT FAILED!!!");
1038 }
1039 }
1040
1041
1042
1043
1044 ////////////////////////////////////////////////////////////////////////////////
1045 //
1046 // Method: ToneGenerator::~ToneGenerator()
1047 //
1048 // Description: Destructor. Stop sound playback and delete audio track if
1049 // needed and delete sine wave generators.
1050 //
1051 // Input:
1052 // none
1053 //
1054 // Output:
1055 // none
1056 //
1057 ////////////////////////////////////////////////////////////////////////////////
~ToneGenerator()1058 ToneGenerator::~ToneGenerator() {
1059 ALOGV("ToneGenerator destructor");
1060
1061 if (mpAudioTrack != 0) {
1062 stopTone();
1063 ALOGV("Delete Track: %p", mpAudioTrack.get());
1064 mpAudioTrack.clear();
1065 }
1066 clearWaveGens();
1067 }
1068
1069 ////////////////////////////////////////////////////////////////////////////////
1070 //
1071 // Method: ToneGenerator::startTone()
1072 //
1073 // Description: Starts tone playback.
1074 //
1075 // Input:
1076 // toneType: Type of tone generated (values in enum tone_type)
1077 // durationMs: The tone duration in milliseconds. If the tone is limited in time by definition,
1078 // the actual duration will be the minimum of durationMs and the defined tone duration.
1079 // Ommiting or setting durationMs to -1 does not limit tone duration.
1080 //
1081 // Output:
1082 // none
1083 //
1084 ////////////////////////////////////////////////////////////////////////////////
startTone(tone_type toneType,int durationMs)1085 bool ToneGenerator::startTone(tone_type toneType, int durationMs) {
1086 bool lResult = false;
1087 status_t lStatus;
1088
1089 if (toneType >= NUM_TONES)
1090 return lResult;
1091
1092 toneType = getToneForRegion(toneType);
1093 if (toneType == TONE_CDMA_SIGNAL_OFF) {
1094 return true;
1095 }
1096
1097 if (mState == TONE_IDLE) {
1098 ALOGV("startTone: try to re-init AudioTrack");
1099 if (!initAudioTrack()) {
1100 return lResult;
1101 }
1102 }
1103
1104 ALOGV("startTone toneType %d", toneType);
1105
1106 mLock.lock();
1107
1108 // Get descriptor for requested tone
1109 mpNewToneDesc = &sToneDescriptors[toneType];
1110
1111 mDurationMs = durationMs;
1112
1113 if (mState == TONE_STOPPED) {
1114 ALOGV("Start waiting for previous tone to stop");
1115 lStatus = mWaitCbkCond.waitRelative(mLock, seconds(3));
1116 if (lStatus != NO_ERROR) {
1117 ALOGE("--- start wait for stop timed out, status %d", lStatus);
1118 mState = TONE_IDLE;
1119 mLock.unlock();
1120 return lResult;
1121 }
1122 }
1123
1124 if (mState == TONE_INIT) {
1125 if (prepareWave()) {
1126 ALOGV("Immediate start, time %d", (unsigned int)(systemTime()/1000000));
1127 lResult = true;
1128 mState = TONE_STARTING;
1129 if (clock_gettime(CLOCK_MONOTONIC, &mStartTime) != 0) {
1130 mStartTime.tv_sec = 0;
1131 }
1132 mLock.unlock();
1133 mpAudioTrack->start();
1134 mLock.lock();
1135 if (mState == TONE_STARTING) {
1136 ALOGV("Wait for start callback");
1137 lStatus = mWaitCbkCond.waitRelative(mLock, seconds(3));
1138 if (lStatus != NO_ERROR) {
1139 ALOGE("--- Immediate start timed out, status %d", lStatus);
1140 mState = TONE_IDLE;
1141 lResult = false;
1142 }
1143 }
1144 } else {
1145 mState = TONE_IDLE;
1146 }
1147 } else {
1148 ALOGV("Delayed start");
1149 mState = TONE_RESTARTING;
1150 mStartTime.tv_sec = 0;
1151 lStatus = mWaitCbkCond.waitRelative(mLock, seconds(3));
1152 if (lStatus == NO_ERROR) {
1153 if (mState != TONE_IDLE) {
1154 lResult = true;
1155 }
1156 ALOGV("cond received");
1157 } else {
1158 ALOGE("--- Delayed start timed out, status %d", lStatus);
1159 mState = TONE_IDLE;
1160 }
1161 }
1162 mLock.unlock();
1163
1164 ALOGV_IF(lResult, "Tone started, time %d", (unsigned int)(systemTime()/1000000));
1165 ALOGW_IF(!lResult, "Tone start failed!!!, time %d", (unsigned int)(systemTime()/1000000));
1166
1167 return lResult;
1168 }
1169
1170 ////////////////////////////////////////////////////////////////////////////////
1171 //
1172 // Method: ToneGenerator::stopTone()
1173 //
1174 // Description: Stops tone playback.
1175 //
1176 // Input:
1177 // none
1178 //
1179 // Output:
1180 // none
1181 //
1182 ////////////////////////////////////////////////////////////////////////////////
stopTone()1183 void ToneGenerator::stopTone() {
1184 ALOGV("stopTone");
1185
1186 mLock.lock();
1187 if (mState != TONE_IDLE && mState != TONE_INIT) {
1188 if (mState == TONE_PLAYING || mState == TONE_STARTING || mState == TONE_RESTARTING) {
1189 struct timespec stopTime;
1190 // If the start time is valid, make sure that the number of audio samples produced
1191 // corresponds at least to the time between the start and stop commands.
1192 // This is needed in case of cold start of the output stream.
1193 if ((mStartTime.tv_sec != 0) && (clock_gettime(CLOCK_MONOTONIC, &stopTime) == 0)) {
1194 time_t sec = stopTime.tv_sec - mStartTime.tv_sec;
1195 auto nsec = stopTime.tv_nsec - mStartTime.tv_nsec;
1196 if (nsec < 0) {
1197 --sec;
1198 nsec += 1000000000;
1199 }
1200
1201 if ((sec + 1) > ((time_t)(INT_MAX / mSamplingRate))) {
1202 mMaxSmp = sec * mSamplingRate;
1203 } else {
1204 // mSamplingRate is always > 1000
1205 sec = sec * 1000 + nsec / 1000000; // duration in milliseconds
1206 mMaxSmp = (unsigned int)(((int64_t)sec * mSamplingRate) / 1000);
1207 }
1208 ALOGV("stopTone() forcing mMaxSmp to %d, total for far %d", mMaxSmp, mTotalSmp);
1209 } else {
1210 mState = TONE_STOPPING;
1211 }
1212 }
1213 ALOGV("waiting cond");
1214 status_t lStatus = mWaitCbkCond.waitRelative(mLock, seconds(3));
1215 if (lStatus == NO_ERROR) {
1216 // If the tone was restarted exit now before calling clearWaveGens();
1217 if (mState != TONE_INIT) {
1218 mLock.unlock();
1219 return;
1220 }
1221 ALOGV("track stop complete, time %d", (unsigned int)(systemTime()/1000000));
1222 } else {
1223 ALOGE("--- Stop timed out");
1224 mState = TONE_IDLE;
1225 mpAudioTrack->stop();
1226 }
1227 clearWaveGens();
1228 }
1229
1230 mLock.unlock();
1231 }
1232
1233 //---------------------------------- private methods ---------------------------
1234
1235
1236
1237
1238 ////////////////////////////////////////////////////////////////////////////////
1239 //
1240 // Method: ToneGenerator::initAudioTrack()
1241 //
1242 // Description: Allocates and configures AudioTrack used for PCM output.
1243 //
1244 // Input:
1245 // none
1246 //
1247 // Output:
1248 // none
1249 //
1250 ////////////////////////////////////////////////////////////////////////////////
initAudioTrack()1251 bool ToneGenerator::initAudioTrack() {
1252 // Open audio track in mono, PCM 16bit, default sampling rate.
1253 mpAudioTrack = new AudioTrack();
1254 ALOGV("AudioTrack(%p) created", mpAudioTrack.get());
1255
1256 audio_attributes_t attr;
1257 audio_stream_type_t streamType = mStreamType;
1258 if (mStreamType == AUDIO_STREAM_VOICE_CALL) {
1259 streamType = AUDIO_STREAM_DTMF;
1260 }
1261 attr = AudioSystem::streamTypeToAttributes(streamType);
1262
1263 const size_t frameCount = mProcessSize;
1264 status_t status = mpAudioTrack->set(
1265 AUDIO_STREAM_DEFAULT,
1266 0, // sampleRate
1267 AUDIO_FORMAT_PCM_16_BIT,
1268 AUDIO_CHANNEL_OUT_MONO,
1269 frameCount,
1270 AUDIO_OUTPUT_FLAG_FAST,
1271 audioCallback,
1272 this, // user
1273 0, // notificationFrames
1274 0, // sharedBuffer
1275 mThreadCanCallJava,
1276 AUDIO_SESSION_ALLOCATE,
1277 AudioTrack::TRANSFER_CALLBACK,
1278 nullptr,
1279 AUDIO_UID_INVALID,
1280 -1,
1281 &attr);
1282 // Set caller name so it can be logged in destructor.
1283 // MediaMetricsConstants.h: AMEDIAMETRICS_PROP_CALLERNAME_VALUE_TONEGENERATOR
1284 mpAudioTrack->setCallerName("tonegenerator");
1285 if (status != NO_ERROR) {
1286 ALOGE("AudioTrack(%p) set failed with error %d", mpAudioTrack.get(), status);
1287 mpAudioTrack.clear();
1288 return false;
1289 }
1290
1291 mpAudioTrack->setVolume(mVolume);
1292 mState = TONE_INIT;
1293 return true;
1294 }
1295
1296 ////////////////////////////////////////////////////////////////////////////////
1297 //
1298 // Method: ToneGenerator::audioCallback()
1299 //
1300 // Description: AudioTrack callback implementation. Generates a block of
1301 // PCM samples
1302 // and manages tone generator sequencer: tones pulses, tone duration...
1303 //
1304 // Input:
1305 // user reference (pointer to our ToneGenerator)
1306 // info audio buffer descriptor
1307 //
1308 // Output:
1309 // returned value: always true.
1310 //
1311 ////////////////////////////////////////////////////////////////////////////////
audioCallback(int event,void * user,void * info)1312 void ToneGenerator::audioCallback(int event, void* user, void *info) {
1313
1314 if (event != AudioTrack::EVENT_MORE_DATA) return;
1315
1316 AudioTrack::Buffer *buffer = static_cast<AudioTrack::Buffer *>(info);
1317 ToneGenerator *lpToneGen = static_cast<ToneGenerator *>(user);
1318 int16_t *lpOut = buffer->i16;
1319 unsigned int lNumSmp = buffer->size/sizeof(int16_t);
1320 const ToneDescriptor *lpToneDesc = lpToneGen->mpToneDesc;
1321
1322 if (buffer->size == 0) return;
1323
1324
1325 // Clear output buffer: WaveGenerator accumulates into lpOut buffer
1326 memset(lpOut, 0, buffer->size);
1327
1328 while (lNumSmp) {
1329 unsigned int lReqSmp = lNumSmp < lpToneGen->mProcessSize*2 ? lNumSmp : lpToneGen->mProcessSize;
1330 unsigned int lGenSmp;
1331 unsigned int lWaveCmd = WaveGenerator::WAVEGEN_CONT;
1332 bool lSignal = false;
1333
1334 lpToneGen->mLock.lock();
1335
1336
1337 // Update pcm frame count and end time (current time at the end of this process)
1338 lpToneGen->mTotalSmp += lReqSmp;
1339
1340 // Update tone gen state machine and select wave gen command
1341 switch (lpToneGen->mState) {
1342 case TONE_PLAYING:
1343 lWaveCmd = WaveGenerator::WAVEGEN_CONT;
1344 break;
1345 case TONE_STARTING:
1346 ALOGV("Starting Cbk");
1347
1348 lWaveCmd = WaveGenerator::WAVEGEN_START;
1349 break;
1350 case TONE_STOPPING:
1351 case TONE_RESTARTING:
1352 ALOGV("Stop/restart Cbk");
1353
1354 lWaveCmd = WaveGenerator::WAVEGEN_STOP;
1355 lpToneGen->mNextSegSmp = TONEGEN_INF; // forced to skip state machine management below
1356 break;
1357 case TONE_STOPPED:
1358 ALOGV("Stopped Cbk");
1359 goto audioCallback_EndLoop;
1360 default:
1361 ALOGV("Extra Cbk");
1362 goto audioCallback_EndLoop;
1363 }
1364
1365 // Exit if tone sequence is over
1366 if (lpToneDesc->segments[lpToneGen->mCurSegment].duration == 0 ||
1367 lpToneGen->mTotalSmp > lpToneGen->mMaxSmp) {
1368 if (lpToneGen->mState == TONE_PLAYING) {
1369 lpToneGen->mState = TONE_STOPPING;
1370 }
1371 if (lpToneDesc->segments[lpToneGen->mCurSegment].duration == 0) {
1372 goto audioCallback_EndLoop;
1373 }
1374 // fade out before stopping if maximum duration reached
1375 lWaveCmd = WaveGenerator::WAVEGEN_STOP;
1376 lpToneGen->mNextSegSmp = TONEGEN_INF; // forced to skip state machine management below
1377 }
1378
1379 if (lpToneGen->mTotalSmp > lpToneGen->mNextSegSmp) {
1380 // Time to go to next sequence segment
1381
1382 ALOGV("End Segment, time: %d", (unsigned int)(systemTime()/1000000));
1383
1384 lGenSmp = lReqSmp;
1385
1386 // If segment, ON -> OFF transition : ramp volume down
1387 if (lpToneDesc->segments[lpToneGen->mCurSegment].waveFreq[0] != 0) {
1388 lWaveCmd = WaveGenerator::WAVEGEN_STOP;
1389 unsigned int lFreqIdx = 0;
1390 uint16_t lFrequency = lpToneDesc->segments[lpToneGen->mCurSegment].waveFreq[lFreqIdx];
1391
1392 while (lFrequency != 0) {
1393 WaveGenerator *lpWaveGen = lpToneGen->mWaveGens.valueFor(lFrequency);
1394 lpWaveGen->getSamples(lpOut, lGenSmp, lWaveCmd);
1395 lFrequency = lpToneDesc->segments[lpToneGen->mCurSegment].waveFreq[++lFreqIdx];
1396 }
1397 ALOGV("ON->OFF, lGenSmp: %d, lReqSmp: %d", lGenSmp, lReqSmp);
1398 }
1399
1400 // check if we need to loop and loop for the reqd times
1401 if (lpToneDesc->segments[lpToneGen->mCurSegment].loopCnt) {
1402 if (lpToneGen->mLoopCounter < lpToneDesc->segments[lpToneGen->mCurSegment].loopCnt) {
1403 ALOGV ("in if loop loopCnt(%d) loopctr(%d), CurSeg(%d)",
1404 lpToneDesc->segments[lpToneGen->mCurSegment].loopCnt,
1405 lpToneGen->mLoopCounter,
1406 lpToneGen->mCurSegment);
1407 lpToneGen->mCurSegment = lpToneDesc->segments[lpToneGen->mCurSegment].loopIndx;
1408 ++lpToneGen->mLoopCounter;
1409 } else {
1410 // completed loop. go to next segment
1411 lpToneGen->mLoopCounter = 0;
1412 lpToneGen->mCurSegment++;
1413 ALOGV ("in else loop loopCnt(%d) loopctr(%d), CurSeg(%d)",
1414 lpToneDesc->segments[lpToneGen->mCurSegment].loopCnt,
1415 lpToneGen->mLoopCounter,
1416 lpToneGen->mCurSegment);
1417 }
1418 } else {
1419 lpToneGen->mCurSegment++;
1420 ALOGV ("Goto next seg loopCnt(%d) loopctr(%d), CurSeg(%d)",
1421 lpToneDesc->segments[lpToneGen->mCurSegment].loopCnt,
1422 lpToneGen->mLoopCounter,
1423 lpToneGen->mCurSegment);
1424
1425 }
1426
1427 // Handle loop if last segment reached
1428 if (lpToneDesc->segments[lpToneGen->mCurSegment].duration == 0) {
1429 ALOGV("Last Seg: %d", lpToneGen->mCurSegment);
1430
1431 // Pre increment loop count and restart if total count not reached. Stop sequence otherwise
1432 if (++lpToneGen->mCurCount <= lpToneDesc->repeatCnt) {
1433 ALOGV("Repeating Count: %d", lpToneGen->mCurCount);
1434
1435 lpToneGen->mCurSegment = lpToneDesc->repeatSegment;
1436 if (lpToneDesc->segments[lpToneDesc->repeatSegment].waveFreq[0] != 0) {
1437 lWaveCmd = WaveGenerator::WAVEGEN_START;
1438 }
1439
1440 ALOGV("New segment %d, Next Time: %lld", lpToneGen->mCurSegment,
1441 ((long long)(lpToneGen->mNextSegSmp)*1000)/lpToneGen->mSamplingRate);
1442
1443
1444 } else {
1445 lGenSmp = 0;
1446 ALOGV("End repeat, time: %d", (unsigned int)(systemTime()/1000000));
1447 }
1448 } else {
1449 ALOGV("New segment %d, Next Time: %lld", lpToneGen->mCurSegment,
1450 ((long long)(lpToneGen->mNextSegSmp)*1000)/lpToneGen->mSamplingRate);
1451
1452 if (lpToneDesc->segments[lpToneGen->mCurSegment].waveFreq[0] != 0) {
1453 // If next segment is not silent, OFF -> ON transition : reset wave generator
1454 lWaveCmd = WaveGenerator::WAVEGEN_START;
1455
1456 ALOGV("OFF->ON, lGenSmp: %d, lReqSmp: %d", lGenSmp, lReqSmp);
1457 } else {
1458 lGenSmp = 0;
1459 }
1460 }
1461
1462 // Update next segment transition position. No harm to do it also for last segment as lpToneGen->mNextSegSmp won't be used any more
1463 lpToneGen->mNextSegSmp
1464 += (lpToneDesc->segments[lpToneGen->mCurSegment].duration * lpToneGen->mSamplingRate) / 1000;
1465
1466 } else {
1467 // Inside a segment keep tone ON or OFF
1468 if (lpToneDesc->segments[lpToneGen->mCurSegment].waveFreq[0] == 0) {
1469 lGenSmp = 0; // If odd segment, tone is currently OFF
1470 } else {
1471 lGenSmp = lReqSmp; // If event segment, tone is currently ON
1472 }
1473 }
1474
1475 if (lGenSmp) {
1476 // If samples must be generated, call all active wave generators and acumulate waves in lpOut
1477 unsigned int lFreqIdx = 0;
1478 uint16_t lFrequency = lpToneDesc->segments[lpToneGen->mCurSegment].waveFreq[lFreqIdx];
1479
1480 while (lFrequency != 0) {
1481 WaveGenerator *lpWaveGen = lpToneGen->mWaveGens.valueFor(lFrequency);
1482 lpWaveGen->getSamples(lpOut, lGenSmp, lWaveCmd);
1483 lFrequency = lpToneDesc->segments[lpToneGen->mCurSegment].waveFreq[++lFreqIdx];
1484 }
1485 }
1486
1487 lNumSmp -= lReqSmp;
1488 lpOut += lReqSmp;
1489
1490 audioCallback_EndLoop:
1491
1492 switch (lpToneGen->mState) {
1493 case TONE_RESTARTING:
1494 ALOGV("Cbk restarting track");
1495 if (lpToneGen->prepareWave()) {
1496 lpToneGen->mState = TONE_STARTING;
1497 if (clock_gettime(CLOCK_MONOTONIC, &lpToneGen->mStartTime) != 0) {
1498 lpToneGen->mStartTime.tv_sec = 0;
1499 }
1500 // must reload lpToneDesc as prepareWave() may change mpToneDesc
1501 lpToneDesc = lpToneGen->mpToneDesc;
1502 } else {
1503 ALOGW("Cbk restarting prepareWave() failed");
1504 lpToneGen->mState = TONE_IDLE;
1505 lpToneGen->mpAudioTrack->stop();
1506 // Force loop exit
1507 lNumSmp = 0;
1508 }
1509 lSignal = true;
1510 break;
1511 case TONE_STOPPING:
1512 ALOGV("Cbk Stopping");
1513 lpToneGen->mState = TONE_STOPPED;
1514 // Force loop exit
1515 lNumSmp = 0;
1516 break;
1517 case TONE_STOPPED:
1518 lpToneGen->mState = TONE_INIT;
1519 ALOGV("Cbk Stopped track");
1520 lpToneGen->mpAudioTrack->stop();
1521 // Force loop exit
1522 lNumSmp = 0;
1523 buffer->size = 0;
1524 lSignal = true;
1525 break;
1526 case TONE_STARTING:
1527 ALOGV("Cbk starting track");
1528 lpToneGen->mState = TONE_PLAYING;
1529 lSignal = true;
1530 break;
1531 case TONE_PLAYING:
1532 break;
1533 default:
1534 // Force loop exit
1535 lNumSmp = 0;
1536 buffer->size = 0;
1537 break;
1538 }
1539
1540 if (lSignal)
1541 lpToneGen->mWaitCbkCond.broadcast();
1542 lpToneGen->mLock.unlock();
1543 }
1544 }
1545
1546
1547 ////////////////////////////////////////////////////////////////////////////////
1548 //
1549 // Method: ToneGenerator::prepareWave()
1550 //
1551 // Description: Prepare wave generators and reset tone sequencer state machine.
1552 // mpNewToneDesc must have been initialized before calling this function.
1553 // Input:
1554 // none
1555 //
1556 // Output:
1557 // returned value: true if wave generators have been created, false otherwise
1558 //
1559 ////////////////////////////////////////////////////////////////////////////////
prepareWave()1560 bool ToneGenerator::prepareWave() {
1561 unsigned int segmentIdx = 0;
1562
1563 if (mpNewToneDesc == NULL) {
1564 return false;
1565 }
1566
1567 // Remove existing wave generators if any
1568 clearWaveGens();
1569
1570 mpToneDesc = mpNewToneDesc;
1571
1572 if (mDurationMs == -1) {
1573 mMaxSmp = TONEGEN_INF;
1574 } else {
1575 if (mDurationMs > (int)(TONEGEN_INF / mSamplingRate)) {
1576 mMaxSmp = (mDurationMs / 1000) * mSamplingRate;
1577 } else {
1578 mMaxSmp = (mDurationMs * mSamplingRate) / 1000;
1579 }
1580 ALOGV("prepareWave, duration limited to %d ms", mDurationMs);
1581 }
1582
1583 while (mpToneDesc->segments[segmentIdx].duration) {
1584 // Get total number of sine waves: needed to adapt sine wave gain.
1585 unsigned int lNumWaves = numWaves(segmentIdx);
1586 unsigned int freqIdx = 0;
1587 unsigned int frequency = mpToneDesc->segments[segmentIdx].waveFreq[freqIdx];
1588 while (frequency) {
1589 // Instantiate a wave generator if ot already done for this frequency
1590 if (mWaveGens.indexOfKey(frequency) == NAME_NOT_FOUND) {
1591 ToneGenerator::WaveGenerator *lpWaveGen =
1592 new ToneGenerator::WaveGenerator(mSamplingRate,
1593 frequency,
1594 TONEGEN_GAIN/lNumWaves);
1595 mWaveGens.add(frequency, lpWaveGen);
1596 }
1597 frequency = mpNewToneDesc->segments[segmentIdx].waveFreq[++freqIdx];
1598 }
1599 segmentIdx++;
1600 }
1601
1602 // Initialize tone sequencer
1603 mTotalSmp = 0;
1604 mCurSegment = 0;
1605 mCurCount = 0;
1606 mLoopCounter = 0;
1607 if (mpToneDesc->segments[0].duration == TONEGEN_INF) {
1608 mNextSegSmp = TONEGEN_INF;
1609 } else{
1610 mNextSegSmp = (mpToneDesc->segments[0].duration * mSamplingRate) / 1000;
1611 }
1612
1613 return true;
1614 }
1615
1616
1617 ////////////////////////////////////////////////////////////////////////////////
1618 //
1619 // Method: ToneGenerator::numWaves()
1620 //
1621 // Description: Count number of sine waves needed to generate a tone segment (e.g 2 for DTMF).
1622 //
1623 // Input:
1624 // segmentIdx tone segment index
1625 //
1626 // Output:
1627 // returned value: nummber of sine waves
1628 //
1629 ////////////////////////////////////////////////////////////////////////////////
numWaves(unsigned int segmentIdx)1630 unsigned int ToneGenerator::numWaves(unsigned int segmentIdx) {
1631 unsigned int lCnt = 0;
1632
1633 if (mpToneDesc->segments[segmentIdx].duration) {
1634 while (mpToneDesc->segments[segmentIdx].waveFreq[lCnt]) {
1635 lCnt++;
1636 }
1637 lCnt++;
1638 }
1639
1640 return lCnt;
1641 }
1642
1643
1644 ////////////////////////////////////////////////////////////////////////////////
1645 //
1646 // Method: ToneGenerator::clearWaveGens()
1647 //
1648 // Description: Removes all wave generators.
1649 //
1650 // Input:
1651 // none
1652 //
1653 // Output:
1654 // none
1655 //
1656 ////////////////////////////////////////////////////////////////////////////////
clearWaveGens()1657 void ToneGenerator::clearWaveGens() {
1658 ALOGV("Clearing mWaveGens:");
1659
1660 for (size_t lIdx = 0; lIdx < mWaveGens.size(); lIdx++) {
1661 delete mWaveGens.valueAt(lIdx);
1662 }
1663 mWaveGens.clear();
1664 }
1665
1666 ////////////////////////////////////////////////////////////////////////////////
1667 //
1668 // Method: ToneGenerator::getToneForRegion()
1669 //
1670 // Description: Get correct ringtone type according to current region.
1671 // The corrected ring tone type is the tone descriptor index in sToneDescriptors[].
1672 //
1673 // Input:
1674 // none
1675 //
1676 // Output:
1677 // none
1678 //
1679 ////////////////////////////////////////////////////////////////////////////////
getToneForRegion(tone_type toneType)1680 ToneGenerator::tone_type ToneGenerator::getToneForRegion(tone_type toneType) {
1681 tone_type regionTone;
1682
1683 if (mRegion == CEPT || toneType < FIRST_SUP_TONE || toneType > LAST_SUP_TONE) {
1684 regionTone = toneType;
1685 } else {
1686 regionTone = (tone_type) sToneMappingTable[mRegion][toneType - FIRST_SUP_TONE];
1687 }
1688
1689 ALOGV("getToneForRegion, tone %d, region %d, regionTone %d", toneType, mRegion, regionTone);
1690
1691 return regionTone;
1692 }
1693
1694
1695 ////////////////////////////////////////////////////////////////////////////////
1696 // WaveGenerator::WaveGenerator class Implementation
1697 ////////////////////////////////////////////////////////////////////////////////
1698
1699 //---------------------------------- public methods ----------------------------
1700
1701 ////////////////////////////////////////////////////////////////////////////////
1702 //
1703 // Method: WaveGenerator::WaveGenerator()
1704 //
1705 // Description: Constructor.
1706 //
1707 // Input:
1708 // samplingRate: Output sampling rate in Hz
1709 // frequency: Frequency of the sine wave to generate in Hz
1710 // volume: volume (0.0 to 1.0)
1711 //
1712 // Output:
1713 // none
1714 //
1715 ////////////////////////////////////////////////////////////////////////////////
WaveGenerator(uint32_t samplingRate,uint16_t frequency,float volume)1716 ToneGenerator::WaveGenerator::WaveGenerator(uint32_t samplingRate,
1717 uint16_t frequency, float volume) {
1718 double d0;
1719 double F_div_Fs; // frequency / samplingRate
1720
1721 F_div_Fs = frequency / (double)samplingRate;
1722 d0 = - (float)GEN_AMP * sin(2 * M_PI * F_div_Fs);
1723 mS2_0 = (int16_t)d0;
1724 mS1 = 0;
1725 mS2 = mS2_0;
1726
1727 mAmplitude_Q15 = (int16_t)(32767. * 32767. * volume / GEN_AMP);
1728 // take some margin for amplitude fluctuation
1729 if (mAmplitude_Q15 > 32500)
1730 mAmplitude_Q15 = 32500;
1731
1732 d0 = 32768.0 * cos(2 * M_PI * F_div_Fs); // Q14*2*cos()
1733 if (d0 > 32767)
1734 d0 = 32767;
1735 mA1_Q14 = (int16_t) d0;
1736
1737 ALOGV("WaveGenerator init, mA1_Q14: %d, mS2_0: %d, mAmplitude_Q15: %d",
1738 mA1_Q14, mS2_0, mAmplitude_Q15);
1739 }
1740
1741 ////////////////////////////////////////////////////////////////////////////////
1742 //
1743 // Method: WaveGenerator::~WaveGenerator()
1744 //
1745 // Description: Destructor.
1746 //
1747 // Input:
1748 // none
1749 //
1750 // Output:
1751 // none
1752 //
1753 ////////////////////////////////////////////////////////////////////////////////
~WaveGenerator()1754 ToneGenerator::WaveGenerator::~WaveGenerator() {
1755 }
1756
1757 ////////////////////////////////////////////////////////////////////////////////
1758 //
1759 // Method: WaveGenerator::getSamples()
1760 //
1761 // Description: Generates count samples of a sine wave and accumulates
1762 // result in outBuffer.
1763 //
1764 // Input:
1765 // outBuffer: Output buffer where to accumulate samples.
1766 // count: number of samples to produce.
1767 // command: special action requested (see enum gen_command).
1768 //
1769 // Output:
1770 // none
1771 //
1772 ////////////////////////////////////////////////////////////////////////////////
getSamples(int16_t * outBuffer,unsigned int count,unsigned int command)1773 void ToneGenerator::WaveGenerator::getSamples(int16_t *outBuffer,
1774 unsigned int count, unsigned int command) {
1775 long lS1, lS2;
1776 long lA1, lAmplitude;
1777 long Sample; // current sample
1778
1779 // init local
1780 if (command == WAVEGEN_START) {
1781 lS1 = (long)0;
1782 lS2 = (long)mS2_0;
1783 } else {
1784 lS1 = mS1;
1785 lS2 = mS2;
1786 }
1787 lA1 = (long)mA1_Q14;
1788 lAmplitude = (long)mAmplitude_Q15;
1789
1790 if (command == WAVEGEN_STOP) {
1791 lAmplitude <<= 16;
1792 if (count == 0) {
1793 return;
1794 }
1795 long dec = lAmplitude/count;
1796 // loop generation
1797 while (count) {
1798 count--;
1799 Sample = ((lA1 * lS1) >> S_Q14) - lS2;
1800 // shift delay
1801 lS2 = lS1;
1802 lS1 = Sample;
1803 Sample = ((lAmplitude>>16) * Sample) >> S_Q15;
1804 *(outBuffer++) += (int16_t)Sample; // put result in buffer
1805 lAmplitude -= dec;
1806 }
1807 } else {
1808 // loop generation
1809 while (count) {
1810 count--;
1811 Sample = ((lA1 * lS1) >> S_Q14) - lS2;
1812 // shift delay
1813 lS2 = lS1;
1814 lS1 = Sample;
1815 Sample = (lAmplitude * Sample) >> S_Q15;
1816 *(outBuffer++) += (int16_t)Sample; // put result in buffer
1817 }
1818 }
1819
1820 // save status
1821 mS1 = lS1;
1822 mS2 = lS2;
1823 }
1824
1825 } // end namespace android
1826