public inbox for igt-dev@lists.freedesktop.org
 help / color / mirror / Atom feed
From: Simon Ser <simon.ser@intel.com>
To: igt-dev@lists.freedesktop.org
Cc: martin.peres@intel.com
Subject: [igt-dev] [PATCH i-g-t 1/2] lib/igt_audio: fix synthesized signal amplitude
Date: Fri, 17 May 2019 13:11:54 +0300	[thread overview]
Message-ID: <20190517101155.21533-1-simon.ser@intel.com> (raw)

For each channel of the audio signal, we choose a set of frequencies to
generate. However we previously divided each sample by the total number of
frequencies, instead of the number of frequencies assigned to the channel we're
currently processing. This resulted in low amplitudes (0.5 instead of 1.0 for
2 channels).

This patch fixes this issue and sets the generated signal amplitude to 0.9.
Indeed, we want to detect if the receiver grows the signal, we don't want it
to get capped at 1.0 immediately.

Signed-off-by: Simon Ser <simon.ser@intel.com>
---
 lib/igt_audio.c | 33 ++++++++++++++++++++++++++++-----
 1 file changed, 28 insertions(+), 5 deletions(-)

diff --git a/lib/igt_audio.c b/lib/igt_audio.c
index 90d16fe4bd11..f6c8e399e345 100644
--- a/lib/igt_audio.c
+++ b/lib/igt_audio.c
@@ -36,6 +36,8 @@
 #include "igt_core.h"
 
 #define FREQS_MAX 64
+#define CHANNELS_MAX 8
+#define SYNTHESIZE_AMPLITUDE 0.9
 
 /**
  * SECTION:igt_audio
@@ -77,6 +79,8 @@ struct audio_signal *audio_signal_init(int channels, int sampling_rate)
 {
 	struct audio_signal *signal;
 
+	igt_assert(channels <= CHANNELS_MAX);
+
 	signal = malloc(sizeof(struct audio_signal));
 	memset(signal, 0, sizeof(struct audio_signal));
 
@@ -156,7 +160,7 @@ void audio_signal_synthesize(struct audio_signal *signal)
 
 		for (j = 0; j < period_len; j++) {
 			value = 2.0 * M_PI * freq / signal->sampling_rate * j;
-			value = sin(value) / signal->freqs_count;
+			value = sin(value) * SYNTHESIZE_AMPLITUDE;
 
 			period[j] = value;
 		}
@@ -195,6 +199,20 @@ void audio_signal_reset(struct audio_signal *signal)
 	signal->freqs_count = 0;
 }
 
+static size_t audio_signal_count_freqs(struct audio_signal *signal, int channel)
+{
+	size_t n, i;
+	struct audio_signal_freq *freq;
+
+	for (i = 0; i < signal->freqs_count; i++) {
+		freq = &signal->freqs[i];
+		if (freq->channel < 0 || freq->channel == channel)
+			n++;
+	}
+
+	return n;
+}
+
 /**
  * audio_signal_fill:
  * @signal: The target signal structure
@@ -208,14 +226,18 @@ void audio_signal_reset(struct audio_signal *signal)
 void audio_signal_fill(struct audio_signal *signal, double *buffer,
 		       size_t samples)
 {
-	double *destination, *source;
+	double *dst, *src;
 	struct audio_signal_freq *freq;
 	int total;
 	int count;
 	int i, j, k;
+	size_t freqs_per_channel[CHANNELS_MAX];
 
 	memset(buffer, 0, sizeof(double) * signal->channels * samples);
 
+	for (i = 0; i < signal->channels; i++)
+		freqs_per_channel[i] = audio_signal_count_freqs(signal, i);
+
 	for (i = 0; i < signal->freqs_count; i++) {
 		freq = &signal->freqs[i];
 		total = 0;
@@ -223,8 +245,8 @@ void audio_signal_fill(struct audio_signal *signal, double *buffer,
 		igt_assert(freq->period);
 
 		while (total < samples) {
-			source = freq->period + freq->offset;
-			destination = buffer + total * signal->channels;
+			src = freq->period + freq->offset;
+			dst = buffer + total * signal->channels;
 
 			count = freq->period_len - freq->offset;
 			if (count > samples - total)
@@ -238,7 +260,8 @@ void audio_signal_fill(struct audio_signal *signal, double *buffer,
 					if (freq->channel >= 0 &&
 					    freq->channel != k)
 						continue;
-					destination[j * signal->channels + k] += source[j];
+					dst[j * signal->channels + k] +=
+						src[j] / freqs_per_channel[k];
 				}
 			}
 
-- 
2.21.0

_______________________________________________
igt-dev mailing list
igt-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/igt-dev

             reply	other threads:[~2019-05-17 10:12 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-05-17 10:11 Simon Ser [this message]
2019-05-17 10:11 ` [igt-dev] [PATCH i-g-t 2/2] lib/igt_audio: sanity-check generated signals Simon Ser
2019-05-17 12:33   ` Martin Peres
2019-05-17 11:04 ` [igt-dev] ✓ Fi.CI.BAT: success for series starting with [i-g-t,1/2] lib/igt_audio: fix synthesized signal amplitude Patchwork
2019-05-17 12:34 ` [igt-dev] [PATCH i-g-t 1/2] " Martin Peres
2019-05-17 14:03 ` [igt-dev] ✓ Fi.CI.IGT: success for series starting with [i-g-t,1/2] " 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=20190517101155.21533-1-simon.ser@intel.com \
    --to=simon.ser@intel.com \
    --cc=igt-dev@lists.freedesktop.org \
    --cc=martin.peres@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