summaryrefslogtreecommitdiff
path: root/lib/tests
diff options
context:
space:
mode:
authorSimon Ser <simon.ser@intel.com>2019-06-04 14:16:52 +0300
committerSimon Ser <simon.ser@intel.com>2019-06-12 14:13:15 +0300
commitc113a803d311915ac2c7fd6a2f71d344b1b6fedd (patch)
treed79e9b14ad60e934ea1724f30c3f645be0ecda39 /lib/tests
parenta66f3dd29d2ce1a9c089596e5619bff7d5a62ed6 (diff)
lib/tests/igt_audio: add phaseshift detection test
Truncate a few samples in the middle of the signal, and make sure the detection fails. Signed-off-by: Simon Ser <simon.ser@intel.com> Reviewed-by: Martin Peres <martin.peres@linux.intel.com>
Diffstat (limited to 'lib/tests')
-rw-r--r--lib/tests/igt_audio.c36
1 files changed, 36 insertions, 0 deletions
diff --git a/lib/tests/igt_audio.c b/lib/tests/igt_audio.c
index 4a48aed2..0fb8f94c 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 };
@@ -138,6 +140,37 @@ static void test_signal_detect_held_sample(struct audio_signal *signal)
igt_assert_f(!ok, "Expected audio signal not to be detected\n");
}
+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;
@@ -176,6 +209,9 @@ igt_main
igt_subtest("signal-detect-held-sample")
test_signal_detect_held_sample(signal);
+ igt_subtest("signal-detect-phaseshift")
+ test_signal_detect_phaseshift(signal);
+
igt_fixture {
audio_signal_fini(signal);
}