From e1b7a5f3769803759c50d1b189160b9f9f03b36e Mon Sep 17 00:00:00 2001 From: "Lu, Han" Date: Thu, 9 Jun 2016 03:42:48 +0800 Subject: [PATCH] alsabat: add a single channel sine wave generator 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 Signed-off-by: Takashi Iwai --- bat/bat-signal.h | 1 + bat/signal.c | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+) 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; +}