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>
28 #include "../../include/mm_sound_plugin_codec.h"
38 #include <pulse/sample.h>
39 #include "../../../include/mm_sound_pa_client.h"
42 #define M_PI 3.14159265358979323846
46 #define M_PI_2 1.57079632679489661923
49 #define SAMPLERATE 44100
51 #define SAMPLE_SIZE 16
53 #define MAX_DURATION 100
55 #define WAIT_THREAD_WAIT_CNT 100
56 #define WAIT_THREAD_WAIT_TIME 10 /* ms */
67 THREAD_STATE_NONE = 0,
82 pthread_mutex_t syncker;
90 int size; /* sizeof hole amr data */
91 pthread_mutex_t mutex;
93 /* Audio Infomations */
96 /* control Informations */
98 int (*stop_cb)(int, bool);
107 bool *is_stop_request_done;
119 typedef struct st_tone {
121 float middle_frequency;
122 float high_frequency;
128 static const int TONE_SEGMENT[][MM_SOUND_TONE_NUM] = {
129 {941, 1336, 0, -1, 0, 0,
130 -1, -1, -1, -1, 0, 0},// 0 key: 1336Hz, 941Hz
132 {697, 1209, 0, -1, 0, 0,
133 -1, -1, -1, -1, 0, 0},// 1 key: 1209Hz, 697Hz
135 {697, 1336, 0, -1, 0, 0,
136 -1, -1, -1, -1, 0, 0},// 2 key: 1336Hz, 697Hz
138 {697, 1477, 0, -1, 0, 0,
139 -1, -1, -1, -1, 0, 0}, // 3 key: 1477Hz, 697Hz
141 {770, 1209, 0, -1, 0, 0,
142 -1, -1, -1, -1, 0, 0},// 4 key: 1209Hz, 770Hz
144 {770, 1336, 0, -1, 0, 0,
145 -1, -1, -1, -1, 0, 0},// 5 key: 1336Hz, 770Hz
147 {770, 1477, 0, -1, 0, 0,
148 -1, -1, -1, -1, 0, 0},// 6 key: 1477Hz, 770Hz
150 {852, 1209, 0, -1, 0, 0,
151 -1, -1, -1, -1, 0, 0},// 7 key: 1209Hz, 852Hz
153 {852, 1336, 0, -1, 0, 0,
154 -1, -1, -1, -1, 0, 0},// 8 key: 1336Hz, 852Hz
156 {852, 1477, 0, -1, 0, 0,
157 -1, -1, -1, -1, 0, 0},// 9 key: 1477Hz, 852Hz
159 {941, 1209, 0, -1, 0, 0,
160 -1, -1, -1, -1, 0, 0},// * key: 1209Hz, 941Hz
162 {941, 1477, 0, -1, 0, 0,
163 -1, -1, -1, -1, 0, 0},// # key: 1477Hz, 941Hz
165 {697, 1633, 0, -1, 0, 0,
166 -1, -1, -1, -1, 0, 0},// A key: 1633Hz, 697Hz
168 {770, 1633, 0, -1, 0, 0,
169 -1, -1, -1, -1, 0, 0},// B key: 1633Hz, 770Hz
171 {852, 1633, 0, -1, 0, 0,
172 -1, -1, -1, -1, 0, 0},// C key: 1633Hz, 852Hz
174 {941, 1633, 0, -1, 0, 0,
175 -1, -1, -1, -1, 0, 0}, // D key: 1633Hz, 941Hz
177 {425, 0, 0, -1, 0, 0,
178 -1, -1, -1, -1, 0, 0}, //Call supervisory tone, Dial tone: CEPT: 425Hz, continuous
180 {350, 440, 0, -1, 0, 0,
181 -1, -1, -1, -1, 0, 0}, //Call supervisory tone, Dial tone: ANSI (IS-95): 350Hz+440Hz, continuous
183 {400, 0, 0, -1, 0, 0,
184 -1, -1, -1, -1, 0, 0}, //Call supervisory tone, Dial tone: JAPAN: 400Hz, continuous
186 {425, 0, 0, 500, 0, 0,
188 -1, -1, -1, -1, 0, 0},//Call supervisory tone, Busy: CEPT: 425Hz, 500ms ON, 500ms OFF...
190 {480, 620, 0, 500, 0, 0,
192 -1, -1, -1, -1, 0, 0}, //Call supervisory tone, Busy: ANSI (IS-95): 480Hz+620Hz, 500ms ON, 500ms OFF...
194 {400, 0, 0, 500, 0, 0,
196 -1, -1, -1, -1, 0, 0}, //Call supervisory tone, Busy: JAPAN: 400Hz, 500ms ON, 500ms OFF...
198 {425, 0, 0, 200, 0, 0,
200 -1, -1, -1, -1, 1, 0}, //Call supervisory tone, Congestion: CEPT, JAPAN: 425Hz, 200ms ON, 200ms OFF
202 {480, 620, 0, 250, 0, 0,
204 -1, -1, -1, -1, 0, 0}, //Call supervisory tone, Congestion: ANSI (IS-95): 480Hz+620Hz, 250ms ON, 250ms OFF...
206 {425, 0, 0, 200, 0, 0,
207 -1, -1, -1, -1, 1, 0}, //Call supervisory tone, Radio path acknowlegment : CEPT, ANSI: 425Hz, 200ms ON
209 {400, 0, 0, 1000, 0, 0,
211 -1, -1, -1, -1, 0, 0}, //Call supervisory tone, Radio path acknowlegment : JAPAN: 400Hz, 1s ON, 2s OFF...
213 {425, 0, 0, 200, 0, 0,
215 -1, -1, -1, -1, 3, 0}, //Call supervisory tone, Radio path not available: 425Hz, 200ms ON, 200 OFF 3 bursts
217 {950, 1400, 1800, 330, 0, 0,
219 -1, -1, -1, -1, 0, 0}, //Call supervisory tone, Error/Special info: 950Hz+1400Hz+1800Hz, 330ms ON, 1s OFF...
221 {425, 0, 0, 200, 0, 0,
223 425, 0, 0, 200, 0, 0,
225 -1, -1, -1, -1, 0, 0}, //Call supervisory tone, Call Waiting: CEPT, JAPAN: 425Hz, 200ms ON, 600ms OFF, 200ms ON, 3s OFF...
227 {440, 0, 0, 300, 0, 0,
229 440, 0, 0, 100, 0, 0,
231 440, 0, 0, 100, 0, 0,
233 -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 ...)
235 {425, 0, 0, 1000, 0, 0,
237 -1, -1, -1, -1, 0, 0}, //Call supervisory tone, Ring Tone: CEPT, JAPAN: 425Hz, 1s ON, 4s OFF...
239 {440, 480, 0, 2000, 0, 0,
241 -1, -1, -1, -1, 0, 0}, //Call supervisory tone, Ring Tone: ANSI (IS-95): 440Hz + 480Hz, 2s ON, 4s OFF...
243 {400, 1200, 0, 35, 0, 0,
244 -1, -1, -1, -1, 1, 0}, // General beep: 400Hz+1200Hz, 35ms ON
246 {1200, 0, 0, 100, 0, 0,
248 -1, -1, -1, -1, 2, 0}, //Proprietary tone, positive acknowlegement: 1200Hz, 100ms ON, 100ms OFF 2 bursts
250 {300, 400, 500, 400, 0, 0,
251 -1, -1, -1, -1, 1, 0}, //Proprietary tone, negative acknowlegement: 300Hz+400Hz+500Hz, 400ms ON
253 {400, 1200, 0, 200, 0, 0,
254 -1, -1, -1, -1, 1, 0}, //Proprietary tone, prompt tone: 400Hz+1200Hz, 200ms ON
256 {400, 1200, 0, 35, 0, 0,
258 400, 1200, 0, 35, 0, 0,
259 -1, -1, -1, -1, 1, 0}, //Proprietary tone, general double beep: twice 400Hz+1200Hz, 35ms ON, 200ms OFF, 35ms ON
261 {440, 0, 0, 250, 0, 0,
262 620, 0, 0, 250, 0, 0,
263 -1, -1, -1, -1, 1, 0}, //Call supervisory tone (IS-95), intercept tone: alternating 440 Hz and 620 Hz tones, each on for 250 ms
265 {440, 0, 0, 250, 0, 0,
266 620, 0, 0, 250, 0, 0,
267 -1, -1, -1, -1, 8, 0}, //Call supervisory tone (IS-95), abbreviated intercept: intercept tone limited to 4 seconds
269 {480, 620, 0, 250, 0, 0,
271 -1, -1, -1, -1, 8, 0}, //Call supervisory tone (IS-95), abbreviated congestion: congestion tone limited to 4 seconds
273 {350, 440, 0, 100, 0, 0,
275 -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
277 {480, 0, 0, 100, 0, 0,
279 -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).
281 { 425, 0, 0, -1, 0, 0,
282 -1, -1, -1, -1, 0, 0}, //425Hz continuous
284 {440, 480, 0, 2000, 0, 0,
286 -1, -1, -1, -1, 0, 0}, //CDMA USA Ringback: 440Hz+480Hz 2s ON, 4000 OFF ...
288 {440, 0, 0, 250, 0, 0,
289 620, 0, 0, 250, 0, 0,
290 -1, -1, -1, -1, 0, 0}, //CDMA Intercept tone: 440Hz 250ms ON, 620Hz 250ms ON ...
292 {440, 0, 0, 250, 0, 0,
293 620, 0, 0, 250, 0, 0,
294 -1, -1, -1, -1, 1, 0 }, //CDMA Abbr Intercept tone: 440Hz 250ms ON, 620Hz 250ms ON
296 {480, 620, 0, 250, 0, 0,
298 -1, -1, -1, -1, 0, 0 }, //CDMA Reorder tone: 480Hz+620Hz 250ms ON, 250ms OFF...
300 {480, 620, 0, 250, 0, 0,
302 -1, -1, -1, -1, 8, 0}, //CDMA Abbr Reorder tone: 480Hz+620Hz 250ms ON, 250ms OFF repeated for 8 times
304 {480, 620, 0, 500, 0, 0,
306 -1, -1, -1, -1, 0, 0}, //CDMA Network Busy tone: 480Hz+620Hz 500ms ON, 500ms OFF continuous
308 {350, 440, 0, 100, 0, 0,
310 -1, -1, -1, -1, 3, 0}, //CDMA Confirm tone: 350Hz+440Hz 100ms ON, 100ms OFF repeated for 3 times
312 {660, 1000, 0, 500, 0, 0,
314 -1, -1, -1, -1, 1, 0}, //CDMA answer tone: silent tone - defintion Frequency 0, 0ms ON, 0ms OFF
316 {440, 0, 0, 300, 0, 0,
317 -1, -1, -1, -1, 1, 0}, //CDMA Network Callwaiting tone: 440Hz 300ms ON
319 {480, 0, 0, 100, 0, 0,
321 -1, -1, -1, -1, 4, 0}, //CDMA PIP tone: 480Hz 100ms ON, 100ms OFF repeated for 4 times
323 {2090, 0, 0, 32, 0, 0,
324 2556, 0, 0, 64, 19, 0,
325 2090, 0, 0, 32, 0, 0,
326 2556, 0, 0, 48, 0, 0,
328 -1, -1, -1, -1, 1, 0}, //ISDN Call Signal Normal tone: {2091Hz 32ms ON, 2556 64ms ON} 20 times, 2091 32ms ON, 2556 48ms ON, 4s OFF
330 {2091, 0, 0, 32, 0, 0,
331 2556, 0, 0, 64, 7, 0,
332 2091, 0, 0, 32, 0, 0,
334 2091, 0, 0, 32, 0, 0,
335 2556, 0, 0, 64, 7, 4,
336 2091, 0, 0, 32, 0, 0,
338 -1, -1, -1, -1, 1, 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
340 {2091, 0, 0, 32, 0, 0,
341 2556, 0, 0, 64, 3, 0,
342 2091, 0, 0, 32, 0, 0,
344 2091, 0, 0, 32, 0, 0,
345 2556, 0, 0, 64, 3, 4,
346 2091, 0, 0, 32, 0, 0,
348 -1, -1, -1, -1, 1, 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
351 -1, -1, -1, -1, 1, 0}, //ISDN Call sign PAT3 tone: silent tone
353 {2091, 0, 0, 32, 0, 0,
354 2556, 0, 0, 64, 4, 0,
355 2091, 0, 0, 20, 0, 0,
356 -1, -1, -1, -1, 1, 0}, //ISDN Ping Ring tone: {2091Hz 32ms ON, 2556Hz 64ms ON} 5 times 2091Hz 20ms ON
359 -1, -1, -1, -1, 1, 0}, //ISDN Pat5 tone: silent tone
362 -1, -1, -1, -1, 1, 0}, //ISDN Pat6 tone: silent tone
365 -1, -1, -1, -1, 1, 0}, //ISDN Pat7 tone: silent tone
367 {3700, 0, 0, 25, 0, 0,
368 4000, 0, 0, 25, 39, 0,
370 -1, -1, -1, -1, 0, 0}, //TONE_CDMA_HIGH_L tone: {3700Hz 25ms, 4000Hz 25ms} 40 times 4000ms OFF, Repeat ....
372 {2600, 0, 0, 25, 0, 0,
373 2900, 0, 0, 25, 39, 0,
375 -1, -1, -1, -1, 0, 0},//TONE_CDMA_MED_L tone: {2600Hz 25ms, 2900Hz 25ms} 40 times 4000ms OFF, Repeat ....
377 {1300, 0, 0, 25, 0, 0,
378 1450, 0, 0, 25, 39, 0,
380 -1, -1, -1, -1, 0, 0}, //TONE_CDMA_LOW_L tone: {1300Hz 25ms, 1450Hz 25ms} 40 times, 4000ms OFF, Repeat ....
382 {3700, 0, 0, 25, 0, 0,
383 4000, 0, 0, 25, 15, 0,
385 -1, -1, -1, -1, 0, 0},//CDMA HIGH SS tone: {3700Hz 25ms, 4000Hz 25ms} repeat 16 times, 400ms OFF, repeat ....
387 {2600, 0, 0, 25, 0, 0,
388 2900, 0, 0, 25, 15, 0,
390 -1, -1, -1, -1, 0, 0}, //CDMA MED SS tone: {2600Hz 25ms, 2900Hz 25ms} repeat 16 times, 400ms OFF, repeat ....
392 {1300, 0, 0, 25, 0, 0,
393 1450, 0, 0, 25, 15, 0,
395 -1, -1, -1, -1, 0, 0}, //CDMA LOW SS tone: {1300z 25ms, 1450Hz 25ms} repeat 16 times, 400ms OFF, repeat ....
397 {3700, 0, 0, 25, 0, 0,
398 4000, 0, 0, 25, 7, 0,
400 3700, 0, 0, 25, 0, 0,
401 4000, 0, 0, 25, 7, 3,
403 3700, 0, 0, 25, 0, 0,
404 4000, 0, 0, 25, 15, 6,
406 -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 ...
408 {2600, 0, 0, 25, 0, 0,
409 2900, 0, 0, 25, 7, 0,
411 2600, 0, 0, 25, 0, 0,
412 2900, 0, 0, 25, 7, 3,
414 2600, 0, 0, 25, 0, 0,
415 2900, 0, 0, 25, 15, 6,
417 -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 ...
419 {1300, 0, 0, 25, 0, 0,
420 1450, 0, 0, 25, 7, 0,
422 1300, 0, 0, 25, 0, 0,
423 1450, 0, 0, 25, 7, 3,
425 1300, 0, 0, 25, 0, 0,
426 1450, 0, 0, 25, 15, 6,
428 -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 ...
430 {3700, 0, 0, 25, 0, 0,
431 4000, 0, 0, 25, 19, 0,
433 3700, 0, 0, 25, 0, 0,
434 4000, 0, 0, 25, 19, 3,
436 -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 ....
438 {2600, 0, 0, 25, 0, 0,
439 2900, 0, 0, 25, 19, 0,
441 2600, 0, 0, 25, 0, 0,
442 2900, 0, 0, 25, 19, 3,
444 -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 ....
446 {1300, 0, 0, 25, 0, 0,
447 1450, 0, 0, 25, 19, 0,
449 1300, 0, 0, 25, 0, 0,
450 1450, 0, 0, 25, 19, 3,
452 -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 ....
454 {3700, 0, 0, 25, 0, 0,
455 4000, 0, 0, 25, 9, 0,
457 3700, 0, 0, 25, 0, 0,
458 4000, 0, 0, 25, 19, 3,
460 3700, 0, 0, 25, 0, 0,
461 4000, 0, 0, 25, 9, 6,
463 -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....
465 {2600, 0, 0, 25, 0, 0,
466 2900, 0, 0, 25, 9, 0,
468 2600, 0, 0, 25, 0, 0,
469 2900, 0, 0, 25, 19, 3,
471 2600, 0, 0, 25, 0, 0,
472 2900, 0, 0, 25, 9, 6,
474 -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....
476 {1300, 0, 0, 25, 0, 0,
477 1450, 0, 0, 25, 9, 0,
479 1300, 0, 0, 25, 0, 0,
480 1450, 0, 0, 25, 19, 3,
482 1300, 0, 0, 25, 0, 0,
483 1450, 0, 0, 25, 9, 6,
485 -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....
487 {3700, 0, 0, 25, 0, 0,
488 4000, 0, 0, 25, 9, 0,
490 3700, 0, 0, 25, 0, 0,
491 4000, 0, 0, 25, 9, 3,
493 3700, 0, 0, 25, 0, 0,
494 4000, 0, 0, 25, 9, 6,
496 -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....
498 {2600, 0, 0, 25, 0, 0,
499 2900, 0, 0, 25, 9, 0,
501 2600, 0, 0, 25, 0, 0,
502 2900, 0, 0, 25, 9, 4,
504 2600, 0, 0, 25, 0, 0,
505 2900, 0, 0, 25, 9, 6,
507 -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....
509 {1300, 0, 0, 25, 0, 0,
510 1450, 0, 0, 25, 9, 0,
512 1300, 0, 0, 25, 0, 0,
513 1450, 0, 0, 25, 9, 3,
515 1300, 0, 0, 25, 0, 0,
516 1450, 0, 0, 25, 9, 6,
518 -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....
520 {3700, 0, 0, 25, 0, 0,
521 4000, 0, 0, 25, 19, 0,
523 -1, -1, -1, -1, 0, 0 },//CDMA HIGH PBX L: {3700Hz 25ms, 4000Hz 25ms}20 times, 2000ms OFF, REPEAT....
525 {2600, 0, 0, 25, 0, 0,
526 2900, 0, 0, 25, 19, 0,
528 -1, -1, -1, -1, 0, 0}, //CDMA MED PBX L: {2600Hz 25ms, 2900Hz 25ms}20 times, 2000ms OFF, REPEAT....
530 {1300, 0, 0, 25, 0, 0,
531 1450, 0, 0, 25, 19, 0,
533 -1, -1, -1, -1, 0, 0 },//CDMA LOW PBX L: {1300Hz 25ms,1450Hz 25ms}20 times, 2000ms OFF, REPEAT....
535 {3700, 0, 0, 25, 0, 0,
536 4000, 0, 0, 25, 7, 0,
538 3700, 0, 0, 25, 0, 0,
539 4000, 0, 0, 25, 7, 3,
541 -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....
543 {2600, 0, 0, 25, 0, 0,
544 2900, 0, 0, 25, 7, 0,
546 2600, 0, 0, 25, 0, 0,
547 2900, 0, 0, 25, 7, 3,
549 -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....
551 {1300, 0, 0, 25, 0, 0,
552 1450, 0, 0, 25, 7, 0,
554 1300, 0, 0, 25, 0, 0,
555 1450, 0, 0, 25, 7, 3,
557 -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....
559 {3700, 0, 0, 25, 0, 0,
560 4000, 0, 0, 25, 7, 0,
562 3700, 0, 0, 25, 0, 0,
563 4000, 0, 0, 25, 7, 3,
565 3700, 0, 0, 25, 0, 0,
566 4000, 0, 0, 25, 15, 6,
568 -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....//
570 {2600, 0, 0, 25, 0, 0,
571 2900, 0, 0, 25, 7, 0,
573 2600, 0, 0, 25, 0, 0,
574 2900, 0, 0, 25, 7, 3,
576 2600, 0, 0, 25, 0, 0,
577 2900, 0, 0, 25, 15, 6,
579 -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....//
581 {1300, 0, 0, 25, 0, 0,
582 1450, 0, 0, 25, 7, 0,
584 1300, 0, 0, 25, 0, 0,
585 1450, 0, 0, 25, 7, 3,
587 1300, 0, 0, 25, 0, 0,
588 1450, 0, 0, 25, 15, 6,
590 -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....//
592 {3700, 0, 0, 25, 0, 0,
593 4000, 0, 0, 25, 15, 0,
595 3700, 0, 0, 25, 0, 0,
596 4000, 0, 0, 25, 7, 3,
598 -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.... //
600 {2600, 0, 0, 25, 0, 0,
601 2900, 0, 0, 25, 15, 0,
603 2600, 0, 0, 25, 0, 0,
604 2900, 0, 0, 25, 7, 3,
606 -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....//
608 {1300, 0, 0, 25, 0, 0,
609 1450, 0, 0, 25, 15, 0,
611 1300, 0, 0, 25, 0, 0,
612 1450, 0, 0, 25, 7, 3,
614 -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....//
616 {3700, 0, 0, 25, 0, 0,
617 4000, 0, 0, 25, 7, 0,
619 3700, 0, 0, 25, 0, 0,
620 4000, 0, 0, 25, 7, 3,
622 3700, 0, 0, 25, 0, 0,
623 4000, 0, 0, 25, 7, 6,
625 3700, 0, 0, 25, 0, 0,
626 4000, 0, 0, 25, 7, 9,
628 -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...
630 {2600, 0, 0, 25, 0, 0,
631 2900, 0, 0, 25, 7, 0,
633 2600, 0, 0, 25, 0, 0,
634 2900, 0, 0, 25, 7, 3,
636 2600, 0, 0, 25, 0, 0,
637 2900, 0, 0, 25, 7, 6,
639 2600, 0, 0, 25, 0, 0,
640 2900, 0, 0, 25, 7, 9,
642 -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...
644 {1300, 0, 0, 25, 0, 0,
645 1450, 0, 0, 25, 7, 0,
647 1300, 0, 0, 25, 0, 0,
648 1450, 0, 0, 25, 7, 3,
650 1300, 0, 0, 25, 0, 0,
651 1450, 0, 0, 25, 7, 6,
653 1300, 0, 0, 25, 0, 0,
654 1450, 0, 0, 25, 7, 9,
656 -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...
658 {1109, 0, 0, 62, 0, 0,
662 1109, 0, 0, 62, 0, 0,
663 -1, -1, -1, -1, 1, 0}, //CDMA Alert Network Lite tone: 1109Hz 62ms ON, 784Hz 62ms ON, 740Hz 62ms ON 622Hz 62ms ON, 1109Hz 62ms ON
665 {1245, 0, 0, 62, 0, 0,
667 1245, 0, 0, 62, 0, 0,
669 1245, 0, 0, 62, 0, 0,
671 1245, 0, 0, 62, 0, 0,
672 -1, -1, -1, -1, 1, 0},//CDMA Alert Auto Redial tone: {1245Hz 62ms ON, 659Hz 62ms ON} 3 times, 1245 62ms ON//
674 {1150, 770, 0, 400, 0, 0,
675 -1, -1, -1, -1, 1, 0}, //CDMA One Min Beep tone: 1150Hz+770Hz 400ms ON//
677 {941, 1477, 0, 120, 0, 0,
678 -1, -1, -1, -1, 1, 0}, //CDMA KEYPAD Volume key lite tone: 941Hz+1477Hz 120ms ON
680 {587, 0, 0, 375, 0, 0,
681 1175, 0, 0, 125, 0, 0,
682 -1, -1, -1, -1, 1, 0}, //CDMA PRESSHOLDKEY LITE tone: 587Hz 375ms ON, 1175Hz 125ms ON
684 {587, 0, 0, 62, 0, 0,
688 1109, 0, 0, 62, 0, 0,
692 -1, -1, -1, -1, 1, 0}, //CDMA ALERT INCALL LITE tone: 587Hz 62ms, 784 62ms, 831Hz 62ms, 784Hz 62ms, 1109 62ms, 784Hz 62ms, 831Hz 62ms, 784Hz 62ms
694 {941, 0, 0, 125, 0, 0,
696 941, 0, 0, 125, 0, 0,
698 1245, 0, 0, 62, 0, 0,
701 -1, -1, -1, -1, 0, 0}, //CDMA EMERGENCY RINGBACK tone: {941Hz 125ms ON, 10ms OFF} 3times 4990ms OFF, REPEAT...
703 {1319, 0, 0, 125, 0, 0,
705 -1, -1, -1, -1, 3, 0 }, //CDMA ALERT CALL GUARD tone: {1319Hz 125ms ON, 125ms OFF} 3 times
707 {1047, 0, 0, 125, 0, 0,
708 370, 0, 0, 125, 0, 0,
709 -1, -1, -1, -1, 1, 0}, //CDMA SOFT ERROR LITE tone: 1047Hz 125ms ON, 370Hz 125ms
711 {1480, 0, 0, 125, 0, 0,
712 1397, 0, 0, 125, 0, 0,
713 784, 0, 0, 125, 0, 0,
714 -1, -1, -1, -1, 1, 0}, //CDMA CALLDROP LITE tone: 1480Hz 125ms, 1397Hz 125ms, 784Hz 125ms//
716 {425, 0, 0, 125, 0, 0,
718 -1, -1, -1, -1, 1, 0},//CDMA_NETWORK_BUSY_ONE_SHOT tone: 425Hz 500ms ON, 500ms OFF
720 {1150, 770, 0, 400, 0, 0,
721 -1, -1, -1, -1, 1, 0}, //CDMA_ABBR_ALERT tone: 1150Hz+770Hz 400ms ON
724 -1, -1, -1, -1, 1, 0}, //CDMA_SIGNAL_OFF - silent tone
726 {100, 0, 0, -1, 0, 0,
727 -1, -1, -1, -1, 0, 0}, //100Hz continuous
729 {200, 0, 0, -1, 0, 0,
730 -1, -1, -1, -1, 0, 0}, //200Hz continuous
732 {300, 0, 0, -1, 0, 0,
733 -1, -1, -1, -1, 0, 0}, //300Hz continuous
737 static tone_control_t g_control;
740 static int (*g_thread_pool_func)(void*, void (*)(void*)) = NULL;
742 static int _MMSoundToneInit(void);
743 static int _MMSoundToneFini(void);
745 static void _running_tone(void *param);
749 int* MMSoundPlugCodecToneGetSupportTypes(void)
752 static int suported[2] = {MM_SOUND_SUPPORTED_CODEC_DTMF, 0};
757 int MMSoundPlugCodecToneCreate(mmsound_codec_param_t *param, mmsound_codec_info_t *info, MMHandleType *handle)
759 tone_info_t *toneInfo;
764 int result = MM_ERROR_NONE;
769 toneInfo = (tone_info_t *)malloc(sizeof(tone_info_t));
770 if (toneInfo == NULL) {
771 debug_error("memory allocation error");
772 return MM_ERROR_OUT_OF_MEMORY;
775 memset(toneInfo, 0, sizeof(tone_info_t));
777 pthread_mutex_init(&toneInfo->mutex, NULL);
778 pthread_mutex_lock(&toneInfo->mutex);
779 toneInfo->state = STATE_READY;
780 toneInfo->thread_state = THREAD_STATE_NONE;
781 pthread_mutex_unlock(&toneInfo->mutex);
783 ss.rate = SAMPLERATE;
784 ss.channels = CHANNELS;
785 ss.format = PA_SAMPLE_S16LE;
787 toneInfo->handle = mm_sound_pa_open(HANDLE_MODE_OUTPUT, param->volume_config, &ss, NULL, &size, param->stream_type, param->stream_index);
788 if (!toneInfo->handle) {
789 debug_error("Device Open Error 0x%x", result);
792 debug_log("Create audio_handle is %d", toneInfo->handle);
794 debug_msg("tone : %d", param->tone);
795 debug_msg("repeat : %d", param->repeat_count);
796 debug_msg("volume config : %x", param->volume_config);
797 debug_msg("callback : %p", param->stop_cb);
798 debug_msg("pid : %d", param->pid);
800 toneInfo->number = param->tone;
801 toneInfo->time = param->repeat_count;
802 toneInfo->stop_cb = param->stop_cb;
803 toneInfo->cb_param = param->param;
804 toneInfo->pid = param->pid;
805 toneInfo->volume = param->volume;
807 result = g_thread_pool_func(toneInfo, _running_tone);
809 debug_error("pthread_create() fail in pcm thread");
810 result = MM_ERROR_SOUND_INTERNAL;
814 *handle = (MMHandleType)toneInfo;
816 debug_msg("wait until thread_stare THREAD_STATE_START");
817 while ((toneInfo->thread_state == THREAD_STATE_NONE) && (wait_count < WAIT_THREAD_WAIT_CNT)) {
818 usleep(WAIT_THREAD_WAIT_TIME * 1000);
822 if (wait_count >= WAIT_THREAD_WAIT_CNT)
823 debug_error("timeout for thread pool. wait_count: %d ms ", WAIT_THREAD_WAIT_CNT * WAIT_THREAD_WAIT_TIME);
825 debug_msg("_running_tone thread is started");
828 return MM_ERROR_NONE;
832 if (toneInfo->handle) {
833 if (MM_ERROR_NONE != mm_sound_pa_close(toneInfo->handle))
834 debug_error("mm_sound_pa_close() fail. handle(%d)", toneInfo->handle);
843 int MMSoundPlugCodecToneDestroy(MMHandleType handle)
845 tone_info_t *toneInfo = (tone_info_t*) handle;
846 int err = MM_ERROR_NONE;
848 debug_critical("Confirm the hadle (is NULL)");
849 return MM_ERROR_SOUND_INTERNAL;
852 debug_enter("(handle %p)", handle);
854 /* if the stop is request done ptr is valid, then inform the result */
855 if (toneInfo->is_stop_request_done)
856 *(toneInfo->is_stop_request_done) = true;
858 pthread_mutex_destroy(&toneInfo->mutex);
867 int MMSoundPlugCodecTonePlay(MMHandleType handle)
869 tone_info_t *toneInfo = (tone_info_t *) handle;
871 debug_enter("(handle %p)", handle);
872 pthread_mutex_lock(&toneInfo->mutex);
873 toneInfo->state = STATE_BEGIN;
874 pthread_mutex_unlock(&toneInfo->mutex);
875 debug_msg("sent start signal");
879 return MM_ERROR_NONE;
883 _create_tone(double *sample, TONE _TONE, double volume, int *toneSize, gboolean is_cycle_ended)
887 double amplitude, f1, f2, f3;
890 float middle_frequency;
891 float high_frequency;
895 if (is_cycle_ended) {
897 middle_frequency = 0;
900 low_frequency = _TONE.low_frequency;
901 middle_frequency = _TONE.middle_frequency;
902 high_frequency = _TONE.high_frequency;
905 if (sample == NULL) {
906 debug_error("Sample buffer is not allocated");
910 /* Create a buffer for the tone */
911 if ((_TONE.playingTime > MAX_DURATION) || (_TONE.playingTime == -1))
912 *toneSize = ((MAX_DURATION / 1000.) * SAMPLERATE * SAMPLE_SIZE * CHANNELS) / 8;
914 *toneSize = ((_TONE.playingTime / 1000.) * SAMPLERATE * SAMPLE_SIZE * CHANNELS) / 8;
916 *toneSize = ((*toneSize + 1) >> 1) << 1;
917 sample_size = (*toneSize) / (SAMPLE_SIZE / 8);
919 debug_log("%0.f, %0.f, %0.f _TONE.playing_time: %d toneSize: %d",
920 low_frequency, middle_frequency, high_frequency, _TONE.playingTime, *toneSize);
922 buffer = g_malloc(*toneSize);
923 if (buffer == NULL) {
924 debug_error("Buffer is not allocated");
927 pbuf = (short*)buffer;
929 if (_TONE.low_frequency > 0)
932 if (_TONE.middle_frequency > 0)
935 if (_TONE.high_frequency > 0)
938 for (i = 0; i < sample_size; i++) {
940 * We add the fundamental frequencies together.
943 f1 = sin(2 * M_PI * low_frequency * ((*sample) / SAMPLERATE));
944 f2 = sin(2 * M_PI * middle_frequency * ((*sample) / SAMPLERATE));
945 f3 = sin(2 * M_PI * high_frequency * ((*sample) / SAMPLERATE));
947 if (f1 + f2 + f3 != 0) {
948 amplitude = (f1 + f2 + f3) / quota;
949 /* Adjust the volume */
952 /* Make the [-1:1] interval into a [-32767:32767] interval */
958 /* Store it in the data buffer */
959 *(pbuf++) = (short) amplitude;
968 _mm_get_tone(int key, int CurIndex)
972 _TONE.low_frequency = TONE_SEGMENT[key][CurIndex * TONE_COLUMN + LOW_FREQUENCY];
973 _TONE.middle_frequency = TONE_SEGMENT[key][CurIndex * TONE_COLUMN + MIDDLE_FREQUENCY];
974 _TONE.high_frequency = TONE_SEGMENT[key][CurIndex * TONE_COLUMN + HIGH_FREQUENCY];
975 _TONE.playingTime = TONE_SEGMENT[key][CurIndex * TONE_COLUMN + PLAYING_TIME];
976 _TONE.loopCnt = TONE_SEGMENT[key][CurIndex * TONE_COLUMN + LOOP_COUNT];
977 _TONE.loopIndx = TONE_SEGMENT[key][CurIndex * TONE_COLUMN + LOOP_INDEX];
983 _mm_get_waveCnt_PlayingTime(int toneTime, TONE _TONE, int *waveCnt, int *waveRestPlayTime)
985 int ret = MM_ERROR_NONE;
986 if (waveCnt == NULL || waveRestPlayTime == NULL) {
987 debug_error("waveCnt || waveRestPlayTime buffer is NULL");
988 return MM_ERROR_SOUND_INTERNAL;
990 /*Set wave count and wave playing time*/
991 if (_TONE.playingTime == -1) {
992 *waveCnt = abs(toneTime) /MAX_DURATION;
993 *waveRestPlayTime = abs(toneTime) % MAX_DURATION;
995 *waveCnt = _TONE.playingTime /MAX_DURATION;
996 *waveRestPlayTime = _TONE.playingTime % MAX_DURATION;
1002 _mm_get_CurIndex(TONE _TONE, int *CurArrayPlayCnt, int *CurIndex)
1004 int ret = MM_ERROR_NONE;
1005 if (CurArrayPlayCnt == NULL || CurIndex == NULL) {
1006 debug_error("CurArrayPlayCnt || CurIndex buffer is NULL");
1007 return MM_ERROR_SOUND_INTERNAL;
1010 if (_TONE.loopCnt != 0 && *CurArrayPlayCnt <= _TONE.loopCnt) {
1011 (*CurArrayPlayCnt)++;
1012 if (*CurArrayPlayCnt > _TONE.loopCnt) {
1014 *CurArrayPlayCnt = 0;
1016 *CurIndex = _TONE.loopIndx;
1021 debug_log("[%d] CurIndex: %d", *CurArrayPlayCnt, *CurIndex);
1025 static void _running_tone(void *param)
1027 char *ptoneBuf = NULL;
1030 if (param == NULL) {
1031 debug_error("param Buffer is not allocated");
1034 tone_info_t *toneInfo = (tone_info_t*) param;
1037 int prePlayingTime = 0;
1039 int playingTime = 0;
1041 int CurWaveIndex = 0;
1043 int waveRestPlayTime = 0;
1045 int CurArrayPlayCnt = 0;
1046 gboolean is_cycle_ended = FALSE;
1049 pthread_mutex_lock(&toneInfo->mutex);
1050 toneInfo->thread_state = THREAD_STATE_START;
1051 debug_msg("set thread_state as THREAD_STATE_START");
1052 pthread_mutex_unlock(&toneInfo->mutex);
1054 toneTime = toneInfo->time;
1055 if (toneTime != 0) {
1056 toneKey = toneInfo->number;
1057 debug_msg("toneKey number = %d", toneKey);
1059 /* Set pid check file */
1060 snprintf(filename, sizeof(filename), "/proc/%d/cmdline", toneInfo->pid);
1062 debug_msg("Wait start signal");
1063 while (toneInfo->state == STATE_READY)
1065 debug_msg("Recv start signal");
1066 pthread_mutex_lock(&toneInfo->mutex);
1068 if ((toneInfo->state == STATE_STOP) || (toneInfo->thread_state == THREAD_STATE_STOP)) {
1069 debug_msg("state is stop. state(%d) thread_state(%d) goto exit.", toneInfo->state, toneInfo->thread_state);
1070 pthread_mutex_unlock(&toneInfo->mutex);
1073 debug_msg("set state STATE_PLAY");
1074 toneInfo->state = STATE_PLAY;
1076 pthread_mutex_unlock(&toneInfo->mutex);
1082 while (toneInfo->thread_state == THREAD_STATE_START) {
1083 TONE _TONE = _mm_get_tone(toneKey, CurIndex); /*Pop one of Tone Set */
1084 if (_mm_get_waveCnt_PlayingTime(toneTime, _TONE, &numWave, &waveRestPlayTime) != MM_ERROR_NONE) {
1085 debug_error("_mm_get_waveCnt_PlayingTime return value error");
1089 if (_mm_get_CurIndex(_TONE, &CurArrayPlayCnt, &CurIndex) != MM_ERROR_NONE) {
1090 debug_error("_mm_get_CurIndex return value error");
1094 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",
1095 CurIndex, toneTime, _TONE.playingTime, numWave, _TONE.low_frequency, _TONE.middle_frequency, _TONE.high_frequency);
1098 if (_TONE.low_frequency == -1) { /* skip frequency which's value is -1*/
1099 if ((_TONE.loopCnt > 0) && (CurArrayPlayCnt == _TONE.loopCnt)) {
1100 is_cycle_ended = TRUE;
1101 debug_log("[is_cycle_ended]");
1103 CurIndex = _TONE.loopIndx;
1107 /* Write pcm data */
1108 for (CurWaveIndex = 0; CurWaveIndex < numWave+1; CurWaveIndex++) {
1109 if (CurWaveIndex == numWave) /* play the last tone set*/
1110 playingTime = waveRestPlayTime;
1112 playingTime = MAX_DURATION;
1114 duration = playingTime;
1116 if (playingTime == 0)
1119 if (prePlayingTime + playingTime > toneTime && toneTime != -1)
1120 playingTime = toneTime - prePlayingTime;
1122 ptoneBuf = _create_tone(&sample, _TONE, toneInfo->volume, &toneSize, is_cycle_ended);
1123 if (ptoneBuf == NULL) {
1124 debug_error("Tone Buffer is not allocated");
1127 debug_log("[TONE] Play.....%dth %dms", CurWaveIndex, playingTime);
1128 mm_sound_pa_write(toneInfo->handle, ptoneBuf, ((toneSize * playingTime /duration + 1)>>1)<<1);
1129 prePlayingTime += playingTime;
1130 debug_log("previous_sum: %d", prePlayingTime);
1134 if (prePlayingTime == toneTime || toneInfo->state != STATE_PLAY) {
1135 debug_log("Finished.....on Total Playing Time : %d _TONE.playing_time: %d", prePlayingTime, _TONE.playingTime);
1136 mm_sound_pa_drain(toneInfo->handle);
1137 debug_log("Finished.....quit loop");
1140 debug_log("[%d] CurIndex: %d previous_sum: %d", CurArrayPlayCnt, CurIndex, prePlayingTime);
1145 if (MM_ERROR_NONE != mm_sound_pa_close(toneInfo->handle))
1146 debug_error("mm_sound_pa_close() fail. handle(%d)", toneInfo->handle);
1149 pthread_mutex_destroy(&g_control.syncker);
1152 debug_msg("Play end");
1153 pthread_mutex_lock(&toneInfo->mutex);
1154 toneInfo->state = STATE_NONE;
1155 pthread_mutex_unlock(&toneInfo->mutex);
1157 if (toneInfo->stop_cb)
1158 toneInfo->stop_cb(toneInfo->cb_param, false);
1164 int MMSoundPlugCodecToneStop(MMHandleType handle)
1166 tone_info_t *toneInfo = (tone_info_t*) handle;
1167 bool is_stop_request_done = false;
1169 debug_enter("(handle %p)", handle);
1170 pthread_mutex_lock(&toneInfo->mutex);
1171 /*If stopped why stop again*/
1172 if (toneInfo->state == STATE_NONE || toneInfo->state == STATE_STOP) {
1173 pthread_mutex_unlock(&toneInfo->mutex);
1174 debug_msg("state(%d) is already STOP or NONE. return", toneInfo->state);
1175 return MM_ERROR_NONE;
1177 toneInfo->is_stop_request_done = &is_stop_request_done;
1178 toneInfo->state = STATE_STOP;
1179 toneInfo->thread_state = THREAD_STATE_STOP;
1180 pthread_mutex_unlock(&toneInfo->mutex);
1181 debug_msg("sent stop signal");
1183 /* check whether stop is actually finished */
1184 while (is_stop_request_done == false)
1189 return MM_ERROR_NONE;
1193 int MMSoundPlugCodecToneSetThreadPool(int (*func)(void*, void (*)(void*)))
1195 debug_enter("(func : %p)", func);
1196 g_thread_pool_func = func;
1198 return MM_ERROR_NONE;
1202 static int _MMSoundToneInit(void)
1204 memset(&g_control, 0, sizeof(tone_control_t));
1205 pthread_mutex_init(&g_control.syncker, NULL);
1206 return MM_ERROR_NONE;
1209 static int _MMSoundToneFini(void)
1211 pthread_mutex_destroy(&g_control.syncker);
1212 return MM_ERROR_NONE;
1217 int MMSoundGetPluginType(void)
1221 return MM_SOUND_PLUGIN_TYPE_CODEC;
1225 int MMSoundPlugCodecGetInterface(mmsound_codec_interface_t *intf)
1229 intf->GetSupportTypes = MMSoundPlugCodecToneGetSupportTypes;
1230 intf->Create = MMSoundPlugCodecToneCreate;
1231 intf->Destroy = MMSoundPlugCodecToneDestroy;
1232 intf->Play = MMSoundPlugCodecTonePlay;
1233 intf->Stop = MMSoundPlugCodecToneStop;
1234 intf->SetThreadPool = MMSoundPlugCodecToneSetThreadPool;
1238 return MM_ERROR_NONE;