2026-11-12 16:34:18 +06:00
|
|
|
#include <iostream>
|
2026-11-12 20:19:00 +06:00
|
|
|
#include <stdexcept>
|
2026-11-13 18:31:07 +06:00
|
|
|
#include <thread>
|
|
|
|
|
#include <atomic>
|
2026-11-12 16:34:18 +06:00
|
|
|
|
|
|
|
|
#include "../include/synth.hpp"
|
2026-11-12 20:19:00 +06:00
|
|
|
#include "../include/audio_engine.hpp"
|
2026-11-13 18:31:07 +06:00
|
|
|
#include "../include/spsc_queue.hpp"
|
|
|
|
|
#include "../include/command.hpp"
|
2026-11-12 16:34:18 +06:00
|
|
|
|
2026-11-13 18:31:07 +06:00
|
|
|
void producer(SpscQueue& queue, std::atomic<bool>& producer_done){
|
|
|
|
|
/*
|
|
|
|
|
* формирует последовательность команд;
|
|
|
|
|
записывает их через queue.push();
|
|
|
|
|
повторяет попытку, если очередь заполнена;
|
|
|
|
|
после успешной отправки последней команды устанавливает producer_done = true.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void consumer(SpscQueue& queue, std::atomic<bool>& producer_done){
|
|
|
|
|
|
|
|
|
|
}
|
2026-11-13 02:02:50 +06:00
|
|
|
|
2026-11-12 16:34:18 +06:00
|
|
|
int main(){
|
|
|
|
|
|
2026-11-12 20:19:00 +06:00
|
|
|
std::cout << "110.гц\n";
|
2026-11-12 20:58:48 +06:00
|
|
|
std::string a = "";
|
2026-11-12 16:34:18 +06:00
|
|
|
Synth synth;
|
2026-11-13 18:31:07 +06:00
|
|
|
SpscQueue queue;
|
2026-11-12 16:34:18 +06:00
|
|
|
|
2026-11-13 18:31:07 +06:00
|
|
|
std::atomic<bool> producer_done;
|
2026-11-12 16:34:18 +06:00
|
|
|
|
2026-11-13 18:31:07 +06:00
|
|
|
// std::thread producer();
|
|
|
|
|
// std::thread consumer();
|
|
|
|
|
|
|
|
|
|
synth.set_frequency(110);
|
|
|
|
|
synth.set_amplitude(0.5);
|
2026-11-12 16:34:18 +06:00
|
|
|
|
2026-11-12 20:19:00 +06:00
|
|
|
try{
|
|
|
|
|
AudioEngine audio_engine(synth);
|
2026-11-13 02:02:50 +06:00
|
|
|
audio_engine.start();
|
2026-11-12 20:58:48 +06:00
|
|
|
while (true){
|
2026-11-13 18:31:07 +06:00
|
|
|
std::cout << std::boolalpha
|
|
|
|
|
<< "Lock-free: " << std::atomic<Command>{}.is_lock_free()
|
|
|
|
|
<< '\n';
|
2026-11-12 20:58:48 +06:00
|
|
|
std::cin >> a;
|
|
|
|
|
if (a == "start"){
|
2026-11-13 02:02:50 +06:00
|
|
|
synth.note_on();
|
2026-11-12 20:58:48 +06:00
|
|
|
}
|
2026-11-13 02:02:50 +06:00
|
|
|
else synth.note_off();
|
2026-11-12 20:58:48 +06:00
|
|
|
}
|
2026-11-13 02:02:50 +06:00
|
|
|
// audio_engine.stop();
|
2026-11-12 20:19:00 +06:00
|
|
|
}
|
|
|
|
|
catch (const std::exception& error){
|
|
|
|
|
std::cerr << error.what() << "\n";
|
|
|
|
|
return 1;
|
2026-11-12 16:34:18 +06:00
|
|
|
}
|
|
|
|
|
|
2026-11-12 20:19:00 +06:00
|
|
|
|
2026-11-12 16:34:18 +06:00
|
|
|
return 0;
|
|
|
|
|
}
|