Skip to content

Commit

Permalink
Fix space/tab whitespace for AudioDevice.h and default initialize all…
Browse files Browse the repository at this point in the history
… variables
  • Loading branch information
dpjudas committed Feb 4, 2024
1 parent 0cb53ae commit 58b05b3
Show file tree
Hide file tree
Showing 2 changed files with 151 additions and 151 deletions.
18 changes: 9 additions & 9 deletions SurrealEngine/Audio/AudioDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,8 @@ class ALSoundSource
private:
UActor* actor = nullptr;
USound* sound = nullptr;
vec3 position;
vec3 velocity;
vec3 position = vec3(0.0f);
vec3 velocity = vec3(0.0f);
float radius = 0.0f;
float volume = 0.0f;
float pitch = 0.0f;
Expand Down Expand Up @@ -533,17 +533,17 @@ class OpenALAudioDevice : public AudioDevice
}
}

ALCdevice* alDevice;
ALCcontext* alContext;
ALenum alError;
ALuint alMusicSource;
ALCdevice* alDevice = nullptr;
ALCcontext* alContext = nullptr;
ALenum alError = 0;
ALuint alMusicSource = 0;
std::vector<ALuint> alMusicBuffers;
std::vector<ALSoundSource> sources;
ALint monoSources;
ALint stereoSources;
ALint monoSources = 0;
ALint stereoSources = 0;
};

std::unique_ptr<AudioDevice> AudioDevice::Create(int frequency, int numVoices, int musicBufferCount, int musicBufferSize)
{
return std::make_unique<OpenALAudioDevice>(frequency, numVoices, musicBufferCount, musicBufferSize);
}
}
284 changes: 142 additions & 142 deletions SurrealEngine/Audio/AudioDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,155 +17,155 @@ class AudioDevice
static std::unique_ptr<AudioDevice> Create(int frequency, int numVoices, int musicBufferCount, int musicBufferSize);

virtual ~AudioDevice() = default;
virtual void AddSound(USound* sound) = 0;
virtual void RemoveSound(USound* sound) = 0;
virtual bool IsPlaying(int channel) = 0;
virtual void AddSound(USound* sound) = 0;
virtual void RemoveSound(USound* sound) = 0;
virtual bool IsPlaying(int channel) = 0;
virtual int PlaySound(int channel, USound* sound, vec3& location, float volume, float radius, float pitch) = 0;
virtual void PlayMusic(std::unique_ptr<AudioSource> source) = 0;
virtual void PlayMusicBuffer() = 0;
virtual void UpdateSound(int channel, USound* sound, vec3& location, float volume, float radius, float pitch) = 0;
virtual void UpdateMusicBuffer() = 0;
virtual void PlayMusic(std::unique_ptr<AudioSource> source) = 0;
virtual void PlayMusicBuffer() = 0;
virtual void UpdateSound(int channel, USound* sound, vec3& location, float volume, float radius, float pitch) = 0;
virtual void UpdateMusicBuffer() = 0;
virtual void StopSound(int channel) = 0;
virtual void SetMusicVolume(float volume) = 0;
virtual void SetSoundVolume(float volume) = 0;
virtual void Update() = 0;

protected:
template<class T> class RingQueue
{
public:
RingQueue<T>()
{
Data = nullptr;
Len = 0;
Num = 0;
Current = 0;
}

RingQueue<T>(size_t n)
{
Data = static_cast<T*>(malloc(sizeof(T) * n));
Len = n;
Num = 0;
Current = 0;
}

RingQueue<T>(size_t n, const T& Value)
{
Data = static_cast<T*>(malloc(sizeof(T) * n));
for (int i = 0; i < n; i++)
Data[i] = Value;

Len = n;
Num = 0;
Current = 0;
}

~RingQueue<T>()
{
free(Data);
}

bool Empty()
{
return (Num == 0);
}

size_t Size()
{
return Num;
}

T& Front()
{
return Data[Current];
}

T& GetNextFree()
{
size_t Index = Current + Num;
if (Index >= Len)
Index -= Len;

return Data[Index];
}

bool Push(const T& Val)
{
if (Num == Len)
return false;

GetNextFree() = Val;
Num++;

return true;
}

bool Push(T& Val)
{
if (Num == Len)
return false;

GetNextFree() = Val;
Num++;

return true;
}

T& Pop()
{
T& Out = Data[Current];
if (Num > 0)
{
Current++;
if (Current >= Len)
Current = 0;

Num--;
}
return Out;
}

bool Resize(size_t NewSize)
{
T* NewData = static_cast<T*>(realloc(Data, sizeof(T) * NewSize));
if (NewData == NULL)
return false;

Data = NewData;
Len = NewSize;
return true;
}

void Clear()
{
Current = 0;
Num = 0;
}

private:
T* Data;
size_t Len;
size_t Current;
size_t Num;
};
template<class T> class RingQueue
{
public:
RingQueue<T>()
{
Data = nullptr;
Len = 0;
Num = 0;
Current = 0;
}

RingQueue<T>(size_t n)
{
Data = static_cast<T*>(malloc(sizeof(T) * n));
Len = n;
Num = 0;
Current = 0;
}

RingQueue<T>(size_t n, const T& Value)
{
Data = static_cast<T*>(malloc(sizeof(T) * n));
for (int i = 0; i < n; i++)
Data[i] = Value;

Len = n;
Num = 0;
Current = 0;
}

~RingQueue<T>()
{
free(Data);
}

bool Empty()
{
return (Num == 0);
}

size_t Size()
{
return Num;
}

T& Front()
{
return Data[Current];
}

T& GetNextFree()
{
size_t Index = Current + Num;
if (Index >= Len)
Index -= Len;

return Data[Index];
}

bool Push(const T& Val)
{
if (Num == Len)
return false;

GetNextFree() = Val;
Num++;

return true;
}

bool Push(T& Val)
{
if (Num == Len)
return false;

GetNextFree() = Val;
Num++;

return true;
}

T& Pop()
{
T& Out = Data[Current];
if (Num > 0)
{
Current++;
if (Current >= Len)
Current = 0;

Num--;
}
return Out;
}

bool Resize(size_t NewSize)
{
T* NewData = static_cast<T*>(realloc(Data, sizeof(T) * NewSize));
if (NewData == NULL)
return false;

Data = NewData;
Len = NewSize;
return true;
}

void Clear()
{
Current = 0;
Num = 0;
}

private:
T* Data = nullptr;
size_t Len = 0;
size_t Current = 0;
size_t Num = 0;
};

int frequency = 48000;
std::vector<USound*> sounds;
std::unique_ptr<AudioSource> music;

std::mutex playbackMutex;
std::unique_ptr<std::thread> playbackThread;
bool bExit;

RingQueue<float*> musicQueue;
int musicBufferCount;
int musicBufferSize;
float* musicBuffer;
bool musicUpdate = false;
bool bMusicTransition = false;
bool bMusicPlaying = false;
float currentMusicVolume;
float targetMusicVolume;
float fadeRate = 0.0;
std::vector<USound*> sounds;
std::unique_ptr<AudioSource> music;

std::mutex playbackMutex;
std::unique_ptr<std::thread> playbackThread;
bool bExit = false;

RingQueue<float*> musicQueue;
int musicBufferCount = 0;
int musicBufferSize = 0;
float* musicBuffer = nullptr;
bool musicUpdate = false;
bool bMusicTransition = false;
bool bMusicPlaying = false;
float currentMusicVolume = 0.0f;
float targetMusicVolume = 0.0f;
float fadeRate = 0.0f;
};

0 comments on commit 58b05b3

Please sign in to comment.