[PATCH 3/4] alsabat: add a single channel sine wave generator

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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

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@xxxxxxxxx>

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

_______________________________________________
Alsa-devel mailing list
Alsa-devel@xxxxxxxxxxxxxxxx
http://mailman.alsa-project.org/mailman/listinfo/alsa-devel



[Index of Archives]     [ALSA User]     [Linux Audio Users]     [Kernel Archive]     [Asterisk PBX]     [Photo Sharing]     [Linux Sound]     [Video 4 Linux]     [Gimp]     [Yosemite News]

  Powered by Linux