From 40508f66cacca49688b85540c79a2ddc3d96d13d Mon Sep 17 00:00:00 2001 From: Eric Laurent Date: Tue, 1 Jul 2014 20:33:36 -0700 Subject: audio: fixed channel count determination from channel mask Do not use popcount() to derive channel count from channel mask. Bug: 15000850. Change-Id: I5050ce7fd7884369eb0de37967e40052630006a9 --- audio/AudioHardwareStub.cpp | 6 ++++-- audio/audio_hw_hal.cpp | 2 +- include/hardware_legacy/AudioHardwareInterface.h | 6 ++++-- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/audio/AudioHardwareStub.cpp b/audio/AudioHardwareStub.cpp index 1083889..fd647d5 100644 --- a/audio/AudioHardwareStub.cpp +++ b/audio/AudioHardwareStub.cpp @@ -128,7 +128,8 @@ status_t AudioStreamOutStub::set(int *pFormat, uint32_t *pChannels, uint32_t *pR ssize_t AudioStreamOutStub::write(const void* buffer, size_t bytes) { // fake timing for audio output - usleep(bytes * 1000000 / sizeof(int16_t) / AudioSystem::popCount(channels()) / sampleRate()); + usleep(bytes * 1000000 / sizeof(int16_t) / + audio_channel_count_from_out_mask(channels()) / sampleRate()); return bytes; } @@ -174,7 +175,8 @@ status_t AudioStreamInStub::set(int *pFormat, uint32_t *pChannels, uint32_t *pRa ssize_t AudioStreamInStub::read(void* buffer, ssize_t bytes) { // fake timing for audio input - usleep(bytes * 1000000 / sizeof(int16_t) / AudioSystem::popCount(channels()) / sampleRate()); + usleep(bytes * 1000000 / sizeof(int16_t) / + audio_channel_count_from_in_mask(channels()) / sampleRate()); memset(buffer, 0, bytes); return bytes; } diff --git a/audio/audio_hw_hal.cpp b/audio/audio_hw_hal.cpp index 9b1f1a3..23ebdae 100644 --- a/audio/audio_hw_hal.cpp +++ b/audio/audio_hw_hal.cpp @@ -480,7 +480,7 @@ static size_t adev_get_input_buffer_size(const struct audio_hw_device *dev, { const struct legacy_audio_device *ladev = to_cladev(dev); return ladev->hwif->getInputBufferSize(config->sample_rate, (int) config->format, - popcount(config->channel_mask)); + audio_channel_count_from_in_mask(config->channel_mask)); } static int adev_open_output_stream(struct audio_hw_device *dev, diff --git a/include/hardware_legacy/AudioHardwareInterface.h b/include/hardware_legacy/AudioHardwareInterface.h index f5b38ea..d37da11 100644 --- a/include/hardware_legacy/AudioHardwareInterface.h +++ b/include/hardware_legacy/AudioHardwareInterface.h @@ -69,7 +69,8 @@ public: /** * return the frame size (number of bytes per sample). */ - uint32_t frameSize() const { return popcount(channels())*((format()==AUDIO_FORMAT_PCM_16_BIT)?sizeof(int16_t):sizeof(int8_t)); } + uint32_t frameSize() const { return audio_channel_count_from_out_mask(channels())* + ((format()==AUDIO_FORMAT_PCM_16_BIT)?sizeof(int16_t):sizeof(int8_t)); } /** * return the audio hardware driver latency in milli seconds. @@ -145,7 +146,8 @@ public: /** * return the frame size (number of bytes per sample). */ - uint32_t frameSize() const { return AudioSystem::popCount(channels())*((format()==AudioSystem::PCM_16_BIT)?sizeof(int16_t):sizeof(int8_t)); } + uint32_t frameSize() const { return audio_channel_count_from_in_mask(channels())* + ((format()==AudioSystem::PCM_16_BIT)?sizeof(int16_t):sizeof(int8_t)); } /** set the input gain for the audio driver. This method is for * for future use */ -- cgit v1.1