2 SDL - Simple DirectMedia Layer
3 Copyright (C) 1997-2009 Sam Lantinga
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
15 You should have received a copy of the GNU Library General Public
16 License along with this library; if not, write to the Free
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 This file based on Apple sample code. We haven't changed the file name,
23 so if you want to see the original search for it on apple.com/developer
25 #include "SDL_config.h"
27 /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
30 #ifndef __AudioFilePlayer_H__
31 #define __AudioFilePlayer_H__
33 #include <CoreServices/CoreServices.h>
35 #include <AudioUnit/AudioUnit.h>
36 #if MAC_OS_X_VERSION_MAX_ALLOWED <= 1050
37 #include <AudioUnit/AUNTComponent.h>
40 #if __MAC_OS_X_VERSION_MIN_REQUIRED < 1050
41 typedef SInt16 FSIORefNum;
44 #include "SDL_error.h"
46 const char* AudioFilePlayerErrorStr (OSStatus error);
49 void ThrowResult (OSStatus result, const char *str);
51 #define THROW_RESULT(str) \
53 ThrowResult (result, str); \
57 typedef void (*AudioFilePlayNotifier)(void *inRefCon,
61 kAudioFilePlayErr_FilePlayUnderrun = -10000,
62 kAudioFilePlay_FileIsFinished = -10001,
63 kAudioFilePlay_PlayerIsUninitialized = -10002
67 struct S_AudioFileManager;
69 #pragma mark __________ AudioFilePlayer
70 typedef struct S_AudioFilePlayer
73 int (*SetDestination)(struct S_AudioFilePlayer *afp, AudioUnit *inDestUnit);
74 void (*SetNotifier)(struct S_AudioFilePlayer *afp, AudioFilePlayNotifier inNotifier, void *inRefCon);
75 void (*SetStartFrame)(struct S_AudioFilePlayer *afp, int frame); /* seek in the file */
76 int (*GetCurrentFrame)(struct S_AudioFilePlayer *afp); /* get the current frame position */
77 void (*SetStopFrame)(struct S_AudioFilePlayer *afp, int frame); /* set limit in the file */
78 int (*Connect)(struct S_AudioFilePlayer *afp);
79 void (*Disconnect)(struct S_AudioFilePlayer *afp);
80 void (*DoNotification)(struct S_AudioFilePlayer *afp, OSStatus inError);
81 int (*IsConnected)(struct S_AudioFilePlayer *afp);
82 AudioUnit (*GetDestUnit)(struct S_AudioFilePlayer *afp);
83 void (*Print)(struct S_AudioFilePlayer *afp);
87 FSIORefNum mForkRefNum;
89 AURenderCallbackStruct mInputCallback;
91 AudioStreamBasicDescription mFileDescription;
95 struct S_AudioFileManager* mAudioFileManager;
97 AudioFilePlayNotifier mNotifier;
102 #pragma mark __________ Private_Methods
104 int (*OpenFile)(struct S_AudioFilePlayer *afp, const FSRef *inRef, SInt64 *outFileSize);
108 AudioFilePlayer *new_AudioFilePlayer(const FSRef *inFileRef);
109 void delete_AudioFilePlayer(AudioFilePlayer *afp);
113 #pragma mark __________ AudioFileManager
114 typedef struct S_AudioFileManager
117 /* this method should NOT be called by an object of this class
118 as it is called by the parent's Disconnect() method */
119 void (*Disconnect)(struct S_AudioFileManager *afm);
120 int (*DoConnect)(struct S_AudioFileManager *afm);
121 OSStatus (*Read)(struct S_AudioFileManager *afm, char *buffer, ByteCount *len);
122 const char* (*GetFileBuffer)(struct S_AudioFileManager *afm);
123 const AudioFilePlayer *(*GetParent)(struct S_AudioFileManager *afm);
124 void (*SetPosition)(struct S_AudioFileManager *afm, SInt64 pos); /* seek/rewind in the file */
125 int (*GetByteCounter)(struct S_AudioFileManager *afm); /* return actual bytes streamed to audio hardware */
126 void (*SetEndOfFile)(struct S_AudioFileManager *afm, SInt64 pos); /* set the "EOF" (will behave just like it reached eof) */
129 AudioFilePlayer* mParent;
131 SInt64 mAudioDataOffset;
137 int mReadFromFirstBuffer;
138 int mLockUnsuccessful;
141 int mNumTimesAskedSinceFinished;
146 UInt32 mBufferOffset;
150 SInt64 mReadFilePosition;
151 int mWriteToFirstBuffer;
152 int mFinishedReadingData;
155 OSStatus (*Render)(struct S_AudioFileManager *afm, AudioBufferList *ioData);
156 OSStatus (*GetFileData)(struct S_AudioFileManager *afm, void** inOutData, UInt32 *inOutDataSize);
157 void (*AfterRender)(struct S_AudioFileManager *afm);
161 OSStatus (*FileInputProc)(void *inRefCon,
162 AudioUnitRenderActionFlags *ioActionFlags,
163 const AudioTimeStamp *inTimeStamp,
165 UInt32 inNumberFrames,
166 AudioBufferList *ioData);
170 AudioFileManager *new_AudioFileManager (AudioFilePlayer *inParent,
175 void delete_AudioFileManager(AudioFileManager *afm);