setup preferred backends for miniaudio;

pull/69/head
Bryan Biedenkapp 1 year ago
parent 35cf087b33
commit 92070b77db

@ -10,8 +10,6 @@
#include "Defines.h"
#include "common/Log.h"
#include "bridge/ActivityLog.h"
#define MINIAUDIO_IMPLEMENTATION
#include "audio/miniaudio.h"
#include "BridgeMain.h"
#include "HostBridge.h"
@ -48,6 +46,15 @@ int g_outputDevice = -1;
uint8_t* g_gitHashBytes = nullptr;
#ifdef _WIN32
ma_backend g_backends[3];
ma_uint32 g_backendCnt = 3;
#else
ma_backend g_backends[7];
ma_uint32 g_backendCnt = 7;
#endif
// ---------------------------------------------------------------------------
// Global Functions
// ---------------------------------------------------------------------------
@ -112,11 +119,13 @@ void usage(const char* message, const char* arg)
g_progExe.c_str());
ma_context context;
if (ma_context_init(NULL, 0, NULL, &context) != MA_SUCCESS) {
if (ma_context_init(g_backends, g_backendCnt, NULL, &context) != MA_SUCCESS) {
fprintf(stderr, "Failed to initialize audio context.\n");
exit(EXIT_FAILURE);
}
fprintf(stdout, "\nAudio Backend: %s", ma_get_backend_name(context.backend));
ma_device_info* playbackDevices;
ma_device_info* captureDevices;
ma_uint32 playbackDeviceCount, captureDeviceCount;
@ -219,6 +228,24 @@ int main(int argc, char** argv)
g_gitHashBytes = new uint8_t[4U];
::memset(g_gitHashBytes, 0x00U, 4U);
#ifdef _WIN32
// Windows
g_backends[0] = ma_backend_winmm;
g_backends[1] = ma_backend_wasapi;
g_backends[2] = ma_backend_null;
#else
// Linux
g_backends[0] = ma_backend_pulseaudio;
g_backends[1] = ma_backend_alsa;
g_backends[2] = ma_backend_jack;
g_backends[3] = ma_backend_oss;
// MacOS
g_backends[4] = ma_backend_coreaudio;
g_backends[5] = ma_backend_sndio;
// BSD
g_backends[6] = ma_backend_null;
#endif
uint32_t hash = ::strtoul(__GIT_VER_HASH__, 0, 16);
__SET_UINT32(hash, g_gitHashBytes, 0U);

@ -17,6 +17,8 @@
#define __BRIDGE_MAIN_H__
#include "Defines.h"
#define MINIAUDIO_IMPLEMENTATION
#include "audio/miniaudio.h"
#include <string>
@ -45,6 +47,14 @@ extern int g_outputDevice;
extern uint8_t* g_gitHashBytes;
#ifdef _WIN32
extern ma_backend g_backends[];
extern ma_uint32 g_backendCnt;
#else
extern ma_backend g_backends[];
extern ma_uint32 g_backendCnt;
#endif
/**
* @brief Helper to trigger a fatal error message. This will cause the program to terminate
* immediately with an error message.

@ -354,7 +354,7 @@ int HostBridge::run()
ma_result result;
if (m_localAudio) {
// initialize audio devices
if (ma_context_init(NULL, 0, NULL, &m_maContext) != MA_SUCCESS) {
if (ma_context_init(g_backends, g_backendCnt, NULL, &m_maContext) != MA_SUCCESS) {
::LogError(LOG_HOST, "Failed to initialize audio context.");
return EXIT_FAILURE;
}
@ -367,6 +367,7 @@ int HostBridge::run()
}
LogInfo("Audio Parameters");
LogInfo(" Audio Backend: %s", ma_get_backend_name(m_maContext.backend));
LogInfo(" Input Device: %s", m_maCaptureDevices[g_inputDevice].name);
LogInfo(" Output Device: %s", m_maPlaybackDevices[g_outputDevice].name);
@ -382,12 +383,13 @@ int HostBridge::run()
m_maDeviceConfig.playback.pDeviceID = &m_maPlaybackDevices[g_outputDevice].id;
m_maDeviceConfig.playback.format = ma_format_s16;
m_maDeviceConfig.playback.channels = 1;
m_maDeviceConfig.playback.shareMode = ma_share_mode_shared;
m_maDeviceConfig.periodSizeInFrames = MBE_SAMPLES_LENGTH;
m_maDeviceConfig.dataCallback = audioCallback;
m_maDeviceConfig.pUserData = this;
result = ma_device_init(NULL, &m_maDeviceConfig, &m_maDevice);
result = ma_device_init(&m_maContext, &m_maDeviceConfig, &m_maDevice);
if (result != MA_SUCCESS) {
ma_context_uninit(&m_maContext);
return EXIT_FAILURE;

Loading…
Cancel
Save

Powered by TurnKey Linux.