mirror of
https://github.com/Ryujinx/libsoundio.git
synced 2024-12-31 23:05:37 +00:00
microphone example: recover from underflow
This commit is contained in:
parent
3d3f9f91a2
commit
ab8a2c2ffe
|
@ -134,8 +134,10 @@ static void write_callback(struct SoundIoOutStream *outstream, int requested_fra
|
||||||
}
|
}
|
||||||
|
|
||||||
static void underflow_callback(struct SoundIoOutStream *outstream) {
|
static void underflow_callback(struct SoundIoOutStream *outstream) {
|
||||||
static int count = 0;
|
char *write_ptr = soundio_ring_buffer_write_ptr(ring_buffer);
|
||||||
fprintf(stderr, "underflow %d\n", count++);
|
int bytes_to_fill = outstream->buffer_duration * outstream->sample_rate * outstream->bytes_per_frame;
|
||||||
|
memset(write_ptr, 0, bytes_to_fill);
|
||||||
|
soundio_ring_buffer_advance_write_ptr(ring_buffer, bytes_to_fill);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int usage(char *exe) {
|
static int usage(char *exe) {
|
||||||
|
@ -289,10 +291,6 @@ int main(int argc, char **argv) {
|
||||||
ring_buffer = soundio_ring_buffer_create(soundio, capacity);
|
ring_buffer = soundio_ring_buffer_create(soundio, capacity);
|
||||||
if (!ring_buffer)
|
if (!ring_buffer)
|
||||||
panic("unable to create ring buffer: out of memory");
|
panic("unable to create ring buffer: out of memory");
|
||||||
char *write_ptr = soundio_ring_buffer_write_ptr(ring_buffer);
|
|
||||||
int bytes_to_fill = outstream->buffer_duration * outstream->sample_rate * outstream->bytes_per_frame;
|
|
||||||
memset(write_ptr, 0, bytes_to_fill);
|
|
||||||
soundio_ring_buffer_advance_write_ptr(ring_buffer, bytes_to_fill);
|
|
||||||
|
|
||||||
if ((err = soundio_instream_start(instream)))
|
if ((err = soundio_instream_start(instream)))
|
||||||
panic("unable to start input device: %s", soundio_strerror(err));
|
panic("unable to start input device: %s", soundio_strerror(err));
|
||||||
|
|
Loading…
Reference in a new issue