A Whole New World (clang-format edition)
I can show you the code Pretty, with proper whitespace Tell me, coder, now when did You last write readable code? I can open your eyes Make you see your bad indent Force you to respect the style The core devs agreed upon A whole new world A new fantastic code format A de facto standard With some sugar Enforced with clang-format A whole new world A dazzling style we all dreamed of And when we read it through It's crystal clear That now we're in a whole new world of code
This commit is contained in:
@ -31,8 +31,7 @@
|
||||
#include "global_config.h"
|
||||
#include "os/os.h"
|
||||
|
||||
const char * AudioDriverXAudio2::get_name() const
|
||||
{
|
||||
const char *AudioDriverXAudio2::get_name() const {
|
||||
return "XAudio2";
|
||||
}
|
||||
|
||||
@ -44,7 +43,6 @@ Error AudioDriverXAudio2::init() {
|
||||
pcm_open = false;
|
||||
samples_in = NULL;
|
||||
|
||||
|
||||
mix_rate = 48000;
|
||||
// FIXME: speaker_mode seems unused in the Xaudio2 driver so far
|
||||
speaker_mode = SPEAKER_MODE_STEREO;
|
||||
@ -53,11 +51,11 @@ Error AudioDriverXAudio2::init() {
|
||||
int latency = GLOBAL_DEF("audio/output_latency", 25);
|
||||
buffer_size = nearest_power_of_2(latency * mix_rate / 1000);
|
||||
|
||||
samples_in = memnew_arr(int32_t, buffer_size*channels);
|
||||
samples_in = memnew_arr(int32_t, buffer_size * channels);
|
||||
for (int i = 0; i < AUDIO_BUFFERS; i++) {
|
||||
samples_out[i] = memnew_arr(int16_t, buffer_size*channels);
|
||||
samples_out[i] = memnew_arr(int16_t, buffer_size * channels);
|
||||
xaudio_buffer[i].AudioBytes = buffer_size * channels * sizeof(int16_t);
|
||||
xaudio_buffer[i].pAudioData = (const BYTE*)(samples_out[i]);
|
||||
xaudio_buffer[i].pAudioData = (const BYTE *)(samples_out[i]);
|
||||
xaudio_buffer[i].Flags = 0;
|
||||
}
|
||||
|
||||
@ -93,15 +91,14 @@ Error AudioDriverXAudio2::init() {
|
||||
return OK;
|
||||
};
|
||||
|
||||
void AudioDriverXAudio2::thread_func(void* p_udata) {
|
||||
void AudioDriverXAudio2::thread_func(void *p_udata) {
|
||||
|
||||
AudioDriverXAudio2* ad = (AudioDriverXAudio2*)p_udata;
|
||||
AudioDriverXAudio2 *ad = (AudioDriverXAudio2 *)p_udata;
|
||||
|
||||
uint64_t usdelay = (ad->buffer_size / float(ad->mix_rate)) * 1000000;
|
||||
|
||||
while (!ad->exit_thread) {
|
||||
|
||||
|
||||
if (!ad->active) {
|
||||
|
||||
for (int i = 0; i < AUDIO_BUFFERS; i++) {
|
||||
@ -116,30 +113,27 @@ void AudioDriverXAudio2::thread_func(void* p_udata) {
|
||||
|
||||
ad->unlock();
|
||||
|
||||
for (unsigned int i = 0;i < ad->buffer_size*ad->channels;i++) {
|
||||
for (unsigned int i = 0; i < ad->buffer_size * ad->channels; i++) {
|
||||
|
||||
ad->samples_out[ad->current_buffer][i] = ad->samples_in[i] >> 16;
|
||||
}
|
||||
|
||||
ad->xaudio_buffer[ad->current_buffer].Flags = 0;
|
||||
ad->xaudio_buffer[ad->current_buffer].AudioBytes = ad->buffer_size * ad->channels * sizeof(int16_t);
|
||||
ad->xaudio_buffer[ad->current_buffer].pAudioData = (const BYTE*)(ad->samples_out[ad->current_buffer]);
|
||||
ad->xaudio_buffer[ad->current_buffer].pAudioData = (const BYTE *)(ad->samples_out[ad->current_buffer]);
|
||||
ad->xaudio_buffer[ad->current_buffer].PlayBegin = 0;
|
||||
ad->source_voice->SubmitSourceBuffer(&(ad->xaudio_buffer[ad->current_buffer]));
|
||||
|
||||
ad->current_buffer = (ad->current_buffer + 1) % AUDIO_BUFFERS;
|
||||
|
||||
XAUDIO2_VOICE_STATE state;
|
||||
while (ad->source_voice->GetState(&state), state.BuffersQueued > AUDIO_BUFFERS - 1)
|
||||
{
|
||||
while (ad->source_voice->GetState(&state), state.BuffersQueued > AUDIO_BUFFERS - 1) {
|
||||
WaitForSingleObject(ad->voice_callback.buffer_end_event, INFINITE);
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
ad->thread_exited = true;
|
||||
|
||||
};
|
||||
|
||||
void AudioDriverXAudio2::start() {
|
||||
@ -228,9 +222,6 @@ AudioDriverXAudio2::AudioDriverXAudio2() {
|
||||
current_buffer = 0;
|
||||
};
|
||||
|
||||
AudioDriverXAudio2::~AudioDriverXAudio2() {
|
||||
|
||||
AudioDriverXAudio2::~AudioDriverXAudio2(){
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
@ -29,15 +29,15 @@
|
||||
#ifndef AUDIO_DRIVER_XAUDIO2_H
|
||||
#define AUDIO_DRIVER_XAUDIO2_H
|
||||
|
||||
#include "servers/audio_server.h"
|
||||
#include "core/os/thread.h"
|
||||
#include "core/os/mutex.h"
|
||||
#include "core/os/thread.h"
|
||||
#include "servers/audio_server.h"
|
||||
|
||||
#include <windows.h>
|
||||
#include <mmsystem.h>
|
||||
#include <mmreg.h>
|
||||
#include <xaudio2.h>
|
||||
#include <mmsystem.h>
|
||||
#include <windows.h>
|
||||
#include <wrl/client.h>
|
||||
#include <xaudio2.h>
|
||||
|
||||
class AudioDriverXAudio2 : public AudioDriver {
|
||||
|
||||
@ -48,26 +48,28 @@ class AudioDriverXAudio2 : public AudioDriver {
|
||||
struct XAudio2DriverVoiceCallback : public IXAudio2VoiceCallback {
|
||||
|
||||
HANDLE buffer_end_event;
|
||||
XAudio2DriverVoiceCallback() : buffer_end_event(CreateEvent(NULL, FALSE, FALSE, NULL)) {}
|
||||
void STDMETHODCALLTYPE OnBufferEnd(void* pBufferContext) { /*print_line("buffer ended");*/ SetEvent(buffer_end_event); }
|
||||
XAudio2DriverVoiceCallback()
|
||||
: buffer_end_event(CreateEvent(NULL, FALSE, FALSE, NULL)) {}
|
||||
void STDMETHODCALLTYPE OnBufferEnd(void *pBufferContext) { /*print_line("buffer ended");*/
|
||||
SetEvent(buffer_end_event);
|
||||
}
|
||||
|
||||
//Unused methods are stubs
|
||||
void STDMETHODCALLTYPE OnStreamEnd() {}
|
||||
void STDMETHODCALLTYPE OnVoiceProcessingPassEnd() {}
|
||||
void STDMETHODCALLTYPE OnVoiceProcessingPassStart(UINT32 SamplesRequired) {}
|
||||
void STDMETHODCALLTYPE OnBufferStart(void * pBufferContext) {}
|
||||
void STDMETHODCALLTYPE OnLoopEnd(void * pBufferContext) {}
|
||||
void STDMETHODCALLTYPE OnVoiceError(void * pBufferContext, HRESULT Error) {}
|
||||
|
||||
void STDMETHODCALLTYPE OnBufferStart(void *pBufferContext) {}
|
||||
void STDMETHODCALLTYPE OnLoopEnd(void *pBufferContext) {}
|
||||
void STDMETHODCALLTYPE OnVoiceError(void *pBufferContext, HRESULT Error) {}
|
||||
};
|
||||
|
||||
Thread* thread;
|
||||
Mutex* mutex;
|
||||
Thread *thread;
|
||||
Mutex *mutex;
|
||||
|
||||
int32_t* samples_in;
|
||||
int16_t* samples_out[AUDIO_BUFFERS];
|
||||
int32_t *samples_in;
|
||||
int16_t *samples_out[AUDIO_BUFFERS];
|
||||
|
||||
static void thread_func(void* p_udata);
|
||||
static void thread_func(void *p_udata);
|
||||
int buffer_size;
|
||||
|
||||
unsigned int mix_rate;
|
||||
@ -83,14 +85,13 @@ class AudioDriverXAudio2 : public AudioDriver {
|
||||
WAVEFORMATEX wave_format;
|
||||
Microsoft::WRL::ComPtr<IXAudio2> xaudio;
|
||||
int current_buffer;
|
||||
IXAudio2MasteringVoice* mastering_voice;
|
||||
IXAudio2MasteringVoice *mastering_voice;
|
||||
XAUDIO2_BUFFER xaudio_buffer[AUDIO_BUFFERS];
|
||||
IXAudio2SourceVoice* source_voice;
|
||||
IXAudio2SourceVoice *source_voice;
|
||||
XAudio2DriverVoiceCallback voice_callback;
|
||||
|
||||
public:
|
||||
|
||||
const char* get_name() const;
|
||||
const char *get_name() const;
|
||||
|
||||
virtual Error init();
|
||||
virtual void start();
|
||||
|
||||
Reference in New Issue
Block a user