Skip to content

Commit

Permalink
Merge "Import commits from CAF." into gingerbread
Browse files Browse the repository at this point in the history
  • Loading branch information
rmcc authored and Gerrit Code Review committed Jan 20, 2012
2 parents c51205f + 144d3f9 commit e831ddd
Showing 1 changed file with 77 additions and 35 deletions.
112 changes: 77 additions & 35 deletions libaudio/AudioHardware.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
** Copyright 2008, The Android Open-Source Project
** Copyright (c) 2010, Code Aurora Forum. All rights reserved.
** Copyright (c) 2010-2011, Code Aurora Forum. All rights reserved.
**
** Licensed under the Apache License, Version 2.0 (the "License");
** you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -51,6 +51,7 @@ const uint32_t AudioHardware::inputSamplingRates[] = {

static int get_audpp_filter(void);
static int msm72xx_enable_postproc(bool state);
static int msm72xx_enable_preproc(bool state);

// Post processing paramters
static struct rx_iir_filter iir_cfg[3];
Expand All @@ -74,7 +75,7 @@ static bool playback_in_progress = false;
static struct tx_iir tx_iir_cfg[9];
static struct ns ns_cfg[9];
static struct tx_agc tx_agc_cfg[9];
static int enable_preproc_mask;
static int enable_preproc_mask[9];

static int snd_device = -1;

Expand Down Expand Up @@ -207,7 +208,9 @@ AudioHardware::~AudioHardware()
close(m7xsnddriverfd);
m7xsnddriverfd = -1;
}
enable_preproc_mask = 0;
for (int index = 0; index < 9; index++) {
enable_preproc_mask[index] = 0;
}
mInit = false;
}

Expand Down Expand Up @@ -265,6 +268,17 @@ AudioStreamIn* AudioHardware::openInputStream(
return 0;
}

if ( (mMode == AudioSystem::MODE_IN_CALL) &&
(getInputSampleRate(*sampleRate) > AUDIO_HW_IN_SAMPLERATE) &&
(*format == AUDIO_HW_IN_FORMAT) )
{
LOGE("PCM recording, in a voice call, with sample rate more than 8K not supported \
re-configure with 8K and try software re-sampler ");
*status = BAD_VALUE;
*sampleRate = AUDIO_HW_IN_SAMPLERATE;
return 0;
}

mLock.lock();

AudioStreamInMSM72xx* in = new AudioStreamInMSM72xx();
Expand Down Expand Up @@ -404,6 +418,9 @@ status_t AudioHardware::setParameters(const String8& keyValuePairs)
} else {
mTtyMode = TTY_OFF;
}
if(mMode != AudioSystem::MODE_IN_CALL){
return NO_ERROR;
}
} else {
mTtyMode = TTY_OFF;
}
Expand Down Expand Up @@ -437,6 +454,12 @@ String8 AudioHardware::getParameters(const String8& keys)
param.add(key, value);
}

key = String8("tunneled-input-formats");
if ( param.get(key,value) == NO_ERROR ) {
param.addInt(String8("AMR"), true );
param.addInt(String8("QCELP"), true );
param.addInt(String8("EVRC"), true );
}
LOGV("AudioHardware::getParameters() %s", param.toString().string());
return param.toString();
}
Expand Down Expand Up @@ -727,7 +750,7 @@ int check_and_set_audpp_parameters(char *buf, int size)

LOGV("TX IIR flag = %02x.", txiir_flag[device_id]);
if (txiir_flag[device_id] != 0)
enable_preproc_mask |= TX_IIR_ENABLE;
enable_preproc_mask[samp_index] |= TX_IIR_ENABLE;
} else if(buf[0] == 'F') {
/* AGC filter */
if (!(p = strtok(buf, ",")))
Expand Down Expand Up @@ -769,8 +792,8 @@ int check_and_set_audpp_parameters(char *buf, int size)

agc_flag[device_id] = (uint16_t)strtol(p, &ps, 16);
LOGV("AGC flag = %02x.", agc_flag[device_id]);
if (agc_flag[device_id != 0])
enable_preproc_mask |= AGC_ENABLE;
if (agc_flag[device_id] != 0)
enable_preproc_mask[samp_index] |= AGC_ENABLE;
} else if ((buf[0] == 'G')) {
/* This is the NS record we are looking for. Tokenize it */
if (!(p = strtok(buf, ",")))
Expand Down Expand Up @@ -820,7 +843,7 @@ int check_and_set_audpp_parameters(char *buf, int size)

LOGV("NS flag = %02x.", ns_flag[device_id]);
if (ns_flag[device_id] != 0)
enable_preproc_mask |= NS_ENABLE;
enable_preproc_mask[samp_index] |= NS_ENABLE;
}
}
return 0;
Expand Down Expand Up @@ -869,7 +892,7 @@ static int get_audpp_filter(void)

current_str = read_buf;

while (1) {
while (*current_str != (char)EOF) {
int len;
next_str = strchr(current_str, '\n');
if (!next_str)
Expand Down Expand Up @@ -1018,12 +1041,12 @@ static int msm72xx_enable_postproc(bool state)
} else{
int disable_mask = 0;

if(post_proc_feature_mask & MBADRC_ENABLE) disable_mask |= MBADRC_DISABLE;
if(post_proc_feature_mask & ADRC_ENABLE) disable_mask |= ADRC_DISABLE;
if(post_proc_feature_mask & EQ_ENABLE) disable_mask |= EQ_DISABLE;
if(post_proc_feature_mask & RX_IIR_ENABLE) disable_mask |= RX_IIR_DISABLE;
if(post_proc_feature_mask & MBADRC_ENABLE) disable_mask &= MBADRC_DISABLE;
if(post_proc_feature_mask & ADRC_ENABLE) disable_mask &= ADRC_DISABLE;
if(post_proc_feature_mask & EQ_ENABLE) disable_mask &= EQ_DISABLE;
if(post_proc_feature_mask & RX_IIR_ENABLE) disable_mask &= RX_IIR_DISABLE;

LOGI("disabling post proc features with mask 0x%04x", post_proc_feature_mask);
LOGI("disabling post proc features with mask 0x%04x", disable_mask);
if (ioctl(fd, AUDIO_ENABLE_AUDPP, &disable_mask) < 0) {
LOGE("enable audpp error");
close(fd);
Expand Down Expand Up @@ -1145,6 +1168,8 @@ status_t AudioHardware::setMasterVolume(float v)
set_volume_rpc(SND_DEVICE_HEADSET_STEREO, SND_METHOD_VOICE, vol, m7xsnddriverfd);
set_volume_rpc(SND_DEVICE_IN_S_SADC_OUT_HANDSET, SND_METHOD_VOICE, vol, m7xsnddriverfd);
set_volume_rpc(SND_DEVICE_IN_S_SADC_OUT_SPEAKER_PHONE, SND_METHOD_VOICE, vol, m7xsnddriverfd);
set_volume_rpc(SND_DEVICE_TTY_HEADSET, SND_METHOD_VOICE, 1, m7xsnddriverfd);
set_volume_rpc(SND_DEVICE_TTY_VCO, SND_METHOD_VOICE, 1, m7xsnddriverfd);
// We return an error code here to let the audioflinger do in-software
// volume on top of the maximum volume that we set through the SND API.
// return error - software mixer will handle it
Expand Down Expand Up @@ -1929,22 +1954,37 @@ status_t AudioHardware::AudioStreamInMSM72xx::set(
//if (!acoustic)
// return NO_ERROR;

audpre_index = calculate_audpre_table_index(mSampleRate);
if(audpre_index < 0) {
LOGE("wrong sampling rate");
status = -EINVAL;
goto Error;
}
return NO_ERROR;

Error:
if (mFd >= 0) {
::close(mFd);
mFd = -1;
}
return status;
}

static int msm72xx_enable_preproc(bool state)
{
uint16_t mask = 0x0000;

if (audpp_filter_inited)
{
int fd;
audpre_index = calculate_audpre_table_index(mSampleRate);
if(audpre_index < 0) {
LOGE("wrong sampling rate");
goto Error;
}

fd = open(PREPROC_CTL_DEVICE, O_RDWR);
if (fd < 0) {
LOGE("Cannot open PreProc Ctl device");
return -EPERM;
}

if (enable_preproc_mask & AGC_ENABLE) {
if (enable_preproc_mask[audpre_index] & AGC_ENABLE) {
/* Setting AGC Params */
LOGI("AGC Filter Param1= %02x.", tx_agc_cfg[audpre_index].cmd_id);
LOGI("AGC Filter Param2= %02x.", tx_agc_cfg[audpre_index].tx_agc_param_mask);
Expand All @@ -1953,14 +1993,14 @@ status_t AudioHardware::AudioStreamInMSM72xx::set(
LOGI("AGC Filter Param5= %02x.", tx_agc_cfg[audpre_index].adaptive_gain_flag);
LOGI("AGC Filter Param6= %02x.", tx_agc_cfg[audpre_index].agc_params[0]);
LOGI("AGC Filter Param7= %02x.", tx_agc_cfg[audpre_index].agc_params[18]);
if ((enable_preproc_mask & AGC_ENABLE) &&
if ((enable_preproc_mask[audpre_index] & AGC_ENABLE) &&
(ioctl(fd, AUDIO_SET_AGC, &tx_agc_cfg[audpre_index]) < 0))
{
LOGE("set AGC filter error.");
}
}

if (enable_preproc_mask & NS_ENABLE) {
if (enable_preproc_mask[audpre_index] & NS_ENABLE) {
/* Setting NS Params */
LOGI("NS Filter Param1= %02x.", ns_cfg[audpre_index].cmd_id);
LOGI("NS Filter Param2= %02x.", ns_cfg[audpre_index].ec_mode_new);
Expand All @@ -1970,43 +2010,43 @@ status_t AudioHardware::AudioStreamInMSM72xx::set(
LOGI("NS Filter Param6= %02x.", ns_cfg[audpre_index].dens_limit_ns_d);
LOGI("NS Filter Param7= %02x.", ns_cfg[audpre_index].wb_gamma_e);
LOGI("NS Filter Param8= %02x.", ns_cfg[audpre_index].wb_gamma_n);
if ((enable_preproc_mask & NS_ENABLE) &&
if ((enable_preproc_mask[audpre_index] & NS_ENABLE) &&
(ioctl(fd, AUDIO_SET_NS, &ns_cfg[audpre_index]) < 0))
{
LOGE("set NS filter error.");
}
}

if (enable_preproc_mask & TX_IIR_ENABLE) {
if (enable_preproc_mask[audpre_index] & TX_IIR_ENABLE) {
/* Setting TX_IIR Params */
LOGI("TX_IIR Filter Param1= %02x.", tx_iir_cfg[audpre_index].cmd_id);
LOGI("TX_IIR Filter Param2= %02x.", tx_iir_cfg[audpre_index].active_flag);
LOGI("TX_IIR Filter Param3= %02x.", tx_iir_cfg[audpre_index].num_bands);
LOGI("TX_IIR Filter Param4= %02x.", tx_iir_cfg[audpre_index].iir_params[0]);
LOGI("TX_IIR Filter Param5= %02x.", tx_iir_cfg[audpre_index].iir_params[1]);
LOGI("TX_IIR Filter Param6 %02x.", tx_iir_cfg[audpre_index].iir_params[47]);
if ((enable_preproc_mask & TX_IIR_ENABLE) &&
if ((enable_preproc_mask[audpre_index] & TX_IIR_ENABLE) &&
(ioctl(fd, AUDIO_SET_TX_IIR, &tx_iir_cfg[audpre_index]) < 0))
{
LOGE("set TX IIR filter error.");
}
}
/*Setting AUDPRE_ENABLE*/
if (ioctl(fd, AUDIO_ENABLE_AUDPRE, &enable_preproc_mask) < 0)
{
LOGE("set AUDPRE_ENABLE error.");

if (state == true) {
/*Setting AUDPRE_ENABLE*/
if (ioctl(fd, AUDIO_ENABLE_AUDPRE, &enable_preproc_mask[audpre_index]) < 0) {
LOGE("set AUDPRE_ENABLE error.");
}
} else {
/*Setting AUDPRE_ENABLE*/
if (ioctl(fd, AUDIO_ENABLE_AUDPRE, &mask) < 0) {
LOGE("set AUDPRE_ENABLE error.");
}
}
close(fd);
}

return NO_ERROR;

Error:
if (mFd >= 0) {
::close(mFd);
mFd = -1;
}
return status;
}

AudioHardware::AudioStreamInMSM72xx::~AudioStreamInMSM72xx()
Expand Down Expand Up @@ -2048,6 +2088,7 @@ ssize_t AudioHardware::AudioStreamInMSM72xx::read( void* buffer, ssize_t bytes)
standby();
return -1;
}
msm72xx_enable_preproc(true);
}

// Resetting the bytes value, to return the appropriate read value
Expand Down Expand Up @@ -2109,6 +2150,7 @@ ssize_t AudioHardware::AudioStreamInMSM72xx::read( void* buffer, ssize_t bytes)
status_t AudioHardware::AudioStreamInMSM72xx::standby()
{
if (mState > AUDIO_INPUT_CLOSED) {
msm72xx_enable_preproc(false);
if (mFd >= 0) {
::close(mFd);
mFd = -1;
Expand Down

6 comments on commit e831ddd

@mik9
Copy link
Contributor

@mik9 mik9 commented on e831ddd Jan 21, 2012

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

First one: commit

Second one: this value related only to TTY output devices (link) and nothing more.

@mik9
Copy link
Contributor

@mik9 mik9 commented on e831ddd Jan 21, 2012

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That change is from another phone

And #undef COMBO_DEVICE_SUPPORTED makes no sense. Combo devices available but not used ever.

@rmcc
Copy link
Member Author

@rmcc rmcc commented on e831ddd Jan 21, 2012

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand that English is probably not your native language, but you're making absolutely no sense at all.
You're demanding code modifications from people with established track records (Kiril has been working on the p500 for quite a while, and I'm... well, me), with no justification whatsoever nor an explanation of what it's supposed to fix. I have no noise in FM, and FM doesn't use TTY. "Look at adam's code" doesn't cut it either. Adam is the CM maintainer for the device, he can do the changes he wants himself.

Not that we're perfect, but even if I knew who you were, you would still have to explain the modifications you're asking for. Random and unexplained changes aren't going to happen.

@SetiroN
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why don't you just try and justify/explain your changes instead of acting menstruated? :)

@psyke83
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't own this device and stumbled upon this conversation by accident, but the "#undef COMBO_DEVICE_SUPPORTED" comment actually does make sense.

Line 40:

define COMBO_DEVICE_SUPPORTED 0

Line 1346:

ifdef COMBO_DEVICE_SUPPORTED

The "#ifdef" is only checking if the token has been defined - it doesn't matter if it's defined as "0" or "false" - it's still defined. I only noticed this recently when I noticed my unofficial galaxy5/tass ports were using parts of the combo code unexpectedly.
Line 1346 should really be: "#if COMBO_DEVICE_SUPPORTED".

@mik9
Copy link
Contributor

@mik9 mik9 commented on e831ddd Jan 30, 2012

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. It's true. But LG P500 supports combo devices.

Please sign in to comment.