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]

Lost in the Hogwarts School Lost in the Hogwarts School

Posted On: July 7, 2023
Does anyone get easily lost in the hogwarts school or is it just me?. Question from user Apprehensive_Ad832 at HogwartsLegacyGaming at reddit. Answer: I’m on my second play through and ...[More]


Where should I sell exploration data for the most benefit? Where should I sell exploration data for the most benefit?

Posted On: June 15, 2023
I spend a LOT of time outside the bubble. (Both the Solar bubble and Colonia area.) Sometimes, I'll be out for months at a stretch and come back with tens of millions of CR worth of exploration da...[More]


How did you guys enjoy Durge? How did you guys enjoy Durge?

Posted On: February 11, 2026
Finished my normal campaign adventure a while ago and am starting off as durge, I was pretty excited so far I was playing as a hero holding back on their urges but as I played I began to become bored,...[More]


I deleted the portal to the end city in minecraft I deleted the portal to the end city in minecraft

Posted On: February 3, 2023
I was messing around with my Minecraft world and accidentally deleted the portal on the main end island that leads to the first end city (don't ask me how). Does anyone know how I can put it ba...[More]


What is this magic circle in Castlevania: Dawn of Sorrow? What is this magic circle in Castlevania: Dawn of Sorrow?

Posted On: April 22, 2024
While I was farming for Alamaric Sniper and Ghost Dancer souls, I had something happen where it looked like a Sniper was going to give me a soul, but I didn't actually get one. Instead, this red magic...[More]


How do I start a Single Player - Multi Player game with a custom map in Starcraft II? How do I start a Single Player - Multi Player game with a custom map in Starcraft II?

Posted On: January 14, 2023
This may sound a little bit silly, but I can’t seem to find how to do this. Single Player -> Vs. A.I. seems the way for single player, but then I can’t find a way to select my map. I...[More]


Are Cheats in GTA5 official feature or is it some hack spread by developers - users? Are Cheats in GTA5 official feature or is it some hack spread by developers - users?

Posted On: November 30, 2023
When you press ` (backtick) key in GTA5, you can enter cheat codes like BUZZOFF. Now I was wondering is this official feature? I find it a bit strange because on GTA5 official site and in their Man...[More]


What is the maximum stamina in Nier Reincarnation? What is the maximum stamina in Nier Reincarnation?

Posted On: April 15, 2024
What is the maximum amount of stamina you can have at once in Nier Reincarnation?Question from user Stevoisiak at gaming.stackexchange.com.Answer:Stamina maxes out at 999. Any stamina gained after rea...[More]


Screen flashing during the day in Watch Dogs Screen flashing during the day in Watch Dogs

Posted On: September 25, 2023
Sometimes textures and the screen start flashing while I play the game. But this only happen during the day. I'm playing Watch Dogs 1 from Steam. Question from user Diego Borba at stackexcha...[More]


How do Dragoon and Daybreak pieces work in Team Battles? How do Dragoon and Daybreak pieces work in Team Battles?

Posted On: December 3, 2023
In normal matches, the Dragoon and Daybreak items in Smash Ultimate require a player to collect all three pieces before they can be used. How do these items work in team battles? If player A picks up ...[More]