[Flac-dev] better seeking

Miroslav Lichvar lichvarm at phoenix.inf.upol.cz
Thu Jul 10 10:48:31 PDT 2003


And here is another one. It allows fast seeking in streams without
total_samples information.

There is a check for such streams in flac, so flac --skip doesn't
work. If the check is removed, it will work with --force-raw-format
only, there is an issue with wav and aiff header handling.

-- 
Miroslav Lichvar
-------------- next part --------------
--- src/libFLAC/seekable_stream_decoder.c.orig1	2003-07-09 23:49:35.000000000 +0200
+++ src/libFLAC/seekable_stream_decoder.c	2003-07-10 14:52:05.000000000 +0200
@@ -826,8 +826,8 @@
 	const unsigned min_blocksize = decoder->private_->stream_info.min_blocksize;
 	const unsigned max_blocksize = decoder->private_->stream_info.max_blocksize;
 	const unsigned max_framesize = decoder->private_->stream_info.max_framesize;
-	const unsigned channels = FLAC__seekable_stream_decoder_get_channels(decoder);
-	const unsigned bps = FLAC__seekable_stream_decoder_get_bits_per_sample(decoder);
+	const unsigned channels = decoder->private_->stream_info.channels;
+	const unsigned bps = decoder->private_->stream_info.bits_per_sample;
 
 	/* we are just guessing here, but we want to guess high, not low */
 	if(max_framesize > 0) {
@@ -869,7 +869,7 @@
 		upper_bound = stream_length - (max_framesize + 128 + 2); /* 128 for a possible ID3V1 tag, 2 for indexing differences */
 	else
 		upper_bound = stream_length - ((channels * bps * FLAC__MAX_BLOCK_SIZE) / 8 + 128 + 2);
-	upper_bound_sample = total_samples;
+	upper_bound_sample = total_samples > 0 ? total_samples : target_sample;
 
 	/*
 	 * Now we refine the bounds if we have a seektable with
@@ -900,7 +900,7 @@
 
 	decoder->private_->target_sample = target_sample;
 
-	needs_seek = (total_samples > 0) ? true : false;
+	needs_seek = true;
 	while(1) {
 		if(needs_seek) {
 #if defined _MSC_VER || defined __MINGW32__


More information about the Flac-dev mailing list