blob: 3729eb34226ffd26d03b96adb665e76bbc69bd24 [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>
24#include <sys/resource.h>
25#include <utils/RefBase.h>
26#include <utils/Timers.h>
Eric Laurentf3af7402009-05-05 00:49:01 -070027#include <cutils/properties.h>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080028#include "media/ToneGenerator.h"
29
Eric Laurentf3af7402009-05-05 00:49:01 -070030
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080031namespace android {
32
Eric Laurentf3af7402009-05-05 00:49:01 -070033
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080034// Descriptors for all available tones (See ToneGenerator::ToneDescriptor class declaration for details)
Eric Laurentf3af7402009-05-05 00:49:01 -070035const ToneGenerator::ToneDescriptor ToneGenerator::sToneDescriptors[] = {
David Krauseb6d90ca2009-06-17 15:46:13 -050036 { segments: {{ duration: ToneGenerator::TONEGEN_INF, waveFreq: { 1336, 941, 0 }, 0, 0},
37 { duration: 0 , waveFreq: { 0 }, 0, 0}},
Eric Laurentf3af7402009-05-05 00:49:01 -070038 repeatCnt: ToneGenerator::TONEGEN_INF,
39 repeatSegment: 0 }, // TONE_DTMF_0
David Krauseb6d90ca2009-06-17 15:46:13 -050040 { segments: { { duration: ToneGenerator::TONEGEN_INF, waveFreq: { 1209, 697, 0 }, 0, 0 },
41 { duration: 0 , waveFreq: { 0 }, 0, 0}},
Eric Laurentf3af7402009-05-05 00:49:01 -070042 repeatCnt: ToneGenerator::TONEGEN_INF,
43 repeatSegment: 0 }, // TONE_DTMF_1
David Krauseb6d90ca2009-06-17 15:46:13 -050044 { segments: { { duration: ToneGenerator::TONEGEN_INF, waveFreq: { 1336, 697, 0 }, 0, 0 },
45 { duration: 0 , waveFreq: { 0 }, 0, 0}},
Eric Laurentf3af7402009-05-05 00:49:01 -070046 repeatCnt: ToneGenerator::TONEGEN_INF,
47 repeatSegment: 0 }, // TONE_DTMF_2
David Krauseb6d90ca2009-06-17 15:46:13 -050048 { segments: { { duration: ToneGenerator::TONEGEN_INF, waveFreq: { 1477, 697, 0 }, 0, 0 },
49 { duration: 0 , waveFreq: { 0 }, 0, 0}},
Eric Laurentf3af7402009-05-05 00:49:01 -070050 repeatCnt: ToneGenerator::TONEGEN_INF,
51 repeatSegment: 0 }, // TONE_DTMF_3
David Krauseb6d90ca2009-06-17 15:46:13 -050052 { segments: { { duration: ToneGenerator::TONEGEN_INF, waveFreq: { 1209, 770, 0 }, 0, 0 },
53 { duration: 0 , waveFreq: { 0 }, 0, 0}},
Eric Laurentf3af7402009-05-05 00:49:01 -070054 repeatCnt: ToneGenerator::TONEGEN_INF,
55 repeatSegment: 0 }, // TONE_DTMF_4
David Krauseb6d90ca2009-06-17 15:46:13 -050056 { segments: { { duration: ToneGenerator::TONEGEN_INF, waveFreq: { 1336, 770, 0 }, 0, 0 },
57 { duration: 0 , waveFreq: { 0 }, 0, 0}},
Eric Laurentf3af7402009-05-05 00:49:01 -070058 repeatCnt: ToneGenerator::TONEGEN_INF,
59 repeatSegment: 0 }, // TONE_DTMF_5
David Krauseb6d90ca2009-06-17 15:46:13 -050060 { segments: { { duration: ToneGenerator::TONEGEN_INF, waveFreq: { 1477, 770, 0 }, 0, 0 },
61 { duration: 0 , waveFreq: { 0 }, 0, 0}},
Eric Laurentf3af7402009-05-05 00:49:01 -070062 repeatCnt: ToneGenerator::TONEGEN_INF,
63 repeatSegment: 0 }, // TONE_DTMF_6
David Krauseb6d90ca2009-06-17 15:46:13 -050064 { segments: { { duration: ToneGenerator::TONEGEN_INF, waveFreq: { 1209, 852, 0 }, 0, 0 },
65 { duration: 0 , waveFreq: { 0 }, 0, 0}},
Eric Laurentf3af7402009-05-05 00:49:01 -070066 repeatCnt: ToneGenerator::TONEGEN_INF,
67 repeatSegment: 0 }, // TONE_DTMF_7
David Krauseb6d90ca2009-06-17 15:46:13 -050068 { segments: { { duration: ToneGenerator::TONEGEN_INF, waveFreq: { 1336, 852, 0 }, 0, 0 },
69 { duration: 0 , waveFreq: { 0 }, 0, 0}},
Eric Laurentf3af7402009-05-05 00:49:01 -070070 repeatCnt: ToneGenerator::TONEGEN_INF,
71 repeatSegment: 0 }, // TONE_DTMF_8
David Krauseb6d90ca2009-06-17 15:46:13 -050072 { segments: { { duration: ToneGenerator::TONEGEN_INF, waveFreq: { 1477, 852, 0 }, 0, 0 },
73 { duration: 0 , waveFreq: { 0 }, 0, 0}},
Eric Laurentf3af7402009-05-05 00:49:01 -070074 repeatCnt: ToneGenerator::TONEGEN_INF,
75 repeatSegment: 0 }, // TONE_DTMF_9
David Krauseb6d90ca2009-06-17 15:46:13 -050076 { segments: { { duration: ToneGenerator::TONEGEN_INF, waveFreq: { 1209, 941, 0 }, 0, 0 },
77 { duration: 0 , waveFreq: { 0 }, 0, 0}},
Eric Laurentf3af7402009-05-05 00:49:01 -070078 repeatCnt: ToneGenerator::TONEGEN_INF,
79 repeatSegment: 0 }, // TONE_DTMF_S
David Krauseb6d90ca2009-06-17 15:46:13 -050080 { segments: { { duration: ToneGenerator::TONEGEN_INF, waveFreq: { 1477, 941, 0 }, 0, 0 },
81 { duration: 0 , waveFreq: { 0 }, 0, 0}},
Eric Laurentf3af7402009-05-05 00:49:01 -070082 repeatCnt: ToneGenerator::TONEGEN_INF,
83 repeatSegment: 0 }, // TONE_DTMF_P
David Krauseb6d90ca2009-06-17 15:46:13 -050084 { segments: { { duration: ToneGenerator::TONEGEN_INF, waveFreq: { 1633, 697, 0 }, 0, 0 },
85 { duration: 0 , waveFreq: { 0 }, 0, 0}},
Eric Laurentf3af7402009-05-05 00:49:01 -070086 repeatCnt: ToneGenerator::TONEGEN_INF,
87 repeatSegment: 0 }, // TONE_DTMF_A
David Krauseb6d90ca2009-06-17 15:46:13 -050088 { segments: { { duration: ToneGenerator::TONEGEN_INF, waveFreq: { 1633, 770, 0 }, 0, 0 },
89 { duration: 0 , waveFreq: { 0 }, 0, 0}},
Eric Laurentf3af7402009-05-05 00:49:01 -070090 repeatCnt: ToneGenerator::TONEGEN_INF,
91 repeatSegment: 0 }, // TONE_DTMF_B
David Krauseb6d90ca2009-06-17 15:46:13 -050092 { segments: { { duration: ToneGenerator::TONEGEN_INF, waveFreq: { 1633, 852, 0 }, 0, 0 },
93 { duration: 0 , waveFreq: { 0 }, 0, 0}},
Eric Laurentf3af7402009-05-05 00:49:01 -070094 repeatCnt: ToneGenerator::TONEGEN_INF,
95 repeatSegment: 0 }, // TONE_DTMF_C
David Krauseb6d90ca2009-06-17 15:46:13 -050096 { segments: { { duration: ToneGenerator::TONEGEN_INF, waveFreq: { 1633, 941, 0 }, 0, 0 },
97 { duration: 0 , waveFreq: { 0 }, 0, 0}},
Eric Laurentf3af7402009-05-05 00:49:01 -070098 repeatCnt: ToneGenerator::TONEGEN_INF,
99 repeatSegment: 0 }, // TONE_DTMF_D
David Krauseb6d90ca2009-06-17 15:46:13 -0500100 { segments: { { duration: ToneGenerator::TONEGEN_INF, waveFreq: { 425, 0 }, 0, 0 },
101 { duration: 0 , waveFreq: { 0 }, 0, 0}},
Eric Laurentf3af7402009-05-05 00:49:01 -0700102 repeatCnt: ToneGenerator::TONEGEN_INF,
103 repeatSegment: 0 }, // TONE_SUP_DIAL
David Krauseb6d90ca2009-06-17 15:46:13 -0500104 { segments: { { duration: 500 , waveFreq: { 425, 0 }, 0, 0},
105 { duration: 500, waveFreq: { 0 }, 0, 0},
106 { duration: 0 , waveFreq: { 0 }, 0, 0}},
Eric Laurentf3af7402009-05-05 00:49:01 -0700107 repeatCnt: ToneGenerator::TONEGEN_INF,
108 repeatSegment: 0 }, // TONE_SUP_BUSY
David Krauseb6d90ca2009-06-17 15:46:13 -0500109 { segments: { { duration: 200, waveFreq: { 425, 0 }, 0, 0 },
110 { duration: 200, waveFreq: { 0 }, 0, 0 },
111 { duration: 0 , waveFreq: { 0 }, 0, 0}},
Eric Laurentf3af7402009-05-05 00:49:01 -0700112 repeatCnt: ToneGenerator::TONEGEN_INF,
113 repeatSegment: 0 }, // TONE_SUP_CONGESTION
David Krauseb6d90ca2009-06-17 15:46:13 -0500114 { segments: { { duration: 200, waveFreq: { 425, 0 }, 0, 0 },
115 { duration: 0 , waveFreq: { 0 }, 0, 0}},
Eric Laurentf3af7402009-05-05 00:49:01 -0700116 repeatCnt: 0,
117 repeatSegment: 0 }, // TONE_SUP_RADIO_ACK
David Krauseb6d90ca2009-06-17 15:46:13 -0500118 { segments: { { duration: 200, waveFreq: { 425, 0 }, 0, 0},
119 { duration: 200, waveFreq: { 0 }, 0, 0},
120 { duration: 0 , waveFreq: { 0 }, 0, 0}},
Eric Laurentf3af7402009-05-05 00:49:01 -0700121 repeatCnt: 2,
122 repeatSegment: 0 }, // TONE_SUP_RADIO_NOTAVAIL
David Krauseb6d90ca2009-06-17 15:46:13 -0500123 { segments: { { duration: 330, waveFreq: { 950, 1400, 1800, 0 }, 0, 0},
124 { duration: 1000, waveFreq: { 0 }, 0, 0},
125 { duration: 0 , waveFreq: { 0 }, 0, 0}},
Eric Laurentf3af7402009-05-05 00:49:01 -0700126 repeatCnt: ToneGenerator::TONEGEN_INF,
127 repeatSegment: 0 }, // TONE_SUP_ERROR
David Krauseb6d90ca2009-06-17 15:46:13 -0500128 { segments: { { duration: 200, waveFreq: { 425, 0 }, 0, 0 },
129 { duration: 600, waveFreq: { 0 }, 0, 0 },
130 { duration: 200, waveFreq: { 425, 0 }, 0, 0 },
131 { duration: 3000, waveFreq: { 0 }, 0, 0 },
132 { duration: 0 , waveFreq: { 0 }, 0, 0}},
Eric Laurentf3af7402009-05-05 00:49:01 -0700133 repeatCnt: ToneGenerator::TONEGEN_INF,
134 repeatSegment: 0 }, // TONE_SUP_CALL_WAITING
David Krauseb6d90ca2009-06-17 15:46:13 -0500135 { segments: { { duration: 1000, waveFreq: { 425, 0 }, 0, 0 },
136 { duration: 4000, waveFreq: { 0 }, 0, 0 },
137 { duration: 0 , waveFreq: { 0 }, 0, 0}},
Eric Laurentf3af7402009-05-05 00:49:01 -0700138 repeatCnt: ToneGenerator::TONEGEN_INF,
139 repeatSegment: 0 }, // TONE_SUP_RINGTONE
David Krauseb6d90ca2009-06-17 15:46:13 -0500140 { segments: { { duration: 40, waveFreq: { 400, 1200, 0 }, 0, 0 },
141 { duration: 0 , waveFreq: { 0 }, 0, 0}},
Eric Laurentf3af7402009-05-05 00:49:01 -0700142 repeatCnt: 0,
143 repeatSegment: 0 }, // TONE_PROP_BEEP
David Krauseb6d90ca2009-06-17 15:46:13 -0500144 { segments: { { duration: 100, waveFreq: { 1200, 0 }, 0, 0 },
145 { duration: 100, waveFreq: { 0 }, 0, 0 },
146 { duration: 0 , waveFreq: { 0 }, 0, 0}},
Eric Laurentf3af7402009-05-05 00:49:01 -0700147 repeatCnt: 1,
148 repeatSegment: 0 }, // TONE_PROP_ACK
David Krauseb6d90ca2009-06-17 15:46:13 -0500149 { segments: { { duration: 400, waveFreq: { 300, 400, 500, 0 }, 0, 0 },
150 { duration: 0 , waveFreq: { 0 }, 0, 0}},
Eric Laurentf3af7402009-05-05 00:49:01 -0700151 repeatCnt: 0,
152 repeatSegment: 0 }, // TONE_PROP_NACK
David Krauseb6d90ca2009-06-17 15:46:13 -0500153 { segments: { { duration: 200, waveFreq: { 400, 1200, 0 }, 0, 0 },
154 { duration: 0 , waveFreq: { 0 }, 0, 0}},
Eric Laurentf3af7402009-05-05 00:49:01 -0700155 repeatCnt: 0,
156 repeatSegment: 0 }, // TONE_PROP_PROMPT
David Krauseb6d90ca2009-06-17 15:46:13 -0500157 { segments: { { duration: 40, waveFreq: { 400, 1200, 0 }, 0, 0 },
158 { duration: 200, waveFreq: { 0 }, 0, 0 },
159 { duration: 40, waveFreq: { 400, 1200, 0 }, 0, 0 },
160 { duration: 0 , waveFreq: { 0 }, 0, 0}},
Eric Laurentf3af7402009-05-05 00:49:01 -0700161 repeatCnt: 0,
162 repeatSegment: 0 }, // TONE_PROP_BEEP2
David Krauseb6d90ca2009-06-17 15:46:13 -0500163 { segments: { { duration: 250, waveFreq: { 440, 0 }, 0, 0 },
164 { duration: 250, waveFreq: { 620, 0 }, 0, 0 },
165 { duration: 0 , waveFreq: { 0 }, 0, 0 }},
Eric Laurentf3af7402009-05-05 00:49:01 -0700166 repeatCnt: ToneGenerator::TONEGEN_INF,
167 repeatSegment: 0 }, // TONE_SUP_INTERCEPT
David Krauseb6d90ca2009-06-17 15:46:13 -0500168 { segments: { { duration: 250, waveFreq: { 440, 0 }, 0, 0 },
169 { duration: 250, waveFreq: { 620, 0 }, 0, 0 },
170 { duration: 0 , waveFreq: { 0 }, 0, 0}},
Eric Laurentf3af7402009-05-05 00:49:01 -0700171 repeatCnt: 7,
172 repeatSegment: 0 }, // TONE_SUP_INTERCEPT_ABBREV
David Krauseb6d90ca2009-06-17 15:46:13 -0500173 { segments: { { duration: 250, waveFreq: { 480, 620, 0 }, 0, 0 },
174 { duration: 250, waveFreq: { 0 }, 0, 0 },
175 { duration: 0 , waveFreq: { 0 }, 0, 0}},
Eric Laurentf3af7402009-05-05 00:49:01 -0700176 repeatCnt: 7,
177 repeatSegment: 0 }, // TONE_SUP_CONGESTION_ABBREV
David Krauseb6d90ca2009-06-17 15:46:13 -0500178 { segments: { { duration: 100, waveFreq: { 350, 440, 0 }, 0, 0 },
179 { duration: 100, waveFreq: { 0 }, 0, 0 },
180 { duration: 0 , waveFreq: { 0 }, 0, 0}},
Eric Laurentf3af7402009-05-05 00:49:01 -0700181 repeatCnt: 2,
182 repeatSegment: 0 }, // TONE_SUP_CONFIRM
David Krauseb6d90ca2009-06-17 15:46:13 -0500183 { segments: { { duration: 100, waveFreq: { 480, 0 }, 0, 0 },
184 { duration: 100, waveFreq: { 0 }, 0, 0 },
185 { duration: 0 , waveFreq: { 0 }, 0, 0}},
Eric Laurentf3af7402009-05-05 00:49:01 -0700186 repeatCnt: 3,
187 repeatSegment: 0 }, // TONE_SUP_PIP
David Krauseb6d90ca2009-06-17 15:46:13 -0500188 { segments: {{ duration: ToneGenerator::TONEGEN_INF, waveFreq: { 425, 0 }, 0, 0},
189 { duration: 0 , waveFreq: { 0 }, 0, 0}},
190 repeatCnt: ToneGenerator::TONEGEN_INF,
191 repeatSegment: 0 }, // TONE_CDMA_DIAL_TONE_LITE
192 { segments: { { duration: 2000, waveFreq: { 440, 480, 0 }, 0, 0 },
193 { duration: 4000, waveFreq: { 0 }, 0, 0 },
194 { duration: 0 , waveFreq: { 0 }, 0, 0}},
195 repeatCnt: ToneGenerator::TONEGEN_INF,
196 repeatSegment: 0 }, // TONE_CDMA_NETWORK_USA_RINGBACK
197 { segments: { { duration: 250, waveFreq: { 440, 0 }, 0, 0 },
198 { duration: 250, waveFreq: { 620, 0 }, 0, 0 },
199 { duration: 0 , waveFreq: { 0 }, 0, 0}},
200 repeatCnt: ToneGenerator::TONEGEN_INF,
201 repeatSegment: 0 }, // TONE_CDMA_INTERCEPT
202 { segments: { { duration: 250, waveFreq: { 440, 0 }, 0, 0 },
203 { duration: 250, waveFreq: { 620, 0 }, 0, 0 },
204 { duration: 0 , waveFreq: { 0 }, 0, 0}},
205 repeatCnt: 0,
206 repeatSegment: 0 }, // TONE_CDMA_ABBR_INTERCEPT
207 { segments: { { duration: 250, waveFreq: { 480, 620, 0 }, 0, 0 },
208 { duration: 250, waveFreq: { 0 }, 0, 0 },
209 { duration: 0 , waveFreq: { 0 }, 0, 0}},
210 repeatCnt: ToneGenerator::TONEGEN_INF,
211 repeatSegment: 0 }, // TONE_CDMA_REORDER
212 { segments: { { duration: 250, waveFreq: { 480, 620, 0 }, 0, 0 },
213 { duration: 250, waveFreq: { 0 }, 0, 0 },
214 { duration: 0 , waveFreq: { 0 }, 0, 0}},
215 repeatCnt: 7,
216 repeatSegment: 0 }, // TONE_CDMA_ABBR_REORDER
217 { segments: { { duration: 500, waveFreq: { 480, 620, 0 }, 0, 0 },
218 { duration: 500, waveFreq: { 0 }, 0, 0 },
219 { duration: 0 , waveFreq: { 0 }, 0, 0}},
220 repeatCnt: ToneGenerator::TONEGEN_INF,
221 repeatSegment: 0 }, // TONE_CDMA_NETWORK_BUSY
222 { segments: { { duration: 100, waveFreq: { 350, 440, 0 }, 0, 0 },
223 { duration: 100, waveFreq: { 0 }, 0, 0 },
224 { duration: 0 , waveFreq: { 0 }, 0, 0}},
225 repeatCnt: 2,
226 repeatSegment: 0 }, // TONE_CDMA_CONFIRM
227 { segments: { { duration: 0, waveFreq: { 0 }, 0, 0 }},
228 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////////////////////////////////////////////////////////////////////////////////
801ToneGenerator::ToneGenerator(int streamType, float volume) {
802
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 }
811 mStreamType = streamType;
812 mVolume = volume;
813 mpAudioTrack = 0;
814 mpToneDesc = 0;
815 mpNewToneDesc = 0;
816 // Generate tone by chunks of 20 ms to keep cadencing precision
817 mProcessSize = (mSamplingRate * 20) / 1000;
818
Eric Laurentf3af7402009-05-05 00:49:01 -0700819 char value[PROPERTY_VALUE_MAX];
820 property_get("gsm.operator.iso-country", value, "");
821 if (strcmp(value,"us") == 0 ||
822 strcmp(value,"ca") == 0) {
823 mRegion = ANSI;
824 } else if (strcmp(value,"jp") == 0) {
825 mRegion = JAPAN;
826 } else {
827 mRegion = CEPT;
828 }
829
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800830 if (initAudioTrack()) {
831 LOGV("ToneGenerator INIT OK, time: %d\n", (unsigned int)(systemTime()/1000000));
832 } else {
833 LOGV("!!!ToneGenerator INIT FAILED!!!\n");
834 }
835}
836
837
838
839
840////////////////////////////////////////////////////////////////////////////////
841//
842// Method: ToneGenerator::~ToneGenerator()
843//
844// Description: Destructor. Stop sound playback and delete audio track if
845// needed and delete sine wave generators.
846//
847// Input:
848// none
849//
850// Output:
851// none
852//
853////////////////////////////////////////////////////////////////////////////////
854ToneGenerator::~ToneGenerator() {
855 LOGV("ToneGenerator destructor\n");
856
857 if (mpAudioTrack) {
858 stopTone();
859 LOGV("Delete Track: %p\n", mpAudioTrack);
860 delete mpAudioTrack;
861 }
862}
863
864////////////////////////////////////////////////////////////////////////////////
865//
866// Method: ToneGenerator::startTone()
867//
868// Description: Starts tone playback.
869//
870// Input:
Eric Laurent96c08a62009-09-07 08:38:38 -0700871// toneType: Type of tone generated (values in enum tone_type)
872// durationMs: The tone duration in milliseconds. If the tone is limited in time by definition,
873// the actual duration will be the minimum of durationMs and the defined tone duration.
874// Ommiting or setting durationMs to -1 does not limit tone duration.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800875//
876// Output:
877// none
878//
879////////////////////////////////////////////////////////////////////////////////
Eric Laurent96c08a62009-09-07 08:38:38 -0700880bool ToneGenerator::startTone(int toneType, int durationMs) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800881 bool lResult = false;
Eric Laurent62443f52009-10-05 20:29:18 -0700882 status_t lStatus;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800883
Dave Sparks4c922472009-05-07 09:26:06 -0700884 if ((toneType < 0) || (toneType >= NUM_TONES))
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800885 return lResult;
886
887 if (mState == TONE_IDLE) {
888 LOGV("startTone: try to re-init AudioTrack");
889 if (!initAudioTrack()) {
890 return lResult;
891 }
892 }
893
894 LOGV("startTone\n");
895
896 mLock.lock();
897
898 // Get descriptor for requested tone
Eric Laurentf3af7402009-05-05 00:49:01 -0700899 toneType = getToneForRegion(toneType);
900 mpNewToneDesc = &sToneDescriptors[toneType];
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800901
Eric Laurent62443f52009-10-05 20:29:18 -0700902 mDurationMs = durationMs;
903
904 if (mState == TONE_STOPPED) {
905 LOGV("Start waiting for previous tone to stop");
906 lStatus = mWaitCbkCond.waitRelative(mLock, seconds(1));
907 if (lStatus != NO_ERROR) {
908 LOGE("--- start wait for stop timed out, status %d", lStatus);
909 mState = TONE_IDLE;
910 return lResult;
Eric Laurent96c08a62009-09-07 08:38:38 -0700911 }
Eric Laurent96c08a62009-09-07 08:38:38 -0700912 }
913
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800914 if (mState == TONE_INIT) {
915 if (prepareWave()) {
916 LOGV("Immediate start, time %d\n", (unsigned int)(systemTime()/1000000));
917 lResult = true;
918 mState = TONE_STARTING;
919 mLock.unlock();
920 mpAudioTrack->start();
921 mLock.lock();
922 if (mState == TONE_STARTING) {
923 LOGV("Wait for start callback");
Eric Laurent62443f52009-10-05 20:29:18 -0700924 lStatus = mWaitCbkCond.waitRelative(mLock, seconds(1));
The Android Open Source Projectb2a3dd82009-03-09 11:52:12 -0700925 if (lStatus != NO_ERROR) {
926 LOGE("--- Immediate start timed out, status %d", lStatus);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800927 mState = TONE_IDLE;
928 lResult = false;
929 }
930 }
931 } else {
Eric Laurentc4e58c02009-08-11 01:26:35 -0700932 mState = TONE_IDLE;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800933 }
934 } else {
935 LOGV("Delayed start\n");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800936 mState = TONE_RESTARTING;
Eric Laurent62443f52009-10-05 20:29:18 -0700937 lStatus = mWaitCbkCond.waitRelative(mLock, seconds(1));
The Android Open Source Projectb2a3dd82009-03-09 11:52:12 -0700938 if (lStatus == NO_ERROR) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800939 if (mState != TONE_IDLE) {
940 lResult = true;
941 }
942 LOGV("cond received");
943 } else {
The Android Open Source Projectb2a3dd82009-03-09 11:52:12 -0700944 LOGE("--- Delayed start timed out, status %d", lStatus);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800945 mState = TONE_IDLE;
946 }
947 }
948 mLock.unlock();
949
950 LOGV_IF(lResult, "Tone started, time %d\n", (unsigned int)(systemTime()/1000000));
951 LOGW_IF(!lResult, "Tone start failed!!!, time %d\n", (unsigned int)(systemTime()/1000000));
952
953 return lResult;
954}
955
956////////////////////////////////////////////////////////////////////////////////
957//
958// Method: ToneGenerator::stopTone()
959//
960// Description: Stops tone playback.
961//
962// Input:
963// none
964//
965// Output:
966// none
967//
968////////////////////////////////////////////////////////////////////////////////
969void ToneGenerator::stopTone() {
970 LOGV("stopTone");
971
972 mLock.lock();
973 if (mState == TONE_PLAYING || mState == TONE_STARTING || mState == TONE_RESTARTING) {
974 mState = TONE_STOPPING;
975 LOGV("waiting cond");
976 status_t lStatus = mWaitCbkCond.waitRelative(mLock, seconds(1));
977 if (lStatus == NO_ERROR) {
978 LOGV("track stop complete, time %d", (unsigned int)(systemTime()/1000000));
979 } else {
980 LOGE("--- Stop timed out");
981 mState = TONE_IDLE;
982 mpAudioTrack->stop();
983 }
984 }
985
986 clearWaveGens();
987
988 mLock.unlock();
989}
990
991//---------------------------------- private methods ---------------------------
992
993
994
995
996////////////////////////////////////////////////////////////////////////////////
997//
998// Method: ToneGenerator::initAudioTrack()
999//
1000// Description: Allocates and configures AudioTrack used for PCM output.
1001//
1002// Input:
1003// none
1004//
1005// Output:
1006// none
1007//
1008////////////////////////////////////////////////////////////////////////////////
1009bool ToneGenerator::initAudioTrack() {
1010
1011 if (mpAudioTrack) {
1012 delete mpAudioTrack;
1013 mpAudioTrack = 0;
1014 }
1015
1016 // Open audio track in mono, PCM 16bit, default sampling rate, default buffer size
1017 mpAudioTrack
Eric Laurenta553c252009-07-17 12:17:14 -07001018 = new AudioTrack(mStreamType, 0, AudioSystem::PCM_16_BIT, AudioSystem::CHANNEL_OUT_MONO, 0, 0, audioCallback, this, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001019
1020 if (mpAudioTrack == 0) {
1021 LOGE("AudioTrack allocation failed");
1022 goto initAudioTrack_exit;
1023 }
1024 LOGV("Create Track: %p\n", mpAudioTrack);
1025
1026 if (mpAudioTrack->initCheck() != NO_ERROR) {
1027 LOGE("AudioTrack->initCheck failed");
1028 goto initAudioTrack_exit;
1029 }
1030
1031 mpAudioTrack->setVolume(mVolume, mVolume);
1032
1033 mState = TONE_INIT;
1034
1035 return true;
1036
1037initAudioTrack_exit:
1038
1039 // Cleanup
1040 if (mpAudioTrack) {
1041 LOGV("Delete Track I: %p\n", mpAudioTrack);
1042 delete mpAudioTrack;
1043 mpAudioTrack = 0;
1044 }
1045
1046 return false;
1047}
1048
1049
1050////////////////////////////////////////////////////////////////////////////////
1051//
1052// Method: ToneGenerator::audioCallback()
1053//
1054// Description: AudioTrack callback implementation. Generates a block of
1055// PCM samples
1056// and manages tone generator sequencer: tones pulses, tone duration...
1057//
1058// Input:
1059// user reference (pointer to our ToneGenerator)
1060// info audio buffer descriptor
1061//
1062// Output:
1063// returned value: always true.
1064//
1065////////////////////////////////////////////////////////////////////////////////
1066void ToneGenerator::audioCallback(int event, void* user, void *info) {
David Krauseb6d90ca2009-06-17 15:46:13 -05001067
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001068 if (event != AudioTrack::EVENT_MORE_DATA) return;
David Krauseb6d90ca2009-06-17 15:46:13 -05001069
Eric Laurentaf141d52009-09-24 07:03:14 -07001070 AudioTrack::Buffer *buffer = static_cast<AudioTrack::Buffer *>(info);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001071 ToneGenerator *lpToneGen = static_cast<ToneGenerator *>(user);
1072 short *lpOut = buffer->i16;
1073 unsigned int lNumSmp = buffer->size/sizeof(short);
Eric Laurentf3af7402009-05-05 00:49:01 -07001074 const ToneDescriptor *lpToneDesc = lpToneGen->mpToneDesc;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001075
1076 if (buffer->size == 0) return;
1077
1078
1079 // Clear output buffer: WaveGenerator accumulates into lpOut buffer
1080 memset(lpOut, 0, buffer->size);
1081
1082 while (lNumSmp) {
1083 unsigned int lReqSmp = lNumSmp < lpToneGen->mProcessSize*2 ? lNumSmp : lpToneGen->mProcessSize;
1084 unsigned int lGenSmp;
1085 unsigned int lWaveCmd = WaveGenerator::WAVEGEN_CONT;
1086 bool lSignal = false;
David Krauseb6d90ca2009-06-17 15:46:13 -05001087
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001088 lpToneGen->mLock.lock();
1089
1090 // Update pcm frame count and end time (current time at the end of this process)
1091 lpToneGen->mTotalSmp += lReqSmp;
David Krauseb6d90ca2009-06-17 15:46:13 -05001092
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001093 // Update tone gen state machine and select wave gen command
1094 switch (lpToneGen->mState) {
1095 case TONE_PLAYING:
1096 lWaveCmd = WaveGenerator::WAVEGEN_CONT;
1097 break;
1098 case TONE_STARTING:
1099 LOGV("Starting Cbk");
David Krauseb6d90ca2009-06-17 15:46:13 -05001100
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001101 lWaveCmd = WaveGenerator::WAVEGEN_START;
1102 break;
1103 case TONE_STOPPING:
1104 case TONE_RESTARTING:
1105 LOGV("Stop/restart Cbk");
David Krauseb6d90ca2009-06-17 15:46:13 -05001106
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001107 lWaveCmd = WaveGenerator::WAVEGEN_STOP;
1108 lpToneGen->mNextSegSmp = TONEGEN_INF; // forced to skip state machine management below
1109 break;
Eric Laurentaf141d52009-09-24 07:03:14 -07001110 case TONE_STOPPED:
1111 LOGV("Stopped Cbk");
1112 goto audioCallback_EndLoop;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001113 default:
1114 LOGV("Extra Cbk");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001115 goto audioCallback_EndLoop;
1116 }
David Krauseb6d90ca2009-06-17 15:46:13 -05001117
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001118 // Exit if tone sequence is over
Eric Laurent96c08a62009-09-07 08:38:38 -07001119 if (lpToneDesc->segments[lpToneGen->mCurSegment].duration == 0 ||
1120 lpToneGen->mTotalSmp > lpToneGen->mMaxSmp) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001121 if (lpToneGen->mState == TONE_PLAYING) {
David Krauseb6d90ca2009-06-17 15:46:13 -05001122 lpToneGen->mState = TONE_STOPPING;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001123 }
Eric Laurent96c08a62009-09-07 08:38:38 -07001124 if (lpToneDesc->segments[lpToneGen->mCurSegment].duration == 0) {
1125 goto audioCallback_EndLoop;
1126 }
Eric Laurentaf141d52009-09-24 07:03:14 -07001127 // fade out before stopping if maximum duration reached
Eric Laurent96c08a62009-09-07 08:38:38 -07001128 lWaveCmd = WaveGenerator::WAVEGEN_STOP;
1129 lpToneGen->mNextSegSmp = TONEGEN_INF; // forced to skip state machine management below
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001130 }
David Krauseb6d90ca2009-06-17 15:46:13 -05001131
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001132 if (lpToneGen->mTotalSmp > lpToneGen->mNextSegSmp) {
1133 // Time to go to next sequence segment
David Krauseb6d90ca2009-06-17 15:46:13 -05001134
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001135 LOGV("End Segment, time: %d\n", (unsigned int)(systemTime()/1000000));
David Krauseb6d90ca2009-06-17 15:46:13 -05001136
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001137 lGenSmp = lReqSmp;
Eric Laurentf3af7402009-05-05 00:49:01 -07001138
1139 // If segment, ON -> OFF transition : ramp volume down
1140 if (lpToneDesc->segments[lpToneGen->mCurSegment].waveFreq[0] != 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001141 lWaveCmd = WaveGenerator::WAVEGEN_STOP;
Eric Laurentf3af7402009-05-05 00:49:01 -07001142 unsigned int lFreqIdx = 0;
1143 unsigned short lFrequency = lpToneDesc->segments[lpToneGen->mCurSegment].waveFreq[lFreqIdx];
1144
1145 while (lFrequency != 0) {
1146 WaveGenerator *lpWaveGen = lpToneGen->mWaveGens.valueFor(lFrequency);
1147 lpWaveGen->getSamples(lpOut, lGenSmp, lWaveCmd);
1148 lFrequency = lpToneDesc->segments[lpToneGen->mCurSegment].waveFreq[++lFreqIdx];
1149 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001150 LOGV("ON->OFF, lGenSmp: %d, lReqSmp: %d\n", lGenSmp, lReqSmp);
1151 }
Eric Laurentf3af7402009-05-05 00:49:01 -07001152
David Krauseb6d90ca2009-06-17 15:46:13 -05001153 // check if we need to loop and loop for the reqd times
1154 if (lpToneDesc->segments[lpToneGen->mCurSegment].loopCnt) {
1155 if (lpToneGen->mLoopCounter < lpToneDesc->segments[lpToneGen->mCurSegment].loopCnt) {
1156 LOGV ("in if loop loopCnt(%d) loopctr(%d), CurSeg(%d) \n",
1157 lpToneDesc->segments[lpToneGen->mCurSegment].loopCnt,
1158 lpToneGen->mLoopCounter,
1159 lpToneGen->mCurSegment);
1160 lpToneGen->mCurSegment = lpToneDesc->segments[lpToneGen->mCurSegment].loopIndx;
1161 ++lpToneGen->mLoopCounter;
1162 } else {
1163 // completed loop. go to next segment
1164 lpToneGen->mLoopCounter = 0;
1165 lpToneGen->mCurSegment++;
1166 LOGV ("in else loop loopCnt(%d) loopctr(%d), CurSeg(%d) \n",
1167 lpToneDesc->segments[lpToneGen->mCurSegment].loopCnt,
1168 lpToneGen->mLoopCounter,
1169 lpToneGen->mCurSegment);
1170 }
1171 } else {
1172 lpToneGen->mCurSegment++;
1173 LOGV ("Goto next seg loopCnt(%d) loopctr(%d), CurSeg(%d) \n",
1174 lpToneDesc->segments[lpToneGen->mCurSegment].loopCnt,
1175 lpToneGen->mLoopCounter,
1176 lpToneGen->mCurSegment);
1177
1178 }
Eric Laurentf3af7402009-05-05 00:49:01 -07001179
1180 // Handle loop if last segment reached
1181 if (lpToneDesc->segments[lpToneGen->mCurSegment].duration == 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001182 LOGV("Last Seg: %d\n", lpToneGen->mCurSegment);
David Krauseb6d90ca2009-06-17 15:46:13 -05001183
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001184 // Pre increment loop count and restart if total count not reached. Stop sequence otherwise
Eric Laurentf3af7402009-05-05 00:49:01 -07001185 if (++lpToneGen->mCurCount <= lpToneDesc->repeatCnt) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001186 LOGV("Repeating Count: %d\n", lpToneGen->mCurCount);
David Krauseb6d90ca2009-06-17 15:46:13 -05001187
Eric Laurentf3af7402009-05-05 00:49:01 -07001188 lpToneGen->mCurSegment = lpToneDesc->repeatSegment;
1189 if (lpToneDesc->segments[lpToneDesc->repeatSegment].waveFreq[0] != 0) {
1190 lWaveCmd = WaveGenerator::WAVEGEN_START;
1191 }
David Krauseb6d90ca2009-06-17 15:46:13 -05001192
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001193 LOGV("New segment %d, Next Time: %d\n", lpToneGen->mCurSegment,
1194 (lpToneGen->mNextSegSmp*1000)/lpToneGen->mSamplingRate);
David Krauseb6d90ca2009-06-17 15:46:13 -05001195
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001196 } else {
Eric Laurentf3af7402009-05-05 00:49:01 -07001197 lGenSmp = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001198 LOGV("End repeat, time: %d\n", (unsigned int)(systemTime()/1000000));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001199 }
1200 } else {
1201 LOGV("New segment %d, Next Time: %d\n", lpToneGen->mCurSegment,
1202 (lpToneGen->mNextSegSmp*1000)/lpToneGen->mSamplingRate);
Eric Laurentf3af7402009-05-05 00:49:01 -07001203 if (lpToneDesc->segments[lpToneGen->mCurSegment].waveFreq[0] != 0) {
1204 // If next segment is not silent, OFF -> ON transition : reset wave generator
1205 lWaveCmd = WaveGenerator::WAVEGEN_START;
1206
1207 LOGV("OFF->ON, lGenSmp: %d, lReqSmp: %d\n", lGenSmp, lReqSmp);
1208 } else {
1209 lGenSmp = 0;
1210 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001211 }
David Krauseb6d90ca2009-06-17 15:46:13 -05001212
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001213 // Update next segment transition position. No harm to do it also for last segment as lpToneGen->mNextSegSmp won't be used any more
1214 lpToneGen->mNextSegSmp
Eric Laurentf3af7402009-05-05 00:49:01 -07001215 += (lpToneDesc->segments[lpToneGen->mCurSegment].duration * lpToneGen->mSamplingRate) / 1000;
David Krauseb6d90ca2009-06-17 15:46:13 -05001216
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001217 } else {
1218 // Inside a segment keep tone ON or OFF
Eric Laurentf3af7402009-05-05 00:49:01 -07001219 if (lpToneDesc->segments[lpToneGen->mCurSegment].waveFreq[0] == 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001220 lGenSmp = 0; // If odd segment, tone is currently OFF
1221 } else {
1222 lGenSmp = lReqSmp; // If event segment, tone is currently ON
1223 }
1224 }
David Krauseb6d90ca2009-06-17 15:46:13 -05001225
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001226 if (lGenSmp) {
1227 // If samples must be generated, call all active wave generators and acumulate waves in lpOut
Eric Laurentf3af7402009-05-05 00:49:01 -07001228 unsigned int lFreqIdx = 0;
1229 unsigned short lFrequency = lpToneDesc->segments[lpToneGen->mCurSegment].waveFreq[lFreqIdx];
David Krauseb6d90ca2009-06-17 15:46:13 -05001230
Eric Laurentf3af7402009-05-05 00:49:01 -07001231 while (lFrequency != 0) {
1232 WaveGenerator *lpWaveGen = lpToneGen->mWaveGens.valueFor(lFrequency);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001233 lpWaveGen->getSamples(lpOut, lGenSmp, lWaveCmd);
Eric Laurentf3af7402009-05-05 00:49:01 -07001234 lFrequency = lpToneDesc->segments[lpToneGen->mCurSegment].waveFreq[++lFreqIdx];
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001235 }
1236 }
David Krauseb6d90ca2009-06-17 15:46:13 -05001237
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001238 lNumSmp -= lReqSmp;
1239 lpOut += lReqSmp;
David Krauseb6d90ca2009-06-17 15:46:13 -05001240
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001241audioCallback_EndLoop:
David Krauseb6d90ca2009-06-17 15:46:13 -05001242
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001243 switch (lpToneGen->mState) {
1244 case TONE_RESTARTING:
1245 LOGV("Cbk restarting track\n");
1246 if (lpToneGen->prepareWave()) {
1247 lpToneGen->mState = TONE_STARTING;
Eric Laurent5964e732009-07-09 01:56:20 -07001248 // must reload lpToneDesc as prepareWave() may change mpToneDesc
1249 lpToneDesc = lpToneGen->mpToneDesc;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001250 } else {
1251 LOGW("Cbk restarting prepareWave() failed\n");
1252 lpToneGen->mState = TONE_IDLE;
1253 lpToneGen->mpAudioTrack->stop();
1254 // Force loop exit
1255 lNumSmp = 0;
1256 }
1257 lSignal = true;
1258 break;
1259 case TONE_STOPPING:
Eric Laurentaf141d52009-09-24 07:03:14 -07001260 LOGV("Cbk Stopping\n");
1261 lpToneGen->mState = TONE_STOPPED;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001262 // Force loop exit
1263 lNumSmp = 0;
1264 break;
Eric Laurentaf141d52009-09-24 07:03:14 -07001265 case TONE_STOPPED:
1266 lpToneGen->mState = TONE_INIT;
1267 LOGV("Cbk Stopped track\n");
1268 lpToneGen->mpAudioTrack->stop();
1269 // Force loop exit
1270 lNumSmp = 0;
1271 buffer->size = 0;
1272 lSignal = true;
1273 break;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001274 case TONE_STARTING:
1275 LOGV("Cbk starting track\n");
1276 lpToneGen->mState = TONE_PLAYING;
1277 lSignal = true;
1278 break;
Eric Laurentaf141d52009-09-24 07:03:14 -07001279 case TONE_PLAYING:
1280 break;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001281 default:
Eric Laurentaf141d52009-09-24 07:03:14 -07001282 // Force loop exit
1283 lNumSmp = 0;
1284 buffer->size = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001285 break;
1286 }
1287
1288 if (lSignal)
1289 lpToneGen->mWaitCbkCond.signal();
1290 lpToneGen->mLock.unlock();
1291 }
1292}
1293
1294
1295////////////////////////////////////////////////////////////////////////////////
1296//
1297// Method: ToneGenerator::prepareWave()
1298//
1299// Description: Prepare wave generators and reset tone sequencer state machine.
Eric Laurentf3af7402009-05-05 00:49:01 -07001300// mpNewToneDesc must have been initialized before calling this function.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001301// Input:
1302// none
1303//
1304// Output:
1305// returned value: true if wave generators have been created, false otherwise
1306//
1307////////////////////////////////////////////////////////////////////////////////
1308bool ToneGenerator::prepareWave() {
Eric Laurentf3af7402009-05-05 00:49:01 -07001309 unsigned int segmentIdx = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001310
1311 if (!mpNewToneDesc) {
1312 return false;
1313 }
Eric Laurentf3af7402009-05-05 00:49:01 -07001314
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001315 // Remove existing wave generators if any
1316 clearWaveGens();
1317
1318 mpToneDesc = mpNewToneDesc;
1319
Eric Laurent62443f52009-10-05 20:29:18 -07001320 if (mDurationMs == -1) {
1321 mMaxSmp = TONEGEN_INF;
1322 } else {
1323 if (mDurationMs > (int)(TONEGEN_INF / mSamplingRate)) {
1324 mMaxSmp = (mDurationMs / 1000) * mSamplingRate;
1325 } else {
1326 mMaxSmp = (mDurationMs * mSamplingRate) / 1000;
1327 }
1328 LOGV("prepareWave, duration limited to %d ms", mDurationMs);
1329 }
1330
Eric Laurentf3af7402009-05-05 00:49:01 -07001331 while (mpToneDesc->segments[segmentIdx].duration) {
1332 // Get total number of sine waves: needed to adapt sine wave gain.
1333 unsigned int lNumWaves = numWaves(segmentIdx);
1334 unsigned int freqIdx = 0;
1335 unsigned int frequency = mpToneDesc->segments[segmentIdx].waveFreq[freqIdx];
1336 while (frequency) {
1337 // Instantiate a wave generator if ot already done for this frequency
1338 if (mWaveGens.indexOfKey(frequency) == NAME_NOT_FOUND) {
1339 ToneGenerator::WaveGenerator *lpWaveGen =
1340 new ToneGenerator::WaveGenerator((unsigned short)mSamplingRate,
1341 frequency,
1342 TONEGEN_GAIN/lNumWaves);
1343 if (lpWaveGen == 0) {
1344 goto prepareWave_exit;
1345 }
1346 mWaveGens.add(frequency, lpWaveGen);
1347 }
1348 frequency = mpNewToneDesc->segments[segmentIdx].waveFreq[++freqIdx];
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001349 }
Eric Laurentf3af7402009-05-05 00:49:01 -07001350 segmentIdx++;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001351 }
1352
1353 // Initialize tone sequencer
1354 mTotalSmp = 0;
1355 mCurSegment = 0;
1356 mCurCount = 0;
David Krauseb6d90ca2009-06-17 15:46:13 -05001357 mLoopCounter = 0;
Eric Laurentf3af7402009-05-05 00:49:01 -07001358 if (mpToneDesc->segments[0].duration == TONEGEN_INF) {
1359 mNextSegSmp = TONEGEN_INF;
1360 } else{
1361 mNextSegSmp = (mpToneDesc->segments[0].duration * mSamplingRate) / 1000;
1362 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001363
1364 return true;
1365
1366prepareWave_exit:
1367
1368 clearWaveGens();
1369
1370 return false;
1371}
1372
1373
1374////////////////////////////////////////////////////////////////////////////////
1375//
1376// Method: ToneGenerator::numWaves()
1377//
Eric Laurentf3af7402009-05-05 00:49:01 -07001378// 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 -08001379//
1380// Input:
Eric Laurentf3af7402009-05-05 00:49:01 -07001381// segmentIdx tone segment index
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001382//
1383// Output:
1384// returned value: nummber of sine waves
1385//
1386////////////////////////////////////////////////////////////////////////////////
Eric Laurentf3af7402009-05-05 00:49:01 -07001387unsigned int ToneGenerator::numWaves(unsigned int segmentIdx) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001388 unsigned int lCnt = 0;
1389
Eric Laurentf3af7402009-05-05 00:49:01 -07001390 if (mpToneDesc->segments[segmentIdx].duration) {
1391 while (mpToneDesc->segments[segmentIdx].waveFreq[lCnt]) {
1392 lCnt++;
1393 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001394 lCnt++;
1395 }
1396
1397 return lCnt;
1398}
1399
1400
1401////////////////////////////////////////////////////////////////////////////////
1402//
1403// Method: ToneGenerator::clearWaveGens()
1404//
1405// Description: Removes all wave generators.
1406//
1407// Input:
1408// none
1409//
1410// Output:
1411// none
1412//
1413////////////////////////////////////////////////////////////////////////////////
1414void ToneGenerator::clearWaveGens() {
1415 LOGV("Clearing mWaveGens:");
1416
Eric Laurentf3af7402009-05-05 00:49:01 -07001417 for (size_t lIdx = 0; lIdx < mWaveGens.size(); lIdx++) {
1418 delete mWaveGens.valueAt(lIdx);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001419 }
Eric Laurentf3af7402009-05-05 00:49:01 -07001420 mWaveGens.clear();
1421}
1422
1423////////////////////////////////////////////////////////////////////////////////
1424//
1425// Method: ToneGenerator::getToneForRegion()
1426//
1427// Description: Get correct ringtone type according to current region.
1428// The corrected ring tone type is the tone descriptor index in sToneDescriptors[].
1429//
1430// Input:
1431// none
1432//
1433// Output:
1434// none
1435//
1436////////////////////////////////////////////////////////////////////////////////
1437int ToneGenerator::getToneForRegion(int toneType) {
1438 int regionTone;
1439
1440 if (mRegion == CEPT || toneType < FIRST_SUP_TONE || toneType > LAST_SUP_TONE) {
1441 regionTone = toneType;
1442 } else {
1443 regionTone = sToneMappingTable[mRegion][toneType - FIRST_SUP_TONE];
1444 }
1445
1446 LOGV("getToneForRegion, tone %d, region %d, regionTone %d", toneType, mRegion, regionTone);
1447
1448 return regionTone;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001449}
1450
1451
1452////////////////////////////////////////////////////////////////////////////////
1453// WaveGenerator::WaveGenerator class Implementation
1454////////////////////////////////////////////////////////////////////////////////
1455
1456//---------------------------------- public methods ----------------------------
1457
1458////////////////////////////////////////////////////////////////////////////////
1459//
1460// Method: WaveGenerator::WaveGenerator()
1461//
1462// Description: Constructor.
1463//
1464// Input:
1465// samplingRate: Output sampling rate in Hz
1466// frequency: Frequency of the sine wave to generate in Hz
1467// volume: volume (0.0 to 1.0)
1468//
1469// Output:
1470// none
1471//
1472////////////////////////////////////////////////////////////////////////////////
1473ToneGenerator::WaveGenerator::WaveGenerator(unsigned short samplingRate,
1474 unsigned short frequency, float volume) {
1475 double d0;
1476 double F_div_Fs; // frequency / samplingRate
1477
1478 F_div_Fs = frequency / (double)samplingRate;
1479 d0 = - (float)GEN_AMP * sin(2 * M_PI * F_div_Fs);
1480 mS2_0 = (short)d0;
1481 mS1 = 0;
1482 mS2 = mS2_0;
1483
1484 mAmplitude_Q15 = (short)(32767. * 32767. * volume / GEN_AMP);
1485 // take some margin for amplitude fluctuation
1486 if (mAmplitude_Q15 > 32500)
1487 mAmplitude_Q15 = 32500;
1488
1489 d0 = 32768.0 * cos(2 * M_PI * F_div_Fs); // Q14*2*cos()
1490 if (d0 > 32767)
1491 d0 = 32767;
1492 mA1_Q14 = (short) d0;
1493
1494 LOGV("WaveGenerator init, mA1_Q14: %d, mS2_0: %d, mAmplitude_Q15: %d\n",
1495 mA1_Q14, mS2_0, mAmplitude_Q15);
1496}
1497
1498////////////////////////////////////////////////////////////////////////////////
1499//
1500// Method: WaveGenerator::~WaveGenerator()
1501//
1502// Description: Destructor.
1503//
1504// Input:
1505// none
1506//
1507// Output:
1508// none
1509//
1510////////////////////////////////////////////////////////////////////////////////
1511ToneGenerator::WaveGenerator::~WaveGenerator() {
1512}
1513
1514////////////////////////////////////////////////////////////////////////////////
1515//
1516// Method: WaveGenerator::getSamples()
1517//
1518// Description: Generates count samples of a sine wave and accumulates
1519// result in outBuffer.
1520//
1521// Input:
1522// outBuffer: Output buffer where to accumulate samples.
1523// count: number of samples to produce.
1524// command: special action requested (see enum gen_command).
1525//
1526// Output:
1527// none
1528//
1529////////////////////////////////////////////////////////////////////////////////
1530void ToneGenerator::WaveGenerator::getSamples(short *outBuffer,
1531 unsigned int count, unsigned int command) {
1532 long lS1, lS2;
1533 long lA1, lAmplitude;
1534 long Sample; // current sample
1535
1536 // init local
1537 if (command == WAVEGEN_START) {
1538 lS1 = (long)0;
1539 lS2 = (long)mS2_0;
1540 } else {
1541 lS1 = (long)mS1;
1542 lS2 = (long)mS2;
1543 }
1544 lA1 = (long)mA1_Q14;
1545 lAmplitude = (long)mAmplitude_Q15;
1546
1547 if (command == WAVEGEN_STOP) {
1548 lAmplitude <<= 16;
1549 if (count == 0) {
1550 return;
1551 }
1552 long dec = lAmplitude/count;
1553 // loop generation
1554 while (count--) {
1555 Sample = ((lA1 * lS1) >> S_Q14) - lS2;
1556 // shift delay
1557 lS2 = lS1;
1558 lS1 = Sample;
1559 Sample = ((lAmplitude>>16) * Sample) >> S_Q15;
1560 *(outBuffer++) += (short)Sample; // put result in buffer
1561 lAmplitude -= dec;
1562 }
1563 } else {
1564 // loop generation
1565 while (count--) {
1566 Sample = ((lA1 * lS1) >> S_Q14) - lS2;
1567 // shift delay
1568 lS2 = lS1;
1569 lS1 = Sample;
1570 Sample = (lAmplitude * Sample) >> S_Q15;
1571 *(outBuffer++) += (short)Sample; // put result in buffer
1572 }
1573 }
1574
1575 // save status
1576 mS1 = (short)lS1;
1577 mS2 = (short)lS2;
1578}
1579
1580} // end namespace android
1581