shithub: m8c

Download patch

ref: 07a11de1ed389f39805968965806e1fdeb4706df
parent: b9961cc0f835caff6f0231e5c509beaaa52a0a32
author: Jonne Kokkonen <jonne.kokkonen@gmail.com>
date: Wed Apr 19 18:31:10 EDT 2023

fixes #104 audio device unplugging and replugging fixes

--- a/audio.c
+++ b/audio.c
@@ -18,6 +18,9 @@
   int m8_device_id = -1;
   int devcount_in = 0; // audio input device count
 
+  // wait for system to initialize possible new audio devices
+  SDL_Delay(500);
+
   devcount_in = SDL_GetNumAudioDevices(SDL_TRUE);
 
   if (devcount_in < 1) {
@@ -26,6 +29,7 @@
   } else {
     for (i = 0; i < devcount_in; i++) {
       // Check if input device exists before doing anything else
+      SDL_LogDebug(SDL_LOG_CATEGORY_AUDIO, "%s", SDL_GetAudioDeviceName(i, SDL_TRUE));
       if (SDL_strstr(SDL_GetAudioDeviceName(i, SDL_TRUE), "M8") != NULL) {
         SDL_Log("M8 Audio Input device found: %s",
                 SDL_GetAudioDeviceName(i, SDL_TRUE));
--- a/main.c
+++ b/main.c
@@ -133,9 +133,10 @@
           if (run == WAIT_FOR_DEVICE && init_serial(0) == 1) {
 
             if (conf.audio_enabled == 1) {
-              if (audio_init(conf.audio_buffer_size, conf.audio_device_name) == 0) {
-                SDL_Log("Cannot initialize audio, exiting.");
-                run = QUIT;
+              if (audio_init(conf.audio_buffer_size, conf.audio_device_name) ==
+                  0) {
+                SDL_Log("Cannot initialize audio");
+                conf.audio_enabled = 0;
               }
             }
 
@@ -251,6 +252,9 @@
               port_inited = 0;
               run = WAIT_FOR_DEVICE;
               close_serial_port();
+              if (conf.audio_enabled == 1) {
+                audio_destroy();
+              }
               /* we'll make one more loop to see if the device is still there
                * but just sending zero bytes. if it doesn't get detected when
                * resetting the port, it will disconnect */
--