Lines Matching refs:afm
371 static int AudioFileManager_DoConnect (AudioFileManager *afm)
373 if (!afm->mIsEngaged)
377 /*afm->mReadFilePosition = 0;*/
378 afm->mFinishedReadingData = 0;
380 afm->mNumTimesAskedSinceFinished = 0;
381 afm->mLockUnsuccessful = 0;
385 if ((afm->mFileLength - afm->mReadFilePosition) < afm->mChunkSize)
386 dataChunkSize = afm->mFileLength - afm->mReadFilePosition;
388 dataChunkSize = afm->mChunkSize;
390 result = afm->Read(afm, afm->mFileBuffer, &dataChunkSize);
393 afm->mReadFilePosition += dataChunkSize;
395 afm->mWriteToFirstBuffer = 0;
396 afm->mReadFromFirstBuffer = 1;
400 afm->mIsEngaged = 1;
409 static void AudioFileManager_Disconnect (AudioFileManager *afm)
411 if (afm->mIsEngaged)
413 sReaderThread->RemoveReader (sReaderThread, afm);
414 afm->mIsEngaged = 0;
418 static OSStatus AudioFileManager_Read(AudioFileManager *afm, char *buffer, ByteCount *len)
420 return FSReadFork (afm->mForkRefNum,
422 afm->mReadFilePosition + afm->mAudioDataOffset,
428 static OSStatus AudioFileManager_GetFileData (AudioFileManager *afm, void** inOutData, UInt32 *inOutDataSize)
430 if (afm->mFinishedReadingData)
432 ++afm->mNumTimesAskedSinceFinished;
438 if (afm->mReadFromFirstBuffer == afm->mWriteToFirstBuffer) {
443 afm->mParent->DoNotification (afm->mParent, kAudioFilePlayErr_FilePlayUnderrun);
447 *inOutDataSize = afm->mChunkSize;
448 *inOutData = afm->mReadFromFirstBuffer ? afm->mFileBuffer : (afm->mFileBuffer + afm->mChunkSize);
451 afm->mLockUnsuccessful = !sReaderThread->TryNextRead (sReaderThread, afm);
453 afm->mReadFromFirstBuffer = !afm->mReadFromFirstBuffer;
458 static void AudioFileManager_AfterRender (AudioFileManager *afm)
460 if (afm->mNumTimesAskedSinceFinished > 0)
465 afm->mParent->DoNotification (afm->mParent, kAudioFilePlay_FileIsFinished);
471 if (afm->mLockUnsuccessful)
472 afm->mLockUnsuccessful = !sReaderThread->TryNextRead (sReaderThread, afm);
475 static void AudioFileManager_SetPosition (AudioFileManager *afm, SInt64 pos)
477 if (pos < 0 || pos >= afm->mFileLength) {
479 (unsigned int)pos, (unsigned int)afm->mFileLength);
483 afm->mReadFilePosition = pos;
486 static void AudioFileManager_SetEndOfFile (AudioFileManager *afm, SInt64 pos)
488 if (pos <= 0 || pos > afm->mFileLength) {
490 pos = afm->mFileLength;
493 afm->mFileLength = pos;
496 static const char *AudioFileManager_GetFileBuffer(AudioFileManager *afm)
498 return afm
501 const AudioFilePlayer *AudioFileManager_GetParent(AudioFileManager *afm)
503 return afm->mParent;
506 static int AudioFileManager_GetByteCounter(AudioFileManager *afm)
508 return afm->mByteCounter;
518 AudioFileManager* afm = (AudioFileManager*)inRefCon;
519 return afm->Render(afm, ioData);
522 static OSStatus AudioFileManager_Render (AudioFileManager *afm, AudioBufferList *ioData)
530 if (afm->mBufferOffset >= afm->mBufferSize) {
531 result = afm->GetFileData(afm, &afm->mTmpBuffer, &afm->mBufferSize);
534 afm->mParent->DoNotification(afm->mParent, result);
538 afm->mBufferOffset = 0;
541 if (abuf->mDataByteSize > afm->mBufferSize - afm->mBufferOffset)
542 abuf->mDataByteSize = afm->mBufferSize - afm->mBufferOffset;
543 abuf->mData = (char *)afm->mTmpBuffer + afm->mBufferOffset;
544 afm->mBufferOffset += abuf->mDataByteSize;
546 afm->mByteCounter += abuf->mDataByteSize;
547 afm->AfterRender(afm);
553 void delete_AudioFileManager (AudioFileManager *afm)
555 if (afm != NULL) {
556 if (afm->mFileBuffer) {
557 free(afm->mFileBuffer);
560 SDL_free(afm);
570 AudioFileManager *afm;
579 afm = (AudioFileManager *) SDL_malloc(sizeof (AudioFileManager));
580 if (afm == NULL)
582 SDL_memset(afm, '\0', sizeof (*afm));
584 #define SET_AUDIOFILEMANAGER_METHOD(m) afm->m = AudioFileManager_##m
599 afm->mParent = inParent;
600 afm->mForkRefNum = inForkRefNum;
601 afm->mBufferSize = inChunkSize;
602 afm->mBufferOffset = inChunkSize;
603 afm->mChunkSize = inChunkSize;
604 afm->mFileLength = inFileLength;
605 afm->mFileBuffer = (char*) SDL_malloc(afm->mChunkSize * 2);
606 FSGetForkPosition(afm->mForkRefNum, &afm->mAudioDataOffset);
607 assert (afm->mFileBuffer != NULL);
608 return afm;