grame-cncm / faust

Functional programming language for signal processing and sound synthesis
http://faust.grame.fr
Other
2.58k stars 322 forks source link

Current version of rtaudio doesn't use exceptions (fix included) #978

Closed shakfu closed 11 months ago

shakfu commented 11 months ago

I encountered some recent issues with the rtaudio driver faust/architectures/faust/audio/rtaudio-dsp.h since it uses exceptions whereas the current version does not.

The fix is quite basic: replace exceptions with the current system based on RtAudioErrorType. Please see below the diff for the fix (which is also attached):

diff --git a/architecture/faust/audio/rtaudio-dsp.h b/architecture/faust/audio/rtaudio-dsp.h
index a0788ed..1d8bc19 100644
--- a/architecture/faust/audio/rtaudio-dsp.h
+++ b/architecture/faust/audio/rtaudio-dsp.h
@@ -92,13 +92,12 @@ class rtaudio : public audio {
                 fDevNumInChans(0), fDevNumOutChans(0) {}

         virtual ~rtaudio() 
-        {   
-            try {
-                fAudioDAC.stopStream();
-                fAudioDAC.closeStream();
-            } catch (RtAudioError& e) {
-                std::cout << '\n' << e.getMessage() << '\n' << std::endl;
+        {
+            RtAudioErrorType err = fAudioDAC.stopStream();
+            if (err != RTAUDIO_NO_ERROR) {
+                std::cout << '\n' << fAudioDAC.getErrorText() << '\n' << std::endl;
             }
+            fAudioDAC.closeStream();
         }

         virtual bool init(const char* name, dsp* DSP)
@@ -134,16 +133,15 @@ class rtaudio : public audio {

             RtAudio::StreamOptions options;
             options.flags |= RTAUDIO_NONINTERLEAVED;
-         
-            try {
-                fAudioDAC.openStream(((numOutputs > 0) ? &oParams : NULL), 
-                    ((numInputs > 0) ? &iParams : NULL), FORMAT, 
-                    fSampleRate, &fBufferSize, audioCallback, this, &options);
-            } catch (RtAudioError& e) {
-                std::cout << '\n' << e.getMessage() << '\n' << std::endl;
+
+            RtAudioErrorType err = fAudioDAC.openStream(
+                ((numOutputs > 0) ? &oParams : NULL),
+                ((numInputs > 0) ? &iParams : NULL), FORMAT,
+                fSampleRate, &fBufferSize, audioCallback, this, &options);
+            if (err != RTAUDIO_NO_ERROR) {
+                std::cout << '\n' << fAudioDAC.getErrorText() << '\n' << std::endl;
                 return false;
             }
-               
             return true;
         }

@@ -163,10 +161,9 @@ class rtaudio : public audio {

         virtual bool start() 
         {
-            try {
-                fAudioDAC.startStream();
-            } catch (RtAudioError& e) {
-                std::cout << '\n' << e.getMessage() << '\n' << std::endl;
+            RtAudioErrorType err = fAudioDAC.startStream();
+            if (err != RTAUDIO_NO_ERROR) {
+                std::cout << '\n' << fAudioDAC.getErrorText() << '\n' << std::endl;
                 return false;
             }
             return true;
@@ -174,10 +171,9 @@ class rtaudio : public audio {

         virtual void stop() 
         {
-            try {
-                fAudioDAC.stopStream();
-            } catch (RtAudioError& e) {
-                std::cout << '\n' << e.getMessage() << '\n' << std::endl;
+            RtAudioErrorType err = fAudioDAC.stopStream();
+            if (err != RTAUDIO_NO_ERROR) {
+                std::cout << '\n' << fAudioDAC.getErrorText() << '\n' << std::endl;
             }
         }

rtaudio-dsp-fix.patch

rtaudio-dsp.h.zip

sletz commented 11 months ago

This looks good. Which minimal version of PortAudio is needed then ?

sletz commented 11 months ago

Can we maintain retro-compatible code ? working with old and newer model ?

shakfu commented 11 months ago

This looks good. Which minimal version of PortAudio is need

I think you mean RtAudio, well, I checked when the rtaudio noexception branch was merged into the main branch and it was in November 19 2021 and from this you can see that basically pre-merge the version was 0.5.2 and then the version went up to 6.0.0 with the merge when exceptions were removed.

shakfu commented 11 months ago

I will revisit this with a check for RTAUDIO_VERSION_MAJOR: 5 is with exceptions, 6 is without.

sletz commented 11 months ago

typo RtAudio tes, OK for testing RTAUDIO_VERSION_MAJOR. Then can you make a proper PR ? Thanks.

shakfu commented 11 months ago

Done: see PR-979