Zrythm v2.0.0-DEV
a highly automated and intuitive digital audio workstation
Loading...
Searching...
No Matches
rtaudio_device.h
1/*
2 * SPDX-FileCopyrightText: © 2020 Alexandros Theodotou <alex@zrythm.org>
3 *
4 * SPDX-License-Identifier: LicenseRef-ZrythmLicense
5 */
6
7#ifndef __AUDIO_RTAUDIO_DEVICE_H__
8#define __AUDIO_RTAUDIO_DEVICE_H__
9
10#include "zrythm-config.h"
11
12#include <array>
13#include <string>
14
15#include "utils/ring_buffer.h"
16
17#if HAVE_RTAUDIO
18
19constexpr int RTAUDIO_DEVICE_BUFFER_SIZE = 32000;
20
21# include <semaphore>
22
23# include <rtaudio_c.h>
24# include <stdint.h>
25
26class AudioPort;
27
33
38enum RtAudioDeviceFlow
39{
40 RTAUDIO_DEVICE_FLOW_OUTPUT,
41 RTAUDIO_DEVICE_FLOW_INPUT,
42};
43
47class RtAudioDevice
48{
49public:
60 RtAudioDevice (
61 bool is_input,
62 unsigned int device_id,
63 unsigned int channel_idx,
64 std::string device_name = "");
65
66 ~RtAudioDevice ()
67 {
68 if (opened_)
69 {
70 close ();
71 }
72 }
73
81 void open (bool start);
82
86 void close ();
87
93 void start ();
94
100 void stop ();
101
102 static void print_dev_info (const rtaudio_device_info_t &nfo);
103
104public:
105 bool is_input_ = false;
106
108 unsigned int channel_idx_ = 0;
109
111 unsigned int id_ = 0;
112
113 std::string name_;
114
116 bool opened_ = false;
117
119 bool started_ = false;
120
121 rtaudio_t handle_ = nullptr;
122
126 std::array<float, 0x4000> audio_buf_{};
127
129 RingBuffer<float> audio_ring_{ RTAUDIO_DEVICE_BUFFER_SIZE };
130
133 std::binary_semaphore audio_ring_sem_{ 1 };
134};
135
139
140#endif // HAVE_RTAUDIO
141#endif
Audio port specifics.
Definition audio_port.h:23