#include <stdio.h>
#include <errno.h>
#include <math.h>
#include <signal.h>
#define M_PI_M2f (float)(M_PI+M_PI)
#define DEFAULT_RATE 44100
#define DEFAULT_CHANNELS 2
#define DEFAULT_VOLUME 0.7f
#define BUFFER_SIZE (16*1024)
struct data {
float accumulator;
float buffer[BUFFER_SIZE * DEFAULT_CHANNELS];
};
static void fill_f32(struct data *d, uint32_t offset, int n_frames)
{
float val;
int i, c;
for (i = 0; i < n_frames; i++) {
d->accumulator += M_PI_M2f * 440 / DEFAULT_RATE;
if (d->accumulator >= M_PI_M2f)
d->accumulator -= M_PI_M2f;
val = sinf(d->accumulator) * DEFAULT_VOLUME;
for (c = 0; c < DEFAULT_CHANNELS; c++)
d->buffer[((offset + i) % BUFFER_SIZE) * DEFAULT_CHANNELS + c] = val;
}
}
static void do_refill(void *userdata, uint64_t count)
{
struct data *data = userdata;
int32_t filled;
uint32_t index, avail;
avail = BUFFER_SIZE - filled;
fill_f32(data, index, avail);
}
static void on_process(void *userdata)
{
struct data *data = userdata;
uint8_t *p;
uint32_t index, to_read, to_silence;
int32_t avail, n_frames, stride;
return;
}
return;
stride = sizeof(float) * DEFAULT_CHANNELS;
to_read = avail > 0 ?
SPA_MIN(avail, n_frames) : 0;
to_silence = n_frames - to_read;
if (to_read > 0) {
data->buffer, BUFFER_SIZE * stride,
(index % BUFFER_SIZE) * stride,
p, to_read * stride);
}
if (to_silence > 0)
memset(
SPA_PTROFF(p, to_read * stride,
void), 0, to_silence * stride);
}
.process = on_process,
};
static void do_quit(void *userdata, int signal_number)
{
struct data *data = userdata;
}
int main(int argc, char *argv[])
{
struct data data = { 0, };
NULL);
if (argc > 1)
"audio-src-ring",
props,
&stream_events,
.channels = DEFAULT_CHANNELS,
.rate = DEFAULT_RATE ));
params, 1);
return 0;
}