[mythtv] MythMusic playlists still not intelligent enough IMHO
David Härdeman
david at hardeman.nu
Thu Apr 19 21:03:41 UTC 2007
On Thu, Apr 19, 2007 at 04:12:36PM +0200, Lasse Nisted wrote:
>> > Hmm, what would be the interpretation of that bitmap?
>>
>> char * bitmap = NULL;
>> int pickasong() {
>> static int played = num_songs;
>> int index = rand() % num_songs;
>>
>> if (!bitmap)
>> bitmap = malloc((num_songs + 7)/8);
>>
>> played++;
>> if (played >= num_songs) {
>> memset(bitmap, 0, (num_songs + 7)/8);
>> played = 0;
>> }
>>
>> while(bitmap[index/8] & (1 << (index % 8))) {
>> index++;
>> if (index >= num_songs)
>> index = 0;
>> }
>>
>> bitmap[index/8] &= (1 << (index % 8));
>> return index;
>> }
>>
>> Worst case scenario is num_songs bit comparisons before a song is found
>> (which could be reduced with more code to a worst case of num_songs / 8
>> byte comparisons and 8 bit comparisons).
>>
>> --
>> David Härdeman
>
>Interesting! :) It seems correct, though I'm not sure the selection
>will be uniform, but maybe it is... I can't think right now :)
Not quite uniform, if a number of adjacent songs are played, odds go up
that the song to the right of them will be selected. Fixing that would
be a simple tweak to the above code though.
--
David Härdeman
More information about the mythtv-dev
mailing list