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);
76 if (effect_type == MM_AUDIO_EFFECT_TYPE_PRESET) {
78 for (i = 0; i < MM_AUDIO_EFFECT_PRESET_NUM; i++) {
79 if (player->ini.audio_effect_preset_list[i]) {
80 if (device_type == MM_SOUND_DEVICE_TYPE_BUILTIN_SPEAKER &&
81 player->ini.audio_effect_preset_earphone_only_list[i])
84 if (!foreach_cb(effect_type, i, user_data))
88 } else if (effect_type == MM_AUDIO_EFFECT_TYPE_CUSTOM) {
90 for (i = 0; i < MM_AUDIO_EFFECT_CUSTOM_NUM; i++) {
91 if (player->ini.audio_effect_custom_list[i]) {
92 if (device_type == MM_SOUND_DEVICE_TYPE_BUILTIN_SPEAKER &&
93 player->ini.audio_effect_custom_earphone_only_list[i]) {
96 if (!foreach_cb(effect_type, i, user_data))
101 LOGE("invalid effect type(%d)", effect_type);
102 result = MM_ERROR_INVALID_ARGUMENT;
110 LOGE("foreach callback returned error");
112 return MM_ERROR_PLAYER_INTERNAL;
117 __mmplayer_set_harmony_effect(mm_player_t *player, GstElement *audio_effect_element)
119 gint *ext_effect_level_list = NULL;
120 int count = 1; /* start from 1, because of excepting eq index */
121 int ext_level_index = 0;
122 int result = MM_ERROR_NONE;
126 MMPLAYER_RETURN_VAL_IF_FAIL(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
127 MMPLAYER_RETURN_VAL_IF_FAIL(audio_effect_element, MM_ERROR_INVALID_ARGUMENT);
130 if (player->ini.audio_effect_custom_eq_band_num) {
131 LOGD("pass custom EQ level list to audio effect plugin");
132 /* set custom-equalizer level list */
133 g_object_set(audio_effect_element, "custom-eq", player->audio_effect_info.custom_eq_level, NULL);
135 LOGW("no custom EQ");
138 /* Custom Extension effects */
139 if (player->ini.audio_effect_custom_ext_num) {
140 LOGD("pass custom extension level list to audio effect plugin");
141 ext_effect_level_list = player->audio_effect_info.custom_ext_level_for_plugin;
142 if (!ext_effect_level_list) {
143 ext_effect_level_list = (gint*) malloc(sizeof(gint)*player->ini.audio_effect_custom_ext_num);
144 if (!ext_effect_level_list) {
145 LOGE("memory allocation for extension effect list failed");
146 return MM_ERROR_OUT_OF_MEMORY;
148 memset(ext_effect_level_list, 0, player->ini.audio_effect_custom_ext_num);
150 /* associate it to player handle */
151 player->audio_effect_info.custom_ext_level_for_plugin = ext_effect_level_list;
155 while (count < MM_AUDIO_EFFECT_CUSTOM_NUM) {
156 if (player->ini.audio_effect_custom_list[count]) {
157 ext_effect_level_list[ext_level_index] = player->audio_effect_info.custom_ext_level[count-1];
159 if (ext_level_index == player->ini.audio_effect_custom_ext_num)
165 /* set custom-extension effects level list */
166 g_object_set(audio_effect_element, "custom-ext", ext_effect_level_list, NULL);
168 LOGW("no custom extension effect");
170 /* order action to audio effect plugin */
171 g_object_set(audio_effect_element, "filter-action", MM_AUDIO_EFFECT_TYPE_CUSTOM, NULL);
172 LOGD("filter-action = %d", MM_AUDIO_EFFECT_TYPE_CUSTOM);
181 __mmplayer_is_earphone_only_effect_type(mm_player_t *player, MMAudioEffectType effect_type, int effect)
183 gboolean result = FALSE;
188 MMPLAYER_RETURN_VAL_IF_FAIL(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
190 if (effect_type == MM_AUDIO_EFFECT_TYPE_PRESET) {
192 if (player->ini.audio_effect_preset_earphone_only_list[effect]) {
193 LOGI("this preset effect(%d) is only available with earphone", effect);
196 } else if (effect_type == MM_AUDIO_EFFECT_TYPE_CUSTOM) {
198 for (i = 1; i < MM_AUDIO_EFFECT_CUSTOM_NUM; i++) {
199 /* it starts from 1(except testing for EQ) */
200 if (player->ini.audio_effect_custom_earphone_only_list[i]) {
201 /* check if the earphone only custom effect was set */
202 if (player->audio_effect_info.custom_ext_level[i-1]) {
203 LOGI("this custom effect(%d) is only available with earphone", i);
209 LOGE("invalid effect type(%d)", effect_type);
217 __mmplayer_audio_set_output_type(mm_player_t *player, MMAudioEffectType effect_type, int effect)
219 GstElement *audio_effect_element = NULL;
220 mm_sound_device_flags_e flags = MM_SOUND_DEVICE_ALL_FLAG;
221 MMSoundDeviceList_t device_list;
222 MMSoundDevice_t device_h = NULL;
223 mm_sound_device_type_e device_type;
225 int result = MM_ERROR_NONE;
229 MMPLAYER_RETURN_VAL_IF_FAIL(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
231 audio_effect_element = player->pipeline->audiobin[MMPLAYER_A_FILTER].gst;
233 /* (1) get current device list */
234 result = mm_sound_get_current_device_list(flags, &device_list);
237 LOGE("mm_sound_get_current_device_list() failed [%x]!!", result);
242 /* (2) get device handle of device list */
243 result = mm_sound_get_next_device(device_list, &device_h);
246 LOGE("mm_sound_get_next_device() failed [%x]!!", result);
251 /* (3) get device type */
252 result = mm_sound_get_device_type(device_h, &device_type);
255 LOGE("mm_sound_get_device_type() failed [%x]!!", result);
261 if (device_type == MM_SOUND_DEVICE_TYPE_BUILTIN_SPEAKER) {
262 if (MM_AUDIO_EFFECT_TYPE_SQUARE != effect_type) {
263 if (__mmplayer_is_earphone_only_effect_type(player, effect_type, effect)) {
264 LOGE("earphone is not equipped, this filter will not be applied");
266 return MM_ERROR_PLAYER_SOUND_EFFECT_INVALID_STATUS;
269 output_type = MM_AUDIO_EFFECT_OUTPUT_SPK;
270 } else if (device_type == MM_SOUND_DEVICE_TYPE_MIRRORING) {
271 output_type = MM_AUDIO_EFFECT_OUTPUT_OTHERS;
272 } else if (device_type == MM_SOUND_DEVICE_TYPE_HDMI) {
273 output_type = MM_AUDIO_EFFECT_OUTPUT_HDMI;
274 } else if (device_type == MM_SOUND_DEVICE_TYPE_BLUETOOTH) {
275 output_type = MM_AUDIO_EFFECT_OUTPUT_BT;
276 } else if (device_type == MM_SOUND_DEVICE_TYPE_USB_AUDIO) {
277 output_type = MM_AUDIO_EFFECT_OUTPUT_USB_AUDIO;
279 /* Other case, include WIRED_ACCESSORY */
280 output_type = MM_AUDIO_EFFECT_OUTPUT_EAR;
282 LOGW("output_type = %d (0:spk,1:ear,2:others)", output_type);
284 /* set filter output mode */
285 g_object_set(audio_effect_element, "filter-output-mode", output_type, NULL);
291 _mmplayer_is_supported_effect_type(mm_player_t* player, MMAudioEffectType effect_type, int effect)
293 gboolean result = TRUE;
294 mm_sound_device_flags_e flags = MM_SOUND_DEVICE_ALL_FLAG;
295 MMSoundDeviceList_t device_list;
296 MMSoundDevice_t device_h = NULL;
297 mm_sound_device_type_e device_type;
298 int ret = MM_ERROR_NONE;
302 /* get status if speaker is activated */
303 /* (1) get current device list */
304 ret = mm_sound_get_current_device_list(flags, &device_list);
307 LOGE("mm_sound_get_current_device_list() failed [%x]!!", ret);
311 /* (2) get device handle of device list */
312 ret = mm_sound_get_next_device(device_list, &device_h);
315 LOGE("mm_sound_get_next_device() failed [%x]!!", ret);
320 /* (3) get device type */
321 ret = mm_sound_get_device_type(device_h, &device_type);
324 LOGE("mm_sound_get_device_type() failed [%x]!!", ret);
330 if (effect_type == MM_AUDIO_EFFECT_TYPE_PRESET) {
331 if (effect < MM_AUDIO_EFFECT_PRESET_AUTO || effect >= MM_AUDIO_EFFECT_PRESET_NUM) {
332 LOGE("out of range, preset effect(%d)", effect);
335 if (!player->ini.audio_effect_preset_list[effect]) {
336 LOGE("this effect(%d) is not supported", effect);
339 if (device_type == MM_SOUND_DEVICE_TYPE_BUILTIN_SPEAKER &&
340 player->ini.audio_effect_preset_earphone_only_list[effect]) {
345 } else if (effect_type == MM_AUDIO_EFFECT_TYPE_CUSTOM) {
347 if (effect < MM_AUDIO_EFFECT_CUSTOM_EQ || effect >= MM_AUDIO_EFFECT_CUSTOM_NUM) {
348 LOGE("out of range, custom effect(%d)", effect);
351 if (!player->ini.audio_effect_custom_list[effect]) {
352 LOGE("this custom effect(%d) is not supported", effect);
355 if (device_type == MM_SOUND_DEVICE_TYPE_BUILTIN_SPEAKER &&
356 player->ini.audio_effect_custom_earphone_only_list[effect]) {
361 } else if (effect_type == MM_AUDIO_EFFECT_TYPE_SQUARE) {
362 if (!player->ini.use_audio_effect_custom) {
363 LOGE("Square effect is not supported");
367 LOGE("invalid effect type(%d)", effect_type);
378 _mmplayer_audio_effect_custom_apply(mm_player_t *player)
380 GstElement *audio_effect_element = NULL;
381 int result = MM_ERROR_NONE;
385 MMPLAYER_RETURN_VAL_IF_FAIL(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
387 /* Music Player can set audio effect value before Audiobin is created. */
388 if (!player->pipeline || !player->pipeline->audiobin || !player->pipeline->audiobin[MMPLAYER_A_FILTER].gst) {
389 LOGW("effect element is not created yet.");
390 player->bypass_audio_effect = FALSE;
392 /* store audio effect setting in order to apply it when audio effect plugin is created */
393 player->audio_effect_info.effect_type = MM_AUDIO_EFFECT_TYPE_CUSTOM;
395 audio_effect_element = player->pipeline->audiobin[MMPLAYER_A_FILTER].gst;
397 /* get status if speaker is activated */
398 result = __mmplayer_audio_set_output_type(player, MM_AUDIO_EFFECT_TYPE_CUSTOM, 0);
400 if (result != MM_ERROR_NONE) {
401 LOGE("failed to set output mode");
406 result = __mmplayer_set_harmony_effect(player, audio_effect_element);
408 LOGE("_set_harmony_effect() failed(%x)", result);
413 player->set_mode.rich_audio = TRUE;
421 _mmplayer_audio_effect_custom_update_level(mm_player_t *player)
423 GstElement *audio_effect_element = NULL;
424 int result = MM_ERROR_NONE;
425 int ext_level_index = 0;
428 gint *custom_eq = NULL;
429 gint *custom_ext_effect_level_list = NULL;
433 MMPLAYER_RETURN_VAL_IF_FAIL(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
435 audio_effect_element = player->pipeline->audiobin[MMPLAYER_A_FILTER].gst;
437 /* get custom eq effect */
438 g_object_get(audio_effect_element, "custom-eq", &custom_eq, NULL);
440 memcpy(player->audio_effect_info.custom_eq_level, custom_eq, sizeof(gint) * player->ini.audio_effect_custom_eq_band_num);
442 for (i = 0; i < player->ini.audio_effect_custom_eq_band_num; i++)
443 LOGD("updated custom-eq [%d] = %d", i, player->audio_effect_info.custom_eq_level[i]);
445 /* get custom ext effect */
447 g_object_get(audio_effect_element, "custom-ext", &custom_ext_effect_level_list, NULL);
449 while (count < MM_AUDIO_EFFECT_CUSTOM_NUM) {
450 if (player->ini.audio_effect_custom_list[count]) {
451 player->audio_effect_info.custom_ext_level[count-1]
452 = custom_ext_effect_level_list[ext_level_index];
453 LOGD("updated custom-ext [%d] = %d", count, player->audio_effect_info.custom_ext_level[count-1]);
466 mm_player_audio_effect_custom_clear_eq_all(MMHandleType hplayer)
468 int result = MM_ERROR_NONE;
469 mm_player_t* player = (mm_player_t*)hplayer;
473 MMPLAYER_RETURN_VAL_IF_FAIL(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
475 /* clear EQ custom effect */
476 memset(player->audio_effect_info.custom_eq_level, MM_AUDIO_EFFECT_CUSTOM_LEVEL_INIT, sizeof(int)*MM_AUDIO_EFFECT_EQ_BAND_NUM_MAX);
478 LOGI("All the EQ bands clearing success");
487 mm_player_audio_effect_custom_clear_ext_all(MMHandleType hplayer)
490 int result = MM_ERROR_NONE;
491 mm_player_t* player = (mm_player_t*)hplayer;
495 MMPLAYER_RETURN_VAL_IF_FAIL(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
497 /* clear ALL custom effects, except EQ */
498 for (i = 0 ; i < MM_AUDIO_EFFECT_CUSTOM_NUM - 1 ; i++)
499 player->audio_effect_info.custom_ext_level[i] = MM_AUDIO_EFFECT_CUSTOM_LEVEL_INIT;
501 LOGI("All the extension effects clearing success");
510 mm_player_is_supported_preset_effect_type(MMHandleType hplayer, MMAudioEffectPresetType effect)
512 mm_player_t* player = (mm_player_t*)hplayer;
513 int result = MM_ERROR_NONE;
517 MMPLAYER_RETURN_VAL_IF_FAIL(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
519 if (!_mmplayer_is_supported_effect_type(player, MM_AUDIO_EFFECT_TYPE_PRESET, effect))
520 result = MM_ERROR_PLAYER_SOUND_EFFECT_NOT_SUPPORTED_FILTER;
529 mm_player_is_supported_custom_effect_type(MMHandleType hplayer, MMAudioEffectCustomType effect)
531 mm_player_t* player = (mm_player_t*)hplayer;
532 int result = MM_ERROR_NONE;
536 MMPLAYER_RETURN_VAL_IF_FAIL(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
538 if (!_mmplayer_is_supported_effect_type(player, MM_AUDIO_EFFECT_TYPE_CUSTOM, effect))
539 result = MM_ERROR_PLAYER_SOUND_EFFECT_NOT_SUPPORTED_FILTER;
547 mm_player_audio_effect_custom_apply(MMHandleType hplayer)
549 mm_player_t* player = (mm_player_t*)hplayer;
550 int result = MM_ERROR_NONE;
554 MMPLAYER_RETURN_VAL_IF_FAIL(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
556 if (!player->ini.use_audio_effect_custom) {
557 LOGE("audio effect(custom) is not supported");
559 return MM_ERROR_NOT_SUPPORT_API;
562 result = _mmplayer_audio_effect_custom_apply(player);
571 mm_player_audio_effect_bypass(MMHandleType hplayer)
573 mm_player_t* player = (mm_player_t*)hplayer;
574 int result = MM_ERROR_NONE;
575 GstElement *audio_effect_element = NULL;
579 MMPLAYER_RETURN_VAL_IF_FAIL(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
581 if (!player->ini.use_audio_effect_preset && !player->ini.use_audio_effect_custom) {
582 LOGE("audio effect(preset/custom) is not supported");
584 return MM_ERROR_NOT_SUPPORT_API;
586 if (!player->pipeline || !player->pipeline->audiobin || !player->pipeline->audiobin[MMPLAYER_A_FILTER].gst) {
587 LOGW("effect element is not created yet.");
589 audio_effect_element = player->pipeline->audiobin[MMPLAYER_A_FILTER].gst;
591 /* order action to audio effect plugin */
592 g_object_set(audio_effect_element, "filter-action", MM_AUDIO_EFFECT_TYPE_NONE, NULL);
593 LOGD("filter-action = %d", MM_AUDIO_EFFECT_TYPE_NONE);
603 _mmplayer_audio_effect_custom_set_level_ext(mm_player_t *player, MMAudioEffectCustomType custom_effect_type, int level)
605 int effect_level_max = 0;
606 int effect_level_min = 0;
607 int count = 1; /* start from 1, because of excepting eq index */
608 int ext_level_index = 1; /* start from 1, because of excepting eq index */
609 int result = MM_ERROR_NONE;
613 MMPLAYER_RETURN_VAL_IF_FAIL(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
615 /* check if EQ is supported */
616 if (!_mmplayer_is_supported_effect_type(player, MM_AUDIO_EFFECT_TYPE_CUSTOM, custom_effect_type)) {
618 return MM_ERROR_PLAYER_SOUND_EFFECT_NOT_SUPPORTED_FILTER;
621 while (count < MM_AUDIO_EFFECT_CUSTOM_NUM) {
622 if (player->ini.audio_effect_custom_list[count]) {
623 if (count == custom_effect_type) {
624 effect_level_min = player->ini.audio_effect_custom_min_level_list[ext_level_index];
625 effect_level_max = player->ini.audio_effect_custom_max_level_list[ext_level_index];
626 LOGI("level min value(%d), level max value(%d)", effect_level_min, effect_level_max);
630 if (ext_level_index == player->ini.audio_effect_custom_ext_num + 1) {
631 LOGE("could not find min, max value. maybe effect information in ini file is not proper for audio effect plugin");
638 if (level < effect_level_min || level > effect_level_max) {
639 LOGE("out of range, level(%d)", level);
640 result = MM_ERROR_INVALID_ARGUMENT;
642 player->audio_effect_info.custom_ext_level[custom_effect_type-1] = level;
643 LOGI("set ext[%d] = %d", custom_effect_type-1, level);
653 _mmplayer_audio_effect_custom_set_level_eq(mm_player_t *player, int index, int level)
655 gint eq_level_max = 0;
656 gint eq_level_min = 0;
657 int result = MM_ERROR_NONE;
661 MMPLAYER_RETURN_VAL_IF_FAIL(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
663 /* check if EQ is supported */
664 if (!_mmplayer_is_supported_effect_type(player, MM_AUDIO_EFFECT_TYPE_CUSTOM, MM_AUDIO_EFFECT_CUSTOM_EQ)) {
666 return MM_ERROR_PLAYER_SOUND_EFFECT_NOT_SUPPORTED_FILTER;
669 if (index < 0 || index > player->ini.audio_effect_custom_eq_band_num - 1) {
670 LOGE("out of range, index(%d)", index);
671 result = MM_ERROR_INVALID_ARGUMENT;
673 eq_level_min = player->ini.audio_effect_custom_min_level_list[MM_AUDIO_EFFECT_CUSTOM_EQ];
674 eq_level_max = player->ini.audio_effect_custom_max_level_list[MM_AUDIO_EFFECT_CUSTOM_EQ];
675 LOGI("EQ level min value(%d), EQ level max value(%d)", eq_level_min, eq_level_max);
677 if (level < eq_level_min || level > eq_level_max) {
678 LOGE("out of range, EQ level(%d)", level);
679 result = MM_ERROR_INVALID_ARGUMENT;
681 player->audio_effect_info.custom_eq_level[index] = level;
682 LOGI("set EQ[%d] = %d", index, level);
692 /* NOTE : parameter eq_index is only used for _set_eq_level() */
694 mm_player_audio_effect_custom_set_level(MMHandleType hplayer, MMAudioEffectCustomType effect_custom_type, int eq_index, int level)
696 mm_player_t* player = (mm_player_t*)hplayer;
697 int result = MM_ERROR_NONE;
701 MMPLAYER_RETURN_VAL_IF_FAIL(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
703 /* check if this effect type is supported */
704 if (!_mmplayer_is_supported_effect_type(player, MM_AUDIO_EFFECT_TYPE_CUSTOM, effect_custom_type)) {
705 result = MM_ERROR_PLAYER_SOUND_EFFECT_NOT_SUPPORTED_FILTER;
707 if (effect_custom_type == MM_AUDIO_EFFECT_CUSTOM_EQ) {
708 result = _mmplayer_audio_effect_custom_set_level_eq(player, eq_index, level);
709 } else if (effect_custom_type > MM_AUDIO_EFFECT_CUSTOM_EQ && effect_custom_type < MM_AUDIO_EFFECT_CUSTOM_NUM) {
710 result = _mmplayer_audio_effect_custom_set_level_ext(player, effect_custom_type, level);
712 LOGE("out of range, effect type(%d)", effect_custom_type);
713 result = MM_ERROR_INVALID_ARGUMENT;
724 mm_player_audio_effect_custom_get_eq_bands_number(MMHandleType hplayer, int *bands)
726 mm_player_t* player = (mm_player_t*)hplayer;
727 int result = MM_ERROR_NONE;
731 MMPLAYER_RETURN_VAL_IF_FAIL(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
733 /* check if EQ is supported */
734 if (!_mmplayer_is_supported_effect_type(player, MM_AUDIO_EFFECT_TYPE_CUSTOM, MM_AUDIO_EFFECT_CUSTOM_EQ)) {
736 return MM_ERROR_PLAYER_SOUND_EFFECT_NOT_SUPPORTED_FILTER;
739 *bands = player->ini.audio_effect_custom_eq_band_num;
740 LOGD("number of custom EQ band = %d", *bands);
749 mm_player_audio_effect_custom_get_eq_bands_width(MMHandleType hplayer, int band_idx, int *width)
751 mm_player_t* player = (mm_player_t*)hplayer;
752 int result = MM_ERROR_NONE;
753 unsigned int eq_num = 0;
757 MMPLAYER_RETURN_VAL_IF_FAIL(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
759 /* check if EQ is supported */
760 if (!_mmplayer_is_supported_effect_type(player, MM_AUDIO_EFFECT_TYPE_CUSTOM, MM_AUDIO_EFFECT_CUSTOM_EQ)) {
762 return MM_ERROR_PLAYER_SOUND_EFFECT_NOT_SUPPORTED_FILTER;
765 eq_num = player->ini.audio_effect_custom_eq_band_num;
766 if (band_idx < 0 || band_idx > eq_num-1) {
767 LOGE("out of range, invalid band_idx(%d)", band_idx);
768 result = MM_ERROR_INVALID_ARGUMENT;
770 /* set the width of EQ band */
771 *width = player->ini.audio_effect_custom_eq_band_width[band_idx];
772 LOGD("width of band_idx(%d) = %dHz", band_idx, *width);
782 mm_player_audio_effect_custom_get_eq_bands_freq(MMHandleType hplayer, int band_idx, int *freq)
784 mm_player_t* player = (mm_player_t*)hplayer;
785 int result = MM_ERROR_NONE;
786 unsigned int eq_num = 0;
790 MMPLAYER_RETURN_VAL_IF_FAIL(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
792 /* check if EQ is supported */
793 if (!_mmplayer_is_supported_effect_type(player, MM_AUDIO_EFFECT_TYPE_CUSTOM, MM_AUDIO_EFFECT_CUSTOM_EQ)) {
795 return MM_ERROR_PLAYER_SOUND_EFFECT_NOT_SUPPORTED_FILTER;
798 eq_num = player->ini.audio_effect_custom_eq_band_num;
799 if (band_idx < 0 || band_idx > eq_num-1) {
800 LOGE("out of range, invalid band_idx(%d)", band_idx);
801 result = MM_ERROR_INVALID_ARGUMENT;
803 /* set the frequency of EQ band */
804 *freq = player->ini.audio_effect_custom_eq_band_freq[band_idx];
805 LOGD("frequency of band_idx(%d) = %dHz", band_idx, *freq);
815 mm_player_audio_effect_custom_get_level(MMHandleType hplayer, MMAudioEffectCustomType type, int eq_index, int *level)
817 mm_player_t* player = (mm_player_t*)hplayer;
818 int result = MM_ERROR_NONE;
822 MMPLAYER_RETURN_VAL_IF_FAIL(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
823 MMPLAYER_RETURN_VAL_IF_FAIL(level, MM_ERROR_PLAYER_NOT_INITIALIZED);
825 /* check if this effect type is supported */
826 if (!_mmplayer_is_supported_effect_type(player, MM_AUDIO_EFFECT_TYPE_CUSTOM, type)) {
828 return MM_ERROR_PLAYER_SOUND_EFFECT_NOT_SUPPORTED_FILTER;
831 if (type == MM_AUDIO_EFFECT_CUSTOM_EQ) {
832 if (eq_index < 0 || eq_index > player->ini.audio_effect_custom_eq_band_num - 1) {
833 LOGE("out of range, EQ index(%d)", eq_index);
834 result = MM_ERROR_INVALID_ARGUMENT;
836 *level = player->audio_effect_info.custom_eq_level[eq_index];
837 LOGD("EQ index = %d, level = %d", eq_index, *level);
839 } else if (type > MM_AUDIO_EFFECT_CUSTOM_EQ && type < MM_AUDIO_EFFECT_CUSTOM_NUM) {
840 *level = player->audio_effect_info.custom_ext_level[type-1];
841 LOGD("extension effect index = %d, level = %d", type, *level);
843 LOGE("out of range, type(%d)", type);
844 result = MM_ERROR_INVALID_ARGUMENT;
854 mm_player_audio_effect_custom_get_level_range(MMHandleType hplayer, MMAudioEffectCustomType type, int *min, int *max)
856 mm_player_t* player = (mm_player_t*)hplayer;
857 int result = MM_ERROR_NONE;
858 int count = 1; /* start from 1, because of excepting eq index */
859 int ext_level_index = 1; /* start from 1, because of excepting eq index */
863 MMPLAYER_RETURN_VAL_IF_FAIL(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
864 MMPLAYER_RETURN_VAL_IF_FAIL(min, MM_ERROR_PLAYER_NOT_INITIALIZED);
865 MMPLAYER_RETURN_VAL_IF_FAIL(max, MM_ERROR_PLAYER_NOT_INITIALIZED);
867 /* check if this effect type is supported */
868 if (!_mmplayer_is_supported_effect_type(player, MM_AUDIO_EFFECT_TYPE_CUSTOM, type)) {
870 return MM_ERROR_PLAYER_SOUND_EFFECT_NOT_SUPPORTED_FILTER;
873 if (type == MM_AUDIO_EFFECT_CUSTOM_EQ) {
874 *min = player->ini.audio_effect_custom_min_level_list[MM_AUDIO_EFFECT_CUSTOM_EQ];
875 *max = player->ini.audio_effect_custom_max_level_list[MM_AUDIO_EFFECT_CUSTOM_EQ];
876 LOGD("EQ min level = %d, max level = %d", *min, *max);
878 while (count < MM_AUDIO_EFFECT_CUSTOM_NUM) {
879 if (player->ini.audio_effect_custom_list[count]) {
881 *min = player->ini.audio_effect_custom_min_level_list[ext_level_index];
882 *max = player->ini.audio_effect_custom_max_level_list[ext_level_index];
883 LOGI("Extension effect(%d) min level = %d, max level = %d", count, *min, *max);
887 if (ext_level_index == player->ini.audio_effect_custom_ext_num + 1) {
888 LOGE("could not find min, max value. maybe effect information in ini file is not proper for audio effect plugin");
903 mm_player_audio_effect_custom_set_level_eq_from_list(MMHandleType hplayer, int *level_list, int size)
905 mm_player_t *player = (mm_player_t*)hplayer;
907 gint eq_level_min = 0;
908 gint eq_level_max = 0;
909 int result = MM_ERROR_NONE;
913 MMPLAYER_RETURN_VAL_IF_FAIL(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
915 /* check if EQ is supported */
916 if (!_mmplayer_is_supported_effect_type(player, MM_AUDIO_EFFECT_TYPE_CUSTOM, MM_AUDIO_EFFECT_CUSTOM_EQ)) {
918 return MM_ERROR_PLAYER_SOUND_EFFECT_NOT_SUPPORTED_FILTER;
921 if (size != player->ini.audio_effect_custom_eq_band_num) {
922 LOGE("input size variable(%d) does not match with number of eq band(%d)", size, player->ini.audio_effect_custom_eq_band_num);
923 result = MM_ERROR_INVALID_ARGUMENT;
925 eq_level_min = player->ini.audio_effect_custom_min_level_list[MM_AUDIO_EFFECT_CUSTOM_EQ];
926 eq_level_max = player->ini.audio_effect_custom_max_level_list[MM_AUDIO_EFFECT_CUSTOM_EQ];
928 for (i = 0 ; i < size ; i++) {
929 if (level_list[i] < eq_level_min || level_list[i] > eq_level_max) {
930 LOGE("out of range, level[%d]=%d", i, level_list[i]);
931 result = MM_ERROR_INVALID_ARGUMENT;
934 player->audio_effect_info.custom_eq_level[i] = level_list[i];