Re: [igt-dev] [PATCH i-g-t 2/2] lib/igt_audio: sanity-check generated signals

Martin Peres
2019-05-17T12:33:04Z

On 17/05/2019 13:11, Simon Ser wrote:
> This is a safety net to ensure we haven't completely messed up our signal
> generation. It would be unfortunate to send e.g. a null signal after a
> refactoring.
>
> Signed-off-by: Simon Ser <simon.ser@intel.com>
> ---
> lib/igt_audio.c | 30 ++++++++++++++++++++++++++++++
> 1 file changed, 30 insertions(+)
>
> diff --git a/lib/igt_audio.c b/lib/igt_audio.c
> index f6c8e399e345..0d7422c6f3ec 100644
> --- a/lib/igt_audio.c
> +++ b/lib/igt_audio.c
> @@ -213,6 +213,34 @@ static size_t audio_signal_count_freqs(struct audio_signal *signal, int channel)
> return n;
> }
>
> +/** audio_sanity_check:
> + *
> + * Make sure our generated signal is not messed up. In particular, make sure
> + * the maximum reaches a reasonable value but doesn't exceed our
> + * SYNTHESIZE_AMPLITUDE limit. Same for the minimum.
> + *
> + * We want the signal to be powerful enough to be able to hear something. We
> + * want the signal not to reach 1.0 so that we're sure it won't get capped by
> + * the audio card or the receiver.
> + */
> +static void audio_sanity_check(double *samples, size_t samples_len)
> +{
> + size_t i;
> + double min = 0, max = 0;
> +
> + for (i = 0; i < samples_len; i++) {
> + if (samples[i] < min)
> + min = samples[i];
> + if (samples[i] > max)
> + max = samples[i];
> + }
> +
> + igt_assert(-SYNTHESIZE_AMPLITUDE <= min);
> + igt_assert(min <= -SYNTHESIZE_AMPLITUDE + 0.2);
> + igt_assert(SYNTHESIZE_AMPLITUDE - 0.2 <= max);
> + igt_assert(max <= SYNTHESIZE_AMPLITUDE);

Maybe we should make the 0.2 a MACRO? Anyway, looks good!

Reviewed-by: Martin Peres <martin.peres@linux.intel.com>
> +}
> +
> /**
> * audio_signal_fill:
> * @signal: The target signal structure
> @@ -268,6 +296,8 @@ void audio_signal_fill(struct audio_signal *signal, double *buffer,
> total += count;
> }
> }
> +
> + audio_sanity_check(buffer, signal->channels * samples);
> }
>
> void audio_signal_fill_s16_le(struct audio_signal *signal, int16_t *buffer,
>
---------------------------------------------------------------------
Intel Finland Oy
Registered Address: PL 281, 00181 Helsinki
Business Identity Code: 0357606 - 4
Domiciled in Helsinki

This e-mail and any attachments may contain confidential material for
the sole use of the intended recipient(s). Any review or distribution
by others is strictly prohibited. If you are not the intended
recipient, please contact the sender and delete all copies.