comparison src/cdrom/macosx/AudioFileReaderThread.cpp @ 773:da0a2ad35bf4

Date: Sun, 4 Jan 2004 23:48:19 +0100 From: Max Horn Subject: Re: Again Audio CD patch Am 04.01.2004 um 22:38 schrieb Sam Lantinga: > > Okay, I fixed the buffering problems by simply using a 4 second buffer > instead of a 1 second buffer. However, using your code I can't play an > entire CD - the playback stops after the first song. > Found the problem: FSReadFork returns eofErr when the file is finished. However, we check its return value for errors, and if anything but noErr occurs, the reader thread aborts its current iteration. That is bad, because it aborts before it can ever set the flag which tells that the file is over (also, any remaining data which FSRead did return is lost - so you'd not hear about to 4 seconds from the end of the file. Furthermore, the computed data size was 8 bytes to high (I forgot to account for the fact that the size of an (A)IFF chunk always contains the chunk header & size fields, too). This is enough to make it work. However, the end condition is rather fragile, so I tuned some other things to be pessimistic (check for <= 0 instead of == 0, when eofErr is encountered enforce mReadFilePosition == mFileLength). You never know... The attached patch fixes the issue for me.
author Sam Lantinga <slouken@libsdl.org>
date Mon, 05 Jan 2004 00:57:51 +0000
parents de1b2c3063b9
children 08b7fc2b5225
comparison
equal deleted inserted replaced
772:5c5656163ebd 773:da0a2ad35bf4
239 dataChunkSize = theItem->mFileLength - theItem->mReadFilePosition; 239 dataChunkSize = theItem->mFileLength - theItem->mReadFilePosition;
240 else 240 else
241 dataChunkSize = theItem->mChunkSize; 241 dataChunkSize = theItem->mChunkSize;
242 242
243 // this is the exit condition for the thread 243 // this is the exit condition for the thread
244 if (dataChunkSize == 0) { 244 if (dataChunkSize <= 0) {
245 theItem->mFinishedReadingData = true; 245 theItem->mFinishedReadingData = true;
246 continue; 246 continue;
247 } 247 }
248 // construct pointer 248 // construct pointer
249 char* writePtr = const_cast<char*>(theItem->GetFileBuffer() + 249 char* writePtr = const_cast<char*>(theItem->GetFileBuffer() +
250 (theItem->mWriteToFirstBuffer ? 0 : theItem->mChunkSize)); 250 (theItem->mWriteToFirstBuffer ? 0 : theItem->mChunkSize));
251 251
252 /* 252 // read data
253 printf ("AudioFileReadBytes: theItem=%.8X fileID=%.8X pos=%.8X sz=%.8X flen=%.8X ptr=%.8X\n",
254 (unsigned int)theItem, (unsigned int)theItem->GetFileID(),
255 (unsigned int)theItem->mReadFilePosition, (unsigned int)dataChunkSize,
256 (unsigned int)theItem->mFileLength, (unsigned int)writePtr);
257 */
258 result = theItem->Read(writePtr, &dataChunkSize); 253 result = theItem->Read(writePtr, &dataChunkSize);
259 if (result) { 254 if (result != noErr && result != eofErr) {
260 theItem->GetParent().DoNotification(result); 255 theItem->GetParent().DoNotification(result);
261 continue; 256 continue;
262 } 257 }
263 258
264 if (dataChunkSize != theItem->mChunkSize) 259 if (dataChunkSize != theItem->mChunkSize)
269 memset (writePtr, 0, (theItem->mChunkSize - dataChunkSize)); 264 memset (writePtr, 0, (theItem->mChunkSize - dataChunkSize));
270 } 265 }
271 266
272 theItem->mWriteToFirstBuffer = !theItem->mWriteToFirstBuffer; // switch buffers 267 theItem->mWriteToFirstBuffer = !theItem->mWriteToFirstBuffer; // switch buffers
273 268
274 theItem->mReadFilePosition += dataChunkSize; // increment count 269 if (result == eofErr)
270 theItem->mReadFilePosition = theItem->mFileLength;
271 else
272 theItem->mReadFilePosition += dataChunkSize; // increment count
275 } 273 }
276 } 274 }
277 275
278 276
279 static FileReaderThread sReaderThread; 277 static FileReaderThread sReaderThread;