quo
New Member
Posts: 13
Posts: 13
|
Post by quo on Jun 3, 2023 9:07:23 GMT
I have a 3 minute song. The first 20 seconds is an intro that should only play once. After which, the song loops from 0:20 to 3:00 continuously until the player leaves the area.
Poking around the settings, songs have a "loop" checkbox and "begin song time mode" field. Setting that to "Section" enables me to set 0:20 and 3:00 as the section to loop. So I'm half-way there. The only problem is that when the song is playing for the first time, it should start at 0:00.
What's the best way to set about doing this?
|
|
|
Post by DarkTonic Dev on Jun 3, 2023 15:23:45 GMT
Yeah you almost got it.
You should set up 2 "songs" both using the same audio clip, where the first one does 0:00 - 0:20 and the other does 0:20 - 3:00 as a section, then you'll auto-advance to the 2nd song which loops automatically. You'll need crossfade set to zero.
|
|
quo
New Member
Posts: 13
Posts: 13
|
Post by quo on Jun 3, 2023 17:18:03 GMT
Thank you! This sorta does the trick, but the transition from the intro clip to the looping clip has a bit of a hiccup. Could the song's status as an addressable be the cause the hiccup problem or am I just not using the right time values?
Also, about crossfade, is there a way to set individual crossfade settings per song? Most of the time I need crossfade set to ~2 seconds. I have a one-scene game. When the player leaves the forest area and enters the volcanic area, crossfade smooths the transition between two different area tracks.
I am curious what other alternative methods there are for achieving a one-time intro. For example, is there a function to set the current playlist controller time? So I could have the section set to loop for 0:20 and 3:00, except when I first play the song, I manually set the time "PlaylistController.SetTime(0f)" and that could override the section loop once. Is there a function like that?
Much obliged!
|
|
|
Post by DarkTonic Dev on Jun 3, 2023 18:37:01 GMT
Thank you! This sorta does the trick, but the transition from the intro clip to the looping clip has a bit of a hiccup. Could the song's status as an addressable be the cause the hiccup problem or am I just not using the right time values? Also, about crossfade, is there a way to set individual crossfade settings per song? Most of the time I need crossfade set to ~2 seconds. I have a one-scene game. When the player leaves the forest area and enters the volcanic area, crossfade smooths the transition between two different area tracks. I am curious what other alternative methods there are for achieving a one-time intro. For example, is there a function to set the current playlist controller time? So I could have the section set to loop for 0:20 and 3:00, except when I first play the song, I manually set the time "PlaylistController.SetTime(0f)" and that could override the section loop once. Is there a function like that? Much obliged! No, addressable should not cause an issue. However, you will need to check the checkbox for "gapless music switching" in Advanced Settings. www.dtdevtools.com/docs/masteraudio/AdvancedSettings.htmCrossfade per song, no. It's per playlist only. There is also no crossfade when you switch to a new playlist, so the only way possible would to use separate playlists and separate playlist controllers for the different fade time. Each song has a dropdown "begin song time mode" has a choice called "specific time" that you can use, but it may not support runtime alterations. Yes, there is a way to programmatically set the time of a song, but it's likely to cause sounds artifacts.
|
|
quo
New Member
Posts: 13
Posts: 13
|
Post by quo on Jun 4, 2023 8:43:48 GMT
Thanks for letting me know what my options are. Ideally, I'd like to keep all the music to one playlist for a variety of reasons (plus, it feels kinda hacky to have 2 playlists split by songs with an intro and songs without - and then to make them function as if they were one playlist...) You said there is a way to programmatically set the time of a song, but it's likely to cause sound artifacts. Can you expound more on what function that is? I'd like to try it and see how bad the sound artifacting is. Another method I'm trying to explore is CustomEvents. So have the song loop on section time, 0:00 - 3:00. And through an event, switch the section time to 0:20 - 3:00 through a timer or such. Would this work? I'd like to try it, but hit a snag getting events to work. I'm using the provided MA_SampleCustomEventReceiver (attached to camera in my scene). However, no events ever fire. Here's a picture of my setup: imgur.com/h1osKp2Sorry for all the questions. Appreciate your help!
|
|
|
Post by DarkTonic Dev on Jun 4, 2023 14:33:59 GMT
If shuffle is turned off for the PlaylistController, there should be no issue putting all songs in one Playlist as long as you always tell it which intro to start on. It would auto-advance to the looped section and play it indefinitely until you queue or play another intro.
For Custom Events, show me the Inspector of your script that's supposed to receive. You should have the custom event name matching to a field there I believe. Also send the entire script over so I can see it.
For code to set the time, try this:
var songAudio = PlaylistController.InstanceByName("YourPlaylistControllerName").ActiveAudioSource; if (songAudio != null) { songAudio.time = 20f; }
|
|
quo
New Member
Posts: 13
Posts: 13
|
Post by quo on Jun 5, 2023 18:30:18 GMT
I do have shuffle turned off. The suggested solution you have does work, BUT the main problem with it is that it's incompatible with cross-fading. Without crossfading, transitioning between 2 areas sounds too abrupt. Custom events would have been my means to change song or playlist variables via script at runtime. For now, I've worked around events by simulating it in FixedUpdate() and just checking when the song is ready. I figured it would be best to know if the solution I was pursuing even worked first before going through the work of getting events to work. And it turns out that it doesn't ... - The first setup I tried was to have sectionStartTime and sectionEndTime set to the looping start and end, and then to set songAudio.time = 0 when the song played. I figured this would make the song play from the beginning, and then when it reached the section end, the “loop section” logic would take over, and everything would work. Unfortunately, it turns out that if you set songAudio.time = 0f and rewinded the song 20 seconds from sectionStartTime, the loop_section would also loop 20 seconds earlier - so it doesn’t reach the end and will loop prematurely.
- The second setup I tried was to have sectionStartTime and sectionEndTime set to 0 and the song's full length respectively. Then when the song played and reached the midpoint, set sectionStartTime forward to 20 seconds (when the loop began) via script. This one showed the most promise, but it'd be fractions of a second off. So the first loop doesn't hit correctly.
So, like you forewarned the sound artifacts will be present ...
So having exhausted that avenue, the only other solution I can think of now is to do what you suggest, and then to separately simulate cross-fading. So turn on gapless switching, turn off cross-fading, and have "2" songs (that are really the same song- one covers the intro and one covers the loop). Do all that, and then simulate the cross-fade for when moving between 2 areas via scripting... Can you tell me your thoughts for how to best simulate cross-fading between two songs? Thanks again for your help!
|
|
|
Post by DarkTonic Dev on Jun 6, 2023 1:18:01 GMT
Thanks, yeah I figured it would mess up the loop or other artifact. Playlist Controller code is extremely complex and does handle quite a bit but not every possible permutation.
Are you asking how to crossfadie between 2 different songs that each have an intro and loopable section? Which would be set up as 4 "songs" in Playlists BTW. I'm not clear on the specifics of what you're wanting to do.
|
|
quo
New Member
Posts: 13
Posts: 13
|
Post by quo on Jun 6, 2023 2:21:34 GMT
Yes. That is exactly what I'd like to do. How best to achieve that?
|
|
|
Post by DarkTonic Dev on Jun 6, 2023 15:16:37 GMT
I'm not sure you can. You can try setting up 2 separate Playlist Controllers, 1 for each each song broken into 2. Then when you want to crossfade, use code to "FadeToVolume" (zero) the currently playing PlaylistController. At the same time, start playing the other PlaylistController with the new song, then FadeToVolume (zero) with 0 fade time, followed by FadeToVolume to your desired volume level.
Pretty hacky, but it may work.
|
|
quo
New Member
Posts: 13
Posts: 13
|
Post by quo on Jun 6, 2023 16:14:30 GMT
Mmm... that does sound pretty hacky. There'd have to be 4 "songs" per song. One for the intro, one for the loop. Multiply that by 2 since a song would need to would occupy both playlists (the game is non-linear adventure, so song A, B, and C may each lead into one another).
Hmmm... at this point, it seems our best solution, all factors considered, is to give up on the idea of play once intros. Going to have a chat with the musician about it, but wanted to know what our options were.
Thanks again for answering my questions!
|
|
|
Post by DarkTonic Dev on Jun 6, 2023 20:14:10 GMT
No problem.
|
|