Skip to content

Commit

Permalink
Initial pre-rendering working, added missing files
Browse files Browse the repository at this point in the history
  • Loading branch information
Drewol committed Dec 14, 2020
1 parent a51f916 commit c57092e
Show file tree
Hide file tree
Showing 13 changed files with 436 additions and 240 deletions.
9 changes: 6 additions & 3 deletions Audio/include/Audio/AudioBase.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ class DSP
DSP() = default; // Abstract
DSP(const DSP &) = delete;

inline void SetSampleRate(uint32 sampleRate) { m_sampleRate = sampleRate; }
uint32 GetStartSample() const;
uint32 GetCurrentSample() const;

Expand All @@ -18,14 +17,13 @@ class DSP
uint32 m_sampleRate = 0;

class AudioBase *m_audioBase = nullptr;
class Audio_Impl *m_audio = nullptr;

public:
virtual ~DSP();

void SetAudio(class Audio_Impl *audio);
void SetAudioBase(class AudioBase *audioBase);
inline void RemoveAudioBase() { m_audioBase = nullptr; }
inline void SetSampleRate(uint32 sampleRate) { m_sampleRate = sampleRate; }

// Process <numSamples> amount of samples in stereo float format
virtual void Process(float *out, uint32 numSamples) = 0;
Expand All @@ -34,6 +32,7 @@ class DSP
float mix = 1.0f;
uint32 priority = 0;
uint32 startTime = 0;
uint32 endTime = 0;
int32 chartOffset = 0;
int32 lastTimingPoint = 0;
};
Expand All @@ -54,13 +53,17 @@ class AudioBase
// Get the sample rate of this audio stream
virtual uint32 GetSampleRate() const = 0;

// Get the exact playback position in samples
virtual uint64 GetSamplePos() const = 0;

// Get the sample rate of the audio connected to this
uint32 GetAudioSampleRate() const;

// Gets pcm data from a decoded stream, nullptr if not available
virtual float *GetPCM() = 0;
// Gets pcm sample count
virtual uint64 GetSampleCount() const = 0;
virtual void PreRenderDSPs(Vector<DSP *> &DSPs) = 0;

void ProcessDSPs(float *out, uint32 numSamples);
// Adds a signal processor to the audio
Expand Down
83 changes: 47 additions & 36 deletions Audio/include/Audio/DSP.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ class PanDSP : public DSP
public:
// -1 to 1 LR pan value
float panning = 0.0f;
virtual void Process(float* out, uint32 numSamples);
virtual const char* GetName() const { return "PanDSP"; }
virtual void Process(float *out, uint32 numSamples);
virtual const char *GetName() const { return "PanDSP"; }
};

// Biquad Filter
Expand All @@ -28,8 +28,8 @@ class BQFDSP : public DSP
float a1 = 0.0f;
float a2 = 0.0f;

virtual void Process(float* out, uint32 numSamples);
virtual const char* GetName() const { return "BQFDSP"; }
virtual void Process(float *out, uint32 numSamples);
virtual const char *GetName() const { return "BQFDSP"; }

// Sets the filter parameters
void SetPeaking(float q, float freq, float gain);
Expand All @@ -39,6 +39,7 @@ class BQFDSP : public DSP
void SetPeaking(float q, float freq, float gain, float sampleRate);
void SetLowPass(float q, float freq, float sampleRate);
void SetHighPass(float q, float freq, float sampleRate);

private:
// Delayed samples
static const uint32 order = 2;
Expand All @@ -55,9 +56,10 @@ class CombinedFilterDSP : public DSP
CombinedFilterDSP(uint32 sampleRate);
void SetLowPass(float q, float freq, float peakQ, float peakGain);
void SetHighPass(float q, float freq, float peakQ, float peakGain);
virtual const char* GetName() const { return "CombinedFilterDSP"; }
virtual const char *GetName() const { return "CombinedFilterDSP"; }

virtual void Process(float *out, uint32 numSamples);

virtual void Process(float* out, uint32 numSamples);
private:
BQFDSP a;
BQFDSP peak;
Expand All @@ -70,8 +72,9 @@ class LimiterDSP : public DSP
LimiterDSP(uint32 sampleRate);

float releaseTime = 0.1f;
virtual void Process(float* out, uint32 numSamples);
virtual const char* GetName() const { return "LimiterDSP"; }
virtual void Process(float *out, uint32 numSamples);
virtual const char *GetName() const { return "LimiterDSP"; }

private:
float m_currentMaxVolume = 1.0f;
float m_currentReleaseTimer = releaseTime;
Expand All @@ -84,12 +87,13 @@ class BitCrusherDSP : public DSP

// Duration of samples, <1 = disable
void SetPeriod(float period = 0);
virtual void Process(float* out, uint32 numSamples);
virtual const char* GetName() const { return "BitCrusherDSP"; }
virtual void Process(float *out, uint32 numSamples);
virtual const char *GetName() const { return "BitCrusherDSP"; }

private:
uint32 m_period = 1;
uint32 m_increment = 0;
float m_sampleBuffer[2] = { 0.0f };
float m_sampleBuffer[2] = {0.0f};
uint32 m_currentDuration = 0;
};

Expand All @@ -105,14 +109,15 @@ class GateDSP : public DSP
// Low volume
float low = 0.1f;

virtual void Process(float* out, uint32 numSamples);
virtual const char* GetName() const { return "GateDSP"; }
virtual void Process(float *out, uint32 numSamples);
virtual const char *GetName() const { return "GateDSP"; }

private:
float m_gating = 0.5f;
uint32 m_length = 0;
uint32 m_fadeIn = 0; // Fade In mark
uint32 m_fadeIn = 0; // Fade In mark
uint32 m_fadeOut = 0; // Fade Out mark
uint32 m_halfway; // Halfway mark
uint32 m_halfway; // Halfway mark
uint32 m_currentSample = 0;
};

Expand All @@ -123,8 +128,9 @@ class TapeStopDSP : public DSP

void SetLength(double length);

virtual void Process(float* out, uint32 numSamples);
virtual const char* GetName() const { return "TapeStopDSP"; }
virtual void Process(float *out, uint32 numSamples);
virtual const char *GetName() const { return "TapeStopDSP"; }

private:
uint32 m_length = 0;
Vector<float> m_sampleBuffer;
Expand All @@ -142,8 +148,9 @@ class RetriggerDSP : public DSP
void SetGating(float gating);
void SetMaxLength(uint32 length);

virtual void Process(float* out, uint32 numSamples);
virtual const char* GetName() const { return "RetriggerDSP"; }
virtual void Process(float *out, uint32 numSamples);
virtual const char *GetName() const { return "RetriggerDSP"; }

private:
float m_gating = 0.75f;
uint32 m_length = 0;
Expand All @@ -166,16 +173,17 @@ class WobbleDSP : public BQFDSP
float fmax = 20000.0f;
float q = 1.414f;

virtual void Process(float* out, uint32 numSamples);
virtual const char* GetName() const { return "WobbleDSP"; }
virtual void Process(float *out, uint32 numSamples);
virtual const char *GetName() const { return "WobbleDSP"; }

private:
uint32 m_length;
uint32 m_currentSample = 0;
};

// Referenced http://www.musicdsp.org/files/phaser.cpp
class PhaserDSP : public DSP
{
{
public:
PhaserDSP(uint32 sampleRate);

Expand All @@ -184,13 +192,13 @@ class PhaserDSP : public DSP
// Frequency range
float dmin = 1000.0f;
float dmax = 4000.0f;
float fb = 0.2f; //feedback
float fb = 0.2f; //feedback
float lmix = 0.33f; //local mix

void SetLength(double length);

virtual void Process(float* out, uint32 numSamples);
virtual const char* GetName() const { return "PhaserDSP"; }
virtual void Process(float *out, uint32 numSamples);
virtual const char *GetName() const { return "PhaserDSP"; }

private:
uint32 m_length = 0;
Expand All @@ -204,7 +212,7 @@ class PhaserDSP : public DSP
};

APF filters[2][6];
float za[2] = { 0.0f };
float za[2] = {0.0f};
};

class FlangerDSP : public DSP
Expand All @@ -215,8 +223,9 @@ class FlangerDSP : public DSP
void SetLength(double length);
void SetDelayRange(uint32 min, uint32 max);

virtual void Process(float* out, uint32 numSamples);
virtual const char* GetName() const { return "FlangerDSP"; }
virtual void Process(float *out, uint32 numSamples);
virtual const char *GetName() const { return "FlangerDSP"; }

private:
uint32 m_length = 0;

Expand All @@ -239,16 +248,16 @@ class EchoDSP : public DSP

float feedback = 0.6f;

virtual void Process(float* out, uint32 numSamples);
virtual const char* GetName() const { return "EchoDSP"; }
virtual void Process(float *out, uint32 numSamples);
virtual const char *GetName() const { return "EchoDSP"; }

private:
uint32 m_bufferLength = 0;
size_t m_bufferOffset = 0;
uint32 m_numLoops = 0;
Vector<float> m_sampleBuffer;
};


class SidechainDSP : public DSP
{
public:
Expand All @@ -262,8 +271,9 @@ class SidechainDSP : public DSP

Interpolation::CubicBezier curve;

virtual void Process(float* out, uint32 numSamples);
virtual const char* GetName() const { return "SidechainDSP"; }
virtual void Process(float *out, uint32 numSamples);
virtual const char *GetName() const { return "SidechainDSP"; }

private:
uint32 m_length = 0;
size_t m_time = 0;
Expand All @@ -279,8 +289,9 @@ class PitchShiftDSP : public DSP

~PitchShiftDSP();

virtual void Process(float* out, uint32 numSamples);
virtual const char* GetName() const { return "PitchShiftDSP"; }
virtual void Process(float *out, uint32 numSamples);
virtual const char *GetName() const { return "PitchShiftDSP"; }

private:
class PitchShiftDSP_Impl* m_impl;
class PitchShiftDSP_Impl *m_impl;
};
Loading

0 comments on commit c57092e

Please sign in to comment.