author | Shuai Li <shuai.li@amlogic.com> | 2016-04-18 08:19:07 (GMT) |
---|---|---|
committer | Shuai Li <shuai.li@amlogic.com> | 2016-05-04 07:32:43 (GMT) |
commit | 97dcf63b26be49cb641ed1ae5db3e80c909106e6 (patch) | |
tree | cbfa5304ca3ad24e5f520864ed8e0027f34792bd | |
parent | 979a262a3a476d5c32711370ebe4cf860dff844a (diff) | |
download | audio-97dcf63b26be49cb641ed1ae5db3e80c909106e6.zip audio-97dcf63b26be49cb641ed1ae5db3e80c909106e6.tar.gz audio-97dcf63b26be49cb641ed1ae5db3e80c909106e6.tar.bz2 |
PD#122565: audio: add audio source positive pre-gain setting interface
Change-Id: I525d6cd3b483a181972b694c44fbabbe9d904723
-rw-r--r-- | libTVaudio/audio/aml_audio.c | 81 | ||||
-rw-r--r-- | libTVaudio/audio/aml_audio.h | 4 | ||||
-rw-r--r-- | libTVaudio/audio/audio_amaudio.cpp | 22 | ||||
-rw-r--r-- | libTVaudio/audio_amaudio.h | 5 |
4 files changed, 103 insertions, 9 deletions
diff --git a/libTVaudio/audio/aml_audio.c b/libTVaudio/audio/aml_audio.c index 5bdb021..33b6ac5 100644 --- a/libTVaudio/audio/aml_audio.c +++ b/libTVaudio/audio/aml_audio.c @@ -6,6 +6,9 @@ ** Email: Zhe.Wang@amlogic.com ** */ + +#define LOG_TAG "aml_audio" + #include <stdbool.h> #include <stdio.h> #include <string.h> @@ -28,8 +31,6 @@ #include "android_out.h" #include "aml_audio.h" -#define LOG_TAG "aml_audio" - #define ANDROID_OUT_BUFFER_SIZE (2048*8*2) //in byte #define DDP_OUT_BUFFER_SIZE (2048*8*2*2*2) //in byte #define DD_61937_BUFFER_SIZE (2048*8*2*2*2) @@ -93,6 +94,8 @@ struct aml_stream_in { int delay_time; int last_delay_time; struct circle_buffer delay_buf; + float pre_gain; + uint pre_mute; }; struct aml_stream_out { @@ -161,6 +164,7 @@ static struct aml_dev gmAmlDevice = { .wr = NULL, .size = 0, }, + .pre_gain = 1.0, }, .out = { @@ -672,11 +676,11 @@ static int get_in_framesize(struct aml_stream_in *in) { return sample_format * in->config.channels; } -static void apply_stream_volume(float vol,char *buf,int size) { +static void apply_stream_volume_and_pregain(float vol, float gain, char *buf, int size) { int i; short *sample = (short*)buf; for (i = 0; i < size/sizeof(short); i++) - sample[i] = vol*sample[i]; + sample[i] = gain*vol*sample[i]; } static int alsa_in_read(struct aml_stream_in *in, void* buffer, size_t bytes) { @@ -704,9 +708,15 @@ static int alsa_in_read(struct aml_stream_in *in, void* buffer, size_t bytes) { return ret; } - if (GetOutputdevice() != 2) { + if (GetOutputdevice() != 2 && + (gUSBCheckFlag & AUDIO_DEVICE_OUT_SPEAKER) != 0) { float vol = get_android_stream_volume(); - apply_stream_volume(vol,in->resample_temp_buffer,bytes); + float gain = in->pre_gain; + uint pre_mute = in->pre_mute; + if (!pre_mute) + apply_stream_volume_and_pregain(vol,gain,in->resample_temp_buffer,bytes); + else + memset(in->resample_temp_buffer, 0, bytes); } DoDumpData(in->resample_temp_buffer, bytes, CC_DUMP_SRC_TYPE_INPUT); @@ -725,7 +735,12 @@ static int alsa_in_read(struct aml_stream_in *in, void* buffer, size_t bytes) { if (GetOutputdevice() != 2 && (gUSBCheckFlag & AUDIO_DEVICE_OUT_SPEAKER) != 0) { float vol = get_android_stream_volume(); - apply_stream_volume(vol,buffer,bytes); + float gain = in->pre_gain; + uint pre_mute = in->pre_mute; + if (!pre_mute) + apply_stream_volume_and_pregain(vol,gain,buffer,bytes); + else + memset(buffer, 0, bytes); } DoDumpData(buffer, bytes, CC_DUMP_SRC_TYPE_INPUT); @@ -2070,3 +2085,55 @@ static void DoDumpData(void *data_buf, int size, int aud_src_type) { } } } + +int aml_audio_set_pregain(float gain) +{ + ALOGD("%s, pre-gain = %f dB\n", __FUNCTION__, gain); + + pthread_mutex_lock(&amaudio_dev_op_mutex); + + if (gpAmlDevice != NULL) { + gpAmlDevice->in.pre_gain = powf(10, gain/20); + } + + pthread_mutex_unlock(&amaudio_dev_op_mutex); + + return 0; +} + +int aml_audio_get_pregain(float *gain) +{ + if (gpAmlDevice != NULL) { + *gain = 20*log10f(gpAmlDevice->in.pre_gain); + return 0; + } + + ALOGE("%s, no active gpAmlDevice!\n", __FUNCTION__); + return -1; +} + +int aml_audio_set_pre_mute(uint mute) +{ + ALOGD("%s, mute = %d\n", __FUNCTION__, mute); + + pthread_mutex_lock(&amaudio_dev_op_mutex); + + if (gpAmlDevice != NULL) { + gpAmlDevice->in.pre_mute = mute; + } + + pthread_mutex_unlock(&amaudio_dev_op_mutex); + + return 0; +} + +int aml_audio_get_pre_mute(uint *mute) +{ + if (gpAmlDevice != NULL) { + *mute = gpAmlDevice->in.pre_mute; + return 0; + } + + ALOGE("%s, no active gpAmlDevice!\n", __FUNCTION__); + return -1; +} diff --git a/libTVaudio/audio/aml_audio.h b/libTVaudio/audio/aml_audio.h index e0cd909..4e75d6c 100644 --- a/libTVaudio/audio/aml_audio.h +++ b/libTVaudio/audio/aml_audio.h @@ -72,6 +72,10 @@ int buffer_write(struct circle_buffer *tmp, char* buffer, size_t bytes); int set_output_record_enable(int enable); int set_audio_delay(int delay_ms); int get_audio_delay(void); +int aml_audio_set_pregain(float gain); +int aml_audio_get_pregain(float *gain); +int aml_audio_set_pre_mute(uint mute); +int aml_audio_get_pre_mute(uint *mute); #ifdef __cplusplus } diff --git a/libTVaudio/audio/audio_amaudio.cpp b/libTVaudio/audio/audio_amaudio.cpp index b5e2658..227a91e 100644 --- a/libTVaudio/audio/audio_amaudio.cpp +++ b/libTVaudio/audio/audio_amaudio.cpp @@ -1,3 +1,5 @@ +#define LOG_TAG "LibAudioCtl" + #include <stdbool.h> #include <stdio.h> #include <string.h> @@ -22,8 +24,6 @@ #include "audio_effect_control.h" #include "../audio_amaudio.h" -#define LOG_TAG "LibAudioCtl" - int amSetAudioDelay(int delay_ms) { return set_audio_delay(delay_ms); } @@ -223,3 +223,21 @@ int amAudioSetSRSTrubassSpeakerSize(int tmp_val) { return amAudioSetSRSParameter(CC_SET_TYPE_TRUBASS_SPEAKERSIZE, tmp_val); } +int amAudioSetPreGain(float gain) +{ + return aml_audio_set_pregain(gain); +} + +int amAudioGetPreGain(float *gain) +{ + return aml_audio_get_pregain(gain); +} +int amAudioSetPreMute(uint mute) +{ + return aml_audio_set_pre_mute(mute); +} + +int amAudioGetPreMute(uint *mute) +{ + return aml_audio_get_pre_mute(mute); +} diff --git a/libTVaudio/audio_amaudio.h b/libTVaudio/audio_amaudio.h index e3262b1..17759f7 100644 --- a/libTVaudio/audio_amaudio.h +++ b/libTVaudio/audio_amaudio.h @@ -31,4 +31,9 @@ int amAudioSetSRSGain(int input_gain, int output_gain); int amAudioSetDumpDataFlag(int tmp_flag); int amAudioGetDumpDataFlag(); +// gain is in dB float format +int amAudioSetPreGain(float gain); +int amAudioGetPreGain(float *gain); +int amAudioSetPreMute(uint mute); +int amAudioGetPreMute(uint *mute); #endif //__TV_AUDIO_AMAUDIO_H__ |