Rockbox mail archive
Subject: [PATCH] playlist and id3 fixes
From: Hardeep Sidhu (hardeeps_at_pobox.com)
Date: 2002-07-20
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
@@ -210,7 +210,7 @@
*/
void randomise_playlist( playlist_info_t *playlist, unsigned int seed )
{
- int count = 0;
+ int count = playlist->amount-1;
int candidate;
int store;
@@ -219,10 +219,10 @@
/* 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];
@@ -230,7 +230,7 @@
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
@@ -444,7 +444,7 @@
version = 1;
break;
default:
- return -1;
+ goto restart;
}
/* Layer */
@@ -459,14 +459,14 @@
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;
@@ -500,7 +500,7 @@
}
/* 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)
Page was last modified "Jan 10 2012" The Rockbox Crew
|