Skip to content

Commit

Permalink
open audio device as needed to avoid potentional conflicts.
Browse files Browse the repository at this point in the history
  • Loading branch information
eebssk1 committed Oct 30, 2023
1 parent ab1ce1a commit 31cbf62
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions SRBeep2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@ Now: EBK21 [email protected]
************************************/

#include <obs-module.h>
#include <obs-frontend-api/obs-frontend-api.h>
#include <obs-frontend-api.h>
#include <thread>
#include <atomic>
#include <sstream>
#include <mutex>

extern "C"
{
#include "SDL.h"
#include "SDL_thread.h"
#include "SDL_mixer.h"
#include <SDL2/SDL.h>
#include <SDL2/SDL_thread.h>
#include <SDL2/SDL_mixer.h>
};

std::mutex audioMutex;
Expand Down Expand Up @@ -56,7 +56,6 @@ void obs_module_unload(void)
{
ps_sto_Thread.join();
}
Mix_CloseAudio();
SDL_Quit();
return;
}
Expand All @@ -81,6 +80,10 @@ void play_clip(const char *filepath)
{
Mix_Music* music;
audioMutex.lock();
if (Mix_OpenAudio(44100, MIX_DEFAULT_FORMAT, 1, 1024)!=0) {
audioMutex.unlock();
return;
}
if(! (music = Mix_LoadMUS(filepath))) {
audioMutex.unlock();
return;
Expand All @@ -91,6 +94,7 @@ void play_clip(const char *filepath)
SDL_Delay(1);
}
Mix_FreeMusic(music);
Mix_CloseAudio();
audioMutex.unlock();
return;
}
Expand Down Expand Up @@ -208,7 +212,6 @@ void obsstudio_srbeep_frontend_event_callback(enum obs_frontend_event event, voi

bool obs_module_load(void)
{
Mix_OpenAudio(44100, MIX_DEFAULT_FORMAT, 1, 1024);
obs_frontend_add_event_callback(obsstudio_srbeep_frontend_event_callback, 0);
return true;
}

0 comments on commit 31cbf62

Please sign in to comment.