pipewire/spa/plugins/audiotestsrc/render.c

45 lines
1.4 KiB
C
Raw Normal View History

/* Spa */
/* SPDX-FileCopyrightText: Copyright © 2018 Wim Taymans */
/* SPDX-License-Identifier: MIT */
#include <math.h>
#define M_PI_M2f (float)(M_PI+M_PI)
2017-05-26 08:05:01 +02:00
#define DEFINE_SINE(type,scale) \
static void \
2017-05-26 18:19:51 +02:00
audio_test_src_create_sine_##type (struct impl *this, type *samples, size_t n_samples) \
2017-05-26 08:05:01 +02:00
{ \
2019-01-08 09:30:40 +01:00
size_t i; \
uint32_t c, channels; \
float step, amp; \
float freq = this->props.freq; \
float volume = this->props.volume; \
2017-05-26 08:05:01 +02:00
\
channels = this->port.current_format.info.raw.channels; \
step = M_PI_M2f * freq / this->port.current_format.info.raw.rate; \
amp = volume * scale; \
2017-05-26 08:05:01 +02:00
\
for (i = 0; i < n_samples; i++) { \
2017-06-28 16:33:11 +02:00
type val; \
this->port.accumulator += step; \
if (this->port.accumulator >= M_PI_M2f) \
this->port.accumulator -= M_PI_M2f; \
val = (type) (sin (this->port.accumulator) * amp); \
2017-05-26 08:05:01 +02:00
for (c = 0; c < channels; ++c) \
2017-06-28 16:33:11 +02:00
*samples++ = val; \
2017-05-26 08:05:01 +02:00
} \
}
DEFINE_SINE(int16_t, 32767.0f);
DEFINE_SINE(int32_t, 2147483647.0f);
DEFINE_SINE(float, 1.0f);
DEFINE_SINE(double, 1.0f);
static const render_func_t sine_funcs[] = {
2017-05-26 08:05:01 +02:00
(render_func_t) audio_test_src_create_sine_int16_t,
(render_func_t) audio_test_src_create_sine_int32_t,
(render_func_t) audio_test_src_create_sine_float,
(render_func_t) audio_test_src_create_sine_double
};