Movement sound adjustments & movement pitch modulation system
This commit is contained in:
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
core/assets/sounds/loops/loopHover2.ogg
Normal file
BIN
core/assets/sounds/loops/loopHover2.ogg
Normal file
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -96,15 +96,21 @@ public class SoundControl{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void loop(Sound sound, Position pos, float volume){
|
public void loop(Sound sound, Position pos, float volume){
|
||||||
if(Vars.headless) return;
|
loop(sound, pos, volume, 1f);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void loop(Sound sound, Position pos, float volume, float pitch){
|
||||||
|
if(Vars.headless || sound == Sounds.none || volume <= 0.00001f) return;
|
||||||
|
|
||||||
float baseVol = sound.calcFalloff(pos.getX(), pos.getY());
|
float baseVol = sound.calcFalloff(pos.getX(), pos.getY());
|
||||||
float vol = baseVol * volume;
|
float vol = baseVol * volume;
|
||||||
|
|
||||||
SoundData data = sounds.get(sound, SoundData::new);
|
SoundData data = sounds.get(sound, SoundData::new);
|
||||||
data.volume += vol;
|
data.volume += vol;
|
||||||
|
data.pitch += pitch * vol;
|
||||||
data.volume = Mathf.clamp(data.volume, 0f, 1f);
|
data.volume = Mathf.clamp(data.volume, 0f, 1f);
|
||||||
data.total += baseVol;
|
data.total += baseVol;
|
||||||
|
data.totalVolume += vol;
|
||||||
data.sum.add(pos.getX() * baseVol, pos.getY() * baseVol);
|
data.sum.add(pos.getX() * baseVol, pos.getY() * baseVol);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -198,9 +204,10 @@ public class SoundControl{
|
|||||||
|
|
||||||
boolean play = data.curVolume > 0.01f;
|
boolean play = data.curVolume > 0.01f;
|
||||||
float pan = Mathf.zero(data.total, 0.0001f) ? 0f : sound.calcPan(data.sum.x / data.total, data.sum.y / data.total);
|
float pan = Mathf.zero(data.total, 0.0001f) ? 0f : sound.calcPan(data.sum.x / data.total, data.sum.y / data.total);
|
||||||
|
float pitch = Mathf.zero(data.totalVolume, 0.0001f) ? 1f : data.pitch / data.totalVolume;
|
||||||
if(data.soundID <= 0 || !Core.audio.isPlaying(data.soundID)){
|
if(data.soundID <= 0 || !Core.audio.isPlaying(data.soundID)){
|
||||||
if(play){
|
if(play){
|
||||||
data.soundID = sound.loop(data.curVolume, 1f, pan);
|
data.soundID = sound.loop(data.curVolume, pitch, pan);
|
||||||
Core.audio.protect(data.soundID, true);
|
Core.audio.protect(data.soundID, true);
|
||||||
}
|
}
|
||||||
}else{
|
}else{
|
||||||
@@ -210,10 +217,15 @@ public class SoundControl{
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Core.audio.set(data.soundID, pan, data.curVolume);
|
Core.audio.set(data.soundID, pan, data.curVolume);
|
||||||
|
if(!Mathf.equal(pitch, 1f, 0.001f)){
|
||||||
|
Core.audio.setPitch(data.soundID, pitch);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
data.pitch = 0f;
|
||||||
data.volume = 0f;
|
data.volume = 0f;
|
||||||
data.total = 0f;
|
data.total = 0f;
|
||||||
|
data.totalVolume = 0f;
|
||||||
data.sum.setZero();
|
data.sum.setZero();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -323,11 +335,11 @@ public class SoundControl{
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected static class SoundData{
|
protected static class SoundData{
|
||||||
float volume;
|
float volume, pitch;
|
||||||
float total;
|
float total;
|
||||||
Vec2 sum = new Vec2();
|
Vec2 sum = new Vec2();
|
||||||
|
|
||||||
int soundID;
|
int soundID;
|
||||||
float curVolume;
|
float curVolume, totalVolume;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -681,7 +681,7 @@ public class UnitTypes{
|
|||||||
|
|
||||||
stepSound = Sounds.walkerStepSmall;
|
stepSound = Sounds.walkerStepSmall;
|
||||||
stepSoundPitch = 1f;
|
stepSoundPitch = 1f;
|
||||||
stepSoundVolume = 0.2f;
|
stepSoundVolume = 0.25f;
|
||||||
|
|
||||||
legCount = 4;
|
legCount = 4;
|
||||||
legLength = 9f;
|
legLength = 9f;
|
||||||
@@ -1037,6 +1037,11 @@ public class UnitTypes{
|
|||||||
circleTargetRadius = 60f;
|
circleTargetRadius = 60f;
|
||||||
wreckSoundVolume = 0.7f;
|
wreckSoundVolume = 0.7f;
|
||||||
|
|
||||||
|
moveSound = Sounds.loopThruster;
|
||||||
|
moveSoundPitchMin = 0.3f;
|
||||||
|
moveSoundPitchMax = 1.5f;
|
||||||
|
moveSoundVolume = 0.2f;
|
||||||
|
|
||||||
weapons.add(new Weapon(){{
|
weapons.add(new Weapon(){{
|
||||||
y = 1f;
|
y = 1f;
|
||||||
x = 0f;
|
x = 0f;
|
||||||
@@ -1062,7 +1067,7 @@ public class UnitTypes{
|
|||||||
health = 340;
|
health = 340;
|
||||||
speed = 1.65f;
|
speed = 1.65f;
|
||||||
accel = 0.08f;
|
accel = 0.08f;
|
||||||
drag = 0.016f;
|
drag = 0.03f;
|
||||||
flying = true;
|
flying = true;
|
||||||
hitSize = 11f;
|
hitSize = 11f;
|
||||||
targetAir = false;
|
targetAir = false;
|
||||||
@@ -1079,6 +1084,10 @@ public class UnitTypes{
|
|||||||
rotateSpeed = 4.5f;
|
rotateSpeed = 4.5f;
|
||||||
circleTargetRadius = 40f;
|
circleTargetRadius = 40f;
|
||||||
|
|
||||||
|
moveSound = Sounds.loopThruster;
|
||||||
|
moveSoundPitchMin = 0.6f;
|
||||||
|
moveSoundVolume = 0.4f;
|
||||||
|
|
||||||
weapons.add(new Weapon(){{
|
weapons.add(new Weapon(){{
|
||||||
minShootVelocity = 1f;
|
minShootVelocity = 1f;
|
||||||
x = 3f;
|
x = 3f;
|
||||||
@@ -2599,7 +2608,7 @@ public class UnitTypes{
|
|||||||
treadRects = new Rect[]{new Rect(12 - 32f, 7 - 32f, 14, 51)};
|
treadRects = new Rect[]{new Rect(12 - 32f, 7 - 32f, 14, 51)};
|
||||||
researchCostMultiplier = 0f;
|
researchCostMultiplier = 0f;
|
||||||
|
|
||||||
tankMoveVolume *= 0.6f;
|
tankMoveVolume *= 0.32f;
|
||||||
tankMoveSound = Sounds.tankMoveSmall;
|
tankMoveSound = Sounds.tankMoveSmall;
|
||||||
|
|
||||||
weapons.add(new Weapon("stell-weapon"){{
|
weapons.add(new Weapon("stell-weapon"){{
|
||||||
@@ -2645,7 +2654,7 @@ public class UnitTypes{
|
|||||||
treadRects = new Rect[]{new Rect(17 - 96f/2f, 10 - 96f/2f, 19, 76)};
|
treadRects = new Rect[]{new Rect(17 - 96f/2f, 10 - 96f/2f, 19, 76)};
|
||||||
researchCostMultiplier = 0f;
|
researchCostMultiplier = 0f;
|
||||||
|
|
||||||
tankMoveVolume *= 0.75f;
|
tankMoveVolume *= 0.55f;
|
||||||
tankMoveSound = Sounds.tankMove;
|
tankMoveSound = Sounds.tankMove;
|
||||||
|
|
||||||
weapons.add(new Weapon("locus-weapon"){{
|
weapons.add(new Weapon("locus-weapon"){{
|
||||||
@@ -3729,6 +3738,10 @@ public class UnitTypes{
|
|||||||
itemCapacity = 0;
|
itemCapacity = 0;
|
||||||
useEngineElevation = false;
|
useEngineElevation = false;
|
||||||
researchCostMultiplier = 0f;
|
researchCostMultiplier = 0f;
|
||||||
|
moveSound = Sounds.loopExtract;
|
||||||
|
moveSoundVolume = 0.25f;
|
||||||
|
moveSoundPitchMin = 0.7f;
|
||||||
|
moveSoundPitchMax = 1.5f;
|
||||||
|
|
||||||
abilities.add(new MoveEffectAbility(0f, -7f, Pal.sapBulletBack, Fx.missileTrailShort, 4f){{
|
abilities.add(new MoveEffectAbility(0f, -7f, Pal.sapBulletBack, Fx.missileTrailShort, 4f){{
|
||||||
teamColor = true;
|
teamColor = true;
|
||||||
|
|||||||
@@ -707,8 +707,13 @@ abstract class UnitComp implements Healthc, Physicsc, Hitboxc, Statusc, Teamc, I
|
|||||||
kill();
|
kill();
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!headless && type.loopSound != Sounds.none){
|
if(!headless){
|
||||||
control.sound.loop(type.loopSound, this, type.loopSoundVolume);
|
control.sound.loop(type.loopSound, this, type.loopSoundVolume);
|
||||||
|
if(type.moveSound != Sounds.none){
|
||||||
|
float progress = Mathf.clamp(vel.len() / type.speed);
|
||||||
|
float pitch = Mathf.lerp(type.moveSoundPitchMin, type.moveSoundPitchMax, progress);
|
||||||
|
control.sound.loop(type.moveSound, this, type.moveSoundVolume * progress, pitch);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//check if environment is unsupported
|
//check if environment is unsupported
|
||||||
|
|||||||
@@ -314,6 +314,12 @@ public class UnitType extends UnlockableContent implements Senseable{
|
|||||||
public float stepSoundPitch = 1f, stepSoundPitchRange = 0.1f;
|
public float stepSoundPitch = 1f, stepSoundPitchRange = 0.1f;
|
||||||
/** sound looped when tank moves */
|
/** sound looped when tank moves */
|
||||||
public Sound tankMoveSound = Sounds.tankMove;
|
public Sound tankMoveSound = Sounds.tankMove;
|
||||||
|
/** sound looped when the unit moves; volume depends on velocity */
|
||||||
|
public Sound moveSound = Sounds.none;
|
||||||
|
/** volume of movement sound */
|
||||||
|
public float moveSoundVolume = 1f;
|
||||||
|
/** pitch of movement sound based on velocity */
|
||||||
|
public float moveSoundPitchMin = 1f, moveSoundPitchMax = 1f;
|
||||||
/** volume of tank move sfx */
|
/** volume of tank move sfx */
|
||||||
public float tankMoveVolume = 0.5f;
|
public float tankMoveVolume = 0.5f;
|
||||||
/** effect that this unit emits when falling */
|
/** effect that this unit emits when falling */
|
||||||
|
|||||||
Reference in New Issue
Block a user