summaryrefslogtreecommitdiffstats
path: root/audio/audio_hw.c
diff options
context:
space:
mode:
authorsbrissen <sbrissen@hotmail.com>2013-06-10 11:04:08 -0400
committersbrissen <sbrissen@hotmail.com>2013-06-13 09:34:25 -0400
commit56b68617e0dff7e1f4cf879b8531ad57037d9fac (patch)
tree89d7935374b1c409040b8901bbe33dba6242f733 /audio/audio_hw.c
parentd4f8a12bef518d8af58f89707f297b557c298f02 (diff)
downloaddevice_samsung_t0lte-56b68617e0dff7e1f4cf879b8531ad57037d9fac.tar.gz
device_samsung_t0lte-56b68617e0dff7e1f4cf879b8531ad57037d9fac.tar.bz2
device_samsung_t0lte-56b68617e0dff7e1f4cf879b8531ad57037d9fac.zip
t0lte: user configureable voice/streaming volumes [1/2]
This uses 4 files to store the voice volume: incall_earpiece, incall_headphone, incall_speaker, incall_bt, and 2 for streaming volume: out_speaker, out_headphone located /data/local/audio. Change-Id: I4269dc65d48e04b5e908b20704128241683d5a80
Diffstat (limited to 'audio/audio_hw.c')
-rwxr-xr-xaudio/audio_hw.c123
1 files changed, 114 insertions, 9 deletions
diff --git a/audio/audio_hw.c b/audio/audio_hw.c
index 3cb40c2..6a4ca04 100755
--- a/audio/audio_hw.c
+++ b/audio/audio_hw.c
@@ -25,6 +25,7 @@
#include <pthread.h>
#include <stdint.h>
#include <sys/time.h>
+#include <sys/stat.h>
#include <stdlib.h>
#include <expat.h>
#include <dlfcn.h>
@@ -196,7 +197,6 @@ struct m0_dev_cfg {
void *mCsdHandle;
int rx_dev_id, tx_dev_id, old_rx_dev;
-int voice_index;
static int (*csd_client_init)();
static int (*csd_client_deinit)();
@@ -533,7 +533,6 @@ static void set_incall_device(struct m0_audio_device *adev)
case AUDIO_DEVICE_OUT_EARPIECE:
rx_dev_id = DEVICE_HANDSET_RX_ACDB_ID;
tx_dev_id = DEVICE_HANDSET_TX_ACDB_ID;
- voice_index = 5;
break;
case AUDIO_DEVICE_OUT_SPEAKER:
case AUDIO_DEVICE_OUT_ANLG_DOCK_HEADSET:
@@ -541,13 +540,11 @@ static void set_incall_device(struct m0_audio_device *adev)
case AUDIO_DEVICE_OUT_AUX_DIGITAL:
rx_dev_id = DEVICE_SPEAKER_MONO_RX_ACDB_ID;
tx_dev_id = DEVICE_SPEAKER_TX_ACDB_ID;
- voice_index = 7;
break;
case AUDIO_DEVICE_OUT_WIRED_HEADSET:
case AUDIO_DEVICE_OUT_WIRED_HEADPHONE:
rx_dev_id = DEVICE_HEADSET_RX_ACDB_ID;
tx_dev_id = DEVICE_HEADSET_TX_ACDB_ID;
- voice_index = 5;
break;
case AUDIO_DEVICE_OUT_BLUETOOTH_SCO:
case AUDIO_DEVICE_OUT_BLUETOOTH_SCO_HEADSET:
@@ -559,12 +556,10 @@ static void set_incall_device(struct m0_audio_device *adev)
rx_dev_id = DEVICE_BT_SCO_RX_ACDB_ID;
tx_dev_id = DEVICE_BT_SCO_TX_ACDB_ID;
}
- voice_index = 7;
break;
default:
rx_dev_id = DEVICE_HANDSET_RX_ACDB_ID;
tx_dev_id = DEVICE_HANDSET_TX_ACDB_ID;
- voice_index = 5;
break;
}
@@ -610,8 +605,25 @@ static void set_input_volumes(struct m0_audio_device *adev, int main_mic_on,
{
}
-static void set_output_volumes(struct m0_audio_device *adev, bool tty_volume)
+static void set_output_volumes(struct m0_audio_device *adev)
{
+ int volume;
+
+ switch(adev->out_device) {
+ case AUDIO_DEVICE_OUT_SPEAKER:
+ volume = get_volume(OUT_SPEAKER);
+ ALOGV("%s: SPEAKER Volume: %i", __func__, volume);
+ mixer_ctl_set_value(adev->mixer_ctls.speaker_volume,0,volume);
+ mixer_ctl_set_value(adev->mixer_ctls.speaker_volume,1,volume);
+ break;
+ case AUDIO_DEVICE_OUT_WIRED_HEADSET:
+ case AUDIO_DEVICE_OUT_WIRED_HEADPHONE:
+ volume = get_volume(OUT_HEADPHONE);
+ ALOGV("%s: HEADPHONE Volume: %i", __func__, volume);
+ mixer_ctl_set_value(adev->mixer_ctls.headphone_volume,0,volume);
+ mixer_ctl_set_value(adev->mixer_ctls.headphone_volume,1,volume);
+ break;
+ }
}
static void force_all_standby(struct m0_audio_device *adev)
@@ -742,6 +754,8 @@ static void select_output_device(struct m0_audio_device *adev)
set_eq_filter(adev);
+ set_output_volumes(adev);
+
if (adev->mode == AUDIO_MODE_IN_CALL) {
if (!bt_on) {
/* force tx path according to TTY mode when in call */
@@ -2719,16 +2733,19 @@ static int adev_init_check(const struct audio_hw_device *dev)
static int adev_set_voice_volume(struct audio_hw_device *dev, float volume)
{
struct m0_audio_device *adev = (struct m0_audio_device *)dev;
+ int voice_index;
adev->voice_volume = volume;
+ voice_index = update_voice_index(adev);
+
ALOGD("%s: Voice Index: %i", __func__, voice_index);
if (adev->mode == AUDIO_MODE_IN_CALL) {
if (csd_volume_index == NULL) {
ALOGE("dlsym: Error:%s Loading csd_volume_index", dlerror());
} else {
- volume = volume * voice_index;
+ volume = volume * (float)voice_index;
ALOGD("%s: calling csd_volume_index(%f)", __func__, volume);
csd_volume_index(volume);
}
@@ -2736,6 +2753,36 @@ static int adev_set_voice_volume(struct audio_hw_device *dev, float volume)
return 0;
}
+int update_voice_index(struct m0_audio_device *adev)
+{
+ int voice_index;
+
+ switch(adev->out_device) {
+ case AUDIO_DEVICE_OUT_EARPIECE:
+ voice_index = get_volume(INCALL_EARPIECE);
+ break;
+ case AUDIO_DEVICE_OUT_SPEAKER:
+ case AUDIO_DEVICE_OUT_ANLG_DOCK_HEADSET:
+ case AUDIO_DEVICE_OUT_DGTL_DOCK_HEADSET:
+ case AUDIO_DEVICE_OUT_AUX_DIGITAL:
+ voice_index = get_volume(INCALL_SPEAKER);
+ break;
+ case AUDIO_DEVICE_OUT_WIRED_HEADSET:
+ case AUDIO_DEVICE_OUT_WIRED_HEADPHONE:
+ voice_index = get_volume(INCALL_HEADPHONE);
+ break;
+ case AUDIO_DEVICE_OUT_BLUETOOTH_SCO:
+ case AUDIO_DEVICE_OUT_BLUETOOTH_SCO_HEADSET:
+ case AUDIO_DEVICE_OUT_BLUETOOTH_SCO_CARKIT:
+ voice_index = get_volume(INCALL_BT);
+ break;
+ default:
+ voice_index = get_volume(INCALL_EARPIECE);
+ break;
+ }
+ return voice_index;
+}
+
static int adev_set_master_volume(struct audio_hw_device *dev, float volume)
{
return -ENOSYS;
@@ -3151,11 +3198,63 @@ static int adev_config_parse(struct m0_audio_device *adev)
return ret;
}
+static int volume_file_check()
+{
+ FILE *f;
+ int i;
+ int default_voice_vol = 5;
+ int default_stream_vol = 50;
+ struct stat st = {0};
+
+ if (stat(AUDIO_DIR, &st) == -1) {
+ ALOGE("Directory %s does not exist, skip creating volume files\n", AUDIO_DIR);
+ return -ENODEV;
+ }
+
+ for ( i = 0; i < MAX_NUM_VOLUME_FILES; i++ ) {
+ f = fopen(volume_file[i], "r");
+ if(!f){
+ ALOGW("Failed to open %s, attempting to create file\n", volume_file[i]);
+ f = fopen(volume_file[i], "w");
+ if(!f){
+ ALOGE("Failed to create %s\n", volume_file[i]);
+ continue;
+ }else{
+ ALOGI("Successfully created %s\n", volume_file[i]);
+ /* first 4 files are for incall voice, anything over that is considered streaming out */
+ if(i > 3)
+ fprintf(f, "%d", default_stream_vol);
+ else
+ fprintf(f, "%d", default_voice_vol);
+ fclose(f);
+ chmod(volume_file[i], 0666);
+ }
+ }else{
+ chmod(volume_file[i],0666);
+ }
+ }
+
+ return 0;
+}
+
+int get_volume(char *file)
+{
+ FILE *f;
+ int index = 1;
+
+ f = fopen(file, "r");
+ if(f) {
+ fscanf(f, "%i", &index);
+ fclose(f);
+ }
+ return index;
+}
+
static int adev_open(const hw_module_t* module, const char* name,
hw_device_t** device)
{
struct m0_audio_device *adev;
- int ret;
+ int ret, volfs;
if (strcmp(name, AUDIO_HARDWARE_INTERFACE) != 0)
return -EINVAL;
@@ -3195,10 +3294,16 @@ static int adev_open(const hw_module_t* module, const char* name,
adev->mixer_ctls.mixinl_in1l_volume = mixer_get_ctl_by_name(adev->mixer, "MIXINL IN1L Volume");
adev->mixer_ctls.mixinl_in2l_volume = mixer_get_ctl_by_name(adev->mixer, "MIXINL IN2L Volume");
+ /* speaker/headphone volume control*/
+ adev->mixer_ctls.speaker_volume = mixer_get_ctl_by_name(adev->mixer, "Speaker Volume");
+ adev->mixer_ctls.headphone_volume = mixer_get_ctl_by_name(adev->mixer, "Headphone Volume");
+
ret = adev_config_parse(adev);
if (ret != 0)
goto err_mixer;
+ volfs = volume_file_check();
+
/* Set the default route before the PCM stream is opened */
pthread_mutex_lock(&adev->lock);
adev->mode = AUDIO_MODE_NORMAL;