Skip to content

Commit

Permalink
more unused warnings and sleep time conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
peterino2 committed Jul 10, 2023
1 parent 2a3505b commit d74df5f
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 13 deletions.
2 changes: 1 addition & 1 deletion example/sio_record.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#include <unistd.h>
#else
#include <Windows.h>
#define sleep Sleep
#define sleep(x) Sleep(x * 1000)
#endif

struct RecordContext {
Expand Down
24 changes: 19 additions & 5 deletions src/dummy.c
Original file line number Diff line number Diff line change
Expand Up @@ -158,10 +158,13 @@ static void wakeup_dummy(struct SoundIoPrivate *si) {
}

static void force_device_scan_dummy(struct SoundIoPrivate *si) {
(void)si;
// nothing to do; dummy devices never change
}

static void outstream_destroy_dummy(struct SoundIoPrivate *si, struct SoundIoOutStreamPrivate *os) {
(void)si;

struct SoundIoOutStreamDummy *osd = &os->backend_data.dummy;

if (osd->thread) {
Expand Down Expand Up @@ -193,7 +196,7 @@ static int outstream_open_dummy(struct SoundIoPrivate *si, struct SoundIoOutStre

int err;
int buffer_size = (int) (outstream->bytes_per_frame * outstream->sample_rate * outstream->software_latency);
if ((err = soundio_ring_buffer_init(&osd->ring_buffer, buffer_size))) {
if ((err = soundio_ring_buffer_init(&osd->ring_buffer, buffer_size)) != 0) {
outstream_destroy_dummy(si, os);
return err;
}
Expand All @@ -211,6 +214,7 @@ static int outstream_open_dummy(struct SoundIoPrivate *si, struct SoundIoOutStre
}

static int outstream_pause_dummy(struct SoundIoPrivate *si, struct SoundIoOutStreamPrivate *os, bool pause) {
(void)si;
struct SoundIoOutStreamDummy *osd = &os->backend_data.dummy;
SOUNDIO_ATOMIC_STORE_BOOL(osd->pause_requested, pause);
return 0;
Expand All @@ -233,6 +237,7 @@ static int outstream_start_dummy(struct SoundIoPrivate *si, struct SoundIoOutStr
static int outstream_begin_write_dummy(struct SoundIoPrivate *si,
struct SoundIoOutStreamPrivate *os, struct SoundIoChannelArea **out_areas, int *frame_count)
{
(void)si;
struct SoundIoOutStream *outstream = &os->pub;
struct SoundIoOutStreamDummy *osd = &os->backend_data.dummy;

Expand All @@ -251,6 +256,7 @@ static int outstream_begin_write_dummy(struct SoundIoPrivate *si,
}

static int outstream_end_write_dummy(struct SoundIoPrivate *si, struct SoundIoOutStreamPrivate *os) {
(void)si;
struct SoundIoOutStreamDummy *osd = &os->backend_data.dummy;
struct SoundIoOutStream *outstream = &os->pub;
int byte_count = osd->write_frame_count * outstream->bytes_per_frame;
Expand All @@ -260,13 +266,15 @@ static int outstream_end_write_dummy(struct SoundIoPrivate *si, struct SoundIoOu
}

static int outstream_clear_buffer_dummy(struct SoundIoPrivate *si, struct SoundIoOutStreamPrivate *os) {
(void)si;
struct SoundIoOutStreamDummy *osd = &os->backend_data.dummy;
SOUNDIO_ATOMIC_FLAG_CLEAR(osd->clear_buffer_flag);
soundio_os_cond_signal(osd->cond, NULL);
return 0;
}

static int outstream_get_latency_dummy(struct SoundIoPrivate *si, struct SoundIoOutStreamPrivate *os, double *out_latency) {
(void)si;
struct SoundIoOutStream *outstream = &os->pub;
struct SoundIoOutStreamDummy *osd = &os->backend_data.dummy;
int fill_bytes = soundio_ring_buffer_fill_count(&osd->ring_buffer);
Expand All @@ -276,6 +284,7 @@ static int outstream_get_latency_dummy(struct SoundIoPrivate *si, struct SoundIo
}

static void instream_destroy_dummy(struct SoundIoPrivate *si, struct SoundIoInStreamPrivate *is) {
(void)si;
struct SoundIoInStreamDummy *isd = &is->backend_data.dummy;

if (isd->thread) {
Expand Down Expand Up @@ -326,6 +335,7 @@ static int instream_open_dummy(struct SoundIoPrivate *si, struct SoundIoInStream
}

static int instream_pause_dummy(struct SoundIoPrivate *si, struct SoundIoInStreamPrivate *is, bool pause) {
(void)si;
struct SoundIoInStreamDummy *isd = &is->backend_data.dummy;
SOUNDIO_ATOMIC_STORE_BOOL(isd->pause_requested, pause);
return 0;
Expand All @@ -348,6 +358,7 @@ static int instream_start_dummy(struct SoundIoPrivate *si, struct SoundIoInStrea
static int instream_begin_read_dummy(struct SoundIoPrivate *si,
struct SoundIoInStreamPrivate *is, struct SoundIoChannelArea **out_areas, int *frame_count)
{
(void)si;
struct SoundIoInStream *instream = &is->pub;
struct SoundIoInStreamDummy *isd = &is->backend_data.dummy;

Expand All @@ -366,6 +377,8 @@ static int instream_begin_read_dummy(struct SoundIoPrivate *si,
}

static int instream_end_read_dummy(struct SoundIoPrivate *si, struct SoundIoInStreamPrivate *is) {
(void)si;

struct SoundIoInStreamDummy *isd = &is->backend_data.dummy;
struct SoundIoInStream *instream = &is->pub;
int byte_count = isd->read_frame_count * instream->bytes_per_frame;
Expand All @@ -375,6 +388,7 @@ static int instream_end_read_dummy(struct SoundIoPrivate *si, struct SoundIoInSt
}

static int instream_get_latency_dummy(struct SoundIoPrivate *si, struct SoundIoInStreamPrivate *is, double *out_latency) {
(void)si;
struct SoundIoInStream *instream = &is->pub;
struct SoundIoInStreamDummy *osd = &is->backend_data.dummy;
int fill_bytes = soundio_ring_buffer_fill_count(&osd->ring_buffer);
Expand Down Expand Up @@ -475,12 +489,12 @@ int soundio_dummy_init(struct SoundIoPrivate *si) {
}

int err;
if ((err = set_all_device_channel_layouts(device))) {
if ((err = set_all_device_channel_layouts(device)) != 0) {
soundio_device_unref(device);
destroy_dummy(si);
return err;
}
if ((err = set_all_device_formats(device))) {
if ((err = set_all_device_formats(device)) != 0) {
soundio_device_unref(device);
destroy_dummy(si);
return err;
Expand Down Expand Up @@ -521,13 +535,13 @@ int soundio_dummy_init(struct SoundIoPrivate *si) {
}

int err;
if ((err = set_all_device_channel_layouts(device))) {
if ((err = set_all_device_channel_layouts(device)) != 0) {
soundio_device_unref(device);
destroy_dummy(si);
return err;
}

if ((err = set_all_device_formats(device))) {
if ((err = set_all_device_formats(device)) != 0) {
soundio_device_unref(device);
destroy_dummy(si);
return err;
Expand Down
11 changes: 6 additions & 5 deletions src/os.c
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,7 @@ void soundio_os_cond_timed_wait(struct SoundIoOsCond *cond,
target_cs = &cond->default_cs_id;
EnterCriticalSection(&cond->default_cs_id);
}
DWORD ms = seconds * 1000.0;
DWORD ms = (DWORD) (seconds * 1000.0);
SleepConditionVariableCS(&cond->id, target_cs, ms);
if (!locked_mutex)
LeaveCriticalSection(&cond->default_cs_id);
Expand Down Expand Up @@ -585,7 +585,7 @@ int soundio_os_init(void) {
if (!pending)
return 0;

if ((err = internal_init()))
if ((err = internal_init()) != 0)
return err;

if (!InitOnceComplete(&win32_init_once, INIT_ONCE_ASYNC, NULL))
Expand All @@ -610,16 +610,17 @@ int soundio_os_page_size(void) {
}

static inline size_t ceil_dbl_to_size_t(double x) {
const double truncation = (size_t)x;
return truncation + (truncation < x);
const size_t trunc = (size_t)x;
const double truncation = (double)trunc;
return (size_t) (truncation + (truncation < x));
}

int soundio_os_init_mirrored_memory(struct SoundIoOsMirroredMemory *mem, size_t requested_capacity) {
size_t actual_capacity = ceil_dbl_to_size_t(requested_capacity / (double)page_size) * page_size;

#if defined(SOUNDIO_OS_WINDOWS)
BOOL ok;
HANDLE hMapFile = CreateFileMapping(INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE, 0, actual_capacity * 2, NULL);
HANDLE hMapFile = CreateFileMapping(INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE, 0, (DWORD)(actual_capacity * 2), NULL);
if (!hMapFile)
return SoundIoErrorNoMem;

Expand Down
1 change: 1 addition & 0 deletions test/latency.c
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ static void write_callback(struct SoundIoOutStream *outstream, int frame_count_m
}

static void underflow_callback(struct SoundIoOutStream *outstream) {
(void)outstream;
soundio_panic("underflow\n");
}

Expand Down
2 changes: 1 addition & 1 deletion test/overflow.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ __attribute__ ((format (printf, 1, 2)))
static void panic(const char *format, ...) {
#else
#include <Windows.h>
#define sleep Sleep
#define sleep(x) Sleep(x * 1000)

__declspec(noreturn) static void panic(const char *format, ...) {
#endif
Expand Down
2 changes: 1 addition & 1 deletion test/underflow.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ __attribute__ ((format (printf, 1, 2)))
static void panic(const char *format, ...) {
#else
#include <Windows.h>
#define sleep Sleep
#define sleep(x) Sleep(x * 1000)
__declspec(noreturn) static void panic(const char *format, ...) {
#endif
va_list ap;
Expand Down

0 comments on commit d74df5f

Please sign in to comment.