Skip to content

Commit 4c88a65

Browse files
committed
tinyhal: audio: Impl channel adjustment for input sound flow
The issue is detected on RCAR3 platform where high level applications can not capture a sound through Tinyhal with requested channel count less than 8 (the min/max interval for allowed channel count values is set to [8..8] in 'pcm3168a' driver, so pcm_open() function returns error in case count != 8). But only AUDIO_CHANNEL_IN_MONO & AUDIO_CHANNEL_IN_STEREO channel masks are supported in alsa_device_profile.c file ('alsa_utils' directory). So it is required to implement a patch which provides a channel adjustment for input sound by converting the 8-channel flow to requested Mono or Stereo flow. Signed-off-by: Oleksandr Bobro <oleksandr.bobro@globallogic.com>
1 parent 5f03d4a commit 4c88a65

1 file changed

Lines changed: 39 additions & 3 deletions

File tree

audio/audio_hw.c

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
#endif
4949

5050
#include <audio_utils/resampler.h>
51+
#include <audio_utils/channels.h>
5152

5253
#include <tinyhal/audio_config.h>
5354

@@ -1874,10 +1875,45 @@ static ssize_t do_in_pcm_read(struct audio_stream_in *stream, void *buffer,
18741875
goto exit;
18751876
}
18761877

1877-
if (in->resampler.resampler != NULL) {
1878-
ret = read_resampled_frames(in, buffer, frames_rq);
1878+
if (in->common.channel_count != in->hw_channel_count) {
1879+
1880+
ALOGV("do_in_pcm_read(): Read %d channel stream with adjustment (HW only supports %d channel reading)",
1881+
in->common.channel_count, in->hw_channel_count);
1882+
1883+
size_t read_buf_size = bytes * in->hw_channel_count / in->common.channel_count;
1884+
void *read_buffer = calloc(1, read_buf_size);
1885+
if (!read_buffer) {
1886+
ret = -1;
1887+
goto exit;
1888+
}
1889+
1890+
if (in->resampler.resampler != NULL) {
1891+
ret = read_resampled_frames(in, read_buffer, frames_rq);
1892+
} else {
1893+
ret = pcm_read(in->pcm, read_buffer, read_buf_size);
1894+
}
1895+
1896+
if (ret >= 0) {
1897+
bytes = adjust_channels(read_buffer, /* Input buffer */
1898+
in->hw_channel_count, /* Input channel count */
1899+
buffer, /* Output buffer */
1900+
in->common.channel_count, /* Output channel count */
1901+
in->common.frame_size / in->common.channel_count, /* Sample size */
1902+
read_buf_size /* Size of input buffer in bytes */
1903+
);
1904+
if (!bytes) {
1905+
ALOGE("do_in_pcm_read(): Failed to adjust channels");
1906+
ret = -1;
1907+
}
1908+
}
1909+
free(read_buffer);
1910+
18791911
} else {
1880-
ret = pcm_read(in->pcm, buffer, bytes);
1912+
if (in->resampler.resampler != NULL) {
1913+
ret = read_resampled_frames(in, buffer, frames_rq);
1914+
} else {
1915+
ret = pcm_read(in->pcm, buffer, bytes);
1916+
}
18811917
}
18821918

18831919
/* Assume any non-negative return is a successful read */

0 commit comments

Comments
 (0)