New shuffle modes in Banshee
by Alexander Kojevnikov
Next version of Banshee will introduce two new shuffle modes: by rating and by score. In this post I will explain how they work since the modes can be a bit confusing.
In the random shuffle mode (aka shuffle by song), every track has an equal probability to be selected. For example if our library contains 1,000 tracks, each of them will be chosen with probability
Pt = 1 ÷ 1,000 = 0.001
But what if we want some tracks to be played more often than others? Say we have 100 favourite tracks and want to play each of them three times as often as any other track? In probability terms this can be written as
Ps = 3 × Pt
where s are our favourite tracks and t – the other 900 tracks in the library. Because the sum of all probabilities must be equal to one, we have
100 × 3 × Pt + 900 × Pt = 1 → Pt = 1/1,200
To chose the next track, we can pretend that our library contains 1,200 songs and pick one at random. If the track number is ≤ 100 × 3, we randomly select one of the 100 favourite songs, otherwise we take one of the 900 remaining songs.
If the library is partitioned into n slots, each containing Ci tracks, we will have
∑i=1,n Ci ⋅ wi ⋅ P1 = 1
where P1 is the probability of selecting a track from the first partition, and wi tells how frequently tracks from the i-th partition should be selected compared to the first one. That is Pi = wi ⋅ P1
Numbers wi are called weights and by changing them we control how often the songs from different slots are played. For example, we could pick a number (lets call it β) and require that songs from the second partition are played β times as often as the songs from the first one, songs from the third β times as often as the songs from the second, and so on. That is, wi = βi-1
For ratings, we have 5 partitions – one for each rating. We could also put all unrated songs into the 3-rd partition (to treat them as songs with 3 stars) so that our entire library is partitioned. Now a good question is what to use for β?
If we take β=1, all songs will have an equal probability to be selected. Note that it’s exactly the same as the shuffle by song mode. If we take β=2, songs rated 5 will be played twice as often as songs rated 4, and so on.
In Banshee we use β = φ ≈ 1.61803, also known as the golden ratio. This number has an interesting property:
φn = φn-1 + φn-2
In terms of ratings, it means that songs with 5 stars will be played as often as songs with 4 and 3 stars combined, and so on.
In the shuffle by score mode, the songs are partitioned into 20 slots, first slot for the songs scoring 1…5, second – for 6…10, and the last – for scores 96…100. We also put songs with no score into the 10th slot (46…50).
We cannot use φ for β because this time we have much more partitions – the songs with low scores would be hardly ever played. To keep scores behaving similar to ratings we need to scale the weights:
β = φ¼, wi = φ(i-1)/4
Hope that wasn’t too tangled and I promise next post won’t include a single formula :)
[...] versia.com (version)controlling thoughts « New shuffle modes in Banshee [...]
This is a fantastic idea!!!
I do have one question though… you say the score mode separates the library into 20 partitions. What criteria goes into the partitioning? (e.g. play count, skip count, ratings?, etc)
Thanks in advance.
@Dan: It’s the score, as implemented in the patch from bgo#555116. The score is an integer value between 0 and 100 that’s calculated based on the number of plays and the number of skips.
[...] Alexander blogged more about this feature. [...]
Amazing! Very good explanation, and very interesting too.
I always wondered how music players often calculate playing weights..
As you mentioned, Banshee uses a beta of phi. Any idea what other big music players use? (ie songbird, itunes, rhythmbox, etc..). Just curious :-D
@lefthandpisces: I don’t know, you will need to check their source code to find out ;)
[...] Nuevos modos de reproducción aleatoria. Podemos configurar el reproductor para que unas determinadas canciones tengan más probabilidades de ser elegidas. Todo esto tiene un fundamente matemático y podéis leer cómo funciona aquí. [...]
Too bad Banshee does not have the shuffle modes enabled! How on earth does one turn them on? They’re always disabled!
You probably have songs in the play queue. The play queue cannot be shuffled, but you can use the auto-DJ feature to populate it from a playlist or from the entire library using one of the shuffle modes. See my other blog post for details: http://versia.com/2009/09/23/updated-play-queue-in-banshee/
Hi. I’d like to shuffle by plays. Do you think it’s possible?
@Marco: Please add this request to bugzilla: https://bugzilla.gnome.org/browse.cgi?product=banshee. Should be easy to implement if there’s an interest in such a feature.
Thank. I’ll do it.
Comment on an old post, sorry for that. It there any more information of how the integer value of a song’s score is calculated? If not, I’ll probably search the source code, but might be complicated.
I’m particularly interested in the skip degradation of a given song’s score. The reason for this is that it would be interesting to see if partial skips (skips at a later time point in the song) are taken into account and whether the weight of such a “late skip” is lower than an “immediate or early skip”.
In the past, I’ve been annoyed by many shuffle functions in programs and played around with pattern recognition as a way to determine the current “listening mood” of the listener and weight songs by that. In such a function, you also have to go by song skipping to determine a song’s weight. (By the way, it was mostly an exercise in neural network programming, not a “real” development project.)
@William: The weight of a partial skip is proportional to the percentage of the play. Check TrackInfo.OnPlaybackFinished() for details: http://git.gnome.org/browse/banshee/tree/src/Core/Banshee.Core/Banshee.Collection/TrackInfo.cs#n81