diff options
Diffstat (limited to 'src/aoapplication.cpp')
| -rw-r--r-- | src/aoapplication.cpp | 92 |
1 files changed, 30 insertions, 62 deletions
diff --git a/src/aoapplication.cpp b/src/aoapplication.cpp index 774816b..ecfd97a 100644 --- a/src/aoapplication.cpp +++ b/src/aoapplication.cpp @@ -26,6 +26,13 @@ AOApplication::AOApplication(QObject *parent) message_handler_context = this; original_message_handler = qInstallMessageHandler(message_handler); + + mus_decoders[0] = ma_decoding_backend_libopus; + mus_decoders[1] = ma_decoding_backend_libvorbis; + mus_decoder_config = ma_decoder_config_init_default(); + mus_decoder_config.pCustomBackendUserData = nullptr; + mus_decoder_config.customBackendCount = 2; + mus_decoder_config.ppCustomBackendVTables = mus_decoders; } AOApplication::~AOApplication() @@ -175,24 +182,6 @@ void AOApplication::call_settings_menu() delete l_dialog; } -// Callback for when BASS device is lost -// Only actually used for music syncs -void CALLBACK AOApplication::BASSreset(HSTREAM handle, DWORD channel, DWORD data, void *user) -{ - Q_UNUSED(handle); - Q_UNUSED(channel); - Q_UNUSED(data); - Q_UNUSED(user); - doBASSreset(); -} - -void AOApplication::doBASSreset() -{ - BASS_Free(); - BASS_Init(-1, 48000, BASS_DEVICE_LATENCY, nullptr, nullptr); - load_bass_plugins(); -} - void AOApplication::server_connected() { qInfo() << "Established connection to server."; @@ -203,35 +192,33 @@ void AOApplication::server_connected() courtroom_loaded = false; } -void AOApplication::initBASS() +void AOApplication::initAudio() { - BASS_SetConfig(BASS_CONFIG_DEV_DEFAULT, 1); - BASS_Free(); - // Change the default audio output device to be the one the user has given - // in his config.ini file for now. - unsigned int a = 0; - BASS_DEVICEINFO info; - - if (Options::getInstance().audioOutputDevice() == "default") + ma_context ctx; + if (ma_context_init(nullptr, 0, nullptr, &ctx) != MA_SUCCESS) { - BASS_Init(-1, 48000, BASS_DEVICE_LATENCY, nullptr, nullptr); - load_bass_plugins(); + qCritical("Failed to initialize audio context."); } - else + // TODO: Support multiple devices + + ma_resource_manager_config rm_config = ma_resource_manager_config_init(); + rm_config.decodedFormat = ma_format_f32; + rm_config.decodedChannels = 2; + rm_config.decodedSampleRate = 48000; + ma_decoding_backend_vtable *decoders[] = {ma_decoding_backend_libopus, ma_decoding_backend_libvorbis}; + rm_config.ppCustomDecodingBackendVTables = decoders; + rm_config.customDecodingBackendCount = sizeof(decoders) / sizeof(decoders[0]); + rm_config.pCustomDecodingBackendUserData = nullptr; + if (ma_resource_manager_init(&rm_config, &audio_rm) != MA_SUCCESS) { - for (a = 0; BASS_GetDeviceInfo(a, &info); a++) - { - if (Options::getInstance().audioOutputDevice() == info.name) - { - BASS_SetDevice(a); - BASS_Init(static_cast<int>(a), 48000, BASS_DEVICE_LATENCY, nullptr, nullptr); - load_bass_plugins(); - qInfo() << info.name << "was set as the default audio output device."; - return; - } - } - BASS_Init(-1, 48000, BASS_DEVICE_LATENCY, nullptr, nullptr); - load_bass_plugins(); + qCritical("Failed to initialize audio resource manager."); + } + + ma_engine_config engine_config = ma_engine_config_init(); + engine_config.pResourceManager = &audio_rm; + if (ma_engine_init(&engine_config, &audio_engine) != MA_SUCCESS) + { + qCritical("Failed to initialize audio engine."); } } @@ -262,22 +249,3 @@ void AOApplication::centerOrMoveWidgetOnPrimaryScreen(QWidget *widget) widget->move(point->x(), point->y()); } } - -#if (defined(_WIN32) || defined(_WIN64)) -void AOApplication::load_bass_plugins() -{ - BASS_PluginLoad("bassopus.dll", 0); -} -#elif defined __APPLE__ -void AOApplication::load_bass_plugins() -{ - BASS_PluginLoad("libbassopus.dylib", 0); -} -#elif (defined(LINUX) || defined(__linux__)) -void AOApplication::load_bass_plugins() -{ - BASS_PluginLoad("libbassopus.so", 0); -} -#else -#error This operating system is unsupported for BASS plugins. -#endif |
