mirror of https://github.com/jorio/Pomme.git
cmixer::SourceMixGuard
This commit is contained in:
parent
8152ef04c9
commit
d83a70ea70
|
@ -61,56 +61,35 @@ namespace cmixer
|
||||||
double pan; // Pan set by `cm_set_pan()`
|
double pan; // Pan set by `cm_set_pan()`
|
||||||
std::function<void()> onComplete; // Callback
|
std::function<void()> onComplete; // Callback
|
||||||
|
|
||||||
|
private:
|
||||||
void ClearPrivate();
|
void ClearPrivate();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
Source();
|
Source();
|
||||||
|
|
||||||
void Init(int samplerate, int length);
|
void Init(int samplerate, int length);
|
||||||
|
|
||||||
virtual void RewindImplementation() = 0;
|
virtual void RewindImplementation() = 0;
|
||||||
|
|
||||||
virtual void ClearImplementation() = 0;
|
virtual void ClearImplementation() = 0;
|
||||||
|
|
||||||
virtual void FillBuffer(int16_t* buffer, int length) = 0;
|
virtual void FillBuffer(int16_t* buffer, int length) = 0;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
virtual ~Source();
|
virtual ~Source();
|
||||||
|
|
||||||
void RemoveFromMixer();
|
void RemoveFromMixer();
|
||||||
|
|
||||||
void Clear();
|
void Clear();
|
||||||
|
|
||||||
void Rewind();
|
void Rewind();
|
||||||
|
|
||||||
void RecalcGains();
|
void RecalcGains();
|
||||||
|
|
||||||
void FillBuffer(int offset, int length);
|
void FillBuffer(int offset, int length);
|
||||||
|
|
||||||
void Process(int len);
|
void Process(int len);
|
||||||
|
|
||||||
double GetLength() const;
|
double GetLength() const;
|
||||||
|
|
||||||
double GetPosition() const;
|
double GetPosition() const;
|
||||||
|
|
||||||
int GetState() const;
|
int GetState() const;
|
||||||
|
|
||||||
void SetGain(double gain);
|
void SetGain(double gain);
|
||||||
|
|
||||||
void SetPan(double pan);
|
void SetPan(double pan);
|
||||||
|
|
||||||
void SetPitch(double pitch);
|
void SetPitch(double pitch);
|
||||||
|
|
||||||
void SetLoop(bool loop);
|
void SetLoop(bool loop);
|
||||||
|
|
||||||
void SetInterpolation(bool interpolation);
|
void SetInterpolation(bool interpolation);
|
||||||
|
|
||||||
void Play();
|
void Play();
|
||||||
|
|
||||||
void Pause();
|
void Pause();
|
||||||
|
|
||||||
void TogglePause();
|
void TogglePause();
|
||||||
|
|
||||||
void Stop();
|
void Stop();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -124,42 +103,31 @@ namespace cmixer
|
||||||
std::vector<char> userBuffer;
|
std::vector<char> userBuffer;
|
||||||
|
|
||||||
void ClearImplementation() override;
|
void ClearImplementation() override;
|
||||||
|
|
||||||
void RewindImplementation() override;
|
void RewindImplementation() override;
|
||||||
|
|
||||||
void FillBuffer(int16_t* buffer, int length) override;
|
void FillBuffer(int16_t* buffer, int length) override;
|
||||||
|
|
||||||
inline uint8_t* data8() const
|
inline uint8_t* data8() const { return reinterpret_cast<uint8_t*>(span.data()); }
|
||||||
{ return reinterpret_cast<uint8_t*>(span.data()); }
|
inline int16_t* data16() const { return reinterpret_cast<int16_t*>(span.data()); }
|
||||||
|
|
||||||
inline int16_t* data16() const
|
|
||||||
{ return reinterpret_cast<int16_t*>(span.data()); }
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
WavStream();
|
WavStream();
|
||||||
|
void Init(int theSampleRate, int theBitDepth, int nChannels, bool bigEndian, std::span<char> data);
|
||||||
void Init(
|
|
||||||
int theSampleRate,
|
|
||||||
int theBitDepth,
|
|
||||||
int nChannels,
|
|
||||||
bool bigEndian,
|
|
||||||
std::span<char> data
|
|
||||||
);
|
|
||||||
|
|
||||||
std::span<char> GetBuffer(int nBytesOut);
|
std::span<char> GetBuffer(int nBytesOut);
|
||||||
|
|
||||||
std::span<char> SetBuffer(std::vector<char>&& data);
|
std::span<char> SetBuffer(std::vector<char>&& data);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Guard class that safely removes the source from the mixer when the guard object is destroyed.
|
||||||
|
class SourceMixGuard
|
||||||
|
{
|
||||||
|
Source& source;
|
||||||
|
|
||||||
|
public:
|
||||||
|
SourceMixGuard(Source& theSource) : source(theSource) {}
|
||||||
|
~SourceMixGuard() { source.RemoveFromMixer(); }
|
||||||
|
};
|
||||||
|
|
||||||
void InitWithSDL();
|
void InitWithSDL();
|
||||||
|
|
||||||
void ShutdownWithSDL();
|
void ShutdownWithSDL();
|
||||||
|
|
||||||
double GetMasterGain();
|
double GetMasterGain();
|
||||||
|
|
||||||
void SetMasterGain(double);
|
void SetMasterGain(double);
|
||||||
|
|
||||||
WavStream LoadWAVFromFile(const char* path);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue