Skip to content

Commit

Permalink
Merge pull request #374 from a740g/openal-backend-removal
Browse files Browse the repository at this point in the history
Remove OpenAL audio backend
  • Loading branch information
a740g authored Sep 23, 2023
2 parents ad6b7ae + 87a99c3 commit 5f5121b
Show file tree
Hide file tree
Showing 199 changed files with 97 additions and 96,473 deletions.
51 changes: 10 additions & 41 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -183,10 +183,6 @@ include $(PATH_INTERNAL_C)/libqb/build.mk
CXXFLAGS += -I$(PATH_LIBQB)/include
EXE_LIBS += $(libqb-objs-y)

include $(PATH_INTERNAL_C)/parts/audio/conversion/build.mk
include $(PATH_INTERNAL_C)/parts/audio/decode/mp3_mini/build.mk
include $(PATH_INTERNAL_C)/parts/audio/decode/ogg/build.mk
include $(PATH_INTERNAL_C)/parts/audio/out/build.mk
include $(PATH_INTERNAL_C)/parts/audio/extras/build.mk
include $(PATH_INTERNAL_C)/parts/audio/build.mk
include $(PATH_INTERNAL_C)/parts/core/build.mk
Expand Down Expand Up @@ -284,6 +280,15 @@ ifneq ($(filter y,$(DEP_AUDIO_MINIAUDIO)),)
EXE_LIBS += $(MINIAUDIO_OBJS)

CXXFLAGS += -DDEPENDENCY_AUDIO_MINIAUDIO
ifeq ($(OS),lnx)
CXXLIBS += -lm -lasound
endif
ifeq ($(OS),win)
CXXLIBS += -lwinmm -lksguid -ldxguid -lole32
endif
ifeq ($(OS),osx)
CXXLIBS += -framework CoreFoundation -framework CoreAudio -framework CoreMIDI -framework AudioUnit -framework AudioToolbox
endif
QBLIB_NAME := $(addsuffix 1,$(QBLIB_NAME))

LICENSE_IN_USE += miniaudio stbvorbis libxmp-lite radv2 hivelytracker qoa
Expand All @@ -292,39 +297,7 @@ ifneq ($(filter y,$(DEP_AUDIO_MINIAUDIO)),)
LICENSE_IN_USE += tinysoundfont tinymidiloader
endif
else
QBLIB_NAME := $(addsuffix 0,$(QBLIB_NAME))
endif

ifneq ($(filter y,$(DEP_AUDIO_CONVERSION) $(DEP_AUDIO_DECODE)),)
EXE_LIBS += $(QB_AUDIO_CONVERSION_LIB)
CXXFLAGS += -DDEPENDENCY_AUDIO_CONVERSION
QBLIB_NAME := $(addsuffix 1,$(QBLIB_NAME))

LICENSE_IN_USE += opus
else
QBLIB_NAME := $(addsuffix 0,$(QBLIB_NAME))
endif

ifneq ($(filter y,$(DEP_AUDIO_DECODE)),)
EXE_LIBS += $(QB_AUDIO_DECODE_MP3_LIB) $(QB_AUDIO_DECODE_OGG_LIB)
CXXFLAGS += -DDEPENDENCY_AUDIO_DECODE
QBLIB_NAME := $(addsuffix 1,$(QBLIB_NAME))

LICENSE_IN_USE += mpg123 stbvorbis
else
QBLIB_NAME := $(addsuffix 0,$(QBLIB_NAME))
endif

ifneq ($(filter y,$(DEP_AUDIO_OUT) $(DEP_AUDIO_CONVERSION) $(DEP_AUDIO_DECODE)),)
EXE_LIBS += $(QB_AUDIO_OUT_LIB)
CXXFLAGS += -DDEPENDENCY_AUDIO_OUT
ifeq ($(OS),osx)
CXXLIBS += -framework AudioUnit -framework AudioToolbox
endif
QBLIB_NAME := $(addsuffix 1,$(QBLIB_NAME))

LICENSE_IN_USE += openal
else
EXE_LIBS += $(MINIAUDIO_STUB_OBJS)
QBLIB_NAME := $(addsuffix 0,$(QBLIB_NAME))
endif

Expand Down Expand Up @@ -376,10 +349,6 @@ ifeq ($(OS),win)
CXXLIBS += -lwinmm
endif

ifneq ($(filter y,$(DEP_AUDIO_OUT) $(DEP_AUDIO_CONVERSION) $(DEP_AUDIO_DECODE) $(DEP_AUDIO_MINIAUDIO)),)
CXXLIBS += -lwinmm -lksguid -ldxguid -lole32
endif

ifneq ($(filter y,$(DEP_ICON) $(DEP_ICON_RC) $(DEP_SCREENIMAGE) $(DEP_PRINTER)),)
CXXLIBS += -lgdi32
endif
Expand Down
5 changes: 1 addition & 4 deletions docs/build-system.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,14 +127,11 @@ These flags controls whether certain dependencies are compiled in or not. All of
| `DEP_ICON_RC` | Adds `$EXEICON` and `$VERSIONINFO` support, compiles `.rc` file into the executable on Windows |
| `DEP_FONT` | Enables various `_FONT` related support. |
| `DEP_DEVICEINPUT` | Enables game controller input support. |
| `DEP_AUDIO_CONVERSION` | Includes the audio resampler (Only relevant when audio decode or out is enabled) |
| `DEP_AUDIO_DECODE` | Pulls in sound support for things like `_SNDOPEN` and also support for opening the support sound formats. |
| `DEP_AUDIO_OUT` | Pulls in sound support for playing sounds via `PLAY`, `_SNDPLAY`, and various other functions that makes sounds. |
| `DEP_ZLIB` | Adds `_DEFLATE` and `_INFLATE` support. |
| `DEP_DATA` | Compiles in data produced via `DATA` statements. |
| `DEP_CONSOLE` | On Windows, this gives the program console support (graphical support is still allowed) |
| `DEP_CONSOLE_ONLY` | Same as `DEP_CONSOLE`, but also removes GLUT and graphics support. |
| `DEP_AUDIO_MINIAUDIO` | Enables the miniaudio backend. Should not be used with the other `DEP_AUDIO` switches which enable the old backend. |
| `DEP_AUDIO_MINIAUDIO` | Pulls in sound support using miniaudio for playing sounds via `PLAY`, `_SNDPLAY`, and various other functions that makes sounds. |
| `DEP_HTTP` | Enables http support via libcurl. Should only be used if `DEP_SOCKETS` is on. |

Versioning
Expand Down
2 changes: 1 addition & 1 deletion internal/c/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
# endif
# include <csignal>
# include <process.h> //required for multi-threading
# if defined DEPENDENCY_AUDIO_OUT || defined QB64_GUI
# if defined DEPENDENCY_AUDIO_MINIAUDIO || defined QB64_GUI
# include <mmsystem.h>
# endif

Expand Down
6 changes: 0 additions & 6 deletions internal/c/libqb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21515,12 +21515,6 @@ double func_sqr(double value) {
return sqrt(value);
}

#ifndef DEPENDENCY_AUDIO_MINIAUDIO
# include "parts/audio/out/src.c"
# include "parts/audio/conversion/src.c"
# include "parts/audio/decode/src.c"
#endif

qbs *func_command_str = NULL;
char **func_command_array = NULL;
int32 func_command_count = 0;
Expand Down
6 changes: 3 additions & 3 deletions internal/c/libqb/include/audio.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@
AUDIO_DEBUG_PRINT("Condition (%s) failed", #_exp_)
#else
# ifdef _MSC_VER
# define AUDIO_DEBUG_PRINT(_fmt_, ...) // Don't do anything in release builds
# define AUDIO_DEBUG_PRINT(_fmt_, ...) // Don't do anything in release builds
# else
# define AUDIO_DEBUG_PRINT(_fmt_, _args_...) // Don't do anything in release builds
# endif
# define AUDIO_DEBUG_CHECK(_exp_) // Don't do anything in release builds
# define AUDIO_DEBUG_CHECK(_exp_) // Don't do anything in release builds
#endif

// We always use 48000
Expand Down Expand Up @@ -67,7 +67,7 @@ void sub__sndraw(float left, float right, int32_t handle, int32_t passed);
void sub__sndrawdone(int32_t handle, int32_t passed);
double func__sndrawlen(int32_t handle, int32_t passed);

mem_block func__memsound(int32_t handle, int32_t targetChannel);
mem_block func__memsound(int32_t handle, int32_t targetChannel, int32_t passed);
int32_t func__sndnew(int32_t frames, int32_t channels, int32_t bits);

void snd_init();
Expand Down
54 changes: 29 additions & 25 deletions internal/c/parts/audio/audio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,10 @@ int32 func_instr(int32 start, qbs *str, qbs *substr, int32 passed); // Did not f
void new_mem_lock(); // This is required for MemSound()
void free_mem_lock(mem_lock *lock); // Same as above

extern ptrszint dblock; // Required for Play(). Did not find this declared anywhere
extern uint64 mem_lock_id; // Another one that we need for the mem stuff
extern mem_lock *mem_lock_base; // Same as above
extern mem_lock *mem_lock_tmp; // Same as above
extern ptrszint dblock; // Required for Play(). Did not find this declared anywhere
extern uint64 mem_lock_id; // Another one that we need for the mem stuff
extern mem_lock *mem_lock_base; // Same as above
extern mem_lock *mem_lock_tmp; // Same as above

/// @brief A simple FP32 stereo sample frame
struct SampleFrame {
Expand All @@ -87,7 +87,7 @@ struct RawStream {
libqb_mutex *m; // we'll use a mutex to give exclusive access to resources used by both threads
bool stop; // set this to true to stop supply of samples completely (including silent samples)

static const size_t DEFAULT_SIZE = 1024; // this is almost twice the amout what miniaudio actually asks for in frameCount
static const size_t DEFAULT_SIZE = 1024; // this is almost twice the amout what miniaudio actually asks for in frameCount

// Delete default, copy and move constructors and assignments
RawStream() = delete;
Expand Down Expand Up @@ -168,19 +168,19 @@ static ma_result RawStreamOnRead(ma_data_source *pDataSource, void *pFramesOut,
if (!pDataSource)
return MA_INVALID_ARGS;

auto pRawStream = (RawStream *)pDataSource; // cast to RawStream instance pointer
auto result = MA_SUCCESS; // must be initialized to MA_SUCCESS
auto maBuffer = (SampleFrame *)pFramesOut; // cast to sample frame pointer
auto pRawStream = (RawStream *)pDataSource; // cast to RawStream instance pointer
auto result = MA_SUCCESS; // must be initialized to MA_SUCCESS
auto maBuffer = (SampleFrame *)pFramesOut; // cast to sample frame pointer

ma_uint64 sampleFramesCount = pRawStream->consumer->data.size() - pRawStream->consumer->cursor; // total amount of samples we need to send to miniaudio
// Swap buffers if we do not have anything left to play
if (!sampleFramesCount) {
pRawStream->SwapBuffers();
sampleFramesCount = pRawStream->consumer->data.size() - pRawStream->consumer->cursor; // get the total number of samples again
}
sampleFramesCount = std::min(sampleFramesCount, frameCount); // we'll always send lower of what miniaudio wants or what we have
sampleFramesCount = std::min(sampleFramesCount, frameCount); // we'll always send lower of what miniaudio wants or what we have

ma_uint64 sampleFramesRead = 0; // sample frame counter
ma_uint64 sampleFramesRead = 0; // sample frame counter
// Now send the samples to miniaudio
while (sampleFramesRead < sampleFramesCount) {
maBuffer[sampleFramesRead] = pRawStream->consumer->data[pRawStream->consumer->cursor];
Expand Down Expand Up @@ -319,7 +319,7 @@ static void RawStreamDestroy(RawStream *pRawStream) {

ma_sound_uninit(pRawStream->maSound); // delete the ma_sound object

delete pRawStream; // delete the raw stream object
delete pRawStream; // delete the raw stream object

AUDIO_DEBUG_PRINT("Raw sound stream destroyed");
}
Expand Down Expand Up @@ -584,7 +584,7 @@ class PSG {
/// @brief Waits for any playback to complete
void AwaitPlaybackCompletion() {
if (background)
return; // no need to wait
return; // no need to wait

auto timeSec = rawStream->GetTimeRemaining() * 0.95 - 0.25; // per original QB64 behavior

Expand Down Expand Up @@ -1059,7 +1059,7 @@ class PSG {
case 'S': // staccato
pause = 1.0 / 4.0;
break;
case 'B': // background
case 'B': // background
if (!background) {
if (playIt) { // play pending buffer in foreground before we switch to background
playIt = false;
Expand Down Expand Up @@ -1403,7 +1403,7 @@ struct AudioEngine {
/// <returns>Returns a non-negative handle if successful</returns>
int32_t CreateHandle() {
if (!isInitialized)
return -1; // We cannot return 0 here. Since 0 is a valid internal handle
return -1; // We cannot return 0 here. Since 0 is a valid internal handle

size_t h, vectorSize = soundHandles.size(); // Save the vector size

Expand Down Expand Up @@ -2064,7 +2064,7 @@ void sub__sndbal(int32_t handle, double x, double y, double z, int32_t channel,
if (passed & 2 || passed & 4) { // If y or z or both are passed
ma_sound_set_spatialization_enabled(&audioEngine.soundHandles[handle]->maSound, MA_TRUE); // Enable 3D spatialization

ma_vec3f v = ma_sound_get_position(&audioEngine.soundHandles[handle]->maSound); // Get the current position in 3D space
ma_vec3f v = ma_sound_get_position(&audioEngine.soundHandles[handle]->maSound); // Get the current position in 3D space

// Set the previous values of x, y, z if these were not passed
if (!(passed & 1))
Expand Down Expand Up @@ -2328,18 +2328,17 @@ int32_t func__sndnew(int32_t frames, int32_t channels, int32_t bits) {
return handle;
}

/// <summary>
/// This function returns a _MEM value referring to a sound's raw data in memory using a designated sound handle created by the _SNDOPEN function.
/// @brief This function returns a _MEM value referring to a sound's raw data in memory using a designated sound handle created by the _SNDOPEN function.
/// miniaudio supports a variety of sample and channel formats. Translating all of that to basic 2 channel 16-bit format that
/// MemSound was originally supporting would require significant overhead both in terms of system resources and code.
/// For now we are just exposing the underlying PCM data directly from miniaudio. This fits rather well using the existing mem structure.
/// Mono sounds should continue to work just as it was before. Stereo and multi-channel sounds however will be required to be handled correctly
/// by the user by checking the 'elementsize' (for frame size in bytes) and 'type' (for data type) members.
/// </summary>
/// <param name="handle">A sound handle</param>
/// <param name="targetChannel">This should be 0 (for interleaved) or 1 (for mono). Anything else will result in failure</param>
/// <returns>A _MEM value that can be used to access the sound data</returns>
mem_block func__memsound(int32_t handle, int32_t targetChannel) {
/// @param handle A sound handle
/// @param targetChannel This should be 0 (for interleaved) or 1 (for mono). Anything else will result in failure
/// @param passed What arguments were passed?
/// @return A _MEM value that can be used to access the sound data
mem_block func__memsound(int32_t handle, int32_t targetChannel, int32_t passed) {
ma_format maFormat = ma_format::ma_format_unknown;
ma_uint32 channels = 0;
ma_uint64 sampleFrames = 0;
Expand All @@ -2351,9 +2350,14 @@ mem_block func__memsound(int32_t handle, int32_t targetChannel) {
mb.lock_id = INVALID_MEM_LOCK;

// Return invalid mem_block if audio is not initialized, handle is invalid or sound type is not static
if (!audioEngine.isInitialized || !IS_SOUND_HANDLE_VALID(handle) || audioEngine.soundHandles[handle]->type != SoundHandle::Type::STATIC ||
(targetChannel != 0 && targetChannel != 1)) {
AUDIO_DEBUG_PRINT("Invalid handle (%i), sound type (%i) or channel (%i)", handle, audioEngine.soundHandles[handle]->type, targetChannel);
if (!audioEngine.isInitialized || !IS_SOUND_HANDLE_VALID(handle) || audioEngine.soundHandles[handle]->type != SoundHandle::Type::STATIC) {
AUDIO_DEBUG_PRINT("Invalid handle (%i) or sound type (%i)", handle, audioEngine.soundHandles[handle]->type);
return mb;
}

// Simply return an "empty" mem_block if targetChannel is not 0 or 1
if (passed && targetChannel != 0 && targetChannel != 1) {
AUDIO_DEBUG_PRINT("Invalid channel (%i)", targetChannel);
return mb;
}

Expand Down
14 changes: 0 additions & 14 deletions internal/c/parts/audio/conversion/build.mk

This file was deleted.

2 changes: 0 additions & 2 deletions internal/c/parts/audio/conversion/download.txt

This file was deleted.

12 changes: 0 additions & 12 deletions internal/c/parts/audio/conversion/src.c

This file was deleted.

Loading

0 comments on commit 5f5121b

Please sign in to comment.