From: Simon Ser <simon.ser@intel.com>
To: igt-dev@lists.freedesktop.org
Subject: [igt-dev] [PATCH i-g-t] lib/igt_audio: make audio_signal_detect take const data
Date: Mon, 13 May 2019 16:53:06 +0300 [thread overview]
Message-ID: <20190513135306.7541-1-simon.ser@intel.com> (raw)
audio_signal_detect uses gsl_fft_real_radix2_transform which mutates the data
array. This can be surprising when calling audio_signal_detect and then read
again the data (e.g. for another check).
Instead of mutating the array, make audio_signal_detect less error-prone by
taking a const parameter. Do an internal copy before calling the gsl function.
Signed-off-by: Simon Ser <simon.ser@intel.com>
---
lib/igt_audio.c | 13 +++++++++++--
lib/igt_audio.h | 2 +-
2 files changed, 12 insertions(+), 3 deletions(-)
diff --git a/lib/igt_audio.c b/lib/igt_audio.c
index fd8cf07c0de3..a1dda50a3c09 100644
--- a/lib/igt_audio.c
+++ b/lib/igt_audio.c
@@ -251,11 +251,14 @@ void audio_signal_fill(struct audio_signal *signal, int16_t *buffer,
* Checks that frequencies specified in signal, and only those, are included
* in the input data.
*
- * sampling_rate is given in Hz. data_len is the number of elements in data.
+ * sampling_rate is given in Hz. samples_len is the number of elements in
+ * samples.
*/
bool audio_signal_detect(struct audio_signal *signal, int sampling_rate,
- int channel, double *data, size_t data_len)
+ int channel, const double *samples, size_t samples_len)
{
+ double *data;
+ size_t data_len = samples_len;
size_t bin_power_len = data_len / 2 + 1;
double bin_power[bin_power_len];
bool detected[FREQS_MAX];
@@ -264,6 +267,10 @@ bool audio_signal_detect(struct audio_signal *signal, int sampling_rate,
size_t i, j;
bool above, success;
+ /* gsl will mutate the array in-place, so make a copy */
+ data = malloc(samples_len * sizeof(double));
+ memcpy(data, samples, samples_len * sizeof(double));
+
/* Allowed error in Hz due to FFT step */
freq_accuracy = sampling_rate / data_len;
igt_debug("Allowed freq. error: %d Hz\n", freq_accuracy);
@@ -372,6 +379,8 @@ bool audio_signal_detect(struct audio_signal *signal, int sampling_rate,
}
}
+ free(data);
+
return success;
}
diff --git a/lib/igt_audio.h b/lib/igt_audio.h
index 466e772a75a4..d5ba1caaca63 100644
--- a/lib/igt_audio.h
+++ b/lib/igt_audio.h
@@ -43,7 +43,7 @@ void audio_signal_reset(struct audio_signal *signal);
void audio_signal_fill(struct audio_signal *signal, int16_t *buffer,
size_t buffer_len);
bool audio_signal_detect(struct audio_signal *signal, int sampling_rate,
- int channel, double *data, size_t data_len);
+ int channel, const double *samples, size_t samples_len);
size_t audio_extract_channel_s32_le(double *dst, size_t dst_cap,
int32_t *src, size_t src_len,
int n_channels, int channel);
--
2.21.0
_______________________________________________
igt-dev mailing list
igt-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/igt-dev
next reply other threads:[~2019-05-13 13:53 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-05-13 13:53 Simon Ser [this message]
2019-05-13 14:52 ` [igt-dev] ✓ Fi.CI.BAT: success for lib/igt_audio: make audio_signal_detect take const data Patchwork
2019-05-13 17:50 ` [igt-dev] ✓ Fi.CI.IGT: " Patchwork
2019-05-14 11:40 ` [igt-dev] [PATCH i-g-t] " Arkadiusz Hiler
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=20190513135306.7541-1-simon.ser@intel.com \
--to=simon.ser@intel.com \
--cc=igt-dev@lists.freedesktop.org \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.