Skip to content

Commit

Permalink
removed final specifier from effect classes
Browse files Browse the repository at this point in the history
  • Loading branch information
ozguronsoy committed Nov 8, 2024
1 parent 002cf68 commit 34b987e
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 49 deletions.
31 changes: 18 additions & 13 deletions HephAudio/HeaderFiles/AudioEffects/Flanger.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,17 @@ namespace HephAudio
* @brief delays the audio data and mixes the result with the input signal.
* The amount of delay applied changes periodically.
*/
class Flanger final : public ModulationEffect
class Flanger : public ModulationEffect
{
public:
using ModulationEffect::Process;

private:
AudioBuffer oldSamples;
protected:
/**
* past samples required for real-time processing.
*/
AudioBuffer pastSamples;

private:
/**
* constant delay in milliseconds.
*/
Expand All @@ -42,37 +44,40 @@ namespace HephAudio
*/
Flanger(double depth, double constantDelay, double variableDelay, const Oscillator& lfo);

std::string Name() const override;
/** @copydoc destructor */
virtual ~Flanger() = default;

void Process(AudioBuffer& buffer, size_t startIndex, size_t frameCount) override;
virtual std::string Name() const override;

virtual void Process(AudioBuffer& buffer, size_t startIndex, size_t frameCount) override;

/**
* gets the constant delay in milliseconds.
*
*/
double GetConstantDelay() const;
virtual double GetConstantDelay() const;

/**
* sets the constant delay in milliseconds.
*
* @param constantDelay @copydetails constantDelay
*/
void SetConstantDelay(double constantDelay);
virtual void SetConstantDelay(double constantDelay);

/**
* gets the variable delay in milliseconds.
* @return
*
*/
double GetVariableDelay() const;
virtual double GetVariableDelay() const;

/**
* sets the variable delay in milliseconds.
*
* @param variableDelay @copydetails variableDelay
*/
void SetVariableDelay(double variableDelay);
virtual void SetVariableDelay(double variableDelay);

private:
void ProcessST(const AudioBuffer& inputBuffer, AudioBuffer& outputBuffer, size_t startIndex, size_t frameCount) override;
protected:
virtual void ProcessST(const AudioBuffer& inputBuffer, AudioBuffer& outputBuffer, size_t startIndex, size_t frameCount) override;
};
}
11 changes: 7 additions & 4 deletions HephAudio/HeaderFiles/AudioEffects/LinearPanning.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace HephAudio
/**
* @brief linearly increases the volume of one channel while decreasing the other one (stereo only).
*/
class LinearPanning final : public PanningEffect
class LinearPanning : public PanningEffect
{
public:
/** @copydoc default_constructor */
Expand All @@ -24,8 +24,11 @@ namespace HephAudio
*/
explicit LinearPanning(double factor);

std::string Name() const override;
double GetFactor() const override;
void SetFactor(double factor) override;
/** @copydoc destructor */
virtual ~LinearPanning() = default;

virtual std::string Name() const override;
virtual double GetFactor() const override;
virtual void SetFactor(double factor) override;
};
}
11 changes: 7 additions & 4 deletions HephAudio/HeaderFiles/AudioEffects/SineLawPanning.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace HephAudio
* @brief increases the volume of one channel while decreasing the other one (stereo only).
* Uses sin function to calculate the volumes.
*/
class SineLawPanning final : public PanningEffect
class SineLawPanning : public PanningEffect
{
public:
/** @copydoc default_constructor */
Expand All @@ -25,8 +25,11 @@ namespace HephAudio
*/
explicit SineLawPanning(double factor);

std::string Name() const override;
double GetFactor() const override;
void SetFactor(double factor) override;
/** @copydoc destructor */
virtual ~SineLawPanning() = default;

virtual std::string Name() const override;
virtual double GetFactor() const override;
virtual void SetFactor(double factor) override;
};
}
11 changes: 7 additions & 4 deletions HephAudio/HeaderFiles/AudioEffects/SquareLawPanning.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace HephAudio
* @brief increases the volume of one channel while decreasing the other one (stereo only).
* Uses square root to calculate the volumes.
*/
class SquareLawPanning final : public PanningEffect
class SquareLawPanning : public PanningEffect
{
public:
/** @copydoc default_constructor */
Expand All @@ -25,8 +25,11 @@ namespace HephAudio
*/
explicit SquareLawPanning(double factor);

std::string Name() const override;
double GetFactor() const override;
void SetFactor(double factor) override;
/** @copydoc destructor */
virtual ~SquareLawPanning() = default;

virtual std::string Name() const override;
virtual double GetFactor() const override;
virtual void SetFactor(double factor) override;
};
}
13 changes: 8 additions & 5 deletions HephAudio/HeaderFiles/AudioEffects/Tremolo.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace HephAudio
/**
* @brief changes the volume of the audio data periodically and mixes the result with the input signal.
*/
class Tremolo final : public ModulationEffect
class Tremolo : public ModulationEffect
{
public:
using ModulationEffect::Process;
Expand All @@ -19,12 +19,15 @@ namespace HephAudio

/** @copydoc ModulationEffect(double, const Oscillator&) */
Tremolo(double depth, const Oscillator& lfo);

/** @copydoc destructor */
virtual ~Tremolo() = default;

std::string Name() const override;
virtual std::string Name() const override;

void Process(AudioBuffer& buffer, size_t startIndex, size_t frameCount) override;
virtual void Process(AudioBuffer& buffer, size_t startIndex, size_t frameCount) override;

private:
void ProcessST(const AudioBuffer& inputBuffer, AudioBuffer& outputBuffer, size_t startIndex, size_t endIndex) override;
protected:
virtual void ProcessST(const AudioBuffer& inputBuffer, AudioBuffer& outputBuffer, size_t startIndex, size_t endIndex) override;
};
}
19 changes: 11 additions & 8 deletions HephAudio/HeaderFiles/AudioEffects/Vibrato.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ namespace HephAudio
*
* @note this is a non-causal effect.
*/
class Vibrato final : public ModulationEffect
class Vibrato : public ModulationEffect
{
private:
protected:
/**
* maximum pitch change in terms of semitones.
*/
Expand All @@ -30,25 +30,28 @@ namespace HephAudio
*/
Vibrato(double depth, double extent, const Oscillator& lfo);

std::string Name() const override;
/** @copydoc destructor */
virtual ~Vibrato() = default;

size_t CalculateRequiredFrameCount(size_t outputFrameCount, const AudioFormatInfo& formatInfo) const override;
virtual std::string Name() const override;

virtual size_t CalculateRequiredFrameCount(size_t outputFrameCount, const AudioFormatInfo& formatInfo) const override;

/**
* gets the @copydetails extent.
*
*/
double GetExtent() const;
virtual double GetExtent() const;

/**
* sets extent.
*
* @param extent @copydetails extent
*
*/
void SetExtent(double extent);
virtual void SetExtent(double extent);

private:
void ProcessST(const AudioBuffer& inputBuffer, AudioBuffer& outputBuffer, size_t startIndex, size_t frameCount) override;
protected:
virtual void ProcessST(const AudioBuffer& inputBuffer, AudioBuffer& outputBuffer, size_t startIndex, size_t frameCount) override;
};
}
22 changes: 11 additions & 11 deletions HephAudio/SourceFiles/AudioEffects/Flanger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,25 +21,25 @@ namespace HephAudio
const AudioFormatInfo& formatInfo = buffer.FormatInfo();
const size_t maxDelay_sample = ceil((this->constantDelay + this->variableDelay) * 1e-3 * formatInfo.sampleRate);

if (this->oldSamples.FormatInfo().sampleRate != formatInfo.sampleRate)
if (this->pastSamples.FormatInfo().sampleRate != formatInfo.sampleRate)
{
this->oldSamples = AudioBuffer(maxDelay_sample, formatInfo.channelLayout, formatInfo.sampleRate);
this->pastSamples = AudioBuffer(maxDelay_sample, formatInfo.channelLayout, formatInfo.sampleRate);
}
else if (this->oldSamples.FrameCount() != maxDelay_sample)
else if (this->pastSamples.FrameCount() != maxDelay_sample)
{
if (maxDelay_sample > this->oldSamples.FrameCount())
if (maxDelay_sample > this->pastSamples.FrameCount())
{
this->oldSamples.Resize(maxDelay_sample);
this->oldSamples >>= maxDelay_sample - this->oldSamples.FrameCount();
this->pastSamples.Resize(maxDelay_sample);
this->pastSamples >>= maxDelay_sample - this->pastSamples.FrameCount();
}
else
{
this->oldSamples <<= this->oldSamples.FrameCount() - maxDelay_sample;
this->oldSamples.Resize(maxDelay_sample);
this->pastSamples <<= this->pastSamples.FrameCount() - maxDelay_sample;
this->pastSamples.Resize(maxDelay_sample);
}
}

AudioBuffer tempBuffer = this->oldSamples;
AudioBuffer tempBuffer = this->pastSamples;
if (buffer.FrameCount() >= maxDelay_sample)
{
const size_t startIndex = buffer.FrameCount() - maxDelay_sample;
Expand All @@ -66,7 +66,7 @@ namespace HephAudio

ModulationEffect::Process(buffer, startIndex, frameCount);

this->oldSamples = std::move(tempBuffer);
this->pastSamples = std::move(tempBuffer);
}

double Flanger::GetConstantDelay() const
Expand Down Expand Up @@ -115,7 +115,7 @@ namespace HephAudio
{
heph_audio_sample_t wetSample = 0;
if (delaySampleIndex < 0)
wetSample = this->oldSamples[this->oldSamples.FrameCount() + delaySampleIndex][j];
wetSample = this->pastSamples[this->pastSamples.FrameCount() + delaySampleIndex][j];
else
wetSample = inputBuffer[delaySampleIndex][j];

Expand Down

0 comments on commit 34b987e

Please sign in to comment.