Open Surge Forum

A fun 2D retro platformer inspired by Sonic games and a game creation system

You are not logged in.

Announcement

Our community has moved to Discord! https://discord.gg/w8JqM7m

#1 2015-09-19 01:22:04

jobromedia
Member
From: Stockholm, Sweden
Registered: 2009-11-01
Posts: 1,072
Website

Multi layered music tutorial

So say you have a level with multiple styles.

Hills
Caverns
Under water

And you want to reflect the level through music. Note I don't know jack sh*t about SurgeScript, it was at least 3 years since I toyed around with Open Surge. But what I've done is to start on a game on my own. To keep the music fluid and bopping around I was forced to think as a DJ when programming the music routine in CTFusion 2.5. This is how you do it:

1. Preload all music before a level starts
2. Set the volume for the song to be heard first at 100, the rest at 0.
3. Create detection objects at all entries where the player switches between the different segments.
4. You need at least twice as many covering all different transitions. In the example above:

Over ground > Under ground
Over ground > Under water
Under ground > Over ground
Under ground > Under water
Under water > Over ground
Under water > Under ground

5. Once the player passes over such a spot, then start crossfading between the musics for a few seconds.

Note that ALL music must be the same BPM, and have the same tonality for this to be really effective. If you don't know what I'm on to. Take a look at Stems:

https://www.youtube.com/watch?v=MKJZO_0zQcM

This is an open source format that loads in 5 tracks, 4 different instrumental tracks and a master specially designed for DJ's. But I feel this could be used for Open Surge as well.

Offline

#2 2015-09-19 08:20:43

TheSeventhEmerald
Member
From: Spain
Registered: 2010-04-19
Posts: 302

Re: Multi layered music tutorial

Looks so nice! I really like the idea and I think that the Open Surge engine can handle that well. I will prove to create the famous transition object.

About music, if I get some synth and pop-instruments libraries I'll do something for Open Surge. I'm working now with Finale+Garritan instruments and I'm doing the music of a visual novel. However, my style is pretty classic/jazz, and it doesn't fit Open Surge for now.
For now tongue


Piece of cake...!

Offline

#3 2015-09-19 09:46:46

jobromedia
Member
From: Stockholm, Sweden
Registered: 2009-11-01
Posts: 1,072
Website

Re: Multi layered music tutorial

I can't give you any commercial libraries, but if you can handle soundfonts then there is a ton of them here.

Offline

#4 2015-09-19 11:08:12

TheSeventhEmerald
Member
From: Spain
Registered: 2010-04-19
Posts: 302

Re: Multi layered music tutorial

Ah, SF for the MIDI. That's great, and it fits Open Surge really better.

Thank you very much! big_smile


Piece of cake...!

Offline

#5 2015-09-20 00:34:56

jobromedia
Member
From: Stockholm, Sweden
Registered: 2009-11-01
Posts: 1,072
Website

Re: Multi layered music tutorial

Can be used with Phenome VST for Windows users.

Offline

#6 2015-09-21 13:29:26

aronthehedgehog
Member
From: Lincoln, NE
Registered: 2013-04-05
Posts: 390

Re: Multi layered music tutorial

Looks nice, and it may work and it could be used toward longer levels as well.


Not active much anymore.
The only things I do now is just let inspiration come to me when it's needed.
Also bad profile pic because I don't have anything else in mind.

Offline

#7 2015-09-23 23:36:09

Alexandre
Administrator
From: Brazil
Registered: 2009-01-27
Posts: 3,300
Website

Re: Multi layered music tutorial

Nice idea, jobro.

Di Rodrigues had suggested a similar idea some time ago: when the character gets underwater, the music gets a little twisted. We could even have a smooth transition of some sort, as you said.

Offline

#8 2015-09-24 02:50:21

jobromedia
Member
From: Stockholm, Sweden
Registered: 2009-11-01
Posts: 1,072
Website

Re: Multi layered music tutorial

Yeah with stems we have that opportunity to do that transitions We can even decide what parts should be heard in which part. This is since stems have 4 individual volume controls. All we need to do is to set up area codes so to say. We could for instance lower the drums  when rushing through a hotell, raise them when we get out to the plaza outside. Then we can have the raw dist guitar and the drums being played when we fight a boss, have some fancy big band come in and play something when we collect the more exclusive powerups such as extra chances, or that big ring.

So how could an area code be designed?

Area code 1 // All playing
{
Stem1 = 100
Stem2 = 100
Stem3 = 100
Stem4 = 100
}

Area code 2 // Under water
{
Stem1 = 0
Stem2 = 0
Stem3 = 100
Stem4 = 100
}

Area code 3 // Above ground
{
Stem1 = 100
Stem2 = 100
Stem3 = 100
Stem4 = 0
}

Area code 4 // Boss battle
{
Stem1 = 100
Stem2 = 0
Stem3 = 100
Stem4 = 0
}

These area codes could be defined on a global basis. But what if we've got different sounds at different channels? Well I'm glad that you asked because this would be rather simple:

Area code 100 // All playing
{
replacing = 2
Stem1 = 100
Stem2 = 0
Stem3 = 0
Stem4 = 100
}

It loads in the area codes from 100 and upward from the level file. Replacing indicates what area code it should override.

Then it would be just to decrease or increase the volume on the respective channels. We have 4 global variables named .Stem1 .. .Stem4 holding the volume for the individual stems. And if stems would have a volume from 0 to 255 then we would have as many musical variations as there are colors.

Then to assign the area code to a transfer object, it's quite simple. You need digits in 3 colors. Say you need to asign the id 29 to a section. You drop in first the 0 from the digits 0 - 9. Then you drop in 2 from the digits 00 - 99. Then finaly you drop in the 9 from digits 000 to 999. This is unless there has been some cracker jacker updates to allow properties to be edited in the latest version on the SVN.

Offline

#9 2015-09-29 21:16:14

TheSeventhEmerald
Member
From: Spain
Registered: 2010-04-19
Posts: 302

Re: Multi layered music tutorial

I've just realized that this cannot be done with current music engine in OpenSurge.

Simply read the docs about the "play_music" command:

Plays the specified music.Only one music can be played at a time. You need to change the state of the object (or destroy it) after you call this command, otherwise the engine will try to play your music at each cycle, causing weird results.

Something has to be changed in the source code. I think that we could change music syntax to make it more flexible:

- 1. In the description of the level, in "music" we should be able to select more than one song. The engine would load all the songs into memory, in a music array. Each song would have its properties, like loop and volume.

- 2. The command set_volume volume would be modified to

set_volume "song_from_preloaded" volume

To assign the value of each song separately. Also a set_loop would be neccesary to set the number of loops of each song.

- 3. Next, modify play_music "song_name_from_musics_folder" to

play_music "song_1", "song_2", "song_3" ..., transition_time, time_to_start

or even

play_music "song_1", "song_2", "song_3" ..., transition_time, time_to_start_song1, time_to_start_song2, ...

Where "song_j" is the name of a pre-loaded song in (1.) and transition time is the fade in/out time. All the songs selected will play simultaneously. Time to start is at which time the songs start playing.

- 4. Finally, a function

getSongCurrentTime("song")

would give the current time of the song. Note that the argument is neccesary because you may have multiple songs playing.

With this new archictecture, the application to our multi-layered music is trivial. In the level config, apply (1.) and pre-load, let's say, 5 songs, called "musics/s1.ogg", "musics/s2.ogg",  ... "musics/s5.ogg".

Then, create an object and set the volume/loops of each song, for example,

set_volume "musics/s3.ogg" 0.6
set_loops "musics/s1.ogg" -1

After that, simply call the songs you want to play with play_music. Suposse we're playing "s1" and then we do

play_music "musics/s2.ogg" "musics/s3.ogg" 1.2 0.0

This would make a fade out of "s1" and then a fade in of "s2" and "s3", in 1.2 seconds. The songs would start playing at the beginning, 0.0.
Then imagine that "s1" ... "s5" are different tracks of the same song, which I want to play in different layers. Then if "s1" is the base music playing, I can do:

play_music "musics/s1.ogg" "musics/s4.ogg" 0.0 getSongCurrentTime("musics/s1.ogg")

That would make the transition without fading (so you the music won't go off and then on), and will continue playing from the time is currently playing. Since all the songs are different tracks, you'll have no syncrhonization problems with the getSongCurrentTime function.

A problem with this could be that you may try to play a 1 minute song starting from second 76, for example. To fix this, I would simply start playing at current_time MOD song_duration. This also could help to minimize the total memory required to do the layers. If "s1" has 40 bars, and "s2" 20 bars, using this trick "s2" will play 2 times every time we have played "s1".
This, combined with the command mentioned in (2.), the set_loops, could be very fancy. Songs would stop simply after certain loops, defined manually.


Piece of cake...!

Offline

#10 2015-09-30 19:25:14

KZR
Member
Registered: 2010-07-14
Posts: 1,447
Website

Re: Multi layered music tutorial

play the music track as a sound effect. in theory, you can even program a basic sequencer inside the engine through scripting only.

If you make a big vertical object that moves right, and several other objects that play a sound effect when they collide with the big one, you can build levels that are actually songs smile


SD_sml.pngSeD_sml.pngLTot_W_sml.png
https://discord.gg/w8JqM7m ---> Open Surge's Discord server

Offline

#11 2015-10-06 13:19:18

aronthehedgehog
Member
From: Lincoln, NE
Registered: 2013-04-05
Posts: 390

Re: Multi layered music tutorial

Interesting.


Not active much anymore.
The only things I do now is just let inspiration come to me when it's needed.
Also bad profile pic because I don't have anything else in mind.

Offline

#12 2015-10-07 13:48:25

TheSeventhEmerald
Member
From: Spain
Registered: 2010-04-19
Posts: 302

Re: Multi layered music tutorial

KZR wrote:

play the music track as a sound effect. in theory, you can even program a basic sequencer inside the engine through scripting only.

If you make a big vertical object that moves right, and several other objects that play a sound effect when they collide with the big one, you can build levels that are actually songs smile

Well, the idea of sound effects is good, but you cannot synchronize the music with them. I mean, the sound effect will always start playing at the beginning. But the background song could be playing anyware, so they won't play synchronized.

So I think you cannot do the multi-layered music using sound effects.

Of course, the musical level is a real possibility smile And the sequencer idea is pretty funny.


Piece of cake...!

Offline

Board footer

Powered by FluxBB  hosted by tuxfamily.org