Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unleash the Chipmunks and the Demons #231

Merged
merged 1 commit into from
May 2, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 13 additions & 6 deletions Assets/Script/Audio/Bass/BassStemChannel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,17 +86,24 @@ public int Load(bool isSpeedUp, float speed) {

if (isSpeedUp) {
// Gets relative speed from 100% (so 1.05f = 5% increase)
float relativeSpeed = Math.Abs(speed) * 100;
relativeSpeed -= 100;
float percentageSpeed = Math.Abs(speed) * 100;
float relativeSpeed = percentageSpeed - 100;

Bass.ChannelSetAttribute(StreamHandle, ChannelAttribute.Tempo, relativeSpeed);
Bass.ChannelSetAttribute(ReverbStreamHandle, ChannelAttribute.Tempo, relativeSpeed);

// Have to handle pitch separately for some reason
if (_manager.IsChipmunkSpeedup) {
// Calculates semitone increase, can probably be improved but this will do for now
float semitones = relativeSpeed > 0 ? 1 * speed : -1 * speed;
Bass.ChannelSetAttribute(StreamHandle, ChannelAttribute.Pitch, semitones);
Bass.ChannelSetAttribute(ReverbStreamHandle, ChannelAttribute.Pitch, semitones);
float semitoneShift = percentageSpeed switch {
> 100 => percentageSpeed / 9 - 100 / 9,
< 100 => percentageSpeed / 3 - 100 / 3,
_ => 0
};

semitoneShift = Math.Clamp(semitoneShift, -60, 60);

Bass.ChannelSetAttribute(StreamHandle, ChannelAttribute.Pitch, semitoneShift);
Bass.ChannelSetAttribute(ReverbStreamHandle, ChannelAttribute.Pitch, semitoneShift);
}
}

Expand Down