Post by j***@astraweb.comPost by g***@aol.comPost by j***@astraweb.comi have a playlist of some 700 songs and it seem that i can count on the same ones playing in the first
few hours.. (it has a 56 hour play time, according to the calculations of the VLC player)
I can watch the playlist bounce around the list as one finishes so it is not sequential.
Is there a way to prevent this?
Randomizers are seldom actually random. Sometimes if you manually
select a song while it is playing random it reshuffles the deck with
some players. I run MPXPLAY and that will scramble them playing that
way
VLC 3.0.3, Vetinari, seems to run the same algorithm on random play audio files?.
A. It looks like you read the title -- thanks for that!.
B. I have tried that manually selecting thing you talk about and it does seem to work. I just don't
think that kind of hands-on interference should be necessary.
What's a little Whack-A-Mole amongst friends ?
The human brain is a fickle thing, so so hard to satisfy...
*******
Why not get the source for VLC and see *why* it does that.
The VideoLAN site uses mirrors for the source. The free 7-zip.org
tool can extract this for you (as .xz is not all that common on a
windows box).
(Swiss army knife: https://www.7-zip.org/ to open the .xz file )
https://mirror.csclub.uwaterloo.ca/vlc/vlc/3.0.11/vlc-3.0.11.tar.xz
Reading source is fun... especially if there are comments about
why a developer did something a particular way. I'm sure the code
for the music shuffler is perfectly unreadable :-) You know,
attempts to satisfy human brains and all.
The tarball has around 4000 files. Do a text search looking
for the word "shuffle" in the code. Thread.c is an example
of a "hit" on that keyword.
******* from thread.c , open the file with Wordpad... *******
void ResetCurrentlyPlaying( playlist_t *p_playlist,
playlist_item_t *p_cur )
{
playlist_private_t *p_sys = pl_priv(p_playlist);
PL_DEBUG( "rebuilding array of current - root %s",
PLI_NAME( p_sys->status.p_node ) );
ARRAY_RESET( p_playlist->current );
p_playlist->i_current_index = -1;
for( playlist_item_t *p_next = NULL; ; )
{
/** FIXME: this is *slow* */
p_next = playlist_GetNextLeaf( p_playlist,
p_sys->status.p_node,
p_next, true, false );
if( !p_next )
break;
if( p_next == p_cur )
p_playlist->i_current_index = p_playlist->current.i_size;
ARRAY_APPEND( p_playlist->current, p_next);
}
PL_DEBUG("rebuild done - %i items, index %i", p_playlist->current.i_size,
p_playlist->i_current_index);
if( var_GetBool( p_playlist, "random" ) && ( p_playlist->current.i_size > 0 ) )
{
/* Shuffle the array */
for( unsigned j = p_playlist->current.i_size - 1; j > 0; j-- )
{
unsigned i = vlc_lrand48() % (j+1); /* between 0 and j */
playlist_item_t *p_tmp;
/* swap the two items */
p_tmp = ARRAY_VAL(p_playlist->current, i);
ARRAY_VAL(p_playlist->current,i) = ARRAY_VAL(p_playlist->current,j);
ARRAY_VAL(p_playlist->current,j) = p_tmp;
}
}
p_sys->b_reset_currently_playing = false;
}
******* from thread.c , open the file with Wordpad... *******
OK, so what we might suspect is:
1) List is rebuilt. I don't understand this code, except to say
that "the starting materials will be the same each time" in the
upper stanza of code. This is probably some sort of linked list
implementation. Some of the linked-list management is done with
macros (the things in all-caps).
2) The lower routine /* Shuffle the array */ is a pretty standard
shuffling method. It uses random swaps from a declining pool of
items.
But what's missing ? How is vlc_lrand48() seeded ?
The seed code doesn't have to be in the same module.
In fact, a typical location might be in the main()
initialization stuff.
Could it be, that the same sequence of random numbers is
generated each time ? Why, yes, that could happen. So now
we have to discover how the lrand48 gets initialized.
Now, open rand.c with Wordpad. The word "seed" isn't even in the code!!!
I think I just saw Jesus start to cry... :-/
The normal way to do this, is to take the TimeOfDay from
the machine, like the current time in nanoseconds and
use that to seed the generator. Since the time monotonically
increases (it's time in the Epoch), the seed won't normally
be the same (without a lot of effort to break it).
The time of day is not a sufficiently random stimulus for
"high quality" random numbers, like say for a crypto algorithm
which must remain secure. An opponent could see what you're
doing to generate a salt and decode every encrypted message
you send. But for the purposes of playing some music, it's
perfectly adequate for the purpose.
OK, patch the code, compile, play tunes... Or something.
*******
If the playlist is a text file, nothing prevents you from
using an *external* randomizer to repair what VLC
might not be doing right.
beatles.mp3 ===> beegees.mp3
beegees.mp3 External randomizer chilipeppers.mp3
chilipeppers.mp3 for text lists beatles.mp3
I don't know what a playlist looks like, but that's just
to illustrate the concept. In fact, you could write your
own (as a form of punishment :-) ).
Paul