clive
New Member
Posts: 7
Posts: 7
|
Post by clive on Jun 24, 2015 22:37:02 GMT
Hi,
1) How can I tell which is the currently playing item (by index) in a sequential playlist? Cross referencing audio clips seems to be the only way I've found so far and my issue is that I prepopulate with the same audioclip in several places within the playlist.
2) How can I remove items that have already been played and then add new items at the end of a currently playing playlist? I have algorithms external to Master Audio which decide on what clips get played sequentially and play, theoretically, in infinitely long song. Unfortunately I don't want to use the memory to build hours long playlist up front, I'd like to remove items that have already been played and then add more to the end when the playlist is below a certain length - but for this I need current position as mentioned above as well as to be able to remove items from playlists and append as well.
I keep reading about "Dynamic Playlists" and wonder if this can help me, but I've been unable to find any classes by that or similar name nor have I been able to find any documentation aside from a few forum posts which say things like "create a dynamic play list" ... but none of them mention how to actually do that.
Thanks,
|
|
|
Post by DarkTonic Dev on Jun 25, 2015 0:17:06 GMT
#2) Playlists don't work like that. They don't remove finished clips from memory, unless they are set up as Resource Files, which is why we recommend always using Resource Files for music. Hours long playlists when configured with Audio Clips (not Resource Files) will indeed take up all the audio memory of all the songs all the time. I don't think there's a way to avoid that either, since a public Audio Clip variable referencing a song (such as you need to store an Audio Clip that's in a prefab in the Scene) MUST take up its memory. Unless there's a "load type" new to Unity 5 that gets around that?
About playing different songs in different orders based on logic, we do that in our game. We just play the songs by name via code, only having each song occur once in the Playlist. You can also use the "queue song" Playlist methods to say "play this song next", but it must already be in the Playlist. Consult the API website for a full list of these.
Dynamic Playlists only mean they aren't configured in the Master Audio game object, but in their own prefab that - when enabled - copies its Playlist into the Master Audio game object until it's disabled. The Dynamic Sound Group Creator prefab is what makes all the "Dynamic" stuff such as Playlists and SFX. There's a whole section on that in the readme.
Question #1 - index: you can't. You can get the name of the song though.
if (PlaylistController.Instances[0].CurrentPlaylistClip != null) { var songName = PlaylistController.Instances[0].CurrentPlaylistClip.name; }
The list of songs in a Playlist is accessible from the following code if you wanted to try adding to and removing items from it:
PlaylistController.Instances[0].CurrentPlaylist.MusicSettings;
However, if you have auto-advance turned on, this will likely lead to buggy behavior as the internal song scheduler song-counting array only gets initialized when a new Playlist gets loaded up.
Edit - I found a new setting "Preload audio data" for Unity 5. I'll add future support for this so Resource Files are not required to save memory.
|
|
|
Post by DarkTonic Dev on Jun 25, 2015 6:00:17 GMT
Today I added support for Preload Audio Data for Unity 5 users. That way it unloads audio data for each song that gets done getting played. So you don't have to use Resource Files for memory saving.
The next version will have this update.
|
|
clive
New Member
Posts: 7
Posts: 7
|
Post by clive on Jun 25, 2015 6:22:24 GMT
Each playlist (of mine) has about 10/12 clips which cross (without fade, I had to modify your source to remove the fade) into each other and get stitched together seamlessly to create the feeling of infinite variance of music.
This is what I was trying (direct copy paste from my own song controller):
void Update()
{
if (!_playing) return;
if (_currentPlaylist != null) {
if (_currentPlaylist.MusicSettings.Count > 0)
{
if (DarkTonic.MasterAudio.MasterAudio.OnlyPlaylistController.CurrentPlaylistClip != _currentPlaylist.MusicSettings[0].clip )
_currentPlaylist.MusicSettings.RemoveAt(0);
}
if (_currentPlaylist.MusicSettings.Count < 3)
addTrackIteration (_currentPlaylist, true);
}
}
Unfortunately, as you pointed out, the current index gets confused and it thinks it's at the end of the playlist.
Because I'm re-using the same audioclip (from my own internal cached store) throughout the playlist the actual memory used by audioclips is relatively low because it's references and not unique audioclips per-item.
Maybe I'm over thinking this, perhaps the best solution is merely to create and pre-populate a playlist, on level start, that's estimated to be many times longer than the longest play time and if someone does just stand there in a level it'll eventually cycle back to the start ... however all this could be solved if I could just remove the very first playlist entry, because that clip is "unique" in for "start level" if, after that clip plays, I was able to remove just it (the first one) without Master Audio indexes getting confused, then the rest of the playlist would loop 100% seamlessly.
|
|
|
Post by DarkTonic Dev on Jun 25, 2015 6:43:05 GMT
Do you know you can just set the crossfade to zero seconds in the UI? Defaults to 3 seconds. And then there's another switch for "Gapless Music Switching" you can turn on that will make it gapless regardless of frame rate stutters or time scale.
You could use a "Playlist of one" song for that intro piece and a separate Playlist for the rest, which ends up repeating all except the first if you loop the 2nd Playlist. Except it might not be gapless when switching to another Playlist. You'd have to try it and see.
If it doesn't work, we'll see if we can figure out a way to make it work for you.
-Brian
|
|
clive
New Member
Posts: 7
Posts: 7
|
Post by clive on Jun 25, 2015 6:52:04 GMT
Do you know you can just set the crossfade to zero seconds in the UI? Defaults to 3 seconds. And then there's another switch for "Gapless Music Switching" you can turn on that will make it gapless regardless of frame rate stutters or time scale. You could use a "Playlist of one" song for that intro piece and a separate Playlist for the rest, which ends up repeating all except the first if you loop the 2nd Playlist. Except it might not be gapless when switching to another Playlist. You'd have to try it and see. If it doesn't work, we'll see if we can figure out a way to make it work for you. -Brian I need cross, but not fade, the individual music samples (or slices) have been created with the intent that they overlap each other - without any fading applied. I quickly tried creating a playlist of over 300 audio clips, total memory usage 38mb. Everything performs very well, except the MasterAudio inspector (if open) has massive overhead (unsurprising) -- this is minor though since it's in editor and only during play and only if I open masteraudio in the inspector to view the incredibly large playlist. Each of my track slices have a variant overlap depending on the track itself, for example some are 3.2 seconds (75 bpm @ 4bpb) whereas some are 70 bpm @ 4bpb. my very small patch to "remove" fading is as follows, I comment out these lines at around line number 367 of PlaylistController.cs: _activeAudio.volume = ratioPassed * _activeAudioEndVolume;
_transitioningAudio.volume = _transitioningAudioStartVolume * (1 - ratioPassed);
... and I replace with just one line: _activeAudio.volume = Mathf.Max ( ratioPassed * _activeAudioEndVolume, _activeAudioEndVolume-0.000001f ); ... it's a bit "hacky" but it works and all my music requires it. Ideally "in a perfect world" I'd be able to continuously & procedurally populate and remove from a playlist without interfering with current playing audio.
|
|
clive
New Member
Posts: 7
Posts: 7
|
Post by clive on Jun 25, 2015 8:31:33 GMT
Let me summarise my ideal requirements again after all the above. All I need is the ability to be able to somehow get access to: * How many entries are "still to be played" in the playlist so I can append tracks if that's low - eg: playlist.MusicSettings.Count - ( playlist.MusicSettings.currentlyPlayingIndex + 1 ) * And then for RAM preservation, the ability to remove already played MusicSettings content - or complete win a checkbox for playlists which does an auto-remove after completed playing (but not destructive of audioClips, just removal of line items). I could probably code these myself in branch off your source if this is not something you'd ever look at I'd just like to know if this is something you're open to adding to MasterAudio main or not so I can proceed. Thanks
|
|
|
Post by DarkTonic Dev on Jun 25, 2015 15:51:03 GMT
A RAM preservation technique already exists, by either using Resource files, or in the next update (as I said above) you can just uncheck "Preload Audio Data" on all the Playlist's Audio Clips.
If you want to read how many haven't been played in a Playlist, make this variable public or add an accessor, which is in PlaylistController.cs near the top.
private readonly List<int> _clipsRemaining = new List<int>(10);
Adding tracks will not update _clipsRemaining, but you could increment it manually. Removing tracks at all is problematic because you need to make sure it's not the track currently playing and also that it's not the next track already scheduled to play when auto-advance with gapless is turned on.
At this time, we are probably not adding anything else in this area.
|
|
clive
New Member
Posts: 7
Posts: 7
|
Post by clive on Jun 25, 2015 21:00:32 GMT
I think you keep misunderstanding me: I don't care about audio clips - It's never using more than 38mb ram for audio clips because of how I'm already pooling them. I'm talking about ram (and processing as well) in playlist length. I don't want a play list that grows forever. I want to delete behind played items in the list so it'll never be an issue because I'll only ever be deleting the first item in the playlist after it's finished playing. Think of the playlist as a rolling queue. next track would never be an issue i'd never be deleting something not yet played.
|
|
clive
New Member
Posts: 7
Posts: 7
|
Post by clive on Jun 25, 2015 21:07:52 GMT
The MasterAudio inspector window is so slow it makes the entire unity editor unresponsive when I have around 300 items in the playlist. I need to be able to "delete behind" so it's always kept small and clean while adding new ones it's removing old ones from the playlist -- that is what I need.
|
|
|
Post by DarkTonic Dev on Jun 25, 2015 21:19:09 GMT
I don't think adding what you want is doable without breaking other Playlist features. Features you may not be using, but we don't drop support for existing featured unless a Unity update makes it impossible.
Yeah 300 songs in a Playlist is ridiculous.
Sounds like you will need to branch the code. It may in fact be easier to do without using a PlaylistController. Just using Sound Groups.
|
|
clive
New Member
Posts: 7
Posts: 7
|
Post by clive on Jun 25, 2015 21:28:37 GMT
I don't think adding what you want is doable without breaking other Playlist features. Features you may not be using, but we don't drop support for existing featured unless a Unity update makes it impossible. Yeah 300 songs in a Playlist is ridiculous. Sounds like you will need to branch the code. It may in fact be easier to do without using a PlaylistController. Just using Sound Groups. ok, i've solved this I added to PlaylistController: public int currentSequentialClipIndex { get { return _currentSequentialClipIndex; } set { _currentSequentialClipIndex = value; } }
then in my own code I have: if ( DarkTonic.MasterAudio.MasterAudio.OnlyPlaylistController.currentSequentialClipIndex > 1 )
{
_currentPlaylist.MusicSettings.RemoveAt(0);
DarkTonic.MasterAudio.MasterAudio.OnlyPlaylistController.currentSequentialClipIndex--;
}
... end result FIFO style playlist cleaning up after itself (how I'm doing procedural additions to playlist is in prior posted example and not repeated here)
|
|
|
Post by DarkTonic Dev on Jun 26, 2015 0:46:50 GMT
Excellent, glad you got it working.
|
|