mirror of https://github.com/jorio/Pomme.git
Make Source::Clear thread-safe
This commit is contained in:
parent
e8939dbc8a
commit
9830a8ea48
|
@ -212,11 +212,11 @@ void Mixer::Process(int16_t* dst, int len)
|
|||
|
||||
Source::Source()
|
||||
{
|
||||
ClearPrivate();
|
||||
active = false;
|
||||
Clear();
|
||||
}
|
||||
|
||||
void Source::Clear()
|
||||
void Source::ClearPrivate()
|
||||
{
|
||||
samplerate = 0;
|
||||
length = 0;
|
||||
|
@ -235,6 +235,14 @@ void Source::Clear()
|
|||
onComplete = nullptr;
|
||||
}
|
||||
|
||||
void Source::Clear()
|
||||
{
|
||||
gMixer.Lock();
|
||||
ClearPrivate();
|
||||
ClearImplementation();
|
||||
gMixer.Unlock();
|
||||
}
|
||||
|
||||
void Source::Init(int theSampleRate, int theLength)
|
||||
{
|
||||
this->samplerate = theSampleRate;
|
||||
|
@ -258,7 +266,7 @@ Source::~Source()
|
|||
|
||||
void Source::Rewind()
|
||||
{
|
||||
Rewind2();
|
||||
RewindImplementation();
|
||||
position = 0;
|
||||
rewind = false;
|
||||
end = length;
|
||||
|
@ -468,16 +476,12 @@ void Source::Stop()
|
|||
|
||||
WavStream::WavStream()
|
||||
: Source()
|
||||
, bitdepth(0)
|
||||
, channels(0)
|
||||
, bigEndian(false)
|
||||
, idx(0)
|
||||
, userBuffer()
|
||||
{}
|
||||
|
||||
void WavStream::Clear()
|
||||
{
|
||||
Source::Clear();
|
||||
ClearImplementation();
|
||||
}
|
||||
|
||||
void WavStream::ClearImplementation()
|
||||
{
|
||||
bitdepth = 0;
|
||||
channels = 0;
|
||||
bigEndian = false;
|
||||
|
@ -514,7 +518,7 @@ std::span<char> WavStream::SetBuffer(std::vector<char>&& data)
|
|||
return std::span(userBuffer.data(), userBuffer.size());
|
||||
}
|
||||
|
||||
void WavStream::Rewind2()
|
||||
void WavStream::RewindImplementation()
|
||||
{
|
||||
idx = 0;
|
||||
}
|
||||
|
|
|
@ -59,19 +59,23 @@ namespace cmixer
|
|||
double pan; // Pan set by `cm_set_pan()`
|
||||
std::function<void()> onComplete; // Callback
|
||||
|
||||
void ClearPrivate();
|
||||
|
||||
protected:
|
||||
Source();
|
||||
|
||||
void Init(int samplerate, int length);
|
||||
|
||||
virtual void Rewind2() = 0;
|
||||
virtual void RewindImplementation() = 0;
|
||||
|
||||
virtual void ClearImplementation() = 0;
|
||||
|
||||
virtual void FillBuffer(int16_t* buffer, int length) = 0;
|
||||
|
||||
public:
|
||||
virtual ~Source();
|
||||
|
||||
virtual void Clear();
|
||||
void Clear();
|
||||
|
||||
void Rewind();
|
||||
|
||||
|
@ -113,7 +117,9 @@ namespace cmixer
|
|||
std::span<char> span;
|
||||
std::vector<char> userBuffer;
|
||||
|
||||
void Rewind2() override;
|
||||
void ClearImplementation() override;
|
||||
|
||||
void RewindImplementation() override;
|
||||
|
||||
void FillBuffer(int16_t* buffer, int length) override;
|
||||
|
||||
|
@ -126,8 +132,6 @@ namespace cmixer
|
|||
public:
|
||||
WavStream();
|
||||
|
||||
virtual void Clear() override;
|
||||
|
||||
void Init(
|
||||
int theSampleRate,
|
||||
int theBitDepth,
|
||||
|
|
Loading…
Reference in New Issue