Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 33d33067 authored by Ravi Kumar Alamanda's avatar Ravi Kumar Alamanda Committed by Vineeta Srivastava
Browse files

audio/hal: Set playback buffer size to integral multiple of msec

- Set the deep-buffer and low-latency output buffer sizes to
  integral multiple of msec. This reduces the variations in
  the writes.
- Compute the input buffer size based on sample rate. Use 20msec
  buffers in capture path.

Bug: 9283911, 9106434
Change-Id: Icbcb653f7f0fd3293dd4b514a54ac91d8311b308
parent b23d5286
Loading
Loading
Loading
Loading
+11 −12
Original line number Diff line number Diff line
@@ -73,7 +73,6 @@ struct pcm_config pcm_config_hdmi_multi = {

struct pcm_config pcm_config_audio_capture = {
    .channels = 2,
    .period_size = AUDIO_CAPTURE_PERIOD_SIZE,
    .period_count = AUDIO_CAPTURE_PERIOD_COUNT,
    .format = PCM_FORMAT_S16_LE,
};
@@ -817,19 +816,19 @@ static size_t get_input_buffer_size(uint32_t sample_rate,
{
    size_t size = 0;

    if (check_input_parameters(sample_rate, format, channel_count) != 0) return 0;
    if (check_input_parameters(sample_rate, format, channel_count) != 0)
        return 0;

    if (sample_rate == 8000 || sample_rate == 16000 || sample_rate == 32000) {
        size = (sample_rate * 20) / 1000;
    } else if (sample_rate == 11025 || sample_rate == 12000) {
        size = 256;
    } else if (sample_rate == 22050 || sample_rate == 24000) {
        size = 512;
    } else if (sample_rate == 44100 || sample_rate == 48000) {
        size = 1024;
    }
    size = (sample_rate * AUDIO_CAPTURE_PERIOD_DURATION_MSEC) / 1000;
    /* ToDo: should use frame_size computed based on the format and
       channel_count here. */
    size *= sizeof(short) * channel_count;

    /* make sure the size is multiple of 64 */
    size += 0x3f;
    size &= ~0x3f;

    return size * sizeof(short) * channel_count;
    return size;
}

static uint32_t out_get_sample_rate(const struct audio_stream *stream)
+1 −1
Original line number Diff line number Diff line
@@ -111,7 +111,7 @@ enum {
#define HDMI_MULTI_DEFAULT_CHANNEL_COUNT 6
#define HDMI_MULTI_PERIOD_BYTES (HDMI_MULTI_PERIOD_SIZE * HDMI_MULTI_DEFAULT_CHANNEL_COUNT * 2)

#define AUDIO_CAPTURE_PERIOD_SIZE 320
#define AUDIO_CAPTURE_PERIOD_DURATION_MSEC 20
#define AUDIO_CAPTURE_PERIOD_COUNT 2

#endif // QCOM_AUDIO_PLATFORM_H
+4 −4
Original line number Diff line number Diff line
@@ -102,9 +102,9 @@ enum {
 * We should take care of returning proper size when AudioFlinger queries for
 * the buffer size of an input/output stream
 */
#define DEEP_BUFFER_OUTPUT_PERIOD_SIZE 1024
#define DEEP_BUFFER_OUTPUT_PERIOD_SIZE 960
#define DEEP_BUFFER_OUTPUT_PERIOD_COUNT 8
#define LOW_LATENCY_OUTPUT_PERIOD_SIZE 256
#define LOW_LATENCY_OUTPUT_PERIOD_SIZE 240
#define LOW_LATENCY_OUTPUT_PERIOD_COUNT 2

#define HDMI_MULTI_PERIOD_SIZE  336
@@ -112,7 +112,7 @@ enum {
#define HDMI_MULTI_DEFAULT_CHANNEL_COUNT 6
#define HDMI_MULTI_PERIOD_BYTES (HDMI_MULTI_PERIOD_SIZE * HDMI_MULTI_DEFAULT_CHANNEL_COUNT * 2)

#define AUDIO_CAPTURE_PERIOD_SIZE 512
#define AUDIO_CAPTURE_PERIOD_COUNT 16
#define AUDIO_CAPTURE_PERIOD_DURATION_MSEC 20
#define AUDIO_CAPTURE_PERIOD_COUNT 2

#endif // QCOM_AUDIO_PLATFORM_H