Skip to content

Commit

Permalink
fix voice capture and receive for UT2004
Browse files Browse the repository at this point in the history
  • Loading branch information
zenakuten committed Aug 28, 2023
1 parent ca3bc1b commit f706c43
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 1 deletion.
11 changes: 11 additions & 0 deletions al/buffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@
#include "eax/x_ram.h"
#endif // ALSOFT_EAX

//snarf
#include <windows.h>
#include "debugapi.h"

namespace {

Expand Down Expand Up @@ -286,9 +289,12 @@ void LoadData(ALCcontext *context, ALbuffer *ALBuf, ALsizei freq, ALuint size,
const FmtChannels DstChannels, const FmtType DstType, const std::byte *SrcData,
ALbitfieldSOFT access)
{
/*
snarf
if(ReadRef(ALBuf->ref) != 0 || ALBuf->MappedAccess != 0) UNLIKELY
return context->setError(AL_INVALID_OPERATION, "Modifying storage for in-use buffer %u",
ALBuf->id);
*/

const ALuint unpackalign{ALBuf->UnpackAlign};
const ALuint align{SanitizeAlignment(DstType, unpackalign)};
Expand Down Expand Up @@ -1247,6 +1253,11 @@ FORCE_ALIGN void AL_APIENTRY alGetBufferiDirect(ALCcontext *context, ALuint buff
*value = static_cast<int>(albuf->UnpackAmbiOrder);
break;

case AL_BUFFER_SOURCE_ID:
*value = static_cast<ALint>(albuf->sourceId);
break;


default:
context->setError(AL_INVALID_ENUM, "Invalid buffer integer property 0x%04x", param);
}
Expand Down
3 changes: 3 additions & 0 deletions al/buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ struct ALbuffer : public BufferStorage {
/* Self ID */
ALuint id{0};

// snarf
ALuint sourceId{0};

static void SetName(ALCcontext *context, ALuint id, std::string_view name);

DISABLE_ALLOC()
Expand Down
46 changes: 46 additions & 0 deletions al/source.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3006,6 +3006,42 @@ FORCE_ALIGN void AL_APIENTRY alGetSourceiDirect(ALCcontext *context, ALuint sour
if(!value) UNLIKELY
return context->setError(AL_INVALID_VALUE, "NULL pointer");

//snarf
ALenum oldParam = param;
if (param == AL_BUFFERS_QUEUED)
{
param = AL_SOURCE_STATE;
std::ignore = GetProperty(Source, context, static_cast<SourceProp>(param),
al::span{ value, 1u });
param = oldParam;

if (*value != AL_PLAYING)
*value = 9;
else
{
*value = Source->mQueue.size();
}
return;
}
else if (param == AL_BUFFERS_PROCESSED)
{
int played{ 0 };
//if (Source->state != AL_INITIAL)
//{
const VoiceBufferItem* Current{ nullptr };
if (Voice * voice{ GetSourceVoice(Source, context) })
Current = voice->mCurrentBuffer.load(std::memory_order_relaxed);
for (auto& item : Source->mQueue)
{
if (&item == Current)
break;
++played;
}
//}
*value = played;
return;
}

std::ignore = GetProperty(Source, context, static_cast<SourceProp>(param),
al::span{value, 1u});
}
Expand Down Expand Up @@ -3422,6 +3458,12 @@ FORCE_ALIGN void AL_APIENTRY alSourceQueueBuffersDirect(ALCcontext *context, ALu
}
if(buffer)
{
//snarf
if (buffer->sourceId == 0)
{
buffer->sourceId = src;
}

if(buffer->mSampleRate < 1)
{
context->setError(AL_INVALID_OPERATION, "Queueing buffer %u with no format",
Expand Down Expand Up @@ -3456,6 +3498,9 @@ FORCE_ALIGN void AL_APIENTRY alSourceQueueBuffersDirect(ALCcontext *context, ALu
BufferList->mLoopEnd = buffer->mSampleLen;
BufferList->mSamples = buffer->mData.data();
BufferList->mBuffer = buffer;

//snarf
buffer->sourceId = src;
IncrementRef(buffer->ref);

if(BufferFmt == nullptr)
Expand Down Expand Up @@ -3548,6 +3593,7 @@ FORCE_ALIGN void AL_APIENTRY alSourceUnqueueBuffersDirect(ALCcontext *context, A
auto &head = source->mQueue.front();
if(ALbuffer *buffer{head.mBuffer})
{
buffer->sourceId = src;
*(buffers++) = buffer->id;
DecrementRef(buffer->ref);
}
Expand Down
5 changes: 4 additions & 1 deletion alc/alc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2728,7 +2728,7 @@ ALC_API ALCcontext* ALC_APIENTRY alcCreateContext(ALCdevice *device, const ALCin

if(ALeffectslot *slot{context->mDefaultSlot.get()})
{
ALenum sloterr{slot->initEffect(0, ALCcontext::sDefaultEffect.type,
ALenum sloterr{slot->initEffect(ALCcontext::sDefaultEffect.type,
ALCcontext::sDefaultEffect.Props, context.get())};
if(sloterr == AL_NO_ERROR)
slot->updateProps(context.get());
Expand Down Expand Up @@ -2998,6 +2998,9 @@ ALC_API ALCboolean ALC_APIENTRY alcCloseDevice(ALCdevice *device) noexcept
************************************************/
ALC_API ALCdevice* ALC_APIENTRY alcCaptureOpenDevice(const ALCchar *deviceName, ALCuint frequency, ALCenum format, ALCsizei samples) noexcept
{
//snarf
samples = samples / 4;

InitConfig();

if(!CaptureFactory)
Expand Down
3 changes: 3 additions & 0 deletions include/AL/al.h
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,9 @@ typedef void ALvoid;
#define AL_EXPONENT_DISTANCE 0xD005
#define AL_EXPONENT_DISTANCE_CLAMPED 0xD006

//snarf
#define AL_BUFFER_SOURCE_ID 0xE001

#ifndef AL_NO_PROTOTYPES
/* Renderer State management. */
AL_API void AL_APIENTRY alEnable(ALenum capability) AL_API_NOEXCEPT;
Expand Down

0 comments on commit f706c43

Please sign in to comment.