mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-12-19 08:57:14 -05:00
audiotestsrc: implement sine wave
Fix audiomixer some more
This commit is contained in:
parent
5c32690cc8
commit
32368d741d
7 changed files with 173 additions and 59 deletions
56
spa/plugins/audiotestsrc/render.c
Normal file
56
spa/plugins/audiotestsrc/render.c
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
/* Spa
|
||||
* Copyright (C) 2017 Wim Taymans <wim.taymans@gmail.com>
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this library; if not, write to the
|
||||
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
|
||||
* Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include <math.h>
|
||||
|
||||
#define M_PI_M2 ( M_PI + M_PI )
|
||||
|
||||
typedef SpaResult (*RenderFunc) (SpaAudioTestSrc *this, void *samples, size_t n_samples);
|
||||
|
||||
#define DEFINE_SINE(type,scale) \
|
||||
static void \
|
||||
audio_test_src_create_sine_##type (SpaAudioTestSrc *this, type * samples, size_t n_samples) \
|
||||
{ \
|
||||
int i, c, channels; \
|
||||
double step, amp; \
|
||||
\
|
||||
channels = this->current_format.info.raw.channels; \
|
||||
step = M_PI_M2 * this->props.freq / this->current_format.info.raw.rate; \
|
||||
amp = this->props.volume * scale; \
|
||||
\
|
||||
for (i = 0; i < n_samples; i++) { \
|
||||
this->accumulator += step; \
|
||||
if (this->accumulator >= M_PI_M2) \
|
||||
this->accumulator -= M_PI_M2; \
|
||||
for (c = 0; c < channels; ++c) \
|
||||
*samples++ = (type) (sin (this->accumulator) * amp); \
|
||||
} \
|
||||
}
|
||||
|
||||
DEFINE_SINE (int16_t, 32767.0);
|
||||
DEFINE_SINE (int32_t, 2147483647.0);
|
||||
DEFINE_SINE (float, 1.0);
|
||||
DEFINE_SINE (double, 1.0);
|
||||
|
||||
static const RenderFunc sine_funcs[] = {
|
||||
(RenderFunc) audio_test_src_create_sine_int16_t,
|
||||
(RenderFunc) audio_test_src_create_sine_int32_t,
|
||||
(RenderFunc) audio_test_src_create_sine_float,
|
||||
(RenderFunc) audio_test_src_create_sine_double
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue