wip: play notes only on press
This commit is contained in:
16
inc/Adder.h
16
inc/Adder.h
@@ -6,23 +6,21 @@
|
||||
#include <vector>
|
||||
|
||||
struct Adder {
|
||||
static std::vector<float>&
|
||||
static void
|
||||
SumOscillators(const std::vector<Oscillator*>& oscillators,
|
||||
float duration) {
|
||||
size_t sample_count = (size_t)(1.f/FPS * SAMPLE_RATE);
|
||||
std::vector<float>& signal) {
|
||||
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);
|
||||
//std::vector<float>* output = new std::vector<float>();
|
||||
//output->reserve(sample_count);
|
||||
|
||||
for (size_t i = 0; i < sample_count; i++) {
|
||||
float sample = 0.0f;
|
||||
for (Oscillator* osc : oscillators) {
|
||||
sample += osc->GenerateSample(duration);
|
||||
sample += osc->GenerateSample(1.f);
|
||||
}
|
||||
|
||||
output->push_back(sample);
|
||||
signal[i] = sample;
|
||||
}
|
||||
|
||||
return (*output);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -16,7 +16,7 @@ class Application {
|
||||
float* m_temp_buffer;
|
||||
Note* m_current_note;
|
||||
Renderer m_renderer;
|
||||
std::size_t detect_note_pressed(Note* note);
|
||||
bool detect_note_pressed(Note* note);
|
||||
void init_synth();
|
||||
void init_audio();
|
||||
void update_on_note_input();
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#define SAMPLE_RATE 48000.f
|
||||
#define SAMPLE_RATE 44100.f
|
||||
#define BPM 120.f
|
||||
#define BEAT_DURATION 60.f/BPM
|
||||
#define PITCH_STANDARD 440.f
|
||||
|
||||
@@ -15,13 +15,14 @@ class Synth {
|
||||
// OscillatorUI* ui_oscillators;
|
||||
// Note m_current_note;
|
||||
std::vector<float> m_out_signal;
|
||||
std::vector<float>& get_note(int semitone, float beats);
|
||||
void get_note(int semitone, float beats);
|
||||
void apply_effects();
|
||||
|
||||
public:
|
||||
Synth(/* args */);
|
||||
~Synth();
|
||||
void ProduceNoteSound(Note input);
|
||||
void StopNoteSound();
|
||||
void AddOscillator();
|
||||
void AddEffect(Effect* fx);
|
||||
const std::vector<float>& GetOutSignal() { return m_out_signal; }
|
||||
|
||||
Reference in New Issue
Block a user