AudioFilePlayer * new_AudioFilePlayer(const FSRef * inFileRef) { SInt64 fileDataSize = 0; AudioFilePlayer *afp = (AudioFilePlayer *) SDL_malloc(sizeof(AudioFilePlayer)); if (afp == NULL) return NULL; SDL_memset(afp, '\0', sizeof(*afp)); #define SET_AUDIOFILEPLAYER_METHOD(m) afp->m = AudioFilePlayer_##m SET_AUDIOFILEPLAYER_METHOD(SetDestination); SET_AUDIOFILEPLAYER_METHOD(SetNotifier); SET_AUDIOFILEPLAYER_METHOD(SetStartFrame); SET_AUDIOFILEPLAYER_METHOD(GetCurrentFrame); SET_AUDIOFILEPLAYER_METHOD(SetStopFrame); SET_AUDIOFILEPLAYER_METHOD(Connect); SET_AUDIOFILEPLAYER_METHOD(Disconnect); SET_AUDIOFILEPLAYER_METHOD(DoNotification); SET_AUDIOFILEPLAYER_METHOD(IsConnected); SET_AUDIOFILEPLAYER_METHOD(GetDestUnit); SET_AUDIOFILEPLAYER_METHOD(Print); SET_AUDIOFILEPLAYER_METHOD(OpenFile); #undef SET_AUDIOFILEPLAYER_METHOD if (!afp->OpenFile(afp, inFileRef, &fileDataSize)) { SDL_free(afp); return NULL; } /* we want about 4 seconds worth of data for the buffer */ int bytesPerSecond = (UInt32) (4 * afp->mFileDescription.mSampleRate * afp->mFileDescription.mBytesPerFrame); #if DEBUG printf("File format:\n"); PrintStreamDesc(&afp->mFileDescription); #endif afp->mAudioFileManager = new_AudioFileManager(afp, afp->mForkRefNum, fileDataSize, bytesPerSecond); if (afp->mAudioFileManager == NULL) { delete_AudioFilePlayer(afp); return NULL; } return afp; }
int ReleaseFile () { int error = -1; if (thePlayer != NULL) { thePlayer->Disconnect(thePlayer); delete_AudioFilePlayer(thePlayer); thePlayer = NULL; } error = 0; return error; }