Skip to content

Commit

Permalink
Some more effect tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
guusw committed Sep 23, 2016
1 parent b0bf2fe commit fc919e3
Show file tree
Hide file tree
Showing 9 changed files with 207 additions and 93 deletions.
20 changes: 16 additions & 4 deletions Audio/src/AudioStream_ogg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,23 @@ class AudioStreamOGG_Impl : public AudioStreamBase
int32 r = ov_read_float(&m_ovf, &readBuffer, m_bufferSize, 0);
if(r > 0)
{
// Copy data to read buffer
for(int32 i = 0; i < r; i++)
if(m_info->channels == 1)
{
m_readBuffer[0][i] = readBuffer[0][i];
m_readBuffer[1][i] = readBuffer[1][i];
// Copy mono to read buffer
for(int32 i = 0; i < r; i++)
{
m_readBuffer[0][i] = readBuffer[0][i];
m_readBuffer[1][i] = readBuffer[0][i];
}
}
else
{
// Copy data to read buffer
for(int32 i = 0; i < r; i++)
{
m_readBuffer[0][i] = readBuffer[0][i];
m_readBuffer[1][i] = readBuffer[1][i];
}
}
m_currentBufferSize = r;
m_remainingBufferData = r;
Expand Down
16 changes: 13 additions & 3 deletions Audio/src/DSP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include "DSP.hpp"
#include "AudioOutput.hpp"
#include "Audio_Impl.hpp"
#include <Shared/Interpolation.hpp>

void PanDSP::Process(float* out, uint32 numSamples)
{
Expand Down Expand Up @@ -305,14 +306,23 @@ void WobbleDSP::SetLength(uint32 length)
}
void WobbleDSP::Process(float* out, uint32 numSamples)
{
static Interpolation::CubicBezier easing(Interpolation::EaseInExpo);
for(uint32 i = 0; i < numSamples; i++)
{
float f = abs(2.0f * ((float)m_currentSample / (float)m_length) - 1.0f);
f = 1.0f - pow(f, 1.5f) * 0.4f;
float freq = (float)pow(22000.0f, f);
SetLowPass(0.7f, freq);
f = easing.Sample(f);
float freq = 25.0f + 24000.0f * f;
SetLowPass(2.0f + 2.5f * f, freq);

float s[2] = { out[i * 2], out[i * 2 + 1] };

BQFDSP::Process(&out[i * 2], 1);

// Apply slight mixing
float mix = 0.5f;
out[i * 2 + 0] = out[i * 2 + 0] * mix + s[0] * (1.0f - mix);
out[i * 2 + 1] = out[i * 2 + 1] * mix + s[1] * (1.0f - mix);

m_currentSample++;
m_currentSample %= m_length;
}
Expand Down
29 changes: 13 additions & 16 deletions Beatmap/src/AudioEffects.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,34 +40,30 @@ static AudioEffect CreateDefault(EffectType type)
// Default timing is 1/4
ret.duration = TimeRange(0.25f);

Interpolation::CubicBezier laserEasingCurve = Interpolation::EaseInExpo;
Interpolation::CubicBezier lpfEasingCurve = Interpolation::EaseOutCubic;

// Set defaults based on effect type
switch(type)
{
// These are assumed to mostly be laser effect types (at least when used with the defaults)
case EffectType::PeakingFilter:
{
Interpolation::Predefined easing = Interpolation::EaseInCubic;
ret.peaking.freq = FloatRange(100.0f, 7000.0f, easing);
ret.peaking.q = FloatRange(0.1f, 0.5f, easing);
ret.peaking.gain = FloatRange(20.0f, 28.0f, easing);
ret.peaking.freq = FloatRange(80.0f, 8000.0f, laserEasingCurve);
ret.peaking.q = FloatRange(1.f, 0.8f);
ret.peaking.gain = FloatRange(20.0f, 20.0f);
break;
}
case EffectType::LowPassFilter:
{
Interpolation::Predefined easing = Interpolation::EaseOutCubic;
ret.lpf.freq = FloatRange(8000.0f, 200.0f, easing);
ret.lpf.q = FloatRange(4.0f, 3.0f, easing);
ret.lpf.gain = FloatRange(5.0f, 10.0f, easing);
ret.lpf.peakQ = FloatRange(1.0f, 0.5f, easing);
ret.lpf.freq = FloatRange(10000.0f, 700.0f, lpfEasingCurve);
ret.lpf.q = FloatRange(7.0f, 10.0f);
break;
}
case EffectType::HighPassFilter:
{
Interpolation::Predefined easing = Interpolation::EaseInCubic;
ret.hpf.freq = FloatRange(100.0f, 2000.0f, easing);
ret.hpf.q = FloatRange(1.0f, 1.0f);
ret.hpf.gain = FloatRange(10.0f, 5.0f, easing);
ret.hpf.peakQ = FloatRange(1.0f, 0.5f, easing);
ret.hpf.freq = FloatRange(80.0f, 2000.0f, laserEasingCurve);
ret.hpf.q = FloatRange(10.0f, 5.0f);
break;
}
case EffectType::Bitcrush:
Expand All @@ -90,8 +86,9 @@ static AudioEffect CreateDefault(EffectType type)
break;
case EffectType::Phaser:
ret.phaser.min = FloatRange(400.0f);
ret.phaser.max = FloatRange(8000.0f);
ret.phaser.feedback = FloatRange(0.3f);
ret.phaser.max = FloatRange(4000.0f);
ret.phaser.feedback = FloatRange(0.5f);
ret.duration = TimeRange(1.0f);
break;
case EffectType::Wobble:
// wobble is 1/12 by default
Expand Down
45 changes: 44 additions & 1 deletion Main/Audio/AudioPlayback.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,50 @@ void AudioPlayback::m_SetLaserEffectParameter(float input)
return;
assert(input >= 0.0f && input <= 1.0f);

m_laserEffect.UpdateDSP(m_laserDSP, *this, input);
// Mix for normal effects
m_laserDSP->mix = m_laserEffectMix;

// Mix float biquad filters, these are applied manualy by changing the filter parameters (gain,q,freq,etc.)
float mix = m_laserEffectMix;
if(input < 0.1f)
mix *= input / 0.1f;

switch(m_laserEffectType)
{
case EffectType::Bitcrush:
{
BitCrusherDSP* bcDSP = (BitCrusherDSP*)m_laserDSP;
bcDSP->SetPeriod((float)m_laserEffect.bitcrusher.reduction.Sample(input));
break;
}
case EffectType::Echo:
{
EchoDSP* echoDSP = (EchoDSP*)m_laserDSP;
echoDSP->feedback = m_laserEffect.echo.feedback.Sample(input);
break;
}
case EffectType::PeakingFilter:
{
if(input > 0.8f)
mix *= 1.0f - (input - 0.8f) / 0.2f;

BQFDSP* bqfDSP = (BQFDSP*)m_laserDSP;
bqfDSP->SetPeaking(m_laserEffect.peaking.q.Sample(input), m_laserEffect.peaking.freq.Sample(input), m_laserEffect.peaking.gain.Sample(input) * mix);
break;
}
case EffectType::LowPassFilter:
{
BQFDSP* bqfDSP = (BQFDSP*)m_laserDSP;
bqfDSP->SetLowPass(m_laserEffect.lpf.q.Sample(input) * mix + 0.1f, m_laserEffect.lpf.freq.Sample(input));
break;
}
case EffectType::HighPassFilter:
{
BQFDSP* bqfDSP = (BQFDSP*)m_laserDSP;
bqfDSP->SetHighPass(m_laserEffect.hpf.q.Sample(input) * mix + 0.1f, m_laserEffect.hpf.freq.Sample(input));
break;
}
}
}

GameAudioEffect::GameAudioEffect(const AudioEffect& other)
Expand Down
2 changes: 0 additions & 2 deletions Main/Audio/AudioPlayback.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ struct GameAudioEffect : public AudioEffect
DSP* CreateDSP(class AudioBase* audioTrack, AudioPlayback& playback);
// Applies the given parameters overriding some settings for this effect (depending on the effect)
void SetParams(DSP* dsp, AudioPlayback& playback, HoldObjectState* object);
// Updates all variable parameters on a DSP created with CreateDSP with laser input values
void UpdateDSP(DSP* dsp, AudioPlayback& playback, float filterInput);
};

/*
Expand Down
56 changes: 2 additions & 54 deletions Main/Audio/AudioEffects.cpp → Main/Audio/GameAudioEffects.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,26 +34,12 @@ DSP* GameAudioEffect::CreateDSP(class AudioBase* audioTrack, AudioPlayback& play
break;
}
case EffectType::PeakingFilter:
{
BQFDSP* bqfDSP = new BQFDSP();
audioTrack->AddDSP(bqfDSP);
bqfDSP->SetPeaking(peaking.q.Sample(filterInput), peaking.freq.Sample(filterInput), peaking.gain.Sample(filterInput));
ret = bqfDSP;
break;
}
case EffectType::LowPassFilter:
{
CombinedFilterDSP* bqfDSP = new CombinedFilterDSP();
audioTrack->AddDSP(bqfDSP);
bqfDSP->SetLowPass(lpf.q.Sample(filterInput), lpf.freq.Sample(filterInput), lpf.peakQ.Sample(filterInput), lpf.gain.Sample(filterInput));
ret = bqfDSP;
break;
}
case EffectType::HighPassFilter:
{
CombinedFilterDSP* bqfDSP = new CombinedFilterDSP();
// Don't set anthing for biquad Filters
BQFDSP* bqfDSP = new BQFDSP();
audioTrack->AddDSP(bqfDSP);
bqfDSP->SetHighPass(hpf.q.Sample(filterInput), hpf.freq.Sample(filterInput), hpf.peakQ.Sample(filterInput), hpf.gain.Sample(filterInput));
ret = bqfDSP;
break;
}
Expand Down Expand Up @@ -173,41 +159,3 @@ void GameAudioEffect::SetParams(DSP* dsp, AudioPlayback& playback, HoldObjectSta
}
}
}
void GameAudioEffect::UpdateDSP(DSP* dsp, AudioPlayback& playback, float filterInput)
{
switch(type)
{
case EffectType::Bitcrush:
{
BitCrusherDSP* bcDSP = (BitCrusherDSP*)dsp;
bcDSP->SetPeriod((float)bitcrusher.reduction.Sample(filterInput));
break;
}
case EffectType::Echo:
{
EchoDSP* echoDSP = (EchoDSP*)dsp;
echoDSP->feedback = echo.feedback.Sample(filterInput);
break;
}
case EffectType::PeakingFilter:
{
BQFDSP* bqfDSP = (BQFDSP*)dsp;
bqfDSP->SetPeaking(peaking.q.Sample(filterInput), peaking.freq.Sample(filterInput), peaking.gain.Sample(filterInput));
break;
}
case EffectType::LowPassFilter:
{
CombinedFilterDSP* bqfDSP = (CombinedFilterDSP*)dsp;
bqfDSP->SetLowPass(lpf.q.Sample(filterInput), lpf.freq.Sample(filterInput), lpf.peakQ.Sample(filterInput), lpf.gain.Sample(filterInput));
break;
}
case EffectType::HighPassFilter:
{
CombinedFilterDSP* bqfDSP = (CombinedFilterDSP*)dsp;
bqfDSP->SetHighPass(hpf.q.Sample(filterInput), hpf.freq.Sample(filterInput), hpf.peakQ.Sample(filterInput), hpf.gain.Sample(filterInput));
break;
}
default:
break;
}
}
16 changes: 8 additions & 8 deletions Main/Game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,11 @@ class Game_Impl : public Game
/// TODO: Load this async
CheckedLoad(m_background = CreateBackground(this));

// Do this here so we don't get input events while still loading
m_scoring.SetPlayback(m_playback);
m_scoring.SetInput(&g_input);
m_scoring.Reset(); // Initialize

return true;
}
virtual bool Init() override
Expand Down Expand Up @@ -538,18 +543,16 @@ class Game_Impl : public Game
m_playback.OnFXEnd.Add(this, &Game_Impl::OnFXEnd);
m_playback.Reset();

m_playback.hittableObjectTreshold = Scoring::goodHitTime;

m_scoring.SetPlayback(m_playback);
m_scoring.SetInput(&g_input);
// Register input bindings
m_scoring.OnButtonMiss.Add(this, &Game_Impl::OnButtonMiss);
m_scoring.OnLaserSlamHit.Add(this, &Game_Impl::OnLaserSlamHit);
m_scoring.OnButtonHit.Add(this, &Game_Impl::OnButtonHit);
m_scoring.OnComboChanged.Add(this, &Game_Impl::OnComboChanged);
m_scoring.OnObjectHold.Add(this, &Game_Impl::OnObjectHold);
m_scoring.OnObjectReleased.Add(this, &Game_Impl::OnObjectReleased);
m_scoring.OnScoreChanged.Add(this, &Game_Impl::OnScoreChanged);
m_scoring.Reset(); // Initialize

m_playback.hittableObjectTreshold = Scoring::goodHitTime;

if(g_application->GetAppCommandLine().Contains("-autobuttons"))
{
Expand Down Expand Up @@ -755,9 +758,6 @@ class Game_Impl : public Game
textPos.y += RenderText(Utility::Sprintf("Laser Effect Mix: %f", m_audioPlayback.GetLaserEffectMix()), textPos).y;
textPos.y += RenderText(Utility::Sprintf("Laser Filter Input: %f", m_scoring.GetLaserOutput()), textPos).y;

float test = Interpolation::CubicBezier(Interpolation::EaseInCubic).Sample(m_scoring.GetLaserOutput());
textPos.y += RenderText(Utility::Sprintf("Laser Filter Input (quad): %f", test), textPos).y;

textPos.y += RenderText(Utility::Sprintf("Score: %d (Max: %d)", m_scoring.currentHitScore, m_scoring.mapTotals.maxScore), textPos).y;
textPos.y += RenderText(Utility::Sprintf("Actual Score: %d", m_scoring.CalculateCurrentScore()), textPos).y;

Expand Down
Loading

0 comments on commit fc919e3

Please sign in to comment.