Atmospheric or Dynamic Music

Discuss modding questions and implementation details.
Post Reply
User avatar
LifeInVelvet
Posts: 34
Joined: Mon Feb 28, 2022 12:16 am

Atmospheric or Dynamic Music

Post by LifeInVelvet »

I had an idea or wish to make a mode that makes the music more dynamic based on whether you're in combat or not.
Kind of like this:

It has the main theme, and then it adds more instruments when an enemy is near and then in combat. And then for doing 'work' and then collecting treasure.
Or just simply make the music more atmospheric and loop instead of ending... And then starting again. Kind of gross that it does that.
More atmospheric by being like this essentially but looping:


It's like the extra instruments fade in on top of the base track. Does anyone know how that works?
Or any tips for the coding that would be needed to make the music loop? I'm not too familiar with coding stuff or music either even.
Last edited by LifeInVelvet on Sun Mar 13, 2022 6:46 pm, edited 1 time in total.

User avatar
BadLuckBurt
Posts: 948
Joined: Sun Nov 05, 2017 8:30 pm

Re: Atmospheric or Dynamic Music

Post by BadLuckBurt »

If I understand correctly, you're looking to implement something like this: https://en.wikipedia.org/wiki/IMUSE in a lesser form I hope because that system was made by two actual composers.

The overall basics are quite simple but the code implementation isn't but also depends on the format (MIDI / tracker music or actual audio files) you use. The Pikmin video you linked gives me the impression they are using one of these formats or a similar approach using layered audio files.

The MIDI format (https://en.wikipedia.org/wiki/MIDI) and tracker music (https://en.wikipedia.org/wiki/Music_tracker) are ideal for these kind of effects. Without music replacement files, Daggerfall Unity uses MIDI with a soundfont so there is a foundation.

When using regular audio files, you would have two or more files. One file would contain the main score and the other file(s) would contain the extra instruments playing along with that score. Then depending on the situation the player finds themselves in, you would fade in or fade out the extra instruments. The problem is often making everything sync up nicely, especially using high quality audio.

Using MIDI or tracker music, it is possible to mute / fade channels to achieve the same effect with all the information being in one file allowing for smoother playback. An added bonus of these formats is that they allow the designation of loop points but the software / code used for playback also needs to support said loop points for that to work. Older games used this a lot as storing high quality audio lead to huge file sizes back in the days before compression like MP3 was available.

I won't mind going into further detail if you want but this would be the gist of it I think.

Off-topic, you're doing the red text thing again ;)
DFU on UESP: https://en.uesp.net/w/index.php?title=T ... fall_Unity
DFU Nexus Mods: https://www.nexusmods.com/daggerfallunity
My github repositories with mostly DFU related stuff: https://github.com/BadLuckBurt

.

User avatar
pango
Posts: 3359
Joined: Wed Jul 18, 2018 6:14 pm
Location: France
Contact:

Re: Atmospheric or Dynamic Music

Post by pango »

To make synthesized (MIDI) music loop, you'd need some way to mark when the music should repeat, and a way to mark where it start repeating from. I think classic used specific notes for that, but the information could also come "out of band" from an extra XML file, for example. And then the MIDI synthesized should be controlled to play the correct sections back-to-back (hopefully the synthesizer API allows something like that).
For digitized music, it should be pretty similar, but you also have to make sure there's no discontinuity in the sound wave at the end of the loop; The usual way to do that is to determine at what samples the wave crosses zero in a fixed direction (consistently pick one of increasing or decreasing) at the beginning and end of the loop section, and use those samples offsets exactly.
Mastodon: @pango@fosstodon.org
When a measure becomes a target, it ceases to be a good measure.
-- Charles Goodhart

User avatar
LifeInVelvet
Posts: 34
Joined: Mon Feb 28, 2022 12:16 am

Re: Atmospheric or Dynamic Music

Post by LifeInVelvet »

Seems like the only possible download versions have the base track included and not separate instruments, so hopefully that doesn't turn out poor. And how you'd get the game to recognize an enemy is nearby but have spotted/is after you yet is possible to, since it's an old game.

But anyway, I should use MIDI or tracker music to try and make this work? Mainly Midi since it has some kind of support.

But as far as triggers for the switch of music, that would require coding or would that just be built within the music file itself? Or need some external additional coding for triggers of changing?

Well, at least I'll be able to put together tracks for daggerfall that loops instead of stopping and starting, using MIDI files at the very least.

The only problem is doing the Thief Soundtrack, as if you've ever played the game before, the music changes depending on which room or area you're in for maximum immersion in the setting. But if I can get the right cut off points and make it loop at the right place it should be fine. Since I'll likely be having to work with the raw music file for the entirety of an level in that game.

Also I usually like to use red text to give some contrast between lines, make things easier to digest when reading. Guess it must not be working as I thought it would.

User avatar
LifeInVelvet
Posts: 34
Joined: Mon Feb 28, 2022 12:16 am

Re: Atmospheric or Dynamic Music

Post by LifeInVelvet »

pango wrote: Sun Mar 13, 2022 10:34 pm To make synthesized (MIDI) music loop, you'd need some way to mark when the music should repeat, and a way to mark where it start repeating from. I think classic used specific notes for that, but the information could also come "out of band" from an extra XML file, for example. And then the MIDI synthesized should be controlled to play the correct sections back-to-back (hopefully the synthesizer API allows something like that).
For digitized music, it should be pretty similar, but you also have to make sure there's no discontinuity in the sound wave at the end of the loop; The usual way to do that is to determine at what samples the wave crosses zero in a fixed direction (consistently pick one of increasing or decreasing) at the beginning and end of the loop section, and use those samples offsets exactly.
So using a midi would need an XML to mark points of repeating.

And jeez, I really don't understand a lot of this. Seems like I'm going to need to look up some tutorial to better understand this stuff.

But I think I kind of get it for digitized the loop section chosen needs to line up perfectly from the start of the loop to the end to make it seamless.

User avatar
LifeInVelvet
Posts: 34
Joined: Mon Feb 28, 2022 12:16 am

Re: Atmospheric or Dynamic Music

Post by LifeInVelvet »

Wait, I found this, this has the loop start and end exactly!
https://www.smashcustommusic.net/song/54774

This is good for the digitized or midi?

User avatar
BadLuckBurt
Posts: 948
Joined: Sun Nov 05, 2017 8:30 pm

Re: Atmospheric or Dynamic Music

Post by BadLuckBurt »

LifeInVelvet wrote: Sun Mar 13, 2022 11:48 pm Also I usually like to use red text to give some contrast between lines, make things easier to digest when reading. Guess it must not be working as I thought it would.
I'm sorry, I could've explained better. I use the dark theme for the forum's appearance and I'm colourblind so it becomes very difficult to read for me. Red on a dark background doesn't really mix that well. You can check the effect yourself by going to your User Control Panel and changing the My board style setting under Board Preferences > Edit global settings.

Overall it's much friendlier to your eyes than the default skin but not everyone is aware it can be changed.

About that Pikmin file you found, that is in Nintendo's own format, BRSTM so that won't do you much good but I'm not sure if you are using this as an example or if you actually want the Pikmin music in-game. You'd have to convert that to a digital format probably but I could be wrong.

The MIDI sequencer (the thing that plays midi files) in Daggerfall Unity does not support markers sadly which is how you would set up loop points directly in a MIDI file.

Using a specific note like Pango said would work, if that is what Daggerfall used originally, that note should still be present inside the MIDI files that ship with Daggerfall Unity. The question is what note though, I wouldn't know. There is no support for XML looping as far as I know but maybe Pango knows more than I do, wouldn't be the first time :D
DFU on UESP: https://en.uesp.net/w/index.php?title=T ... fall_Unity
DFU Nexus Mods: https://www.nexusmods.com/daggerfallunity
My github repositories with mostly DFU related stuff: https://github.com/BadLuckBurt

.

User avatar
LifeInVelvet
Posts: 34
Joined: Mon Feb 28, 2022 12:16 am

Re: Atmospheric or Dynamic Music

Post by LifeInVelvet »

From what I remember playing original daggerfall, the music would also loop in that annoying way of the song ending... Then starts up again.
But damn, even if I could use an XML or find the specific note, finding atmospheric/minimalist music that's decent quality (the pikmin and thief music are old and have a weird 'pop' and fuzzyness to them that would subtly grate the ears if listening on headphones, don't know how to fix it either, don't do many audio things), I'm not experienced with doing audio related things.
I really hope that looping can be found out for this game so the music isn't grating on the ears.

I mean the current sort of work-around for it would be like:

But it's gonna make one hell of an needlessly large download when all you need is like a good 3-6 minute loop of ambience and maybe minor instruments.

User avatar
ByteMixer
Posts: 153
Joined: Sun Mar 25, 2018 4:43 am
Location: Philadelphia, PA, USA
Contact:

Re: Atmospheric or Dynamic Music

Post by ByteMixer »

Disclaimer Note: I'm not a coder, I just have an AA degree in computer information science from like, 20+ years ago. (though I occasionally flirt with the idea or getting back into it and learning some C# or Python3) My field is music composition and performance.

So, I'm not sure what the eventual intended scope here is.

If you are talking truly dynamic music, where individual instruments or groups of instruments are swapped in and out ad-hoc based on the environment/location and situation/drama/tension, well, that's a fairly advanced thing to deal with, and quite a lot of work for the musician or composer.

You'd usually use something like WWISE or FMOD or equivalent to handle the scripting and crossfading, and it would require some scripting to detect what's happening based on various triggers, then handle the crossfading of full tracks or individual instrument tracks as they are swapped as needed. And in those cases the composer would usually rewrite the same melodic ideas and themes multiple times in different expressive styles to facilitate the buildup and release of the drama or tension in a dynamic sense.

It's a Lot of work for the composer as they have to recreate the same themes 4 or 5 times in various expressive forms, and sometimes are also responsible for actually writing the scripts to handle their music. So those who are knowledgeable in WWISE and/or FMOD and get commissioned to do that type of dynamic game music are worth every golden penny of that commission.

E.g. say you have a central theme you want as you explore. Let's say you've got some drums, some strings, maybe some woodwinds playing some sort of melodic idea along with harmonic and rhythmic ideas. You travel towards a cave or see a creature lurking around. The script would need to account for that or recognize it by some sort of trigger, (maybe distance from location or distance from hostile?) and start swapping some instruments to use a more tense harmonic section, or the drums would need to swap to a more dramatic rhythm section. Doing that smoothly would use crossfading. Then as you enter actual combat, you'd probably just crossfade to the full combat track, and then after combat, release the tension and crossfade back to the normal environmental theme.

At least that's how I understand that things are generally done. I don't write dynamic music, I'm just a more traditional composer, but I had a mild interest in it at one point, so looked into FMOD and WWISE. And then I decided it wasn't worth my time and went back to doing what I do, which is more traditional songwriting and music composition.

Now, in a smaller scope, if you just want the existing music to loop seamlessly, you can pull the midi files into a DAW so you can see the individual tracks, go to the end of the individual instrument tracks, and you should see a single sustained note at the very end that is technically outside of the instrument's range and "silent." In the piano roll, that note will either be very very high, or very very low for that instrument. As I understand, this was usually something done to create a few seconds "pause" before the midi track loops. So, removing that "silent" note, and then pulling the track length back to the end of the last real note on all instrument tracks should allow for the midi file to loop seamlessly. I think. I haven't really messed with any of those since I did the music used in KOW's DREAM mod, and I don't plan to revisit those anytime soon.

And there are already a couple mods that allow for seamless looping of the in-game music. Should be able to find them on Nexus.

But, any kind of dynamic music, whether you're simply crossfading between tracks based on combat, or going full bore dynamic, and swapping in and out different variants of the same theme based on tension/drama requirements, you're going to have to do some scripting, at the very least, create some sort of trigger that causes the crossfade to happen.

In my mind, the simplest thing to do for combat would be to have a trigger detect when the weapon is drawn. Something like: On weapon being drawn, crossfade to combatmusic1.mid and set weapon_drawn = true. While weapon_drawn = true continue looping combatmusic1.mid. On weapon being sheathed, crossfade to normaltheme.mid and set weapon_drawn = false. That is just some really really basic logic example to use a trigger to detect if you are in combat or not, and to switch to an appropriate combat music track if and while in combat.

I feel like WWISE or FMOD is a bit overkill to do that, but maybe there exists some other simpler tool to allow for that. I feel like I rambled a bit, so hopefully my thoughts aren't all over the place too much.
"Whatever you do, make good art." - Neil Gaiman

Post Reply