#include <stdio.h>
#include <errno.h>
#include <math.h>
#include <signal.h>
#include <spa/param/audio/format-utils.h>
#include <pipewire/pipewire.h>
struct data {
unsigned move:1;
};
static void on_process(void *userdata)
{
struct data *data = userdata;
float *samples, max;
uint32_t c, n, n_channels, n_samples, peak;
return;
}
return;
n_channels = data->format.info.raw.channels;
if (data->move)
fprintf(stdout, "%c[%dA", 0x1b, n_channels + 1);
fprintf(stdout, "captured %d samples\n", n_samples / n_channels);
for (c = 0; c < data->format.info.raw.channels; c++) {
max = 0.0f;
for (n = c; n < n_samples; n += n_channels)
max = fmaxf(max, fabsf(samples[n]));
fprintf(stdout, "channel %d: |%*s%*s| peak:%f\n",
c, peak+1, "*", 40 - peak, "", max);
}
data->move = true;
fflush(stdout);
}
static void
on_stream_param_changed(
void *_data, uint32_t
id,
const struct spa_pod *param)
{
struct data *data = _data;
return;
if (
spa_format_parse(param, &data->format.media_type, &data->format.media_subtype) < 0)
return;
return;
fprintf(stdout, "capturing rate:%d channels:%d\n",
data->format.info.raw.rate, data->format.info.raw.channels);
}
.param_changed = on_stream_param_changed,
.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, };
uint8_t buffer[1024];
NULL);
if (argc > 1)
"audio-capture",
props,
&stream_events,
&data);
params, 1);
return 0;
}