Skip to content

Commit

Permalink
Merge pull request #3 from holoplot/master-backup
Browse files Browse the repository at this point in the history
re-add custom core-audio truncation after syncing fork
  • Loading branch information
lkotsonis authored Dec 3, 2024
2 parents 7aba116 + a1644b3 commit d901c0e
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 9 deletions.
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));
}
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

0 comments on commit d901c0e

Please sign in to comment.