[igt-dev] [PATCH i-g-t v2 3/3] lib/tests/igt_audio: add phaseshift detection test

Simon Ser simon.ser at intel.com
Tue Jun 4 11:48:36 UTC 2019


Truncate a few samples in the middle of the signal, and make sure the detection
fails.

Signed-off-by: Simon Ser <simon.ser at intel.com>
---
 lib/tests/igt_audio.c | 36 ++++++++++++++++++++++++++++++++++++
 1 file changed, 36 insertions(+)

diff --git a/lib/tests/igt_audio.c b/lib/tests/igt_audio.c
index 821813bae47a..7c5279acc92e 100644
--- a/lib/tests/igt_audio.c
+++ b/lib/tests/igt_audio.c
@@ -33,6 +33,8 @@
 #define SAMPLING_RATE 44100
 #define CHANNELS 1
 #define BUFFER_LEN 2048
+/** PHASESHIFT_LEN: how many samples will be truncated from the signal */
+#define PHASESHIFT_LEN 8
 
 static const int test_freqs[] = { 300, 700, 5000 };
 
@@ -136,6 +138,37 @@ static void test_signal_detect_pop(struct audio_signal *signal)
 	igt_assert(!ok);
 }
 
+static void test_signal_detect_phaseshift(struct audio_signal *signal)
+{
+	double *buf;
+	bool ok;
+
+	buf = malloc((BUFFER_LEN + PHASESHIFT_LEN) * sizeof(double));
+	audio_signal_fill(signal, buf, (BUFFER_LEN + PHASESHIFT_LEN) / CHANNELS);
+
+	/* Perform a phaseshift (this isn't related to sirens).
+	 *
+	 * The idea is to remove a part of the signal in the middle of the
+	 * buffer:
+	 *
+	 *   BUFFER_LEN/3   PHASESHIFT_LEN            2*BUFFER_LEN/3
+	 * [--------------|################|---------------------------------]
+	 *
+	 *                           |
+	 *                           V
+	 *
+	 * [--------------|---------------------------------]
+	 */
+	memmove(&buf[BUFFER_LEN / 3], &buf[BUFFER_LEN / 3 + PHASESHIFT_LEN],
+		(2 * BUFFER_LEN / 3) * sizeof(double));
+
+	ok = audio_signal_detect(signal, SAMPLING_RATE, 0, buf, BUFFER_LEN);
+
+	free(buf);
+
+	igt_assert(!ok);
+}
+
 igt_main
 {
 	struct audio_signal *signal;
@@ -174,6 +207,9 @@ igt_main
 		igt_subtest("signal-detect-pop")
 			test_signal_detect_pop(signal);
 
+		igt_subtest("signal-detect-phaseshift")
+			test_signal_detect_phaseshift(signal);
+
 		igt_fixture {
 			audio_signal_fini(signal);
 		}
-- 
2.21.0



More information about the igt-dev mailing list