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