4 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: JongHyuk Choi <jhchoi.choi@samsung.com>,YeJin Cho <cho.yejin@samsung.com>, YoungHwan An <younghwan_.an@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 #include "mm_player_utils.h"
25 #include "mm_player_audioeffect.h"
26 #include "mm_player_ini.h"
27 #include "mm_player_priv.h"
32 mm_player_get_foreach_present_supported_effect_type(MMHandleType hplayer, MMAudioEffectType effect_type, mmplayer_supported_audio_effect_cb foreach_cb, void *user_data)
34 mm_player_t *player = NULL;
35 int result = MM_ERROR_NONE;
36 mm_sound_device_flags_e flags = MM_SOUND_DEVICE_IO_DIRECTION_OUT_FLAG | MM_SOUND_DEVICE_STATE_ACTIVATED_FLAG;
37 MMSoundDeviceList_t device_list;
38 MMSoundDevice_t device_h = NULL;
39 mm_sound_device_type_e device_type;
44 MMPLAYER_RETURN_VAL_IF_FAIL ( hplayer, MM_ERROR_PLAYER_NOT_INITIALIZED );
46 player = MM_PLAYER_CAST(hplayer);
48 /* get status if speaker is activated */
49 /* (1) get current device list */
50 result = mm_sound_get_current_device_list(flags, &device_list);
53 LOGE("mm_sound_get_current_device_list() failed [%x]!!", result);
58 /* (2) get device handle of device list */
59 result = mm_sound_get_next_device (device_list, &device_h);
62 LOGE("mm_sound_get_next_device() failed [%x]!!", result);
67 /* (3) get device type */
68 result = mm_sound_get_device_type(device_h, &device_type);
71 LOGE("mm_sound_get_device_type() failed [%x]!!", result);
77 if (effect_type == MM_AUDIO_EFFECT_TYPE_PRESET)
79 for ( i = 0; i < MM_AUDIO_EFFECT_PRESET_NUM; i++ )
81 if (player->ini.audio_effect_preset_list[i] )
83 if (device_type == MM_SOUND_DEVICE_TYPE_BUILTIN_SPEAKER &&
84 player->ini.audio_effect_preset_earphone_only_list[i])
88 if (!foreach_cb(effect_type,i, user_data))
96 else if (effect_type == MM_AUDIO_EFFECT_TYPE_CUSTOM)
98 for ( i = 0; i < MM_AUDIO_EFFECT_CUSTOM_NUM; i++ )
100 if (player->ini.audio_effect_custom_list[i] )
102 if (device_type == MM_SOUND_DEVICE_TYPE_BUILTIN_SPEAKER &&
103 player->ini.audio_effect_custom_earphone_only_list[i])
107 if (!foreach_cb(effect_type,i, user_data))
116 LOGE("invalid effect type(%d)", effect_type);
117 result = MM_ERROR_INVALID_ARGUMENT;
125 LOGE("foreach callback returned error");
127 return MM_ERROR_PLAYER_INTERNAL;
132 __mmplayer_set_harmony_effect(mm_player_t *player, GstElement *audio_effect_element)
134 gint *ext_effect_level_list = NULL;
135 int count = 1; /* start from 1, because of excepting eq index */
136 int ext_level_index = 0;
137 int result = MM_ERROR_NONE;
141 MMPLAYER_RETURN_VAL_IF_FAIL ( player, MM_ERROR_PLAYER_NOT_INITIALIZED );
142 MMPLAYER_RETURN_VAL_IF_FAIL ( audio_effect_element, MM_ERROR_INVALID_ARGUMENT );
145 if( player->ini.audio_effect_custom_eq_band_num )
147 LOGD("pass custom EQ level list to audio effect plugin");
148 /* set custom-equalizer level list */
149 g_object_set(audio_effect_element, "custom-eq", player->audio_effect_info.custom_eq_level, NULL);
153 LOGW("no custom EQ");
156 /* Custom Extension effects */
157 if( player->ini.audio_effect_custom_ext_num )
159 LOGD("pass custom extension level list to audio effect plugin");
160 ext_effect_level_list = player->audio_effect_info.custom_ext_level_for_plugin;
161 if (!ext_effect_level_list) {
162 ext_effect_level_list = (gint*) malloc (sizeof(gint)*player->ini.audio_effect_custom_ext_num);
163 if (!ext_effect_level_list)
165 LOGE("memory allocation for extension effect list failed");
166 return MM_ERROR_OUT_OF_MEMORY;
170 memset (ext_effect_level_list, 0, player->ini.audio_effect_custom_ext_num);
172 /* associate it to player handle */
173 player->audio_effect_info.custom_ext_level_for_plugin = ext_effect_level_list;
177 while ( count < MM_AUDIO_EFFECT_CUSTOM_NUM )
179 if ( player->ini.audio_effect_custom_list[count] )
181 ext_effect_level_list[ext_level_index] = player->audio_effect_info.custom_ext_level[count-1];
183 if (ext_level_index == player->ini.audio_effect_custom_ext_num)
191 /* set custom-extension effects level list */
192 g_object_set(audio_effect_element, "custom-ext", ext_effect_level_list, NULL);
196 LOGW("no custom extension effect");
199 /* order action to audio effect plugin */
200 g_object_set(audio_effect_element, "filter-action", MM_AUDIO_EFFECT_TYPE_CUSTOM, NULL);
201 LOGD("filter-action = %d", MM_AUDIO_EFFECT_TYPE_CUSTOM);
210 __mmplayer_is_earphone_only_effect_type(mm_player_t *player, MMAudioEffectType effect_type, int effect)
212 gboolean result = FALSE;
217 MMPLAYER_RETURN_VAL_IF_FAIL(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
220 if (effect_type == MM_AUDIO_EFFECT_TYPE_PRESET)
222 if (player->ini.audio_effect_preset_earphone_only_list[effect])
224 LOGI("this preset effect(%d) is only available with earphone", effect);
229 else if (effect_type == MM_AUDIO_EFFECT_TYPE_CUSTOM)
231 for (i = 1; i < MM_AUDIO_EFFECT_CUSTOM_NUM; i++) /* it starts from 1(except testing for EQ) */
233 if (player->ini.audio_effect_custom_earphone_only_list[i])
235 /* check if the earphone only custom effect was set */
236 if (player->audio_effect_info.custom_ext_level[i-1])
238 LOGI("this custom effect(%d) is only available with earphone", i);
246 LOGE("invalid effect type(%d)", effect_type);
255 __mmplayer_audio_set_output_type (mm_player_t *player, MMAudioEffectType effect_type, int effect)
257 GstElement *audio_effect_element = NULL;
258 mm_sound_device_flags_e flags = MM_SOUND_DEVICE_ALL_FLAG;
259 MMSoundDeviceList_t device_list;
260 MMSoundDevice_t device_h = NULL;
261 mm_sound_device_type_e device_type;
263 int result = MM_ERROR_NONE;
267 MMPLAYER_RETURN_VAL_IF_FAIL(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
269 audio_effect_element = player->pipeline->audiobin[MMPLAYER_A_FILTER].gst;
271 /* (1) get current device list */
272 result = mm_sound_get_current_device_list(flags, &device_list);
275 LOGE("mm_sound_get_current_device_list() failed [%x]!!", result);
280 /* (2) get device handle of device list */
281 result = mm_sound_get_next_device (device_list, &device_h);
284 LOGE("mm_sound_get_next_device() failed [%x]!!", result);
289 /* (3) get device type */
290 result = mm_sound_get_device_type(device_h, &device_type);
293 LOGE("mm_sound_get_device_type() failed [%x]!!", result);
299 if (device_type == MM_SOUND_DEVICE_TYPE_BUILTIN_SPEAKER)
301 if ( MM_AUDIO_EFFECT_TYPE_SQUARE != effect_type ) {
302 if (__mmplayer_is_earphone_only_effect_type(player, effect_type, effect))
304 LOGE("earphone is not equipped, this filter will not be applied");
306 return MM_ERROR_PLAYER_SOUND_EFFECT_INVALID_STATUS;
310 output_type = MM_AUDIO_EFFECT_OUTPUT_SPK;
312 else if (device_type == MM_SOUND_DEVICE_TYPE_MIRRORING)
314 output_type = MM_AUDIO_EFFECT_OUTPUT_OTHERS;
316 else if (device_type == MM_SOUND_DEVICE_TYPE_HDMI)
318 output_type = MM_AUDIO_EFFECT_OUTPUT_HDMI;
320 else if (device_type == MM_SOUND_DEVICE_TYPE_BLUETOOTH)
322 output_type = MM_AUDIO_EFFECT_OUTPUT_BT;
324 else if (device_type == MM_SOUND_DEVICE_TYPE_USB_AUDIO)
326 output_type = MM_AUDIO_EFFECT_OUTPUT_USB_AUDIO;
328 /* Other case, include WIRED_ACCESSORY */
331 output_type = MM_AUDIO_EFFECT_OUTPUT_EAR;
333 LOGW("output_type = %d (0:spk,1:ear,2:others)", output_type);
335 /* set filter output mode */
336 g_object_set(audio_effect_element, "filter-output-mode", output_type, NULL);
342 _mmplayer_is_supported_effect_type(mm_player_t* player, MMAudioEffectType effect_type, int effect)
344 gboolean result = TRUE;
345 mm_sound_device_flags_e flags = MM_SOUND_DEVICE_ALL_FLAG;
346 MMSoundDeviceList_t device_list;
347 MMSoundDevice_t device_h = NULL;
348 mm_sound_device_type_e device_type;
349 int ret = MM_ERROR_NONE;
353 /* get status if speaker is activated */
354 /* (1) get current device list */
355 ret = mm_sound_get_current_device_list(flags, &device_list);
358 LOGE("mm_sound_get_current_device_list() failed [%x]!!", ret);
362 /* (2) get device handle of device list */
363 ret = mm_sound_get_next_device (device_list, &device_h);
366 LOGE("mm_sound_get_next_device() failed [%x]!!", ret);
371 /* (3) get device type */
372 ret = mm_sound_get_device_type(device_h, &device_type);
375 LOGE("mm_sound_get_device_type() failed [%x]!!", ret);
381 if (effect_type == MM_AUDIO_EFFECT_TYPE_PRESET)
383 if ( effect < MM_AUDIO_EFFECT_PRESET_AUTO || effect >= MM_AUDIO_EFFECT_PRESET_NUM )
385 LOGE("out of range, preset effect(%d)", effect);
390 if (!player->ini.audio_effect_preset_list[effect])
392 LOGE("this effect(%d) is not supported", effect);
397 if (device_type == MM_SOUND_DEVICE_TYPE_BUILTIN_SPEAKER &&
398 player->ini.audio_effect_preset_earphone_only_list[effect])
406 else if (effect_type == MM_AUDIO_EFFECT_TYPE_CUSTOM)
408 if ( effect < MM_AUDIO_EFFECT_CUSTOM_EQ || effect >= MM_AUDIO_EFFECT_CUSTOM_NUM )
410 LOGE("out of range, custom effect(%d)", effect);
415 if (!player->ini.audio_effect_custom_list[effect])
417 LOGE("this custom effect(%d) is not supported", effect);
422 if (device_type == MM_SOUND_DEVICE_TYPE_BUILTIN_SPEAKER &&
423 player->ini.audio_effect_custom_earphone_only_list[effect])
430 else if (effect_type == MM_AUDIO_EFFECT_TYPE_SQUARE)
432 if (!player->ini.use_audio_effect_custom)
434 LOGE("Square effect is not supported");
440 LOGE("invalid effect type(%d)", effect_type);
451 _mmplayer_audio_effect_custom_apply(mm_player_t *player)
453 GstElement *audio_effect_element = NULL;
454 int result = MM_ERROR_NONE;
458 MMPLAYER_RETURN_VAL_IF_FAIL( player, MM_ERROR_PLAYER_NOT_INITIALIZED );
460 /* Music Player can set audio effect value before Audiobin is created. */
461 if ( !player->pipeline || !player->pipeline->audiobin || !player->pipeline->audiobin[MMPLAYER_A_FILTER].gst )
463 LOGW("effect element is not created yet.");
465 player->bypass_audio_effect = FALSE;
467 /* store audio effect setting in order to apply it when audio effect plugin is created */
468 player->audio_effect_info.effect_type = MM_AUDIO_EFFECT_TYPE_CUSTOM;
472 audio_effect_element = player->pipeline->audiobin[MMPLAYER_A_FILTER].gst;
474 /* get status if speaker is activated */
475 result = __mmplayer_audio_set_output_type(player, MM_AUDIO_EFFECT_TYPE_CUSTOM, 0);
477 if ( result != MM_ERROR_NONE) {
478 LOGE("failed to set output mode");
483 result = __mmplayer_set_harmony_effect(player, audio_effect_element);
486 LOGE("_set_harmony_effect() failed(%x)", result);
491 player->set_mode.rich_audio = TRUE;
499 _mmplayer_audio_effect_custom_update_level(mm_player_t *player)
501 GstElement *audio_effect_element = NULL;
502 int result = MM_ERROR_NONE;
503 int ext_level_index = 0;
506 gint *custom_eq = NULL;
507 gint *custom_ext_effect_level_list = NULL;
511 MMPLAYER_RETURN_VAL_IF_FAIL( player, MM_ERROR_PLAYER_NOT_INITIALIZED );
513 audio_effect_element = player->pipeline->audiobin[MMPLAYER_A_FILTER].gst;
515 /* get custom eq effect */
516 g_object_get(audio_effect_element, "custom-eq", &custom_eq, NULL);
518 memcpy(player->audio_effect_info.custom_eq_level, custom_eq, sizeof(gint) * player->ini.audio_effect_custom_eq_band_num);
520 for (i=0; i<player->ini.audio_effect_custom_eq_band_num;i++)
522 LOGD("updated custom-eq [%d] = %d", i, player->audio_effect_info.custom_eq_level[i]);
525 /* get custom ext effect */
527 g_object_get(audio_effect_element, "custom-ext", &custom_ext_effect_level_list, NULL);
529 while ( count < MM_AUDIO_EFFECT_CUSTOM_NUM )
531 if ( player->ini.audio_effect_custom_list[count] )
533 player->audio_effect_info.custom_ext_level[count-1]
534 = custom_ext_effect_level_list[ext_level_index];
535 LOGD("updated custom-ext [%d] = %d", count, player->audio_effect_info.custom_ext_level[count-1]);
548 mm_player_audio_effect_custom_clear_eq_all(MMHandleType hplayer)
550 int result = MM_ERROR_NONE;
551 mm_player_t* player = (mm_player_t*)hplayer;
555 MMPLAYER_RETURN_VAL_IF_FAIL(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
557 /* clear EQ custom effect */
558 memset(player->audio_effect_info.custom_eq_level, MM_AUDIO_EFFECT_CUSTOM_LEVEL_INIT, sizeof(int)*MM_AUDIO_EFFECT_EQ_BAND_NUM_MAX);
560 LOGI("All the EQ bands clearing success");
569 mm_player_audio_effect_custom_clear_ext_all(MMHandleType hplayer)
572 int result = MM_ERROR_NONE;
573 mm_player_t* player = (mm_player_t*)hplayer;
577 MMPLAYER_RETURN_VAL_IF_FAIL(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
579 /* clear ALL custom effects, except EQ */
580 for ( i = 0 ; i < MM_AUDIO_EFFECT_CUSTOM_NUM - 1 ; i++ )
582 player->audio_effect_info.custom_ext_level[i] = MM_AUDIO_EFFECT_CUSTOM_LEVEL_INIT;
585 LOGI("All the extension effects clearing success");
594 mm_player_is_supported_preset_effect_type(MMHandleType hplayer, MMAudioEffectPresetType effect)
596 mm_player_t* player = (mm_player_t*)hplayer;
597 int result = MM_ERROR_NONE;
601 MMPLAYER_RETURN_VAL_IF_FAIL(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
603 if ( !_mmplayer_is_supported_effect_type( player, MM_AUDIO_EFFECT_TYPE_PRESET, effect ) )
605 result = MM_ERROR_PLAYER_SOUND_EFFECT_NOT_SUPPORTED_FILTER;
615 mm_player_is_supported_custom_effect_type(MMHandleType hplayer, MMAudioEffectCustomType effect)
617 mm_player_t* player = (mm_player_t*)hplayer;
618 int result = MM_ERROR_NONE;
622 MMPLAYER_RETURN_VAL_IF_FAIL(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
624 if ( !_mmplayer_is_supported_effect_type( player, MM_AUDIO_EFFECT_TYPE_CUSTOM, effect ) )
626 result = MM_ERROR_PLAYER_SOUND_EFFECT_NOT_SUPPORTED_FILTER;
635 mm_player_audio_effect_custom_apply(MMHandleType hplayer)
637 mm_player_t* player = (mm_player_t*)hplayer;
638 int result = MM_ERROR_NONE;
642 MMPLAYER_RETURN_VAL_IF_FAIL(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
644 if (!player->ini.use_audio_effect_custom)
646 LOGE("audio effect(custom) is not supported");
648 return MM_ERROR_NOT_SUPPORT_API;
651 result = _mmplayer_audio_effect_custom_apply(player);
660 mm_player_audio_effect_bypass (MMHandleType hplayer)
662 mm_player_t* player = (mm_player_t*)hplayer;
663 int result = MM_ERROR_NONE;
664 GstElement *audio_effect_element = NULL;
668 MMPLAYER_RETURN_VAL_IF_FAIL(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
670 if ( !player->ini.use_audio_effect_preset && !player->ini.use_audio_effect_custom )
672 LOGE("audio effect(preset/custom) is not supported");
674 return MM_ERROR_NOT_SUPPORT_API;
676 if ( !player->pipeline || !player->pipeline->audiobin || !player->pipeline->audiobin[MMPLAYER_A_FILTER].gst )
678 LOGW("effect element is not created yet.");
682 audio_effect_element = player->pipeline->audiobin[MMPLAYER_A_FILTER].gst;
684 /* order action to audio effect plugin */
685 g_object_set(audio_effect_element, "filter-action", MM_AUDIO_EFFECT_TYPE_NONE, NULL);
686 LOGD("filter-action = %d", MM_AUDIO_EFFECT_TYPE_NONE);
696 _mmplayer_audio_effect_custom_set_level_ext(mm_player_t *player, MMAudioEffectCustomType custom_effect_type, int level)
698 int effect_level_max = 0;
699 int effect_level_min = 0;
700 int count = 1; /* start from 1, because of excepting eq index */
701 int ext_level_index = 1; /* start from 1, because of excepting eq index */
702 int result = MM_ERROR_NONE;
706 MMPLAYER_RETURN_VAL_IF_FAIL( player, MM_ERROR_PLAYER_NOT_INITIALIZED );
708 /* check if EQ is supported */
709 if ( !_mmplayer_is_supported_effect_type( player, MM_AUDIO_EFFECT_TYPE_CUSTOM, custom_effect_type ) )
712 return MM_ERROR_PLAYER_SOUND_EFFECT_NOT_SUPPORTED_FILTER;
715 while ( count < MM_AUDIO_EFFECT_CUSTOM_NUM )
717 if ( player->ini.audio_effect_custom_list[count] )
719 if ( count == custom_effect_type )
721 effect_level_min = player->ini.audio_effect_custom_min_level_list[ext_level_index];
722 effect_level_max = player->ini.audio_effect_custom_max_level_list[ext_level_index];
723 LOGI("level min value(%d), level max value(%d)", effect_level_min, effect_level_max);
727 if (ext_level_index == player->ini.audio_effect_custom_ext_num + 1)
729 LOGE("could not find min, max value. maybe effect information in ini file is not proper for audio effect plugin");
736 if ( level < effect_level_min || level > effect_level_max )
738 LOGE("out of range, level(%d)", level);
739 result = MM_ERROR_INVALID_ARGUMENT;
743 player->audio_effect_info.custom_ext_level[custom_effect_type-1] = level;
744 LOGI("set ext[%d] = %d", custom_effect_type-1, level);
754 _mmplayer_audio_effect_custom_set_level_eq(mm_player_t *player, int index, int level)
756 gint eq_level_max = 0;
757 gint eq_level_min = 0;
758 int result = MM_ERROR_NONE;
762 MMPLAYER_RETURN_VAL_IF_FAIL( player, MM_ERROR_PLAYER_NOT_INITIALIZED );
764 /* check if EQ is supported */
765 if ( !_mmplayer_is_supported_effect_type( player, MM_AUDIO_EFFECT_TYPE_CUSTOM, MM_AUDIO_EFFECT_CUSTOM_EQ ) )
768 return MM_ERROR_PLAYER_SOUND_EFFECT_NOT_SUPPORTED_FILTER;
771 if ( index < 0 || index > player->ini.audio_effect_custom_eq_band_num - 1 )
773 LOGE("out of range, index(%d)", index);
774 result = MM_ERROR_INVALID_ARGUMENT;
778 eq_level_min = player->ini.audio_effect_custom_min_level_list[MM_AUDIO_EFFECT_CUSTOM_EQ];
779 eq_level_max = player->ini.audio_effect_custom_max_level_list[MM_AUDIO_EFFECT_CUSTOM_EQ];
780 LOGI("EQ level min value(%d), EQ level max value(%d)", eq_level_min, eq_level_max);
782 if ( level < eq_level_min || level > eq_level_max )
784 LOGE("out of range, EQ level(%d)", level);
785 result = MM_ERROR_INVALID_ARGUMENT;
789 player->audio_effect_info.custom_eq_level[index] = level;
790 LOGI("set EQ[%d] = %d", index, level);
800 /* NOTE : parameter eq_index is only used for _set_eq_level() */
802 mm_player_audio_effect_custom_set_level(MMHandleType hplayer, MMAudioEffectCustomType effect_custom_type, int eq_index, int level)
804 mm_player_t* player = (mm_player_t*)hplayer;
805 int result = MM_ERROR_NONE;
809 MMPLAYER_RETURN_VAL_IF_FAIL( player, MM_ERROR_PLAYER_NOT_INITIALIZED );
811 /* check if this effect type is supported */
812 if ( !_mmplayer_is_supported_effect_type( player, MM_AUDIO_EFFECT_TYPE_CUSTOM, effect_custom_type ) )
814 result = MM_ERROR_PLAYER_SOUND_EFFECT_NOT_SUPPORTED_FILTER;
818 if (effect_custom_type == MM_AUDIO_EFFECT_CUSTOM_EQ)
820 result = _mmplayer_audio_effect_custom_set_level_eq(player, eq_index, level);
822 else if (effect_custom_type > MM_AUDIO_EFFECT_CUSTOM_EQ && effect_custom_type < MM_AUDIO_EFFECT_CUSTOM_NUM)
824 result = _mmplayer_audio_effect_custom_set_level_ext(player, effect_custom_type, level);
828 LOGE("out of range, effect type(%d)", effect_custom_type);
829 result = MM_ERROR_INVALID_ARGUMENT;
840 mm_player_audio_effect_custom_get_eq_bands_number(MMHandleType hplayer, int *bands)
842 mm_player_t* player = (mm_player_t*)hplayer;
843 int result = MM_ERROR_NONE;
847 MMPLAYER_RETURN_VAL_IF_FAIL( player, MM_ERROR_PLAYER_NOT_INITIALIZED );
849 /* check if EQ is supported */
850 if ( !_mmplayer_is_supported_effect_type( player, MM_AUDIO_EFFECT_TYPE_CUSTOM, MM_AUDIO_EFFECT_CUSTOM_EQ ) )
853 return MM_ERROR_PLAYER_SOUND_EFFECT_NOT_SUPPORTED_FILTER;
856 *bands = player->ini.audio_effect_custom_eq_band_num;
857 LOGD("number of custom EQ band = %d", *bands);
866 mm_player_audio_effect_custom_get_eq_bands_width(MMHandleType hplayer, int band_idx, int *width)
868 mm_player_t* player = (mm_player_t*)hplayer;
869 int result = MM_ERROR_NONE;
870 unsigned int eq_num = 0;
874 MMPLAYER_RETURN_VAL_IF_FAIL( player, MM_ERROR_PLAYER_NOT_INITIALIZED );
876 /* check if EQ is supported */
877 if ( !_mmplayer_is_supported_effect_type( player, MM_AUDIO_EFFECT_TYPE_CUSTOM, MM_AUDIO_EFFECT_CUSTOM_EQ ) )
880 return MM_ERROR_PLAYER_SOUND_EFFECT_NOT_SUPPORTED_FILTER;
883 eq_num = player->ini.audio_effect_custom_eq_band_num;
884 if (band_idx < 0 || band_idx > eq_num-1)
886 LOGE("out of range, invalid band_idx(%d)", band_idx);
887 result = MM_ERROR_INVALID_ARGUMENT;
891 /* set the width of EQ band */
892 *width = player->ini.audio_effect_custom_eq_band_width[band_idx];
893 LOGD("width of band_idx(%d) = %dHz", band_idx, *width);
903 mm_player_audio_effect_custom_get_eq_bands_freq(MMHandleType hplayer, int band_idx, int *freq)
905 mm_player_t* player = (mm_player_t*)hplayer;
906 int result = MM_ERROR_NONE;
907 unsigned int eq_num = 0;
911 MMPLAYER_RETURN_VAL_IF_FAIL( player, MM_ERROR_PLAYER_NOT_INITIALIZED );
913 /* check if EQ is supported */
914 if ( !_mmplayer_is_supported_effect_type( player, MM_AUDIO_EFFECT_TYPE_CUSTOM, MM_AUDIO_EFFECT_CUSTOM_EQ ) )
917 return MM_ERROR_PLAYER_SOUND_EFFECT_NOT_SUPPORTED_FILTER;
920 eq_num = player->ini.audio_effect_custom_eq_band_num;
921 if (band_idx < 0 || band_idx > eq_num-1)
923 LOGE("out of range, invalid band_idx(%d)", band_idx);
924 result = MM_ERROR_INVALID_ARGUMENT;
928 /* set the frequency of EQ band */
929 *freq = player->ini.audio_effect_custom_eq_band_freq[band_idx];
930 LOGD("frequency of band_idx(%d) = %dHz", band_idx, *freq);
940 mm_player_audio_effect_custom_get_level(MMHandleType hplayer, MMAudioEffectCustomType type, int eq_index, int *level)
942 mm_player_t* player = (mm_player_t*)hplayer;
943 int result = MM_ERROR_NONE;
947 MMPLAYER_RETURN_VAL_IF_FAIL( player, MM_ERROR_PLAYER_NOT_INITIALIZED );
948 MMPLAYER_RETURN_VAL_IF_FAIL( level, MM_ERROR_PLAYER_NOT_INITIALIZED );
950 /* check if this effect type is supported */
951 if ( !_mmplayer_is_supported_effect_type( player, MM_AUDIO_EFFECT_TYPE_CUSTOM, type ) )
954 return MM_ERROR_PLAYER_SOUND_EFFECT_NOT_SUPPORTED_FILTER;
957 if (type == MM_AUDIO_EFFECT_CUSTOM_EQ)
959 if ( eq_index < 0 || eq_index > player->ini.audio_effect_custom_eq_band_num - 1 )
961 LOGE("out of range, EQ index(%d)", eq_index);
962 result = MM_ERROR_INVALID_ARGUMENT;
966 *level = player->audio_effect_info.custom_eq_level[eq_index];
967 LOGD("EQ index = %d, level = %d", eq_index, *level);
970 else if ( type > MM_AUDIO_EFFECT_CUSTOM_EQ && type < MM_AUDIO_EFFECT_CUSTOM_NUM )
972 *level = player->audio_effect_info.custom_ext_level[type-1];
973 LOGD("extension effect index = %d, level = %d", type, *level);
977 LOGE("out of range, type(%d)", type);
978 result = MM_ERROR_INVALID_ARGUMENT;
988 mm_player_audio_effect_custom_get_level_range(MMHandleType hplayer, MMAudioEffectCustomType type, int *min, int *max)
990 mm_player_t* player = (mm_player_t*)hplayer;
991 int result = MM_ERROR_NONE;
992 int count = 1; /* start from 1, because of excepting eq index */
993 int ext_level_index = 1; /* start from 1, because of excepting eq index */
997 MMPLAYER_RETURN_VAL_IF_FAIL( player, MM_ERROR_PLAYER_NOT_INITIALIZED );
998 MMPLAYER_RETURN_VAL_IF_FAIL( min, MM_ERROR_PLAYER_NOT_INITIALIZED );
999 MMPLAYER_RETURN_VAL_IF_FAIL( max, MM_ERROR_PLAYER_NOT_INITIALIZED );
1001 /* check if this effect type is supported */
1002 if ( !_mmplayer_is_supported_effect_type( player, MM_AUDIO_EFFECT_TYPE_CUSTOM, type ) )
1005 return MM_ERROR_PLAYER_SOUND_EFFECT_NOT_SUPPORTED_FILTER;
1008 if ( type == MM_AUDIO_EFFECT_CUSTOM_EQ )
1010 *min = player->ini.audio_effect_custom_min_level_list[MM_AUDIO_EFFECT_CUSTOM_EQ];
1011 *max = player->ini.audio_effect_custom_max_level_list[MM_AUDIO_EFFECT_CUSTOM_EQ];
1012 LOGD("EQ min level = %d, max level = %d", *min, *max);
1016 while ( count < MM_AUDIO_EFFECT_CUSTOM_NUM )
1018 if ( player->ini.audio_effect_custom_list[count] )
1020 if ( count == type )
1022 *min = player->ini.audio_effect_custom_min_level_list[ext_level_index];
1023 *max = player->ini.audio_effect_custom_max_level_list[ext_level_index];
1024 LOGI("Extension effect(%d) min level = %d, max level = %d", count, *min, *max);
1028 if ( ext_level_index == player->ini.audio_effect_custom_ext_num + 1 )
1030 LOGE("could not find min, max value. maybe effect information in ini file is not proper for audio effect plugin");
1045 mm_player_audio_effect_custom_set_level_eq_from_list(MMHandleType hplayer, int *level_list, int size)
1047 mm_player_t *player = (mm_player_t*)hplayer;
1049 gint eq_level_min = 0;
1050 gint eq_level_max = 0;
1051 int result = MM_ERROR_NONE;
1055 MMPLAYER_RETURN_VAL_IF_FAIL( player, MM_ERROR_PLAYER_NOT_INITIALIZED );
1057 /* check if EQ is supported */
1058 if ( !_mmplayer_is_supported_effect_type( player, MM_AUDIO_EFFECT_TYPE_CUSTOM, MM_AUDIO_EFFECT_CUSTOM_EQ ) )
1061 return MM_ERROR_PLAYER_SOUND_EFFECT_NOT_SUPPORTED_FILTER;
1064 if ( size != player->ini.audio_effect_custom_eq_band_num )
1066 LOGE("input size variable(%d) does not match with number of eq band(%d)", size, player->ini.audio_effect_custom_eq_band_num);
1067 result = MM_ERROR_INVALID_ARGUMENT;
1071 eq_level_min = player->ini.audio_effect_custom_min_level_list[MM_AUDIO_EFFECT_CUSTOM_EQ];
1072 eq_level_max = player->ini.audio_effect_custom_max_level_list[MM_AUDIO_EFFECT_CUSTOM_EQ];
1074 for ( i = 0 ; i < size ; i++ )
1076 if ( level_list[i] < eq_level_min || level_list[i] > eq_level_max)
1078 LOGE("out of range, level[%d]=%d", i, level_list[i]);
1079 result = MM_ERROR_INVALID_ARGUMENT;
1082 player->audio_effect_info.custom_eq_level[i] = level_list[i];