diff options
author | Simon Ser <simon.ser@intel.com> | 2019-05-17 13:11:55 +0300 |
---|---|---|
committer | Simon Ser <simon.ser@intel.com> | 2019-05-17 15:47:10 +0300 |
commit | 6fe5d254ec1b9b47d61408e1b49a7339876bf1e7 (patch) | |
tree | 069e6455c2a418cda7033ff34ee6f4e7fa7662f8 /lib/igt_audio.c | |
parent | 959f5a11b9690a73c2e7b2888a8874c76d55ff89 (diff) |
lib/igt_audio: sanity-check generated signals
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>
Reviewed-by: Martin Peres <martin.peres@linux.intel.com>
Diffstat (limited to 'lib/igt_audio.c')
-rw-r--r-- | lib/igt_audio.c | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/lib/igt_audio.c b/lib/igt_audio.c index f6c8e399..adf814a0 100644 --- a/lib/igt_audio.c +++ b/lib/igt_audio.c @@ -38,6 +38,7 @@ #define FREQS_MAX 64 #define CHANNELS_MAX 8 #define SYNTHESIZE_AMPLITUDE 0.9 +#define SYNTHESIZE_ACCURACY 0.2 /** * SECTION:igt_audio @@ -213,6 +214,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 + SYNTHESIZE_ACCURACY); + igt_assert(SYNTHESIZE_AMPLITUDE - SYNTHESIZE_ACCURACY <= max); + igt_assert(max <= SYNTHESIZE_AMPLITUDE); +} + /** * audio_signal_fill: * @signal: The target signal structure @@ -268,6 +297,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, |