From 07f20ab0fd9089a1b5c97a9bcbec1df5979f318e Mon Sep 17 00:00:00 2001 From: Paul Kocialkowski Date: Wed, 31 Oct 2012 12:57:56 +0100 Subject: Return correct input buffer size. Signed-off-by: Paul Kocialkowski --- audio_hw.c | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/audio_hw.c b/audio_hw.c index 0292216..cfe4058 100644 --- a/audio_hw.c +++ b/audio_hw.c @@ -310,9 +310,33 @@ static char *audio_hw_get_parameters(const struct audio_hw_device *dev, static size_t audio_hw_get_input_buffer_size(const struct audio_hw_device *dev, uint32_t sample_rate, int format, int channel_count) { + struct tinyalsa_audio_device *device; + struct tinyalsa_mixer_io_props *mixer_props; + size_t size; + LOGD("%s(%p, %d, %d, %d)", __func__, dev, sample_rate, format, channel_count); - return 320; + if(dev == NULL) + return -1; + + device = (struct tinyalsa_audio_device *) dev; + + if(device->mixer == NULL) + return -1; + + mixer_props = tinyalsa_mixer_get_input_props(device->mixer); + if(mixer_props == NULL) + return -1; + + // Default value + if(mixer_props->rate == 0) + mixer_props->rate = 44100; + + size = (mixer_props->period_size * sample_rate) / mixer_props->rate; + size = ((size + 15) / 16) * 16; + size = size * channel_count * audio_bytes_per_sample(format); + + return size; } static int audio_hw_dump(const audio_hw_device_t *device, int fd) -- cgit v1.1