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]

What is the origin of the Qin Shi Huang theme music in Civilization IV? What is the origin of the Qin Shi Huang theme music in Civilization IV?

Posted On: July 10, 2023
I've been trying to identify the music that is heard while one talks diplomacy with Qin Shi Huang in Civilization IV. The melody has been stuck in my head for a while now, and I'd like to k...[More]


Hogwarts Legacy Help 100% please Hogwarts Legacy Help 100% please

Posted On: July 29, 2023
Can somebody please walk me through what I'm missing for the platinum? I'm missing 1 revelio page in hogwarts and I don't know which one it is, I've tried guides and everything, I just...[More]


Do baby creatures grow in Hogwarts Legacy? Do baby creatures grow in Hogwarts Legacy?

Posted On: June 20, 2023
I have been playing for some time now (72 hrs.) and I have not seen any of the baby creatures grow at all. Question from user Maxwell-Fate at HogwartsLegacyGaming at reddit. Answer: No, unfor...[More]


Do you ever cast other smites over Divine as Paladin? Do you ever cast other smites over Divine as Paladin?

Posted On: April 26, 2026
Like thunderous smite for example.Question from user Cagedglobe at BaldursGate3 at reddit.com.Answer:Thunderous Smite is decent; Thunder damage is a good type of damage, and knocking enemies prone giv...[More]


What does this checkmark mean in the course listing screen? What does this checkmark mean in the course listing screen?

Posted On: October 20, 2023
Started playing through the levels and trying to pick up everything I see along the way so I don't have to go back and revisit the levels. First course so far so good. First course complete....[More]


Hearthstone keeps crashing on Lutris on Ubuntu Hearthstone keeps crashing on Lutris on Ubuntu

Posted On: June 5, 2023
I just installed Lutris to play Hearthstone on Ubuntu. Battle.net launcher and the game launches, the bar door screen, Hearthstone text, settings and social buttons appear then the game shuts down. . ...[More]


How do damage upgrades of the same type stack in Dead Cells? How do damage upgrades of the same type stack in Dead Cells?

Posted On: April 13, 2023
When I pick up an upgrade scroll I can increase my attack power for brutality, tactic, or survival objects by 15%. How do damage increases of the same type stack with each other? Are they additive or ...[More]


How to find the Dishonored combination of the underwater safe? How to find the Dishonored combination of the underwater safe?

Posted On: May 12, 2023
In Central Rudshore of the Flooded District before entering the Daud's base there is a safe in the flooded basement of a nearby building. Where am I supposed to find the combination of it in-game?...[More]


USB Loader GX keeps on crashing to the Homebrew Channel USB Loader GX keeps on crashing to the Homebrew Channel

Posted On: March 24, 2023
I have a Wii on version 4.3U. One of my games used to work, but now all of them just crash to the Homebrew Channel. I already know there is another post about this, but I didn't perform a system u...[More]


Can you import included and DLC tracks from Just Dance 2 into Just Dance 3? Can you import included and DLC tracks from Just Dance 2 into Just Dance 3?

Posted On: June 24, 2023
My wife has been enjoying Just Dance 2 on the Wii since I gave it to her last Christmas and has actually bought a number of additional tracks — enough that I had to buy her a big SD card just fo...[More]