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.
24 * @brief Application interface library for sound module.
28 * Application interface library for sound module.
31 #ifndef __MM_SOUND_H__
32 #define __MM_SOUND_H__
36 #include <mm_message.h>
46 This part is describes the sound module of multimedia framework. Sound
47 module provides APIs to implement play wav file with simple api, to handle volume information,
48 to handle audio route policy.
51 There is six different volume type for normal usage. application should set proper volume type to multimedia playback APIs.
55 <td><B>Description</B></td>
58 <td>VOLUME_TYPE_SYSTEM</td>
59 <td>volume for normal system sound (e.g. keysound, camera shutter)</td>
62 <td>VOLUME_TYPE_NOTIFICATION</td>
63 <td>volume for notification (e.g. message, email notification)</td>
66 <td>VOLUME_TYPE_RINGTONE</td>
67 <td>volume for incoming call ring</td>
70 <td>VOLUME_TYPE_MEDIA</td>
71 <td>volume for media playback (e.g. music, video playback)</td>
74 <td>VOLUME_TYPE_CALL</td>
75 <td>volume for call</td>
80 application can change audio route policy with mm-sound API.
81 Audio route is input and output of audio stream.
84 @image html audio_device.png "Figure1. Audio Devices of mobile phone" width=12cm
85 @image latex audio_device.png "Figure1. Audio Devices of mobile phone" width=12cm
88 Default audio route policy is like follows
93 <td><B>Bluetooth headset</B></td>
94 <td><B>Wired headset</B></td>
95 <td><B>Playback Device</B></td>
100 <td>Bluetooth headset</td>
105 <td>Bluetooth headset</td>
108 <td>disconnected</td>
110 <td>Wired headset</td>
113 <td>disconnected</td>
115 <td>Loud speaker</td>
120 for capture (bluetooth headset mic used only in call mode)
123 <td><B>Bluetooth headset mic</B></td>
124 <td><B>Wired headset mic</B></td>
125 <td><B>Capture Device</B></td>
130 <td>Wired headset mic</td>
138 <td>disconnected</td>
140 <td>Wired headset mic</td>
143 <td>disconnected</td>
145 <td>Wired headset mic</td>
150 If application changes routing policy to SYSTEM_AUDIO_ROUTE_POLICY_IGNORE_A2DP with mm_sound_route_set_system_policy
151 audio routing policy has changed to ignore bluetooth headset connection.
156 <td><B>Bluetooth headset</B></td>
157 <td><B>Wired headset</B></td>
158 <td><B>Playback Device</B></td>
163 <td>Wired headset</td>
168 <td>Loud speaker</td>
171 <td>disconnected</td>
173 <td>Wired headset</td>
176 <td>disconnected</td>
178 <td>Loud speaker</td>
183 for capture (bluetooth headset mic used only in call mode)
186 <td><B>Bluetooth headset mic</B></td>
187 <td><B>Wired headset mic</B></td>
188 <td><B>Capture Device</B></td>
193 <td>Wired headset mic</td>
201 <td>disconnected</td>
203 <td>Wired headset mic</td>
206 <td>disconnected</td>
208 <td>Wired headset mic</td>
213 If application changes routing policy to SYSTEM_AUDIO_ROUTE_POLICY_HANDSET_ONLY with mm_sound_route_set_system_policy
214 audio routing policy has changed to use only loud speaker and microphone.
219 <td><B>Bluetooth headset</B></td>
220 <td><B>Wired headset</B></td>
221 <td><B>Playback Device</B></td>
226 <td>Loud speaker</td>
231 <td>Loud speaker</td>
234 <td>disconnected</td>
236 <td>Loud speaker</td>
239 <td>disconnected</td>
241 <td>Loud speaker</td>
246 for capture (bluetooth headset mic used only in call mode)
249 <td><B>Bluetooth headset mic</B></td>
250 <td><B>Wired headset mic</B></td>
251 <td><B>Capture Device</B></td>
264 <td>disconnected</td>
269 <td>disconnected</td>
278 * MMSound Volume APIs
282 * Enumerations of Volume type.
286 VOLUME_TYPE_SYSTEM, /**< System volume type */
287 VOLUME_TYPE_NOTIFICATION, /**< Notification volume type */
288 VOLUME_TYPE_ALARM, /**< Alarm volume type */
289 VOLUME_TYPE_RINGTONE, /**< Ringtone volume type */
290 VOLUME_TYPE_MEDIA, /**< Media volume type */
291 VOLUME_TYPE_CALL, /**< Call volume type */
292 VOLUME_TYPE_VOIP, /**< VOIP volume type */
293 VOLUME_TYPE_FIXED, /**< Volume type for fixed acoustic level */
294 VOLUME_TYPE_EXT_JAVA, /**< External system volume for Java */
295 VOLUME_TYPE_MAX, /**< Volume type count */
296 VOLUME_TYPE_EXT_ANDROID = VOLUME_TYPE_FIXED, /**< External system volume for Android */
300 VOLUME_GAIN_DEFAULT = 0,
301 VOLUME_GAIN_DIALER = 1<<8,
302 VOLUME_GAIN_TOUCH = 2<<8,
303 VOLUME_GAIN_AF = 3<<8,
304 VOLUME_GAIN_SHUTTER1 = 4<<8,
305 VOLUME_GAIN_SHUTTER2 = 5<<8,
306 VOLUME_GAIN_CAMCORDING = 6<<8,
307 VOLUME_GAIN_MIDI = 7<<8,
308 VOLUME_GAIN_BOOTING = 8<<8,
309 VOLUME_GAIN_VIDEO = 9<<8,
310 VOLUME_GAIN_VIDEO_HDMI = 10<<8,
314 * Volume change callback function type.
316 * @param user_data [in] Argument passed when callback has called
318 * @return No return value
320 * @see mm_sound_volume_add_callback mm_sound_volume_remove_callback
322 typedef void (*volume_callback_fn)(void* user_data);
325 * This function is to retrieve number of volume level.
327 * @param type [in] volume type to query
328 * @param step [out] number of volume steps
330 * @return This function returns MM_ERROR_NONE on success, or negative value
332 * @remark step means number of steps. so actual volume step can be 0 ~ step-1
342 ret = mm_sound_volume_get_step(VOLUME_TYPE_SYSTEM, &step);
345 printf("Can not get volume step\n");
350 //set system volume to max value
351 mm_sound_volume_set_value(VOLUME_TYPE_SYSTEM, max);
355 int mm_sound_volume_get_step(volume_type_t type, int *step);
359 * This function is to add volume changed callback.
361 * @param type [in] volume type to set change callback function
362 * @param func [in] callback function pointer
363 * @param user_data [in] user data passing to callback function
365 * @return This function returns MM_ERROR_NONE on success, or negative value
367 * @remark Only one callback function per volume type will be registered.
368 * if you want to change callback function for certain volume type,
369 * remove callback first via mm_sound_volume_remove_callback().
370 * @see volume_type_t volume_callback_fn
371 * @pre There should be not be pre-registered callback fuction to given volume type.
372 * @post Callback function will be registered to given volume type
375 volume_type_t g_vol_type = VOLUME_TYPE_MEDIA;
377 void _volume_callback(void *data)
379 unsigned int value = 0;
381 volume_type_t *type = (volume_type_t*)data;
383 result = mm_sound_volume_get_value(*type, &value);
384 if(result == MM_ERROR_NONE)
386 printf("Current volume value is %d\n", value);
390 printf("Can not get volume\n");
398 ret = mm_sound_volume_add_callback(g_vol_type, _volume_callback, (void*)&g_vol_type);
399 if ( MM_ERROR_NONE != ret)
401 printf("Can not add callback\n");
405 printf("Add callback success\n");
413 int mm_sound_volume_add_callback(volume_type_t type, volume_callback_fn func, void* user_data);
417 * This function is to remove volume changed callback.
419 * @param type [in] volume type to set change callback function
421 * @return This function returns MM_ERROR_NONE on success, or negative value
424 * @pre Callback function should be registered previously for given volume type.
425 * @post Callback function will not be called anymore.
429 void _volume_callback(void *data)
431 printf("Callback function\n");
434 int volume_callback()
437 int vol_type = VOLUME_TYPE_MEDIA;
439 mm_sound_volume_add_callback(vol_type, _volume_callback, NULL);
441 ret = mm_sound_volume_remove_callback(vol_type);
442 if ( MM_ERROR_NONE == ret)
444 printf("Remove callback success\n");
448 printf("Remove callback failed\n");
456 int mm_sound_volume_remove_callback(volume_type_t type);
460 * This function is to set volume level of certain volume type.
462 * @param type [in] volume type to set value.
463 * @param value [in] volume value.
465 * @return This function returns MM_ERROR_NONE on success, or negative value
467 * @remark value should be 0 ~ mm_sound_volume_get_step() -1
468 * @see mm_sound_volume_get_step, mm_sound_volume_get_value volume_type_t
470 * @post Volume value will be changed to given value for given volume type.
477 ret = mm_sound_volume_get_step(VOLUME_TYPE_SYSTEM, &step);
480 printf("Can not get volume step\n");
485 //set system volume to max value
486 ret = mm_sound_volume_set_value(VOLUME_TYPE_SYSTEM, max);
489 printf("Can not set volume value\n");
494 int mm_sound_volume_set_value(volume_type_t type, const unsigned int value);
499 * This function is to get volume level of certain volume type.
501 * @param type [in] volume type to get value.
502 * @param value [out] volume value.
504 * @return This function returns MM_ERROR_NONE on success, or negative value
509 * @see volume_type_t mm_sound_volume_set_value
515 ret = mm_sound_volume_get_value(VOLUME_TYPE_SYSTEM, &value);
518 printf("Can not get volume\n");
522 printf("System type volume is %d\n", value);
525 * @see mm_sound_volume_set_value
527 int mm_sound_volume_get_value(volume_type_t type, unsigned int *value);
532 * This function is to set primary volume type.
534 * @param type [in] volume type to set as primary volume type.
536 * @return This function returns MM_ERROR_NONE on success, or negative value
538 * @remark Application should use this function during foreground.
539 * Application should clear primary volume type by mm_sound_volume_primary_type_clear() when it goes background.
541 * @post Volume app. will be update given volume type when H/W volume control key pressed.
542 * @see mm_sound_volume_primary_type_clear volume_type_t
545 static int _resume(void *data)
549 ret = mm_sound_volume_primary_type_set(VOLUME_TYPE_MEDIA);
552 printf("Can not set primary volume type\n");
557 static int _pause(void* data)
561 ret = mm_sound_volume_primary_type_clear();
564 printf("Can not clear primary volume type\n");
572 struct appcore_ops ops = {
574 .terminate = _terminate,
580 return appcore_efl_main(PACKAGE, ..., &ops);
584 int mm_sound_volume_primary_type_set(volume_type_t type);
589 * This function is to clear primary volume type.
592 * @return This function returns MM_ERROR_NONE on success, or negative value
594 * @remark mm_sound_volume_primary_type_set() and mm_sound_volume_primary_type_clear() should be used as pair
595 * @see mm_sound_volume_primary_type_set
596 * @pre primary volume should be set at same process.
597 * @post primary volume will be cleared.
600 static int _resume(void *data)
604 ret = mm_sound_volume_primary_type_set(VOLUME_TYPE_MEDIA);
607 printf("Can not set primary volume type\n");
612 static int _pause(void* data)
616 ret = mm_sound_volume_primary_type_clear();
619 printf("Can not clear primary volume type\n");
627 struct appcore_ops ops = {
629 .terminate = _terminate,
635 return appcore_efl_main(PACKAGE, ..., &ops);
639 int mm_sound_volume_primary_type_clear();
644 * This function is to get current playing volume type
646 * @param type [out] current playing volume type
648 * @return This function returns MM_ERROR_NONE on success,
649 * or MM_ERROR_SOUND_VOLUME_NO_INSTANCE when there is no existing playing instance,
650 * or MM_ERROR_SOUND_VOLUME_CAPTURE_ONLY when only capture audio instances are exist.
651 * or negative value with error code for other errors.
655 * @see mm_sound_volume_get_value, mm_sound_volume_set_value
659 volume_type_t type = 0;
661 ret = mm_sound_volume_get_current_playing_type(&type);
665 printf("Current playing is %d\n", type);
667 case MM_ERROR_SOUND_VOLUME_NO_INSTANCE:
668 printf("No sound instance\n");
670 case MM_ERROR_SOUND_VOLUME_CAPTURE_ONLY:
671 printf("Only sound capture instances are exist\n");
680 int mm_sound_volume_get_current_playing_type(volume_type_t *type);
686 typedef void* MMSoundPcmHandle_t; /**< MMsound PCM handle type */
689 * Enumerations of Format used in MMSoundPcm operation.
692 MMSOUND_PCM_U8 = 0x70, /**< unsigned 8bit audio */
693 MMSOUND_PCM_S16_LE, /**< signed 16bit audio */
694 } MMSoundPcmFormat_t;
697 * Enumerations of Channel count used in MMSoundPcm operation.
700 MMSOUND_PCM_MONO = 0x80, /**< Mono channel */
701 MMSOUND_PCM_STEREO, /**< Stereo channel */
702 }MMSoundPcmChannel_t;
706 * This function is to create handle for PCM playback.
708 * @param handle [out] handle to play pcm data
709 * @param rate [in] sample rate (8000Hz ~ 44100Hz)
710 * @param channel [in] number of channels (mono or stereo)
711 * @param format [in] S8 or S16LE
712 * @param volume [in] volume type
714 * @return This function returns suggested buffer size (in bytes) on success, or negative value
716 * @remark use mm_sound_volume_set_value() function to change volume
717 * @see mm_sound_pcm_play_write, mm_sound_pcm_play_close, mm_sound_volume_set_value, MMSoundPcmFormat_t, MMSoundPcmChannel_t volume_type_t
719 * @post PCM play handle will be created.
722 #include <mm_sound.h>
726 int main(int argc, char* argv[])
733 MMSoundPcmHandle_t handle;
734 char *filename = NULL;
738 printf("Usage) %s filename\n", argv[0]);
743 fp = fopen(filename,"r");
746 printf("Can not open file %s\n", filename);
750 size = mm_sound_pcm_play_open(&handle, 44100, MMSOUND_PCM_STEREO, MMSOUND_PCM_S16_LE, VOLUME_TYPE_SYSTEM);
753 printf("Can not open playback handle\n");
757 buffer = alloca(size);
758 while((readed = fread(buffer, size, sizeof(char), fp)) > 0 )
760 ret = mm_sound_pcm_play_write(handle, (void*)buffer, readed);
763 printf("write fail\n");
766 memset(buffer, '\0', sizeof(buffer));
770 mm_sound_pcm_play_close(handle);
775 int mm_sound_pcm_play_open(MMSoundPcmHandle_t *handle, const unsigned int rate, MMSoundPcmChannel_t channel, MMSoundPcmFormat_t format, const volume_type_t volume);
778 * This function start pcm playback
780 * @param handle [in] handle to start playback
782 * @return This function returns MM_ERROR_NONE on success, or negative value
786 * @pre PCM playback handle should be allocated.
787 * @post PCM playback is ready to write.
789 int mm_sound_pcm_play_start(MMSoundPcmHandle_t handle);
792 * This function stop pcm playback
794 * @param handle [in] handle to stop playback
796 * @return This function returns MM_ERROR_NONE on success, or negative value
800 * @pre PCM playback handle should be allocated.
801 * @post PCM playback data will not be buffered.
803 int mm_sound_pcm_play_stop(MMSoundPcmHandle_t handle);
806 * This function is to play PCM memory buffer.
808 * @param handle [in] handle to play pcm data
809 * @param ptr [in] pcm buffer address
810 * @param length_byte [in] size of pcm buffer (in bytes)
812 * @return This function returns written data size on success, or negative value
814 * @remark Make pcm buffer size with returned value of mm_sound_pcm_play_open()
815 * @see mm_sound_pcm_play_open, mm_sound_pcm_play_close
816 * @pre PCM play handle should be created.
817 * @post Sound will be generated with given PCM buffer data.
820 #include <mm_sound.h>
824 int main(int argc, char* argv[])
831 MMSoundPcmHandle_t handle;
832 char *filename = NULL;
836 printf("Usage) %s filename\n", argv[0]);
841 fp = fopen(filename,"r");
844 printf("Can not open file %s\n", filename);
848 size = mm_sound_pcm_play_open(&handle, 44100, MMSOUND_PCM_STEREO, MMSOUND_PCM_S16_LE, VOLUME_TYPE_SYSTEM);
851 printf("Can not open playback handle\n");
855 buffer = alloca(size);
856 while((readed = fread(buffer, size, sizeof(char), fp)) > 0 )
858 ret = mm_sound_pcm_play_write(handle, (void*)buffer, readed);
861 printf("write fail\n");
864 memset(buffer, '\0', sizeof(buffer));
868 mm_sound_pcm_play_close(handle);
873 int mm_sound_pcm_play_write(MMSoundPcmHandle_t handle, void* ptr, unsigned int length_byte);
878 * This function is to close PCM memory playback handle
880 * @param handle [in] handle to play pcm data
882 * @return This function returns MM_ERROR_NONE on success, or negative value
885 * @see mm_sound_pcm_play_open, mm_sound_pcm_play_write
886 * @pre PCM play handle should be created
887 * @post PCM play handle will be terminated.
890 #include <mm_sound.h>
894 int main(int argc, char* argv[])
901 MMSoundPcmHandle_t handle;
902 char *filename = NULL;
906 printf("Usage) %s filename\n", argv[0]);
911 fp = fopen(filename,"r");
914 printf("Can not open file %s\n", filename);
918 size = mm_sound_pcm_play_open(&handle, 44100, MMSOUND_PCM_STEREO, MMSOUND_PCM_S16_LE, VOLUME_TYPE_SYSTEM);
921 printf("Can not open playback handle\n");
925 buffer = alloca(size);
926 while((readed = fread(buffer, size, sizeof(char), fp)) > 0 )
928 ret = mm_sound_pcm_play_write(handle, (void*)buffer, readed);
931 printf("write fail\n");
934 memset(buffer, '\0', sizeof(buffer));
938 mm_sound_pcm_play_close(handle);
943 int mm_sound_pcm_play_close(MMSoundPcmHandle_t handle);
946 * This function is to ignore session for playback
948 * @param handle [in] handle to play pcm data
950 * @return This function returns MM_ERROR_NONE on success, or negative value
952 * @remark This function only works for not started pcm handle and can't be reversed.
954 * @pre PCM play handle should be created and not started.
955 * @post PCM play session will be set to mix.
957 int mm_sound_pcm_play_ignore_session(MMSoundPcmHandle_t *handle);
960 * This function is to create handle for PCM capture.
962 * @param handle [out] handle to capture pcm data
963 * @param rate [in] sample rate (8000Hz ~ 44100Hz)
964 * @param channel [in] number of channels (mono or stereo)
965 * @param format [in] S8 or S16LE
967 * @return This function returns suggested buffer size (in bytes) on success, or negative value
969 * @remark only mono channel is valid for now.
970 * @see mm_sound_pcm_capture_read, mm_sound_pcm_capture_close, MMSoundPcmFormat_t, MMSoundPcmChannel_t
972 * @post PCM capture handle will be allocated.
975 #include <mm_sound.h>
979 int main(int argc, char* argv[])
986 MMSoundPcmHandle_t handle;
987 char *filename = NULL;
991 printf("Usage) %s filename\n", argv[0]);
996 fp = fopen(filename,"w");
999 printf("Can not open file %s\n", filename);
1003 size = mm_sound_pcm_capture_open(&handle, 44100, MMSOUND_PCM_MONO, MMSOUND_PCM_S16_LE);
1006 printf("Can not open capture handle\n");
1010 buffer = alloca(size);
1013 ret = mm_sound_pcm_capture_read(handle, (void*)buffer, size);
1016 printf("read fail\n");
1019 fwrite(buffer, ret, sizeof(char), fp);
1026 mm_sound_pcm_capture_close(handle);
1032 int mm_sound_pcm_capture_open(MMSoundPcmHandle_t *handle, const unsigned int rate, MMSoundPcmChannel_t channel, MMSoundPcmFormat_t format);
1035 * This function start pcm capture
1037 * @param handle [in] handle to start capture
1039 * @return This function returns read data size on success, or negative value
1043 * @pre PCM capture handle should be allocated.
1044 * @post PCM capture data will be buffered.
1046 int mm_sound_pcm_capture_start(MMSoundPcmHandle_t handle);
1049 * This function stop pcm capture
1051 * @param handle [in] handle to stop capture
1053 * @return This function returns read data size on success, or negative value
1057 * @pre PCM capture handle should be allocated.
1058 * @post PCM capture data will not be buffered.
1060 int mm_sound_pcm_capture_stop(MMSoundPcmHandle_t handle);
1063 * This function captures PCM to memory buffer. (Samsung extension)
1065 * @param handle [in] handle to play pcm data
1066 * @param buffer [in] pcm buffer address
1067 * @param length [in] size of pcm buffer (in bytes)
1069 * @return This function returns read data size on success, or negative value
1071 * @remark Make pcm buffer size with returned value of mm_sound_pcm_capture_open()
1072 * @see mm_sound_pcm_capture_open, mm_sound_pcm_capture_close
1073 * @pre PCM capture handle should be allcated.
1074 * @post PCM data will be filled to given memory pointer.
1077 #include <mm_sound.h>
1081 int main(int argc, char* argv[])
1084 char *buffer = NULL;
1088 MMSoundPcmHandle_t handle;
1089 char *filename = NULL;
1093 printf("Usage) %s filename\n", argv[0]);
1098 fp = fopen(filename,"w");
1101 printf("Can not open file %s\n", filename);
1105 size = mm_sound_pcm_capture_open(&handle, 44100, MMSOUND_PCM_MONO, MMSOUND_PCM_S16_LE);
1108 printf("Can not open capture handle\n");
1112 buffer = alloca(size);
1115 ret = mm_sound_pcm_capture_read(handle, (void*)buffer, size);
1118 printf("read fail\n");
1121 fwrite(buffer, ret, sizeof(char), fp);
1128 mm_sound_pcm_capture_close(handle);
1134 int mm_sound_pcm_capture_read(MMSoundPcmHandle_t handle, void *buffer, const unsigned int length );
1137 * This function captures PCM memory to memory buffer (Samsung extension)
1139 * @param handle [in] handle to capture pcm data
1141 * @return This function returns MM_ERROR_NONE on success, or negative value
1144 * @see mm_sound_pcm_capture_open, mm_sound_pcm_capture_read
1145 * @pre PCM capture handle should be opend.
1146 * @post PCM capture handle will be freed.
1149 #include <mm_sound.h>
1153 int main(int argc, char* argv[])
1156 char *buffer = NULL;
1160 MMSoundPcmHandle_t handle;
1161 char *filename = NULL;
1165 printf("Usage) %s filename\n", argv[0]);
1170 fp = fopen(filename,"w");
1173 printf("Can not open file %s\n", filename);
1177 size = mm_sound_pcm_capture_open(&handle, 44100, MMSOUND_PCM_MONO, MMSOUND_PCM_S16_LE);
1180 printf("Can not open capture handle\n");
1184 buffer = alloca(size);
1187 ret = mm_sound_pcm_capture_read(handle, (void*)buffer, size);
1190 printf("read fail\n");
1193 fwrite(buffer, ret, sizeof(char), fp);
1200 mm_sound_pcm_capture_close(handle);
1206 int mm_sound_pcm_capture_close(MMSoundPcmHandle_t handle);
1209 * This function is to ignore session for capture
1211 * @param handle [in] handle to capture pcm data
1213 * @return This function returns MM_ERROR_NONE on success, or negative value
1215 * @remark This function only works for not started pcm handle and can't be reversed.
1217 * @pre PCM capture handle should be created and not started.
1218 * @post PCM capture session will be set to mix.
1220 int mm_sound_pcm_capture_ignore_session(MMSoundPcmHandle_t *handle);
1223 * This function sets callback function for receiving messages from pcm API.
1225 * @param handle [in] Handle of pcm.
1226 * @param callback [in] Message callback function.
1227 * @param user_param [in] User parameter which is passed to callback function.
1229 * @return This function returns MM_ERROR_NONE on success, or negative value with error code.
1230 * @see MMMessageCallback
1234 int msg_callback(int message, MMMessageParamType *param, void *user_param)
1238 case MM_MESSAGE_SOUND_PCM_CAPTURE_RESTRICTED:
1242 case MM_MESSAGE_SOUND_PCM_INTERRUPTED:
1252 mm_sound_pcm_set_message_callback(pcmHandle, msg_callback, (void *)pcmHandle);
1255 int mm_sound_pcm_set_message_callback (MMSoundPcmHandle_t handle, MMMessageCallback callback, void *user_param);
1258 * Terminate callback function type.
1260 * @param param [in] Argument passed when callback was set
1262 * @return No return value
1263 * @remark It is not allowed to call MMSound API recursively or do time-consuming
1264 * task in this callback because this callback is called synchronously.
1265 * @see mm_sound_play_sound
1267 typedef void (*mm_sound_stop_callback_func) (void *data);
1274 * This function is to play system sound.
1276 * @param filename [in] Sound filename to play
1277 * @param volume config [in] Volume type & volume gain
1278 * @param callback [in] Callback function pointer when playing is terminated.
1279 * @param data [in] Pointer to user data when callback is called.
1280 * @param handle [out] Handle of sound play.
1282 * @return This function returns MM_ERROR_NONE on success, or negative value
1284 * @remark When the stop callback is set, it will be called when system sound is
1285 * terminated. If mm_sound_stop_sound() is called apparently before
1286 * system sound is terminated, stop_callback will not be called.
1287 * @see mm_sound_stop_sound mm_sound_stop_callback_func volume_type_t volume_gain_t
1289 * @post Sound will be generated with given filename.
1293 void _stop_callback(void* data)
1295 printf("Stop callback\n");
1301 char filename[] ="/opt/media/Sound/testfile.wav";
1302 volume_type_t volume = VOLUME_TYPE_SYSTEM;
1306 ret = mm_sound_play_sound(filename, volume, _stop_callback, NULL, &handle);
1309 printf("play file failed\n");
1313 printf("play file success\n");
1319 printf("play stopped\n");
1324 int mm_sound_play_sound(const char *filename, int volume_config, mm_sound_stop_callback_func callback, void *data, int *handle);
1327 * This function is to play system sound. And other audio stream will be mute during playing time
1329 * @param filename [in] Sound filename to play
1330 * @param volume config [in] Volume type & volume gain
1331 * @param callback [in] Callback function pointer when playing is terminated.
1332 * @param data [in] Pointer to user data when callback is called.
1333 * @param handle [out] Handle of sound play.
1335 * @return This function returns MM_ERROR_NONE on success, or negative value
1337 * @remark This function is almost same with mm_sound_play_sound,
1338 * but this make other audio playback stream to mute during playing time.
1339 * @see mm_sound_stop_sound mm_sound_stop_callback_func volume_type_t volume_gain_t
1341 * @post Sound will be generated with given filename.
1345 void _stop_callback(void* data)
1347 printf("Stop callback\n");
1353 char filename[] ="/opt/media/Sound/testfile.wav";
1354 volume_type_t volume = VOLUME_TYPE_SYSTEM;
1358 ret = mm_sound_play_loud_solo_sound(filename, volume, _stop_callback, NULL, &handle);
1361 printf("play file failed\n");
1365 printf("play file success\n");
1371 printf("play stopped\n");
1376 int mm_sound_play_loud_solo_sound(const char *filename, int volume_config, mm_sound_stop_callback_func callback, void *data, int *handle);
1378 int mm_sound_play_loud_solo_sound_no_restore(const char *filename, int volume_config, mm_sound_stop_callback_func callback, void *data, int *handle);
1381 * This function is to stop playing system sound.
1383 * @param handle [in] Handle of mm_sound_play_sound
1385 * @return This function returns MM_ERROR_NONE on success, or negative value
1388 * @remark When system sound is terminated with this function call, it does not
1389 * call stop callback which was set when start playing system sound.
1390 * @see mm_sound_play_sound
1391 * @pre An sound play handle should be valid.
1392 * @post Playing sound file will be stopped.
1396 void _stop_callback(void* data)
1398 printf("Stop callback\n");
1402 int play_file_one_second()
1404 char filename[] ="/opt/media/Sound/testfile.wav";
1405 volume_type_t volume = VOLUME_TYPE_SYSTEM;
1409 ret = mm_sound_play_sound(filename, volume, _stop_callback, NULL, &handle);
1412 printf("play file failed\n");
1416 printf("play file success\n");
1419 sleep(1); //wait 1 second
1421 ret = mm_sound_stop_sound(handle);
1424 printf("stop failed\n");
1428 printf("play stopped\n");
1434 int mm_sound_stop_sound(int handle);
1438 * Enumerations for TONE
1442 MM_SOUND_TONE_DTMF_0 = 0, /**< Predefined DTMF 0 */
1443 MM_SOUND_TONE_DTMF_1, /**< Predefined DTMF 1 */
1444 MM_SOUND_TONE_DTMF_2, /**< Predefined DTMF 2 */
1445 MM_SOUND_TONE_DTMF_3, /**< Predefined DTMF 3 */
1446 MM_SOUND_TONE_DTMF_4, /**< Predefined DTMF 4 */
1447 MM_SOUND_TONE_DTMF_5, /**< Predefined DTMF 5 */
1448 MM_SOUND_TONE_DTMF_6, /**< Predefined DTMF 6 */
1449 MM_SOUND_TONE_DTMF_7, /**< Predefined DTMF 7 */
1450 MM_SOUND_TONE_DTMF_8, /**< Predefined DTMF 8 */
1451 MM_SOUND_TONE_DTMF_9, /**< Predefined DTMF 9 */
1452 MM_SOUND_TONE_DTMF_S, /**< Predefined DTMF Star - Asterisk (*) */
1453 MM_SOUND_TONE_DTMF_P, /**< Predefined DTMF sharP (#) */
1454 MM_SOUND_TONE_DTMF_A, /**< Predefined DTMF A (A) */
1455 MM_SOUND_TONE_DTMF_B, /**< Predefined DTMF B (B) */
1456 MM_SOUND_TONE_DTMF_C, /**< Predefined DTMF C (C) */
1457 MM_SOUND_TONE_DTMF_D, /**< Predefined DTMF D (D) */
1459 /**< Pre-defined TONE */
1460 MM_SOUND_TONE_SUP_DIAL, /**Call supervisory tone, Dial tone: CEPT: 425Hz, continuous */
1461 MM_SOUND_TONE_ANSI_DIAL, /**Call supervisory tone, Dial tone: ANSI (IS-95): 350Hz+440Hz, continuous */
1462 MM_SOUND_TONE_JAPAN_DIAL, /**Call supervisory tone, Dial tone: JAPAN: 400Hz, continuous*/
1463 MM_SOUND_TONE_SUP_BUSY, /**Call supervisory tone, Busy: CEPT: 425Hz, 500ms ON, 500ms OFF... */
1464 MM_SOUND_TONE_ANSI_BUSY, /**Call supervisory tone, Busy: ANSI (IS-95): 480Hz+620Hz, 500ms ON, 500ms OFF... */
1465 MM_SOUND_TONE_JAPAN_BUSY, /**Call supervisory tone, Busy: JAPAN: 400Hz, 500ms ON, 500ms OFF...*/
1466 MM_SOUND_TONE_SUP_CONGESTION, /**Call supervisory tone, Congestion: CEPT, JAPAN: 425Hz, 200ms ON, 200ms OFF */
1467 MM_SOUND_TONE_ANSI_CONGESTION, /**Call supervisory tone, Congestion: ANSI (IS-95): 480Hz+620Hz, 250ms ON, 250ms OFF... */
1468 MM_SOUND_TONE_SUP_RADIO_ACK, /**Call supervisory tone, Radio path acknowlegment : CEPT, ANSI: 425Hz, 200ms ON */
1469 MM_SOUND_TONE_JAPAN_RADIO_ACK, /**Call supervisory tone, Radio path acknowlegment : JAPAN: 400Hz, 1s ON, 2s OFF...*/
1470 MM_SOUND_TONE_SUP_RADIO_NOTAVAIL, /**Call supervisory tone, Radio path not available: 425Hz, 200ms ON, 200 OFF 3 bursts */
1471 MM_SOUND_TONE_SUP_ERROR, /**Call supervisory tone, Error/Special info: 950Hz+1400Hz+1800Hz, 330ms ON, 1s OFF... */
1472 MM_SOUND_TONE_SUP_CALL_WAITING, /**Call supervisory tone, Call Waiting: CEPT, JAPAN: 425Hz, 200ms ON, 600ms OFF, 200ms ON, 3s OFF... */
1473 MM_SOUND_TONE_ANSI_CALL_WAITING, /**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 ...) */
1474 MM_SOUND_TONE_SUP_RINGTONE, /**Call supervisory tone, Ring Tone: CEPT, JAPAN: 425Hz, 1s ON, 4s OFF... */
1475 MM_SOUND_TONE_ANSI_RINGTONE, /**Call supervisory tone, Ring Tone: ANSI (IS-95): 440Hz + 480Hz, 2s ON, 4s OFF... */
1476 MM_SOUND_TONE_PROP_BEEP, /**General beep: 400Hz+1200Hz, 35ms ON */
1477 MM_SOUND_TONE_PROP_ACK, /**Proprietary tone, positive acknowlegement: 1200Hz, 100ms ON, 100ms OFF 2 bursts */
1478 MM_SOUND_TONE_PROP_NACK, /**Proprietary tone, negative acknowlegement: 300Hz+400Hz+500Hz, 400ms ON */
1479 MM_SOUND_TONE_PROP_PROMPT, /**Proprietary tone, prompt tone: 400Hz+1200Hz, 200ms ON */
1480 MM_SOUND_TONE_PROP_BEEP2, /**Proprietary tone, general double beep: twice 400Hz+1200Hz, 35ms ON, 200ms OFF, 35ms ON */
1481 MM_SOUND_TONE_SUP_INTERCEPT, /**Call supervisory tone (IS-95), intercept tone: alternating 440 Hz and 620 Hz tones, each on for 250 ms */
1482 MM_SOUND_TONE_SUP_INTERCEPT_ABBREV, /**Call supervisory tone (IS-95), abbreviated intercept: intercept tone limited to 4 seconds */
1483 MM_SOUND_TONE_SUP_CONGESTION_ABBREV, /**Call supervisory tone (IS-95), abbreviated congestion: congestion tone limited to 4 seconds */
1484 MM_SOUND_TONE_SUP_CONFIRM, /**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 */
1485 MM_SOUND_TONE_SUP_PIP, /**Call supervisory tone (IS-95), pip tone: four bursts of 480 Hz tone (0.1 s on, 0.1 s off). */
1486 MM_SOUND_TONE_CDMA_DIAL_TONE_LITE, /**425Hz continuous */
1487 MM_SOUND_TONE_CDMA_NETWORK_USA_RINGBACK, /**CDMA USA Ringback: 440Hz+480Hz 2s ON, 4000 OFF ...*/
1488 MM_SOUND_TONE_CDMA_INTERCEPT, /**CDMA Intercept tone: 440Hz 250ms ON, 620Hz 250ms ON ...*/
1489 MM_SOUND_TONE_CDMA_ABBR_INTERCEPT, /**CDMA Abbr Intercept tone: 440Hz 250ms ON, 620Hz 250ms ON */
1490 MM_SOUND_TONE_CDMA_REORDER, /**CDMA Reorder tone: 480Hz+620Hz 250ms ON, 250ms OFF... */
1491 MM_SOUND_TONE_CDMA_ABBR_REORDER, /**CDMA Abbr Reorder tone: 480Hz+620Hz 250ms ON, 250ms OFF repeated for 8 times */
1492 MM_SOUND_TONE_CDMA_NETWORK_BUSY, /**CDMA Network Busy tone: 480Hz+620Hz 500ms ON, 500ms OFF continuous */
1493 MM_SOUND_TONE_CDMA_CONFIRM, /**CDMA Confirm tone: 350Hz+440Hz 100ms ON, 100ms OFF repeated for 3 times */
1494 MM_SOUND_TONE_CDMA_ANSWER, /**CDMA answer tone: silent tone - defintion Frequency 0, 0ms ON, 0ms OFF */
1495 MM_SOUND_TONE_CDMA_NETWORK_CALLWAITING, /**CDMA Network Callwaiting tone: 440Hz 300ms ON */
1496 MM_SOUND_TONE_CDMA_PIP, /**CDMA PIP tone: 480Hz 100ms ON, 100ms OFF repeated for 4 times */
1497 MM_SOUND_TONE_CDMA_CALL_SIGNAL_ISDN_NORMAL, /**ISDN Call Signal Normal tone: {2091Hz 32ms ON, 2556 64ms ON} 20 times, 2091 32ms ON, 2556 48ms ON, 4s OFF */
1498 MM_SOUND_TONE_CDMA_CALL_SIGNAL_ISDN_INTERGROUP, /**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.*/
1499 MM_SOUND_TONE_CDMA_CALL_SIGNAL_ISDN_SP_PRI, /**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 */
1500 MM_SOUND_TONE_CDMA_CALL_SIGNAL_ISDN_PAT3, /**SDN Call sign PAT3 tone: silent tone */
1501 MM_SOUND_TONE_CDMA_CALL_SIGNAL_ISDN_PING_RING, /**ISDN Ping Ring tone: {2091Hz 32ms ON, 2556Hz 64ms ON} 5 times 2091Hz 20ms ON */
1502 MM_SOUND_TONE_CDMA_CALL_SIGNAL_ISDN_PAT5, /**ISDN Pat5 tone: silent tone */
1503 MM_SOUND_TONE_CDMA_CALL_SIGNAL_ISDN_PAT6, /**ISDN Pat6 tone: silent tone */
1504 MM_SOUND_TONE_CDMA_CALL_SIGNAL_ISDN_PAT7, /**ISDN Pat7 tone: silent tone */
1505 MM_SOUND_TONE_CDMA_HIGH_L, /**TONE_CDMA_HIGH_L tone: {3700Hz 25ms, 4000Hz 25ms} 40 times 4000ms OFF, Repeat .... */
1506 MM_SOUND_TONE_CDMA_MED_L, /**TONE_CDMA_MED_L tone: {2600Hz 25ms, 2900Hz 25ms} 40 times 4000ms OFF, Repeat .... */
1507 MM_SOUND_TONE_CDMA_LOW_L, /**TONE_CDMA_LOW_L tone: {1300Hz 25ms, 1450Hz 25ms} 40 times, 4000ms OFF, Repeat .... */
1508 MM_SOUND_TONE_CDMA_HIGH_SS, /**CDMA HIGH SS tone: {3700Hz 25ms, 4000Hz 25ms} repeat 16 times, 400ms OFF, repeat .... */
1509 MM_SOUND_TONE_CDMA_MED_SS, /**CDMA MED SS tone: {2600Hz 25ms, 2900Hz 25ms} repeat 16 times, 400ms OFF, repeat .... */
1510 MM_SOUND_TONE_CDMA_LOW_SS, /**CDMA LOW SS tone: {1300z 25ms, 1450Hz 25ms} repeat 16 times, 400ms OFF, repeat .... */
1511 MM_SOUND_TONE_CDMA_HIGH_SSL, /**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 ... */
1512 MM_SOUND_TONE_CDMA_MED_SSL, /**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 ... */
1513 MM_SOUND_TONE_CDMA_LOW_SSL, /**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 ... */
1514 MM_SOUND_TONE_CDMA_HIGH_SS_2, /**CDMA HIGH SS2 tone: {3700Hz 25ms, 4000Hz 25ms} 20 times, 1000ms OFF, {3700Hz 25ms, 4000Hz 25ms} 20 times, 3000ms OFF, repeat .... */
1515 MM_SOUND_TONE_CDMA_MED_SS_2, /**CDMA MED SS2 tone: {2600Hz 25ms, 2900Hz 25ms} 20 times, 1000ms OFF, {2600Hz 25ms, 2900Hz 25ms} 20 times, 3000ms OFF, repeat .... */
1516 MM_SOUND_TONE_CDMA_LOW_SS_2, /**CDMA LOW SS2 tone: {1300Hz 25ms, 1450Hz 25ms} 20 times, 1000ms OFF, {1300Hz 25ms, 1450Hz 25ms} 20 times, 3000ms OFF, repeat .... */
1517 MM_SOUND_TONE_CDMA_HIGH_SLS, /**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 */
1518 MM_SOUND_TONE_CDMA_MED_SLS, /**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 */
1519 MM_SOUND_TONE_CDMA_LOW_SLS, /**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 */
1520 MM_SOUND_TONE_CDMA_HIGH_S_X4, /**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.... */
1521 MM_SOUND_TONE_CDMA_MED_S_X4, /**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.... */
1522 MM_SOUND_TONE_CDMA_LOW_S_X4, /**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....*/
1523 MM_SOUND_TONE_CDMA_HIGH_PBX_L, /**CDMA HIGH PBX L: {3700Hz 25ms, 4000Hz 25ms}20 times, 2000ms OFF, REPEAT.... */
1524 MM_SOUND_TONE_CDMA_MED_PBX_L, /**CDMA MED PBX L: {2600Hz 25ms, 2900Hz 25ms}20 times, 2000ms OFF, REPEAT.... */
1525 MM_SOUND_TONE_CDMA_LOW_PBX_L, /**CDMA LOW PBX L: {1300Hz 25ms,1450Hz 25ms}20 times, 2000ms OFF, REPEAT.... */
1526 MM_SOUND_TONE_CDMA_HIGH_PBX_SS, /**CDMA HIGH PBX SS tone: {3700Hz 25ms, 4000Hz 25ms} 8 times 200 ms OFF, {3700Hz 25ms 4000Hz 25ms}8 times, 2000ms OFF, REPEAT.... */
1527 MM_SOUND_TONE_CDMA_MED_PBX_SS, /**CDMA MED PBX SS tone: {2600Hz 25ms, 2900Hz 25ms} 8 times 200 ms OFF, {2600Hz 25ms 2900Hz 25ms}8 times, 2000ms OFF, REPEAT.... */
1528 MM_SOUND_TONE_CDMA_LOW_PBX_SS, /**CDMA LOW PBX SS tone: {1300Hz 25ms, 1450Hz 25ms} 8 times 200 ms OFF, {1300Hz 25ms 1450Hz 25ms}8 times, 2000ms OFF, REPEAT.... */
1529 MM_SOUND_TONE_CDMA_HIGH_PBX_SSL, /**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.... */
1530 MM_SOUND_TONE_CDMA_MED_PBX_SSL, /**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.... */
1531 MM_SOUND_TONE_CDMA_LOW_PBX_SSL, /**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.... */
1532 MM_SOUND_TONE_CDMA_HIGH_PBX_SLS, /**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.... */
1533 MM_SOUND_TONE_CDMA_MED_PBX_SLS, /**CDMA MED 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.... */
1534 MM_SOUND_TONE_CDMA_LOW_PBX_SLS, /**CDMA LOW 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.... */
1535 MM_SOUND_TONE_CDMA_HIGH_PBX_S_X4, /**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... */
1536 MM_SOUND_TONE_CDMA_MED_PBX_S_X4, /**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... */
1537 MM_SOUND_TONE_CDMA_LOW_PBX_S_X4, /**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... */
1538 MM_SOUND_TONE_CDMA_ALERT_NETWORK_LITE, /**CDMA Alert Network Lite tone: 1109Hz 62ms ON, 784Hz 62ms ON, 740Hz 62ms ON 622Hz 62ms ON, 1109Hz 62ms ON */
1539 MM_SOUND_TONE_CDMA_ALERT_AUTOREDIAL_LITE, /**CDMA Alert Auto Redial tone: {1245Hz 62ms ON, 659Hz 62ms ON} 3 times, 1245 62ms ON */
1540 MM_SOUND_TONE_CDMA_ONE_MIN_BEEP, /**CDMA One Min Beep tone: 1150Hz+770Hz 400ms ON */
1541 MM_SOUND_TONE_CDMA_KEYPAD_VOLUME_KEY_LITE, /**CDMA KEYPAD Volume key lite tone: 941Hz+1477Hz 120ms ON */
1542 MM_SOUND_TONE_CDMA_PRESSHOLDKEY_LITE, /**CDMA PRESSHOLDKEY LITE tone: 587Hz 375ms ON, 1175Hz 125ms ON */
1543 MM_SOUND_TONE_CDMA_ALERT_INCALL_LITE, /**CDMA ALERT INCALL LITE tone: 587Hz 62ms, 784 62ms, 831Hz 62ms, 784Hz 62ms, 1109 62ms, 784Hz 62ms, 831Hz 62ms, 784Hz 62ms*/
1544 MM_SOUND_TONE_CDMA_EMERGENCY_RINGBACK, /**CDMA EMERGENCY RINGBACK tone: {941Hz 125ms ON, 10ms OFF} 3times 4990ms OFF, REPEAT... */
1545 MM_SOUND_TONE_CDMA_ALERT_CALL_GUARD, /**CDMA ALERT CALL GUARD tone: {1319Hz 125ms ON, 125ms OFF} 3 times */
1546 MM_SOUND_TONE_CDMA_SOFT_ERROR_LITE, /**CDMA SOFT ERROR LITE tone: 1047Hz 125ms ON, 370Hz 125ms */
1547 MM_SOUND_TONE_CDMA_CALLDROP_LITE, /**CDMA CALLDROP LITE tone: 1480Hz 125ms, 1397Hz 125ms, 784Hz 125ms */
1548 MM_SOUND_TONE_CDMA_NETWORK_BUSY_ONE_SHOT, /**CDMA_NETWORK_BUSY_ONE_SHOT tone: 425Hz 500ms ON, 500ms OFF. */
1549 MM_SOUND_TONE_CDMA_ABBR_ALERT, /**CDMA_ABBR_ALERT tone: 1150Hz+770Hz 400ms ON */
1550 MM_SOUND_TONE_CDMA_SIGNAL_OFF, /**CDMA_SIGNAL_OFF - silent tone */
1554 typedef unsigned long sound_time_msec_t; /**< millisecond unit */
1557 * This function is to play tone sound.
1559 * @param num [in] predefined tone type (MMSoundTone_t)
1560 * volume config [in] volume type & volume gain
1561 * volume [in] volume ratio (0.0 ~1.0)
1562 * duration [in] millisecond (-1 for infinite)
1563 * handle [in] Handle of mm_sound_play_tone
1565 * @return This function returns MM_ERROR_NONE on success, or negative value
1568 * @remark It doesn't provide stop
1569 * @see volume_type_t volume_gain_t MMSoundTone_t
1571 * @post TONE sound will be played.
1576 ret = mm_sound_play_tone(MM_SOUND_TONE_DTMF_9, VOLUME_TYPE_SYSTEM, 1.0, 1000, &handle); //play 1 second with volume ratio 1.0
1579 printf("play tone failed\n");
1583 printf("play tone success\n");
1587 int mm_sound_play_tone (MMSoundTone_t num, int volume_config, const double volume, const int duration, int *handle);
1590 * Enumerations of System audio route policy
1593 SYSTEM_AUDIO_ROUTE_POLICY_DEFAULT, /**< Play via a2dp headset if connected. or play via headset if connected. or play via speaker.
1594 And capture via 4pole headset-mic if connected. or capture via mic */
1595 SYSTEM_AUDIO_ROUTE_POLICY_IGNORE_A2DP, /**< Play via headset if connected. or play via speaker
1596 And capture via 4pole headset-mic if connected. or capture via mic */
1597 SYSTEM_AUDIO_ROUTE_POLICY_HANDSET_ONLY, /**< Play via speaker. and capture via mic */
1598 SYSTEM_AUDIO_ROUTE_POLICY_MAX
1599 }system_audio_route_t;
1602 SYSTEM_AUDIO_ROUTE_PLAYBACK_DEVICE_NONE, /**< Abnormal case */
1603 SYSTEM_AUDIO_ROUTE_PLAYBACK_DEVICE_HANDSET, /**< Speaker or Headset or Earpiece */
1604 SYSTEM_AUDIO_ROUTE_PLAYBACK_DEVICE_BLUETOOTH, /**< Bluetooth */
1605 SYSTEM_AUDIO_ROUTE_PLAYBACK_DEVICE_EARPHONE, /**< Earphone */
1606 SYSTEM_AUDIO_ROUTE_PLAYBACK_DEVICE_MAX,
1607 }system_audio_route_device_t;
1610 SYSTEM_AUDIO_CAPTURE_NONE, /**< Capture device is not in use */
1611 SYSTEM_AUDIO_CAPTURE_ACTIVE, /**< Capture device is in use */
1612 SYSTEM_AUDIO_CAPTURE_MAX,
1613 }system_audio_capture_status_t;
1617 * This function set system route policy.
1619 * @param route [in] audio route type
1621 * @return This function returns MM_ERROR_NONE on success, or negative value
1623 * @remark If bluetooth has disconnected during SYSTEM_AUDIO_ROUTE_POLICY_IGNORE_A2DP policy,
1624 * The audio route policy will be changed to SYSTEM_AUDIO_ROUTE_POLICY_DEFAULT.
1625 * @see mm_sound_route_get_system_policy system_audio_route_t mm_sound_route_is_a2dp_on
1627 * @post Audio routing policy will be changed with given type. And route change callback function will be called if registered.
1631 void _stop_callback()
1636 int play_file_via_speaker()
1639 system_audio_route_t route, original_route;
1641 //get backup current policy
1642 ret = mm_sound_route_get_system_policy(&original_route);
1645 printf("Can not get system audio route policy\n");
1649 //set route policy to ignore a2dp
1650 route = SYSTEM_AUDIO_ROUTE_POLICY_IGNORE_A2DP;
1651 ret = mm_sound_route_set_system_policy(route);
1654 printf("Ca not set route policy\n");
1660 ret = mm_sound_play_sound("/opt/media/Sound/alert.wav", VOLUME_TYPE_SYSTEM, NULL, NULL, &handle);
1663 printf("Can not play wav file\n");
1671 //restore original policy
1672 mm_sound_route_set_system_policy(original_route);
1680 int mm_sound_route_set_system_policy (system_audio_route_t route);
1683 * This function get sysytem route policy.
1685 * @param route [out] audio route type
1687 * @return This function returns MM_ERROR_NONE on success, or negative value
1690 * @see mm_sound_route_set_system_policy system_audio_route_t mm_sound_route_is_a2dp_on
1696 void _stop_callback()
1701 int play_file_via_speaker()
1704 system_audio_route_t route, original_route;
1706 //get backup current policy
1707 ret = mm_sound_route_get_system_policy(&original_route);
1710 printf("Can not get system audio route policy\n");
1714 //set route policy to ignore a2dp
1715 route = SYSTEM_AUDIO_ROUTE_POLICY_IGNORE_A2DP;
1716 ret = mm_sound_route_set_system_policy(route);
1719 printf("Can not set route policy\n");
1725 ret = mm_sound_play_sound("/opt/media/Sound/alert.wav", VOLUME_TYPE_SYSTEM, NULL, NULL, &handle);
1728 printf("Can not play wav file\n");
1736 //restore original policy
1737 mm_sound_route_set_system_policy(original_route);
1745 int mm_sound_route_get_system_policy (system_audio_route_t *route);
1750 * This function get a2dp activation information.
1752 * @param connected [out] is Bluetooth A2DP connected (1:connected, 0:not connected)
1753 * bt_name [out] Bluetooth A2DP connected device name (allocated by internal when connected=1 otherwise set to null)
1756 * @return This function returns MM_ERROR_NONE on success, or negative value
1758 * @remark This function allocation memory to given bt_name pointer internally.
1759 * So application should free given memory pointer later after use.
1760 * bt_name will be null if there's no a2dp device is connected (connected is 0)
1761 * @see mm_sound_route_set_system_policy mm_sound_route_get_system_policy
1763 * @post memory buffer will be allocated and fill with bluetooth device name.
1768 char* bt_name = NULL;
1769 ret = mm_sound_route_get_a2dp_status (&connected, &bt_name);
1771 if (ret == MM_ERROR_NONE) {
1772 g_print ("### Is Bluetooth A2DP On Success : connected=[%d] name=[%s]\n", connected, bt_name);
1776 g_print ("### Is Bluetooth A2DP On Error : errno [%d]\n", ret);
1780 int mm_sound_route_get_a2dp_status (bool* connected, char** bt_name);
1784 * This function get current playing device.
1786 * @param dev [out] current playing device information
1788 * @return This function returns MM_ERROR_NONE on success, or negative value
1790 * @remark if there is no running instance in system,
1791 * output parameter dev can be SYSTEM_AUDIO_ROUTE_PLAYING_DEVICE_NONE.
1793 * @see system_audio_route_device_t
1799 system_audio_route_device_t dev;
1801 ret = mm_sound_route_get_playing_device (&dev);
1802 if(ret == MM_ERROR_NONE)
1806 case SYSTEM_AUDIO_ROUTE_PLAYBACK_DEVICE_HANDSET:
1807 printf("Handset is playing\n");
1809 case SYSTEM_AUDIO_ROUTE_PLAYBACK_DEVICE_BLUETOOTH:
1810 printf("Bluetooth is playing\n");
1812 case SYSTEM_AUDIO_ROUTE_PLAYBACK_DEVICE_NONE:
1814 printf("Unexptected\n");
1820 printf ("Can not get current running device\n");
1825 int mm_sound_route_get_playing_device(system_audio_route_device_t *dev);
1829 * Audio route policy change callback function type.
1831 * @param user_data [in] Argument passed when callback has called
1832 * @param policy [in] changed policy type
1834 * @return No return value
1836 * @see mm_sound_volume_add_callback mm_sound_volume_remove_callback
1838 typedef void (*audio_route_policy_changed_callback_fn)(void* user_data, system_audio_route_t policy);
1841 * This function set system audio policy changed callback function.
1843 * @param func [in] callback function pointer
1844 * @param user_data [in] user data will be called with func
1846 * @return This function returns MM_ERROR_NONE on success, or negative value
1849 * @see mm_sound_route_remove_change_callback mm_sound_route_set_system_policy mm_sound_route_get_system_policy system_audio_route_t
1854 void audio_route_policy_changed_callback(void* data, system_audio_route_t policy)
1856 int value = (int) data;
1857 system_audio_route_t lv_policy;
1858 char *str_route[SYSTEM_AUDIO_ROUTE_POLICY_MAX] = {
1859 "DEFAULT","IGN_A2DP","HANDSET"
1861 printf("Audio Route Policy has changed to [%s]\n", str_route[policy]);
1862 printf("user data : %d\n", value);
1863 if(0 > mm_sound_route_get_system_policy(&lv_policy)) {
1864 printf("Can not get policy...in callback function\n");
1867 printf("readed policy [%s]\n", str_route[lv_policy]);
1873 ret = mm_sound_route_add_change_callback(audio_route_policy_changed_callback, (void*)111);
1876 printf("Can not add callback\n");
1882 int mm_sound_route_add_change_callback(audio_route_policy_changed_callback_fn func, void* user_data);
1885 * This function remove system audio policy changed callback function.
1887 * @return This function returns MM_ERROR_NONE on success, or negative value
1890 * @see mm_sound_route_add_change_callback mm_sound_route_set_system_policy mm_sound_route_get_system_policy system_audio_route_t
1891 * @pre Sound route change callback should be registered.
1892 * @post Sound route change callback deregistered and does not be called anymore.
1895 void audio_route_policy_changed_callback(void* data, system_audio_route_t policy)
1897 int value = (int) data;
1898 system_audio_route_t lv_policy;
1899 char *str_route[SYSTEM_AUDIO_ROUTE_POLICY_MAX] = {
1900 "DEFAULT","IGN_A2DP","HANDSET"
1902 printf("Audio Route Policy has changed to [%s]\n", str_route[policy]);
1903 printf("user data : %d\n", value);
1904 if(0 > mm_sound_route_get_system_policy(&lv_policy)) {
1905 printf("Can not get policy...in callback function\n");
1908 printf("readed policy [%s]\n", str_route[lv_policy]);
1914 ret = mm_sound_route_add_change_callback(audio_route_policy_changed_callback, (void*)111);
1917 printf("Can not add callback\n");
1921 ret = mm_sound_route_remove_change_callback();
1924 printf("Can not remove callback\n");
1931 int mm_sound_route_remove_change_callback(void);
1934 * Enumerations of device & route
1938 MM_SOUND_DEVICE_IN_NONE = 0x00,
1939 MM_SOUND_DEVICE_IN_MIC = 0x01, /**< Device builtin mic. */
1940 MM_SOUND_DEVICE_IN_WIRED_ACCESSORY = 0x02, /**< Wired input devices */
1941 MM_SOUND_DEVICE_IN_BT_SCO = 0x04, /**< Bluetooth SCO device */
1942 } mm_sound_device_in;
1945 MM_SOUND_DEVICE_OUT_NONE = 0x000,
1946 MM_SOUND_DEVICE_OUT_SPEAKER = 0x001<<8, /**< Device builtin speaker */
1947 MM_SOUND_DEVICE_OUT_RECEIVER = 0x002<<8, /**< Device builtin receiver */
1948 MM_SOUND_DEVICE_OUT_WIRED_ACCESSORY = 0x004<<8, /**< Wired output devices such as headphone, headset, and so on. */
1949 MM_SOUND_DEVICE_OUT_BT_SCO = 0x008<<8, /**< Bluetooth SCO device */
1950 MM_SOUND_DEVICE_OUT_BT_A2DP = 0x010<<8, /**< Bluetooth A2DP device */
1951 MM_SOUND_DEVICE_OUT_DOCK = 0x020<<8, /**< DOCK device */
1952 MM_SOUND_DEVICE_OUT_HDMI = 0x040<<8, /**< HDMI device */
1953 MM_SOUND_DEVICE_OUT_WFD = 0x080<<8, /**< WFD device */
1954 MM_SOUND_DEVICE_OUT_USB_AUDIO = 0x100<<8, /**< USB Audio device */
1955 } mm_sound_device_out;
1957 #define MM_SOUND_ROUTE_NUM 14
1960 MM_SOUND_ROUTE_OUT_SPEAKER = MM_SOUND_DEVICE_OUT_SPEAKER, /**< Routing audio output to builtin device such as internal speaker. */
1961 MM_SOUND_ROUTE_OUT_WIRED_ACCESSORY = MM_SOUND_DEVICE_OUT_WIRED_ACCESSORY,/**< Routing audio output to wired accessory such as headphone, headset, and so on. */
1962 MM_SOUND_ROUTE_OUT_BLUETOOTH = MM_SOUND_DEVICE_OUT_BT_A2DP, /**< Routing audio output to bluetooth A2DP. */
1963 MM_SOUND_ROUTE_OUT_DOCK = MM_SOUND_DEVICE_OUT_DOCK, /**< Routing audio output to DOCK */
1964 MM_SOUND_ROUTE_OUT_HDMI = MM_SOUND_DEVICE_OUT_HDMI, /**< Routing audio output to HDMI */
1965 MM_SOUND_ROUTE_OUT_WFD = MM_SOUND_DEVICE_OUT_WFD, /**< Routing audio output to WFD */
1966 MM_SOUND_ROUTE_OUT_USB_AUDIO = MM_SOUND_DEVICE_OUT_USB_AUDIO, /**< Routing audio output to USB Audio */
1967 MM_SOUND_ROUTE_IN_MIC = MM_SOUND_DEVICE_IN_MIC, /**< Routing audio input to device builtin mic. */
1968 MM_SOUND_ROUTE_IN_WIRED_ACCESSORY = MM_SOUND_DEVICE_IN_WIRED_ACCESSORY, /**< Routing audio input to wired accessory. */
1969 MM_SOUND_ROUTE_IN_MIC_OUT_RECEIVER = MM_SOUND_DEVICE_IN_MIC | MM_SOUND_DEVICE_OUT_RECEIVER, /**< Routing audio input to device builtin mic and routing audio output to builtin receiver*/
1970 MM_SOUND_ROUTE_IN_MIC_OUT_SPEAKER = MM_SOUND_DEVICE_IN_MIC | MM_SOUND_DEVICE_OUT_SPEAKER , /**< Routing audio input to device builtin mic and routing audio output to builtin speaker */
1971 MM_SOUND_ROUTE_IN_MIC_OUT_HEADPHONE = MM_SOUND_DEVICE_IN_MIC | MM_SOUND_DEVICE_OUT_WIRED_ACCESSORY,/**< Routing audio input to device builtin mic and routing audio output to headphone */
1972 MM_SOUND_ROUTE_INOUT_HEADSET = MM_SOUND_DEVICE_IN_WIRED_ACCESSORY | MM_SOUND_DEVICE_OUT_WIRED_ACCESSORY, /**< Routing audio input and output to headset*/
1973 MM_SOUND_ROUTE_INOUT_BLUETOOTH = MM_SOUND_DEVICE_IN_BT_SCO | MM_SOUND_DEVICE_OUT_BT_SCO /**< Routing audio input and output to bluetooth SCO */
1976 typedef int (*mm_sound_available_route_cb)(mm_sound_route route, void *user_data);
1978 int mm_sound_is_route_available(mm_sound_route route, bool *is_available);
1980 int mm_sound_foreach_available_route_cb(mm_sound_available_route_cb, void *user_data);
1982 int mm_sound_set_active_route(mm_sound_route route);
1985 * This function is to get active playback device and capture device.
1987 * @param playback_device [out] playback device.
1988 * @param capture_device [out] capture device.
1990 * @return This function returns MM_ERROR_NONE on success, or negative value
1995 * @see mm_sound_set_active_route mm_sound_device_in mm_sound_device_out
1997 int mm_sound_get_active_device(mm_sound_device_in *device_in, mm_sound_device_out *device_out);
2000 * Active device changed callback function type.
2002 * @param user_data [in] Argument passed when callback has called
2004 * @return No return value
2006 * @see mm_sound_add_active_device_changed_callback mm_sound_remove_active_device_changed_callback
2008 typedef void (*mm_sound_active_device_changed_cb) (mm_sound_device_in device_in, mm_sound_device_out device_out, void *user_data);
2011 * This function is to add active device callback.
2013 * @param func [in] callback function pointer
2014 * @param user_data [in] user data passing to callback function
2016 * @return This function returns MM_ERROR_NONE on success, or negative value
2019 * @see mm_sound_remove_active_device_changed_callback mm_sound_active_device_changed_cb
2025 void __active_device_callback(void *user_data)
2027 printf("Callback function\n");
2030 int active_device_control()
2034 ret = mm_sound_add_active_device_changed_callback(__active_device_callback, NULL);
2035 if ( MM_ERROR_NONE != ret)
2037 printf("Can not add callback\n");
2041 printf("Add callback success\n");
2049 int mm_sound_add_active_device_changed_callback(mm_sound_active_device_changed_cb func, void *user_data);
2052 * This function is to remove active device callback.
2054 * @return This function returns MM_ERROR_NONE on success, or negative value
2057 * @pre Active device callback should be registered.
2058 * @post Active device callback deregistered and does not be called anymore.
2059 * @see mm_sound_add_active_device_changed_callback mm_sound_active_device_changed_cb
2062 void __active_device_callback(void *data)
2064 printf("Callback function\n");
2067 int active_device_control()
2071 mm_sound_add_active_device_changed_callback(__active_device_callback, NULL);
2073 ret = mm_sound_remove_active_device_changed_callback();
2074 if ( MM_ERROR_NONE == ret)
2076 printf("Remove callback success\n");
2080 printf("Remove callback failed\n");
2088 int mm_sound_remove_active_device_changed_callback(void);
2091 * Available route changed callback function type.
2093 * @param user_data [in] Argument passed when callback has called
2095 * @return No return value
2097 * @see mm_sound_add_active_device_changed_callback mm_sound_remove_active_device_changed_callback
2099 typedef void (*mm_sound_available_route_changed_cb) (mm_sound_route route, bool available, void *user_data);
2102 * This function is to add available device callback.
2104 * @param func [in] callback function pointer
2105 * @param user_data [in] user data passing to callback function
2107 * @return This function returns MM_ERROR_NONE on success, or negative value
2110 * @see mm_sound_remove_available_route_changed_callback mm_sound_active_device_changed_cb
2116 void __available_device_callback(void *user_data)
2118 printf("Callback function\n");
2121 int available_device_control()
2125 ret = mm_sound_add_available_route_changed_callback(__available_device_callback, NULL);
2126 if ( MM_ERROR_NONE != ret)
2128 printf("Can not add callback\n");
2132 printf("Add callback success\n");
2140 int mm_sound_add_available_route_changed_callback(mm_sound_available_route_changed_cb func, void *user_data);
2143 * This function is to remove available device callback.
2145 * @return This function returns MM_ERROR_NONE on success, or negative value
2148 * @pre available device callback should be registered.
2149 * @post available device callback deregistered and does not be called anymore.
2150 * @see mm_sound_add_available_route_changed_callback mm_sound_active_device_changed_cb
2153 void __available_device_callback(void *data)
2155 printf("Callback function\n");
2158 int available_device_control()
2162 mm_sound_add_available_route_changed_callback(__available_device_callback, NULL);
2164 ret = mm_sound_remove_available_route_changed_callback();
2165 if ( MM_ERROR_NONE == ret)
2167 printf("Remove callback success\n");
2171 printf("Remove callback failed\n");
2179 int mm_sound_remove_available_route_changed_callback(void);
2188 #endif /* __MM_SOUND_H__ */