feat(audio): formalize runtime effects and wav loading
This commit is contained in:
@@ -11,7 +11,7 @@ public:
|
||||
Equalizer();
|
||||
~Equalizer() override;
|
||||
|
||||
void ProcessAudio(float* buffer, uint32 sampleCount, uint32 channels) override;
|
||||
void ProcessAudio(float* buffer, uint32 frameCount, uint32 channels) override;
|
||||
|
||||
void SetBandCount(uint32 count);
|
||||
uint32 GetBandCount() const { return m_bandCount; }
|
||||
@@ -30,13 +30,15 @@ public:
|
||||
|
||||
void SetWetMix(float wetMix) override;
|
||||
float GetWetMix() const override { return m_wetMix; }
|
||||
void SetSampleRate(uint32 sampleRate) override;
|
||||
void ResetState() override;
|
||||
|
||||
private:
|
||||
void ProcessBand(float* buffer, uint32 sampleCount, uint32 channel, uint32 band);
|
||||
void EnsureStateCapacity(uint32 channels);
|
||||
void ComputeCoefficients(uint32 band, float frequency, float q, float gainDb);
|
||||
|
||||
private:
|
||||
uint32 m_bandCount = 4;
|
||||
uint32 m_bandCount = 0;
|
||||
std::vector<float> m_frequencies;
|
||||
std::vector<float> m_gains;
|
||||
std::vector<float> m_qs;
|
||||
@@ -54,11 +56,8 @@ private:
|
||||
};
|
||||
|
||||
std::vector<BandState> m_bandStates;
|
||||
uint32 m_stateChannels = 0;
|
||||
|
||||
float m_wetMix = 1.0f;
|
||||
bool m_enabled = true;
|
||||
|
||||
uint32 m_sampleRate = 48000;
|
||||
};
|
||||
|
||||
} // namespace Audio
|
||||
|
||||
@@ -12,13 +12,14 @@ public:
|
||||
explicit FFTFilter(uint32 fftSize);
|
||||
~FFTFilter() override;
|
||||
|
||||
void ProcessAudio(float* buffer, uint32 sampleCount, uint32 channels) override;
|
||||
void ProcessAudio(float* buffer, uint32 frameCount, uint32 channels) override;
|
||||
|
||||
void SetFFTSize(uint32 size);
|
||||
uint32 GetFFTSize() const { return m_fftSize; }
|
||||
|
||||
void SetSmoothingFactor(float factor);
|
||||
float GetSmoothingFactor() const { return m_smoothingFactor; }
|
||||
void ResetState() override;
|
||||
|
||||
const float* GetSpectrumData() const { return m_spectrumData.data(); }
|
||||
size_t GetSpectrumSize() const { return m_spectrumData.size(); }
|
||||
|
||||
@@ -24,7 +24,7 @@ public:
|
||||
HRTF();
|
||||
~HRTF();
|
||||
|
||||
void ProcessAudio(float* buffer, uint32 sampleCount, uint32 channels,
|
||||
void ProcessAudio(float* buffer, uint32 frameCount, uint32 channels,
|
||||
const Math::Vector3& sourcePosition,
|
||||
const Math::Vector3& listenerPosition,
|
||||
const Math::Quaternion& listenerRotation);
|
||||
@@ -46,6 +46,9 @@ public:
|
||||
|
||||
void SetSpeedOfSound(float speed);
|
||||
float GetSpeedOfSound() const { return m_speedOfSound; }
|
||||
void SetSampleRate(uint32 sampleRate);
|
||||
uint32 GetSampleRate() const { return m_sampleRate; }
|
||||
void ResetState();
|
||||
|
||||
private:
|
||||
void ComputeDirection(const Math::Vector3& sourcePosition,
|
||||
@@ -56,8 +59,8 @@ private:
|
||||
void ComputeILD(float azimuth, float elevation);
|
||||
float ComputePinnaEffect(float azimuth, float elevation);
|
||||
|
||||
void ApplyHRTF(float* buffer, uint32 sampleCount, uint32 channels);
|
||||
void ApplySimplePanning(float* buffer, uint32 sampleCount, uint32 channels, float pan);
|
||||
void ApplyHRTF(float* buffer, uint32 frameCount, uint32 channels);
|
||||
void ApplySimplePanning(float* buffer, uint32 frameCount, uint32 channels, float pan);
|
||||
|
||||
private:
|
||||
bool m_enabled = true;
|
||||
|
||||
@@ -9,7 +9,7 @@ class IAudioEffect {
|
||||
public:
|
||||
virtual ~IAudioEffect() = default;
|
||||
|
||||
virtual void ProcessAudio(float* buffer, uint32 sampleCount, uint32 channels) = 0;
|
||||
virtual void ProcessAudio(float* buffer, uint32 frameCount, uint32 channels) = 0;
|
||||
|
||||
virtual void SetEnabled(bool enabled) { m_enabled = enabled; }
|
||||
virtual bool IsEnabled() const { return m_enabled; }
|
||||
@@ -17,9 +17,17 @@ public:
|
||||
virtual void SetWetMix(float wetMix) { m_wetMix = wetMix; }
|
||||
virtual float GetWetMix() const { return m_wetMix; }
|
||||
|
||||
virtual void SetSampleRate(uint32 sampleRate) {
|
||||
m_sampleRate = sampleRate > 0 ? sampleRate : 1u;
|
||||
}
|
||||
virtual uint32 GetSampleRate() const { return m_sampleRate; }
|
||||
|
||||
virtual void ResetState() {}
|
||||
|
||||
protected:
|
||||
bool m_enabled = true;
|
||||
float m_wetMix = 1.0f;
|
||||
uint32 m_sampleRate = 48000;
|
||||
};
|
||||
|
||||
} // namespace Audio
|
||||
|
||||
@@ -11,7 +11,7 @@ public:
|
||||
Reverbation();
|
||||
~Reverbation() override;
|
||||
|
||||
void ProcessAudio(float* buffer, uint32 sampleCount, uint32 channels) override;
|
||||
void ProcessAudio(float* buffer, uint32 frameCount, uint32 channels) override;
|
||||
|
||||
void SetRoomSize(float size);
|
||||
float GetRoomSize() const { return m_roomSize; }
|
||||
@@ -30,19 +30,10 @@ public:
|
||||
|
||||
void SetFreeze(bool freeze);
|
||||
bool IsFreeze() const { return m_freeze; }
|
||||
void SetSampleRate(uint32 sampleRate) override;
|
||||
void ResetState() override;
|
||||
|
||||
private:
|
||||
void ProcessCombFilter(float* buffer, uint32 sampleCount, uint32 channel, uint32 combIndex);
|
||||
void ProcessAllPassFilter(float* buffer, uint32 sampleCount, uint32 channel);
|
||||
|
||||
private:
|
||||
float m_roomSize = 0.5f;
|
||||
float m_damping = 0.5f;
|
||||
float m_wetMix = 0.3f;
|
||||
float m_dryMix = 0.7f;
|
||||
float m_width = 1.0f;
|
||||
bool m_freeze = false;
|
||||
|
||||
static constexpr uint32 CombCount = 8;
|
||||
static constexpr uint32 AllPassCount = 4;
|
||||
static constexpr uint32 MaxDelayLength = 2000;
|
||||
@@ -61,13 +52,28 @@ private:
|
||||
std::vector<float> buffer;
|
||||
uint32 bufferSize = 0;
|
||||
uint32 writeIndex = 0;
|
||||
float feedback = 0.0f;
|
||||
float feedback = 0.5f;
|
||||
};
|
||||
|
||||
CombFilter m_combFilters[CombCount];
|
||||
AllPassFilter m_allPassFilters[AllPassCount];
|
||||
struct ChannelState {
|
||||
CombFilter combFilters[CombCount];
|
||||
AllPassFilter allPassFilters[AllPassCount];
|
||||
};
|
||||
|
||||
uint32 m_sampleRate = 48000;
|
||||
void EnsureChannelState(uint32 channels);
|
||||
void InitializeChannelState(ChannelState& state, uint32 channelIndex);
|
||||
void UpdateCombParameters();
|
||||
float ProcessChannelSample(uint32 channelIndex, float inputSample);
|
||||
|
||||
private:
|
||||
float m_roomSize = 0.5f;
|
||||
float m_damping = 0.5f;
|
||||
float m_dryMix = 0.7f;
|
||||
float m_width = 1.0f;
|
||||
bool m_freeze = false;
|
||||
|
||||
std::vector<ChannelState> m_channelStates;
|
||||
uint32 m_stateChannels = 0;
|
||||
};
|
||||
|
||||
} // namespace Audio
|
||||
|
||||
Reference in New Issue
Block a user