fix microphone example fill with zeros case

Usually when microphone example is run you never hit buffer underflow and "fill with zeros" branch is never executed. But when it's executed it fails with "invalid value" because of checks performed on frame_count. This platform-independent check 8094dc5249/src/soundio.c (L447) sometimes passed because unitialized local frame_count have arbitrary value, but this CoreAudio one 8094dc5249/src/coreaudio.c (L1078) is not passed, and "fill with zeros" scenario always fails on MacOS.
This commit is contained in:
Ruslan Prokopchuk 2017-03-27 10:39:38 +03:00
parent 8094dc5249
commit ae7fc0177b
1 changed files with 7 additions and 1 deletions

View File

@ -113,6 +113,7 @@ static void read_callback(struct SoundIoInStream *instream, int frame_count_min,
static void write_callback(struct SoundIoOutStream *outstream, int frame_count_min, int frame_count_max) {
struct SoundIoChannelArea *areas;
int frames_left;
int frame_count;
int err;
@ -122,7 +123,11 @@ static void write_callback(struct SoundIoOutStream *outstream, int frame_count_m
if (frame_count_min > fill_count) {
// Ring buffer does not have enough data, fill with zeroes.
frames_left = frame_count_min;
for (;;) {
frame_count = frames_left;
if (frame_count <= 0)
return;
if ((err = soundio_outstream_begin_write(outstream, &areas, &frame_count)))
panic("begin write error: %s", soundio_strerror(err));
if (frame_count <= 0)
@ -135,11 +140,12 @@ static void write_callback(struct SoundIoOutStream *outstream, int frame_count_m
}
if ((err = soundio_outstream_end_write(outstream)))
panic("end write error: %s", soundio_strerror(err));
frames_left -= frame_count;
}
}
int read_count = min_int(frame_count_max, fill_count);
int frames_left = read_count;
frames_left = read_count;
while (frames_left > 0) {
int frame_count = frames_left;