Skip to content

Commit

Permalink
Merge branch 'kcat:master' into jack
Browse files Browse the repository at this point in the history
  • Loading branch information
ThreeDeeJay authored Aug 21, 2024
2 parents 568c09e + f721be4 commit b5e734b
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 2 deletions.
6 changes: 5 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1044,10 +1044,14 @@ if(WIN32)
set(HAVE_WASAPI 1)
set(BACKENDS "${BACKENDS} WASAPI,")
set(ALC_OBJS ${ALC_OBJS} alc/backends/wasapi.cpp alc/backends/wasapi.h)

if(NOT ALSOFT_UWP)
set(EXTRA_LIBS avrt ${EXTRA_LIBS})
endif()
endif()
endif()

option(ALSOFT_BACKEND_OTHERIO "Enable OtherIO backend" ON)
option(ALSOFT_BACKEND_OTHERIO "Enable OtherIO backend" OFF)
option(ALSOFT_REQUIRE_OTHERIO "Require OtherIO backend" OFF)
if(ALSOFT_BACKEND_OTHERIO)
set(HAVE_OTHERIO 1)
Expand Down
4 changes: 3 additions & 1 deletion alc/backends/jack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,9 @@ bool jack_load()
#ifdef HAVE_DYNLOAD
if(!jack_handle)
{
#ifdef _WIN32
#if defined(_WIN64)
#define JACKLIB "libjack64.dll"
#elif defined(_WIN32)
#define JACKLIB "libjack.dll"
#else
#define JACKLIB "libjack.so.0"
Expand Down
23 changes: 23 additions & 0 deletions alc/backends/wasapi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include <cstdlib>
#include <memory.h>

#include <avrt.h>
#include <wtypes.h>
#include <mmdeviceapi.h>
#include <audiosessiontypes.h>
Expand Down Expand Up @@ -319,6 +320,13 @@ struct DeviceListLock : public std::unique_lock<DeviceList> {
DeviceList gDeviceList;


#ifdef AVRTAPI
struct AvrtHandleCloser {
void operator()(HANDLE handle) { AvRevertMmThreadCharacteristics(handle); }
};
using AvrtHandlePtr = std::unique_ptr<std::remove_pointer_t<HANDLE>,AvrtHandleCloser>;
#endif

#if defined(ALSOFT_UWP)
enum EDataFlow {
eRender = 0,
Expand Down Expand Up @@ -968,6 +976,7 @@ struct WasapiProxy {
static inline std::deque<Msg> mMsgQueue;
static inline std::mutex mMsgQueueLock;
static inline std::condition_variable mMsgQueueCond;
static inline DWORD sAvIndex{};

static inline std::optional<DeviceHelper> sDeviceHelper;

Expand Down Expand Up @@ -1169,6 +1178,15 @@ FORCE_ALIGN int WasapiPlayback::mixerProc()
const UINT32 buffer_len{mOrigBufferSize};
const void *resbufferptr{};

#ifdef AVRTAPI
/* TODO: "Audio" or "Pro Audio"? The suggestion is to use "Pro Audio" for
* device periods less than 10ms, and "Audio" for greater than or equal to
* 10ms.
*/
auto taskname = (update_size < mFormat.Format.nSamplesPerSec/100) ? L"Pro Audio" : L"Audio";
auto avhandle = AvrtHandlePtr{AvSetMmThreadCharacteristicsW(taskname, &sAvIndex)};
#endif

mBufferFilled = 0;
while(!mKillNow.load(std::memory_order_relaxed))
{
Expand Down Expand Up @@ -1257,6 +1275,11 @@ FORCE_ALIGN int WasapiPlayback::mixerSpatialProc()
std::vector<void*> resbuffers;
std::vector<const void*> tmpbuffers;

#ifdef AVRTAPI
auto taskname = (mOrigUpdateSize<mFormat.Format.nSamplesPerSec/100) ? L"Pro Audio" : L"Audio";
auto avhandle = AvrtHandlePtr{AvSetMmThreadCharacteristicsW(taskname, &sAvIndex)};
#endif

/* TODO: Set mPadding appropriately. There doesn't seem to be a way to
* update it dynamically based on the stream, so a fixed size may be the
* best we can do.
Expand Down

0 comments on commit b5e734b

Please sign in to comment.