-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVirtualAudioDevice_Linux.h
More file actions
60 lines (46 loc) · 1.72 KB
/
VirtualAudioDevice_Linux.h
File metadata and controls
60 lines (46 loc) · 1.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#pragma once
#include <JuceHeader.h>
#include <jack/jack.h>
#include <memory>
#include <atomic>
//==============================================================================
class VirtualAudioDevice_Linux
{
public:
VirtualAudioDevice_Linux();
~VirtualAudioDevice_Linux();
bool initialize(const juce::String& deviceName);
void shutdown();
bool isAvailable() const { return jackClient != nullptr; }
bool isActive() const { return active.load(); }
void setActive(bool shouldBeActive);
void processAudioBlock(const juce::AudioBuffer<float>& buffer, int startSample, int numSamples);
// JACK callbacks
static int jackProcessCallback(jack_nframes_t nframes, void* arg);
static void jackShutdownCallback(void* arg);
static int jackSampleRateCallback(jack_nframes_t nframes, void* arg);
static int jackBufferSizeCallback(jack_nframes_t nframes, void* arg);
private:
// JACK client and ports
jack_client_t* jackClient = nullptr;
jack_port_t* inputPort = nullptr;
jack_port_t* outputPort = nullptr;
// Audio buffer for inter-thread communication
juce::AudioBuffer<float> audioBuffer;
juce::AbstractFifo audioFifo;
std::unique_ptr<float[]> fifoBuffer;
// State
std::atomic<bool> active{false};
std::atomic<bool> initialized{false};
// Audio parameters
int sampleRate = 44100;
int bufferSize = 512;
// Thread safety
juce::CriticalSection bufferLock;
// Helper methods
bool createJackClient(const juce::String& clientName);
bool createJackPorts();
bool activateJackClient();
void deactivateJackClient();
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(VirtualAudioDevice_Linux)
};