BackgroundAudio: Switch to a heap allocated buffer.

This commit is contained in:
Henrik Rydgård committed 2020-08-03 10:43:26 +02:00
1 parent 6f02844b5b
commit e13b53e02c
2 files changed
+18 -2

No files matched your search

+9 -1
View File
@@ -226,6 +226,14 @@ private:
BackgroundAudio g_BackgroundAudio;
BackgroundAudio::BackgroundAudio() {
buffer = new int[BUFSIZE]();
}
BackgroundAudio::~BackgroundAudio() {
delete[] buffer;
}
void BackgroundAudio::Clear(bool hard) {
if (!hard) {
fadingOut = true;
@@ -276,7 +284,7 @@ int BackgroundAudio::Play() {
double now = time_now();
if (at3Reader) {
int sz = lastPlaybackTime <= 0.0 ? 44100 / 60 : (int)((now - lastPlaybackTime) * 44100);
sz = std::min((int)ARRAY_SIZE(buffer) / 2, sz);
sz = std::min(BUFSIZE / 2, sz);
if (sz >= 16) {
if (at3Reader->Read(buffer, sz)) {
if (!fadingOut) {
+9 -1
View File
@@ -1,23 +1,31 @@
#pragma once
#include <string>
#include <mutex>
class AT3PlusReader;
class BackgroundAudio {
public:
BackgroundAudio();
~BackgroundAudio();
void Clear(bool hard);
void SetGame(const std::string &path);
void Update();
int Play();
private:
enum {
BUFSIZE = 44100,
};
std::mutex g_bgMutex;
std::string bgGamePath;
int playbackOffset = 0;
AT3PlusReader *at3Reader;
double gameLastChanged = 0.0;
double lastPlaybackTime = 0.0;
int buffer[44100];
int *buffer = nullptr;
bool fadingOut = true;
float volume = 0.0f;
float delta = -0.0001f;