atomic
This commit is contained in:
@@ -0,0 +1,10 @@
|
||||
#ifndef COMMAND
|
||||
#define COMMAND
|
||||
|
||||
enum class Command{
|
||||
None,
|
||||
NoteOn,
|
||||
NoteOff
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,29 @@
|
||||
#ifndef SPSC_QUEUE
|
||||
#define SPSC_QUEUE
|
||||
|
||||
#include <atomic>
|
||||
#include <array>
|
||||
#include <cstddef>
|
||||
|
||||
#include "../include/command.hpp"
|
||||
|
||||
class SpscQueue{
|
||||
|
||||
public:
|
||||
SpscQueue(){
|
||||
head.store(0, std::memory_order_relaxed);
|
||||
tail.store(0, std::memory_order_relaxed);
|
||||
buffer.fill(Command::None);
|
||||
}
|
||||
|
||||
bool push(Command command);
|
||||
bool pop(Command& command);
|
||||
|
||||
|
||||
private:
|
||||
std::array<Command, 64> buffer;
|
||||
std::atomic<std::size_t> head;
|
||||
std::atomic<std::size_t> tail;
|
||||
};
|
||||
|
||||
#endif
|
||||
+7
-2
@@ -4,7 +4,11 @@
|
||||
#include <cstdint>
|
||||
#include <numbers>
|
||||
#include <cmath>
|
||||
#include <atomic>
|
||||
|
||||
#include "../include/envelope.hpp"
|
||||
#include "../include/spsc_queue.hpp"
|
||||
#include "../include/command.hpp"
|
||||
|
||||
class Synth {
|
||||
public:
|
||||
@@ -21,8 +25,8 @@ class Synth {
|
||||
void set_frequency(double value);
|
||||
void set_amplitude(double value);
|
||||
|
||||
void note_on();
|
||||
void note_off();
|
||||
bool note_on();
|
||||
bool note_off();
|
||||
|
||||
private:
|
||||
/* 1. частота звука в Герцах
|
||||
@@ -31,6 +35,7 @@ class Synth {
|
||||
4. фаза. от 0 до 2 пи*/
|
||||
|
||||
Envelope envelope;
|
||||
SpscQueue queue;
|
||||
|
||||
double frequency;
|
||||
double amplitude;
|
||||
|
||||
Reference in New Issue
Block a user