fix: apply format
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include "Effect.h"
|
#include "Effect.h"
|
||||||
#include <cstddef>
|
|
||||||
#include "Ramp.h"
|
#include "Ramp.h"
|
||||||
|
#include <cstddef>
|
||||||
|
|
||||||
struct ADSRParameters {
|
struct ADSRParameters {
|
||||||
float attack_time; // Attack time in seconds
|
float attack_time; // Attack time in seconds
|
||||||
@@ -16,20 +16,21 @@ class ADSR : public Effect {
|
|||||||
private:
|
private:
|
||||||
ADSRParameters m_parameters;
|
ADSRParameters m_parameters;
|
||||||
ADSRState m_state;
|
ADSRState m_state;
|
||||||
Ramp *m_ramp;
|
Ramp* m_ramp;
|
||||||
|
|
||||||
void process_sample(float* sample);
|
void process_sample(float* sample);
|
||||||
bool is_attack_elapsed();
|
bool is_attack_elapsed();
|
||||||
bool is_decay_elapsed();
|
bool is_decay_elapsed();
|
||||||
bool is_release_elapsed();
|
bool is_release_elapsed();
|
||||||
void recheck_state();
|
void recheck_state();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
ADSR(/* args */);
|
ADSR(/* args */);
|
||||||
ADSR(ADSRParameters param);
|
ADSR(ADSRParameters param);
|
||||||
~ADSR();
|
~ADSR();
|
||||||
void OnSetNote() override;
|
void OnSetNote() override;
|
||||||
void OnUnsetNote() override;
|
void OnUnsetNote() override;
|
||||||
//void RetriggerState() override;
|
// void RetriggerState() override;
|
||||||
void Process(std::vector<float>& samples) override;
|
void Process(std::vector<float>& samples) override;
|
||||||
void Reset();
|
void Reset();
|
||||||
};
|
};
|
||||||
|
|||||||
10
inc/Adder.h
10
inc/Adder.h
@@ -6,13 +6,13 @@
|
|||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
struct Adder {
|
struct Adder {
|
||||||
static void
|
static void SumOscillators(const std::vector<Oscillator*>& oscillators,
|
||||||
SumOscillators(const std::vector<Oscillator*>& oscillators,
|
|
||||||
std::vector<float>& signal) {
|
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>();
|
// std::vector<float>* output = new std::vector<float>();
|
||||||
//output->reserve(sample_count);
|
// output->reserve(sample_count);
|
||||||
|
|
||||||
for (size_t i = 0; i < sample_count; i++) {
|
for (size_t i = 0; i < sample_count; i++) {
|
||||||
float sample = 0.0f;
|
float sample = 0.0f;
|
||||||
|
|||||||
@@ -8,6 +8,6 @@ class Effect {
|
|||||||
~Effect(){};
|
~Effect(){};
|
||||||
virtual void OnSetNote(){};
|
virtual void OnSetNote(){};
|
||||||
virtual void OnUnsetNote(){};
|
virtual void OnUnsetNote(){};
|
||||||
//virtual void RetriggerState(){};
|
// virtual void RetriggerState(){};
|
||||||
virtual void Process(std::vector<float>& samples){};
|
virtual void Process(std::vector<float>& samples){};
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,17 +1,16 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
class Ramp
|
class Ramp {
|
||||||
{
|
private:
|
||||||
private:
|
|
||||||
float m_level;
|
float m_level;
|
||||||
float m_sample_rate;
|
float m_sample_rate;
|
||||||
float m_increment;
|
float m_increment;
|
||||||
int m_counter;
|
int m_counter;
|
||||||
public:
|
|
||||||
|
public:
|
||||||
Ramp(float starting_level, float sample_rate);
|
Ramp(float starting_level, float sample_rate);
|
||||||
~Ramp();
|
~Ramp();
|
||||||
void RampTo(float value, float time);
|
void RampTo(float value, float time);
|
||||||
float Process();
|
float Process();
|
||||||
bool IsCompleted();
|
bool IsCompleted();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
#define SAMPLE_RATE 44100.f
|
#define SAMPLE_RATE 44100.f
|
||||||
#define BPM 120.f
|
#define BPM 120.f
|
||||||
#define BEAT_DURATION 60.f/BPM
|
#define BEAT_DURATION 60.f / BPM
|
||||||
#define PITCH_STANDARD 440.f
|
#define PITCH_STANDARD 440.f
|
||||||
#define VOLUME 0.5f
|
#define VOLUME 0.5f
|
||||||
#define ATTACK_MS 100.f
|
#define ATTACK_MS 100.f
|
||||||
|
|||||||
31
src/ADSR.cpp
31
src/ADSR.cpp
@@ -1,6 +1,6 @@
|
|||||||
#include "ADSR.h"
|
#include "ADSR.h"
|
||||||
#include "Settings.h"
|
|
||||||
#include "Logger.h"
|
#include "Logger.h"
|
||||||
|
#include "Settings.h"
|
||||||
|
|
||||||
ADSR::ADSR(/* args */) {
|
ADSR::ADSR(/* args */) {
|
||||||
m_parameters.attack_time = 1.f;
|
m_parameters.attack_time = 1.f;
|
||||||
@@ -10,13 +10,9 @@ ADSR::ADSR(/* args */) {
|
|||||||
m_ramp = new Ramp(0, SAMPLE_RATE);
|
m_ramp = new Ramp(0, SAMPLE_RATE);
|
||||||
}
|
}
|
||||||
|
|
||||||
ADSR::ADSR(ADSRParameters param) {
|
ADSR::ADSR(ADSRParameters param) { m_parameters = param; }
|
||||||
m_parameters = param;
|
|
||||||
}
|
|
||||||
|
|
||||||
ADSR::~ADSR() {
|
ADSR::~ADSR() { delete m_ramp; }
|
||||||
delete m_ramp;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool ADSR::is_attack_elapsed() {
|
bool ADSR::is_attack_elapsed() {
|
||||||
return m_state == Attack && m_ramp->IsCompleted();
|
return m_state == Attack && m_ramp->IsCompleted();
|
||||||
@@ -31,12 +27,12 @@ bool ADSR::is_release_elapsed() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void ADSR::recheck_state() {
|
void ADSR::recheck_state() {
|
||||||
switch (m_state)
|
switch (m_state) {
|
||||||
{
|
|
||||||
case Attack:
|
case Attack:
|
||||||
if (is_attack_elapsed()) {
|
if (is_attack_elapsed()) {
|
||||||
m_state = Decay;
|
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;
|
break;
|
||||||
case Decay:
|
case Decay:
|
||||||
@@ -57,17 +53,13 @@ void ADSR::recheck_state() {
|
|||||||
void ADSR::process_sample(float* sample) {
|
void ADSR::process_sample(float* sample) {
|
||||||
if (m_state == Off) {
|
if (m_state == Off) {
|
||||||
(*sample) = 0;
|
(*sample) = 0;
|
||||||
}
|
} else if (m_state == Attack) {
|
||||||
else if (m_state == Attack) {
|
|
||||||
(*sample) = (*sample) * m_ramp->Process();
|
(*sample) = (*sample) * m_ramp->Process();
|
||||||
}
|
} else if (m_state == Decay) {
|
||||||
else if (m_state == Decay) {
|
|
||||||
(*sample) = (*sample) * m_ramp->Process();
|
(*sample) = (*sample) * m_ramp->Process();
|
||||||
}
|
} else if (m_state == Sustain) {
|
||||||
else if (m_state == Sustain) {
|
|
||||||
(*sample) = (*sample) * m_parameters.sustain_level;
|
(*sample) = (*sample) * m_parameters.sustain_level;
|
||||||
}
|
} else if (m_state == Release) {
|
||||||
else if (m_state == Release) {
|
|
||||||
(*sample) = (*sample) * m_ramp->Process();
|
(*sample) = (*sample) * m_ramp->Process();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -76,8 +68,7 @@ void ADSR::OnSetNote() {
|
|||||||
write_log("Set ADSR\n");
|
write_log("Set ADSR\n");
|
||||||
if (m_state == Off) {
|
if (m_state == Off) {
|
||||||
m_state = Attack;
|
m_state = Attack;
|
||||||
}
|
} else if (m_state == Release) {
|
||||||
else if (m_state == Release) {
|
|
||||||
m_state = Attack;
|
m_state = Attack;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -86,23 +86,22 @@ bool Application::detect_note_pressed(Note* note) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool is_note_up() {
|
bool is_note_up() {
|
||||||
return IsKeyReleased(KEY_A) || IsKeyReleased(KEY_B) || IsKeyReleased(KEY_C)
|
return IsKeyReleased(KEY_A) || IsKeyReleased(KEY_B) ||
|
||||||
|| IsKeyReleased(KEY_D) || IsKeyReleased(KEY_E) || IsKeyReleased(KEY_F)
|
IsKeyReleased(KEY_C) || IsKeyReleased(KEY_D) ||
|
||||||
|| IsKeyReleased(KEY_G);
|
IsKeyReleased(KEY_E) || IsKeyReleased(KEY_F) || IsKeyReleased(KEY_G);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update On Input
|
// Update On Input
|
||||||
void Application::update_on_note_input() {
|
void Application::update_on_note_input() {
|
||||||
if (detect_note_pressed(m_current_note)) {
|
if (detect_note_pressed(m_current_note)) {
|
||||||
|
|
||||||
if (!m_synth.GetIsNoteTriggered()){
|
if (!m_synth.GetIsNoteTriggered()) {
|
||||||
m_synth.TriggerNote((*m_current_note));
|
m_synth.TriggerNote((*m_current_note));
|
||||||
}
|
}
|
||||||
|
|
||||||
//m_sound_played_count = 0;
|
// m_sound_played_count = 0;
|
||||||
write_log("Note played: %s\n", m_current_note->name.c_str());
|
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();
|
m_synth.StopSound();
|
||||||
}
|
}
|
||||||
// will produce 0 signal if ADSR is in off state
|
// will produce 0 signal if ADSR is in off state
|
||||||
@@ -112,11 +111,14 @@ void Application::update_on_note_input() {
|
|||||||
// Play ring-buffered audio
|
// Play ring-buffered audio
|
||||||
void Application::play_buffered_audio() {
|
void Application::play_buffered_audio() {
|
||||||
if (IsAudioStreamProcessed(m_synth_stream)) {
|
if (IsAudioStreamProcessed(m_synth_stream)) {
|
||||||
//const float audio_frame_start_time = GetTime();
|
// const float audio_frame_start_time = GetTime();
|
||||||
update_on_note_input();
|
update_on_note_input();
|
||||||
UpdateAudioStream(m_synth_stream, m_synth.GetOutSignal().data(), STREAM_BUFFER_SIZE);
|
UpdateAudioStream(m_synth_stream, m_synth.GetOutSignal().data(),
|
||||||
//const float audio_freme_duration = GetTime() - audio_frame_start_time;
|
STREAM_BUFFER_SIZE);
|
||||||
//write_log("Frame time: %.3f%% \n", 100.0f / ((1.0f / audio_freme_duration) / ((float)SAMPLE_RATE/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)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
10
src/Ramp.cpp
10
src/Ramp.cpp
@@ -6,13 +6,13 @@ Ramp::Ramp(float starting_level, float sample_rate) {
|
|||||||
m_sample_rate = sample_rate;
|
m_sample_rate = sample_rate;
|
||||||
}
|
}
|
||||||
|
|
||||||
Ramp::~Ramp() {
|
Ramp::~Ramp() {}
|
||||||
}
|
|
||||||
|
|
||||||
void Ramp::RampTo(float val, float time) {
|
void Ramp::RampTo(float val, float time) {
|
||||||
m_increment = (val - m_level) / (m_sample_rate * time);
|
m_increment = (val - m_level) / (m_sample_rate * time);
|
||||||
m_counter = (int)(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() {
|
float Ramp::Process() {
|
||||||
@@ -24,6 +24,4 @@ float Ramp::Process() {
|
|||||||
return m_level;
|
return m_level;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Ramp::IsCompleted() {
|
bool Ramp::IsCompleted() { return m_counter == 0; }
|
||||||
return m_counter == 0;
|
|
||||||
}
|
|
||||||
@@ -10,7 +10,6 @@
|
|||||||
#include "raygui.h"
|
#include "raygui.h"
|
||||||
#pragma clang diagnostic pop
|
#pragma clang diagnostic pop
|
||||||
|
|
||||||
|
|
||||||
Renderer::Renderer(/* args */) {
|
Renderer::Renderer(/* args */) {
|
||||||
InitWindow(WINDOW_WIDTH, WINDOW_HEIGHT, "SeeSynth - v0.2");
|
InitWindow(WINDOW_WIDTH, WINDOW_HEIGHT, "SeeSynth - v0.2");
|
||||||
SetTargetFPS(FPS);
|
SetTargetFPS(FPS);
|
||||||
@@ -129,8 +128,7 @@ void Renderer::draw_oscillators_panels(
|
|||||||
delete_button_rect.y -= el_rect.height + el_spacing;
|
delete_button_rect.y -= el_rect.height + el_spacing;
|
||||||
delete_button_rect.width = 30;
|
delete_button_rect.width = 30;
|
||||||
bool is_delete_button_pressed = GuiButton(delete_button_rect, "X");
|
bool is_delete_button_pressed = GuiButton(delete_button_rect, "X");
|
||||||
if (is_delete_button_pressed)
|
if (is_delete_button_pressed) {
|
||||||
{
|
|
||||||
// memmove(
|
// memmove(
|
||||||
// synth->ui_oscillator + ui_osc_i,
|
// synth->ui_oscillator + ui_osc_i,
|
||||||
// synth->ui_oscillator + ui_osc_i + 1,
|
// synth->ui_oscillator + ui_osc_i + 1,
|
||||||
@@ -139,7 +137,6 @@ void Renderer::draw_oscillators_panels(
|
|||||||
// );
|
// );
|
||||||
// synth->ui_oscillator_count -= 1;
|
// synth->ui_oscillator_count -= 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -149,7 +146,8 @@ void Renderer::draw_main_panel(const Rectangle& panel_bounds) {
|
|||||||
GuiPanel(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) {
|
Rectangle panel_bounds) {
|
||||||
//clang-format off
|
//clang-format off
|
||||||
bool click_add_oscillator =
|
bool click_add_oscillator =
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
#include "Synth.h"
|
#include "Synth.h"
|
||||||
#include "ADSR.h"
|
#include "ADSR.h"
|
||||||
#include "KeyBoard.h"
|
#include "KeyBoard.h"
|
||||||
|
#include "Logger.h"
|
||||||
#include "OscillatorType.h"
|
#include "OscillatorType.h"
|
||||||
#include "Settings.h"
|
#include "Settings.h"
|
||||||
#include "Logger.h"
|
|
||||||
|
|
||||||
Synth::Synth(/* args */) {
|
Synth::Synth(/* args */) {
|
||||||
AddOscillator();
|
AddOscillator();
|
||||||
|
|||||||
Reference in New Issue
Block a user