comparison src/cdrom/macosx/AudioFilePlayer.h @ 1143:71a2648acc75

Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam requested this effort on the mailing list, apparently because of binary compatibility issues between 10.4 and earlier systems (or gcc4 and earlier compilers?). Works fine with SDL12/test/testcdrom.c, with this command line: ./testcdrom -status -list -play -sleep 5000 -pause -sleep 3000 -resume \ -sleep 5000 -stop -sleep 3000 -play -sleep 3000 -stop \ -sleep 3000 -eject Unix Makefiles work, XCode project still need updating for new filenames.
author Ryan C. Gordon <icculus@icculus.org>
date Thu, 22 Sep 2005 08:48:16 +0000
parents f8d5ddc7aef1
children d910939febfa
comparison
equal deleted inserted replaced
1142:c7376efecdb5 1143:71a2648acc75
35 35
36 #include "SDL_error.h" 36 #include "SDL_error.h"
37 37
38 const char* AudioFilePlayerErrorStr (OSStatus error); 38 const char* AudioFilePlayerErrorStr (OSStatus error);
39 39
40 /*
40 void ThrowResult (OSStatus result, const char *str); 41 void ThrowResult (OSStatus result, const char *str);
41 42
42 #define THROW_RESULT(str) \ 43 #define THROW_RESULT(str) \
43 if (result) { \ 44 if (result) { \
44 ThrowResult (result, str); \ 45 ThrowResult (result, str); \
45 } 46 }
47 */
46 48
47 typedef void (*AudioFilePlayNotifier)(void *inRefCon, 49 typedef void (*AudioFilePlayNotifier)(void *inRefCon,
48 OSStatus inStatus); 50 OSStatus inStatus);
49 51
50 enum { 52 enum {
52 kAudioFilePlay_FileIsFinished = -10001, 54 kAudioFilePlay_FileIsFinished = -10001,
53 kAudioFilePlay_PlayerIsUninitialized = -10002 55 kAudioFilePlay_PlayerIsUninitialized = -10002
54 }; 56 };
55 57
56 58
57 class AudioFileManager; 59 struct S_AudioFileManager;
58 60
59 #pragma mark __________ AudioFilePlayer 61 #pragma mark __________ AudioFilePlayer
60 class AudioFilePlayer 62 typedef struct S_AudioFilePlayer
61 { 63 {
62 public: 64 //public:
63 AudioFilePlayer (const FSRef *inFileRef); 65 int (*SetDestination)(struct S_AudioFilePlayer *afp, AudioUnit *inDestUnit);
64 66 void (*SetNotifier)(struct S_AudioFilePlayer *afp, AudioFilePlayNotifier inNotifier, void *inRefCon);
65 ~AudioFilePlayer(); 67 void (*SetStartFrame)(struct S_AudioFilePlayer *afp, int frame); // seek in the file
68 int (*GetCurrentFrame)(struct S_AudioFilePlayer *afp); // get the current frame position
69 void (*SetStopFrame)(struct S_AudioFilePlayer *afp, int frame); // set limit in the file
70 int (*Connect)(struct S_AudioFilePlayer *afp);
71 void (*Disconnect)(struct S_AudioFilePlayer *afp);
72 void (*DoNotification)(struct S_AudioFilePlayer *afp, OSStatus inError);
73 int (*IsConnected)(struct S_AudioFilePlayer *afp);
74 AudioUnit (*GetDestUnit)(struct S_AudioFilePlayer *afp);
75 void (*Print)(struct S_AudioFilePlayer *afp);
66 76
67 void SetDestination (AudioUnit &inDestUnit); 77 //private:
68
69 void SetNotifier (AudioFilePlayNotifier inNotifier, void *inRefCon)
70 {
71 mNotifier = inNotifier;
72 mRefCon = inRefCon;
73 }
74
75 void SetStartFrame (int frame); // seek in the file
76
77 int GetCurrentFrame (); // get the current frame position
78
79 void SetStopFrame (int frame); // set limit in the file
80
81 void Connect();
82
83 void Disconnect();
84
85 void DoNotification (OSStatus inError) const;
86
87 bool IsConnected () const { return mConnected; }
88
89 AudioUnit GetDestUnit () const { return mPlayUnit; }
90
91 #if DEBUG
92 void Print() const
93 {
94 printf ("Is Connected:%s\n", (IsConnected() ? "true" : "false"));
95 printf ("- - - - - - - - - - - - - - \n");
96 }
97 #endif
98
99 private:
100 AudioUnit mPlayUnit; 78 AudioUnit mPlayUnit;
101 SInt16 mForkRefNum; 79 SInt16 mForkRefNum;
102 80
103 AudioUnitInputCallback mInputCallback; 81 AudioUnitInputCallback mInputCallback;
104 82
105 AudioStreamBasicDescription mFileDescription; 83 AudioStreamBasicDescription mFileDescription;
106 84
107 bool mConnected; 85 int mConnected;
108 86
109 AudioFileManager* mAudioFileManager; 87 struct S_AudioFileManager* mAudioFileManager;
110 88
111 AudioFilePlayNotifier mNotifier; 89 AudioFilePlayNotifier mNotifier;
112 void* mRefCon; 90 void* mRefCon;
113 91
114 int mStartFrame; 92 int mStartFrame;
115 93
116 #pragma mark __________ Private_Methods 94 #pragma mark __________ Private_Methods
117 95
118 void OpenFile (const FSRef *inRef, SInt64& outFileSize); 96 int (*OpenFile)(struct S_AudioFilePlayer *afp, const FSRef *inRef, SInt64 *outFileSize);
119 }; 97 } AudioFilePlayer;
98
99
100 AudioFilePlayer *new_AudioFilePlayer(const FSRef *inFileRef);
101 void delete_AudioFilePlayer(AudioFilePlayer *afp);
102
103
120 104
121 #pragma mark __________ AudioFileManager 105 #pragma mark __________ AudioFileManager
122 class AudioFileManager 106 typedef struct S_AudioFileManager
123 { 107 {
124 public: 108 //public:
125 AudioFileManager (AudioFilePlayer &inParent,
126 SInt16 inForkRefNum,
127 SInt64 inFileLength,
128 UInt32 inChunkSize);
129
130 ~AudioFileManager();
131
132
133 // this method should NOT be called by an object of this class 109 // this method should NOT be called by an object of this class
134 // as it is called by the parent's Disconnect() method 110 // as it is called by the parent's Disconnect() method
135 void Disconnect (); 111 void (*Disconnect)(struct S_AudioFileManager *afm);
136 112 int (*DoConnect)(struct S_AudioFileManager *afm);
137 void DoConnect (); 113 OSStatus (*Read)(struct S_AudioFileManager *afm, char *buffer, UInt32 *len);
138 114 const char* (*GetFileBuffer)(struct S_AudioFileManager *afm);
139 OSStatus Read(char *buffer, UInt32 *len); 115 const AudioFilePlayer *(*GetParent)(struct S_AudioFileManager *afm);
140 116 void (*SetPosition)(struct S_AudioFileManager *afm, SInt64 pos); // seek/rewind in the file
141 const char* GetFileBuffer () { return mFileBuffer; } 117 int (*GetByteCounter)(struct S_AudioFileManager *afm); // return actual bytes streamed to audio hardware
142 118 void (*SetEndOfFile)(struct S_AudioFileManager *afm, SInt64 pos); // set the "EOF" (will behave just like it reached eof)
143 const AudioFilePlayer& GetParent () const { return mParent; }
144
145 void SetPosition (SInt64 pos); // seek/rewind in the file
146
147 int GetByteCounter () { return mByteCounter; } // return actual bytes streamed to audio hardware
148
149 void SetEndOfFile (SInt64 pos); // set the "EOF" (will behave just like it reached eof)
150 119
151 protected: 120 //protected:
152 AudioFilePlayer& mParent; 121 AudioFilePlayer* mParent;
153 SInt16 mForkRefNum; 122 SInt16 mForkRefNum;
154 SInt64 mAudioDataOffset; 123 SInt64 mAudioDataOffset;
155 124
156 char* mFileBuffer; 125 char* mFileBuffer;
157 126
158 int mByteCounter; 127 int mByteCounter;
159 128
160 bool mReadFromFirstBuffer; 129 int mReadFromFirstBuffer;
161 bool mLockUnsuccessful; 130 int mLockUnsuccessful;
162 bool mIsEngaged; 131 int mIsEngaged;
163 132
164 int mNumTimesAskedSinceFinished; 133 int mNumTimesAskedSinceFinished;
165 134
166 135
167 void* mTmpBuffer; 136 void* mTmpBuffer;
168 UInt32 mBufferSize; 137 UInt32 mBufferSize;
169 UInt32 mBufferOffset; 138 UInt32 mBufferOffset;
170 public: 139 //public:
171 const UInt32 mChunkSize; 140 UInt32 mChunkSize;
172 SInt64 mFileLength; 141 SInt64 mFileLength;
173 SInt64 mReadFilePosition; 142 SInt64 mReadFilePosition;
174 bool mWriteToFirstBuffer; 143 int mWriteToFirstBuffer;
175 bool mFinishedReadingData; 144 int mFinishedReadingData;
176 145
177 protected: 146 //protected:
178 OSStatus Render (AudioBuffer &ioData); 147 OSStatus (*Render)(struct S_AudioFileManager *afm, AudioBuffer *ioData);
179 148 OSStatus (*GetFileData)(struct S_AudioFileManager *afm, void** inOutData, UInt32 *inOutDataSize);
180 OSStatus GetFileData (void** inOutData, UInt32 *inOutDataSize); 149 void (*AfterRender)(struct S_AudioFileManager *afm);
181
182 void AfterRender ();
183 150
184 public: 151 //public:
185 static OSStatus FileInputProc (void *inRefCon, 152 //static
186 AudioUnitRenderActionFlags inActionFlags, 153 OSStatus (*FileInputProc)(void *inRefCon,
187 const AudioTimeStamp *inTimeStamp, 154 AudioUnitRenderActionFlags inActionFlags,
188 UInt32 inBusNumber, 155 const AudioTimeStamp *inTimeStamp,
189 AudioBuffer *ioData); 156 UInt32 inBusNumber,
190 }; 157 AudioBuffer *ioData);
158 } AudioFileManager;
191 159
192 160
161 AudioFileManager *new_AudioFileManager (AudioFilePlayer *inParent,
162 SInt16 inForkRefNum,
163 SInt64 inFileLength,
164 UInt32 inChunkSize);
165
166 void delete_AudioFileManager(AudioFileManager *afm);
167
193 #endif 168 #endif
169