Any way to crossfade music?

[BACK]
Any way to crossfade music?
Posted On: April 2, 2024

I would like to be able to create a music crossfade in an adventure map that I'm creating. The idea is to overlap two versions of the same song, one the "chill" version, another the "fight" version, and when a player gets in a fight with enemies, crossfade over to the fight version, as well as being able to nicely fade out music in general.


My original idea was to have 2 invisible armor stands act as the source for each of the tracks, then move the armor stands away/towards the player, slowly fading in/out each track. This actually works pretty well, but when the crossfade is over, I make the armor stand emitting the now faded-in song ride the player, so it just sticks with them. This also works, and when the player is running straight ahead, it sounds correct, but when the player strafes, it does like a sawtooth effect on the panning, and is REALLY distracting sounding. Any other ideas for a way to make this kind of thing work?


I've also tried messing with setting the attenuation_distance very high in the resource pack, but that doesn't change anything, though I suspect that it's because it only affects certain entity types anyways.


I am writing a server plugin, so I can do anything available in bukkit/paper, and am even perfectly fine doing things with ProtocolLib or other version specific hacks, but I am not expecting players to have to download a client side mod for this map.


Question from user LadyCailin at gaming.stackexchange.com.


Answer:

So, I ended up with a situation that works good enough for my purposes, but still has some drawbacks. Essentially, I place 4 entities (item displays) at the cardinal directions of the player, 10 blocks out, 5 blocks above, and start the music with each of the 4 in the same tick. This seems to reliably sync up the music. Then, every so often (4 times a second) I move the entities into the correct location again, so they are again 10 blocks out, 5 blocks up. This has a strange effect when the player spins around quickly, but actually, that strange effect happens with the rain and other sounds too, so I can live with that.


For the crossfade, this is simple, and just does the same as , I have the other set of 4 entities far enough away from the player that they can't hear them, but then move the first song's "speakers" down, while moving the fade in song's speakers up. This has a very nice fade effect, and while it is a bit jumpy, I could fix that with a higher frame rate.


Speaking of frame rates, because my "adjust position" logic only runs every .20 seconds, this method is pretty bad with flight and falling from high distances. However, you can turn the volume up, and this works well enough, since this decreases the amount of attenuation per unit moved. However, this means that the distance of the "fade out" state needs to be higher before it drops to 0. If you set that too high, this introduces a new problem with the "stowed away" speakers, which is that if the player gets too far away, they stop playing music, presumably because the client unloads them, and so also forgets that they were playing music. Thus, I have settled on just living with the fact that if a player moves fast enough, this system gets a bit janky. I may continue to improve on this later.


All in all though, this works surprisingly well, though I am excited to see how it performs with load testing.


Answer from user LadyCailin at gaming.stackexchange.com.


[BACK]
Any way to crossfade music?
Posted On: April 2, 2024

I would like to be able to create a music crossfade in an adventure map that I'm creating. The idea is to overlap two versions of the same song, one the "chill" version, another the "fight" version, and when a player gets in a fight with enemies, crossfade over to the fight version, as well as being able to nicely fade out music in general.


My original idea was to have 2 invisible armor stands act as the source for each of the tracks, then move the armor stands away/towards the player, slowly fading in/out each track. This actually works pretty well, but when the crossfade is over, I make the armor stand emitting the now faded-in song ride the player, so it just sticks with them. This also works, and when the player is running straight ahead, it sounds correct, but when the player strafes, it does like a sawtooth effect on the panning, and is REALLY distracting sounding. Any other ideas for a way to make this kind of thing work?


I've also tried messing with setting the attenuation_distance very high in the resource pack, but that doesn't change anything, though I suspect that it's because it only affects certain entity types anyways.


I am writing a server plugin, so I can do anything available in bukkit/paper, and am even perfectly fine doing things with ProtocolLib or other version specific hacks, but I am not expecting players to have to download a client side mod for this map.


Question from user LadyCailin at gaming.stackexchange.com.


Answer:

So, I ended up with a situation that works good enough for my purposes, but still has some drawbacks. Essentially, I place 4 entities (item displays) at the cardinal directions of the player, 10 blocks out, 5 blocks above, and start the music with each of the 4 in the same tick. This seems to reliably sync up the music. Then, every so often (4 times a second) I move the entities into the correct location again, so they are again 10 blocks out, 5 blocks up. This has a strange effect when the player spins around quickly, but actually, that strange effect happens with the rain and other sounds too, so I can live with that.


For the crossfade, this is simple, and just does the same as , I have the other set of 4 entities far enough away from the player that they can't hear them, but then move the first song's "speakers" down, while moving the fade in song's speakers up. This has a very nice fade effect, and while it is a bit jumpy, I could fix that with a higher frame rate.


Speaking of frame rates, because my "adjust position" logic only runs every .20 seconds, this method is pretty bad with flight and falling from high distances. However, you can turn the volume up, and this works well enough, since this decreases the amount of attenuation per unit moved. However, this means that the distance of the "fade out" state needs to be higher before it drops to 0. If you set that too high, this introduces a new problem with the "stowed away" speakers, which is that if the player gets too far away, they stop playing music, presumably because the client unloads them, and so also forgets that they were playing music. Thus, I have settled on just living with the fact that if a player moves fast enough, this system gets a bit janky. I may continue to improve on this later.


All in all though, this works surprisingly well, though I am excited to see how it performs with load testing.


Answer from user LadyCailin at gaming.stackexchange.com.


[BACK]

In EVE, What happens to skills in the training queue when an account reverts to alpha clone status? In EVE, What happens to skills in the training queue when an account reverts to alpha clone status?

Posted On: March 9, 2023
I have a bunch of skills queued to train, which includes advanced skills that an Alpha clone cannot train and several skills that are scheduled to start several days out. Since these two conditions ar...[More]


Having a horrible time with a fight and need help Having a horrible time with a fight and need help

Posted On: November 6, 2023
I’m in the underdark trying to kill Nere and I cannot get through this fight. There are a million duergar and I keep dying when I try to go through the fight. I’m level 5 and have mysel...[More]


I swear I need them all. I don't have a problem! I swear I need them all. I don't have a problem!

Posted On: January 6, 2025
Question from user Nevaroth021 at BaldursGate3 at reddit.com.Answer:Look, at least you are just herding scrolls. I hoard weapons and armor to outfit a small army, but i cant sell them!.Answer from use...[More]


How to learn the duration of spells in Baldurs Gate 3? How to learn the duration of spells in Baldurs Gate 3?

Posted On: August 14, 2023
One thing that continues to annoy me is that a whole lot of spells (and potions) have no information of how long the spell will last. Neither in the spell description nor once actually cast. For ex...[More]


Whats the most efficient way to acquire Minecraft Dark Oak Saplings? Whats the most efficient way to acquire Minecraft Dark Oak Saplings?

Posted On: June 5, 2023
I need several stacks of dark oak saplings. By efficient, I'm interested in minimizing game time. I have tons of resources, so throw any resources you can think of at the answer if it will help...[More]


Crossed Wand final round Crossed Wand final round

Posted On: August 1, 2023
I just can't do it. I keep trying. That dummy practice is useless as its not at all like the real dual I just keep going back and back, and sie. The opponents even reheal? Sebastian is no bloody h...[More]


What does Johnny say if youve not completed Blistering Love prior to starting Nocturne Op55N1? What does Johnny say if youve not completed Blistering Love prior to starting Nocturne Op55N1?

Posted On: March 15, 2024
This question is about an option near the end of Cyberpunk 2077. There are certain side quests that, if completed, provide extra options to finishing the last quest. What does Johnny say if those side...[More]


Why does Romance have to be creepy in Hogwarts Why does Romance have to be creepy in Hogwarts

Posted On: March 13, 2023
It might be an old topic, but I've seen too many people saying that wanting romance in this game is pedo behaviour. Why does "romance" have to be a synonym for +18 content? seriously,...[More]


Marked as a quest item. Reading it never updated my journal? Marked as a quest item. Reading it never updated my journal?

Posted On: March 13, 2026
I've had sooo many playthroughs and this quest item never made sense. I think I have a memory of it working in early patches - lately I haven't triggered anything from it. Not even dialogue reactions....[More]


Is there any way I can give myself 360° vision in game? Is there any way I can give myself 360° vision in game?

Posted On: July 6, 2023
A key gameplay mechanic in Project Zomboid is that your character can only see what's in front of them, even though the game has an isometric perspective. Anything behind becomes shrouded. That...[More]