dgerb
New Member
Posts: 7
Posts: 7
|
Post by dgerb on Feb 3, 2016 20:41:36 GMT
Hi there! I'm trying to create a musical pattern of Intro, Loop1, Bridge, Loop2 for one of my levels. Basically, it starts the Intro and enters Loop1 where it will loop until the main character walks through some door. Then it will play the Bridge and go to Loop2. When the character walks through the door, I'm calling this line: plc.StopLoopingCurrentSong (); where plc is the current PlaylistController. However, it doesn't seem to work as I thought it would. It basically stop looping Loop1, but doesn't queue the Bridge. When I inspect the PlaylistController's AudioSources, I do indeed find that the inactive AudioSource is not being updated. Am I doing something wrong? I have attached my playlist as is stored in the global MasterAudio singleton. Note that in these pictures, I label my Intro as Bridge_1, and Bridge as Bridge_2. Sorry for the confusion. Thanks! Daniel
|
|
dgerb
New Member
Posts: 7
Posts: 7
|
Post by dgerb on Feb 3, 2016 20:45:24 GMT
On a side note, I did try this code:
plc.StopLoopingCurrentSong (); string songName = plc.CurrentPlaylistClip.name; while (plc.CurrentPlaylistClip.name == songName) yield return null; yield return null; yield return null; tracks [index].isLoop = true;
It seems to work as desired 50% of the time. The times it does not work, it will have a long gap (about the length of the Bridge), and then continue as intended. Even during the times it works, the music may switch songs seamlessly, but there's a very noticeable 0.1 second hickup in the game's framerate. I would assume that something still isn't getting loaded.
|
|
|
Post by DarkTonic Dev on Feb 4, 2016 2:36:05 GMT
There's always settings you haven't mentioned that may or may not make this hard to reproduce, so we ask that you always send a small project that reproduces the problem. Please see the official bug reporting rules thread stickied in this forum.
I will watch for your reply!
|
|
dgerb
New Member
Posts: 7
Posts: 7
|
Post by dgerb on Feb 4, 2016 21:30:50 GMT
Hi,
Sorry that I missed the bug reporting rules thread! Here's a link to a test project. I'm not really sure what you meant by asking us to remove the MasterAudio plugins since that would cause the project not to function.
LINK REMOVED.
It's basically the demo except with a soundtrack as described in the first post. If you press "O", it should break out of Loop1 (and go back to Bridge1). The code is in MusicManager.
In creating this, I discovered that I have this problem when MasterAudio's Gapless Music Switching option is turned on. When I turn that option off and try again, the problem goes away. I'd prefer to use Gapless Music Switching if possible.
Thanks, Daniel
|
|
|
Post by DarkTonic Dev on Feb 4, 2016 23:15:58 GMT
You have to remove the Master Audio plugin when posting on a PUBLIC page because otherwise it would allow people who didn't even buy it to obtain the source code. I will install the latest version of MA from the Asset Store after downloading your project so it will compile.
I have removed your link.
I will take a look at this soon and report back. Thank you.
|
|
|
Post by DarkTonic Dev on Feb 5, 2016 0:46:27 GMT
I think you just need to add these 3 lines of code to the end of StopLoopingCurrentSong method in PlaylistController.cs. Let me know if this fixes it for you.
if (CanSchedule) { ScheduleNextSong(); }
|
|
dgerb
New Member
Posts: 7
Posts: 7
|
Post by dgerb on Feb 5, 2016 19:22:33 GMT
EDIT: issue #2 solved when I updated MasterAudio once again.Thanks! That fix now causes StopLoopingCurrentSong to work with Gapless Music Switching in my project! The problems discussed here do still remain: It seems to work as desired 50% of the time. The times it does not work, it will have a long gap (about the length of the Bridge), and then continue as intended. Even during the times it works, the music may switch songs seamlessly, but there's a very noticeable 0.1 second hickup in the game's framerate. I would assume that something still isn't getting loaded. Basically, there are two main issues: 1. A 0.1 second hickup in the framerate when switching from Loop1 to Bridge. (for reference, the form is Intro, Loop1, Bridge, Loop2) 2. The long gap in audio when switching from Bridge to Loop2. To address problem 1, I suspected that the hickup is due to loading a long audio (possibly Loop2). So I added this code that loads all the level's audio at the start of the level: tracks = plc.CurrentPlaylist.MusicSettings; foreach (MusicSetting ms in tracks) clips.Add ((AudioClip)Resources.Load(ms.resourceFileName));
Adding this code seemed to fix the issue. However, I wonder if I should consider un-loading Intro, Loop1, and Bridge once the song has progressed to Loop2. As for problem 2, I have discovered why this long gap happens. During a cutscene while somebody's talking, I will sometimes pause the game (Time.timeScale = 0.0f). It would seem that the PlaylistController can't switch tracks when the game is paused. I'll update my test project with a pause feature and send you a link in a bit. And thanks again for your continued support!
|
|
dgerb
New Member
Posts: 7
Posts: 7
|
Post by dgerb on Feb 5, 2016 20:00:58 GMT
Ok, this is a bit embarrassing, but my main project wasn't updated completely, which caused issue 2 in the above post. Once I fully updated the project, issue 2 went away.
I'm still a bit curious if you have any advice on solving issue 1 in a more effective manner than the code from the post above.. But it's not too pressing, since everything seems to work!
Thanks again, Daniel
|
|
|
Post by DarkTonic Dev on Feb 5, 2016 20:30:58 GMT
Issue #1 may occasionally be caused by Unity itself, which can hiccup when it finished loading resources that are large sometimes, and thus is not avoidable. You might want to try using the "preload audio data" turned off instead of Resource files and see if that's any better.
Note that the resource loading code and "preload audio data" code that is used for gapless in MA already loads the next clip well in advance so it can schedule the next song. There is substantial code in MA to handle unloading previous songs to minimize on memory usage. If you load all the Resource'd songs at the beginning of the Scene (your code you posted), you lose any memory advantage and you may as well just be using Audio Clips instead of Resource files. Yes that would be better on performance but at the cost of audio memory. All memory from all songs would be initially needed, which is bad.
|
|
dgerb
New Member
Posts: 7
Posts: 7
|
Post by dgerb on Feb 5, 2016 22:57:31 GMT
In this case, Loop2 is much much larger than Intro, Loop1, or Bridge. I wouldn't mind loading them all at once at the beginning of the level, and then unload each clip after it has finished playing. I'm a bit confused on how AudioUtil and AudioResourceOptimizer do this.
I'd like to load all the clips from a single playlist at the beginning of the level, but then let MasterAudio unload each clip once it's finished playing. Is the procedure to load the clips to some list, listen for a song changed event, and remove the clip from the list manually? Does MasterAudio perhaps have a built in functionality that will do this? I see a function called PopulateSourcesWithResourceClip() and a dictionary AudioClipsByName already in being used in AudioResourceOptimizer, but these are only for sound effects (and not playlists), right?
|
|
|
Post by DarkTonic Dev on Feb 6, 2016 0:09:00 GMT
What I'm saying is that there's no point loading ALL resource clips in a Playlist at the beginning of a Scene (if you have enough memory to do that, why not just use non-Resource files)? The entire point of using Resource files (or Preload Audio Data off) is to minimize the amount of audio memory being consumed at any one time (1 song in memory for non-gapless or 2 songs in memory for gapless). For example if you have 6 songs in a Playlist, and are doing a mobile game, you probably don't have enough memory to load all 6 into memory unless your game doesn't have much in the way of large textures and other assets. So you're forced to use Resource files to avoid crashing the game. Even if you do have the room available, it's a waste of memory really.
So, if you have enough memory to load all the songs at the beginning, then unloading them one by one from memory later doesn't matter much. You have no advantage in doing this, and are wasting time writing that code when you could just use Audio Clips instead of Resource files. AudioResourceOptimizer only loads up a song when it needs to schedule the next song for gapless, or does so much later for non-gapless. In either case, the Resource file is automatically unloaded when the song ends and the audio stops. There is a list of audio files in that class for Playlists as well. You don't need to be concerned with how it works, but it does work.
|
|
dgerb
New Member
Posts: 7
Posts: 7
|
Post by dgerb on Feb 6, 2016 1:37:29 GMT
Thanks for the advice! I may go ahead and use clips then. Just to be sure, if I have multiple playlists each with several clips, the AudioClips from an inactive playlist (one that is not currently playing) will NOT be loaded into audio memory, right?
|
|
|
Post by DarkTonic Dev on Feb 6, 2016 2:49:32 GMT
No that's incorrect. Clips from all playlists in the master audio game object will be loaded into memory unfortunately, due to how unity works. I would still try turning off "preload audio data" on your song clips and see if it is smoother.
You can get around this by only adding one in the MA game object and using Dynamic Sound Group Creator prefabs (read up on those).
|
|