Skip to content

Commit

Permalink
Properly clear buffer (#52)
Browse files Browse the repository at this point in the history
  • Loading branch information
drfiemost committed Oct 24, 2024
1 parent 9a90250 commit c37df27
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/audio/AudioBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#define AUDIOBASE_H

#include <string>
#include <cstring>

#include "IAudio.h"
#include "AudioConfig.h"
Expand Down Expand Up @@ -69,6 +70,8 @@ class AudioBase : public IAudio

short *buffer() const override { return _sampleBuffer; }

void clearBuffer() override { std::memset(_sampleBuffer, 0, _settings.getBufBytes()); }

void getConfig(AudioConfig &cfg) const override
{
cfg = _settings;
Expand Down
2 changes: 2 additions & 0 deletions src/audio/AudioConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ class AudioConfig
precision(16),
channels(1),
bufSize(0) {}

uint_least32_t getBufBytes() const { return bufSize * channels * (precision/8); }
};

#endif // AUDIOCONFIG_H
1 change: 1 addition & 0 deletions src/audio/AudioDrv.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class audioDrv : public IAudio
void close() override { audio->close(); }
void pause() override { audio->pause(); }
short *buffer() const override { return audio->buffer(); }
void clearBuffer() override { audio->clearBuffer(); }
void getConfig(AudioConfig &cfg) const override { audio->getConfig(cfg); }
const char *getErrorString() const override { return audio->getErrorString(); }
};
Expand Down
1 change: 1 addition & 0 deletions src/audio/IAudio.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class IAudio
virtual void close() = 0;
virtual void pause() = 0;
virtual short *buffer() const = 0;
virtual void clearBuffer() = 0;
virtual void getConfig(AudioConfig &cfg) const = 0;
virtual const char *getErrorString() const = 0;
};
Expand Down
2 changes: 1 addition & 1 deletion src/player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1026,7 +1026,7 @@ uint_least32_t ConsolePlayer::getBufSize()
{ // Switch audio drivers.
m_timer.starting = false;
m_driver.selected = m_driver.device;
memset(m_driver.selected->buffer (), 0, m_driver.cfg.bufSize); // FIXME
m_driver.selected->clearBuffer();
m_speed.current = 1;
m_engine.fastForward(100);
if (m_cpudebug)
Expand Down

0 comments on commit c37df27

Please sign in to comment.