blob: 7c2200edfc3c71b406f434aa62e368e87c31cbd1 [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001/*
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#include <utils/threads.h>
20
21#include <stdio.h>
22#include <math.h>
23#include <utils/Log.h>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080024#include <utils/RefBase.h>
25#include <utils/Timers.h>
Eric Laurentf3af7402009-05-05 00:49:01 -070026#include <cutils/properties.h>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080027#include "media/ToneGenerator.h"
28
Eric Laurentf3af7402009-05-05 00:49:01 -070029
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080030namespace android {
31
Eric Laurentf3af7402009-05-05 00:49:01 -070032
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080033// Descriptors for all available tones (See ToneGenerator::ToneDescriptor class declaration for details)
Eric Laurentf3af7402009-05-05 00:49:01 -070034const ToneGenerator::ToneDescriptor ToneGenerator::sToneDescriptors[] = {
David Krauseb6d90ca2009-06-17 15:46:13 -050035 { segments: {{ duration: ToneGenerator::TONEGEN_INF, waveFreq: { 1336, 941, 0 }, 0, 0},
36 { duration: 0 , waveFreq: { 0 }, 0, 0}},
Eric Laurentf3af7402009-05-05 00:49:01 -070037 repeatCnt: ToneGenerator::TONEGEN_INF,
38 repeatSegment: 0 }, // TONE_DTMF_0
David Krauseb6d90ca2009-06-17 15:46:13 -050039 { segments: { { duration: ToneGenerator::TONEGEN_INF, waveFreq: { 1209, 697, 0 }, 0, 0 },
40 { duration: 0 , waveFreq: { 0 }, 0, 0}},
Eric Laurentf3af7402009-05-05 00:49:01 -070041 repeatCnt: ToneGenerator::TONEGEN_INF,
42 repeatSegment: 0 }, // TONE_DTMF_1
David Krauseb6d90ca2009-06-17 15:46:13 -050043 { segments: { { duration: ToneGenerator::TONEGEN_INF, waveFreq: { 1336, 697, 0 }, 0, 0 },
44 { duration: 0 , waveFreq: { 0 }, 0, 0}},
Eric Laurentf3af7402009-05-05 00:49:01 -070045 repeatCnt: ToneGenerator::TONEGEN_INF,
46 repeatSegment: 0 }, // TONE_DTMF_2
David Krauseb6d90ca2009-06-17 15:46:13 -050047 { segments: { { duration: ToneGenerator::TONEGEN_INF, waveFreq: { 1477, 697, 0 }, 0, 0 },
48 { duration: 0 , waveFreq: { 0 }, 0, 0}},
Eric Laurentf3af7402009-05-05 00:49:01 -070049 repeatCnt: ToneGenerator::TONEGEN_INF,
50 repeatSegment: 0 }, // TONE_DTMF_3
David Krauseb6d90ca2009-06-17 15:46:13 -050051 { segments: { { duration: ToneGenerator::TONEGEN_INF, waveFreq: { 1209, 770, 0 }, 0, 0 },
52 { duration: 0 , waveFreq: { 0 }, 0, 0}},
Eric Laurentf3af7402009-05-05 00:49:01 -070053 repeatCnt: ToneGenerator::TONEGEN_INF,
54 repeatSegment: 0 }, // TONE_DTMF_4
David Krauseb6d90ca2009-06-17 15:46:13 -050055 { segments: { { duration: ToneGenerator::TONEGEN_INF, waveFreq: { 1336, 770, 0 }, 0, 0 },
56 { duration: 0 , waveFreq: { 0 }, 0, 0}},
Eric Laurentf3af7402009-05-05 00:49:01 -070057 repeatCnt: ToneGenerator::TONEGEN_INF,
58 repeatSegment: 0 }, // TONE_DTMF_5
David Krauseb6d90ca2009-06-17 15:46:13 -050059 { segments: { { duration: ToneGenerator::TONEGEN_INF, waveFreq: { 1477, 770, 0 }, 0, 0 },
60 { duration: 0 , waveFreq: { 0 }, 0, 0}},
Eric Laurentf3af7402009-05-05 00:49:01 -070061 repeatCnt: ToneGenerator::TONEGEN_INF,
62 repeatSegment: 0 }, // TONE_DTMF_6
David Krauseb6d90ca2009-06-17 15:46:13 -050063 { segments: { { duration: ToneGenerator::TONEGEN_INF, waveFreq: { 1209, 852, 0 }, 0, 0 },
64 { duration: 0 , waveFreq: { 0 }, 0, 0}},
Eric Laurentf3af7402009-05-05 00:49:01 -070065 repeatCnt: ToneGenerator::TONEGEN_INF,
66 repeatSegment: 0 }, // TONE_DTMF_7
David Krauseb6d90ca2009-06-17 15:46:13 -050067 { segments: { { duration: ToneGenerator::TONEGEN_INF, waveFreq: { 1336, 852, 0 }, 0, 0 },
68 { duration: 0 , waveFreq: { 0 }, 0, 0}},
Eric Laurentf3af7402009-05-05 00:49:01 -070069 repeatCnt: ToneGenerator::TONEGEN_INF,
70 repeatSegment: 0 }, // TONE_DTMF_8
David Krauseb6d90ca2009-06-17 15:46:13 -050071 { segments: { { duration: ToneGenerator::TONEGEN_INF, waveFreq: { 1477, 852, 0 }, 0, 0 },
72 { duration: 0 , waveFreq: { 0 }, 0, 0}},
Eric Laurentf3af7402009-05-05 00:49:01 -070073 repeatCnt: ToneGenerator::TONEGEN_INF,
74 repeatSegment: 0 }, // TONE_DTMF_9
David Krauseb6d90ca2009-06-17 15:46:13 -050075 { segments: { { duration: ToneGenerator::TONEGEN_INF, waveFreq: { 1209, 941, 0 }, 0, 0 },
76 { duration: 0 , waveFreq: { 0 }, 0, 0}},
Eric Laurentf3af7402009-05-05 00:49:01 -070077 repeatCnt: ToneGenerator::TONEGEN_INF,
78 repeatSegment: 0 }, // TONE_DTMF_S
David Krauseb6d90ca2009-06-17 15:46:13 -050079 { segments: { { duration: ToneGenerator::TONEGEN_INF, waveFreq: { 1477, 941, 0 }, 0, 0 },
80 { duration: 0 , waveFreq: { 0 }, 0, 0}},
Eric Laurentf3af7402009-05-05 00:49:01 -070081 repeatCnt: ToneGenerator::TONEGEN_INF,
82 repeatSegment: 0 }, // TONE_DTMF_P
David Krauseb6d90ca2009-06-17 15:46:13 -050083 { segments: { { duration: ToneGenerator::TONEGEN_INF, waveFreq: { 1633, 697, 0 }, 0, 0 },
84 { duration: 0 , waveFreq: { 0 }, 0, 0}},
Eric Laurentf3af7402009-05-05 00:49:01 -070085 repeatCnt: ToneGenerator::TONEGEN_INF,
86 repeatSegment: 0 }, // TONE_DTMF_A
David Krauseb6d90ca2009-06-17 15:46:13 -050087 { segments: { { duration: ToneGenerator::TONEGEN_INF, waveFreq: { 1633, 770, 0 }, 0, 0 },
88 { duration: 0 , waveFreq: { 0 }, 0, 0}},
Eric Laurentf3af7402009-05-05 00:49:01 -070089 repeatCnt: ToneGenerator::TONEGEN_INF,
90 repeatSegment: 0 }, // TONE_DTMF_B
David Krauseb6d90ca2009-06-17 15:46:13 -050091 { segments: { { duration: ToneGenerator::TONEGEN_INF, waveFreq: { 1633, 852, 0 }, 0, 0 },
92 { duration: 0 , waveFreq: { 0 }, 0, 0}},
Eric Laurentf3af7402009-05-05 00:49:01 -070093 repeatCnt: ToneGenerator::TONEGEN_INF,
94 repeatSegment: 0 }, // TONE_DTMF_C
David Krauseb6d90ca2009-06-17 15:46:13 -050095 { segments: { { duration: ToneGenerator::TONEGEN_INF, waveFreq: { 1633, 941, 0 }, 0, 0 },
96 { duration: 0 , waveFreq: { 0 }, 0, 0}},
Eric Laurentf3af7402009-05-05 00:49:01 -070097 repeatCnt: ToneGenerator::TONEGEN_INF,
98 repeatSegment: 0 }, // TONE_DTMF_D
David Krauseb6d90ca2009-06-17 15:46:13 -050099 { segments: { { duration: ToneGenerator::TONEGEN_INF, waveFreq: { 425, 0 }, 0, 0 },
100 { duration: 0 , waveFreq: { 0 }, 0, 0}},
Eric Laurentf3af7402009-05-05 00:49:01 -0700101 repeatCnt: ToneGenerator::TONEGEN_INF,
102 repeatSegment: 0 }, // TONE_SUP_DIAL
David Krauseb6d90ca2009-06-17 15:46:13 -0500103 { segments: { { duration: 500 , waveFreq: { 425, 0 }, 0, 0},
104 { duration: 500, waveFreq: { 0 }, 0, 0},
105 { duration: 0 , waveFreq: { 0 }, 0, 0}},
Eric Laurentf3af7402009-05-05 00:49:01 -0700106 repeatCnt: ToneGenerator::TONEGEN_INF,
107 repeatSegment: 0 }, // TONE_SUP_BUSY
David Krauseb6d90ca2009-06-17 15:46:13 -0500108 { segments: { { duration: 200, waveFreq: { 425, 0 }, 0, 0 },
109 { duration: 200, waveFreq: { 0 }, 0, 0 },
110 { duration: 0 , waveFreq: { 0 }, 0, 0}},
Eric Laurentf3af7402009-05-05 00:49:01 -0700111 repeatCnt: ToneGenerator::TONEGEN_INF,
112 repeatSegment: 0 }, // TONE_SUP_CONGESTION
David Krauseb6d90ca2009-06-17 15:46:13 -0500113 { segments: { { duration: 200, waveFreq: { 425, 0 }, 0, 0 },
114 { duration: 0 , waveFreq: { 0 }, 0, 0}},
Eric Laurentf3af7402009-05-05 00:49:01 -0700115 repeatCnt: 0,
116 repeatSegment: 0 }, // TONE_SUP_RADIO_ACK
David Krauseb6d90ca2009-06-17 15:46:13 -0500117 { segments: { { duration: 200, waveFreq: { 425, 0 }, 0, 0},
118 { duration: 200, waveFreq: { 0 }, 0, 0},
119 { duration: 0 , waveFreq: { 0 }, 0, 0}},
Eric Laurentf3af7402009-05-05 00:49:01 -0700120 repeatCnt: 2,
121 repeatSegment: 0 }, // TONE_SUP_RADIO_NOTAVAIL
David Krauseb6d90ca2009-06-17 15:46:13 -0500122 { segments: { { duration: 330, waveFreq: { 950, 1400, 1800, 0 }, 0, 0},
123 { duration: 1000, waveFreq: { 0 }, 0, 0},
124 { duration: 0 , waveFreq: { 0 }, 0, 0}},
Eric Laurentf3af7402009-05-05 00:49:01 -0700125 repeatCnt: ToneGenerator::TONEGEN_INF,
126 repeatSegment: 0 }, // TONE_SUP_ERROR
David Krauseb6d90ca2009-06-17 15:46:13 -0500127 { segments: { { duration: 200, waveFreq: { 425, 0 }, 0, 0 },
128 { duration: 600, waveFreq: { 0 }, 0, 0 },
129 { duration: 200, waveFreq: { 425, 0 }, 0, 0 },
130 { duration: 3000, waveFreq: { 0 }, 0, 0 },
131 { duration: 0 , waveFreq: { 0 }, 0, 0}},
Eric Laurentf3af7402009-05-05 00:49:01 -0700132 repeatCnt: ToneGenerator::TONEGEN_INF,
133 repeatSegment: 0 }, // TONE_SUP_CALL_WAITING
David Krauseb6d90ca2009-06-17 15:46:13 -0500134 { segments: { { duration: 1000, waveFreq: { 425, 0 }, 0, 0 },
135 { duration: 4000, waveFreq: { 0 }, 0, 0 },
136 { duration: 0 , waveFreq: { 0 }, 0, 0}},
Eric Laurentf3af7402009-05-05 00:49:01 -0700137 repeatCnt: ToneGenerator::TONEGEN_INF,
138 repeatSegment: 0 }, // TONE_SUP_RINGTONE
David Krauseb6d90ca2009-06-17 15:46:13 -0500139 { segments: { { duration: 40, waveFreq: { 400, 1200, 0 }, 0, 0 },
140 { duration: 0 , waveFreq: { 0 }, 0, 0}},
Eric Laurentf3af7402009-05-05 00:49:01 -0700141 repeatCnt: 0,
142 repeatSegment: 0 }, // TONE_PROP_BEEP
David Krauseb6d90ca2009-06-17 15:46:13 -0500143 { segments: { { duration: 100, waveFreq: { 1200, 0 }, 0, 0 },
144 { duration: 100, waveFreq: { 0 }, 0, 0 },
145 { duration: 0 , waveFreq: { 0 }, 0, 0}},
Eric Laurentf3af7402009-05-05 00:49:01 -0700146 repeatCnt: 1,
147 repeatSegment: 0 }, // TONE_PROP_ACK
David Krauseb6d90ca2009-06-17 15:46:13 -0500148 { segments: { { duration: 400, waveFreq: { 300, 400, 500, 0 }, 0, 0 },
149 { duration: 0 , waveFreq: { 0 }, 0, 0}},
Eric Laurentf3af7402009-05-05 00:49:01 -0700150 repeatCnt: 0,
151 repeatSegment: 0 }, // TONE_PROP_NACK
David Krauseb6d90ca2009-06-17 15:46:13 -0500152 { segments: { { duration: 200, waveFreq: { 400, 1200, 0 }, 0, 0 },
153 { duration: 0 , waveFreq: { 0 }, 0, 0}},
Eric Laurentf3af7402009-05-05 00:49:01 -0700154 repeatCnt: 0,
155 repeatSegment: 0 }, // TONE_PROP_PROMPT
David Krauseb6d90ca2009-06-17 15:46:13 -0500156 { segments: { { duration: 40, waveFreq: { 400, 1200, 0 }, 0, 0 },
157 { duration: 200, waveFreq: { 0 }, 0, 0 },
158 { duration: 40, waveFreq: { 400, 1200, 0 }, 0, 0 },
159 { duration: 0 , waveFreq: { 0 }, 0, 0}},
Eric Laurentf3af7402009-05-05 00:49:01 -0700160 repeatCnt: 0,
161 repeatSegment: 0 }, // TONE_PROP_BEEP2
David Krauseb6d90ca2009-06-17 15:46:13 -0500162 { segments: { { duration: 250, waveFreq: { 440, 0 }, 0, 0 },
163 { duration: 250, waveFreq: { 620, 0 }, 0, 0 },
164 { duration: 0 , waveFreq: { 0 }, 0, 0 }},
Eric Laurentf3af7402009-05-05 00:49:01 -0700165 repeatCnt: ToneGenerator::TONEGEN_INF,
166 repeatSegment: 0 }, // TONE_SUP_INTERCEPT
David Krauseb6d90ca2009-06-17 15:46:13 -0500167 { segments: { { duration: 250, waveFreq: { 440, 0 }, 0, 0 },
168 { duration: 250, waveFreq: { 620, 0 }, 0, 0 },
169 { duration: 0 , waveFreq: { 0 }, 0, 0}},
Eric Laurentf3af7402009-05-05 00:49:01 -0700170 repeatCnt: 7,
171 repeatSegment: 0 }, // TONE_SUP_INTERCEPT_ABBREV
David Krauseb6d90ca2009-06-17 15:46:13 -0500172 { segments: { { duration: 250, waveFreq: { 480, 620, 0 }, 0, 0 },
173 { duration: 250, waveFreq: { 0 }, 0, 0 },
174 { duration: 0 , waveFreq: { 0 }, 0, 0}},
Eric Laurentf3af7402009-05-05 00:49:01 -0700175 repeatCnt: 7,
176 repeatSegment: 0 }, // TONE_SUP_CONGESTION_ABBREV
David Krauseb6d90ca2009-06-17 15:46:13 -0500177 { segments: { { duration: 100, waveFreq: { 350, 440, 0 }, 0, 0 },
178 { duration: 100, waveFreq: { 0 }, 0, 0 },
179 { duration: 0 , waveFreq: { 0 }, 0, 0}},
Eric Laurentf3af7402009-05-05 00:49:01 -0700180 repeatCnt: 2,
181 repeatSegment: 0 }, // TONE_SUP_CONFIRM
David Krauseb6d90ca2009-06-17 15:46:13 -0500182 { segments: { { duration: 100, waveFreq: { 480, 0 }, 0, 0 },
183 { duration: 100, waveFreq: { 0 }, 0, 0 },
184 { duration: 0 , waveFreq: { 0 }, 0, 0}},
Eric Laurentf3af7402009-05-05 00:49:01 -0700185 repeatCnt: 3,
186 repeatSegment: 0 }, // TONE_SUP_PIP
David Krauseb6d90ca2009-06-17 15:46:13 -0500187 { segments: {{ duration: ToneGenerator::TONEGEN_INF, waveFreq: { 425, 0 }, 0, 0},
188 { duration: 0 , waveFreq: { 0 }, 0, 0}},
189 repeatCnt: ToneGenerator::TONEGEN_INF,
190 repeatSegment: 0 }, // TONE_CDMA_DIAL_TONE_LITE
191 { segments: { { duration: 2000, waveFreq: { 440, 480, 0 }, 0, 0 },
192 { duration: 4000, waveFreq: { 0 }, 0, 0 },
193 { duration: 0 , waveFreq: { 0 }, 0, 0}},
194 repeatCnt: ToneGenerator::TONEGEN_INF,
195 repeatSegment: 0 }, // TONE_CDMA_NETWORK_USA_RINGBACK
196 { segments: { { duration: 250, waveFreq: { 440, 0 }, 0, 0 },
197 { duration: 250, waveFreq: { 620, 0 }, 0, 0 },
198 { duration: 0 , waveFreq: { 0 }, 0, 0}},
199 repeatCnt: ToneGenerator::TONEGEN_INF,
200 repeatSegment: 0 }, // TONE_CDMA_INTERCEPT
201 { segments: { { duration: 250, waveFreq: { 440, 0 }, 0, 0 },
202 { duration: 250, waveFreq: { 620, 0 }, 0, 0 },
203 { duration: 0 , waveFreq: { 0 }, 0, 0}},
204 repeatCnt: 0,
205 repeatSegment: 0 }, // TONE_CDMA_ABBR_INTERCEPT
206 { segments: { { duration: 250, waveFreq: { 480, 620, 0 }, 0, 0 },
207 { duration: 250, waveFreq: { 0 }, 0, 0 },
208 { duration: 0 , waveFreq: { 0 }, 0, 0}},
209 repeatCnt: ToneGenerator::TONEGEN_INF,
210 repeatSegment: 0 }, // TONE_CDMA_REORDER
211 { segments: { { duration: 250, waveFreq: { 480, 620, 0 }, 0, 0 },
212 { duration: 250, waveFreq: { 0 }, 0, 0 },
213 { duration: 0 , waveFreq: { 0 }, 0, 0}},
214 repeatCnt: 7,
215 repeatSegment: 0 }, // TONE_CDMA_ABBR_REORDER
216 { segments: { { duration: 500, waveFreq: { 480, 620, 0 }, 0, 0 },
217 { duration: 500, waveFreq: { 0 }, 0, 0 },
218 { duration: 0 , waveFreq: { 0 }, 0, 0}},
219 repeatCnt: ToneGenerator::TONEGEN_INF,
220 repeatSegment: 0 }, // TONE_CDMA_NETWORK_BUSY
221 { segments: { { duration: 100, waveFreq: { 350, 440, 0 }, 0, 0 },
222 { duration: 100, waveFreq: { 0 }, 0, 0 },
223 { duration: 0 , waveFreq: { 0 }, 0, 0}},
224 repeatCnt: 2,
225 repeatSegment: 0 }, // TONE_CDMA_CONFIRM
Naveen Kalla6c84d732009-10-13 15:29:47 -0700226 { segments: { { duration: 500, waveFreq: { 660, 1000, 0 }, 0, 0 },
227 { duration: 0 , waveFreq: { 0 }, 0, 0}},
David Krauseb6d90ca2009-06-17 15:46:13 -0500228 repeatCnt: 0,
229 repeatSegment: 0 }, // TONE_CDMA_ANSWER
230 { segments: { { duration: 300, waveFreq: { 440, 0 }, 0, 0 },
231 { duration: 0 , waveFreq: { 0 }, 0, 0}},
232 repeatCnt: 0,
233 repeatSegment: 0 }, // TONE_CDMA_NETWORK_CALLWAITING
234 { segments: { { duration: 100, waveFreq: { 480, 0 }, 0, 0 },
235 { duration: 100, waveFreq: { 0 }, 0, 0 },
236 { duration: 0 , waveFreq: { 0 }, 0, 0}},
237 repeatCnt: 3,
238 repeatSegment: 0 }, // TONE_CDMA_PIP
239
240 { segments: { { duration: 32, waveFreq: { 2091, 0}, 0, 0 },
241 { duration: 64, waveFreq: { 2556, 0}, 19, 0},
242 { duration: 32, waveFreq: { 2091, 0}, 0, 0},
243 { duration: 48, waveFreq: { 2556, 0}, 0, 0},
244 { duration: 4000, waveFreq: { 0 }, 0, 0},
245 { duration: 0, waveFreq: { 0 }, 0, 0}},
246 repeatCnt: 0,
247 repeatSegment: 0 }, // TONE_CDMA_CALL_SIGNAL_ISDN_NORMAL
248 { segments: { { duration: 32, waveFreq: { 2091, 0}, 0, 0 },
249 { duration: 64, waveFreq: { 2556, 0}, 7, 0 },
250 { duration: 32, waveFreq: { 2091, 0}, 0, 0 },
251 { duration: 400, waveFreq: { 0 }, 0, 0 },
252 { duration: 32, waveFreq: { 2091, 0}, 0, 0 },
253 { duration: 64, waveFreq: { 2556, 0}, 7, 4 },
254 { duration: 32, waveFreq: { 2091, 0}, 0, 0 },
255 { duration: 4000, waveFreq: { 0 }, 0, 0 },
256 { duration: 0, waveFreq: { 0 }, 0, 0 } },
257 repeatCnt: 0,
258 repeatSegment: 0 }, // TONE_CDMA_CALL_SIGNAL_ISDN_INTERGROUP
259 { segments: { { duration: 32, waveFreq: { 2091, 0}, 0, 0 },
260 { duration: 64, waveFreq: { 2556, 0}, 3, 0 },
261 { duration: 16, waveFreq: { 2091, 0}, 0, 0 },
262 { duration: 200, waveFreq: { 0 }, 0, 0 },
263 { duration: 32, waveFreq: { 2091, 0}, 0, 0 },
264 { duration: 64, waveFreq: { 2556, 0}, 3, 4 },
265 { duration: 16, waveFreq: { 2091, 0}, 0, 0 },
266 { duration: 200, waveFreq: { 0 }, 0, 0 },
267 { duration: 0, waveFreq: { 0 }, 0, 0 } },
268 repeatCnt: 0,
269 repeatSegment: 0 }, // TONE_CDMA_CALL_SIGNAL_ISDN_SP_PRI
270 { segments: { { duration: 0, waveFreq: { 0 }, 0, 0} },
271 repeatCnt: 0,
272 repeatSegment: 0 }, // TONE_CDMA_CALL_SIGNAL_ISDN_PAT3
273 { segments: { { duration: 32, waveFreq: { 2091, 0 }, 0, 0 },
274 { duration: 64, waveFreq: { 2556, 0 }, 4, 0 },
275 { duration: 20, waveFreq: { 2091, 0 }, 0, 0 },
276 { duration: 0, waveFreq: { 0 } , 0, 0 } },
277 repeatCnt: 0,
278 repeatSegment: 0 }, // TONE_CDMA_CALL_SIGNAL_ISDN_PING_RING
279 { segments: { { duration: 0, waveFreq: { 0 }, 0, 0} },
280 repeatCnt: 0,
281 repeatSegment: 0 }, // TONE_CDMA_CALL_SIGNAL_ISDN_PAT5
282 { segments: { { duration: 0, waveFreq: { 0 }, 0, 0} },
283 repeatCnt: 0,
284 repeatSegment: 0 }, // TONE_CDMA_CALL_SIGNAL_ISDN_PAT6
285 { segments: { { duration: 0, waveFreq: { 0 }, 0, 0} },
286 repeatCnt: 0,
287 repeatSegment: 0 }, // TONE_CDMA_CALL_SIGNAL_ISDN_PAT7
288
289 { segments: { { duration: 25, waveFreq: { 3700, 0 }, 0, 0 },
290 { duration: 25, waveFreq: { 4000, 0 }, 39, 0 },
291 { duration: 4000, waveFreq: { 0 }, 0, 0 },
292 { duration: 0, waveFreq: { 0 }, 0, 0 } },
293 repeatCnt: ToneGenerator::TONEGEN_INF,
294 repeatSegment: 0 }, // TONE_CDMA_HIGH_L
295 { segments: { { duration: 25, waveFreq: { 2600, 0 }, 0, 0 },
296 { duration: 25, waveFreq: { 2900, 0 }, 39, 0 },
297 { duration: 4000, waveFreq: { 0 }, 0, 0 },
298 { duration: 0, waveFreq: { 0 }, 0, 0 } },
299 repeatCnt: ToneGenerator::TONEGEN_INF,
300 repeatSegment: 0 }, // TONE_CDMA_MED_L
301 { segments: { { duration: 25, waveFreq: { 1300, 0 }, 0, 0 },
302 { duration: 25, waveFreq: { 1450, 0 }, 39, 0 },
303 { duration: 4000, waveFreq: { 0 }, 0, 0 },
304 { duration: 0, waveFreq: { 0 }, 0, 0 } },
305 repeatCnt: ToneGenerator::TONEGEN_INF,
306 repeatSegment: 0 }, // TONE_CDMA_LOW_L
307 { segments: { { duration: 25, waveFreq: { 3700, 0 }, 0, 0 },
308 { duration: 25, waveFreq: { 4000, 0 }, 15, 0 },
309 { duration: 400, waveFreq: { 0 }, 0, 0 },
310 { duration: 0, waveFreq: { 0 }, 0, 0 } },
311 repeatCnt: ToneGenerator::TONEGEN_INF,
312 repeatSegment: 0 }, // TONE_CDMA_HIGH_SS
313 { segments: { { duration: 25, waveFreq: { 2600, 0 }, 0, 0 },
314 { duration: 25, waveFreq: { 2900, 0 }, 15, 0 },
315 { duration: 400, waveFreq: { 0 }, 0, 0 },
316 { duration: 0, waveFreq: { 0 }, 0, 0 }},
317 repeatCnt: ToneGenerator::TONEGEN_INF,
318 repeatSegment: 0 }, // TONE_CDMA_MED_SS
319 { segments: { { duration: 25, waveFreq: { 1300, 0 }, 0, 0 },
320 { duration: 25, waveFreq: { 1450, 0 }, 15, 0 },
321 { duration: 400, waveFreq: { 0 }, 0, 0 },
322 { duration: 0, waveFreq: { 0 }, 0, 0 }},
323 repeatCnt: ToneGenerator::TONEGEN_INF,
324 repeatSegment: 0 }, // TONE_CDMA_LOW_SS
325 { segments: { { duration: 25, waveFreq: { 3700, 0 }, 0, 0 },
326 { duration: 25, waveFreq: { 4000, 0 }, 7, 0 },
327 { duration: 200, waveFreq: { 0 }, 0, 0 },
328 { duration: 25, waveFreq: { 3700, 0 }, 0, 0 },
329 { duration: 25, waveFreq: { 4000, 0 }, 7, 3 },
330 { duration: 200, waveFreq: { 0 }, 0, 0 },
331 { duration: 25, waveFreq: { 3700, 0 }, 0, 0 },
332 { duration: 25, waveFreq: { 4000, 0 }, 15, 6 },
333 { duration: 4000, waveFreq: { 0 }, 0, 0 },
334 { duration: 0, waveFreq: { 0 }, 0, 0 }},
335 repeatCnt: ToneGenerator::TONEGEN_INF,
336 repeatSegment: 0 }, // TONE_CDMA_HIGH_SSL
337 { segments: { { duration: 25, waveFreq: { 2600, 0 }, 0, 0 },
338 { duration: 25, waveFreq: { 2900, 0 }, 7, 0 },
339 { duration: 200, waveFreq: { 0 }, 0, 0 },
340 { duration: 25, waveFreq: { 2600, 0 }, 0, 0 },
341 { duration: 25, waveFreq: { 2900, 0 }, 7, 3 },
342 { duration: 200, waveFreq: { 0 }, 0, 0 },
343 { duration: 25, waveFreq: { 2600, 0 }, 0, 0 },
344 { duration: 25, waveFreq: { 2900, 0 }, 15, 6 },
345 { duration: 4000, waveFreq: { 0 }, 0, 0 },
346 { duration: 0, waveFreq: { 0 }, 0, 0 }},
347 repeatCnt: ToneGenerator::TONEGEN_INF,
348 repeatSegment: 0 }, // TONE_CDMA_MED_SSL
349 { segments: { { duration: 25, waveFreq: { 1300, 0 }, 0, 0 },
350 { duration: 25, waveFreq: { 1450, 0 }, 7, 0 },
351 { duration: 200, waveFreq: { 0 }, 0, 0 },
352 { duration: 25, waveFreq: { 1300, 0 }, 0, 0 },
353 { duration: 25, waveFreq: { 1450, 0 }, 7, 3 },
354 { duration: 200, waveFreq: { 0 }, 0, 0 },
355 { duration: 25, waveFreq: { 1300, 0 }, 0, 0 },
356 { duration: 25, waveFreq: { 1450, 0 }, 15, 6 },
357 { duration: 4000, waveFreq: { 0 }, 0, 0 },
358 { duration: 0, waveFreq: { 0 }, 0, 0 }},
359 repeatCnt: ToneGenerator::TONEGEN_INF,
360 repeatSegment: 0 }, // TONE_CDMA_LOW_SSL
361 { segments: { { duration: 25, waveFreq: { 3700, 0 }, 0, 0 },
362 { duration: 25, waveFreq: { 4000, 0 }, 19, 0 },
363 { duration: 1000, waveFreq: { 0 }, 0, 0 },
364 { duration: 25, waveFreq: { 3700, 0 }, 0, 0 },
365 { duration: 25, waveFreq: { 4000, 0 }, 19, 3 },
366 { duration: 3000, waveFreq: { 0 }, 0, 0 },
367 { duration: 0, waveFreq: { 0 }, 0, 0 }},
368 repeatCnt: ToneGenerator::TONEGEN_INF,
369 repeatSegment: 0 }, // TONE_CDMA_HIGH_SS_2
370 { segments: { { duration: 25, waveFreq: { 2600, 0 }, 0, 0 },
371 { duration: 25, waveFreq: { 2900, 0 }, 19, 0 },
372 { duration: 1000, waveFreq: { 0 }, 0, 0 },
373 { duration: 25, waveFreq: { 2600, 0 }, 0, 0 },
374 { duration: 25, waveFreq: { 2900, 0 }, 19, 3 },
375 { duration: 3000, waveFreq: { 0 }, 0, 0 },
376 { duration: 0, waveFreq: { 0 }, 0, 0 }},
377 repeatCnt: ToneGenerator::TONEGEN_INF,
378 repeatSegment: 0 }, // TONE_CDMA_MED_SS_2
379 { segments: { { duration: 25, waveFreq: { 1300, 0 }, 0, 0 },
380 { duration: 25, waveFreq: { 1450, 0 }, 19, 0 },
381 { duration: 1000, waveFreq: { 0 }, 0, 0 },
382 { duration: 25, waveFreq: { 1300, 0 }, 0, 0 },
383 { duration: 25, waveFreq: { 1450, 0 }, 19, 3 },
384 { duration: 3000, waveFreq: { 0 }, 0, 0 },
385 { duration: 0, waveFreq: { 0 }, 0, 0 }},
386 repeatCnt: ToneGenerator::TONEGEN_INF,
387 repeatSegment: 0 }, // TONE_CDMA_LOW_SS_2
388 { segments: { { duration: 25, waveFreq: { 3700, 0 }, 0, 0 },
389 { duration: 25, waveFreq: { 4000, 0 }, 9, 0 },
390 { duration: 500, waveFreq: { 0 }, 0, 0 },
391 { duration: 25, waveFreq: { 3700, 0 }, 0, 0 },
392 { duration: 25, waveFreq: { 4000, 0 }, 19, 3 },
393 { duration: 500, waveFreq: { 0 }, 0, 0 },
394 { duration: 25, waveFreq: { 3700, 0 }, 0, 0 },
395 { duration: 25, waveFreq: { 4000, 0 }, 9, 6 },
396 { duration: 3000, waveFreq: { 0 }, 0, 0 },
397 { duration: 0, waveFreq: { 0 }, 0, 0 }},
398 repeatCnt: ToneGenerator::TONEGEN_INF,
399 repeatSegment: 0 }, // TONE_CDMA_HIGH_SLS
400 { segments: { { duration: 25, waveFreq: { 2600, 0 }, 0, 0 },
401 { duration: 25, waveFreq: { 2900, 0 }, 9, 0 },
402 { duration: 500, waveFreq: { 0 }, 0, 0 },
403 { duration: 25, waveFreq: { 2600, 0 }, 0, 0 },
404 { duration: 25, waveFreq: { 2900, 0 }, 19, 3 },
405 { duration: 500, waveFreq: { 0 }, 0, 0 },
406 { duration: 25, waveFreq: { 2600, 0 }, 0, 0 },
407 { duration: 25, waveFreq: { 2900, 0 }, 9, 6 },
408 { duration: 3000, waveFreq: { 0 }, 0, 0 },
409 { duration: 0, waveFreq: { 0 }, 0, 0 }},
410 repeatCnt: ToneGenerator::TONEGEN_INF,
411 repeatSegment: 0 }, // TONE_CDMA_MED_SLS
412 { segments: { { duration: 25, waveFreq: { 1300, 0 }, 0, 0 },
413 { duration: 25, waveFreq: { 1450, 0 }, 9, 0 },
414 { duration: 500, waveFreq: { 0 }, 0, 0 },
415 { duration: 25, waveFreq: { 1300, 0 }, 0, 0 },
416 { duration: 25, waveFreq: { 1450, 0 }, 19, 3 },
417 { duration: 500, waveFreq: { 0 }, 0, 0 },
418 { duration: 25, waveFreq: { 1300, 0 }, 0, 0 },
419 { duration: 25, waveFreq: { 1450, 0 }, 9, 6 },
420 { duration: 3000, waveFreq: { 0 }, 0, 0 },
421 { duration: 0, waveFreq: { 0 }, 0, 0 }},
422 repeatCnt: ToneGenerator::TONEGEN_INF,
423 repeatSegment: 0 }, // TONE_CDMA_LOW_SLS
424 { segments: { { duration: 25, waveFreq: { 3700, 0 }, 0, 0 },
425 { duration: 25, waveFreq: { 4000, 0 }, 9, 0 },
426 { duration: 500, waveFreq: { 0 }, 0, 0 },
427 { duration: 25, waveFreq: { 3700, 0 }, 0, 0 },
428 { duration: 25, waveFreq: { 4000, 0 }, 9, 3 },
429 { duration: 500, waveFreq: { 0 }, 0, 0 },
430 { duration: 25, waveFreq: { 3700, 0 }, 0, 0 },
431 { duration: 25, waveFreq: { 4000, 0 }, 9, 6 },
432 { duration: 500, waveFreq: { 0 }, 0, 0 },
433 { duration: 25, waveFreq: { 3700, 0 }, 0, 0 },
434 { duration: 25, waveFreq: { 4000, 0 }, 9, 9 },
435 { duration: 2500, waveFreq: { 0 }, 0, 0 },
436 { duration: 0, waveFreq: { 0 }, 0, 0 }},
437 repeatCnt: ToneGenerator::TONEGEN_INF,
438 repeatSegment: 0 }, // TONE_CDMA_HIGH_S_X4
439 { segments: { { duration: 25, waveFreq: { 2600, 0 }, 0, 0 },
440 { duration: 25, waveFreq: { 2900, 0 }, 9, 0 },
441 { duration: 500, waveFreq: { 0 }, 0, 0 },
442 { duration: 25, waveFreq: { 2600, 0 }, 0, 0 },
443 { duration: 25, waveFreq: { 2900, 0 }, 9, 3 },
444 { duration: 500, waveFreq: { 0 }, 0, 0 },
445 { duration: 25, waveFreq: { 2600, 0 }, 0, 0 },
446 { duration: 25, waveFreq: { 2900, 0 }, 9, 6 },
447 { duration: 500, waveFreq: { 0 }, 0, 0 },
448 { duration: 25, waveFreq: { 2600, 0 }, 0, 0 },
449 { duration: 25, waveFreq: { 2900, 0 }, 9, 9 },
450 { duration: 2500, waveFreq: { 0 }, 0, 0 },
451 { duration: 0, waveFreq: { 0 }, 0, 0 }},
452 repeatCnt: ToneGenerator::TONEGEN_INF,
453 repeatSegment: 0 }, // TONE_CDMA_MED_S_X4
454 { segments: { { duration: 25, waveFreq: { 1300, 0 }, 0, 0 },
455 { duration: 25, waveFreq: { 1450, 0 }, 9, 0 },
456 { duration: 500, waveFreq: { 0 }, 0, 0 },
457 { duration: 25, waveFreq: { 1300, 0 }, 0, 0 },
458 { duration: 25, waveFreq: { 1450, 0 }, 9, 3 },
459 { duration: 500, waveFreq: { 0 }, 0, 0 },
460 { duration: 25, waveFreq: { 1300, 0 }, 0, 0 },
461 { duration: 25, waveFreq: { 1450, 0 }, 9, 6 },
462 { duration: 500, waveFreq: { 0 }, 0, 0 },
463 { duration: 25, waveFreq: { 1300, 0 }, 0, 0 },
464 { duration: 25, waveFreq: { 1450, 0 }, 9, 9 },
465 { duration: 2500, waveFreq: { 0 }, 0, 0 },
466 { duration: 0, waveFreq: { 0 }, 0, 0 }},
467 repeatCnt: ToneGenerator::TONEGEN_INF,
468 repeatSegment: 0 }, // TONE_CDMA_LOW_S_X4
469 { segments: { { duration: 25, waveFreq: { 3700, 0 }, 0, 0 },
470 { duration: 25, waveFreq: { 4000, 0 }, 19, 0 },
471 { duration: 2000, waveFreq: { 0 }, 0, 0 },
472 { duration: 0, waveFreq: { 0 }, 0, 0 }},
473 repeatCnt: ToneGenerator::TONEGEN_INF,
474 repeatSegment: 0 }, // TONE_CDMA_HIGH_PBX_L
475 { segments: { { duration: 25, waveFreq: { 2600, 0 }, 0, 0 },
476 { duration: 25, waveFreq: { 2900, 0 }, 19, 0 },
477 { duration: 2000, waveFreq: { 0 }, 0, 0 },
478 { duration: 0, waveFreq: { 0 }, 0, 0 }},
479 repeatCnt: ToneGenerator::TONEGEN_INF,
480 repeatSegment: 0 }, // TONE_CDMA_MED_PBX_L
481 { segments: { { duration: 25, waveFreq: { 1300, 0 }, 0, 0 },
482 { duration: 25, waveFreq: { 1450, 0 }, 19, 0 },
483 { duration: 2000, waveFreq: { 0 }, 0, 0 },
484 { duration: 0, waveFreq: { 0 }, 0, 0 }},
485 repeatCnt: ToneGenerator::TONEGEN_INF,
486 repeatSegment: 0 }, // TONE_CDMA_LOW_PBX_L
487 { segments: { { duration: 25, waveFreq: { 3700, 0 }, 0, 0 },
488 { duration: 25, waveFreq: { 4000, 0 }, 7, 0 },
489 { duration: 200, waveFreq: { 0 }, 0, 0 },
490 { duration: 25, waveFreq: { 3700, 0 }, 0, 0 },
491 { duration: 25, waveFreq: { 4000, 0 }, 7, 3 },
492 { duration: 2000, waveFreq: { 0 }, 0, 0 },
493 { duration: 0, waveFreq: { 0 }, 0, 0 }},
494 repeatCnt: ToneGenerator::TONEGEN_INF,
495 repeatSegment: 0 }, // TONE_CDMA_HIGH_PBX_SS
496 { segments: { { duration: 25, waveFreq: { 2600, 0 }, 0, 0 },
497 { duration: 25, waveFreq: { 2900, 0 }, 7, 0 },
498 { duration: 200, waveFreq: { 0 }, 0, 0 },
499 { duration: 25, waveFreq: { 2600, 0 }, 0, 0 },
500 { duration: 25, waveFreq: { 2900, 0 }, 7, 3 },
501 { duration: 2000, waveFreq: { 0 }, 0, 0 },
502 { duration: 0, waveFreq: { 0 }, 0, 0 }},
503 repeatCnt: ToneGenerator::TONEGEN_INF,
504 repeatSegment: 0 }, // TONE_CDMA_MED_PBX_SS
505 { segments: { { duration: 25, waveFreq: { 1300, 0 }, 0, 0 },
506 { duration: 25, waveFreq: { 1450, 0 }, 7, 0 },
507 { duration: 200, waveFreq: { 0 }, 0, 0 },
508 { duration: 25, waveFreq: { 1300, 0 }, 0, 0 },
509 { duration: 25, waveFreq: { 1450, 0 }, 7, 3 },
510 { duration: 2000, waveFreq: { 0 }, 0, 0 },
511 { duration: 0, waveFreq: { 0 }, 0, 0 }},
512 repeatCnt: ToneGenerator::TONEGEN_INF,
513 repeatSegment: 0 }, // TONE_CDMA_LOW_PBX_SS
514 { segments: { { duration: 25, waveFreq: { 3700, 0 }, 0, 0 },
515 { duration: 25, waveFreq: { 4000, 0 }, 7, 0 },
516 { duration: 200, waveFreq: { 0 }, 0, 0 },
517 { duration: 25, waveFreq: { 3700, 0 }, 0, 0 },
518 { duration: 25, waveFreq: { 4000, 0 }, 7, 3 },
519 { duration: 200, waveFreq: { 0 }, 0, 0 },
520 { duration: 25, waveFreq: { 3700, 0 }, 0, 0 },
521 { duration: 25, waveFreq: { 4000, 0 }, 15, 6 },
522 { duration: 1000, waveFreq: { 0 }, 0, 0 },
523 { duration: 0, waveFreq: { 0 }, 0, 0 }},
524 repeatCnt: ToneGenerator::TONEGEN_INF,
525 repeatSegment: 0 }, // TONE_CDMA_HIGH_PBX_SSL
526 { segments: { { duration: 25, waveFreq: { 2600, 0 }, 0, 0 },
527 { duration: 25, waveFreq: { 2900, 0 }, 7, 0 },
528 { duration: 200, waveFreq: { 0 }, 0, 0 },
529 { duration: 25, waveFreq: { 2600, 0 }, 0, 0 },
530 { duration: 25, waveFreq: { 2900, 0 }, 7, 3 },
531 { duration: 200, waveFreq: { 0 }, 0, 0 },
532 { duration: 25, waveFreq: { 2600, 0 }, 0, 0 },
533 { duration: 25, waveFreq: { 2900, 0 }, 15, 6 },
534 { duration: 1000, waveFreq: { 0 }, 0, 0 },
535 { duration: 0, waveFreq: { 0 }, 0, 0 }},
536 repeatCnt: ToneGenerator::TONEGEN_INF,
537 repeatSegment: 0 }, // TONE_CDMA_MED_PBX_SSL
538 { segments: { { duration: 25, waveFreq: { 1300, 0 }, 0, 0 },
539 { duration: 25, waveFreq: { 1450, 0 }, 7, 0 },
540 { duration: 200, waveFreq: { 0 }, 0, 0 },
541 { duration: 25, waveFreq: { 1300, 0 }, 0, 0 },
542 { duration: 25, waveFreq: { 1450, 0 }, 7, 3 },
543 { duration: 200, waveFreq: { 0 }, 0, 0 },
544 { duration: 25, waveFreq: { 1300, 0 }, 0, 0 },
545 { duration: 25, waveFreq: { 1450, 0 }, 15, 6 },
546 { duration: 1000, waveFreq: { 0 }, 0, 0 },
547 { duration: 0, waveFreq: { 0 }, 0, 0 }},
548 repeatCnt: ToneGenerator::TONEGEN_INF,
549 repeatSegment: 0 }, // TONE_CDMA_LOW_PBX_SSL
550 { segments: { { duration: 25, waveFreq: { 3700, 0 }, 0, 0 },
551 { duration: 25, waveFreq: { 4000, 0 }, 7, 0 },
552 { duration: 200, waveFreq: { 0 }, 0, 0 },
553 { duration: 25, waveFreq: { 3700, 0 }, 0, 0 },
554 { duration: 25, waveFreq: { 4000, 0 }, 15, 3 },
555 { duration: 200, waveFreq: { 0 }, 0, 0 },
556 { duration: 25, waveFreq: { 3700, 0 }, 0, 0 },
557 { duration: 25, waveFreq: { 4000, 0 }, 7, 6 },
558 { duration: 1000, waveFreq: { 0 }, 0, 0 },
559 { duration: 0, waveFreq: { 0 }, 0, 0 }},
560 repeatCnt: ToneGenerator::TONEGEN_INF,
561 repeatSegment: 0 }, // TONE_CDMA_HIGH_PBX_SLS
562 { segments: { { duration: 25, waveFreq: { 2600, 0 }, 0, 0 },
563 { duration: 25, waveFreq: { 2900, 0 }, 7, 0 },
564 { duration: 200, waveFreq: { 0 }, 0, 0 },
565 { duration: 25, waveFreq: { 2600, 0 }, 0, 0 },
566 { duration: 25, waveFreq: { 2900, 0 }, 15, 3 },
567 { duration: 200, waveFreq: { 0 }, 0, 0 },
568 { duration: 25, waveFreq: { 2600, 0 }, 0, 0 },
569 { duration: 25, waveFreq: { 2900, 0 }, 7, 6 },
570 { duration: 1000, waveFreq: { 0 }, 0, 0 },
571 { duration: 0, waveFreq: { 0 }, 0, 0 }},
572 repeatCnt: ToneGenerator::TONEGEN_INF,
573 repeatSegment: 0 }, // TONE_CDMA_MED_PBX_SLS
574 { segments: { { duration: 25, waveFreq: { 1300, 0 }, 0, 0 },
575 { duration: 25, waveFreq: { 1450, 0 }, 7, 0 },
576 { duration: 200, waveFreq: { 0 }, 0, 0 },
577 { duration: 25, waveFreq: { 1300, 0 }, 0, 0 },
578 { duration: 25, waveFreq: { 1450, 0 }, 15, 3 },
579 { duration: 200, waveFreq: { 0 }, 0, 0 },
580 { duration: 25, waveFreq: { 1300, 0 }, 0, 0 },
581 { duration: 25, waveFreq: { 1450, 0 }, 7, 6 },
582 { duration: 1000, waveFreq: { 0 }, 0, 0 },
583 { duration: 0, waveFreq: { 0 }, 0, 0 }},
584 repeatCnt: ToneGenerator::TONEGEN_INF,
585 repeatSegment: 0 }, // TONE_CDMA_LOW_PBX_SLS
586 { segments: { { duration: 25, waveFreq: { 3700, 0 }, 0, 0 },
587 { duration: 25, waveFreq: { 4000, 0 }, 7, 0 },
588 { duration: 200, waveFreq: { 0 }, 0, 0 },
589 { duration: 25, waveFreq: { 3700, 0 }, 0, 0 },
590 { duration: 25, waveFreq: { 4000, 0 }, 7, 3 },
591 { duration: 200, waveFreq: { 0 }, 0, 0 },
592 { duration: 25, waveFreq: { 3700, 0 }, 0, 0 },
593 { duration: 25, waveFreq: { 4000, 0 }, 7, 6 },
594 { duration: 200, waveFreq: { 0 }, 0, 0 },
595 { duration: 25, waveFreq: { 3700, 0 }, 0, 0 },
596 { duration: 25, waveFreq: { 4000, 0 }, 7, 9 },
597 { duration: 800, waveFreq: { 0 }, 0, 0 },
598 { duration: 0, waveFreq: { 0 }, 0, 0 }},
599 repeatCnt: ToneGenerator::TONEGEN_INF,
600 repeatSegment: 0 }, // TONE_CDMA_HIGH_PBX_S_X4
601 { segments: { { duration: 25, waveFreq: { 2600, 0 }, 0, 0 },
602 { duration: 25, waveFreq: { 2900, 0 }, 7, 0 },
603 { duration: 200, waveFreq: { 0 }, 0, 0 },
604 { duration: 25, waveFreq: { 2600, 0 }, 0, 0 },
605 { duration: 25, waveFreq: { 2900, 0 }, 7, 3 },
606 { duration: 200, waveFreq: { 0 }, 0, 0 },
607 { duration: 25, waveFreq: { 2600, 0 }, 0, 0 },
608 { duration: 25, waveFreq: { 2900, 0 }, 7, 6 },
609 { duration: 200, waveFreq: { 0 }, 0, 0 },
610 { duration: 25, waveFreq: { 2600, 0 }, 0, 0 },
611 { duration: 25, waveFreq: { 2900, 0 }, 7, 9 },
612 { duration: 800, waveFreq: { 0 }, 0, 0 },
613 { duration: 0, waveFreq: { 0 }, 0, 0 }},
614 repeatCnt: ToneGenerator::TONEGEN_INF,
615 repeatSegment: 0 }, // TONE_CDMA_MED_PBX_S_X4
616 { segments: { { duration: 25, waveFreq: { 1300, 0 }, 0, 0 },
617 { duration: 25, waveFreq: { 1450, 0 }, 7, 0 },
618 { duration: 200, waveFreq: { 0 }, 0, 0 },
619 { duration: 25, waveFreq: { 1300, 0 }, 0, 0 },
620 { duration: 25, waveFreq: { 1450, 0 }, 7, 3 },
621 { duration: 200, waveFreq: { 0 }, 0, 0 },
622 { duration: 25, waveFreq: { 1300, 0 }, 0, 0 },
623 { duration: 25, waveFreq: { 1450, 0 }, 7, 6 },
624 { duration: 200, waveFreq: { 0 }, 0, 0 },
625 { duration: 25, waveFreq: { 1300, 0 }, 0, 0 },
626 { duration: 25, waveFreq: { 1450, 0 }, 7, 9 },
627 { duration: 800, waveFreq: { 0 }, 0, 0 },
628 { duration: 0, waveFreq: { 0 }, 0, 0 }},
629 repeatCnt: ToneGenerator::TONEGEN_INF,
630 repeatSegment: 0 }, // TONE_CDMA_LOW_PBX_S_X4
631
632 { segments: { { duration: 62, waveFreq: { 1109, 0 }, 0, 0 },
633 { duration: 62, waveFreq: { 784, 0 }, 0, 0 },
634 { duration: 62, waveFreq: { 740, 0 }, 0, 0 },
635 { duration: 62, waveFreq: { 622, 0 }, 0, 0 },
636 { duration: 62, waveFreq: { 1109, 0 }, 0, 0 },
637 { duration: 0, waveFreq: { 0 }, 0, 0 } },
638 repeatCnt: 0,
639 repeatSegment: 0 }, // TONE_CDMA_ALERT_NETWORK_LITE
640 { segments: { { duration: 62, waveFreq: { 1245, 0 }, 0, 0 },
641 { duration: 62, waveFreq: { 659, 0 }, 2, 0 },
642 { duration: 62, waveFreq: { 1245, 0 }, 0, 0 },
643 { duration: 0, waveFreq: { 0 }, 0, 0 } },
644 repeatCnt: 0,
645 repeatSegment: 0 }, // TONE_CDMA_ALERT_AUTOREDIAL_LITE
646 { segments: { { duration: 400, waveFreq: { 1150, 770, 0 }, 0, 0 },
647 { duration: 0, waveFreq: { 0 }, 0, 0 } },
648 repeatCnt: 0,
649 repeatSegment: 0 }, // TONE_CDMA_ONE_MIN_BEEP
650 { segments: { { duration: 120, waveFreq: { 941, 1477, 0 }, 0, 0 },
651 { duration: 0, waveFreq: { 0 }, 0, 0 } },
652 repeatCnt: 0,
653 repeatSegment: 0 }, // TONE_CDMA_KEYPAD_VOLUME_KEY_LITE
654 { segments: { { duration: 375, waveFreq: { 587, 0 }, 0, 0 },
655 { duration: 125, waveFreq: { 1175, 0 }, 0, 0 },
656 { duration: 0, waveFreq: { 0 }, 0, 0 } },
657 repeatCnt: 0,
658 repeatSegment: 0 }, // TONE_CDMA_PRESSHOLDKEY_LITE
659 { segments: { { duration: 62, waveFreq: { 587, 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: 62, waveFreq: { 1109, 0 }, 0, 0 },
664 { duration: 62, waveFreq: { 784, 0 }, 0, 0 },
665 { duration: 62, waveFreq: { 831, 0 }, 0, 0 },
666 { duration: 62, waveFreq: { 784, 0 }, 0, 0 },
667 { duration: 0, waveFreq: { 0 }, 0, 0 } },
668 repeatCnt: 0,
669 repeatSegment: 0 }, // TONE_CDMA_ALERT_INCALL_LITE
670 { segments: { { duration: 125, waveFreq: { 941, 0 }, 0, 0 },
671 { duration: 10, waveFreq: { 0 }, 2, 0 },
672 { duration: 4990, waveFreq: { 0 }, 0, 0 },
673 { duration: 0, waveFreq: { 0 }, 0, 0 } },
674 repeatCnt: ToneGenerator::TONEGEN_INF,
675 repeatSegment: 0 }, // TONE_CDMA_EMERGENCY_RINGBACK
676 { segments: { { duration: 125, waveFreq: { 1319, 0 }, 0, 0 },
677 { duration: 125, waveFreq: { 0 }, 0, 0 },
678 { duration: 0, waveFreq: { 0 }, 0, 0 } },
679 repeatCnt: 2,
680 repeatSegment: 0 }, // TONE_CDMA_ALERT_CALL_GUARD
681 { segments: { { duration: 125, waveFreq: { 1047, 0 }, 0, 0 },
682 { duration: 125, waveFreq: { 370, 0 }, 0, 0 },
683 { duration: 0, waveFreq: { 0 }, 0, 0 } },
684 repeatCnt: 0,
685 repeatSegment: 0 }, // TONE_CDMA_SOFT_ERROR_LITE
686 { segments: { { duration: 125, waveFreq: { 1480, 0 }, 0, 0 },
687 { duration: 125, waveFreq: { 1397, 0 }, 0, 0 },
688 { duration: 125, waveFreq: { 784, 0 }, 0, 0 },
689 { duration: 0, waveFreq: { 0 }, 0, 0 } },
690 repeatCnt: 0,
691 repeatSegment: 0 }, // TONE_CDMA_CALLDROP_LITE
692
693 { segments: { { duration: 500, waveFreq: { 425, 0 }, 0, 0 },
694 { duration: 500, waveFreq: { 0 }, 0, 0 },
695 { duration: 0, waveFreq: { 0 }, 0, 0 }},
696 repeatCnt: 0,
697 repeatSegment: 0 }, // TONE_CDMA_NETWORK_BUSY_ONE_SHOT
698 { segments: { { duration: 400, waveFreq: { 1150, 770 }, 0, 0 },
699 { duration: 0, waveFreq: { 0 }, 0, 0 }},
700 repeatCnt: 0,
701 repeatSegment: 0 }, // TONE_CDMA_ABBR_ALERT
702 { segments: { { duration: 0, waveFreq: { 0 }, 0, 0 }},
703 repeatCnt: 0,
704 repeatSegment: 0 }, // TONE_CDMA_SIGNAL_OFF
705
706 { segments: { { duration: ToneGenerator::TONEGEN_INF, waveFreq: { 350, 440, 0 }, 0, 0 },
707 { duration: 0 , waveFreq: { 0 }, 0, 0}},
Eric Laurentf3af7402009-05-05 00:49:01 -0700708 repeatCnt: ToneGenerator::TONEGEN_INF,
709 repeatSegment: 0 }, // TONE_ANSI_DIAL
David Krauseb6d90ca2009-06-17 15:46:13 -0500710 { segments: { { duration: 500, waveFreq: { 480, 620, 0 }, 0, 0 },
711 { duration: 500, waveFreq: { 0 }, 0, 0 },
712 { duration: 0 , waveFreq: { 0 }, 0, 0}},
Eric Laurentf3af7402009-05-05 00:49:01 -0700713 repeatCnt: ToneGenerator::TONEGEN_INF,
714 repeatSegment: 0 }, // TONE_ANSI_BUSY
David Krauseb6d90ca2009-06-17 15:46:13 -0500715 { segments: { { duration: 250, waveFreq: { 480, 620, 0 }, 0, 0 },
716 { duration: 250, waveFreq: { 0 }, 0, 0 },
717 { duration: 0 , waveFreq: { 0 }, 0, 0}},
Eric Laurentf3af7402009-05-05 00:49:01 -0700718 repeatCnt: ToneGenerator::TONEGEN_INF,
719 repeatSegment: 0 }, // TONE_ANSI_CONGESTION
David Krauseb6d90ca2009-06-17 15:46:13 -0500720 { segments: { { duration: 300, waveFreq: { 440, 0 }, 0, 0 },
721 { duration: 9700, waveFreq: { 0 }, 0, 0 },
722 { duration: 100, waveFreq: { 440, 0 }, 0, 0 },
723 { duration: 100, waveFreq: { 0 }, 0, 0 },
724 { duration: 100, waveFreq: { 440, 0 }, 0, 0 },
725 { duration: 0 , waveFreq: { 0 }, 0, 0}},
Eric Laurentf3af7402009-05-05 00:49:01 -0700726 repeatCnt: ToneGenerator::TONEGEN_INF,
727 repeatSegment: 1 }, // TONE_ANSI_CALL_WAITING
David Krauseb6d90ca2009-06-17 15:46:13 -0500728 { segments: { { duration: 2000, waveFreq: { 440, 480, 0 }, 0, 0 },
729 { duration: 4000, waveFreq: { 0 }, 0, 0 },
730 { duration: 0 , waveFreq: { 0 }, 0, 0}},
Eric Laurentf3af7402009-05-05 00:49:01 -0700731 repeatCnt: ToneGenerator::TONEGEN_INF,
732 repeatSegment: 0 }, // TONE_ANSI_RINGTONE
David Krauseb6d90ca2009-06-17 15:46:13 -0500733 { segments: { { duration: ToneGenerator::TONEGEN_INF, waveFreq: { 400, 0 }, 0, 0 },
734 { duration: 0 , waveFreq: { 0 }, 0, 0}},
Eric Laurentf3af7402009-05-05 00:49:01 -0700735 repeatCnt: ToneGenerator::TONEGEN_INF,
736 repeatSegment: 0 }, // TONE_JAPAN_DIAL
David Krauseb6d90ca2009-06-17 15:46:13 -0500737 { segments: { { duration: 500, waveFreq: { 400, 0 }, 0, 0 },
738 { duration: 500, waveFreq: { 0 }, 0, 0 },
739 { duration: 0 , waveFreq: { 0 }, 0, 0}},
Eric Laurentf3af7402009-05-05 00:49:01 -0700740 repeatCnt: ToneGenerator::TONEGEN_INF,
741 repeatSegment: 0 }, // TONE_JAPAN_BUSY
David Krauseb6d90ca2009-06-17 15:46:13 -0500742 { segments: { { duration: 1000, waveFreq: { 400, 0 }, 0, 0 },
743 { duration: 2000, waveFreq: { 0 }, 0, 0 },
744 { duration: 0 , waveFreq: { 0 }, 0, 0}},
Eric Laurentf3af7402009-05-05 00:49:01 -0700745 repeatCnt: ToneGenerator::TONEGEN_INF,
746 repeatSegment: 0 }, // TONE_JAPAN_RADIO_ACK
David Krauseb6d90ca2009-06-17 15:46:13 -0500747
748
749
Eric Laurentf3af7402009-05-05 00:49:01 -0700750};
751
752// Used by ToneGenerator::getToneForRegion() to convert user specified supervisory tone type
753// to actual tone for current region.
754const unsigned char ToneGenerator::sToneMappingTable[NUM_REGIONS-1][NUM_SUP_TONES] = {
755 { // ANSI
756 TONE_ANSI_DIAL, // TONE_SUP_DIAL
757 TONE_ANSI_BUSY, // TONE_SUP_BUSY
758 TONE_ANSI_CONGESTION, // TONE_SUP_CONGESTION
759 TONE_SUP_RADIO_ACK, // TONE_SUP_RADIO_ACK
760 TONE_SUP_RADIO_NOTAVAIL, // TONE_SUP_RADIO_NOTAVAIL
761 TONE_SUP_ERROR, // TONE_SUP_ERROR
762 TONE_ANSI_CALL_WAITING, // TONE_SUP_CALL_WAITING
763 TONE_ANSI_RINGTONE // TONE_SUP_RINGTONE
764 },
765 { // JAPAN
766 TONE_JAPAN_DIAL, // TONE_SUP_DIAL
767 TONE_JAPAN_BUSY, // TONE_SUP_BUSY
768 TONE_SUP_CONGESTION, // TONE_SUP_CONGESTION
769 TONE_JAPAN_RADIO_ACK, // TONE_SUP_RADIO_ACK
770 TONE_SUP_RADIO_NOTAVAIL, // TONE_SUP_RADIO_NOTAVAIL
771 TONE_SUP_ERROR, // TONE_SUP_ERROR
772 TONE_SUP_CALL_WAITING, // TONE_SUP_CALL_WAITING
773 TONE_SUP_RINGTONE // TONE_SUP_RINGTONE
774 }
775};
776
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800777
778////////////////////////////////////////////////////////////////////////////////
779// ToneGenerator class Implementation
780////////////////////////////////////////////////////////////////////////////////
781
782
783//---------------------------------- public methods ----------------------------
784
785
786////////////////////////////////////////////////////////////////////////////////
787//
788// Method: ToneGenerator::ToneGenerator()
789//
790// Description: Constructor. Initializes the tone sequencer, intantiates required sine wave
791// generators, instantiates output audio track.
792//
793// Input:
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800794// streamType: Type of stream used for tone playback (enum AudioTrack::stream_type)
795// volume: volume applied to tone (0.0 to 1.0)
796//
797// Output:
798// none
799//
800////////////////////////////////////////////////////////////////////////////////
Eric Laurentbda74692009-11-04 08:27:26 -0800801ToneGenerator::ToneGenerator(int streamType, float volume, bool threadCanCallJava) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800802
803 LOGV("ToneGenerator constructor: streamType=%d, volume=%f\n", streamType, volume);
804
805 mState = TONE_IDLE;
806
807 if (AudioSystem::getOutputSamplingRate(&mSamplingRate, streamType) != NO_ERROR) {
808 LOGE("Unable to marshal AudioFlinger");
809 return;
810 }
Eric Laurentbda74692009-11-04 08:27:26 -0800811 mThreadCanCallJava = threadCanCallJava;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800812 mStreamType = streamType;
813 mVolume = volume;
814 mpAudioTrack = 0;
815 mpToneDesc = 0;
816 mpNewToneDesc = 0;
817 // Generate tone by chunks of 20 ms to keep cadencing precision
818 mProcessSize = (mSamplingRate * 20) / 1000;
819
Eric Laurentf3af7402009-05-05 00:49:01 -0700820 char value[PROPERTY_VALUE_MAX];
821 property_get("gsm.operator.iso-country", value, "");
822 if (strcmp(value,"us") == 0 ||
823 strcmp(value,"ca") == 0) {
824 mRegion = ANSI;
825 } else if (strcmp(value,"jp") == 0) {
826 mRegion = JAPAN;
827 } else {
828 mRegion = CEPT;
829 }
830
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800831 if (initAudioTrack()) {
832 LOGV("ToneGenerator INIT OK, time: %d\n", (unsigned int)(systemTime()/1000000));
833 } else {
834 LOGV("!!!ToneGenerator INIT FAILED!!!\n");
835 }
836}
837
838
839
840
841////////////////////////////////////////////////////////////////////////////////
842//
843// Method: ToneGenerator::~ToneGenerator()
844//
845// Description: Destructor. Stop sound playback and delete audio track if
846// needed and delete sine wave generators.
847//
848// Input:
849// none
850//
851// Output:
852// none
853//
854////////////////////////////////////////////////////////////////////////////////
855ToneGenerator::~ToneGenerator() {
856 LOGV("ToneGenerator destructor\n");
857
858 if (mpAudioTrack) {
859 stopTone();
860 LOGV("Delete Track: %p\n", mpAudioTrack);
861 delete mpAudioTrack;
862 }
863}
864
865////////////////////////////////////////////////////////////////////////////////
866//
867// Method: ToneGenerator::startTone()
868//
869// Description: Starts tone playback.
870//
871// Input:
Eric Laurent96c08a62009-09-07 08:38:38 -0700872// toneType: Type of tone generated (values in enum tone_type)
873// durationMs: The tone duration in milliseconds. If the tone is limited in time by definition,
874// the actual duration will be the minimum of durationMs and the defined tone duration.
875// Ommiting or setting durationMs to -1 does not limit tone duration.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800876//
877// Output:
878// none
879//
880////////////////////////////////////////////////////////////////////////////////
Eric Laurent96c08a62009-09-07 08:38:38 -0700881bool ToneGenerator::startTone(int toneType, int durationMs) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800882 bool lResult = false;
Eric Laurent62443f52009-10-05 20:29:18 -0700883 status_t lStatus;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800884
Dave Sparks4c922472009-05-07 09:26:06 -0700885 if ((toneType < 0) || (toneType >= NUM_TONES))
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800886 return lResult;
887
888 if (mState == TONE_IDLE) {
889 LOGV("startTone: try to re-init AudioTrack");
890 if (!initAudioTrack()) {
891 return lResult;
892 }
893 }
894
895 LOGV("startTone\n");
896
897 mLock.lock();
898
899 // Get descriptor for requested tone
Eric Laurentf3af7402009-05-05 00:49:01 -0700900 toneType = getToneForRegion(toneType);
901 mpNewToneDesc = &sToneDescriptors[toneType];
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800902
Eric Laurent62443f52009-10-05 20:29:18 -0700903 mDurationMs = durationMs;
904
905 if (mState == TONE_STOPPED) {
906 LOGV("Start waiting for previous tone to stop");
Eric Laurentdd28d562009-10-23 04:46:30 -0700907 lStatus = mWaitCbkCond.waitRelative(mLock, seconds(3));
Eric Laurent62443f52009-10-05 20:29:18 -0700908 if (lStatus != NO_ERROR) {
909 LOGE("--- start wait for stop timed out, status %d", lStatus);
910 mState = TONE_IDLE;
Eric Laurentdd28d562009-10-23 04:46:30 -0700911 mLock.unlock();
Eric Laurent62443f52009-10-05 20:29:18 -0700912 return lResult;
Eric Laurent96c08a62009-09-07 08:38:38 -0700913 }
Eric Laurent96c08a62009-09-07 08:38:38 -0700914 }
915
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800916 if (mState == TONE_INIT) {
917 if (prepareWave()) {
918 LOGV("Immediate start, time %d\n", (unsigned int)(systemTime()/1000000));
919 lResult = true;
920 mState = TONE_STARTING;
921 mLock.unlock();
922 mpAudioTrack->start();
923 mLock.lock();
924 if (mState == TONE_STARTING) {
925 LOGV("Wait for start callback");
Eric Laurentdd28d562009-10-23 04:46:30 -0700926 lStatus = mWaitCbkCond.waitRelative(mLock, seconds(3));
The Android Open Source Projectb2a3dd82009-03-09 11:52:12 -0700927 if (lStatus != NO_ERROR) {
928 LOGE("--- Immediate start timed out, status %d", lStatus);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800929 mState = TONE_IDLE;
930 lResult = false;
931 }
932 }
933 } else {
Eric Laurentc4e58c02009-08-11 01:26:35 -0700934 mState = TONE_IDLE;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800935 }
936 } else {
937 LOGV("Delayed start\n");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800938 mState = TONE_RESTARTING;
Eric Laurentdd28d562009-10-23 04:46:30 -0700939 lStatus = mWaitCbkCond.waitRelative(mLock, seconds(3));
The Android Open Source Projectb2a3dd82009-03-09 11:52:12 -0700940 if (lStatus == NO_ERROR) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800941 if (mState != TONE_IDLE) {
942 lResult = true;
943 }
944 LOGV("cond received");
945 } else {
The Android Open Source Projectb2a3dd82009-03-09 11:52:12 -0700946 LOGE("--- Delayed start timed out, status %d", lStatus);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800947 mState = TONE_IDLE;
948 }
949 }
950 mLock.unlock();
951
952 LOGV_IF(lResult, "Tone started, time %d\n", (unsigned int)(systemTime()/1000000));
953 LOGW_IF(!lResult, "Tone start failed!!!, time %d\n", (unsigned int)(systemTime()/1000000));
954
955 return lResult;
956}
957
958////////////////////////////////////////////////////////////////////////////////
959//
960// Method: ToneGenerator::stopTone()
961//
962// Description: Stops tone playback.
963//
964// Input:
965// none
966//
967// Output:
968// none
969//
970////////////////////////////////////////////////////////////////////////////////
971void ToneGenerator::stopTone() {
972 LOGV("stopTone");
973
974 mLock.lock();
975 if (mState == TONE_PLAYING || mState == TONE_STARTING || mState == TONE_RESTARTING) {
976 mState = TONE_STOPPING;
977 LOGV("waiting cond");
Eric Laurentdd28d562009-10-23 04:46:30 -0700978 status_t lStatus = mWaitCbkCond.waitRelative(mLock, seconds(3));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800979 if (lStatus == NO_ERROR) {
980 LOGV("track stop complete, time %d", (unsigned int)(systemTime()/1000000));
981 } else {
982 LOGE("--- Stop timed out");
983 mState = TONE_IDLE;
984 mpAudioTrack->stop();
985 }
986 }
987
988 clearWaveGens();
989
990 mLock.unlock();
991}
992
993//---------------------------------- private methods ---------------------------
994
995
996
997
998////////////////////////////////////////////////////////////////////////////////
999//
1000// Method: ToneGenerator::initAudioTrack()
1001//
1002// Description: Allocates and configures AudioTrack used for PCM output.
1003//
1004// Input:
1005// none
1006//
1007// Output:
1008// none
1009//
1010////////////////////////////////////////////////////////////////////////////////
1011bool ToneGenerator::initAudioTrack() {
1012
1013 if (mpAudioTrack) {
1014 delete mpAudioTrack;
1015 mpAudioTrack = 0;
1016 }
1017
1018 // Open audio track in mono, PCM 16bit, default sampling rate, default buffer size
Eric Laurentbda74692009-11-04 08:27:26 -08001019 mpAudioTrack = new AudioTrack();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001020 if (mpAudioTrack == 0) {
1021 LOGE("AudioTrack allocation failed");
1022 goto initAudioTrack_exit;
1023 }
1024 LOGV("Create Track: %p\n", mpAudioTrack);
1025
Eric Laurentbda74692009-11-04 08:27:26 -08001026 mpAudioTrack->set(mStreamType,
1027 0,
Dima Zavin24fc2fb2011-04-19 22:30:36 -07001028 AUDIO_FORMAT_PCM_16_BIT,
1029 AUDIO_CHANNEL_OUT_MONO,
Eric Laurentbda74692009-11-04 08:27:26 -08001030 0,
1031 0,
1032 audioCallback,
1033 this,
1034 0,
1035 0,
1036 mThreadCanCallJava);
1037
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001038 if (mpAudioTrack->initCheck() != NO_ERROR) {
1039 LOGE("AudioTrack->initCheck failed");
1040 goto initAudioTrack_exit;
1041 }
1042
1043 mpAudioTrack->setVolume(mVolume, mVolume);
1044
1045 mState = TONE_INIT;
1046
1047 return true;
1048
1049initAudioTrack_exit:
1050
1051 // Cleanup
1052 if (mpAudioTrack) {
1053 LOGV("Delete Track I: %p\n", mpAudioTrack);
1054 delete mpAudioTrack;
1055 mpAudioTrack = 0;
1056 }
1057
1058 return false;
1059}
1060
1061
1062////////////////////////////////////////////////////////////////////////////////
1063//
1064// Method: ToneGenerator::audioCallback()
1065//
1066// Description: AudioTrack callback implementation. Generates a block of
1067// PCM samples
1068// and manages tone generator sequencer: tones pulses, tone duration...
1069//
1070// Input:
1071// user reference (pointer to our ToneGenerator)
1072// info audio buffer descriptor
1073//
1074// Output:
1075// returned value: always true.
1076//
1077////////////////////////////////////////////////////////////////////////////////
Glenn Kastene46a86f2011-06-01 15:20:35 -07001078void ToneGenerator::audioCallback(int event, void* user, void *info) {
David Krauseb6d90ca2009-06-17 15:46:13 -05001079
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001080 if (event != AudioTrack::EVENT_MORE_DATA) return;
David Krauseb6d90ca2009-06-17 15:46:13 -05001081
Eric Laurentaf141d52009-09-24 07:03:14 -07001082 AudioTrack::Buffer *buffer = static_cast<AudioTrack::Buffer *>(info);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001083 ToneGenerator *lpToneGen = static_cast<ToneGenerator *>(user);
1084 short *lpOut = buffer->i16;
1085 unsigned int lNumSmp = buffer->size/sizeof(short);
Eric Laurentf3af7402009-05-05 00:49:01 -07001086 const ToneDescriptor *lpToneDesc = lpToneGen->mpToneDesc;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001087
1088 if (buffer->size == 0) return;
1089
1090
1091 // Clear output buffer: WaveGenerator accumulates into lpOut buffer
1092 memset(lpOut, 0, buffer->size);
1093
1094 while (lNumSmp) {
1095 unsigned int lReqSmp = lNumSmp < lpToneGen->mProcessSize*2 ? lNumSmp : lpToneGen->mProcessSize;
1096 unsigned int lGenSmp;
1097 unsigned int lWaveCmd = WaveGenerator::WAVEGEN_CONT;
1098 bool lSignal = false;
David Krauseb6d90ca2009-06-17 15:46:13 -05001099
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001100 lpToneGen->mLock.lock();
1101
Eric Laurentdd28d562009-10-23 04:46:30 -07001102
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001103 // Update pcm frame count and end time (current time at the end of this process)
1104 lpToneGen->mTotalSmp += lReqSmp;
David Krauseb6d90ca2009-06-17 15:46:13 -05001105
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001106 // Update tone gen state machine and select wave gen command
1107 switch (lpToneGen->mState) {
1108 case TONE_PLAYING:
1109 lWaveCmd = WaveGenerator::WAVEGEN_CONT;
1110 break;
1111 case TONE_STARTING:
1112 LOGV("Starting Cbk");
David Krauseb6d90ca2009-06-17 15:46:13 -05001113
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001114 lWaveCmd = WaveGenerator::WAVEGEN_START;
1115 break;
1116 case TONE_STOPPING:
1117 case TONE_RESTARTING:
1118 LOGV("Stop/restart Cbk");
David Krauseb6d90ca2009-06-17 15:46:13 -05001119
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001120 lWaveCmd = WaveGenerator::WAVEGEN_STOP;
1121 lpToneGen->mNextSegSmp = TONEGEN_INF; // forced to skip state machine management below
1122 break;
Eric Laurentaf141d52009-09-24 07:03:14 -07001123 case TONE_STOPPED:
1124 LOGV("Stopped Cbk");
1125 goto audioCallback_EndLoop;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001126 default:
1127 LOGV("Extra Cbk");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001128 goto audioCallback_EndLoop;
1129 }
David Krauseb6d90ca2009-06-17 15:46:13 -05001130
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001131 // Exit if tone sequence is over
Eric Laurent96c08a62009-09-07 08:38:38 -07001132 if (lpToneDesc->segments[lpToneGen->mCurSegment].duration == 0 ||
1133 lpToneGen->mTotalSmp > lpToneGen->mMaxSmp) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001134 if (lpToneGen->mState == TONE_PLAYING) {
David Krauseb6d90ca2009-06-17 15:46:13 -05001135 lpToneGen->mState = TONE_STOPPING;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001136 }
Eric Laurent96c08a62009-09-07 08:38:38 -07001137 if (lpToneDesc->segments[lpToneGen->mCurSegment].duration == 0) {
1138 goto audioCallback_EndLoop;
1139 }
Eric Laurentaf141d52009-09-24 07:03:14 -07001140 // fade out before stopping if maximum duration reached
Eric Laurent96c08a62009-09-07 08:38:38 -07001141 lWaveCmd = WaveGenerator::WAVEGEN_STOP;
1142 lpToneGen->mNextSegSmp = TONEGEN_INF; // forced to skip state machine management below
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001143 }
David Krauseb6d90ca2009-06-17 15:46:13 -05001144
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001145 if (lpToneGen->mTotalSmp > lpToneGen->mNextSegSmp) {
1146 // Time to go to next sequence segment
David Krauseb6d90ca2009-06-17 15:46:13 -05001147
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001148 LOGV("End Segment, time: %d\n", (unsigned int)(systemTime()/1000000));
David Krauseb6d90ca2009-06-17 15:46:13 -05001149
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001150 lGenSmp = lReqSmp;
Eric Laurentf3af7402009-05-05 00:49:01 -07001151
1152 // If segment, ON -> OFF transition : ramp volume down
1153 if (lpToneDesc->segments[lpToneGen->mCurSegment].waveFreq[0] != 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001154 lWaveCmd = WaveGenerator::WAVEGEN_STOP;
Eric Laurentf3af7402009-05-05 00:49:01 -07001155 unsigned int lFreqIdx = 0;
1156 unsigned short lFrequency = lpToneDesc->segments[lpToneGen->mCurSegment].waveFreq[lFreqIdx];
1157
1158 while (lFrequency != 0) {
1159 WaveGenerator *lpWaveGen = lpToneGen->mWaveGens.valueFor(lFrequency);
1160 lpWaveGen->getSamples(lpOut, lGenSmp, lWaveCmd);
1161 lFrequency = lpToneDesc->segments[lpToneGen->mCurSegment].waveFreq[++lFreqIdx];
1162 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001163 LOGV("ON->OFF, lGenSmp: %d, lReqSmp: %d\n", lGenSmp, lReqSmp);
1164 }
Eric Laurentf3af7402009-05-05 00:49:01 -07001165
David Krauseb6d90ca2009-06-17 15:46:13 -05001166 // check if we need to loop and loop for the reqd times
1167 if (lpToneDesc->segments[lpToneGen->mCurSegment].loopCnt) {
1168 if (lpToneGen->mLoopCounter < lpToneDesc->segments[lpToneGen->mCurSegment].loopCnt) {
1169 LOGV ("in if loop loopCnt(%d) loopctr(%d), CurSeg(%d) \n",
1170 lpToneDesc->segments[lpToneGen->mCurSegment].loopCnt,
1171 lpToneGen->mLoopCounter,
1172 lpToneGen->mCurSegment);
1173 lpToneGen->mCurSegment = lpToneDesc->segments[lpToneGen->mCurSegment].loopIndx;
1174 ++lpToneGen->mLoopCounter;
1175 } else {
1176 // completed loop. go to next segment
1177 lpToneGen->mLoopCounter = 0;
1178 lpToneGen->mCurSegment++;
1179 LOGV ("in else loop loopCnt(%d) loopctr(%d), CurSeg(%d) \n",
1180 lpToneDesc->segments[lpToneGen->mCurSegment].loopCnt,
1181 lpToneGen->mLoopCounter,
1182 lpToneGen->mCurSegment);
1183 }
1184 } else {
1185 lpToneGen->mCurSegment++;
1186 LOGV ("Goto next seg loopCnt(%d) loopctr(%d), CurSeg(%d) \n",
1187 lpToneDesc->segments[lpToneGen->mCurSegment].loopCnt,
1188 lpToneGen->mLoopCounter,
1189 lpToneGen->mCurSegment);
1190
1191 }
Eric Laurentf3af7402009-05-05 00:49:01 -07001192
1193 // Handle loop if last segment reached
1194 if (lpToneDesc->segments[lpToneGen->mCurSegment].duration == 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001195 LOGV("Last Seg: %d\n", lpToneGen->mCurSegment);
David Krauseb6d90ca2009-06-17 15:46:13 -05001196
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001197 // Pre increment loop count and restart if total count not reached. Stop sequence otherwise
Eric Laurentf3af7402009-05-05 00:49:01 -07001198 if (++lpToneGen->mCurCount <= lpToneDesc->repeatCnt) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001199 LOGV("Repeating Count: %d\n", lpToneGen->mCurCount);
David Krauseb6d90ca2009-06-17 15:46:13 -05001200
Eric Laurentf3af7402009-05-05 00:49:01 -07001201 lpToneGen->mCurSegment = lpToneDesc->repeatSegment;
1202 if (lpToneDesc->segments[lpToneDesc->repeatSegment].waveFreq[0] != 0) {
1203 lWaveCmd = WaveGenerator::WAVEGEN_START;
1204 }
David Krauseb6d90ca2009-06-17 15:46:13 -05001205
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001206 LOGV("New segment %d, Next Time: %d\n", lpToneGen->mCurSegment,
1207 (lpToneGen->mNextSegSmp*1000)/lpToneGen->mSamplingRate);
David Krauseb6d90ca2009-06-17 15:46:13 -05001208
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001209 } else {
Eric Laurentf3af7402009-05-05 00:49:01 -07001210 lGenSmp = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001211 LOGV("End repeat, time: %d\n", (unsigned int)(systemTime()/1000000));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001212 }
1213 } else {
1214 LOGV("New segment %d, Next Time: %d\n", lpToneGen->mCurSegment,
1215 (lpToneGen->mNextSegSmp*1000)/lpToneGen->mSamplingRate);
Eric Laurentf3af7402009-05-05 00:49:01 -07001216 if (lpToneDesc->segments[lpToneGen->mCurSegment].waveFreq[0] != 0) {
1217 // If next segment is not silent, OFF -> ON transition : reset wave generator
1218 lWaveCmd = WaveGenerator::WAVEGEN_START;
1219
1220 LOGV("OFF->ON, lGenSmp: %d, lReqSmp: %d\n", lGenSmp, lReqSmp);
1221 } else {
1222 lGenSmp = 0;
1223 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001224 }
David Krauseb6d90ca2009-06-17 15:46:13 -05001225
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001226 // Update next segment transition position. No harm to do it also for last segment as lpToneGen->mNextSegSmp won't be used any more
1227 lpToneGen->mNextSegSmp
Eric Laurentf3af7402009-05-05 00:49:01 -07001228 += (lpToneDesc->segments[lpToneGen->mCurSegment].duration * lpToneGen->mSamplingRate) / 1000;
David Krauseb6d90ca2009-06-17 15:46:13 -05001229
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001230 } else {
1231 // Inside a segment keep tone ON or OFF
Eric Laurentf3af7402009-05-05 00:49:01 -07001232 if (lpToneDesc->segments[lpToneGen->mCurSegment].waveFreq[0] == 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001233 lGenSmp = 0; // If odd segment, tone is currently OFF
1234 } else {
1235 lGenSmp = lReqSmp; // If event segment, tone is currently ON
1236 }
1237 }
David Krauseb6d90ca2009-06-17 15:46:13 -05001238
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001239 if (lGenSmp) {
1240 // If samples must be generated, call all active wave generators and acumulate waves in lpOut
Eric Laurentf3af7402009-05-05 00:49:01 -07001241 unsigned int lFreqIdx = 0;
1242 unsigned short lFrequency = lpToneDesc->segments[lpToneGen->mCurSegment].waveFreq[lFreqIdx];
David Krauseb6d90ca2009-06-17 15:46:13 -05001243
Eric Laurentf3af7402009-05-05 00:49:01 -07001244 while (lFrequency != 0) {
1245 WaveGenerator *lpWaveGen = lpToneGen->mWaveGens.valueFor(lFrequency);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001246 lpWaveGen->getSamples(lpOut, lGenSmp, lWaveCmd);
Eric Laurentf3af7402009-05-05 00:49:01 -07001247 lFrequency = lpToneDesc->segments[lpToneGen->mCurSegment].waveFreq[++lFreqIdx];
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001248 }
1249 }
David Krauseb6d90ca2009-06-17 15:46:13 -05001250
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001251 lNumSmp -= lReqSmp;
1252 lpOut += lReqSmp;
David Krauseb6d90ca2009-06-17 15:46:13 -05001253
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001254audioCallback_EndLoop:
David Krauseb6d90ca2009-06-17 15:46:13 -05001255
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001256 switch (lpToneGen->mState) {
1257 case TONE_RESTARTING:
1258 LOGV("Cbk restarting track\n");
1259 if (lpToneGen->prepareWave()) {
1260 lpToneGen->mState = TONE_STARTING;
Eric Laurent5964e732009-07-09 01:56:20 -07001261 // must reload lpToneDesc as prepareWave() may change mpToneDesc
1262 lpToneDesc = lpToneGen->mpToneDesc;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001263 } else {
1264 LOGW("Cbk restarting prepareWave() failed\n");
1265 lpToneGen->mState = TONE_IDLE;
1266 lpToneGen->mpAudioTrack->stop();
1267 // Force loop exit
1268 lNumSmp = 0;
1269 }
1270 lSignal = true;
1271 break;
1272 case TONE_STOPPING:
Eric Laurentaf141d52009-09-24 07:03:14 -07001273 LOGV("Cbk Stopping\n");
1274 lpToneGen->mState = TONE_STOPPED;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001275 // Force loop exit
1276 lNumSmp = 0;
1277 break;
Eric Laurentaf141d52009-09-24 07:03:14 -07001278 case TONE_STOPPED:
1279 lpToneGen->mState = TONE_INIT;
1280 LOGV("Cbk Stopped track\n");
1281 lpToneGen->mpAudioTrack->stop();
1282 // Force loop exit
1283 lNumSmp = 0;
1284 buffer->size = 0;
1285 lSignal = true;
1286 break;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001287 case TONE_STARTING:
1288 LOGV("Cbk starting track\n");
1289 lpToneGen->mState = TONE_PLAYING;
1290 lSignal = true;
1291 break;
Eric Laurentaf141d52009-09-24 07:03:14 -07001292 case TONE_PLAYING:
1293 break;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001294 default:
Eric Laurentaf141d52009-09-24 07:03:14 -07001295 // Force loop exit
1296 lNumSmp = 0;
1297 buffer->size = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001298 break;
1299 }
1300
1301 if (lSignal)
1302 lpToneGen->mWaitCbkCond.signal();
1303 lpToneGen->mLock.unlock();
1304 }
1305}
1306
1307
1308////////////////////////////////////////////////////////////////////////////////
1309//
1310// Method: ToneGenerator::prepareWave()
1311//
1312// Description: Prepare wave generators and reset tone sequencer state machine.
Eric Laurentf3af7402009-05-05 00:49:01 -07001313// mpNewToneDesc must have been initialized before calling this function.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001314// Input:
1315// none
1316//
1317// Output:
1318// returned value: true if wave generators have been created, false otherwise
1319//
1320////////////////////////////////////////////////////////////////////////////////
1321bool ToneGenerator::prepareWave() {
Eric Laurentf3af7402009-05-05 00:49:01 -07001322 unsigned int segmentIdx = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001323
1324 if (!mpNewToneDesc) {
1325 return false;
1326 }
Eric Laurentf3af7402009-05-05 00:49:01 -07001327
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001328 // Remove existing wave generators if any
1329 clearWaveGens();
1330
1331 mpToneDesc = mpNewToneDesc;
1332
Eric Laurent62443f52009-10-05 20:29:18 -07001333 if (mDurationMs == -1) {
1334 mMaxSmp = TONEGEN_INF;
1335 } else {
1336 if (mDurationMs > (int)(TONEGEN_INF / mSamplingRate)) {
1337 mMaxSmp = (mDurationMs / 1000) * mSamplingRate;
1338 } else {
1339 mMaxSmp = (mDurationMs * mSamplingRate) / 1000;
1340 }
1341 LOGV("prepareWave, duration limited to %d ms", mDurationMs);
1342 }
1343
Eric Laurentf3af7402009-05-05 00:49:01 -07001344 while (mpToneDesc->segments[segmentIdx].duration) {
1345 // Get total number of sine waves: needed to adapt sine wave gain.
1346 unsigned int lNumWaves = numWaves(segmentIdx);
1347 unsigned int freqIdx = 0;
1348 unsigned int frequency = mpToneDesc->segments[segmentIdx].waveFreq[freqIdx];
1349 while (frequency) {
1350 // Instantiate a wave generator if ot already done for this frequency
1351 if (mWaveGens.indexOfKey(frequency) == NAME_NOT_FOUND) {
1352 ToneGenerator::WaveGenerator *lpWaveGen =
1353 new ToneGenerator::WaveGenerator((unsigned short)mSamplingRate,
1354 frequency,
1355 TONEGEN_GAIN/lNumWaves);
1356 if (lpWaveGen == 0) {
1357 goto prepareWave_exit;
1358 }
1359 mWaveGens.add(frequency, lpWaveGen);
1360 }
1361 frequency = mpNewToneDesc->segments[segmentIdx].waveFreq[++freqIdx];
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001362 }
Eric Laurentf3af7402009-05-05 00:49:01 -07001363 segmentIdx++;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001364 }
1365
1366 // Initialize tone sequencer
1367 mTotalSmp = 0;
1368 mCurSegment = 0;
1369 mCurCount = 0;
David Krauseb6d90ca2009-06-17 15:46:13 -05001370 mLoopCounter = 0;
Eric Laurentf3af7402009-05-05 00:49:01 -07001371 if (mpToneDesc->segments[0].duration == TONEGEN_INF) {
1372 mNextSegSmp = TONEGEN_INF;
1373 } else{
1374 mNextSegSmp = (mpToneDesc->segments[0].duration * mSamplingRate) / 1000;
1375 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001376
1377 return true;
1378
1379prepareWave_exit:
1380
1381 clearWaveGens();
1382
1383 return false;
1384}
1385
1386
1387////////////////////////////////////////////////////////////////////////////////
1388//
1389// Method: ToneGenerator::numWaves()
1390//
Eric Laurentf3af7402009-05-05 00:49:01 -07001391// Description: Count number of sine waves needed to generate a tone segment (e.g 2 for DTMF).
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001392//
1393// Input:
Eric Laurentf3af7402009-05-05 00:49:01 -07001394// segmentIdx tone segment index
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001395//
1396// Output:
1397// returned value: nummber of sine waves
1398//
1399////////////////////////////////////////////////////////////////////////////////
Eric Laurentf3af7402009-05-05 00:49:01 -07001400unsigned int ToneGenerator::numWaves(unsigned int segmentIdx) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001401 unsigned int lCnt = 0;
1402
Eric Laurentf3af7402009-05-05 00:49:01 -07001403 if (mpToneDesc->segments[segmentIdx].duration) {
1404 while (mpToneDesc->segments[segmentIdx].waveFreq[lCnt]) {
1405 lCnt++;
1406 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001407 lCnt++;
1408 }
1409
1410 return lCnt;
1411}
1412
1413
1414////////////////////////////////////////////////////////////////////////////////
1415//
1416// Method: ToneGenerator::clearWaveGens()
1417//
1418// Description: Removes all wave generators.
1419//
1420// Input:
1421// none
1422//
1423// Output:
1424// none
1425//
1426////////////////////////////////////////////////////////////////////////////////
1427void ToneGenerator::clearWaveGens() {
1428 LOGV("Clearing mWaveGens:");
1429
Eric Laurentf3af7402009-05-05 00:49:01 -07001430 for (size_t lIdx = 0; lIdx < mWaveGens.size(); lIdx++) {
1431 delete mWaveGens.valueAt(lIdx);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001432 }
Eric Laurentf3af7402009-05-05 00:49:01 -07001433 mWaveGens.clear();
1434}
1435
1436////////////////////////////////////////////////////////////////////////////////
1437//
1438// Method: ToneGenerator::getToneForRegion()
1439//
1440// Description: Get correct ringtone type according to current region.
1441// The corrected ring tone type is the tone descriptor index in sToneDescriptors[].
1442//
1443// Input:
1444// none
1445//
1446// Output:
1447// none
1448//
1449////////////////////////////////////////////////////////////////////////////////
1450int ToneGenerator::getToneForRegion(int toneType) {
1451 int regionTone;
1452
1453 if (mRegion == CEPT || toneType < FIRST_SUP_TONE || toneType > LAST_SUP_TONE) {
1454 regionTone = toneType;
1455 } else {
1456 regionTone = sToneMappingTable[mRegion][toneType - FIRST_SUP_TONE];
1457 }
1458
1459 LOGV("getToneForRegion, tone %d, region %d, regionTone %d", toneType, mRegion, regionTone);
1460
1461 return regionTone;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001462}
1463
1464
1465////////////////////////////////////////////////////////////////////////////////
1466// WaveGenerator::WaveGenerator class Implementation
1467////////////////////////////////////////////////////////////////////////////////
1468
1469//---------------------------------- public methods ----------------------------
1470
1471////////////////////////////////////////////////////////////////////////////////
1472//
1473// Method: WaveGenerator::WaveGenerator()
1474//
1475// Description: Constructor.
1476//
1477// Input:
1478// samplingRate: Output sampling rate in Hz
1479// frequency: Frequency of the sine wave to generate in Hz
1480// volume: volume (0.0 to 1.0)
1481//
1482// Output:
1483// none
1484//
1485////////////////////////////////////////////////////////////////////////////////
1486ToneGenerator::WaveGenerator::WaveGenerator(unsigned short samplingRate,
1487 unsigned short frequency, float volume) {
1488 double d0;
1489 double F_div_Fs; // frequency / samplingRate
1490
1491 F_div_Fs = frequency / (double)samplingRate;
1492 d0 = - (float)GEN_AMP * sin(2 * M_PI * F_div_Fs);
1493 mS2_0 = (short)d0;
1494 mS1 = 0;
1495 mS2 = mS2_0;
1496
1497 mAmplitude_Q15 = (short)(32767. * 32767. * volume / GEN_AMP);
1498 // take some margin for amplitude fluctuation
1499 if (mAmplitude_Q15 > 32500)
1500 mAmplitude_Q15 = 32500;
1501
1502 d0 = 32768.0 * cos(2 * M_PI * F_div_Fs); // Q14*2*cos()
1503 if (d0 > 32767)
1504 d0 = 32767;
1505 mA1_Q14 = (short) d0;
1506
1507 LOGV("WaveGenerator init, mA1_Q14: %d, mS2_0: %d, mAmplitude_Q15: %d\n",
1508 mA1_Q14, mS2_0, mAmplitude_Q15);
1509}
1510
1511////////////////////////////////////////////////////////////////////////////////
1512//
1513// Method: WaveGenerator::~WaveGenerator()
1514//
1515// Description: Destructor.
1516//
1517// Input:
1518// none
1519//
1520// Output:
1521// none
1522//
1523////////////////////////////////////////////////////////////////////////////////
1524ToneGenerator::WaveGenerator::~WaveGenerator() {
1525}
1526
1527////////////////////////////////////////////////////////////////////////////////
1528//
1529// Method: WaveGenerator::getSamples()
1530//
1531// Description: Generates count samples of a sine wave and accumulates
1532// result in outBuffer.
1533//
1534// Input:
1535// outBuffer: Output buffer where to accumulate samples.
1536// count: number of samples to produce.
1537// command: special action requested (see enum gen_command).
1538//
1539// Output:
1540// none
1541//
1542////////////////////////////////////////////////////////////////////////////////
1543void ToneGenerator::WaveGenerator::getSamples(short *outBuffer,
1544 unsigned int count, unsigned int command) {
1545 long lS1, lS2;
1546 long lA1, lAmplitude;
1547 long Sample; // current sample
1548
1549 // init local
1550 if (command == WAVEGEN_START) {
1551 lS1 = (long)0;
1552 lS2 = (long)mS2_0;
1553 } else {
1554 lS1 = (long)mS1;
1555 lS2 = (long)mS2;
1556 }
1557 lA1 = (long)mA1_Q14;
1558 lAmplitude = (long)mAmplitude_Q15;
1559
1560 if (command == WAVEGEN_STOP) {
1561 lAmplitude <<= 16;
1562 if (count == 0) {
1563 return;
1564 }
1565 long dec = lAmplitude/count;
1566 // loop generation
1567 while (count--) {
1568 Sample = ((lA1 * lS1) >> S_Q14) - lS2;
1569 // shift delay
1570 lS2 = lS1;
1571 lS1 = Sample;
1572 Sample = ((lAmplitude>>16) * Sample) >> S_Q15;
1573 *(outBuffer++) += (short)Sample; // put result in buffer
1574 lAmplitude -= dec;
1575 }
1576 } else {
1577 // loop generation
1578 while (count--) {
1579 Sample = ((lA1 * lS1) >> S_Q14) - lS2;
1580 // shift delay
1581 lS2 = lS1;
1582 lS1 = Sample;
1583 Sample = (lAmplitude * Sample) >> S_Q15;
1584 *(outBuffer++) += (short)Sample; // put result in buffer
1585 }
1586 }
1587
1588 // save status
1589 mS1 = (short)lS1;
1590 mS2 = (short)lS2;
1591}
1592
1593} // end namespace android
1594