diff options
| author | SathishKumar Mani <smani@codeaurora.org> | 2012-09-21 20:58:33 -0700 |
|---|---|---|
| committer | Iliyan Malchev <malchev@google.com> | 2012-09-26 15:29:55 -0700 |
| commit | 77780382b45794eb5bc0e8589d9b7c96bb406772 (patch) | |
| tree | 531c3546ac162c5607223b7ee4cb97e6ccf6f9f7 | |
| parent | c669c27ef9c5663692c3dd8818bb6e7fcdc39b7a (diff) | |
| download | android_hardware_qcom_audio-77780382b45794eb5bc0e8589d9b7c96bb406772.tar.gz android_hardware_qcom_audio-77780382b45794eb5bc0e8589d9b7c96bb406772.tar.bz2 android_hardware_qcom_audio-77780382b45794eb5bc0e8589d9b7c96bb406772.zip | |
alsa_sound: Add support for flexible buffer size for recording
- In the current implementation, all the read calls to the driver
are limited to 320 bytes only. This results performance overhead
for recording at higher sampling rates.
- Added support for flexible buffer size to allow upto 4096 bytes.
Bug: 7223456
Change-Id: Ic0522d92de905b04481a0d8daa103c77552257e8
Signed-off-by: Iliyan Malchev <malchev@google.com>
| -rw-r--r-- | alsa_sound/AudioHardwareALSA.cpp | 46 | ||||
| -rw-r--r-- | alsa_sound/AudioHardwareALSA.h | 5 | ||||
| -rw-r--r-- | alsa_sound/alsa_default.cpp | 3 |
3 files changed, 23 insertions, 31 deletions
diff --git a/alsa_sound/AudioHardwareALSA.cpp b/alsa_sound/AudioHardwareALSA.cpp index 9aacc2ff..ed82f527 100644 --- a/alsa_sound/AudioHardwareALSA.cpp +++ b/alsa_sound/AudioHardwareALSA.cpp @@ -848,7 +848,7 @@ AudioHardwareALSA::openOutputStream(uint32_t devices, } else { ALOGD("openOutputStream: Lowlatency Output"); alsa_handle.bufferSize = PLAYBACK_LOW_LATENCY_BUFFER_SIZE; - alsa_handle.latency = PLAYBACK_LOW_LATENCY; + alsa_handle.latency = PLAYBACK_LOW_LATENCY_MEASURED; if ((use_case == NULL) || (!strcmp(use_case, SND_USE_CASE_VERB_INACTIVE))) { strlcpy(alsa_handle.useCase, SND_USE_CASE_VERB_HIFI_LOWLATENCY_MUSIC, sizeof(alsa_handle.useCase)); } else { @@ -1114,7 +1114,7 @@ AudioHardwareALSA::openInputStream(uint32_t devices, return in; } else { alsa_handle_t alsa_handle; - unsigned long bufferSize = DEFAULT_IN_BUFFER_SIZE; + unsigned long bufferSize = MIN_CAPTURE_BUFFER_SIZE_PER_CH; alsa_handle.module = mALSADevice; alsa_handle.bufferSize = bufferSize; @@ -1266,15 +1266,11 @@ AudioHardwareALSA::openInputStream(uint32_t devices, if(sampleRate) { it->sampleRate = *sampleRate; } -#ifdef QCOM_SSR_ENABLED - if (6 == it->channels) { - if (!strncmp(it->useCase, SND_USE_CASE_VERB_HIFI_REC, strlen(SND_USE_CASE_VERB_HIFI_REC)) - || !strncmp(it->useCase, SND_USE_CASE_MOD_CAPTURE_MUSIC, strlen(SND_USE_CASE_MOD_CAPTURE_MUSIC))) { - ALOGV("OpenInoutStream: Use larger buffer size for 5.1(%s) recording ", it->useCase); - it->bufferSize = getInputBufferSize(it->sampleRate,*format,it->channels); - } + if (!strncmp(it->useCase, SND_USE_CASE_VERB_HIFI_REC, strlen(SND_USE_CASE_VERB_HIFI_REC)) + || !strncmp(it->useCase, SND_USE_CASE_MOD_CAPTURE_MUSIC, strlen(SND_USE_CASE_MOD_CAPTURE_MUSIC))) { + ALOGV("OpenInoutStream: Use larger buffer size for 5.1(%s) recording ", it->useCase); + it->bufferSize = getInputBufferSize(it->sampleRate,*format,it->channels); } -#endif err = mALSADevice->open(&(*it)); if (err) { ALOGE("Error opening pcm input device"); @@ -1338,25 +1334,19 @@ status_t AudioHardwareALSA::dump(int fd, const Vector<String16>& args) size_t AudioHardwareALSA::getInputBufferSize(uint32_t sampleRate, int format, int channelCount) { - size_t bufferSize; - if (format != AudioSystem::PCM_16_BIT - && format != AudioSystem::AMR_NB - && format != AudioSystem::AMR_WB -#ifdef QCOM_QCHAT_ENABLED - && format != AudioSystem::EVRC - && format != AudioSystem::EVRCB - && format != AudioSystem::EVRCWB -#endif - ) { - ALOGW("getInputBufferSize bad format: %d", format); - return 0; - } - if(sampleRate == 16000) { - bufferSize = DEFAULT_IN_BUFFER_SIZE * 2 * channelCount; - } else if(sampleRate < 44100) { - bufferSize = DEFAULT_IN_BUFFER_SIZE * channelCount; + size_t bufferSize = 0; + if (format == AudioSystem::PCM_16_BIT) { + if(sampleRate == 8000 || sampleRate == 16000 || sampleRate == 32000) { + bufferSize = (sampleRate * channelCount * 20 * sizeof(int16_t)) / 1000; + } else if (sampleRate == 11025 || sampleRate == 12000) { + bufferSize = 256 * sizeof(int16_t) * channelCount; + } else if (sampleRate == 22050 || sampleRate == 24000) { + bufferSize = 512 * sizeof(int16_t) * channelCount; + } else if (sampleRate == 44100 || sampleRate == 48000) { + bufferSize = 1024 * sizeof(int16_t) * channelCount; + } } else { - bufferSize = DEFAULT_IN_BUFFER_SIZE * 12; + ALOGE("getInputBufferSize bad format: %d", format); } return bufferSize; } diff --git a/alsa_sound/AudioHardwareALSA.h b/alsa_sound/AudioHardwareALSA.h index 0a0b06e9..3d952a43 100644 --- a/alsa_sound/AudioHardwareALSA.h +++ b/alsa_sound/AudioHardwareALSA.h @@ -65,8 +65,11 @@ class AudioHardwareALSA; #define DEFAULT_BUFFER_SIZE 4096 #define DEFAULT_VOICE_BUFFER_SIZE 2048 #define PLAYBACK_LOW_LATENCY_BUFFER_SIZE 1024 -#define PLAYBACK_LOW_LATENCY 11000 +#define PLAYBACK_LOW_LATENCY 22000 +#define PLAYBACK_LOW_LATENCY_MEASURED 42000 #define DEFAULT_IN_BUFFER_SIZE 320 +#define MIN_CAPTURE_BUFFER_SIZE_PER_CH 320 +#define MAX_CAPTURE_BUFFER_SIZE_PER_CH 2048 #define FM_BUFFER_SIZE 1024 #define VOIP_SAMPLING_RATE_8K 8000 diff --git a/alsa_sound/alsa_default.cpp b/alsa_sound/alsa_default.cpp index ea8ad2f0..c285e1e0 100644 --- a/alsa_sound/alsa_default.cpp +++ b/alsa_sound/alsa_default.cpp @@ -252,7 +252,6 @@ status_t setHardwareParams(alsa_handle_t *handle) || !strncmp(handle->useCase, SND_USE_CASE_MOD_CAPTURE_MUSIC, strlen(SND_USE_CASE_MOD_CAPTURE_MUSIC))) { ALOGV("HWParams: Use 4 channels in kernel for 5.1(%s) recording ", handle->useCase); channels = 4; - reqBuffSize = DEFAULT_IN_BUFFER_SIZE; } } #endif @@ -275,7 +274,7 @@ status_t setHardwareParams(alsa_handle_t *handle) format); param_set_mask(params, SNDRV_PCM_HW_PARAM_SUBFORMAT, SNDRV_PCM_SUBFORMAT_STD); - param_set_min(params, SNDRV_PCM_HW_PARAM_PERIOD_BYTES, reqBuffSize); + param_set_int(params, SNDRV_PCM_HW_PARAM_PERIOD_BYTES, reqBuffSize); param_set_int(params, SNDRV_PCM_HW_PARAM_SAMPLE_BITS, 16); param_set_int(params, SNDRV_PCM_HW_PARAM_FRAME_BITS, channels * 16); |
