Switching audio system to platform-agnostic primitives.
This commit is contained in:
@@ -24,32 +24,27 @@ namespace xaudio2 {
|
||||
|
||||
class XAudio2AudioDriver::VoiceCallback : public IXAudio2VoiceCallback {
|
||||
public:
|
||||
VoiceCallback(HANDLE semaphore) : semaphore_(semaphore) {}
|
||||
VoiceCallback(xe::threading::Semaphore* semaphore) : semaphore_(semaphore) {}
|
||||
~VoiceCallback() {}
|
||||
|
||||
void OnStreamEnd() {}
|
||||
void OnVoiceProcessingPassEnd() {}
|
||||
void OnVoiceProcessingPassStart(uint32_t samples_required) {}
|
||||
void OnBufferEnd(void* context) {
|
||||
BOOL ret = ReleaseSemaphore(semaphore_, 1, NULL);
|
||||
assert_true(ret == TRUE);
|
||||
auto ret = semaphore_->Release(1, nullptr);
|
||||
assert_true(ret);
|
||||
}
|
||||
void OnBufferStart(void* context) {}
|
||||
void OnLoopEnd(void* context) {}
|
||||
void OnVoiceError(void* context, HRESULT result) {}
|
||||
|
||||
private:
|
||||
HANDLE semaphore_;
|
||||
xe::threading::Semaphore* semaphore_ = nullptr;
|
||||
};
|
||||
|
||||
XAudio2AudioDriver::XAudio2AudioDriver(Emulator* emulator, HANDLE semaphore)
|
||||
: AudioDriver(emulator),
|
||||
audio_(nullptr),
|
||||
mastering_voice_(nullptr),
|
||||
pcm_voice_(nullptr),
|
||||
semaphore_(semaphore),
|
||||
voice_callback_(nullptr),
|
||||
current_frame_(0) {
|
||||
XAudio2AudioDriver::XAudio2AudioDriver(Emulator* emulator,
|
||||
xe::threading::Semaphore* semaphore)
|
||||
: AudioDriver(emulator), semaphore_(semaphore) {
|
||||
static_assert(frame_count_ == XAUDIO2_MAX_QUEUED_BUFFERS,
|
||||
"xaudio header differs");
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ namespace xaudio2 {
|
||||
|
||||
class XAudio2AudioDriver : public AudioDriver {
|
||||
public:
|
||||
XAudio2AudioDriver(Emulator* emulator, HANDLE semaphore);
|
||||
XAudio2AudioDriver(Emulator* emulator, xe::threading::Semaphore* semaphore);
|
||||
~XAudio2AudioDriver() override;
|
||||
|
||||
void Initialize();
|
||||
@@ -30,13 +30,13 @@ class XAudio2AudioDriver : public AudioDriver {
|
||||
void Shutdown();
|
||||
|
||||
private:
|
||||
IXAudio2* audio_;
|
||||
IXAudio2MasteringVoice* mastering_voice_;
|
||||
IXAudio2SourceVoice* pcm_voice_;
|
||||
HANDLE semaphore_;
|
||||
IXAudio2* audio_ = nullptr;
|
||||
IXAudio2MasteringVoice* mastering_voice_ = nullptr;
|
||||
IXAudio2SourceVoice* pcm_voice_ = nullptr;
|
||||
xe::threading::Semaphore* semaphore_ = nullptr;
|
||||
|
||||
class VoiceCallback;
|
||||
VoiceCallback* voice_callback_;
|
||||
VoiceCallback* voice_callback_ = nullptr;
|
||||
|
||||
static const uint32_t frame_count_ = 64;
|
||||
static const uint32_t frame_channels_ = 6;
|
||||
@@ -44,7 +44,7 @@ class XAudio2AudioDriver : public AudioDriver {
|
||||
static const uint32_t frame_samples_ = frame_channels_ * channel_samples_;
|
||||
static const uint32_t frame_size_ = sizeof(float) * frame_samples_;
|
||||
float frames_[frame_count_][frame_samples_];
|
||||
uint32_t current_frame_;
|
||||
uint32_t current_frame_ = 0;
|
||||
};
|
||||
|
||||
} // namespace xaudio2
|
||||
|
||||
@@ -30,7 +30,8 @@ XAudio2AudioSystem::~XAudio2AudioSystem() {}
|
||||
|
||||
void XAudio2AudioSystem::Initialize() { AudioSystem::Initialize(); }
|
||||
|
||||
X_STATUS XAudio2AudioSystem::CreateDriver(size_t index, HANDLE semaphore,
|
||||
X_STATUS XAudio2AudioSystem::CreateDriver(size_t index,
|
||||
xe::threading::Semaphore* semaphore,
|
||||
AudioDriver** out_driver) {
|
||||
assert_not_null(out_driver);
|
||||
auto driver = new XAudio2AudioDriver(emulator_, semaphore);
|
||||
|
||||
@@ -23,7 +23,7 @@ class XAudio2AudioSystem : public AudioSystem {
|
||||
|
||||
static std::unique_ptr<AudioSystem> Create(Emulator* emulator);
|
||||
|
||||
X_RESULT CreateDriver(size_t index, HANDLE semaphore,
|
||||
X_RESULT CreateDriver(size_t index, xe::threading::Semaphore* semaphore,
|
||||
AudioDriver** out_driver) override;
|
||||
void DestroyDriver(AudioDriver* driver) override;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user