alsa-devel.alsa-project.org archive mirror
 help / color / mirror / Atom feed
From: han.lu@intel.com
To: tiwai@suse.de, liam.r.girdwood@linux.intel.com,
	alsa-devel@alsa-project.org
Cc: "Lu, Han" <han.lu@intel.com>
Subject: [PATCH 3/4] alsabat: add a single channel sine wave generator
Date: Thu,  9 Jun 2016 03:42:48 +0800	[thread overview]
Message-ID: <b9544395785f623026f776411755fa5ebd29d869.1465404865.git.han.lu@intel.com> (raw)
In-Reply-To: <cover.1465404865.git.han.lu@intel.com>
In-Reply-To: <cover.1465404865.git.han.lu@intel.com>

From: "Lu, Han" <han.lu@intel.com>

Add function generate_sine_wave_raw_mono(). It serves as a single
channel sine wave generator, to provide data for calculation (e.g.
for noise analysis).
The function is similar to generate_sine_wave(), but a lite revision.
It has no dependency on bat channels and target frequency, no malloc
inside, no data conversion from float to integer samples, and supports
one channel only.

Signed-off-by: Lu, Han <han.lu@intel.com>

diff --git a/bat/bat-signal.h b/bat/bat-signal.h
index a295517..3c314a5 100644
--- a/bat/bat-signal.h
+++ b/bat/bat-signal.h
@@ -28,3 +28,4 @@ int sin_generator_init(struct sin_generator *, float, float, float);
 float sin_generator_next_sample(struct sin_generator *);
 void sin_generator_vfill(struct sin_generator *, float *, int);
 int generate_sine_wave(struct bat *, int, void *);
+int generate_sine_wave_raw_mono(struct bat *, float *, float, int);
diff --git a/bat/signal.c b/bat/signal.c
index 2047f53..c9b5c7b 100644
--- a/bat/signal.c
+++ b/bat/signal.c
@@ -183,3 +183,21 @@ exit:
 
 	return err;
 }
+
+/* generate single channel sine waveform without sample conversion */
+int generate_sine_wave_raw_mono(struct bat *bat, float *buf,
+		float freq, int nsamples)
+{
+	int err = 0;
+	struct sin_generator sg;
+
+	err = sin_generator_init(&sg, 1.0, freq, bat->rate);
+	if (err < 0)
+		return err;
+	sin_generator_vfill(&sg, buf, nsamples);
+
+	/* adjust amplitude and offset of waveform */
+	err = adjust_waveform(bat, buf, nsamples, 1);
+
+	return err;
+}
-- 
2.5.0

  parent reply	other threads:[~2016-06-08 11:46 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-06-08 19:42 [PATCH 0/4] alsabat: add noise detection han.lu
2016-06-08 13:18 ` Takashi Iwai
2016-06-08 19:42 ` [PATCH 1/4] alsabat: align the data type on float han.lu
2016-06-08 19:42 ` [PATCH 2/4] alsabat: add channels parameter for adjust_waveform() han.lu
2016-06-08 19:42 ` han.lu [this message]
2016-06-08 19:42 ` [PATCH 4/4] alsabat: add noise detection han.lu

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=b9544395785f623026f776411755fa5ebd29d869.1465404865.git.han.lu@intel.com \
    --to=han.lu@intel.com \
    --cc=alsa-devel@alsa-project.org \
    --cc=liam.r.girdwood@linux.intel.com \
    --cc=tiwai@suse.de \
    /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;
as well as URLs for NNTP newsgroup(s).