examples: improve console output

Go back up right before we're going to draw so that we're always at
the bottom when we quit because of ctrl-C.
This commit is contained in:
Wim Taymans 2022-11-17 15:54:18 +01:00
parent 945529f029
commit 80983b9fb6

View file

@ -42,6 +42,7 @@ struct data {
struct pw_stream *stream; struct pw_stream *stream;
struct spa_audio_info format; struct spa_audio_info format;
unsigned move:1;
}; };
/* our data processing function is in general: /* our data processing function is in general:
@ -73,6 +74,9 @@ static void on_process(void *userdata)
n_channels = data->format.info.raw.channels; n_channels = data->format.info.raw.channels;
n_samples = buf->datas[0].chunk->size / sizeof(float); n_samples = buf->datas[0].chunk->size / sizeof(float);
/* move cursor up */
if (data->move)
fprintf(stdout, "%c[%dA", 0x1b, n_channels + 1);
fprintf(stdout, "captured %d samples\n", n_samples / n_channels); fprintf(stdout, "captured %d samples\n", n_samples / n_channels);
for (c = 0; c < data->format.info.raw.channels; c++) { for (c = 0; c < data->format.info.raw.channels; c++) {
max = 0.0f; max = 0.0f;
@ -84,8 +88,7 @@ static void on_process(void *userdata)
fprintf(stdout, "channel %d: |%*s%*s| peak:%f\n", fprintf(stdout, "channel %d: |%*s%*s| peak:%f\n",
c, peak+1, "*", 40 - peak, "", max); c, peak+1, "*", 40 - peak, "", max);
} }
/* move cursor up */ data->move = true;
fprintf(stdout, "%c[%dA", 0x1b, n_channels + 1);
fflush(stdout); fflush(stdout);
pw_stream_queue_buffer(data->stream, b); pw_stream_queue_buffer(data->stream, b);