Skip to content

Commit

Permalink
Merge pull request #59 from treapster/main
Browse files Browse the repository at this point in the history
Fix UBSan errors
  • Loading branch information
iurienistor committed Feb 17, 2024
2 parents 1d20f00 + 45a01cc commit 08d017e
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 8 deletions.
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ endif ()

if (GKICK_ARCHITECTURE MATCHES x86_64)
message(STATUS "set optimisation compiler flags for ${GKICK_ARCHITECTURE}")
set(GKICK_OPTIMISATION_FLAGS "-O3 -msse -msse2 -mfpmath=sse -ffast-math -fomit-frame-pointer")
set(GKICK_OPTIMISATION_FLAGS "-O3 -msse -msse2 -mfpmath=sse -funsafe-math-optimizations -fno-math-errno -fno-trapping-math -fomit-frame-pointer")
else ()
message(STATUS "set optimisation compiler flags for ${GKICK_ARCHITECTURE}")
set(GKICK_OPTIMISATION_FLAGS "-O3 -ffast-math -fomit-frame-pointer")
set(GKICK_OPTIMISATION_FLAGS "-O3 -funsafe-math-optimizations -fno-math-errno -fno-trapping-math -fomit-frame-pointer")
endif ()

set(CMAKE_CXX_STANDARD 17)
Expand Down
3 changes: 2 additions & 1 deletion src/compressor_group_box.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,8 @@ void CompressorGroupBox::updateGui()
compressorCheckbox->setPressed(geonkickApi->isCompressorEnabled());

// Attack
attackSlider->onSetValue(100 * (log10(1000 * geonkickApi->getCompressorAttack()) / log10(2000)));
double attack = 100 * (log10(1000 * geonkickApi->getCompressorAttack()) / log10(2000));
attackSlider->onSetValue(static_cast<int>(std::max(attack, 0.0)));

// Threshold
auto threshold = geonkickApi->getCompressorThreshold();
Expand Down
4 changes: 4 additions & 0 deletions src/dsp/src/geonkick.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ extern "C" {
#include <float.h>
#include <stdbool.h>

#ifdef __FAST_MATH__
#error -ffast-math disables nan detection needed by geonkick
#endif

#ifdef __STDC_NO_ATOMICS__
#error atomic operations are not supported
#endif
Expand Down
4 changes: 2 additions & 2 deletions src/dsp/src/mixer.c
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,8 @@ gkick_mixer_process(struct gkick_mixer *mixer,
out[right_index] + offset,
size,
limiter_val);
gkick_real leveler_val = ring_buffer_get_cur_data(output->ring_buffer);
leveler_val *= limiter_val;
gkick_real sample = ring_buffer_get_cur_data(output->ring_buffer);
gkick_real leveler_val = fabsf(sample) * limiter_val;
gkick_mixer_set_leveler(mixer, i, leveler_val);
}
ring_buffer_next(output->ring_buffer, size);
Expand Down
9 changes: 7 additions & 2 deletions src/dsp/src/synthesizer.c
Original file line number Diff line number Diff line change
Expand Up @@ -1088,9 +1088,14 @@ synth_kick_env_get_apply_type(struct gkick_synth *synth,
enum gkick_envelope_apply_type *apply_type)
{
gkick_synth_lock(synth);
if (env_type == GEONKICK_FILTER_CUTOFF_ENVELOPE) {
switch (env_type) {
case GEONKICK_FILTER_CUTOFF_ENVELOPE:
*apply_type = gkick_envelope_get_apply_type(synth->filter->cutoff_env);
}
break;
default:
*apply_type = GEONKICK_ENVELOPE_APPLY_LINEAR;
break;
}
gkick_synth_unlock(synth);
return GEONKICK_OK;
}
Expand Down
3 changes: 2 additions & 1 deletion src/kit_model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,8 @@ int KitModel::percussionLimiter(PercussionIndex index) const
int KitModel::percussionLeveler(PercussionIndex index) const
{
auto realVal = geonkickApi->getLimiterLevelerValue(percussionId(index));
double logVal = 20 * log10(realVal);
// add small delta to avoid -inf for zero value
double logVal = 20 * log10(realVal + 0.000000001);
int val = (logVal + 55.0) * 100.0 / 75;
if (val < 0)
val = 0;
Expand Down

0 comments on commit 08d017e

Please sign in to comment.