Skip to content

Commit

Permalink
Merge branch 'main' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
iurienistor committed Feb 18, 2024
2 parents 145b150 + 963c2c1 commit adb83eb
Show file tree
Hide file tree
Showing 10 changed files with 44 additions and 26 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 20)
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
7 changes: 4 additions & 3 deletions 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 Expand Up @@ -205,8 +206,8 @@ void KitModel::loadModelData()
bool KitModel::open(const std::string &file)
{
auto kit = std::make_unique<KitState>();
if (kit->open(file)) {
GEONKICK_LOG_ERROR("can't open kit");
if (!kit->open(file)) {
GEONKICK_LOG_ERROR("can't open kit, the preset might be wrong or corrupted");
return false;
}

Expand Down
24 changes: 15 additions & 9 deletions src/kit_state.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,7 @@ bool KitState::open(const std::string &fileName)
(std::istreambuf_iterator<char>()));

sfile.close();
fromJson(fileData);
return false;
return fromJson(fileData);
}

bool KitState::save(const std::string &fileName)
Expand Down Expand Up @@ -123,17 +122,18 @@ const std::vector<std::unique_ptr<PercussionState>>& KitState::percussions() con
return percussionsList;
}

void KitState::fromJson(const std::string &jsonData)
bool KitState::fromJson(const std::string &jsonData)
{
rapidjson::Document document;
document.Parse(jsonData.c_str());
if (!document.IsObject())
return;
fromJsonObject(document);
return false;
return fromJsonObject(document);
}

void KitState::fromJsonObject(const rapidjson::Value &obj)
bool KitState::fromJsonObject(const rapidjson::Value &obj)
{
bool isOk = true;
for (const auto &m: obj.GetObject()) {
if (m.name == "KitAppVersion" && m.value.IsInt())
kitAppVersion = m.value.GetInt();
Expand All @@ -144,19 +144,25 @@ void KitState::fromJsonObject(const rapidjson::Value &obj)
if (m.name == "url" && m.value.IsString())
setUrl(m.value.GetString());
if (m.name == "percussions" && m.value.IsArray())
parsePercussions(m.value);
isOk = parsePercussions(m.value);
}
return isOk;
}

void KitState::parsePercussions(const rapidjson::Value &percussionsArray)
bool KitState::parsePercussions(const rapidjson::Value &percussionsArray)
{
if (percussionsArray.Empty())
return false;

size_t i = 0;
for (const auto &per: percussionsArray.GetArray()) {
auto state = std::make_unique<PercussionState>();
state->setId(i++);
state->loadObject(per);
if (!state->loadObject(per))
return false;
addPercussion(std::move(state));
}
return true;
}

std::string KitState::toJson() const
Expand Down
6 changes: 3 additions & 3 deletions src/kit_state.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ class KitState {
KitState();
bool open(const std::string &fileName);
bool save(const std::string &fileName);
void fromJson(const std::string &jsonData);
void fromJsonObject(const rapidjson::Value &obj);
bool fromJson(const std::string &jsonData);
bool fromJsonObject(const rapidjson::Value &obj);
void setName(const std::string &name);
std::string getName() const;
void setAuthor(const std::string &author);
Expand All @@ -48,7 +48,7 @@ class KitState {
const std::vector<std::unique_ptr<PercussionState>>& percussions() const;

protected:
void parsePercussions(const rapidjson::Value &percussionsArray);
bool parsePercussions(const rapidjson::Value &percussionsArray);

private:
std::vector<std::unique_ptr<PercussionState>> percussionsList;
Expand Down
7 changes: 4 additions & 3 deletions src/percussion_state.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,10 @@ bool PercussionState::loadData(const std::string &data)
return true;
}

void PercussionState::loadObject(const rapidjson::Value &obj)
bool PercussionState::loadObject(const rapidjson::Value &obj)
{
if (!obj.IsObject())
return;
return false;

bool kickParsed = false;
for (const auto &m: obj.GetObject()) {
Expand All @@ -110,7 +110,7 @@ void PercussionState::loadObject(const rapidjson::Value &obj)
}

if (!kickParsed)
return;
return false;

for (const auto &m: obj.GetObject()) {
for (decltype(layers.size()) i = 0; i < layers.size(); i++) {
Expand All @@ -127,6 +127,7 @@ void PercussionState::loadObject(const rapidjson::Value &obj)
}
}
}
return true;
}

size_t PercussionState::getId() const
Expand Down
2 changes: 1 addition & 1 deletion src/percussion_state.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class PercussionState
PercussionState();
bool loadFile(const std::string &file);
bool loadData(const std::string &data);
void loadObject(const rapidjson::Value &obj);
bool loadObject(const rapidjson::Value &obj);
size_t getId() const;
void setId(size_t id);
void setChannel(size_t channel);
Expand Down

0 comments on commit adb83eb

Please sign in to comment.