From: "Ser, Simon" <simon.ser@intel.com>
To: "igt-dev@lists.freedesktop.org" <igt-dev@lists.freedesktop.org>,
"martin.peres@linux.intel.com" <martin.peres@linux.intel.com>
Cc: "Peres, Martin" <martin.peres@intel.com>
Subject: Re: [igt-dev] [PATCH i-g-t 1/5] lib/igt_audio: add basic audio_signal_detect tests
Date: Tue, 4 Jun 2019 08:00:42 +0000 [thread overview]
Message-ID: <873142b8978b29b9eda842100198c18572a16682.camel@intel.com> (raw)
In-Reply-To: <96a33b04-083f-d5b7-0ada-4113b370e399@linux.intel.com>
On Mon, 2019-06-03 at 16:43 +0300, Martin Peres wrote:
> On 29/05/2019 16:32, Simon Ser wrote:
> > This adds three basic library tests for igt_audio's audio_signal_detect: one
> > that checks that detection works with the generated signal unchanged, and two
> > that check that detection properly fails with a silent/noise input signal.
> >
> > Signed-off-by: Simon Ser <simon.ser@intel.com>
> > ---
> > lib/tests/igt_audio.c | 101 ++++++++++++++++++++++++++++++++++++++++++
> > lib/tests/meson.build | 7 +++
> > 2 files changed, 108 insertions(+)
> > create mode 100644 lib/tests/igt_audio.c
> >
> > diff --git a/lib/tests/igt_audio.c b/lib/tests/igt_audio.c
> > new file mode 100644
> > index 000000000000..0ca3a4342ad9
> > --- /dev/null
> > +++ b/lib/tests/igt_audio.c
> > @@ -0,0 +1,101 @@
> > +/*
> > + * Copyright © 2019 Intel Corporation
> > + *
> > + * Permission is hereby granted, free of charge, to any person obtaining a
> > + * copy of this software and associated documentation files (the "Software"),
> > + * to deal in the Software without restriction, including without limitation
> > + * the rights to use, copy, modify, merge, publish, distribute, sublicense,
> > + * and/or sell copies of the Software, and to permit persons to whom the
> > + * Software is furnished to do so, subject to the following conditions:
> > + *
> > + * The above copyright notice and this permission notice (including the next
> > + * paragraph) shall be included in all copies or substantial portions of the
> > + * Software.
> > + *
> > + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
> > + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
> > + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
> > + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
> > + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
> > + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
> > + * IN THE SOFTWARE.
> > + *
> > + * Author: Simon Ser <simon.ser@intel.com>
> > + */
> > +
> > +#include "config.h"
> > +
> > +#include "igt_core.h"
> > +#include "igt_audio.h"
> > +
> > +#define SAMPLING_RATE 44100
> > +#define CHANNELS 1
> > +#define BUFFER_LEN 2048
> > +
> > +static void test_signal_detect_verbatim(struct audio_signal *signal)
>
> test_signal_detect_untampered would be more understandable.
>
> > +{
> > + double buf[BUFFER_LEN];
> > + bool ok;
> > +
> > + audio_signal_fill(signal, buf, BUFFER_LEN / CHANNELS);
> > + ok = audio_signal_detect(signal, SAMPLING_RATE, 0, buf, BUFFER_LEN);
> > + igt_assert(ok);
> > +}
> > +
> > +static void test_signal_detect_silence(struct audio_signal *signal)
> > +{
> > + double buf[BUFFER_LEN] = {0};
> > + bool ok;
> > +
> > + ok = audio_signal_detect(signal, SAMPLING_RATE, 0, buf, BUFFER_LEN);
> > +
> > + igt_assert(!ok);
> > +}
> > +
> > +static void test_signal_detect_noise(struct audio_signal *signal)
> > +{
> > + double buf[BUFFER_LEN];
> > + bool ok;
> > + size_t i;
> > +
> > + for (i = 0; i < BUFFER_LEN; i++)
> > + buf[i] = (double) (i % 10) / 10;
>
> This creates a period signal with a frequency of 4.410kHz... so this is
> not exactly noise.
>
> We probably want to do:
>
> srandom(42);
> for (i = 0; i < BUFFER_LEN; i++)
> buf[i] = ((double) random()) / RAND_MAX;
>
> This will create a less periodic signal, and still be repeatable (not
> sure if the random algorithm is allowed to changed between libc versions).
Indeed.
I chose to use this slightly modified formula:
(double) random() / RAND_MAX * 2 - 1
So that samples are generated between -1 and 1.
> With the proposed changes:
>
> Reviewed-by: Martin Peres <martin.peres@linux.intel.com>
>
> > +
> > + ok = audio_signal_detect(signal, SAMPLING_RATE, 0, buf, BUFFER_LEN);
> > +
> > + igt_assert(!ok);
> > +}
> > +
> > +igt_main
> > +{
> > + struct audio_signal *signal;
> > + int ret;
> > +
> > + igt_subtest_group {
> > + igt_fixture {
> > + signal = audio_signal_init(CHANNELS, SAMPLING_RATE);
> > +
> > + ret = audio_signal_add_frequency(signal, 300, 0);
> > + igt_assert(ret == 0);
> > + ret = audio_signal_add_frequency(signal, 700, 0);
> > + igt_assert(ret == 0);
> > + ret = audio_signal_add_frequency(signal, 5000, 0);
> > + igt_assert(ret == 0);
> > +
> > + audio_signal_synthesize(signal);
> > + }
> > +
> > + igt_subtest("signal-detect-verbatim")
> > + test_signal_detect_verbatim(signal);
> > +
> > + igt_subtest("signal-detect-silence")
> > + test_signal_detect_silence(signal);
> > +
> > + igt_subtest("signal-detect-noise")
> > + test_signal_detect_noise(signal);
> > +
> > + igt_fixture {
> > + audio_signal_fini(signal);
> > + }
> > + }
> > +}
> > diff --git a/lib/tests/meson.build b/lib/tests/meson.build
> > index 9950bd59c174..eb75cbd571b9 100644
> > --- a/lib/tests/meson.build
> > +++ b/lib/tests/meson.build
> > @@ -22,6 +22,13 @@ lib_fail_tests = [
> > 'igt_timeout',
> > ]
> >
> > +lib_tests_deps = igt_deps
> > +
> > +if chamelium.found()
> > + lib_deps += chamelium
> > + lib_tests += 'igt_audio'
> > +endif
> > +
> > foreach lib_test : lib_tests
> > exec = executable(lib_test, lib_test + '.c', install : false,
> > dependencies : igt_deps)
> >
_______________________________________________
igt-dev mailing list
igt-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/igt-dev
next prev parent reply other threads:[~2019-06-04 8:01 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-05-29 13:32 [igt-dev] [PATCH i-g-t 0/5] Add igt_audio self-tests and check for noise/pops Simon Ser
2019-05-29 13:32 ` [igt-dev] [PATCH i-g-t 1/5] lib/igt_audio: add basic audio_signal_detect tests Simon Ser
2019-06-03 13:43 ` Martin Peres
2019-06-04 8:00 ` Ser, Simon [this message]
2019-05-29 13:32 ` [igt-dev] [PATCH i-g-t 2/5] lib/tests/igt_audio: add test with missing frequency Simon Ser
2019-06-03 13:46 ` Martin Peres
2019-05-29 13:32 ` [igt-dev] [PATCH i-g-t 3/5] lib/tests/igt_audio: add test with an extra frequency Simon Ser
2019-06-03 13:49 ` Martin Peres
2019-05-29 13:32 ` [igt-dev] [PATCH i-g-t 4/5] lib/igt_audio: detect noise and pops Simon Ser
2019-06-03 14:11 ` Martin Peres
2019-05-29 13:32 ` [igt-dev] [PATCH i-g-t 5/5] lib/tests/igt_audio: add a pop test Simon Ser
2019-06-03 14:14 ` Martin Peres
2019-05-29 14:44 ` [igt-dev] ✓ Fi.CI.BAT: success for Add igt_audio self-tests and check for noise/pops Patchwork
2019-05-29 22:22 ` [igt-dev] ✓ Fi.CI.IGT: " Patchwork
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=873142b8978b29b9eda842100198c18572a16682.camel@intel.com \
--to=simon.ser@intel.com \
--cc=igt-dev@lists.freedesktop.org \
--cc=martin.peres@intel.com \
--cc=martin.peres@linux.intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox