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

Simon Ser simon.ser at intel.com
Fri May 17 10:11:55 UTC 2019


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 at 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);
+}
+
 /**
  * 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,
-- 
2.21.0



More information about the igt-dev mailing list