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]

Why do I create 2 characters when starting a new playthrough? Why do I create 2 characters when starting a new playthrough?

Posted On: August 8, 2023
The character creation process is very confusing to me. I know it's early access and things are being polished continuously, but it's unclear why I need to create 2 characters. After comple...[More]


Using bikes over karts in time trials in Mario Kart 8 Deluxe Using bikes over karts in time trials in Mario Kart 8 Deluxe

Posted On: April 27, 2023
I realized I never beaten staff times on MK8 and I'd like to give them a try. So, I watched several MK8 time trials on Youtube, and I noticed that bikes are often used. Is there a real advantag...[More]


Will the Cursed Swords one-hit death effect apply in Dead Cells? Will the Cursed Swords one-hit death effect apply in Dead Cells?

Posted On: April 18, 2023
The description of the Cursed Sword says "One hit and you're dead", presumably meaning you will die in one hit while it is equipped. However, there's a mutation called Porcupack that...[More]


Do you think we will get a 6th and 7th year of Hogwarts Legacy? Do you think we will get a 6th and 7th year of Hogwarts Legacy?

Posted On: April 7, 2023
Question from user KhreeoftheShire at HogwartsLegacyGaming at reddit.com. Answer: They will likely do something. It sold too well not to. Answer from user AgentEndive at HogwartsLegacyGaming ...[More]


Is there a way to de-fuse weapons in Zelda Tears of the Kingdom? Is there a way to de-fuse weapons in Zelda Tears of the Kingdom?

Posted On: May 17, 2023
Sometimes I want to de-fuse a weapon because I've found a better component I want to add, or a better weapon to use that component. Is there a way to de-fuse a weapon or shield? Question from u...[More]


How can you jump farther in Temple Run? How can you jump farther in Temple Run?

Posted On: August 5, 2023
I'm playing Temple Run for iOS and there are parts where you need to jump really far in order to get over a broken path. Does anyone know how to jump over these tricky parts? Is there a way to ...[More]


Which house do you find to be the coziest? Which house do you find to be the coziest?

Posted On: September 19, 2023
I have done a play through as 3 of the four houses (Ravenclaw, Slytherin, and Gryffindor). I find that Gryffindor is more cozy than the other two. Might just be because the colors are warmer. Hufflepu...[More]


Any way to crossfade music? 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, a...[More]


In Hogwarts Legacy, Am I the only one who prefers the switch Hagrid? In Hogwarts Legacy, Am I the only one who prefers the switch Hagrid?

Posted On: April 19, 2023
Question from user supxleon123 at HogwartsLegacyGaming at reddit.com. Answer: We’re getting a PS5 hagrid? Answer from user UglyPuta- at HogwartsLegacyGaming at reddit.com....[More]


Who exactly is Fake Crash? Who exactly is Fake Crash?

Posted On: April 8, 2024
In Crash Bandicoot: Warped and also in N. Sane Trilogy you can see this weird (and fake) version of Crash dancing outside of some levels. He even became a playable character then in Crash Team Racing....[More]