fix: apply format

This commit is contained in:
2023-09-05 03:15:08 +04:00
parent 564955c911
commit de31b73673
11 changed files with 77 additions and 88 deletions

View File

@@ -1,7 +1,7 @@
#pragma once
#include "Effect.h"
#include <cstddef>
#include "Ramp.h"
#include <cstddef>
struct ADSRParameters {
float attack_time; // Attack time in seconds
@@ -23,6 +23,7 @@ class ADSR : public Effect {
bool is_decay_elapsed();
bool is_release_elapsed();
void recheck_state();
public:
ADSR(/* args */);
ADSR(ADSRParameters param);

View File

@@ -6,10 +6,10 @@
#include <vector>
struct Adder {
static void
SumOscillators(const std::vector<Oscillator*>& oscillators,
static void SumOscillators(const std::vector<Oscillator*>& oscillators,
std::vector<float>& signal) {
size_t sample_count = STREAM_BUFFER_SIZE;//(size_t)(1.f/FPS * SAMPLE_RATE);
size_t sample_count =
STREAM_BUFFER_SIZE; //(size_t)(1.f/FPS * SAMPLE_RATE);
// std::vector<float>* output = new std::vector<float>();
// output->reserve(sample_count);

View File

@@ -1,12 +1,12 @@
#pragma once
class Ramp
{
class Ramp {
private:
float m_level;
float m_sample_rate;
float m_increment;
int m_counter;
public:
Ramp(float starting_level, float sample_rate);
~Ramp();
@@ -14,4 +14,3 @@ public:
float Process();
bool IsCompleted();
};

View File

@@ -1,6 +1,6 @@
#include "ADSR.h"
#include "Settings.h"
#include "Logger.h"
#include "Settings.h"
ADSR::ADSR(/* args */) {
m_parameters.attack_time = 1.f;
@@ -10,13 +10,9 @@ ADSR::ADSR(/* args */) {
m_ramp = new Ramp(0, SAMPLE_RATE);
}
ADSR::ADSR(ADSRParameters param) {
m_parameters = param;
}
ADSR::ADSR(ADSRParameters param) { m_parameters = param; }
ADSR::~ADSR() {
delete m_ramp;
}
ADSR::~ADSR() { delete m_ramp; }
bool ADSR::is_attack_elapsed() {
return m_state == Attack && m_ramp->IsCompleted();
@@ -31,12 +27,12 @@ bool ADSR::is_release_elapsed() {
}
void ADSR::recheck_state() {
switch (m_state)
{
switch (m_state) {
case Attack:
if (is_attack_elapsed()) {
m_state = Decay;
m_ramp->RampTo(m_parameters.sustain_level, m_parameters.decay_time);
m_ramp->RampTo(m_parameters.sustain_level,
m_parameters.decay_time);
}
break;
case Decay:
@@ -57,17 +53,13 @@ void ADSR::recheck_state() {
void ADSR::process_sample(float* sample) {
if (m_state == Off) {
(*sample) = 0;
}
else if (m_state == Attack) {
} else if (m_state == Attack) {
(*sample) = (*sample) * m_ramp->Process();
}
else if (m_state == Decay) {
} else if (m_state == Decay) {
(*sample) = (*sample) * m_ramp->Process();
}
else if (m_state == Sustain) {
} else if (m_state == Sustain) {
(*sample) = (*sample) * m_parameters.sustain_level;
}
else if (m_state == Release) {
} else if (m_state == Release) {
(*sample) = (*sample) * m_ramp->Process();
}
}
@@ -76,8 +68,7 @@ void ADSR::OnSetNote() {
write_log("Set ADSR\n");
if (m_state == Off) {
m_state = Attack;
}
else if (m_state == Release) {
} else if (m_state == Release) {
m_state = Attack;
};

View File

@@ -86,9 +86,9 @@ bool Application::detect_note_pressed(Note* note) {
}
bool is_note_up() {
return IsKeyReleased(KEY_A) || IsKeyReleased(KEY_B) || IsKeyReleased(KEY_C)
|| IsKeyReleased(KEY_D) || IsKeyReleased(KEY_E) || IsKeyReleased(KEY_F)
|| IsKeyReleased(KEY_G);
return IsKeyReleased(KEY_A) || IsKeyReleased(KEY_B) ||
IsKeyReleased(KEY_C) || IsKeyReleased(KEY_D) ||
IsKeyReleased(KEY_E) || IsKeyReleased(KEY_F) || IsKeyReleased(KEY_G);
}
// Update On Input
@@ -101,8 +101,7 @@ void Application::update_on_note_input() {
// m_sound_played_count = 0;
write_log("Note played: %s\n", m_current_note->name.c_str());
}
else if (is_note_up() && m_synth.GetIsNoteTriggered()) {
} else if (is_note_up() && m_synth.GetIsNoteTriggered()) {
m_synth.StopSound();
}
// will produce 0 signal if ADSR is in off state
@@ -114,9 +113,12 @@ void Application::play_buffered_audio() {
if (IsAudioStreamProcessed(m_synth_stream)) {
// const float audio_frame_start_time = GetTime();
update_on_note_input();
UpdateAudioStream(m_synth_stream, m_synth.GetOutSignal().data(), STREAM_BUFFER_SIZE);
//const float audio_freme_duration = GetTime() - audio_frame_start_time;
//write_log("Frame time: %.3f%% \n", 100.0f / ((1.0f / audio_freme_duration) / ((float)SAMPLE_RATE/STREAM_BUFFER_SIZE)));
UpdateAudioStream(m_synth_stream, m_synth.GetOutSignal().data(),
STREAM_BUFFER_SIZE);
// const float audio_freme_duration = GetTime() -
// audio_frame_start_time; write_log("Frame time: %.3f%% \n", 100.0f /
// ((1.0f / audio_freme_duration) /
// ((float)SAMPLE_RATE/STREAM_BUFFER_SIZE)));
}
}

View File

@@ -6,13 +6,13 @@ Ramp::Ramp(float starting_level, float sample_rate) {
m_sample_rate = sample_rate;
}
Ramp::~Ramp() {
}
Ramp::~Ramp() {}
void Ramp::RampTo(float val, float time) {
m_increment = (val - m_level) / (m_sample_rate * time);
m_counter = (int)(m_sample_rate * time);
write_log("Ramping from: %.1f to: %.1f by: %lf for: %d\n", m_level, val, m_increment, m_counter);
write_log("Ramping from: %.1f to: %.1f by: %lf for: %d\n", m_level, val,
m_increment, m_counter);
}
float Ramp::Process() {
@@ -24,6 +24,4 @@ float Ramp::Process() {
return m_level;
}
bool Ramp::IsCompleted() {
return m_counter == 0;
}
bool Ramp::IsCompleted() { return m_counter == 0; }

View File

@@ -10,7 +10,6 @@
#include "raygui.h"
#pragma clang diagnostic pop
Renderer::Renderer(/* args */) {
InitWindow(WINDOW_WIDTH, WINDOW_HEIGHT, "SeeSynth - v0.2");
SetTargetFPS(FPS);
@@ -129,8 +128,7 @@ void Renderer::draw_oscillators_panels(
delete_button_rect.y -= el_rect.height + el_spacing;
delete_button_rect.width = 30;
bool is_delete_button_pressed = GuiButton(delete_button_rect, "X");
if (is_delete_button_pressed)
{
if (is_delete_button_pressed) {
// memmove(
// synth->ui_oscillator + ui_osc_i,
// synth->ui_oscillator + ui_osc_i + 1,
@@ -139,7 +137,6 @@ void Renderer::draw_oscillators_panels(
// );
// synth->ui_oscillator_count -= 1;
}
}
}
@@ -149,7 +146,8 @@ void Renderer::draw_main_panel(const Rectangle& panel_bounds) {
GuiPanel(panel_bounds, "");
}
void Renderer::draw_add_oscillator_button(Synth& synth, SynthGuiState& synth_gui,
void Renderer::draw_add_oscillator_button(Synth& synth,
SynthGuiState& synth_gui,
Rectangle panel_bounds) {
//clang-format off
bool click_add_oscillator =

View File

@@ -1,9 +1,9 @@
#include "Synth.h"
#include "ADSR.h"
#include "KeyBoard.h"
#include "Logger.h"
#include "OscillatorType.h"
#include "Settings.h"
#include "Logger.h"
Synth::Synth(/* args */) {
AddOscillator();