no longer depend on or link against libm

This commit is contained in:
Andrew Kelley 2015-09-05 14:49:00 -07:00
parent 8406dcd0ad
commit e2e483a4d5
7 changed files with 37 additions and 16 deletions

View file

@ -190,7 +190,6 @@ set(LIBSOUNDIO_LIBS
${COREAUDIO_LIBRARY} ${COREAUDIO_LIBRARY}
${COREFOUNDATION_LIBRARY} ${COREFOUNDATION_LIBRARY}
${AUDIOUNIT_LIBRARY} ${AUDIOUNIT_LIBRARY}
m
${CMAKE_THREAD_LIBS_INIT} ${CMAKE_THREAD_LIBS_INIT}
) )
@ -261,7 +260,7 @@ if(BUILD_EXAMPLE_PROGRAMS)
set_target_properties(sio_sine PROPERTIES set_target_properties(sio_sine PROPERTIES
LINKER_LANGUAGE C LINKER_LANGUAGE C
COMPILE_FLAGS ${EXAMPLE_CFLAGS}) COMPILE_FLAGS ${EXAMPLE_CFLAGS})
target_link_libraries(sio_sine libsoundio_shared) target_link_libraries(sio_sine libsoundio_shared m)
install(TARGETS sio_sine DESTINATION ${CMAKE_INSTALL_BINDIR}) install(TARGETS sio_sine DESTINATION ${CMAKE_INSTALL_BINDIR})
add_executable(sio_list_devices example/sio_list_devices.c) add_executable(sio_list_devices example/sio_list_devices.c)
@ -296,7 +295,7 @@ if(BUILD_TESTS)
) )
add_executable(latency "${CMAKE_SOURCE_DIR}/test/latency.cpp" ${LIBSOUNDIO_SOURCES}) add_executable(latency "${CMAKE_SOURCE_DIR}/test/latency.cpp" ${LIBSOUNDIO_SOURCES})
target_link_libraries(latency LINK_PUBLIC ${LIBSOUNDIO_LIBS}) target_link_libraries(latency LINK_PUBLIC ${LIBSOUNDIO_LIBS} m)
set_target_properties(latency PROPERTIES set_target_properties(latency PROPERTIES
LINKER_LANGUAGE C LINKER_LANGUAGE C
COMPILE_FLAGS ${LIB_CFLAGS} COMPILE_FLAGS ${LIB_CFLAGS}
@ -306,7 +305,7 @@ if(BUILD_TESTS)
set_target_properties(underflow PROPERTIES set_target_properties(underflow PROPERTIES
LINKER_LANGUAGE C LINKER_LANGUAGE C
COMPILE_FLAGS ${EXAMPLE_CFLAGS}) COMPILE_FLAGS ${EXAMPLE_CFLAGS})
target_link_libraries(underflow libsoundio_shared) target_link_libraries(underflow libsoundio_shared m)
add_executable(backend_disconnect_recover test/backend_disconnect_recover.c) add_executable(backend_disconnect_recover test/backend_disconnect_recover.c)
set_target_properties(backend_disconnect_recover PROPERTIES set_target_properties(backend_disconnect_recover PROPERTIES

View file

@ -59,6 +59,11 @@ static void destroy_alsa(SoundIoPrivate *si) {
close(sia->notify_fd); close(sia->notify_fd);
} }
static inline snd_pcm_uframes_t ceil_dbl_to_uframes(double x) {
const double truncation = (snd_pcm_uframes_t)x;
return truncation + (truncation < x);
}
static char * str_partition_on_char(char *str, char c) { static char * str_partition_on_char(char *str, char c) {
while (*str) { while (*str) {
if (*str == c) { if (*str == c) {
@ -1253,7 +1258,7 @@ static int outstream_open_alsa(SoundIoPrivate *si, SoundIoOutStreamPrivate *os)
return SoundIoErrorOpeningDevice; return SoundIoErrorOpeningDevice;
} }
osa->buffer_size_frames = ceil(outstream->software_latency * (double)outstream->sample_rate); osa->buffer_size_frames = ceil_dbl_to_int(outstream->software_latency * (double)outstream->sample_rate);
if ((err = snd_pcm_hw_params_set_buffer_size_near(osa->handle, hwparams, &osa->buffer_size_frames)) < 0) { if ((err = snd_pcm_hw_params_set_buffer_size_near(osa->handle, hwparams, &osa->buffer_size_frames)) < 0) {
outstream_destroy_alsa(si, os); outstream_destroy_alsa(si, os);
@ -1269,7 +1274,8 @@ static int outstream_open_alsa(SoundIoPrivate *si, SoundIoOutStreamPrivate *os)
} }
} else { } else {
double period_duration = outstream->software_latency / 2.0; double period_duration = outstream->software_latency / 2.0;
snd_pcm_uframes_t period_frames = ceil(period_duration * (double)outstream->sample_rate); snd_pcm_uframes_t period_frames =
ceil_dbl_to_uframes(period_duration * (double)outstream->sample_rate);
if ((err = snd_pcm_hw_params_set_period_size_near(osa->handle, hwparams, &period_frames, nullptr)) < 0) { if ((err = snd_pcm_hw_params_set_period_size_near(osa->handle, hwparams, &period_frames, nullptr)) < 0) {
outstream_destroy_alsa(si, os); outstream_destroy_alsa(si, os);
@ -1567,7 +1573,7 @@ static int instream_open_alsa(SoundIoPrivate *si, SoundIoInStreamPrivate *is) {
return SoundIoErrorOpeningDevice; return SoundIoErrorOpeningDevice;
} }
snd_pcm_uframes_t period_frames = ceil(0.5 * instream->software_latency * (double)instream->sample_rate); snd_pcm_uframes_t period_frames = ceil_dbl_to_uframes(0.5 * instream->software_latency * (double)instream->sample_rate);
if ((err = snd_pcm_hw_params_set_period_size_near(isa->handle, hwparams, &period_frames, nullptr)) < 0) { if ((err = snd_pcm_hw_params_set_period_size_near(isa->handle, hwparams, &period_frames, nullptr)) < 0) {
instream_destroy_alsa(si, is); instream_destroy_alsa(si, is);
return SoundIoErrorOpeningDevice; return SoundIoErrorOpeningDevice;

View file

@ -683,8 +683,8 @@ static int refresh_devices(struct SoundIoPrivate *si) {
if (avr_array_len == 1) { if (avr_array_len == 1) {
rd.device->sample_rate_count = 1; rd.device->sample_rate_count = 1;
rd.device->sample_rates = &dev->prealloc_sample_rate_range; rd.device->sample_rates = &dev->prealloc_sample_rate_range;
rd.device->sample_rates[0].min = ceil(rd.avr_array[0].mMinimum); rd.device->sample_rates[0].min = ceil_dbl_to_int(rd.avr_array[0].mMinimum);
rd.device->sample_rates[0].max = floor(rd.avr_array[0].mMaximum); rd.device->sample_rates[0].max = (int)(rd.avr_array[0].mMaximum);
} else { } else {
rd.device->sample_rate_count = avr_array_len; rd.device->sample_rate_count = avr_array_len;
rd.device->sample_rates = allocate<SoundIoSampleRateRange>(avr_array_len); rd.device->sample_rates = allocate<SoundIoSampleRateRange>(avr_array_len);
@ -694,8 +694,8 @@ static int refresh_devices(struct SoundIoPrivate *si) {
} }
for (int i = 0; i < avr_array_len; i += 1) { for (int i = 0; i < avr_array_len; i += 1) {
AudioValueRange *avr = &rd.avr_array[i]; AudioValueRange *avr = &rd.avr_array[i];
int min_val = ceil(avr->mMinimum); int min_val = ceil_dbl_to_int(avr->mMinimum);
int max_val = floor(avr->mMaximum); int max_val = (int)(avr->mMaximum);
rd.device->sample_rates[i].min = min_val; rd.device->sample_rates[i].min = min_val;
rd.device->sample_rates[i].max = max_val; rd.device->sample_rates[i].max = max_val;
} }

View file

@ -29,7 +29,7 @@ static void playback_thread_run(void *arg) {
double now = soundio_os_get_time(); double now = soundio_os_get_time();
double time_passed = now - start_time; double time_passed = now - start_time;
double next_period = start_time + double next_period = start_time +
ceil(time_passed / osd->period_duration) * osd->period_duration; ceil_dbl(time_passed / osd->period_duration) * osd->period_duration;
double relative_time = next_period - now; double relative_time = next_period - now;
soundio_os_cond_timed_wait(osd->cond, nullptr, relative_time); soundio_os_cond_timed_wait(osd->cond, nullptr, relative_time);
if (!osd->clear_buffer_flag.test_and_set()) { if (!osd->clear_buffer_flag.test_and_set()) {
@ -80,7 +80,7 @@ static void capture_thread_run(void *arg) {
double now = soundio_os_get_time(); double now = soundio_os_get_time();
double time_passed = now - start_time; double time_passed = now - start_time;
double next_period = start_time + double next_period = start_time +
ceil(time_passed / isd->period_duration) * isd->period_duration; ceil_dbl(time_passed / isd->period_duration) * isd->period_duration;
double relative_time = next_period - now; double relative_time = next_period - now;
soundio_os_cond_timed_wait(isd->cond, nullptr, relative_time); soundio_os_cond_timed_wait(isd->cond, nullptr, relative_time);

View file

@ -604,8 +604,13 @@ int soundio_os_page_size(void) {
return page_size; return page_size;
} }
static inline size_t ceil_dbl_to_size_t(double x) {
const double truncation = (size_t)x;
return truncation + (truncation < x);
}
int soundio_os_init_mirrored_memory(struct SoundIoOsMirroredMemory *mem, size_t requested_capacity) { int soundio_os_init_mirrored_memory(struct SoundIoOsMirroredMemory *mem, size_t requested_capacity) {
size_t actual_capacity = ceil(requested_capacity / (double)page_size) * page_size; size_t actual_capacity = ceil_dbl_to_size_t(requested_capacity / (double)page_size) * page_size;
#if defined(SOUNDIO_OS_WINDOWS) #if defined(SOUNDIO_OS_WINDOWS)
BOOL ok; BOOL ok;

View file

@ -693,7 +693,7 @@ static int outstream_open_pa(SoundIoPrivate *si, SoundIoOutStreamPrivate *os) {
int bytes_per_second = outstream->bytes_per_frame * outstream->sample_rate; int bytes_per_second = outstream->bytes_per_frame * outstream->sample_rate;
if (outstream->software_latency > 0.0) { if (outstream->software_latency > 0.0) {
int buffer_length = outstream->bytes_per_frame * int buffer_length = outstream->bytes_per_frame *
ceil(outstream->software_latency * bytes_per_second / (double)outstream->bytes_per_frame); ceil_dbl_to_int(outstream->software_latency * bytes_per_second / (double)outstream->bytes_per_frame);
ospa->buffer_attr.maxlength = buffer_length; ospa->buffer_attr.maxlength = buffer_length;
ospa->buffer_attr.tlength = buffer_length; ospa->buffer_attr.tlength = buffer_length;
@ -925,7 +925,7 @@ static int instream_open_pa(SoundIoPrivate *si, SoundIoInStreamPrivate *is) {
if (instream->software_latency > 0.0) { if (instream->software_latency > 0.0) {
int bytes_per_second = instream->bytes_per_frame * instream->sample_rate; int bytes_per_second = instream->bytes_per_frame * instream->sample_rate;
int buffer_length = instream->bytes_per_frame * int buffer_length = instream->bytes_per_frame *
ceil(instream->software_latency * bytes_per_second / (double)instream->bytes_per_frame); ceil_dbl_to_int(instream->software_latency * bytes_per_second / (double)instream->bytes_per_frame);
ispa->buffer_attr.fragsize = buffer_length; ispa->buffer_attr.fragsize = buffer_length;
} }

View file

@ -50,6 +50,17 @@ static inline bool soundio_streql(const char *str1, int str1_len, const char *st
return memcmp(str1, str2, str1_len) == 0; return memcmp(str1, str2, str1_len) == 0;
} }
static inline int ceil_dbl_to_int(double x) {
const double truncation = (int)x;
return truncation + (truncation < x);
}
static inline double ceil_dbl(double x) {
const double truncation = (long long) x;
const double ceiling = truncation + (truncation < x);
return ceiling;
}
template <typename T, long n> template <typename T, long n>
static constexpr long array_length(const T (&)[n]) { static constexpr long array_length(const T (&)[n]) {