Debian Codegraph @

src/engine/platform/pcspkr.h

raw
1 /**
2 * Furnace Tracker - multi-system chiptune tracker
3 * Copyright (C) 2021-2025 tildearrow and contributors
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
19
20 #ifndef _PCSPKR_H
21 #define _PCSPKR_H
22
23 #include "../dispatch.h"
24 #include "../../fixedQueue.h"
25 #include <thread>
26 #include <condition_variable>
27
28 class DivPlatformPCSpeaker: public DivDispatch {
29 struct Channel: public SharedChannel<signed char> {
30 Channel():
31 SharedChannel<signed char>(15) {}
32 };
33 Channel chan[1];
34 DivDispatchOscBuffer* oscBuf;
35 std::thread* realOutThread;
36 std::mutex realOutSelfLock;
37 std::condition_variable realOutCond;
38 bool realOutQuit;
39 struct RealQueueVal {
40 int tv_sec, tv_nsec;
41 unsigned short val;
42 RealQueueVal():
43 tv_sec(0),
44 tv_nsec(0),
45 val(0) {}
46 RealQueueVal(int sec, int nsec, unsigned short v):
47 tv_sec(sec),
48 tv_nsec(nsec),
49 val(v) {}
50 };
51 FixedQueue<RealQueueVal,2048> realQueue;
52 std::mutex realQueueLock;
53 bool isMuted[1];
54 bool on, flip, lastOn, realOutEnabled, resetPhase, posToggle;
55 int pos, oldOut, speakerType, beepFD, realOutMethod;
56 float low, band;
57 float low2, high2, band2;
58 float low3, band3;
59 float cut;
60 float reso;
61
62 unsigned short freq, lastFreq;
63 unsigned char regPool[2];
64
65 friend void putDispatchChip(void*,int);
66 friend void putDispatchChan(void*,int,int);
67
68 void beepFreq(int freq, int delay=0);
69
70 void acquire_unfilt(blip_buffer_t** bb, size_t len);
71 void acquire_cone(short** buf, size_t len);
72 void acquire_piezo(short** buf, size_t len);
73 void acquire_real(blip_buffer_t** bb, size_t len);
74
75 public:
76 void pcSpeakerThread();
77 void acquireDirect(blip_buffer_t** bb, size_t len);
78 void acquire(short** buf, size_t len);
79 int dispatch(DivCommand c);
80 void* getChanState(int chan);
81 DivMacroInt* getChanMacroInt(int ch);
82 DivDispatchOscBuffer* getOscBuffer(int chan);
83 unsigned char* getRegisterPool();
84 int getRegisterPoolSize();
85 void reset();
86 void forceIns();
87 void tick(bool sysTick=true);
88 void muteChannel(int ch, bool mute);
89 bool keyOffAffectsArp(int ch);
90 bool hasAcquireDirect();
91 void setFlags(const DivConfig& flags);
92 void notifyInsDeletion(void* ins);
93 void notifyPlaybackStop();
94 void poke(unsigned int addr, unsigned short val);
95 void poke(std::vector<DivRegWrite>& wlist);
96 const char** getRegisterSheet();
97 int init(DivEngine* parent, int channels, int sugRate, const DivConfig& flags);
98 void quit();
99 ~DivPlatformPCSpeaker();
100 };
101
102 #endif