4 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: Seungbae Shin <seungbae.shin@samsung.com>
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
26 #include <semaphore.h>
30 #include <avsys-audio.h>
32 #include "../../include/mm_sound_thread_pool.h"
33 #include "../../include/mm_sound_plugin_codec.h"
38 #include <sys/types.h>
46 #define M_PI 3.14159265358979323846
50 #define M_PI_2 1.57079632679489661923
53 #define SAMPLERATE 44100
55 #define SAMPLE_SIZE 16
57 #define MAX_DURATION 100
76 pthread_mutex_t syncker;
83 int size; /* sizeof hole amr data */
85 /* Audio Infomations */
86 avsys_handle_t audio_handle;
88 /* control Informations */
110 typedef struct st_tone
113 float middle_frequency;
114 float high_frequency;
120 static const int TONE_SEGMENT[][MM_SOUND_TONE_NUM] =
122 {941, 1336, 0, -1, 0, 0,
123 -1, -1, -1, -1, 0, 0},// 0 key: 1336Hz, 941Hz
125 {697, 1209, 0, -1, 0, 0,
126 -1, -1, -1, -1, 0, 0},// 1 key: 1209Hz, 697Hz
128 {697, 1336, 0, -1, 0, 0,
129 -1, -1, -1, -1, 0, 0},// 2 key: 1336Hz, 697Hz
131 {697, 1477, 0, -1, 0, 0,
132 -1, -1, -1, -1, 0, 0}, // 3 key: 1477Hz, 697Hz
134 {770, 1209, 0, -1, 0, 0,
135 -1, -1, -1, -1, 0, 0},// 4 key: 1209Hz, 770Hz
137 {770, 1336, 0, -1, 0, 0,
138 -1, -1, -1, -1, 0, 0},// 5 key: 1336Hz, 770Hz
140 {770, 1477, 0, -1, 0, 0,
141 -1, -1, -1, -1, 0, 0},// 6 key: 1477Hz, 770Hz
143 {852, 1209, 0, -1, 0, 0,
144 -1, -1, -1, -1, 0, 0},// 7 key: 1209Hz, 852Hz
146 {852, 1336, 0, -1, 0, 0,
147 -1, -1, -1, -1, 0, 0},// 8 key: 1336Hz, 852Hz
149 {852, 1477, 0, -1, 0, 0,
150 -1, -1, -1, -1, 0, 0},// 9 key: 1477Hz, 852Hz
152 {941, 1209, 0, -1, 0, 0,
153 -1, -1, -1, -1, 0, 0},// * key: 1209Hz, 941Hz
155 {941, 1477, 0, -1, 0, 0,
156 -1, -1, -1, -1, 0, 0},// # key: 1477Hz, 941Hz
158 {697, 1633, 0, -1, 0, 0,
159 -1, -1, -1, -1, 0, 0},// A key: 1633Hz, 697Hz
161 {770, 1633, 0, -1, 0, 0,
162 -1, -1, -1, -1, 0, 0},// B key: 1633Hz, 770Hz
164 {852, 1633, 0, -1, 0, 0,
165 -1, -1, -1, -1, 0, 0},// C key: 1633Hz, 852Hz
167 {941, 1633, 0, -1, 0, 0,
168 -1, -1, -1, -1, 0, 0}, // D key: 1633Hz, 941Hz
170 {425, 0, 0, -1, 0, 0,
171 -1, -1, -1, -1, 0, 0}, //Call supervisory tone, Dial tone: CEPT: 425Hz, continuous
173 {350, 440, 0, -1, 0, 0,
174 -1, -1, -1, -1, 0, 0}, //Call supervisory tone, Dial tone: ANSI (IS-95): 350Hz+440Hz, continuous
176 {400, 0, 0, -1, 0, 0,
177 -1, -1, -1, -1, 0, 0}, //Call supervisory tone, Dial tone: JAPAN: 400Hz, continuous
179 {425, 0, 0, 500, 0, 0,
181 -1, -1, -1, -1, 0, 0},//Call supervisory tone, Busy: CEPT: 425Hz, 500ms ON, 500ms OFF...
183 {480, 620, 0, 500, 0, 0,
185 -1, -1, -1, -1, 0, 0}, //Call supervisory tone, Busy: ANSI (IS-95): 480Hz+620Hz, 500ms ON, 500ms OFF...
187 {400, 0, 0, 500, 0, 0,
189 -1, -1, -1, -1, 0, 0}, //Call supervisory tone, Busy: JAPAN: 400Hz, 500ms ON, 500ms OFF...
191 {425, 0, 0, 200, 0, 0,
193 -1, -1, -1, -1, 0, 0}, //Call supervisory tone, Congestion: CEPT, JAPAN: 425Hz, 200ms ON, 200ms OFF
195 {480, 620, 0, 250, 0, 0,
197 -1, -1, -1, -1, 0, 0}, //Call supervisory tone, Congestion: ANSI (IS-95): 480Hz+620Hz, 250ms ON, 250ms OFF...
199 {425, 0, 0, 200, 0, 0,
200 -1, -1, -1, -1, 0, 0}, //Call supervisory tone, Radio path acknowlegment : CEPT, ANSI: 425Hz, 200ms ON
202 {400, 0, 0, 1000, 0, 0,
204 -1, -1, -1, -1, 0, 0}, //Call supervisory tone, Radio path acknowlegment : JAPAN: 400Hz, 1s ON, 2s OFF...
206 {425, 0, 0, 200, 0, 0,
208 -1, -1, -1, -1, 3, 0}, //Call supervisory tone, Radio path not available: 425Hz, 200ms ON, 200 OFF 3 bursts
210 {950, 1400, 1800, 330, 0, 0,
212 -1, -1, -1, -1, 0, 0}, //Call supervisory tone, Error/Special info: 950Hz+1400Hz+1800Hz, 330ms ON, 1s OFF...
214 {425, 0, 0, 200, 0, 0,
216 425, 0, 0, 200, 0, 0,
218 -1, -1, -1, -1, 0, 0}, //Call supervisory tone, Call Waiting: CEPT, JAPAN: 425Hz, 200ms ON, 600ms OFF, 200ms ON, 3s OFF...
220 {440, 0, 0, 300, 0, 0,
222 440, 0, 0, 100, 0, 0,
224 440, 0, 0, 100, 0, 0,
226 -1, -1, -1, -1, 0, 0}, //Call supervisory tone, Call Waiting: ANSI (IS-95): 440 Hz, 300 ms ON, 9.7 s OFF, (100 ms ON, 100 ms OFF, 100 ms ON, 9.7s OFF ...)
228 {425, 0, 0, 1000, 0, 0,
230 -1, -1, -1, -1, 0, 0}, //Call supervisory tone, Ring Tone: CEPT, JAPAN: 425Hz, 1s ON, 4s OFF...
232 {440, 480, 0, 2000, 0, 0,
234 -1, -1, -1, -1, 0, 0}, //Call supervisory tone, Ring Tone: ANSI (IS-95): 440Hz + 480Hz, 2s ON, 4s OFF...
236 {400, 1200, 0, 35, 0, 0,
237 -1, -1, -1, -1, 0, 0}, // General beep: 400Hz+1200Hz, 35ms ON
239 {1200, 0, 0, 100, 0, 0,
241 -1, -1, -1, -1, 2, 0}, //Proprietary tone, positive acknowlegement: 1200Hz, 100ms ON, 100ms OFF 2 bursts
243 {300, 400, 500, 400, 0, 0,
244 -1, -1, -1, -1, 0, 0}, //Proprietary tone, negative acknowlegement: 300Hz+400Hz+500Hz, 400ms ON
246 {400, 1200, 0, 200, 0, 0,
247 -1, -1, -1, -1, 0, 0}, //Proprietary tone, prompt tone: 400Hz+1200Hz, 200ms ON
249 {400, 1200, 0, 35, 0, 0,
251 400, 1200, 0, 35, 0, 0,
252 -1, -1, -1, -1, 0, 0}, //Proprietary tone, general double beep: twice 400Hz+1200Hz, 35ms ON, 200ms OFF, 35ms ON
254 {440, 0, 0, 250, 0, 0,
255 620, 0, 0, 250, 0, 0,
256 -1, -1, -1, -1, 0, 0}, //Call supervisory tone (IS-95), intercept tone: alternating 440 Hz and 620 Hz tones, each on for 250 ms
258 {440, 0, 0, 250, 0, 0,
259 620, 0, 0, 250, 0, 0,
260 -1, -1, -1, -1, 8, 0}, //Call supervisory tone (IS-95), abbreviated intercept: intercept tone limited to 4 seconds
262 {480, 620, 0, 250, 0, 0,
264 -1, -1, -1, -1, 8, 0 }, //Call supervisory tone (IS-95), abbreviated congestion: congestion tone limited to 4 seconds
266 {350, 440, 0, 100, 0, 0,
268 -1, -1, -1, -1, 3, 0}, //Call supervisory tone (IS-95), confirm tone: a 350 Hz tone added to a 440 Hz tone repeated 3 times in a 100 ms on, 100 ms off cycle
270 {480, 0, 0, 100, 0, 0,
272 -1, -1, -1, -1, 4, 0}, //Call supervisory tone (IS-95), pip tone: four bursts of 480 Hz tone (0.1 s on, 0.1 s off).
274 { 425, 0, 0, -1, 0, 0,
275 -1, -1, -1, -1, 0, 0}, //425Hz continuous
277 {440, 480, 0, 2000, 0, 0,
279 -1, -1, -1, -1, 0, 0}, //CDMA USA Ringback: 440Hz+480Hz 2s ON, 4000 OFF ...
281 {440, 0, 0, 250, 0, 0,
282 620, 0, 0, 250, 0, 0,
283 -1, -1, -1, -1, 0, 0}, //CDMA Intercept tone: 440Hz 250ms ON, 620Hz 250ms ON ...
285 {440, 0, 0, 250, 0, 0,
286 620, 0, 0, 250, 0, 0,
287 -1, -1, -1, -1, 0, 0 }, //CDMA Abbr Intercept tone: 440Hz 250ms ON, 620Hz 250ms ON
289 {480, 620, 0, 250, 0, 0,
291 -1, -1, -1, -1, 0, 0 }, //CDMA Reorder tone: 480Hz+620Hz 250ms ON, 250ms OFF...
293 {480, 620, 0, 250, 0, 0,
295 -1, -1, -1, -1, 8, 0}, //CDMA Abbr Reorder tone: 480Hz+620Hz 250ms ON, 250ms OFF repeated for 8 times
297 {480, 620, 0, 500, 0, 0,
299 -1, -1, -1, -1, 0, 0}, //CDMA Network Busy tone: 480Hz+620Hz 500ms ON, 500ms OFF continuous
301 {350, 440, 0, 100, 0, 0,
303 -1, -1, -1, -1, 3, 0}, //CDMA Confirm tone: 350Hz+440Hz 100ms ON, 100ms OFF repeated for 3 times
305 {660, 1000, 0, 500, 0, 0,
307 -1, -1, -1, -1, 0, 0}, //CDMA answer tone: silent tone - defintion Frequency 0, 0ms ON, 0ms OFF
309 {440, 0, 0, 300, 0, 0,
310 -1, -1, -1, -1, 0, 0}, //CDMA Network Callwaiting tone: 440Hz 300ms ON
312 {480, 0, 0, 100, 0, 0,
314 -1, -1, -1, -1, 4, 0}, //CDMA PIP tone: 480Hz 100ms ON, 100ms OFF repeated for 4 times
316 {2090, 0, 0, 32, 0, 0,
317 2556, 0, 0, 64, 19, 0,
318 2090, 0, 0, 32, 0, 0,
319 2556, 0, 0, 48, 0, 0,
321 -1, -1, -1, -1, 0, 0}, //ISDN Call Signal Normal tone: {2091Hz 32ms ON, 2556 64ms ON} 20 times, 2091 32ms ON, 2556 48ms ON, 4s OFF
323 {2091, 0, 0, 32, 0, 0,
324 2556, 0, 0, 64, 7, 0,
325 2091, 0, 0, 32, 0, 0,
327 2091, 0, 0, 32, 0, 0,
328 2556, 0, 0, 64, 7, 4,
329 2091, 0, 0, 32, 0, 0,
331 -1, -1, -1, -1, 0, 0}, //ISDN Call Signal Intergroup tone: {2091Hz 32ms ON, 2556 64ms ON} 8 times, 2091Hz 32ms ON, 400ms OFF, {2091Hz 32ms ON, 2556Hz 64ms ON} 8times, 2091Hz 32ms ON, 4s OFF.
333 {2091, 0, 0, 32, 0, 0,
334 2556, 0, 0, 64, 3, 0,
335 2091, 0, 0, 32, 0, 0,
337 2091, 0, 0, 32, 0, 0,
338 2556, 0, 0, 64, 3, 4,
339 2091, 0, 0, 32, 0, 0,
341 -1, -1, -1, -1, 0, 0},//ISDN Call Signal SP PRI tone:{2091Hz 32ms ON, 2556 64ms ON} 4 times 2091Hz 16ms ON, 200ms OFF, {2091Hz 32ms ON, 2556Hz 64ms ON} 4 times, 2091Hz 16ms ON, 200ms OFF
344 -1, -1, -1, -1, 0, 0}, //ISDN Call sign PAT3 tone: silent tone
346 {2091, 0, 0, 32, 0, 0,
347 2556, 0, 0, 64, 4, 0,
348 2091, 0, 0, 20, 0, 0,
349 -1, -1, -1, -1, 0, 0}, //ISDN Ping Ring tone: {2091Hz 32ms ON, 2556Hz 64ms ON} 5 times 2091Hz 20ms ON
352 -1, -1, -1, -1, 0, 0}, //ISDN Pat5 tone: silent tone
355 -1, -1, -1, -1, 0, 0}, //ISDN Pat6 tone: silent tone
358 -1, -1, -1, -1, 0, 0}, //ISDN Pat7 tone: silent tone
360 {3700, 0, 0, 25, 0, 0,
361 4000, 0, 0, 25, 39, 0,
363 -1, -1, -1, -1, 0, 0}, //TONE_CDMA_HIGH_L tone: {3700Hz 25ms, 4000Hz 25ms} 40 times 4000ms OFF, Repeat ....
365 {2600, 0, 0, 25, 0, 0,
366 2900, 0, 0, 25, 39, 0,
368 -1, -1, -1, -1, 0, 0},//TONE_CDMA_MED_L tone: {2600Hz 25ms, 2900Hz 25ms} 40 times 4000ms OFF, Repeat ....
370 {1300, 0, 0, 25, 0, 0,
371 1450, 0, 0, 25, 39, 0,
373 -1, -1, -1, -1, 0, 0}, //TONE_CDMA_LOW_L tone: {1300Hz 25ms, 1450Hz 25ms} 40 times, 4000ms OFF, Repeat ....
375 {3700, 0, 0, 25, 0, 0,
376 4000, 0, 0, 25, 15, 0,
378 -1, -1, -1, -1, 0, 0},//CDMA HIGH SS tone: {3700Hz 25ms, 4000Hz 25ms} repeat 16 times, 400ms OFF, repeat ....
380 {2600, 0, 0, 25, 0, 0,
381 2900, 0, 0, 25, 15, 0,
383 -1, -1, -1, -1, 0, 0}, //CDMA MED SS tone: {2600Hz 25ms, 2900Hz 25ms} repeat 16 times, 400ms OFF, repeat ....
385 {1300, 0, 0, 25, 0, 0,
386 1450, 0, 0, 25, 15, 0,
388 -1, -1, -1, -1, 0, 0}, //CDMA LOW SS tone: {1300z 25ms, 1450Hz 25ms} repeat 16 times, 400ms OFF, repeat ....
390 {3700, 0, 0, 25, 0, 0,
391 4000, 0, 0, 25, 7, 0,
393 3700, 0, 0, 25, 0, 0,
394 4000, 0, 0, 25, 7, 3,
396 3700, 0, 0, 25, 0, 0,
397 4000, 0, 0, 25, 15, 6,
399 -1, -1, -1, -1, 0, 0}, //CDMA HIGH SSL tone: {3700Hz 25ms, 4000Hz 25ms} 8 times, 200ms OFF, {3700Hz 25ms, 4000Hz 25ms} repeat 8 times, 200ms OFF, {3700Hz 25ms, 4000Hz 25ms} repeat 16 times, 4000ms OFF, repeat ...
401 {2600, 0, 0, 25, 0, 0,
402 2900, 0, 0, 25, 7, 0,
404 2600, 0, 0, 25, 0, 0,
405 2900, 0, 0, 25, 7, 3,
407 2600, 0, 0, 25, 0, 0,
408 2900, 0, 0, 25, 15, 6,
410 -1, -1, -1, -1, 0, 0}, //CDMA MED SSL tone: {2600Hz 25ms, 2900Hz 25ms} 8 times, 200ms OFF, {2600Hz 25ms, 2900Hz 25ms} repeat 8 times, 200ms OFF, {2600Hz 25ms, 2900Hz 25ms} repeat 16 times, 4000ms OFF, repeat ...
412 {1300, 0, 0, 25, 0, 0,
413 1450, 0, 0, 25, 7, 0,
415 1300, 0, 0, 25, 0, 0,
416 1450, 0, 0, 25, 7, 3,
418 1300, 0, 0, 25, 0, 0,
419 1450, 0, 0, 25, 15, 6,
421 -1, -1, -1, -1, 0, 0}, //CDMA LOW SSL tone: {1300Hz 25ms, 1450Hz 25ms} 8 times, 200ms OFF, {1300Hz 25ms, 1450Hz 25ms} repeat 8 times, 200ms OFF, {1300Hz 25ms, 1450Hz 25ms} repeat 16 times, 4000ms OFF, repeat ...
423 {3700, 0, 0, 25, 0, 0,
424 4000, 0, 0, 25, 19, 0,
426 3700, 0, 0, 25, 0, 0,
427 4000, 0, 0, 25, 19, 3,
429 -1, -1, -1, -1, 0, 0 },//CDMA HIGH SS2 tone: {3700Hz 25ms, 4000Hz 25ms} 20 times, 1000ms OFF, {3700Hz 25ms, 4000Hz 25ms} 20 times, 3000ms OFF, repeat ....
431 {2600, 0, 0, 25, 0, 0,
432 2900, 0, 0, 25, 19, 0,
434 2600, 0, 0, 25, 0, 0,
435 2900, 0, 0, 25, 19, 3,
437 -1, -1, -1, -1, 0, 0}, //CDMA MED SS2 tone: {2600Hz 25ms, 2900Hz 25ms} 20 times, 1000ms OFF, {2600Hz 25ms, 2900Hz 25ms} 20 times, 3000ms OFF, repeat ....
439 {1300, 0, 0, 25, 0, 0,
440 1450, 0, 0, 25, 19, 0,
442 1300, 0, 0, 25, 0, 0,
443 1450, 0, 0, 25, 19, 3,
445 -1, -1, -1, -1, 0, 0 }, //CDMA LOW SS2 tone: {1300Hz 25ms, 1450Hz 25ms} 20 times, 1000ms OFF, {1300Hz 25ms, 1450Hz 25ms} 20 times, 3000ms OFF, repeat ....
447 {3700, 0, 0, 25, 0, 0,
448 4000, 0, 0, 25, 9, 0,
450 3700, 0, 0, 25, 0, 0,
451 4000, 0, 0, 25, 19, 3,
453 3700, 0, 0, 25, 0, 0,
454 4000, 0, 0, 25, 9, 6,
456 -1, -1, -1, -1, 0, 0}, //CDMA HIGH SLS tone: {3700Hz 25ms, 4000Hz 25ms} 10 times, 500ms OFF, {3700Hz 25ms, 4000Hz 25ms} 20 times, 500ms OFF, {3700Hz 25ms, 4000Hz 25ms} 10 times, 3000ms OFF, REPEAT
458 {2600, 0, 0, 25, 0, 0,
459 2900, 0, 0, 25, 9, 0,
461 2600, 0, 0, 25, 0, 0,
462 2900, 0, 0, 25, 19, 3,
464 2600, 0, 0, 25, 0, 0,
465 2900, 0, 0, 25, 9, 6,
467 -1, -1, -1, -1, 0, 0}, //CDMA MED SLS tone: {2600Hz 25ms, 2900Hz 25ms} 10 times, 500ms OFF, {2600Hz 25ms, 2900Hz 25ms} 20 times, 500ms OFF, {2600Hz 25ms, 2900Hz 25ms} 10 times, 3000ms OFF, REPEAT
469 {1300, 0, 0, 25, 0, 0,
470 1450, 0, 0, 25, 9, 0,
472 1300, 0, 0, 25, 0, 0,
473 1450, 0, 0, 25, 19, 3,
475 1300, 0, 0, 25, 0, 0,
476 1450, 0, 0, 25, 9, 6,
478 -1, -1, -1, -1, 0, 0}, //CDMA LOW SLS tone: {1300Hz 25ms, 1450Hz 25ms} 10 times, 500ms OFF, {1300Hz 25ms, 1450Hz 25ms} 20 times, 500ms OFF, {1300Hz 25ms, 1450Hz 25ms} 10 times, 3000ms OFF, REPEAT//
480 {3700, 0, 0, 25, 0, 0,
481 4000, 0, 0, 25, 9, 0,
483 3700, 0, 0, 25, 0, 0,
484 4000, 0, 0, 25, 9, 3,
486 3700, 0, 0, 25, 0, 0,
487 4000, 0, 0, 25, 9, 6,
489 -1, -1, -1, -1, 0, 0}, ////CDMA HIGH S X4 tone: {3700Hz 25ms, 4000Hz 25ms} 10 times, 500ms OFF, {3700Hz 25ms, 4000Hz 25ms} 10 times, 500ms OFF, {3700Hz 25ms, 4000Hz 25ms} 10 times, 500ms OFF, {3700Hz 25ms, 4000Hz 25ms} 10 times, 2500ms OFF, REPEAT....
491 {2600, 0, 0, 25, 0, 0,
492 2900, 0, 0, 25, 9, 0,
494 2600, 0, 0, 25, 0, 0,
495 2900, 0, 0, 25, 9, 4,
497 2600, 0, 0, 25, 0, 0,
498 2900, 0, 0, 25, 9, 6,
500 -1, -1, -1, -1, 0, 0 },//CDMA MED S X4 tone: {2600Hz 25ms, 2900Hz 25ms} 10 times, 500ms OFF, {2600Hz 25ms, 2900Hz 25ms} 10 times, 500ms OFF, {2600Hz 25ms, 2900Hz 25ms} 10 times, 500ms OFF, {2600Hz 25ms, 2900Hz 25ms} 10 times, 2500ms OFF, REPEAT....
502 {1300, 0, 0, 25, 0, 0,
503 1450, 0, 0, 25, 9, 0,
505 1300, 0, 0, 25, 0, 0,
506 1450, 0, 0, 25, 9, 3,
508 1300, 0, 0, 25, 0, 0,
509 1450, 0, 0, 25, 9, 6,
511 -1, -1, -1, -1, 0, 0}, //CDMA LOW S X4 tone: {2600Hz 25ms, 2900Hz 25ms} 10 times, 500ms OFF, {2600Hz 25ms, 2900Hz 25ms} 10 times, 500ms OFF, {2600Hz 25ms, 2900Hz 25ms} 10 times, 500ms OFF, {2600Hz 25ms, 2900Hz 25ms} 10 times, 2500ms OFF, REPEAT....
513 {3700, 0, 0, 25, 0, 0,
514 4000, 0, 0, 25, 19, 0,
516 -1, -1, -1, -1, 0, 0 },//CDMA HIGH PBX L: {3700Hz 25ms, 4000Hz 25ms}20 times, 2000ms OFF, REPEAT....
518 {2600, 0, 0, 25, 0, 0,
519 2900, 0, 0, 25, 19, 0,
521 -1, -1, -1, -1, 0, 0}, //CDMA MED PBX L: {2600Hz 25ms, 2900Hz 25ms}20 times, 2000ms OFF, REPEAT....
523 {1300, 0, 0, 25, 0, 0,
524 1450, 0, 0, 25, 19, 0,
526 -1, -1, -1, -1, 0, 0 },//CDMA LOW PBX L: {1300Hz 25ms,1450Hz 25ms}20 times, 2000ms OFF, REPEAT....
528 {3700, 0, 0, 25, 0, 0,
529 4000, 0, 0, 25, 7, 0,
531 3700, 0, 0, 25, 0, 0,
532 4000, 0, 0, 25, 7, 3,
534 -1, -1, -1, -1, 0, 0}, //CDMA HIGH PBX SS tone: {3700Hz 25ms, 4000Hz 25ms} 8 times 200 ms OFF, {3700Hz 25ms 4000Hz 25ms}8 times, 2000ms OFF, REPEAT....
536 {2600, 0, 0, 25, 0, 0,
537 2900, 0, 0, 25, 7, 0,
539 2600, 0, 0, 25, 0, 0,
540 2900, 0, 0, 25, 7, 3,
542 -1, -1, -1, -1, 0, 0 }, //CDMA MED PBX SS tone: {2600Hz 25ms, 2900Hz 25ms} 8 times 200 ms OFF, {2600Hz 25ms 2900Hz 25ms}8 times, 2000ms OFF, REPEAT....
544 {1300, 0, 0, 25, 0, 0,
545 1450, 0, 0, 25, 7, 0,
547 1300, 0, 0, 25, 0, 0,
548 1450, 0, 0, 25, 7, 3,
550 -1, -1, -1, -1, 0, 0 },//CDMA LOW PBX SS tone: {1300Hz 25ms, 1450Hz 25ms} 8 times 200 ms OFF, {1300Hz 25ms 1450Hz 25ms}8 times, 2000ms OFF, REPEAT....
552 {3700, 0, 0, 25, 0, 0,
553 4000, 0, 0, 25, 7, 0,
555 3700, 0, 0, 25, 0, 0,
556 4000, 0, 0, 25, 7, 3,
558 3700, 0, 0, 25, 0, 0,
559 4000, 0, 0, 25, 15, 6,
561 -1, -1, -1, -1, 0, 0}, //CDMA HIGH PBX SSL tone:{3700Hz 25ms, 4000Hz 25ms} 8 times 200ms OFF, {3700Hz 25ms, 4000Hz 25ms} 8 times, 200ms OFF, {3700Hz 25ms, 4000Hz 25ms} 16 times, 1000ms OFF, REPEAT....//
563 {2600, 0, 0, 25, 0, 0,
564 2900, 0, 0, 25, 7, 0,
566 2600, 0, 0, 25, 0, 0,
567 2900, 0, 0, 25, 7, 3,
569 2600, 0, 0, 25, 0, 0,
570 2900, 0, 0, 25, 15, 6,
572 -1, -1, -1, -1, 0, 0}, //CDMA MED PBX SSL tone:{2600Hz 25ms, 2900Hz 25ms} 8 times 200ms OFF, {2600Hz 25ms, 2900Hz 25ms} 8 times, 200ms OFF, {2600Hz 25ms, 2900Hz 25ms} 16 times, 1000ms OFF, REPEAT....//
574 {1300, 0, 0, 25, 0, 0,
575 1450, 0, 0, 25, 7, 0,
577 1300, 0, 0, 25, 0, 0,
578 1450, 0, 0, 25, 7, 3,
580 1300, 0, 0, 25, 0, 0,
581 1450, 0, 0, 25, 15, 6,
583 -1, -1, -1, -1, 0, 0}, //CDMA LOW PBX SSL tone:{1300Hz 25ms, 1450Hz 25ms} 8 times 200ms OFF, {1300Hz 25ms, 1450Hz 25ms} 8 times, 200ms OFF, {1300Hz 25ms, 1450Hz 25ms} 16 times, 1000ms OFF, REPEAT....//
585 {3700, 0, 0, 25, 0, 0,
586 4000, 0, 0, 25, 15, 0,
588 3700, 0, 0, 25, 0, 0,
589 4000, 0, 0, 25, 7, 3,
591 -1, -1, -1, -1, 0, 0 },//CDMA HIGH PBX SLS tone:{3700Hz 25ms, 4000Hz 25ms} 8 times 200ms OFF, {3700Hz 25ms, 4000Hz 25ms} 16 times, 200ms OFF, {3700Hz 25ms, 4000Hz 25ms} 8 times, 1000ms OFF, REPEAT.... //
593 {2600, 0, 0, 25, 0, 0,
594 2900, 0, 0, 25, 15, 0,
596 2600, 0, 0, 25, 0, 0,
597 2900, 0, 0, 25, 7, 3,
599 -1, -1, -1, -1, 0, 0 }, //CDMA HIGH PBX SLS tone:{2600Hz 25ms, 2900Hz 25ms} 8 times 200ms OFF, {2600Hz 25ms, 2900Hz 25ms} 16 times, 200ms OFF, {2600Hz 25ms, 2900Hz 25ms} 8 times, 1000ms OFF, REPEAT....//
601 {1300, 0, 0, 25, 0, 0,
602 1450, 0, 0, 25, 15, 0,
604 1300, 0, 0, 25, 0, 0,
605 1450, 0, 0, 25, 7, 3,
607 -1, -1, -1, -1, 0, 0 }, //CDMA HIGH PBX SLS tone:{1300Hz 25ms, 1450Hz 25ms} 8 times 200ms OFF, {1300Hz 25ms, 1450Hz 25ms} 16 times, 200ms OFF, {1300Hz 25ms, 1450Hz 25ms} 8 times, 1000ms OFF, REPEAT....//
609 {3700, 0, 0, 25, 0, 0,
610 4000, 0, 0, 25, 7, 0,
612 3700, 0, 0, 25, 0, 0,
613 4000, 0, 0, 25, 7, 3,
615 3700, 0, 0, 25, 0, 0,
616 4000, 0, 0, 25, 7, 6,
618 3700, 0, 0, 25, 0, 0,
619 4000, 0, 0, 25, 7, 9,
621 -1, -1, -1, -1, 0, 0}, //CDMA HIGH PBX X S4 tone: {3700Hz 25ms 4000Hz 25ms} 8 times, 200ms OFF, {3700Hz 25ms 4000Hz 25ms} 8 times, 200ms OFF, {3700Hz 25ms 4000Hz 25ms} 8 times, 200ms OFF, {3700Hz 25ms 4000Hz 25ms} 8 times, 800ms OFF, REPEAT...
623 {2600, 0, 0, 25, 0, 0,
624 2900, 0, 0, 25, 7, 0,
626 2600, 0, 0, 25, 0, 0,
627 2900, 0, 0, 25, 7, 3,
629 2600, 0, 0, 25, 0, 0,
630 2900, 0, 0, 25, 7, 6,
632 2600, 0, 0, 25, 0, 0,
633 2900, 0, 0, 25, 7, 9,
635 -1, -1, -1, -1, 0, 0}, //CDMA MED PBX X S4 tone: {2600Hz 25ms 2900Hz 25ms} 8 times, 200ms OFF, {2600Hz 25ms 2900Hz 25ms} 8 times, 200ms OFF, {2600Hz 25ms 2900Hz 25ms} 8 times, 200ms OFF, {2600Hz 25ms 2900Hz 25ms} 8 times, 800ms OFF, REPEAT...
637 {1300, 0, 0, 25, 0, 0,
638 1450, 0, 0, 25, 7, 0,
640 1300, 0, 0, 25, 0, 0,
641 1450, 0, 0, 25, 7, 3,
643 1300, 0, 0, 25, 0, 0,
644 1450, 0, 0, 25, 7, 6,
646 1300, 0, 0, 25, 0, 0,
647 1450, 0, 0, 25, 7, 9,
649 -1, -1, -1, -1, 0, 0}, //CDMA LOW PBX X S4 tone: {1300Hz 25ms 1450Hz 25ms} 8 times, 200ms OFF, {1300Hz 25ms 1450Hz 25ms} 8 times, 200ms OFF, {1300Hz 25ms 1450Hz 25ms} 8 times, 200ms OFF, {1300Hz 25ms 1450Hz 25ms} 8 times, 800ms OFF, REPEAT...
651 {1109, 0, 0, 62, 0, 0,
655 1109, 0, 0, 62, 0, 0,
656 -1, -1, -1, -1, 0, 0}, //CDMA Alert Network Lite tone: 1109Hz 62ms ON, 784Hz 62ms ON, 740Hz 62ms ON 622Hz 62ms ON, 1109Hz 62ms ON
658 {1245, 0, 0, 62, 0, 0,
660 1245, 0, 0, 62, 0, 0,
662 1245, 0, 0, 62, 0, 0,
664 1245, 0, 0, 62, 0, 0,
665 -1, -1, -1, -1, 0, 0},//CDMA Alert Auto Redial tone: {1245Hz 62ms ON, 659Hz 62ms ON} 3 times, 1245 62ms ON//
667 {1150, 770, 0, 400, 0, 0,
668 -1, -1, -1, -1, 0, 0}, //CDMA One Min Beep tone: 1150Hz+770Hz 400ms ON//
670 {941, 1477, 0, 120, 0, 0,
671 -1, -1, -1, -1, 0, 0}, //CDMA KEYPAD Volume key lite tone: 941Hz+1477Hz 120ms ON
673 {587, 0, 0, 375, 0, 0,
674 1175, 0, 0, 125, 0, 0,
675 -1, -1, -1, -1, 0, 0}, //CDMA PRESSHOLDKEY LITE tone: 587Hz 375ms ON, 1175Hz 125ms ON
677 {587, 0, 0, 62, 0, 0,
681 1109, 0, 0, 62, 0, 0,
685 -1, -1, -1, -1, 0, 0}, //CDMA ALERT INCALL LITE tone: 587Hz 62ms, 784 62ms, 831Hz 62ms, 784Hz 62ms, 1109 62ms, 784Hz 62ms, 831Hz 62ms, 784Hz 62ms
687 {941, 0, 0, 125, 0, 0,
689 941, 0, 0, 125, 0, 0,
691 1245, 0, 0, 62, 0, 0,
694 -1, -1, -1, -1, 0, 0}, //CDMA EMERGENCY RINGBACK tone: {941Hz 125ms ON, 10ms OFF} 3times 4990ms OFF, REPEAT...
696 {1319, 0, 0, 125, 0, 0,
698 -1, -1, -1, -1, 3, 0 }, //CDMA ALERT CALL GUARD tone: {1319Hz 125ms ON, 125ms OFF} 3 times
700 {1047, 0, 0, 125, 0, 0,
701 370, 0, 0, 125, 0, 0,
702 -1, -1, -1, -1, 0, 0}, //CDMA SOFT ERROR LITE tone: 1047Hz 125ms ON, 370Hz 125ms
704 {1480, 0, 0, 125, 0, 0,
705 1397, 0, 0, 125, 0, 0,
706 784, 0, 0, 125, 0, 0,
707 -1, -1, -1, -1, 0, 0}, //CDMA CALLDROP LITE tone: 1480Hz 125ms, 1397Hz 125ms, 784Hz 125ms//
709 {425, 0, 0, 125, 0, 0,
711 -1, -1, -1, -1, 0, 0},//CDMA_NETWORK_BUSY_ONE_SHOT tone: 425Hz 500ms ON, 500ms OFF.
713 {1150, 770, 0, 400, 0, 0,
714 -1, -1, -1, -1, 0, 0}, //CDMA_ABBR_ALERT tone: 1150Hz+770Hz 400ms ON
717 -1, -1, -1, -1, 0, 0}, //CDMA_SIGNAL_OFF - silent tone
720 static tone_control_t g_control;
721 static int (*g_thread_pool_func)(void*, void (*)(void*)) = NULL;
723 static int _MMSoundToneInit(void);
724 static int _MMSoundToneFini(void);
725 static void _running_tone(void *param);
729 int* MMSoundPlugCodecToneGetSupportTypes(void)
732 static int suported[2] = {MM_SOUND_SUPPORTED_CODEC_DTMF, 0};
737 int MMSoundPlugCodecToneParse(MMSourceType *source, mmsound_codec_info_t *info)
742 return MM_ERROR_NONE;
745 int MMSoundPlugCodecToneCreate(mmsound_codec_param_t *param, mmsound_codec_info_t *info, MMHandleType *handle)
747 avsys_audio_param_t audio_param;
748 tone_info_t *toneInfo;
750 int result = AVSYS_STATE_SUCCESS;
754 toneInfo = (tone_info_t *)malloc(sizeof(tone_info_t));
755 if (toneInfo == NULL) {
756 debug_error("memory allocation error\n");
757 return MM_ERROR_OUT_OF_MEMORY;
760 memset(toneInfo, 0, sizeof(tone_info_t));
762 toneInfo->state = STATE_READY;
764 /* set audio param */
765 memset (&audio_param, 0, sizeof(avsys_audio_param_t));
767 /* Set sound player parameter */
768 audio_param.samplerate = SAMPLERATE;
769 audio_param.channels = CHANNELS;
770 audio_param.format = AVSYS_AUDIO_FORMAT_16BIT;
771 audio_param.mode = AVSYS_AUDIO_MODE_OUTPUT;
772 audio_param.vol_type = param->volume_config;
773 audio_param.priority = AVSYS_AUDIO_PRIORITY_0;
775 result = avsys_audio_open(&audio_param, &toneInfo->audio_handle, &toneInfo->size);
776 if (AVSYS_FAIL(result)) {
777 debug_error("Device Open Error 0x%x\n", result);
780 debug_log("Create audio_handle is %d\n", toneInfo->audio_handle);
782 debug_msg("tone : %d\n", param->tone);
783 debug_msg("repeat : %d\n", param->repeat_count);
784 debug_msg("volume config : %x\n", param->volume_config);
785 debug_msg("callback : %p\n", param->stop_cb);
786 debug_msg("pid : %d\n", param->pid);
788 toneInfo->number = param->tone;
789 toneInfo->time = param->repeat_count;
790 toneInfo->stop_cb = param->stop_cb;
791 toneInfo->cb_param = param->param;
792 toneInfo->pid = param->pid;
793 toneInfo->volume = param->volume;
795 result = g_thread_pool_func(toneInfo, _running_tone);
797 debug_error("pthread_create() fail in pcm thread\n");
798 result = MM_ERROR_SOUND_INTERNAL;
802 *handle = (MMHandleType)toneInfo;
805 return MM_ERROR_NONE;
809 if(toneInfo->audio_handle)
810 avsys_audio_close(toneInfo->audio_handle);
819 int MMSoundPlugCodecToneDestroy(MMHandleType handle)
821 tone_info_t *toneInfo = (tone_info_t*) handle;
822 int err = MM_ERROR_NONE;
824 debug_critical("Confirm the hadle (is NULL)\n");
825 return MM_ERROR_SOUND_INTERNAL;
828 debug_enter("(handle %x)\n", handle);
838 int MMSoundPlugCodecTonePlay(MMHandleType handle)
840 tone_info_t *toneInfo = (tone_info_t *) handle;
842 debug_enter("(handle %x)\n", handle);
844 toneInfo->state = STATE_BEGIN;
845 debug_msg("sent start signal\n");
849 return MM_ERROR_NONE;
853 _create_tone (double *sample, TONE _TONE, double volume, int *toneSize)
857 double amplitude, f1, f2, f3;
859 float low_frequency = _TONE.low_frequency;
860 float middle_frequency = _TONE.middle_frequency;
861 float high_frequency = _TONE.high_frequency;
865 debug_error("Sample buffer is not allocated\n");
869 /* Create a buffer for the tone */
870 if((_TONE.playingTime > MAX_DURATION) || (_TONE.playingTime == -1) ) {
871 *toneSize = ((MAX_DURATION / 1000.) * SAMPLERATE * SAMPLE_SIZE * CHANNELS) / 8;
873 *toneSize = ((_TONE.playingTime / 1000.) * SAMPLERATE * SAMPLE_SIZE * CHANNELS) / 8;
875 *toneSize = ((*toneSize+1)>>1)<<1;
876 sample_size = (*toneSize) / (SAMPLE_SIZE / 8);
878 debug_log("_TONE.playing_time: %d toneSize: %d\n", _TONE.playingTime, *toneSize);
879 char* buffer = g_malloc (*toneSize);
882 debug_error("Buffer is not allocated\n");
885 pbuf = (short*)buffer;
887 if(_TONE.low_frequency > 0) {
890 if(_TONE.middle_frequency > 0) {
893 if(_TONE.high_frequency > 0) {
897 for (i = 0; i < sample_size; i++) {
899 * We add the fundamental frequencies together.
902 f1 = sin (2 * M_PI * low_frequency * ((*sample) / SAMPLERATE));
903 f2 = sin (2 * M_PI * middle_frequency * ((*sample) / SAMPLERATE));
904 f3 = sin (2 * M_PI * high_frequency * ((*sample) / SAMPLERATE));
906 if(f1 + f2 + f3 != 0) {
907 amplitude = (f1 + f2 + f3) / quota;
908 /* Adjust the volume */
911 /* Make the [-1:1] interval into a [-32767:32767] interval */
917 /* Store it in the data buffer */
918 *(pbuf++) = (short) amplitude;
927 _mm_get_tone(int key, int CurIndex)
931 _TONE.low_frequency = TONE_SEGMENT[key][CurIndex * TONE_COLUMN + LOW_FREQUENCY];
932 _TONE.middle_frequency = TONE_SEGMENT[key][CurIndex * TONE_COLUMN + MIDDLE_FREQUENCY];
933 _TONE.high_frequency = TONE_SEGMENT[key][CurIndex * TONE_COLUMN + HIGH_FREQUENCY];
934 _TONE.playingTime = TONE_SEGMENT[key][CurIndex * TONE_COLUMN + PLAYING_TIME];
935 _TONE.loopCnt = TONE_SEGMENT[key][CurIndex * TONE_COLUMN + LOOP_COUNT];
936 _TONE.loopIndx = TONE_SEGMENT[key][CurIndex * TONE_COLUMN + LOOP_INDEX];
942 _mm_get_waveCnt_PlayingTime(int toneTime, TONE _TONE, int *waveCnt, int *waveRestPlayTime)
944 int ret = MM_ERROR_NONE;
945 if(waveCnt == NULL || waveRestPlayTime == NULL) {
946 debug_error("waveCnt || waveRestPlayTime buffer is NULL\n");
947 return MM_ERROR_SOUND_INTERNAL;
949 /*Set wave count and wave playing time*/
950 if( _TONE.playingTime == -1) {
951 *waveCnt = abs(toneTime) /MAX_DURATION;
952 *waveRestPlayTime = abs(toneTime) % MAX_DURATION;
954 *waveCnt = _TONE.playingTime /MAX_DURATION;
955 *waveRestPlayTime = _TONE.playingTime % MAX_DURATION;
961 _mm_get_CurIndex(TONE _TONE, int *CurArrayPlayCnt, int *CurIndex)
963 int ret = MM_ERROR_NONE;
964 if(CurArrayPlayCnt == NULL || CurIndex == NULL) {
965 debug_error("CurArrayPlayCnt || CurIndex buffer is NULL\n");
966 return MM_ERROR_SOUND_INTERNAL;
969 if(_TONE.loopCnt != 0 && *CurArrayPlayCnt <= _TONE.loopCnt) {
970 (*CurArrayPlayCnt)++;
971 if(*CurArrayPlayCnt >_TONE.loopCnt) {
973 *CurArrayPlayCnt = 0;
975 *CurIndex = _TONE.loopIndx;
980 debug_log("CurIndex: %d, CurArrayPlayCnt :%d", *CurIndex, *CurArrayPlayCnt);
984 static void _running_tone(void *param)
986 int result = AVSYS_STATE_SUCCESS;
987 char *ptoneBuf = NULL;
991 debug_error("param Buffer is not allocated\n");
994 tone_info_t *toneInfo = (tone_info_t*) param;
997 int prePlayingTime = 0;
1001 int CurWaveIndex = 0;
1003 int waveRestPlayTime = 0;
1005 int CurArrayPlayCnt = 0;
1009 toneTime = toneInfo->time;
1011 toneKey = toneInfo->number;
1012 debug_msg ("toneKey number = %d\n", toneKey);
1014 /* Set pid check file */
1015 snprintf(filename, sizeof(filename), "/proc/%d/cmdline", toneInfo->pid);
1017 debug_msg("Wait start signal\n");
1018 while(toneInfo->state == STATE_READY)
1020 debug_msg("Recv start signal\n");
1021 toneInfo->state = STATE_PLAY;
1027 TONE _TONE = _mm_get_tone(toneKey, CurIndex); /*Pop one of Tone Set */
1028 if(_mm_get_waveCnt_PlayingTime(toneTime, _TONE, &numWave, &waveRestPlayTime) != MM_ERROR_NONE) {
1029 debug_error("_mm_get_waveCnt_PlayingTime return value error\n");
1032 debug_log ("Predefined Tone[%d] Total Play time (ms) : %d, _TONE.playing_time: %d _numWave = %d low_frequency: %0.f, middle_frequency: %0.f, high_frequency: %0.f\n",
1033 CurIndex, toneTime, _TONE.playingTime, numWave, _TONE.low_frequency, _TONE.middle_frequency, _TONE.high_frequency);
1035 if (_TONE.low_frequency == -1) { /* skip frequency which's value is -1*/
1036 CurIndex = _TONE.loopIndx;
1040 /* Write pcm data */
1042 for(CurWaveIndex = 0; CurWaveIndex < numWave+1; CurWaveIndex++) {
1043 if(CurWaveIndex == numWave ) { /* play the last tone set*/
1044 playingTime = waveRestPlayTime;
1046 playingTime = MAX_DURATION;
1048 duration = playingTime;
1050 if(playingTime == 0) {
1054 if(prePlayingTime + playingTime > toneTime && toneTime != -1) {
1055 playingTime = toneTime - prePlayingTime;
1058 ptoneBuf = _create_tone (&sample, _TONE, toneInfo->volume, &toneSize);
1059 if(ptoneBuf == NULL) {
1060 debug_error("Tone Buffer is not allocated\n");
1063 debug_log ("[TONE] Play.....%dth %dms\n", CurWaveIndex, playingTime);
1064 avsys_audio_write(toneInfo->audio_handle, ptoneBuf, ((toneSize * playingTime /duration + 1)>>1)<<1);
1065 prePlayingTime += playingTime;
1066 debug_log ("previous_sum: %d\n", prePlayingTime);
1070 if(prePlayingTime == toneTime || toneInfo->state != STATE_PLAY) {
1071 debug_log ("Finished.....on Total Playing Time : %d _TONE.playing_time: %d\n", prePlayingTime, _TONE.playingTime);
1072 avsys_audio_drain(toneInfo->audio_handle);
1073 debug_log ("Finished.....quit loop\n");
1077 if(_mm_get_CurIndex(_TONE, &CurArrayPlayCnt, &CurIndex) != MM_ERROR_NONE) {
1078 debug_error("_mm_get_CurIndex return value error\n");
1082 debug_log ("CurIndex: %d previous_sum: %d CurArrayPlayCnt: %d\n", CurIndex, prePlayingTime, CurArrayPlayCnt);
1086 result = avsys_audio_close(toneInfo->audio_handle);
1087 if(AVSYS_FAIL(result)) {
1088 debug_error("Device Close Error 0x%x\n", result);
1091 pthread_mutex_destroy(&g_control.syncker);
1093 debug_msg("Play end\n");
1094 toneInfo->state = STATE_STOP;
1096 if (toneInfo->stop_cb)
1097 toneInfo->stop_cb(toneInfo->cb_param);
1103 int MMSoundPlugCodecToneStop(MMHandleType handle)
1105 tone_info_t *toneInfo = (tone_info_t*) handle;
1107 debug_enter("(handle %x)\n", handle);
1108 toneInfo->state = STATE_STOP;
1109 debug_msg("sent stop signal\n");
1112 return MM_ERROR_NONE;
1116 int MMSoundPlugCodecToneSetThreadPool(int (*func)(void*, void (*)(void*)))
1118 debug_enter("(func : 0x%x)\n", func);
1119 g_thread_pool_func = func;
1121 return MM_ERROR_NONE;
1124 static int _MMSoundToneInit(void)
1126 memset(&g_control, 0, sizeof(tone_control_t));
1127 pthread_mutex_init(&g_control.syncker, NULL);
1128 return MM_ERROR_NONE;
1131 static int _MMSoundToneFini(void)
1133 pthread_mutex_destroy(&g_control.syncker);
1134 return MM_ERROR_NONE;
1138 int MMSoundGetPluginType(void)
1142 return MM_SOUND_PLUGIN_TYPE_CODEC;
1146 int MMSoundPlugCodecGetInterface(mmsound_codec_interface_t *intf)
1150 intf->GetSupportTypes = MMSoundPlugCodecToneGetSupportTypes;
1151 intf->Parse = MMSoundPlugCodecToneParse;
1152 intf->Create = MMSoundPlugCodecToneCreate;
1153 intf->Destroy = MMSoundPlugCodecToneDestroy;
1154 intf->Play = MMSoundPlugCodecTonePlay;
1155 intf->Stop = MMSoundPlugCodecToneStop;
1156 intf->SetThreadPool = MMSoundPlugCodecToneSetThreadPool;
1160 return MM_ERROR_NONE;