From bef0df2f0bcf269747132a9510f1fd88c4c846e1 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Sun, 23 Oct 2016 19:19:47 -0400 Subject: [PATCH] use consistent enum to string function names closes #115 --- example/sio_list_devices.c | 8 ++++---- example/sio_microphone.c | 22 +++++++++++----------- example/sio_record.c | 14 +++++++------- example/sio_sine.c | 20 ++++++++++---------- soundio/soundio.h | 6 +++--- src/soundio.c | 10 +++++----- test/backend_disconnect_recover.c | 6 +++--- test/latency.c | 16 ++++++++-------- test/overflow.c | 12 ++++++------ test/underflow.c | 12 ++++++------ test/unit_tests.c | 2 +- 11 files changed, 64 insertions(+), 64 deletions(-) diff --git a/example/sio_list_devices.c b/example/sio_list_devices.c index 00fa20d..5aa5bdd 100644 --- a/example/sio_list_devices.c +++ b/example/sio_list_devices.c @@ -44,7 +44,7 @@ static void print_device(struct SoundIoDevice *device, bool is_default) { fprintf(stderr, " id: %s\n", device->id); if (device->probe_error) { - fprintf(stderr, " probe error: %s\n", soundio_strerror(device->probe_error)); + fprintf(stderr, " probe error: %s\n", soundio_error_name(device->probe_error)); } else { fprintf(stderr, " channel layouts:\n"); for (int i = 0; i < device->layout_count; i += 1) { @@ -69,11 +69,11 @@ static void print_device(struct SoundIoDevice *device, bool is_default) { fprintf(stderr, " formats: "); for (int i = 0; i < device->format_count; i += 1) { const char *comma = (i == device->format_count - 1) ? "" : ", "; - fprintf(stderr, "%s%s", soundio_format_string(device->formats[i]), comma); + fprintf(stderr, "%s%s", soundio_format_name(device->formats[i]), comma); } fprintf(stderr, "\n"); if (device->current_format != SoundIoFormatInvalid) - fprintf(stderr, " current format: %s\n", soundio_format_string(device->current_format)); + fprintf(stderr, " current format: %s\n", soundio_format_name(device->current_format)); fprintf(stderr, " min software latency: %0.8f sec\n", device->software_latency_min); fprintf(stderr, " max software latency: %0.8f sec\n", device->software_latency_max); @@ -163,7 +163,7 @@ int main(int argc, char **argv) { soundio_connect(soundio) : soundio_connect_backend(soundio, backend); if (err) { - fprintf(stderr, "%s\n", soundio_strerror(err)); + fprintf(stderr, "%s\n", soundio_error_name(err)); return err; } diff --git a/example/sio_microphone.c b/example/sio_microphone.c index c95e106..1941165 100644 --- a/example/sio_microphone.c +++ b/example/sio_microphone.c @@ -83,7 +83,7 @@ static void read_callback(struct SoundIoInStream *instream, int frame_count_min, int frame_count = frames_left; if ((err = soundio_instream_begin_read(instream, &areas, &frame_count))) - panic("begin read error: %s", soundio_strerror(err)); + panic("begin read error: %s", soundio_error_name(err)); if (!frame_count) break; @@ -104,7 +104,7 @@ static void read_callback(struct SoundIoInStream *instream, int frame_count_min, } if ((err = soundio_instream_end_read(instream))) - panic("end read error: %s", soundio_strerror(err)); + panic("end read error: %s", soundio_error_name(err)); frames_left -= frame_count; if (frames_left <= 0) @@ -128,7 +128,7 @@ static void write_callback(struct SoundIoOutStream *outstream, int frame_count_m // Ring buffer does not have enough data, fill with zeroes. for (;;) { if ((err = soundio_outstream_begin_write(outstream, &areas, &frame_count))) - panic("begin write error: %s", soundio_strerror(err)); + panic("begin write error: %s", soundio_error_name(err)); if (frame_count <= 0) return; for (int frame = 0; frame < frame_count; frame += 1) { @@ -138,7 +138,7 @@ 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)); + panic("end write error: %s", soundio_error_name(err)); } } @@ -149,7 +149,7 @@ static void write_callback(struct SoundIoOutStream *outstream, int frame_count_m int frame_count = frames_left; if ((err = soundio_outstream_begin_write(outstream, &areas, &frame_count))) - panic("begin write error: %s", soundio_strerror(err)); + panic("begin write error: %s", soundio_error_name(err)); if (frame_count <= 0) break; @@ -163,7 +163,7 @@ 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)); + panic("end write error: %s", soundio_error_name(err)); frames_left -= frame_count; } @@ -245,7 +245,7 @@ int main(int argc, char **argv) { int err = (backend == SoundIoBackendNone) ? soundio_connect(soundio) : soundio_connect_backend(soundio, backend); if (err) - panic("error connecting: %s", soundio_strerror(err)); + panic("error connecting: %s", soundio_error_name(err)); soundio_flush_events(soundio); @@ -342,7 +342,7 @@ int main(int argc, char **argv) { instream->read_callback = read_callback; if ((err = soundio_instream_open(instream))) { - fprintf(stderr, "unable to open input stream: %s", soundio_strerror(err)); + fprintf(stderr, "unable to open input stream: %s", soundio_error_name(err)); return 1; } @@ -357,7 +357,7 @@ int main(int argc, char **argv) { outstream->underflow_callback = underflow_callback; if ((err = soundio_outstream_open(outstream))) { - fprintf(stderr, "unable to open output stream: %s", soundio_strerror(err)); + fprintf(stderr, "unable to open output stream: %s", soundio_error_name(err)); return 1; } @@ -371,10 +371,10 @@ int main(int argc, char **argv) { soundio_ring_buffer_advance_write_ptr(ring_buffer, fill_count); if ((err = soundio_instream_start(instream))) - panic("unable to start input device: %s", soundio_strerror(err)); + panic("unable to start input device: %s", soundio_error_name(err)); if ((err = soundio_outstream_start(outstream))) - panic("unable to start output device: %s", soundio_strerror(err)); + panic("unable to start output device: %s", soundio_error_name(err)); for (;;) soundio_wait_events(soundio); diff --git a/example/sio_record.c b/example/sio_record.c index 82ec635..21857f5 100644 --- a/example/sio_record.c +++ b/example/sio_record.c @@ -77,7 +77,7 @@ static void read_callback(struct SoundIoInStream *instream, int frame_count_min, int frame_count = frames_left; if ((err = soundio_instream_begin_read(instream, &areas, &frame_count))) { - fprintf(stderr, "begin read error: %s", soundio_strerror(err)); + fprintf(stderr, "begin read error: %s", soundio_error_name(err)); exit(1); } @@ -99,7 +99,7 @@ static void read_callback(struct SoundIoInStream *instream, int frame_count_min, } if ((err = soundio_instream_end_read(instream))) { - fprintf(stderr, "end read error: %s", soundio_strerror(err)); + fprintf(stderr, "end read error: %s", soundio_error_name(err)); exit(1); } @@ -183,7 +183,7 @@ int main(int argc, char **argv) { int err = (backend == SoundIoBackendNone) ? soundio_connect(soundio) : soundio_connect_backend(soundio, backend); if (err) { - fprintf(stderr, "error connecting: %s", soundio_strerror(err)); + fprintf(stderr, "error connecting: %s", soundio_error_name(err)); return 1; } @@ -216,7 +216,7 @@ int main(int argc, char **argv) { fprintf(stderr, "Device: %s\n", selected_device->name); if (selected_device->probe_error) { - fprintf(stderr, "Unable to probe device: %s\n", soundio_strerror(selected_device->probe_error)); + fprintf(stderr, "Unable to probe device: %s\n", soundio_error_name(selected_device->probe_error)); return 1; } @@ -261,12 +261,12 @@ int main(int argc, char **argv) { instream->userdata = &rc; if ((err = soundio_instream_open(instream))) { - fprintf(stderr, "unable to open input stream: %s", soundio_strerror(err)); + fprintf(stderr, "unable to open input stream: %s", soundio_error_name(err)); return 1; } fprintf(stderr, "%s %dHz %s interleaved\n", - instream->layout.name, sample_rate, soundio_format_string(fmt)); + instream->layout.name, sample_rate, soundio_format_name(fmt)); const int ring_buffer_duration_seconds = 30; int capacity = ring_buffer_duration_seconds * instream->sample_rate * instream->bytes_per_frame; @@ -277,7 +277,7 @@ int main(int argc, char **argv) { } if ((err = soundio_instream_start(instream))) { - fprintf(stderr, "unable to start input device: %s", soundio_strerror(err)); + fprintf(stderr, "unable to start input device: %s", soundio_error_name(err)); return 1; } diff --git a/example/sio_sine.c b/example/sio_sine.c index cc70c67..9efef74 100644 --- a/example/sio_sine.c +++ b/example/sio_sine.c @@ -65,7 +65,7 @@ static void write_callback(struct SoundIoOutStream *outstream, int frame_count_m for (;;) { int frame_count = frames_left; if ((err = soundio_outstream_begin_write(outstream, &areas, &frame_count))) { - fprintf(stderr, "unrecoverable stream error: %s\n", soundio_strerror(err)); + fprintf(stderr, "unrecoverable stream error: %s\n", soundio_error_name(err)); exit(1); } @@ -88,7 +88,7 @@ static void write_callback(struct SoundIoOutStream *outstream, int frame_count_m if ((err = soundio_outstream_end_write(outstream))) { if (err == SoundIoErrorUnderflow) return; - fprintf(stderr, "unrecoverable stream error: %s\n", soundio_strerror(err)); + fprintf(stderr, "unrecoverable stream error: %s\n", soundio_error_name(err)); exit(1); } @@ -166,7 +166,7 @@ int main(int argc, char **argv) { soundio_connect(soundio) : soundio_connect_backend(soundio, backend); if (err) { - fprintf(stderr, "Unable to connect to backend: %s\n", soundio_strerror(err)); + fprintf(stderr, "Unable to connect to backend: %s\n", soundio_error_name(err)); return 1; } @@ -204,7 +204,7 @@ int main(int argc, char **argv) { fprintf(stderr, "Output device: %s\n", device->name); if (device->probe_error) { - fprintf(stderr, "Cannot probe device: %s\n", soundio_strerror(device->probe_error)); + fprintf(stderr, "Cannot probe device: %s\n", soundio_error_name(device->probe_error)); return 1; } @@ -238,7 +238,7 @@ int main(int argc, char **argv) { } if ((err = soundio_outstream_open(outstream))) { - fprintf(stderr, "unable to open device: %s", soundio_strerror(err)); + fprintf(stderr, "unable to open device: %s", soundio_error_name(err)); return 1; } @@ -251,10 +251,10 @@ int main(int argc, char **argv) { "'q\\n' - quit\n"); if (outstream->layout_error) - fprintf(stderr, "unable to set channel layout: %s\n", soundio_strerror(outstream->layout_error)); + fprintf(stderr, "unable to set channel layout: %s\n", soundio_error_name(outstream->layout_error)); if ((err = soundio_outstream_start(outstream))) { - fprintf(stderr, "unable to start device: %s\n", soundio_strerror(err)); + fprintf(stderr, "unable to start device: %s\n", soundio_error_name(err)); return 1; } @@ -263,16 +263,16 @@ int main(int argc, char **argv) { int c = getc(stdin); if (c == 'p') { fprintf(stderr, "pausing result: %s\n", - soundio_strerror(soundio_outstream_pause(outstream, true))); + soundio_error_name(soundio_outstream_pause(outstream, true))); } else if (c == 'P') { want_pause = true; } else if (c == 'u') { want_pause = false; fprintf(stderr, "unpausing result: %s\n", - soundio_strerror(soundio_outstream_pause(outstream, false))); + soundio_error_name(soundio_outstream_pause(outstream, false))); } else if (c == 'c') { fprintf(stderr, "clear buffer result: %s\n", - soundio_strerror(soundio_outstream_clear_buffer(outstream))); + soundio_error_name(soundio_outstream_clear_buffer(outstream))); } else if (c == 'q') { break; } else if (c == '\r' || c == '\n') { diff --git a/soundio/soundio.h b/soundio/soundio.h index 4b648f6..9d1619c 100644 --- a/soundio/soundio.h +++ b/soundio/soundio.h @@ -68,7 +68,7 @@ * Demonstrates recovering from a backend disconnecting. */ -/// See also ::soundio_strerror +/// See also ::soundio_error_name enum SoundIoError { SoundIoErrorNone, /// Out of memory. @@ -729,7 +729,7 @@ SOUNDIO_EXPORT enum SoundIoError soundio_connect_backend(struct SoundIo *soundio SOUNDIO_EXPORT void soundio_disconnect(struct SoundIo *soundio); /// Get a string representation of a #SoundIoError -SOUNDIO_EXPORT const char *soundio_strerror(enum SoundIoError error); +SOUNDIO_EXPORT const char *soundio_error_name(enum SoundIoError error); /// Get a string representation of a #SoundIoBackend SOUNDIO_EXPORT const char *soundio_backend_name(enum SoundIoBackend backend); @@ -853,7 +853,7 @@ static inline int soundio_get_bytes_per_second(enum SoundIoFormat format, } /// Returns string representation of `format`. -SOUNDIO_EXPORT const char * soundio_format_string(enum SoundIoFormat format); +SOUNDIO_EXPORT const char * soundio_format_name(enum SoundIoFormat format); diff --git a/src/soundio.c b/src/soundio.c index 3de5fab..288d612 100644 --- a/src/soundio.c +++ b/src/soundio.c @@ -73,7 +73,7 @@ static backend_init_t backend_init_fns[] = { SOUNDIO_MAKE_LIST_DEF(struct SoundIoDevice*, SoundIoListDevicePtr, SOUNDIO_LIST_NOT_STATIC) SOUNDIO_MAKE_LIST_DEF(struct SoundIoSampleRateRange, SoundIoListSampleRateRange, SOUNDIO_LIST_NOT_STATIC) -const char *soundio_strerror(enum SoundIoError error) { +const char *soundio_error_name(enum SoundIoError error) { switch (error) { case SoundIoErrorNone: return "(no error)"; case SoundIoErrorNoMem: return "out of memory"; @@ -125,7 +125,7 @@ int soundio_get_bytes_per_sample(enum SoundIoFormat format) { return -1; } -const char * soundio_format_string(enum SoundIoFormat format) { +const char * soundio_format_name(enum SoundIoFormat format) { switch (format) { case SoundIoFormatS8: return "signed 8-bit"; case SoundIoFormatU8: return "unsigned 8-bit"; @@ -182,7 +182,7 @@ static void do_nothing_cb(struct SoundIo *soundio) { } static void default_msg_callback(const char *msg) { } static void default_backend_disconnect_cb(struct SoundIo *soundio, enum SoundIoError err) { - soundio_panic("libsoundio: backend disconnected: %s", soundio_strerror(err)); + soundio_panic("libsoundio: backend disconnected: %s", soundio_error_name(err)); } static struct SoundIoAtomicFlag rtprio_seen = SOUNDIO_ATOMIC_FLAG_INIT; @@ -465,7 +465,7 @@ enum SoundIoError soundio_outstream_end_write(struct SoundIoOutStream *outstream } static void default_outstream_error_callback(struct SoundIoOutStream *os, enum SoundIoError err) { - soundio_panic("libsoundio: %s", soundio_strerror(err)); + soundio_panic("libsoundio: %s", soundio_error_name(err)); } static void default_underflow_callback(struct SoundIoOutStream *outstream) { } @@ -569,7 +569,7 @@ enum SoundIoError soundio_outstream_get_latency(struct SoundIoOutStream *outstre } static void default_instream_error_callback(struct SoundIoInStream *is, enum SoundIoError err) { - soundio_panic("libsoundio: %s", soundio_strerror(err)); + soundio_panic("libsoundio: %s", soundio_error_name(err)); } static void default_overflow_callback(struct SoundIoInStream *instream) { } diff --git a/test/backend_disconnect_recover.c b/test/backend_disconnect_recover.c index 8f04191..863d002 100644 --- a/test/backend_disconnect_recover.c +++ b/test/backend_disconnect_recover.c @@ -39,7 +39,7 @@ static enum SoundIoBackend backend = SoundIoBackendNone; static bool severed = false; static void on_backend_disconnect(struct SoundIo *soundio, enum SoundIoError err) { - fprintf(stderr, "OK backend disconnected with '%s'.\n", soundio_strerror(err)); + fprintf(stderr, "OK backend disconnected with '%s'.\n", soundio_error_name(err)); severed = true; } @@ -87,7 +87,7 @@ int main(int argc, char **argv) { soundio_connect(soundio) : soundio_connect_backend(soundio, backend); if (err) - panic("error connecting: %s", soundio_strerror(err)); + panic("error connecting: %s", soundio_error_name(err)); soundio->on_backend_disconnect = on_backend_disconnect; @@ -110,7 +110,7 @@ int main(int argc, char **argv) { soundio_connect(soundio) : soundio_connect_backend(soundio, backend); if (err) - panic("error reconnecting: %s", soundio_strerror(err)); + panic("error reconnecting: %s", soundio_error_name(err)); fprintf(stderr, "OK reconnected successfully to %s\n", soundio_backend_name(soundio->current_backend)); diff --git a/test/latency.c b/test/latency.c index abce052..ec5ddad 100644 --- a/test/latency.c +++ b/test/latency.c @@ -57,7 +57,7 @@ static void write_time(struct SoundIoOutStream *outstream, double extra) { double latency; int err; if ((err = soundio_outstream_get_latency(outstream, &latency))) { - soundio_panic("getting latency: %s", soundio_strerror(err)); + soundio_panic("getting latency: %s", soundio_error_name(err)); } double now = soundio_os_get_time(); double audible_time = now + latency + extra; @@ -78,7 +78,7 @@ static void write_callback(struct SoundIoOutStream *outstream, int frame_count_m int frame_count = frames_left; if ((err = soundio_outstream_begin_write(outstream, &areas, &frame_count))) - soundio_panic("begin write: %s", soundio_strerror(err)); + soundio_panic("begin write: %s", soundio_error_name(err)); if (!frame_count) break; @@ -116,7 +116,7 @@ static void write_callback(struct SoundIoOutStream *outstream, int frame_count_m seconds_offset += seconds_per_frame * frame_count; if ((err = soundio_outstream_end_write(outstream))) - soundio_panic("end write: %s", soundio_strerror(err)); + soundio_panic("end write: %s", soundio_error_name(err)); frames_left -= frame_count; } @@ -171,7 +171,7 @@ int main(int argc, char **argv) { soundio_connect(soundio) : soundio_connect_backend(soundio, backend); if (err) - soundio_panic("error connecting: %s", soundio_strerror(err)); + soundio_panic("error connecting: %s", soundio_error_name(err)); soundio_flush_events(soundio); @@ -208,16 +208,16 @@ int main(int argc, char **argv) { } if ((err = soundio_ring_buffer_init(&pulse_rb, 1024))) - soundio_panic("ring buffer init: %s", soundio_strerror(err)); + soundio_panic("ring buffer init: %s", soundio_error_name(err)); if ((err = soundio_outstream_open(outstream))) - soundio_panic("unable to open device: %s", soundio_strerror(err)); + soundio_panic("unable to open device: %s", soundio_error_name(err)); if (outstream->layout_error) - fprintf(stderr, "unable to set channel layout: %s\n", soundio_strerror(outstream->layout_error)); + fprintf(stderr, "unable to set channel layout: %s\n", soundio_error_name(outstream->layout_error)); if ((err = soundio_outstream_start(outstream))) - soundio_panic("unable to start device: %s", soundio_strerror(err)); + soundio_panic("unable to start device: %s", soundio_error_name(err)); bool beep_on = true; int count = 0; diff --git a/test/overflow.c b/test/overflow.c index dcff2e9..f6dd1fe 100644 --- a/test/overflow.c +++ b/test/overflow.c @@ -90,7 +90,7 @@ static void read_callback(struct SoundIoInStream *instream, int frame_count_min, int frame_count = frames_left; if ((err = soundio_instream_begin_read(instream, &areas, &frame_count))) - panic("begin read error: %s", soundio_strerror(err)); + panic("begin read error: %s", soundio_error_name(err)); if (!frame_count) break; @@ -98,7 +98,7 @@ static void read_callback(struct SoundIoInStream *instream, int frame_count_min, seconds_offset += seconds_per_frame * frame_count; if ((err = soundio_instream_end_read(instream))) - panic("end read error: %s", soundio_strerror(err)); + panic("end read error: %s", soundio_error_name(err)); frames_left -= frame_count; if (frames_left <= 0) @@ -165,7 +165,7 @@ int main(int argc, char **argv) { soundio_connect(soundio) : soundio_connect_backend(soundio, backend); if (err) - panic("error connecting: %s", soundio_strerror(err)); + panic("error connecting: %s", soundio_error_name(err)); soundio_flush_events(soundio); @@ -210,12 +210,12 @@ int main(int argc, char **argv) { instream->overflow_callback = overflow_callback; if ((err = soundio_instream_open(instream))) - panic("unable to open device: %s", soundio_strerror(err)); + panic("unable to open device: %s", soundio_error_name(err)); - fprintf(stderr, "OK format: %s\n", soundio_format_string(instream->format)); + fprintf(stderr, "OK format: %s\n", soundio_format_name(instream->format)); if ((err = soundio_instream_start(instream))) - panic("unable to start device: %s", soundio_strerror(err)); + panic("unable to start device: %s", soundio_error_name(err)); while (seconds_offset < seconds_end) soundio_wait_events(soundio); diff --git a/test/underflow.c b/test/underflow.c index 083e92d..1a4ba40 100644 --- a/test/underflow.c +++ b/test/underflow.c @@ -90,7 +90,7 @@ static void write_callback(struct SoundIoOutStream *outstream, int frame_count_m for (;;) { int frame_count = frames_left; if ((err = soundio_outstream_begin_write(outstream, &areas, &frame_count))) - panic("%s", soundio_strerror(err)); + panic("%s", soundio_error_name(err)); if (!frame_count) break; @@ -111,7 +111,7 @@ static void write_callback(struct SoundIoOutStream *outstream, int frame_count_m if ((err = soundio_outstream_end_write(outstream))) { if (err == SoundIoErrorUnderflow) return; - panic("%s", soundio_strerror(err)); + panic("%s", soundio_error_name(err)); } frames_left -= frame_count; @@ -182,7 +182,7 @@ int main(int argc, char **argv) { soundio_connect(soundio) : soundio_connect_backend(soundio, backend); if (err) - panic("error connecting: %s", soundio_strerror(err)); + panic("error connecting: %s", soundio_error_name(err)); soundio_flush_events(soundio); @@ -233,13 +233,13 @@ int main(int argc, char **argv) { } if ((err = soundio_outstream_open(outstream))) - panic("unable to open device: %s", soundio_strerror(err)); + panic("unable to open device: %s", soundio_error_name(err)); if (outstream->layout_error) - fprintf(stderr, "unable to set channel layout: %s\n", soundio_strerror(outstream->layout_error)); + fprintf(stderr, "unable to set channel layout: %s\n", soundio_error_name(outstream->layout_error)); if ((err = soundio_outstream_start(outstream))) - panic("unable to start device: %s", soundio_strerror(err)); + panic("unable to start device: %s", soundio_error_name(err)); while (seconds_offset < seconds_end) soundio_wait_events(soundio); diff --git a/test/unit_tests.c b/test/unit_tests.c index 9ba33f4..f0a288b 100644 --- a/test/unit_tests.c +++ b/test/unit_tests.c @@ -12,7 +12,7 @@ static inline void ok_or_panic(int err) { if (err) - soundio_panic("%s", soundio_strerror(err)); + soundio_panic("%s", soundio_error_name(err)); } static void test_os_get_time(void) {