[igt-dev] [PATCH i-g-t v2 7/9] lib/igt_audio: make audio_extract_channel_s32_le support a NULL dst

Martin Peres martin.peres at linux.intel.com
Mon May 27 12:30:15 UTC 2019


On 24/05/2019 18:03, Simon Ser wrote:
> This adds a snprintf-like behaviour to audio_extract_channel_s32_le.
> 
> Signed-off-by: Simon Ser <simon.ser at intel.com>

Reviewed-by: Martin Peres <martin.peres at linux.intel.com>

> ---
>  lib/igt_audio.c | 11 ++++++++++-
>  1 file changed, 10 insertions(+), 1 deletion(-)
> 
> diff --git a/lib/igt_audio.c b/lib/igt_audio.c
> index f2aac0e23a37..c7407fa1a97b 100644
> --- a/lib/igt_audio.c
> +++ b/lib/igt_audio.c
> @@ -445,7 +445,13 @@ bool audio_signal_detect(struct audio_signal *signal, int sampling_rate,
>  }
>  
>  /**
> - * Extracts a single channel from a multi-channel S32_LE input buffer.
> + * audio_extract_channel_s32_le: extracts a single channel from a multi-channel
> + * S32_LE input buffer.
> + *
> + * If dst_cap is zero, no copy is performed. This can be used to compute the
> + * minimum required capacity.
> + *
> + * Returns: the number of samples extracted.
>   */
>  size_t audio_extract_channel_s32_le(double *dst, size_t dst_cap,
>  				    int32_t *src, size_t src_len,
> @@ -456,6 +462,9 @@ size_t audio_extract_channel_s32_le(double *dst, size_t dst_cap,
>  	igt_assert(channel < n_channels);
>  	igt_assert(src_len % n_channels == 0);
>  	dst_len = src_len / n_channels;
> +	if (dst_cap == 0)
> +		return dst_len;
> +
>  	igt_assert(dst_len <= dst_cap);
>  	for (i = 0; i < dst_len; i++)
>  		dst[i] = (double) src[i * n_channels + channel] / INT32_MAX;
> 


More information about the igt-dev mailing list