File: RtAudio52.patch

package info (click to toggle)
giada 1.4.0-2
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 3,532 kB
  • sloc: cpp: 30,620; sh: 144; xml: 66; makefile: 55; ansic: 1
file content (168 lines) | stat: -rw-r--r-- 5,721 bytes parent folder | download | duplicates (3)
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
From: =?utf-8?q?IOhannes_m_zm=C3=B6lnig?= <zmoelnig@iem.at>
Date: Fri, 17 Dec 2021 10:35:28 +0100
Subject: RtAudio-5.2.0 support

Upstream vendored in a RtAudio-6 git snapshot and called it 5.2.0
---
 src/core/kernelAudio.cpp | 107 ++++++++++++++++++++++++++---------------------
 1 file changed, 60 insertions(+), 47 deletions(-)

Index: giada/src/core/kernelAudio.cpp
===================================================================
--- giada.orig/src/core/kernelAudio.cpp
+++ giada/src/core/kernelAudio.cpp
@@ -95,10 +95,6 @@ int KernelAudio::openDevice(const Conf::
 		return 0;
 	}
 
-	m_rtAudio->setErrorCallback([](RtAudioErrorType type, const std::string& msg) {
-		u::log::print("[KA] RtAudio error %d: %s\n", type, msg.c_str());
-	});
-
 	u::log::print("[KA] Opening device out=%d, in=%d, samplerate=%d\n",
 	    conf.soundDeviceOut, conf.soundDeviceIn, conf.samplerate);
 
@@ -159,33 +155,33 @@ int KernelAudio::openDevice(const Conf::
 
 #endif
 
-	m_callbackInfo = {
-	    /* kernelAudio      = */ this,
-	    /* ready            = */ true,
-	    /* withJack         = */ getAPI() == G_SYS_API_JACK,
-	    /* outBuf           = */ nullptr, // filled later on in audio callback
-	    /* inBuf            = */ nullptr, // filled later on in audio callback
-	    /* bufferSize       = */ 0,       // filled later on in audio callback
-	    /* channelsOutCount = */ m_channelsOutCount,
-	    /* channelsInCount  = */ m_channelsInCount};
-
-	RtAudioErrorType res = m_rtAudio->openStream(
-	    &outParams,                                     // output params
-	    conf.soundDeviceIn != -1 ? &inParams : nullptr, // input params if inDevice is selected
-	    RTAUDIO_FLOAT32,                                // audio format
-	    m_realSampleRate,                               // sample rate
-	    &m_realBufferSize,                              // buffer size in byte
-	    &audioCallback,                                 // audio callback
-	    &m_callbackInfo,                                // user data passed to callback
-	    &options);
-
-	if (res == RtAudioErrorType::RTAUDIO_NO_ERROR)
+	try
 	{
+		m_callbackInfo = {
+		    /* kernelAudio      = */ this,
+		    /* ready            = */ true,
+		    /* withJack         = */ getAPI() == G_SYS_API_JACK,
+		    /* outBuf           = */ nullptr, // filled later on in audio callback
+		    /* inBuf            = */ nullptr, // filled later on in audio callback
+		    /* bufferSize       = */ 0,       // filled later on in audio callback
+		    /* channelsOutCount = */ m_channelsOutCount,
+		    /* channelsInCount  = */ m_channelsInCount};
+
+		m_rtAudio->openStream(
+		    &outParams,                                     // output params
+		    conf.soundDeviceIn != -1 ? &inParams : nullptr, // input params if inDevice is selected
+		    RTAUDIO_FLOAT32,                                // audio format
+		    m_realSampleRate,                               // sample rate
+		    &m_realBufferSize,                              // buffer size in byte
+		    &audioCallback,                                 // audio callback
+		    &m_callbackInfo,                                // user data passed to callback
+		    &options);
 		m_ready = true;
 		return 1;
 	}
-	else
+	catch (RtAudioError& e)
 	{
+		u::log::print("[KA] RtAudio init error: %s\n", e.getMessage());
 		closeDevice();
 		return 0;
 	}
@@ -195,24 +191,33 @@ int KernelAudio::openDevice(const Conf::
 
 int KernelAudio::startStream()
 {
-	if (m_rtAudio->startStream() == RtAudioErrorType::RTAUDIO_NO_ERROR)
+	try
 	{
-		u::log::print("[KA] Start stream - latency = %lu\n", m_rtAudio->getStreamLatency());
+		m_rtAudio->startStream();
+		u::log::print("[KA] latency = %lu\n", m_rtAudio->getStreamLatency());
 		return 1;
 	}
-	return 0;
+	catch (RtAudioError& e)
+	{
+		u::log::print("[KA] Start stream error: %s\n", e.getMessage());
+		return 0;
+	}
 }
 
 /* -------------------------------------------------------------------------- */
 
 int KernelAudio::stopStream()
 {
-	if (m_rtAudio->stopStream() == RtAudioErrorType::RTAUDIO_NO_ERROR)
+	try
 	{
-		u::log::print("[KA] Stop stream\n");
+		m_rtAudio->stopStream();
 		return 1;
 	}
-	return 0;
+	catch (RtAudioError& /*e*/)
+	{
+		u::log::print("[KA] Stop stream error\n");
+		return 0;
+	}
 }
 
 /* -------------------------------------------------------------------------- */
@@ -329,24 +334,32 @@ void KernelAudio::logCompiledAPIs()
 
 m::KernelAudio::Device KernelAudio::fetchDevice(size_t deviceIndex) const
 {
-	RtAudio::DeviceInfo info = m_rtAudio->getDeviceInfo(deviceIndex);
+	try
+	{
+		RtAudio::DeviceInfo info = m_rtAudio->getDeviceInfo(deviceIndex);
 
-	if (!info.probed)
+		if (!info.probed)
+		{
+			u::log::print("[KA] Can't probe device %d\n", deviceIndex);
+			return {deviceIndex};
+		}
+
+		return {
+		    deviceIndex,
+		    true,
+		    info.name,
+		    static_cast<int>(info.outputChannels),
+		    static_cast<int>(info.inputChannels),
+		    static_cast<int>(info.duplexChannels),
+		    info.isDefaultOutput,
+		    info.isDefaultInput,
+		    u::vector::cast<int>(info.sampleRates)};
+	}
+	catch (RtAudioError& e)
 	{
-		u::log::print("[KA] Can't probe device %d\n", deviceIndex);
-		return {deviceIndex};
+		u::log::print("[KA] Error fetching device %d: %s\n", deviceIndex, e.getMessage());
+		return {0};
 	}
-
-	return {
-	    deviceIndex,
-	    true,
-	    info.name,
-	    static_cast<int>(info.outputChannels),
-	    static_cast<int>(info.inputChannels),
-	    static_cast<int>(info.duplexChannels),
-	    info.isDefaultOutput,
-	    info.isDefaultInput,
-	    u::vector::cast<int>(info.sampleRates)};
 }
 
 /* -------------------------------------------------------------------------- */