Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

re-add custom core-audio truncation after syncing fork #3

Merged
merged 2 commits into from
Dec 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,13 @@ option(RTAUDIO_API_PULSE "Build PulseAudio API" ${pulse_FOUND})
option(RTAUDIO_API_JACK "Build JACK audio server API" ${HAVE_JACK})
option(RTAUDIO_API_CORE "Build CoreAudio API" ${APPLE})

# String encoding
option(RTAUDIO_UNICODE "Request UTF-8 encoded strings from system calls" OFF)

if (RTAUDIO_UNICODE)
add_definitions(-DUNICODE)
endif ()

# Check for functions
include(CheckFunctionExists)
check_function_exists(gettimeofday HAVE_GETTIMEOFDAY)
Expand Down
25 changes: 16 additions & 9 deletions RtAudio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11210,8 +11210,8 @@ void RtApi :: convertBuffer( char *outBuffer, char *inBuffer, ConvertInfo &info
Float32 *in = (Float32 *)inBuffer;
for (unsigned int i=0; i<stream_.bufferSize; i++) {
for (j=0; j<info.channels; j++) {
// Use llround() which returns `long long` which is guaranteed to be at least 64 bits.
out[info.outOffset[j]] = (Int32) std::max(std::min(std::llround(in[info.inOffset[j]] * 2147483648.f), 2147483647LL), -2147483648LL);
long long value = in[info.inOffset[j]] * 2147483648LL;
out[info.outOffset[j]] = std::max(-2147483648LL, std::min(value, 2147483647LL));

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: std::clamp

}
in += info.inJump;
out += info.outJump;
Expand All @@ -11221,7 +11221,8 @@ void RtApi :: convertBuffer( char *outBuffer, char *inBuffer, ConvertInfo &info
Float64 *in = (Float64 *)inBuffer;
for (unsigned int i=0; i<stream_.bufferSize; i++) {
for (j=0; j<info.channels; j++) {
out[info.outOffset[j]] = (Int32) std::max(std::min(std::llround(in[info.inOffset[j]] * 2147483648.0), 2147483647LL), -2147483648LL);
long long value = in[info.inOffset[j]] * 2147483648LL;
out[info.outOffset[j]] = std::max(-2147483648LL, std::min(value, 2147483647LL));
}
in += info.inJump;
out += info.outJump;
Expand Down Expand Up @@ -11278,7 +11279,8 @@ void RtApi :: convertBuffer( char *outBuffer, char *inBuffer, ConvertInfo &info
Float32 *in = (Float32 *)inBuffer;
for (unsigned int i=0; i<stream_.bufferSize; i++) {
for (j=0; j<info.channels; j++) {
out[info.outOffset[j]] = (Int32) std::max(std::min(std::llround(in[info.inOffset[j]] * 8388608.f), 8388607LL), -8388608LL);
Int32 value = in[info.inOffset[j]] * 8388608;
out[info.outOffset[j]] = std::max(-8388608, std::min(value, 8388607));
}
in += info.inJump;
out += info.outJump;
Expand All @@ -11288,7 +11290,8 @@ void RtApi :: convertBuffer( char *outBuffer, char *inBuffer, ConvertInfo &info
Float64 *in = (Float64 *)inBuffer;
for (unsigned int i=0; i<stream_.bufferSize; i++) {
for (j=0; j<info.channels; j++) {
out[info.outOffset[j]] = (Int32) std::max(std::min(std::llround(in[info.inOffset[j]] * 8388608.0), 8388607LL), -8388608LL);
Int32 value = in[info.inOffset[j]] * 8388608;
out[info.outOffset[j]] = std::max(-8388608, std::min(value, 8388607));
}
in += info.inJump;
out += info.outJump;
Expand Down Expand Up @@ -11343,7 +11346,8 @@ void RtApi :: convertBuffer( char *outBuffer, char *inBuffer, ConvertInfo &info
Float32 *in = (Float32 *)inBuffer;
for (unsigned int i=0; i<stream_.bufferSize; i++) {
for (j=0; j<info.channels; j++) {
out[info.outOffset[j]] = (Int16) std::max(std::min(std::llround(in[info.inOffset[j]] * 32768.f), 32767LL), -32768LL);
Int32 value = in[info.inOffset[j]] * 32768;
out[info.outOffset[j]] = std::max(-32768, std::min(value, 32767));
}
in += info.inJump;
out += info.outJump;
Expand All @@ -11353,7 +11357,8 @@ void RtApi :: convertBuffer( char *outBuffer, char *inBuffer, ConvertInfo &info
Float64 *in = (Float64 *)inBuffer;
for (unsigned int i=0; i<stream_.bufferSize; i++) {
for (j=0; j<info.channels; j++) {
out[info.outOffset[j]] = (Int16) std::max(std::min(std::llround(in[info.inOffset[j]] * 32768.0), 32767LL), -32768LL);
Int32 value = in[info.inOffset[j]] * 32768;
out[info.outOffset[j]] = std::max(-32768, std::min(value, 32767));
}
in += info.inJump;
out += info.outJump;
Expand Down Expand Up @@ -11407,7 +11412,8 @@ void RtApi :: convertBuffer( char *outBuffer, char *inBuffer, ConvertInfo &info
Float32 *in = (Float32 *)inBuffer;
for (unsigned int i=0; i<stream_.bufferSize; i++) {
for (j=0; j<info.channels; j++) {
out[info.outOffset[j]] = (signed char) std::max(std::min(std::llround(in[info.inOffset[j]] * 128.f), 127LL), -128LL);
Int32 value = in[info.inOffset[j]] * 128;
out[info.outOffset[j]] = std::max(-128, std::min(value, 127));
}
in += info.inJump;
out += info.outJump;
Expand All @@ -11417,7 +11423,8 @@ void RtApi :: convertBuffer( char *outBuffer, char *inBuffer, ConvertInfo &info
Float64 *in = (Float64 *)inBuffer;
for (unsigned int i=0; i<stream_.bufferSize; i++) {
for (j=0; j<info.channels; j++) {
out[info.outOffset[j]] = (signed char) std::max(std::min(std::llround(in[info.inOffset[j]] * 128.0), 127LL), -128LL);
Int32 value = in[info.inOffset[j]] * 128;
out[info.outOffset[j]] = std::max(-128, std::min(value, 127));
}
in += info.inJump;
out += info.outJump;
Expand Down
Loading