blob: 91d0d00953382eddf5bc19514971053ec513527e [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");
Eric Laurentdd28d562009-10-23 04:46:30 -0700906 lStatus = mWaitCbkCond.waitRelative(mLock, seconds(3));
Eric Laurent62443f52009-10-05 20:29:18 -0700907 if (lStatus != NO_ERROR) {
908 LOGE("--- start wait for stop timed out, status %d", lStatus);
909 mState = TONE_IDLE;
Eric Laurentdd28d562009-10-23 04:46:30 -0700910 mLock.unlock();
Eric Laurent62443f52009-10-05 20:29:18 -0700911 return lResult;
Eric Laurent96c08a62009-09-07 08:38:38 -0700912 }
Eric Laurent96c08a62009-09-07 08:38:38 -0700913 }
914
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800915 if (mState == TONE_INIT) {
916 if (prepareWave()) {
917 LOGV("Immediate start, time %d\n", (unsigned int)(systemTime()/1000000));
918 lResult = true;
919 mState = TONE_STARTING;
920 mLock.unlock();
921 mpAudioTrack->start();
922 mLock.lock();
923 if (mState == TONE_STARTING) {
924 LOGV("Wait for start callback");
Eric Laurentdd28d562009-10-23 04:46:30 -0700925 lStatus = mWaitCbkCond.waitRelative(mLock, seconds(3));
The Android Open Source Projectb2a3dd82009-03-09 11:52:12 -0700926 if (lStatus != NO_ERROR) {
927 LOGE("--- Immediate start timed out, status %d", lStatus);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800928 mState = TONE_IDLE;
929 lResult = false;
930 }
931 }
932 } else {
Eric Laurentc4e58c02009-08-11 01:26:35 -0700933 mState = TONE_IDLE;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800934 }
935 } else {
936 LOGV("Delayed start\n");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800937 mState = TONE_RESTARTING;
Eric Laurentdd28d562009-10-23 04:46:30 -0700938 lStatus = mWaitCbkCond.waitRelative(mLock, seconds(3));
The Android Open Source Projectb2a3dd82009-03-09 11:52:12 -0700939 if (lStatus == NO_ERROR) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800940 if (mState != TONE_IDLE) {
941 lResult = true;
942 }
943 LOGV("cond received");
944 } else {
The Android Open Source Projectb2a3dd82009-03-09 11:52:12 -0700945 LOGE("--- Delayed start timed out, status %d", lStatus);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800946 mState = TONE_IDLE;
947 }
948 }
949 mLock.unlock();
950
951 LOGV_IF(lResult, "Tone started, time %d\n", (unsigned int)(systemTime()/1000000));
952 LOGW_IF(!lResult, "Tone start failed!!!, time %d\n", (unsigned int)(systemTime()/1000000));
953
954 return lResult;
955}
956
957////////////////////////////////////////////////////////////////////////////////
958//
959// Method: ToneGenerator::stopTone()
960//
961// Description: Stops tone playback.
962//
963// Input:
964// none
965//
966// Output:
967// none
968//
969////////////////////////////////////////////////////////////////////////////////
970void ToneGenerator::stopTone() {
971 LOGV("stopTone");
972
973 mLock.lock();
974 if (mState == TONE_PLAYING || mState == TONE_STARTING || mState == TONE_RESTARTING) {
975 mState = TONE_STOPPING;
976 LOGV("waiting cond");
Eric Laurentdd28d562009-10-23 04:46:30 -0700977 status_t lStatus = mWaitCbkCond.waitRelative(mLock, seconds(3));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800978 if (lStatus == NO_ERROR) {
979 LOGV("track stop complete, time %d", (unsigned int)(systemTime()/1000000));
980 } else {
981 LOGE("--- Stop timed out");
982 mState = TONE_IDLE;
983 mpAudioTrack->stop();
984 }
985 }
986
987 clearWaveGens();
988
989 mLock.unlock();
990}
991
992//---------------------------------- private methods ---------------------------
993
994
995
996
997////////////////////////////////////////////////////////////////////////////////
998//
999// Method: ToneGenerator::initAudioTrack()
1000//
1001// Description: Allocates and configures AudioTrack used for PCM output.
1002//
1003// Input:
1004// none
1005//
1006// Output:
1007// none
1008//
1009////////////////////////////////////////////////////////////////////////////////
1010bool ToneGenerator::initAudioTrack() {
1011
1012 if (mpAudioTrack) {
1013 delete mpAudioTrack;
1014 mpAudioTrack = 0;
1015 }
1016
1017 // Open audio track in mono, PCM 16bit, default sampling rate, default buffer size
1018 mpAudioTrack
Eric Laurenta553c252009-07-17 12:17:14 -07001019 = 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 -08001020
1021 if (mpAudioTrack == 0) {
1022 LOGE("AudioTrack allocation failed");
1023 goto initAudioTrack_exit;
1024 }
1025 LOGV("Create Track: %p\n", mpAudioTrack);
1026
1027 if (mpAudioTrack->initCheck() != NO_ERROR) {
1028 LOGE("AudioTrack->initCheck failed");
1029 goto initAudioTrack_exit;
1030 }
1031
1032 mpAudioTrack->setVolume(mVolume, mVolume);
1033
1034 mState = TONE_INIT;
1035
1036 return true;
1037
1038initAudioTrack_exit:
1039
1040 // Cleanup
1041 if (mpAudioTrack) {
1042 LOGV("Delete Track I: %p\n", mpAudioTrack);
1043 delete mpAudioTrack;
1044 mpAudioTrack = 0;
1045 }
1046
1047 return false;
1048}
1049
1050
1051////////////////////////////////////////////////////////////////////////////////
1052//
1053// Method: ToneGenerator::audioCallback()
1054//
1055// Description: AudioTrack callback implementation. Generates a block of
1056// PCM samples
1057// and manages tone generator sequencer: tones pulses, tone duration...
1058//
1059// Input:
1060// user reference (pointer to our ToneGenerator)
1061// info audio buffer descriptor
1062//
1063// Output:
1064// returned value: always true.
1065//
1066////////////////////////////////////////////////////////////////////////////////
1067void ToneGenerator::audioCallback(int event, void* user, void *info) {
David Krauseb6d90ca2009-06-17 15:46:13 -05001068
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001069 if (event != AudioTrack::EVENT_MORE_DATA) return;
David Krauseb6d90ca2009-06-17 15:46:13 -05001070
Eric Laurentaf141d52009-09-24 07:03:14 -07001071 AudioTrack::Buffer *buffer = static_cast<AudioTrack::Buffer *>(info);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001072 ToneGenerator *lpToneGen = static_cast<ToneGenerator *>(user);
1073 short *lpOut = buffer->i16;
1074 unsigned int lNumSmp = buffer->size/sizeof(short);
Eric Laurentf3af7402009-05-05 00:49:01 -07001075 const ToneDescriptor *lpToneDesc = lpToneGen->mpToneDesc;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001076
1077 if (buffer->size == 0) return;
1078
1079
1080 // Clear output buffer: WaveGenerator accumulates into lpOut buffer
1081 memset(lpOut, 0, buffer->size);
1082
1083 while (lNumSmp) {
1084 unsigned int lReqSmp = lNumSmp < lpToneGen->mProcessSize*2 ? lNumSmp : lpToneGen->mProcessSize;
1085 unsigned int lGenSmp;
1086 unsigned int lWaveCmd = WaveGenerator::WAVEGEN_CONT;
1087 bool lSignal = false;
David Krauseb6d90ca2009-06-17 15:46:13 -05001088
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001089 lpToneGen->mLock.lock();
1090
Eric Laurentdd28d562009-10-23 04:46:30 -07001091
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001092 // Update pcm frame count and end time (current time at the end of this process)
1093 lpToneGen->mTotalSmp += lReqSmp;
David Krauseb6d90ca2009-06-17 15:46:13 -05001094
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001095 // Update tone gen state machine and select wave gen command
1096 switch (lpToneGen->mState) {
1097 case TONE_PLAYING:
1098 lWaveCmd = WaveGenerator::WAVEGEN_CONT;
1099 break;
1100 case TONE_STARTING:
1101 LOGV("Starting Cbk");
David Krauseb6d90ca2009-06-17 15:46:13 -05001102
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001103 lWaveCmd = WaveGenerator::WAVEGEN_START;
1104 break;
1105 case TONE_STOPPING:
1106 case TONE_RESTARTING:
1107 LOGV("Stop/restart Cbk");
David Krauseb6d90ca2009-06-17 15:46:13 -05001108
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001109 lWaveCmd = WaveGenerator::WAVEGEN_STOP;
1110 lpToneGen->mNextSegSmp = TONEGEN_INF; // forced to skip state machine management below
1111 break;
Eric Laurentaf141d52009-09-24 07:03:14 -07001112 case TONE_STOPPED:
1113 LOGV("Stopped Cbk");
1114 goto audioCallback_EndLoop;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001115 default:
1116 LOGV("Extra Cbk");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001117 goto audioCallback_EndLoop;
1118 }
David Krauseb6d90ca2009-06-17 15:46:13 -05001119
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001120 // Exit if tone sequence is over
Eric Laurent96c08a62009-09-07 08:38:38 -07001121 if (lpToneDesc->segments[lpToneGen->mCurSegment].duration == 0 ||
1122 lpToneGen->mTotalSmp > lpToneGen->mMaxSmp) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001123 if (lpToneGen->mState == TONE_PLAYING) {
David Krauseb6d90ca2009-06-17 15:46:13 -05001124 lpToneGen->mState = TONE_STOPPING;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001125 }
Eric Laurent96c08a62009-09-07 08:38:38 -07001126 if (lpToneDesc->segments[lpToneGen->mCurSegment].duration == 0) {
1127 goto audioCallback_EndLoop;
1128 }
Eric Laurentaf141d52009-09-24 07:03:14 -07001129 // fade out before stopping if maximum duration reached
Eric Laurent96c08a62009-09-07 08:38:38 -07001130 lWaveCmd = WaveGenerator::WAVEGEN_STOP;
1131 lpToneGen->mNextSegSmp = TONEGEN_INF; // forced to skip state machine management below
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001132 }
David Krauseb6d90ca2009-06-17 15:46:13 -05001133
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001134 if (lpToneGen->mTotalSmp > lpToneGen->mNextSegSmp) {
1135 // Time to go to next sequence segment
David Krauseb6d90ca2009-06-17 15:46:13 -05001136
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001137 LOGV("End Segment, time: %d\n", (unsigned int)(systemTime()/1000000));
David Krauseb6d90ca2009-06-17 15:46:13 -05001138
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001139 lGenSmp = lReqSmp;
Eric Laurentf3af7402009-05-05 00:49:01 -07001140
1141 // If segment, ON -> OFF transition : ramp volume down
1142 if (lpToneDesc->segments[lpToneGen->mCurSegment].waveFreq[0] != 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001143 lWaveCmd = WaveGenerator::WAVEGEN_STOP;
Eric Laurentf3af7402009-05-05 00:49:01 -07001144 unsigned int lFreqIdx = 0;
1145 unsigned short lFrequency = lpToneDesc->segments[lpToneGen->mCurSegment].waveFreq[lFreqIdx];
1146
1147 while (lFrequency != 0) {
1148 WaveGenerator *lpWaveGen = lpToneGen->mWaveGens.valueFor(lFrequency);
1149 lpWaveGen->getSamples(lpOut, lGenSmp, lWaveCmd);
1150 lFrequency = lpToneDesc->segments[lpToneGen->mCurSegment].waveFreq[++lFreqIdx];
1151 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001152 LOGV("ON->OFF, lGenSmp: %d, lReqSmp: %d\n", lGenSmp, lReqSmp);
1153 }
Eric Laurentf3af7402009-05-05 00:49:01 -07001154
David Krauseb6d90ca2009-06-17 15:46:13 -05001155 // check if we need to loop and loop for the reqd times
1156 if (lpToneDesc->segments[lpToneGen->mCurSegment].loopCnt) {
1157 if (lpToneGen->mLoopCounter < lpToneDesc->segments[lpToneGen->mCurSegment].loopCnt) {
1158 LOGV ("in if loop loopCnt(%d) loopctr(%d), CurSeg(%d) \n",
1159 lpToneDesc->segments[lpToneGen->mCurSegment].loopCnt,
1160 lpToneGen->mLoopCounter,
1161 lpToneGen->mCurSegment);
1162 lpToneGen->mCurSegment = lpToneDesc->segments[lpToneGen->mCurSegment].loopIndx;
1163 ++lpToneGen->mLoopCounter;
1164 } else {
1165 // completed loop. go to next segment
1166 lpToneGen->mLoopCounter = 0;
1167 lpToneGen->mCurSegment++;
1168 LOGV ("in else loop loopCnt(%d) loopctr(%d), CurSeg(%d) \n",
1169 lpToneDesc->segments[lpToneGen->mCurSegment].loopCnt,
1170 lpToneGen->mLoopCounter,
1171 lpToneGen->mCurSegment);
1172 }
1173 } else {
1174 lpToneGen->mCurSegment++;
1175 LOGV ("Goto next seg loopCnt(%d) loopctr(%d), CurSeg(%d) \n",
1176 lpToneDesc->segments[lpToneGen->mCurSegment].loopCnt,
1177 lpToneGen->mLoopCounter,
1178 lpToneGen->mCurSegment);
1179
1180 }
Eric Laurentf3af7402009-05-05 00:49:01 -07001181
1182 // Handle loop if last segment reached
1183 if (lpToneDesc->segments[lpToneGen->mCurSegment].duration == 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001184 LOGV("Last Seg: %d\n", lpToneGen->mCurSegment);
David Krauseb6d90ca2009-06-17 15:46:13 -05001185
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001186 // Pre increment loop count and restart if total count not reached. Stop sequence otherwise
Eric Laurentf3af7402009-05-05 00:49:01 -07001187 if (++lpToneGen->mCurCount <= lpToneDesc->repeatCnt) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001188 LOGV("Repeating Count: %d\n", lpToneGen->mCurCount);
David Krauseb6d90ca2009-06-17 15:46:13 -05001189
Eric Laurentf3af7402009-05-05 00:49:01 -07001190 lpToneGen->mCurSegment = lpToneDesc->repeatSegment;
1191 if (lpToneDesc->segments[lpToneDesc->repeatSegment].waveFreq[0] != 0) {
1192 lWaveCmd = WaveGenerator::WAVEGEN_START;
1193 }
David Krauseb6d90ca2009-06-17 15:46:13 -05001194
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001195 LOGV("New segment %d, Next Time: %d\n", lpToneGen->mCurSegment,
1196 (lpToneGen->mNextSegSmp*1000)/lpToneGen->mSamplingRate);
David Krauseb6d90ca2009-06-17 15:46:13 -05001197
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001198 } else {
Eric Laurentf3af7402009-05-05 00:49:01 -07001199 lGenSmp = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001200 LOGV("End repeat, time: %d\n", (unsigned int)(systemTime()/1000000));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001201 }
1202 } else {
1203 LOGV("New segment %d, Next Time: %d\n", lpToneGen->mCurSegment,
1204 (lpToneGen->mNextSegSmp*1000)/lpToneGen->mSamplingRate);
Eric Laurentf3af7402009-05-05 00:49:01 -07001205 if (lpToneDesc->segments[lpToneGen->mCurSegment].waveFreq[0] != 0) {
1206 // If next segment is not silent, OFF -> ON transition : reset wave generator
1207 lWaveCmd = WaveGenerator::WAVEGEN_START;
1208
1209 LOGV("OFF->ON, lGenSmp: %d, lReqSmp: %d\n", lGenSmp, lReqSmp);
1210 } else {
1211 lGenSmp = 0;
1212 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001213 }
David Krauseb6d90ca2009-06-17 15:46:13 -05001214
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001215 // Update next segment transition position. No harm to do it also for last segment as lpToneGen->mNextSegSmp won't be used any more
1216 lpToneGen->mNextSegSmp
Eric Laurentf3af7402009-05-05 00:49:01 -07001217 += (lpToneDesc->segments[lpToneGen->mCurSegment].duration * lpToneGen->mSamplingRate) / 1000;
David Krauseb6d90ca2009-06-17 15:46:13 -05001218
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001219 } else {
1220 // Inside a segment keep tone ON or OFF
Eric Laurentf3af7402009-05-05 00:49:01 -07001221 if (lpToneDesc->segments[lpToneGen->mCurSegment].waveFreq[0] == 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001222 lGenSmp = 0; // If odd segment, tone is currently OFF
1223 } else {
1224 lGenSmp = lReqSmp; // If event segment, tone is currently ON
1225 }
1226 }
David Krauseb6d90ca2009-06-17 15:46:13 -05001227
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001228 if (lGenSmp) {
1229 // If samples must be generated, call all active wave generators and acumulate waves in lpOut
Eric Laurentf3af7402009-05-05 00:49:01 -07001230 unsigned int lFreqIdx = 0;
1231 unsigned short lFrequency = lpToneDesc->segments[lpToneGen->mCurSegment].waveFreq[lFreqIdx];
David Krauseb6d90ca2009-06-17 15:46:13 -05001232
Eric Laurentf3af7402009-05-05 00:49:01 -07001233 while (lFrequency != 0) {
1234 WaveGenerator *lpWaveGen = lpToneGen->mWaveGens.valueFor(lFrequency);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001235 lpWaveGen->getSamples(lpOut, lGenSmp, lWaveCmd);
Eric Laurentf3af7402009-05-05 00:49:01 -07001236 lFrequency = lpToneDesc->segments[lpToneGen->mCurSegment].waveFreq[++lFreqIdx];
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001237 }
1238 }
David Krauseb6d90ca2009-06-17 15:46:13 -05001239
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001240 lNumSmp -= lReqSmp;
1241 lpOut += lReqSmp;
David Krauseb6d90ca2009-06-17 15:46:13 -05001242
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001243audioCallback_EndLoop:
David Krauseb6d90ca2009-06-17 15:46:13 -05001244
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001245 switch (lpToneGen->mState) {
1246 case TONE_RESTARTING:
1247 LOGV("Cbk restarting track\n");
1248 if (lpToneGen->prepareWave()) {
1249 lpToneGen->mState = TONE_STARTING;
Eric Laurent5964e732009-07-09 01:56:20 -07001250 // must reload lpToneDesc as prepareWave() may change mpToneDesc
1251 lpToneDesc = lpToneGen->mpToneDesc;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001252 } else {
1253 LOGW("Cbk restarting prepareWave() failed\n");
1254 lpToneGen->mState = TONE_IDLE;
1255 lpToneGen->mpAudioTrack->stop();
1256 // Force loop exit
1257 lNumSmp = 0;
1258 }
1259 lSignal = true;
1260 break;
1261 case TONE_STOPPING:
Eric Laurentaf141d52009-09-24 07:03:14 -07001262 LOGV("Cbk Stopping\n");
1263 lpToneGen->mState = TONE_STOPPED;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001264 // Force loop exit
1265 lNumSmp = 0;
1266 break;
Eric Laurentaf141d52009-09-24 07:03:14 -07001267 case TONE_STOPPED:
1268 lpToneGen->mState = TONE_INIT;
1269 LOGV("Cbk Stopped track\n");
1270 lpToneGen->mpAudioTrack->stop();
1271 // Force loop exit
1272 lNumSmp = 0;
1273 buffer->size = 0;
1274 lSignal = true;
1275 break;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001276 case TONE_STARTING:
1277 LOGV("Cbk starting track\n");
1278 lpToneGen->mState = TONE_PLAYING;
1279 lSignal = true;
1280 break;
Eric Laurentaf141d52009-09-24 07:03:14 -07001281 case TONE_PLAYING:
1282 break;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001283 default:
Eric Laurentaf141d52009-09-24 07:03:14 -07001284 // Force loop exit
1285 lNumSmp = 0;
1286 buffer->size = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001287 break;
1288 }
1289
1290 if (lSignal)
1291 lpToneGen->mWaitCbkCond.signal();
1292 lpToneGen->mLock.unlock();
1293 }
1294}
1295
1296
1297////////////////////////////////////////////////////////////////////////////////
1298//
1299// Method: ToneGenerator::prepareWave()
1300//
1301// Description: Prepare wave generators and reset tone sequencer state machine.
Eric Laurentf3af7402009-05-05 00:49:01 -07001302// mpNewToneDesc must have been initialized before calling this function.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001303// Input:
1304// none
1305//
1306// Output:
1307// returned value: true if wave generators have been created, false otherwise
1308//
1309////////////////////////////////////////////////////////////////////////////////
1310bool ToneGenerator::prepareWave() {
Eric Laurentf3af7402009-05-05 00:49:01 -07001311 unsigned int segmentIdx = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001312
1313 if (!mpNewToneDesc) {
1314 return false;
1315 }
Eric Laurentf3af7402009-05-05 00:49:01 -07001316
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001317 // Remove existing wave generators if any
1318 clearWaveGens();
1319
1320 mpToneDesc = mpNewToneDesc;
1321
Eric Laurent62443f52009-10-05 20:29:18 -07001322 if (mDurationMs == -1) {
1323 mMaxSmp = TONEGEN_INF;
1324 } else {
1325 if (mDurationMs > (int)(TONEGEN_INF / mSamplingRate)) {
1326 mMaxSmp = (mDurationMs / 1000) * mSamplingRate;
1327 } else {
1328 mMaxSmp = (mDurationMs * mSamplingRate) / 1000;
1329 }
1330 LOGV("prepareWave, duration limited to %d ms", mDurationMs);
1331 }
1332
Eric Laurentf3af7402009-05-05 00:49:01 -07001333 while (mpToneDesc->segments[segmentIdx].duration) {
1334 // Get total number of sine waves: needed to adapt sine wave gain.
1335 unsigned int lNumWaves = numWaves(segmentIdx);
1336 unsigned int freqIdx = 0;
1337 unsigned int frequency = mpToneDesc->segments[segmentIdx].waveFreq[freqIdx];
1338 while (frequency) {
1339 // Instantiate a wave generator if ot already done for this frequency
1340 if (mWaveGens.indexOfKey(frequency) == NAME_NOT_FOUND) {
1341 ToneGenerator::WaveGenerator *lpWaveGen =
1342 new ToneGenerator::WaveGenerator((unsigned short)mSamplingRate,
1343 frequency,
1344 TONEGEN_GAIN/lNumWaves);
1345 if (lpWaveGen == 0) {
1346 goto prepareWave_exit;
1347 }
1348 mWaveGens.add(frequency, lpWaveGen);
1349 }
1350 frequency = mpNewToneDesc->segments[segmentIdx].waveFreq[++freqIdx];
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001351 }
Eric Laurentf3af7402009-05-05 00:49:01 -07001352 segmentIdx++;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001353 }
1354
1355 // Initialize tone sequencer
1356 mTotalSmp = 0;
1357 mCurSegment = 0;
1358 mCurCount = 0;
David Krauseb6d90ca2009-06-17 15:46:13 -05001359 mLoopCounter = 0;
Eric Laurentf3af7402009-05-05 00:49:01 -07001360 if (mpToneDesc->segments[0].duration == TONEGEN_INF) {
1361 mNextSegSmp = TONEGEN_INF;
1362 } else{
1363 mNextSegSmp = (mpToneDesc->segments[0].duration * mSamplingRate) / 1000;
1364 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001365
1366 return true;
1367
1368prepareWave_exit:
1369
1370 clearWaveGens();
1371
1372 return false;
1373}
1374
1375
1376////////////////////////////////////////////////////////////////////////////////
1377//
1378// Method: ToneGenerator::numWaves()
1379//
Eric Laurentf3af7402009-05-05 00:49:01 -07001380// 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 -08001381//
1382// Input:
Eric Laurentf3af7402009-05-05 00:49:01 -07001383// segmentIdx tone segment index
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001384//
1385// Output:
1386// returned value: nummber of sine waves
1387//
1388////////////////////////////////////////////////////////////////////////////////
Eric Laurentf3af7402009-05-05 00:49:01 -07001389unsigned int ToneGenerator::numWaves(unsigned int segmentIdx) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001390 unsigned int lCnt = 0;
1391
Eric Laurentf3af7402009-05-05 00:49:01 -07001392 if (mpToneDesc->segments[segmentIdx].duration) {
1393 while (mpToneDesc->segments[segmentIdx].waveFreq[lCnt]) {
1394 lCnt++;
1395 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001396 lCnt++;
1397 }
1398
1399 return lCnt;
1400}
1401
1402
1403////////////////////////////////////////////////////////////////////////////////
1404//
1405// Method: ToneGenerator::clearWaveGens()
1406//
1407// Description: Removes all wave generators.
1408//
1409// Input:
1410// none
1411//
1412// Output:
1413// none
1414//
1415////////////////////////////////////////////////////////////////////////////////
1416void ToneGenerator::clearWaveGens() {
1417 LOGV("Clearing mWaveGens:");
1418
Eric Laurentf3af7402009-05-05 00:49:01 -07001419 for (size_t lIdx = 0; lIdx < mWaveGens.size(); lIdx++) {
1420 delete mWaveGens.valueAt(lIdx);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001421 }
Eric Laurentf3af7402009-05-05 00:49:01 -07001422 mWaveGens.clear();
1423}
1424
1425////////////////////////////////////////////////////////////////////////////////
1426//
1427// Method: ToneGenerator::getToneForRegion()
1428//
1429// Description: Get correct ringtone type according to current region.
1430// The corrected ring tone type is the tone descriptor index in sToneDescriptors[].
1431//
1432// Input:
1433// none
1434//
1435// Output:
1436// none
1437//
1438////////////////////////////////////////////////////////////////////////////////
1439int ToneGenerator::getToneForRegion(int toneType) {
1440 int regionTone;
1441
1442 if (mRegion == CEPT || toneType < FIRST_SUP_TONE || toneType > LAST_SUP_TONE) {
1443 regionTone = toneType;
1444 } else {
1445 regionTone = sToneMappingTable[mRegion][toneType - FIRST_SUP_TONE];
1446 }
1447
1448 LOGV("getToneForRegion, tone %d, region %d, regionTone %d", toneType, mRegion, regionTone);
1449
1450 return regionTone;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001451}
1452
1453
1454////////////////////////////////////////////////////////////////////////////////
1455// WaveGenerator::WaveGenerator class Implementation
1456////////////////////////////////////////////////////////////////////////////////
1457
1458//---------------------------------- public methods ----------------------------
1459
1460////////////////////////////////////////////////////////////////////////////////
1461//
1462// Method: WaveGenerator::WaveGenerator()
1463//
1464// Description: Constructor.
1465//
1466// Input:
1467// samplingRate: Output sampling rate in Hz
1468// frequency: Frequency of the sine wave to generate in Hz
1469// volume: volume (0.0 to 1.0)
1470//
1471// Output:
1472// none
1473//
1474////////////////////////////////////////////////////////////////////////////////
1475ToneGenerator::WaveGenerator::WaveGenerator(unsigned short samplingRate,
1476 unsigned short frequency, float volume) {
1477 double d0;
1478 double F_div_Fs; // frequency / samplingRate
1479
1480 F_div_Fs = frequency / (double)samplingRate;
1481 d0 = - (float)GEN_AMP * sin(2 * M_PI * F_div_Fs);
1482 mS2_0 = (short)d0;
1483 mS1 = 0;
1484 mS2 = mS2_0;
1485
1486 mAmplitude_Q15 = (short)(32767. * 32767. * volume / GEN_AMP);
1487 // take some margin for amplitude fluctuation
1488 if (mAmplitude_Q15 > 32500)
1489 mAmplitude_Q15 = 32500;
1490
1491 d0 = 32768.0 * cos(2 * M_PI * F_div_Fs); // Q14*2*cos()
1492 if (d0 > 32767)
1493 d0 = 32767;
1494 mA1_Q14 = (short) d0;
1495
1496 LOGV("WaveGenerator init, mA1_Q14: %d, mS2_0: %d, mAmplitude_Q15: %d\n",
1497 mA1_Q14, mS2_0, mAmplitude_Q15);
1498}
1499
1500////////////////////////////////////////////////////////////////////////////////
1501//
1502// Method: WaveGenerator::~WaveGenerator()
1503//
1504// Description: Destructor.
1505//
1506// Input:
1507// none
1508//
1509// Output:
1510// none
1511//
1512////////////////////////////////////////////////////////////////////////////////
1513ToneGenerator::WaveGenerator::~WaveGenerator() {
1514}
1515
1516////////////////////////////////////////////////////////////////////////////////
1517//
1518// Method: WaveGenerator::getSamples()
1519//
1520// Description: Generates count samples of a sine wave and accumulates
1521// result in outBuffer.
1522//
1523// Input:
1524// outBuffer: Output buffer where to accumulate samples.
1525// count: number of samples to produce.
1526// command: special action requested (see enum gen_command).
1527//
1528// Output:
1529// none
1530//
1531////////////////////////////////////////////////////////////////////////////////
1532void ToneGenerator::WaveGenerator::getSamples(short *outBuffer,
1533 unsigned int count, unsigned int command) {
1534 long lS1, lS2;
1535 long lA1, lAmplitude;
1536 long Sample; // current sample
1537
1538 // init local
1539 if (command == WAVEGEN_START) {
1540 lS1 = (long)0;
1541 lS2 = (long)mS2_0;
1542 } else {
1543 lS1 = (long)mS1;
1544 lS2 = (long)mS2;
1545 }
1546 lA1 = (long)mA1_Q14;
1547 lAmplitude = (long)mAmplitude_Q15;
1548
1549 if (command == WAVEGEN_STOP) {
1550 lAmplitude <<= 16;
1551 if (count == 0) {
1552 return;
1553 }
1554 long dec = lAmplitude/count;
1555 // loop generation
1556 while (count--) {
1557 Sample = ((lA1 * lS1) >> S_Q14) - lS2;
1558 // shift delay
1559 lS2 = lS1;
1560 lS1 = Sample;
1561 Sample = ((lAmplitude>>16) * Sample) >> S_Q15;
1562 *(outBuffer++) += (short)Sample; // put result in buffer
1563 lAmplitude -= dec;
1564 }
1565 } else {
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 * Sample) >> S_Q15;
1573 *(outBuffer++) += (short)Sample; // put result in buffer
1574 }
1575 }
1576
1577 // save status
1578 mS1 = (short)lS1;
1579 mS2 = (short)lS2;
1580}
1581
1582} // end namespace android
1583