# [SUGGESTION] Create audio list with C2

Discussion and feedback on Construct 2

### » Wed Apr 26, 2017 1:58 am

I tried it.. it's strange.. it depends on system resources I think.. and if it's already been played before.. on the first play through it's fine..sometimes I can hear the last cut, but not always.. but when I start the entire song over already having played it once, the overlap is too long and you hear each cut.

https://www.dropbox.com/s/7pbenhfmarbbq ... .capx?dl=0

Definitely streaming from disk is the culprit. If you read your tracks into memory that would fix it - not that you would want to do that.
B
101
S
34
G
16
Posts: 1,212
Reputation: 17,016

### » Wed Apr 26, 2017 4:53 am

Nice song ^^
B
50
S
22
G
58
Posts: 116
Reputation: 32,658

### » Wed Apr 26, 2017 5:35 am

Okay, you're doing it for soundtrack purposes. I'm a little tied up doing animation work to make an example, so hopefully this explains how to do it.

Each of your four clips need to have the full music for the time frame they should represent + the decay that overhangs the end of the bar. Don't worry about the length of the clips--you'll never use it. But this will give the most realistic approach and is how every major studio does things like this. So for this, I'm going to assume each clip is two measures long in 4/4 with a tempo of 140.

First, you need to determine the length of time for your segment. This is solved by 60/140*8 (60/tempo*beats). Store that in a variable.

Now, all you need to do is cue up the next track to play at that regular interval. So 3.428571 repeating. Just have C2 solve it and store the answer in a variable ("length" or whatever)--don't bother using a calculator. I'm going to assume you can come up with your own method for deciding which segment should play next. I keep track of the track currently playing, where it is in context of the piece, and assign the next segment based on that + game parameters.

So on the first play, store the current system time in a variable ("oldtime" or something). Your next segment should play at "oldtime" + "length" time. Don't use the Audio>Play action any more because you can't ensure events will run at the right times. It may not matter for visuals much, but 16ms is quite significant for audio. Now you should use the Audio plugin's Schedule option. Once the other segment is playing and the current system time is far enough beyond the "oldtime", schedule your next segment. Schedule it for "oldtime"+"length" then set "oldtime" to "oldtime"+"length". I suggest delaying when you call the schedule event until as late as you think reasonable so that you can make last-second changes in what track comes next should you need it. So I run my schedule event after something like 'is system time > "oldtime"+"length"- (however long you want. I suggest maybe 200 milliseconds or .2 seconds). This way, it will schedule the next track 200 milliseconds before it's time to start.

I've only tried this with the audio preloaded into memory. I'm not sure if streaming it (ie, putting it in the "Music" folder in C2) will have an effect. I put everything in the "Sounds" folder, personally, and just preload everything I need.

If you're going for mixed-meter stuff, change the "length" variable to a new solution of 60/tempo*beats whenever necessary based on however you determine what track comes next.

I hope this helps!
B
104
S
38
G
19
Posts: 962
Reputation: 18,026

### » Wed Apr 26, 2017 6:57 am

C-7 wrote:I've only tried this with the audio preloaded into memory. I'm not sure if streaming it (ie, putting it in the "Music" folder in C2) will have an effect. I put everything in the "Sounds" folder, personally, and just preload everything I need.

Now that you can unload sounds it's less of a problem but still.. you need to be careful here.. loading music fully into memory can take up a lot of space quick! If I remember correctly audio is uncompressed in memory so your 8MB song can easily be 80MB in memory. Add a handful more tracks and suddenly your footprint is half a GB... and that's no good.
B
101
S
34
G
16
Posts: 1,212
Reputation: 17,016

### » Wed Apr 26, 2017 10:18 am

Thanks for the advice and for the information.
Maybe it works the way you describe but it is beyond what I would like but I do not discard it, thanks for taking the time to describe the process! So this is a kind of suggestion.

THE IMPLEMENTATION OF REPRODUCTION LISTS IN CONSTRUCT

The example works perfectly, I have reproduced the song 3 times and I have never heard any silence or strange jump in chrome for windows, maybe there were jumps but I did not perceive them because I do not know the song exactly.
B
33
S
13
G
22
Posts: 847
Reputation: 14,826

### » Wed Apr 26, 2017 2:04 pm

jobel wrote:
C-7 wrote:I've only tried this with the audio preloaded into memory. I'm not sure if streaming it (ie, putting it in the "Music" folder in C2) will have an effect. I put everything in the "Sounds" folder, personally, and just preload everything I need.

Now that you can unload sounds it's less of a problem but still.. you need to be careful here.. loading music fully into memory can take up a lot of space quick! If I remember correctly audio is uncompressed in memory so your 8MB song can easily be 80MB in memory. Add a handful more tracks and suddenly your footprint is half a GB... and that's no good.

You're not thinking realistically about it. Uncompressed audio is about 10 MB per minute. Your scenario implies loading in nearly an hour of music at once, which is more than many games have for music in their entire soundtrack. In actual practice, particularly with interactive music, you'd never load in more than a couple minutes of music (15-30 MB) at a time, and you totally get more mileage out of less audio content with interactive music. This also is loaded into system memory and not vram, which most PCs have tons of. Even on mobile, which is quite limited, it's not even close to being an issue. Even before the ability to unload it was barely a problem in nearly all cases, but now it isn't at all.
B
104
S
38
G
19
Posts: 962
Reputation: 18,026

### » Wed Apr 26, 2017 5:05 pm

C-7 wrote:Your scenario implies loading in nearly an hour of music at once, which is more than many games have for music in their entire soundtrack. In actual practice, particularly with interactive music, you'd never load in more than a couple minutes of music (15-30 MB) at a time, and you totally get more mileage out of less audio content with interactive music.

I once wrote and produced 30 minutes of music for a small little game. if that music was not streamed they would have had serious memory issues - they simply would not have been able to do it with the graphics they had. All I'm saying is to anyone reading this is the same thing that is in https://www.scirra.com/blog/112/remembe ... our-memory - and even though it does not mention audio per say, I think at the time of writing it was not conceived of a reason for music to be read into memory.

also check out games like Undertale or Lisa.. crazy amounts of music
https://widdly2diddly.bandcamp.com/releases

EDIT: People want to make music games with C2. and look at the problems that KLANG had... it's just a friendly warning!
Last edited by jobel on Fri Apr 28, 2017 9:26 pm, edited 1 time in total.
B
101
S
34
G
16
Posts: 1,212
Reputation: 17,016

### » Wed Apr 26, 2017 6:39 pm

jobel wrote:
C-7 wrote:Your scenario implies loading in nearly an hour of music at once, which is more than many games have for music in their entire soundtrack. In actual practice, particularly with interactive music, you'd never load in more than a couple minutes of music (15-30 MB) at a time, and you totally get more mileage out of less audio content with interactive music.

I once wrote and produced 30 minutes of music for a small little game. if that music was not streamed they would have had serious memory issues - they simply would not have been able to do it with the graphics they had. All I'm saying is to anyone reading this is the same thing that is in https://www.scirra.com/blog/112/remembe ... our-memory - and even though it does not mention audio per say, I think at the time of writing it was not conceived of a reason for music to be read into memory.

EDIT: People want to make music games with C2. and look at the problems that KLANG had... it's just a friendly warning!

It's not worth arguing, that isn't the point of the thread. But my point is the developers would've been morons to load all 30 minutes in at once. The total amount of music for the project is irrelevant as of now. For instant playback of interactive music, the best bet is always loading what you need into memory. If you're just playing basic loops or tracks to play through, sample-accurate playback time isn't important and streaming is fine.
B
104
S
38
G
19
Posts: 962
Reputation: 18,026

### » Wed Apr 26, 2017 7:53 pm

@C-7 who's arguing? I'm saying be careful with reading that much data into memory. period. are you actually arguing to NOT be prudent? If so, that's terrible advice.
B
101
S
34
G
16
Posts: 1,212
Reputation: 17,016

Previous

### Who is online

Users browsing this forum: No registered users and 10 guests