hal: Fix alignement of buffer sent to DSP for multichannel clips
- currently buffer size is Aligned with 96 which is not multiple
of some channels(5,7).
- Buffer size must be multiple of (number of channels * bytes per sample).
For writes to succeed, the buffer must be written at address which is
multiple of 32.
- Alignments of (number of channels * bytes per sample)*32 satisfies both
of the above requirements.
Change-Id: I20de875615141a4a331383a5348abd28b97306f7
diff --git a/hal/msm8916/platform.c b/hal/msm8916/platform.c
index b9b0e28..4b970bd 100644
--- a/hal/msm8916/platform.c
+++ b/hal/msm8916/platform.c
@@ -3290,8 +3290,7 @@
// To have same PCM samples for all channels, the buffer size requires to
// be multiple of (number of channels * bytes per sample)
// For writes to succeed, the buffer must be written at address which is multiple of 32
- // Alignment of 96 satsfies both of the above requirements
- fragment_size = ALIGN(fragment_size, 96);
+ fragment_size = ALIGN(fragment_size, ((bits_per_sample >> 3)* popcount(info->channel_mask) * 32));
ALOGI("PCM offload Fragment size to %d bytes", fragment_size);
return fragment_size;
diff --git a/hal/msm8974/platform.c b/hal/msm8974/platform.c
index b4c4c44..0d48617 100644
--- a/hal/msm8974/platform.c
+++ b/hal/msm8974/platform.c
@@ -3021,15 +3021,14 @@
* info->sample_rate
* (bits_per_sample >> 3)
* popcount(info->channel_mask))/1000;
- // To have same PCM samples for all channels, the buffer size requires to
- // be multiple of (number of channels * bytes per sample)
- // For writes to succeed, the buffer must be written at address which is multiple of 32
- // Alignment of 96 satsfies both of the above requirements
- fragment_size = ALIGN(fragment_size, 96);
if(fragment_size < MIN_PCM_OFFLOAD_FRAGMENT_SIZE)
fragment_size = MIN_PCM_OFFLOAD_FRAGMENT_SIZE;
else if(fragment_size > MAX_PCM_OFFLOAD_FRAGMENT_SIZE)
fragment_size = MAX_PCM_OFFLOAD_FRAGMENT_SIZE;
+ // To have same PCM samples for all channels, the buffer size requires to
+ // be multiple of (number of channels * bytes per sample)
+ // For writes to succeed, the buffer must be written at address which is multiple of 32
+ fragment_size = ALIGN(fragment_size, ((bits_per_sample >> 3)* popcount(info->channel_mask) * 32));
ALOGI("PCM offload Fragment size to %d bytes", fragment_size);
return fragment_size;