Skip to content

Commit

Permalink
update openal; openalhost-buffer prototyping
Browse files Browse the repository at this point in the history
  • Loading branch information
Try committed Jul 3, 2024
1 parent cd9bbb6 commit 80fd9b6
Show file tree
Hide file tree
Showing 20 changed files with 103 additions and 271 deletions.
21 changes: 21 additions & 0 deletions Engine/sound/sound.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,12 @@ const int32_t Sound::indexTable[] = {
};

Sound::Data::~Data() {
#if 0
alDeleteBuffersHost(1, &buffer);
#else
auto ctx = reinterpret_cast<ALCcontext*>(SoundDevice::bufferContextSt());
alDeleteBuffersDirect(ctx, 1,&buffer);
#endif
}

uint64_t Sound::Data::timeLength() const {
Expand Down Expand Up @@ -106,6 +110,22 @@ Sound::Sound(IDevice& f) {
}

void Sound::initData(const char* bytes, int format, size_t size, size_t rate) {
#if 0
uint32_t b = 0;
if(alGenBuffersHost(1, &b)!=AL_NO_ERROR) {
throw std::bad_alloc();
}

if(alBufferDataHost(b, format, bytes, int(size), int(rate))!=AL_NO_ERROR) {
alDeleteBuffersHost(1, &b);
throw std::bad_alloc();
}

auto d = std::make_shared<Data>();
d->buffer = b;
data = d;
#else

auto guard = SoundDevice::globalLock(); // for alGetError
auto ctx = reinterpret_cast<ALCcontext*>(SoundDevice::bufferContextSt());

Expand All @@ -124,6 +144,7 @@ void Sound::initData(const char* bytes, int format, size_t size, size_t rate) {
auto d = std::make_shared<Data>();
d->buffer = b;
data = d;
#endif
}

bool Sound::isEmpty() const {
Expand Down
20 changes: 18 additions & 2 deletions Engine/sound/soundeffect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,26 @@ struct SoundEffect::Impl {
ALCcontext* bufCtx = reinterpret_cast<ALCcontext*>(dev.bufferContext());

auto guard = SoundDevice::globalLock(); // for alGetError
#if 0
alGenBuffersHost(1, &stream);
#else
alGenBuffersDirect(bufCtx, 1, &stream);
alBufferCallbackDirectSOFT(ctx, stream, frm, freq, bufferCallback, this);
alcSetThreadContext(bufCtx);
alBufferCallbackSOFT(stream, frm, freq, bufferCallback, this);
alcSetThreadContext(nullptr);
#endif
alBufferCallbackDirectSOFT(bufCtx, stream, frm, freq, bufferCallback, this);
if(alGetErrorDirect(bufCtx)!=AL_NO_ERROR) {
throw std::bad_alloc();
}

alGenSourcesDirect(ctx, 1, &source);
if(alGetErrorDirect(ctx)!=AL_NO_ERROR) {
#if 0
alDeleteBuffersHost(1, &stream);
#else
alDeleteBuffersDirect(bufCtx, 1, &stream);
#endif
throw std::bad_alloc();
}

Expand All @@ -67,8 +78,13 @@ struct SoundEffect::Impl {

alSourcePausevDirect(ctx, 1, &source);
alDeleteSourcesDirect(ctx, 1, &source);
if(stream!=0)
if(stream!=0) {
#if 0
alDeleteBuffersHost(1, &stream);
#else
alDeleteBuffersDirect(bufCtx, 1, &stream);
#endif
}
}

static ALsizei bufferCallback(ALvoid *userptr, ALvoid *sampledata, ALsizei numbytes) noexcept {
Expand Down
152 changes: 0 additions & 152 deletions Engine/thirdparty/openal-soft/.github/workflows/ci.yml

This file was deleted.

76 changes: 0 additions & 76 deletions Engine/thirdparty/openal-soft/.github/workflows/makemhr.yml

This file was deleted.

7 changes: 4 additions & 3 deletions Engine/thirdparty/openal-soft/alc/backends/wasapi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -246,10 +246,11 @@ struct PropVariant {
{
if constexpr(std::is_same_v<T,uint>)
{
alassert(mProp.vt == VT_UI4);
return mProp.uiVal;
alassert(mProp.vt == VT_UI4 || mProp.vt == VT_UINT);
return mProp.uintVal;
}
else if constexpr(std::is_same_v<T,std::wstring_view> || std::is_same_v<T,std::wstring>)
else if constexpr(std::is_same_v<T,std::wstring_view> || std::is_same_v<T,std::wstring>
|| std::is_same_v<T,LPWSTR> || std::is_same_v<T,LPCWSTR>)
{
alassert(mProp.vt == VT_LPWSTR);
return mProp.pwszVal;
Expand Down
5 changes: 5 additions & 0 deletions Engine/thirdparty/openal-soft/alc/inprogext.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,11 @@ void ALC_APIENTRY alsoft_set_log_callback(LPALSOFTLOGCALLBACK callback, void *us
AL_API void AL_APIENTRY alSourceQueueBufferLayersSOFT(ALuint src, ALsizei nb,
const ALuint *buffers) noexcept;

AL_API void AL_APIENTRY alAuxiliaryEffectSlotPlaySOFT(ALuint slotid) noexcept;
AL_API void AL_APIENTRY alAuxiliaryEffectSlotPlayvSOFT(ALsizei n, const ALuint *slotids) noexcept;
AL_API void AL_APIENTRY alAuxiliaryEffectSlotStopSOFT(ALuint slotid) noexcept;
AL_API void AL_APIENTRY alAuxiliaryEffectSlotStopvSOFT(ALsizei n, const ALuint *slotids) noexcept;

AL_API ALint64SOFT AL_APIENTRY alGetInteger64SOFT(ALenum pname) AL_API_NOEXCEPT;
AL_API void AL_APIENTRY alGetInteger64vSOFT(ALenum pname, ALint64SOFT *values) AL_API_NOEXCEPT;
ALint64SOFT AL_APIENTRY alGetInteger64DirectSOFT(ALCcontext *context, ALenum pname) AL_API_NOEXCEPT;
Expand Down
18 changes: 18 additions & 0 deletions Engine/thirdparty/openal-soft/common/opthelpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,24 @@
#define NOINLINE
#endif

#if defined(__MINGW32__) && defined(__i386__)
/* 32-bit MinGW targets have a bug where __STDCPP_DEFAULT_NEW_ALIGNMENT__
* reports 16, despite the default operator new calling standard malloc which
* only guarantees 8-byte alignment. As a result, structs that need and specify
* 16-byte alignment only get 8-byte alignment. Explicitly specifying 32-byte
* alignment forces the over-aligned operator new to be called, giving the
* correct (if larger than necessary) alignment.
*
* Technically this bug affects 32-bit GCC more generally, but typically only
* with fairly old glibc versions as newer versions do guarantee the 16-byte
* alignment as specified. MinGW is reliant on msvcrt.dll's malloc however,
* which can't be updated to give that guarantee.
*/
#define SIMDALIGN alignas(32)
#else
#define SIMDALIGN
#endif

/* Unlike the likely attribute, ASSUME requires the condition to be true or
* else it invokes undefined behavior. It's essentially an assert without
* actually checking the condition at run-time, allowing for stronger
Expand Down
2 changes: 1 addition & 1 deletion Engine/thirdparty/openal-soft/common/phase_shifter.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
* signal delay (FilterSize/2) to properly align.
*/
template<std::size_t FilterSize>
struct PhaseShifterT {
struct SIMDALIGN PhaseShifterT {
static_assert(FilterSize >= 16, "FilterSize needs to be at least 16");
static_assert((FilterSize&(FilterSize-1)) == 0, "FilterSize needs to be power-of-two");

Expand Down
3 changes: 2 additions & 1 deletion Engine/thirdparty/openal-soft/core/bformatdec.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,12 @@
#include "devformat.h"
#include "filters/splitter.h"
#include "front_stablizer.h"
#include "opthelpers.h"


using ChannelDec = std::array<float,MaxAmbiChannels>;

class BFormatDec {
class SIMDALIGN BFormatDec {
static constexpr size_t sHFBand{0};
static constexpr size_t sLFBand{1};
static constexpr size_t sNumBands{2};
Expand Down
Loading

0 comments on commit 80fd9b6

Please sign in to comment.