[vorbis-dev] fixing shuffle in ogg123
Guillaume Cottenceau
gc at mandrakesoft.com
Mon Dec 11 03:33:12 PST 2000
Hi,
There is a bug in the shuffle of ogg123 which was here at least until the
CVS version of 3 days ago. Here's our fix: (it seems to be not perfectly
equiprobable but at least fixes the old one which sometimes gives two
times the same song and never the other song)
-=-=--
--- vorbis-tools-1.0beta3/ogg123/ogg123.c.pix Sat Nov 4 01:23:21 2000
+++ vorbis-tools-1.0beta3/ogg123/ogg123.c Thu Dec 7 13:13:36 2000
@@ -324,12 +324,20 @@
if (param.shuffle)
{
- int i=optind, j=0;
- for (i = optind; i < argc; i++)
+ int i;
+ int nb = argc - optind;
+ int *p = alloca(sizeof(int) * nb);
+ for (i = 0; i < nb; i++) p[i] = i;
+
+ srand (time (NULL));
+ for (i = 1; i < nb; i++)
{
- srand (time (NULL));
- j = (int) ((float) (argc - optind) * rand () / (RAND_MAX + 1.0));
- param.read_file = argv[j+optind];
+ int j = i * ((float) rand() / RAND_MAX);
+ int temp = p[j]; p[j] = p[i]; p[i] = temp;
+ }
+ for (i = 0; i < nb; i++)
+ {
+ param.read_file = argv[p[i]+optind];
play_file ();
}
}
-=-=--
--
Guillaume Cottenceau - http://us.mandrakesoft.com/~gc/
--- >8 ----
List archives: http://www.xiph.org/archives/
Ogg project homepage: http://www.xiph.org/ogg/
To unsubscribe from this list, send a message to 'vorbis-dev-request at xiph.org'
containing only the word 'unsubscribe' in the body. No subject is needed.
Unsubscribe messages sent to the list will be ignored/filtered.
More information about the Vorbis-dev
mailing list