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 <han.lu@intel.com>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
This commit is contained in:
Lu, Han 2016-06-09 03:42:48 +08:00 committed by Takashi Iwai
parent e0c1c86a90
commit e1b7a5f376
2 changed files with 19 additions and 0 deletions

View file

@ -28,3 +28,4 @@ int sin_generator_init(struct sin_generator *, float, float, float);
float sin_generator_next_sample(struct sin_generator *); float sin_generator_next_sample(struct sin_generator *);
void sin_generator_vfill(struct sin_generator *, float *, int); void sin_generator_vfill(struct sin_generator *, float *, int);
int generate_sine_wave(struct bat *, int, void *); int generate_sine_wave(struct bat *, int, void *);
int generate_sine_wave_raw_mono(struct bat *, float *, float, int);

View file

@ -183,3 +183,21 @@ exit:
return err; 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;
}