Multiple Background Music

For questions about using Classic.

Post » Fri Oct 14, 2011 7:16 pm

I can not seem to figure this one out. I currently have:

+ System: Start of layout
-> XAudio2: Autoplay resource "Skillet - Hero (instrumental).wav" (Loop)

How can I go about having multiple music clips playing one after another, but then looping back to the beginning of the play list? Is it easier to just combine all the clips into one, using my audio editor, to stick with just one background WAV for Construct?

Thanks.
B
5
S
1
G
1
Posts: 157
Reputation: 1,219

Post » Fri Oct 14, 2011 11:49 pm

I think you would be better just having a single WAV, or combining them all together. I'm not sure if there is any conditions available that deal with music files ending/starting, but I could be wrong.
B
8
S
2
G
2
Posts: 144
Reputation: 1,588

Post » Sat Oct 15, 2011 1:07 am

When using 'autoplay resource' you're using the sound part of XAudio2, not the music part. That has a few advantages. While playing music does not allow you to get informations about the music, you have control over sounds that are playing:

Get length
Get position

Just test the second against the first. There is only one thing to keep in mind, and that is the frames at which the game runs. If it runs with 60 fps you won't be able to catch the exact end of the song. It is better to just test if the position is greater than a certain distance from the end.

position >= length - 0.25 (or any other number that works with your framerate)

To get the channel number of the sound you can use 'Get last channel autoplayed', but it would be much easier to load the resource to a specific channel. Then use 'Set reserved' to protect this channel.

You can use an array for the file names of the wav files and a global variable that increases with every sound played and corresponds to the index of the next wav file name to load. But you would then need to load them from a folder, because if I remember right there's an issue that prevents using strings for the resources.
Image
B
23
S
8
G
10
Posts: 1,820
Reputation: 8,242

Post » Sat Oct 15, 2011 2:28 am

Here is an example to the explanations above:

http://www.scirra.com/forum/topic45283_post283470.html#283470
Image
B
23
S
8
G
10
Posts: 1,820
Reputation: 8,242

Post » Sun Oct 16, 2011 2:21 am

Thanks, palies. Will try it all out and report back.
B
5
S
1
G
1
Posts: 157
Reputation: 1,219

Post » Mon Nov 14, 2011 10:21 pm

Still looking at this. Although the events still a bit away for me to fully understand, I think I have the idea how it all works.
B
5
S
1
G
1
Posts: 157
Reputation: 1,219

Post » Wed Nov 16, 2011 7:16 pm

Is it more efficient to keep music as files to be pulled from a directory:

+ File: For each file in AppPath & "audio"

...and keep sound effects as resources:

-> XAudio2: Autoplay resource "Skillet - Hero (instrumental).wav" (Loop)
B
5
S
1
G
1
Posts: 157
Reputation: 1,219

Post » Wed Feb 22, 2012 4:11 am

To continue this, I have just recently made my first EXE in months and realized that the background music is not included, being set for files instead of being resources.

+ System: Is global variable 'currentfile' Less than global('fileindex')
-> System: Add 1 to global variable 'currentfile'
-> XAudio2: Load file AppPath & "music\" & filenames (global('currentfile')) to channel 1 (No loop)
-> XAudio2: Play channel 1
-> tCurrent: Set text to filenames (global('currentfile'))

+ System: Else
-> System: Set global variable 'currentfile' to 1
-> XAudio2: Load file AppPath & "music\" & filenames (global('currentfile')) to channel 1 (No loop)
-> XAudio2: Play channel 1
-> tCurrent: Set text to filenames (global('currentfile'))

Is it possible to set this up so they can be set as resources and therefore be included in the EXE package?
B
5
S
1
G
1
Posts: 157
Reputation: 1,219

Post » Wed May 08, 2013 3:49 am

I know this is kinda an old thread, but this is the issue that I am facing.

The previous post refers to:
-> XAudio2: Load file AppPath & "music\" & filenames (global('currentfile')) to channel 1 (No loop)

This allows the song name to be stored in a varaible.
But how do you actually put that line above into construct?
B
15
S
2
G
3
Posts: 61
Reputation: 2,321


Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 3 guests