Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Random algorithm reapeating songs frecuently #475

Open
apika opened this issue Nov 16, 2016 · 23 comments
Open

Random algorithm reapeating songs frecuently #475

apika opened this issue Nov 16, 2016 · 23 comments

Comments

@apika
Copy link

apika commented Nov 16, 2016

Is possible that the shuffle option is not really that shuffle? After some time listening in this mode or when reseting the phone, I found that some songs shuffle "together".
Does Vanilla algorithm works like Winamp's shuffle? When You shuffle in Winamp (at least old versions), It will jump X number ahead in the list so using the same list and starting from the same point will give you the same songs order,

Sorry for not giving a lot of feedback, I found this very difficult to debug.

@adrian-bl
Copy link
Member

Just to make sure: Are you talking about shuffling the timeline (eg: the button on the left side) or the Random mode (the dieces on the right side) ?

The random mode creates an internal playlist with all songs and will pop() one of them if you reached the last item on the playlist.

@apika
Copy link
Author

apika commented Nov 17, 2016

I am talking about the Random mode, some programs translate Shuffle as Random (but in spanish) so there was my confusion. The left button doesn't affect this situation.

@apika apika changed the title Shuffle algorithm reapeating songs frecuently Random algorithm reapeating songs frecuently Nov 17, 2016
@adrian-bl
Copy link
Member

I am talking about the Random mode,

Ok, thanks for clearing this up.

It will jump X number ahead in the list so using the same list and starting from the same point will
give you the same songs order,

No: Our Random mode works different:

Vanilla Music fetches all songs from the library and keeps them in a shuffled array. Every time the end of the queue is reached, the last item of the shuffled array is removed and appended to the queue.

So songs should will only start to repeat after all songs in the library have been played.

@apika
Copy link
Author

apika commented Nov 25, 2016

So songs should will only start to repeat after all songs in the library have been played.

Just today I hear Anyway by Genesis and Octopus's Garden twice in less than 2 hours of non continuos music playing. I have a lot of music in my SD, for sure more than 2 hours (cause prog rock, 6 tracks are 2 hours for example). I didn't reset my phone in the middle.

Does this shuffled array resets every time I stop playing music? Theres a way to mantain this array even when closing the app/stop playing music?.

@adrian-bl
Copy link
Member

Does this shuffled array resets every time I stop playing music? Theres a way to mantain this array
even when closing the app/stop playing music?.

No, but it will reset if Vanilla Music gets killed while being in the background, which is rare but might happen (depending on your OS and Hardware)

@apika
Copy link
Author

apika commented Nov 29, 2016

There is a way to know that? Something like the queue not remembering your last song? Or the notification closing even when you left it to be always on?

@adrian-bl
Copy link
Member

There is a way to know that? Something like the queue not remembering your last song?

Hmm, no: such restarts are somewhat hard to spot: One way to tell is if the scrolling position in the library view jumped back to the top

@hboetes
Copy link

hboetes commented Feb 28, 2017

getting random songs is not as easy as it sounds: http://www.independent.co.uk/life-style/gadgets-and-tech/news/why-random-shuffle-feels-far-from-random-10066621.html

You basically have to take notes for how often you have played songs and try to play each song as often as the other. And take changes in the collection into account so you have to store the first time the track showed up in the collection as well.

I would welcome that feature.

@adrian-bl
Copy link
Member

With the new media db, we have this information at hand: We keep track the mtime and a play- & skipcounter for every song.

Implementing a smarter random mode could therefore be done in a single SQL statement.

Feel free to give it a try (you can grab a copy of the sqlite database if your phone is rooted from /data/data/ch.blinkenlights.android.vanilla/databases)

@hboetes
Copy link

hboetes commented Feb 28, 2017

Awesome that you are working on implementing this!

@adrian-bl
Copy link
Member

You misunderstood me: i am not working on this, i just said that the required data is already there

@hboetes
Copy link

hboetes commented Feb 28, 2017

I’m trying to inspire you. :-)

@Kaned1as
Copy link
Member

Kaned1as commented Feb 28, 2017

Lol, this is actually a very funny issue :D

Go ahead, tell me that I miss entropy in my /proc/sys/kernel/random/entropy_avail so I should prematurely click at random places of screen every time I want my next song to be truly random XD

@hboetes
Copy link

hboetes commented Mar 1, 2017

ok, let me explain the issue for you, look at this code:

for i in {1..100}; do echo $(($RANDOM % 100 + 1)); done|sort -n|uniq -c|sort -n

Do you really want some of your 100 tracks to be played 3, 4 times and others not at all? True randomness doesn’t help with that issue. Most people want their tracks to be played equally often but in random order.

This is the same code, but with much better randomness:

for i in {1..100}; do rndm=$(od -vAn -N4 -tu4 < /dev/urandom); echo $(($rndm % 100 + 1)); done|sort -n|uniq -c|sort -n|tail

Same result.

@Kaned1as
Copy link
Member

Kaned1as commented Mar 1, 2017

Ok, that makes sense.

But we maintain a list of available songs in random order and just walk through it in this mode, so songs aren't repeated.

The only issue I can see is that when this list ends and next song is requested, the list is reshuffled and may provide the same song as the one that was last (or near enough to the end of old list) as first one. This may give impression of imperfect random mode.

@hboetes
Copy link

hboetes commented Mar 1, 2017

Oh that’s interesting. Where is that list stored?

@Kaned1as
Copy link
Member

Kaned1as commented Mar 1, 2017

IIRC it's somewhere in MediaUtils.getRandomSong

@hboetes
Copy link

hboetes commented Mar 1, 2017 via email

@mindforger
Copy link

mindforger commented Mar 1, 2017

you could split your list in 3 pieces

1st, 2nd and 3rd part (which i will call buffer)

when finished with the 1st, you scramble a new 1st from half the 1st and the buffer, left over songs get dropped in buffer

when finished with the 2nd, you scrambe a new 2nd with half the songs from buffer and the 2nd part, leftovers back to buffer

the distance between a song repeating is never smaller than a third of the list

or did i forgot any corner case?

the chance of a song never beeing played still is present

Could be done quiet easily with a infinite linked list!

@adrian-bl
Copy link
Member

The current implementation (see getRandomSong) grabs a copy of the library, shuffles it and pops a song on every call.

We are not repeating songs until the random list is cleared (app restart) or exhausted

@hboetes
Copy link

hboetes commented Mar 2, 2017

Right, that explains my issue. As soon as I stop the car the app is restarted. Would it be possible to store the library so it survives restarts?

@apika
Copy link
Author

apika commented Jun 25, 2017

You could make you list (if you want all the songs just click in play all), then shuffle tracks and save that list. That's how I fix my "problem".

@SebiderSushi
Copy link

Vanilla Music fetches all songs from the library and keeps them in a shuffled array. Every time the end of the queue is reached, the last item of the shuffled array is removed and appended to the queue.

So songs should will only start to repeat after all songs in the library have been played.

Wait - i always thought it would be the other way around?
Because this behavior sounds a lot like Shuffle & Repeat, which also reshuffles the list once all songs have been played. The only differences being that you can have can always see all passed and future tracks in the queue instead of 20 passed and the unplayed tracks and that it does not get reset on app restarts, which, as i read it, was mostly experienced as a (possibly unwanted) side effect rather than a feature.

With a shuffle mode like this i always presumed that "Random" would in contrast mean that every track from the library would have a statistically equal chance of being the next one.

What sets the Random mode apart from Shuffle & Repeat in regards to plaing dynamics?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants