Rockbox.org home
release
dev builds
extras
themes manual
wiki
device status forums
mailing lists
IRC bugs
patches
dev guide



Rockbox mail archive

Subject: [PATCH] playlist and id3 fixes

[PATCH] playlist and id3 fixes

From: Hardeep Sidhu <hardeeps_at_pobox.com>
Date: Sat, 20 Jul 2002 12:47:45 -0700

Minor fixes in playlist and id3 code.

playlist:
- The shuffle algorithm wasn't quite correct

id3:
- If the audio version, layer, or bitrate are invalid then continue parsing
the file instead of exiting. I have a valid mp3 file which contains junk
before the first frame that is incorrectly being recognized as a frame
header (even the "garbage" check passes). I noticed that XMMS (an open
source mp3 app on linux) gives up if the first frame header can't be found
in the first 256K so that might be an option.

- The tpf calculation was wrong for mp3's with version>1 resulting in
invalid times being displayed

-Hardeep

--- orig/apps/playlist.c Wed Jul 17 21:20:01 2002
+++ apps/playlist.c Thu Jul 18 10:39:34 2002
_at__at_ -210,7 +210,7 _at__at_
  */
 void randomise_playlist( playlist_info_t *playlist, unsigned int seed )
 {
- int count = 0;
+ int count = playlist->amount-1;
     int candidate;
     int store;

_at__at_ -219,10 +219,10 _at__at_

     /* randomise entire indices list */

- while( count < playlist->amount )
+ while( count > 0 )
     {
         /* the rand is from 0 to RAND_MAX, so adjust to our value range */
- candidate = rand() % playlist->amount;
+ candidate = rand() % (count+1);

         /* now swap the values at the 'count' and 'candidate' positions */
         store = playlist->indices[candidate];
_at__at_ -230,7 +230,7 _at__at_
         playlist->indices[count] = store;

         /* move along */
- count++;
+ count--;
     }
 }

--- orig/firmware/id3.c Thu Jul 18 08:46:49 2002
+++ firmware/id3.c Thu Jul 18 21:58:14 2002
_at__at_ -444,7 +444,7 _at__at_
         version = 1;
         break;
     default:
- return -1;
+ goto restart;
     }

     /* Layer */
_at__at_ -459,14 +459,14 _at__at_
         layer = 1;
         break;
     default:
- return -1;
+ goto restart;
     }

     /* Bitrate */
     bitindex = (header & 0xF000) >> 12;
     bitrate = bitrate_table[version-1][layer-1][bitindex];
     if(bitrate == 0)
- return -1;
+ goto restart;

     /* Sampling frequency */
     freqindex = (header & 0x0C00) >> 10;
_at__at_ -500,7 +500,7 _at__at_
     }

     /* Calculate time per frame */
- tpf = bs[layer] / freqtab[version-1][freqindex] << (version - 1);
+ tpf = bs[layer] / (freqtab[version-1][freqindex] << (version - 1));

     /* OK, we have found a frame. Let's see if it has a Xing header */
     if(read(fd, frame, sizeof frame) < 0)
Received on 2002-07-20

Page template was last modified "Tue Sep 7 00:00:02 2021" The Rockbox Crew -- Privacy Policy