comparison src/cdrom/macosx/AudioFilePlayer.c @ 1895:c121d94672cb

SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
author Sam Lantinga <slouken@libsdl.org>
date Mon, 10 Jul 2006 21:04:37 +0000
parents 4d66375c2012
children e27bdcc80744
comparison
equal deleted inserted replaced
1894:c69cee13dd76 1895:c121d94672cb
36 throw result; 36 throw result;
37 } 37 }
38 */ 38 */
39 39
40 #if DEBUG 40 #if DEBUG
41 static void PrintStreamDesc (AudioStreamBasicDescription *inDesc) 41 static void
42 PrintStreamDesc(AudioStreamBasicDescription * inDesc)
42 { 43 {
43 if (!inDesc) { 44 if (!inDesc) {
44 printf ("Can't print a NULL desc!\n"); 45 printf("Can't print a NULL desc!\n");
45 return; 46 return;
46 } 47 }
47 48
48 printf ("- - - - - - - - - - - - - - - - - - - -\n"); 49 printf("- - - - - - - - - - - - - - - - - - - -\n");
49 printf (" Sample Rate:%f\n", inDesc->mSampleRate); 50 printf(" Sample Rate:%f\n", inDesc->mSampleRate);
50 printf (" Format ID:%s\n", (char*)&inDesc->mFormatID); 51 printf(" Format ID:%s\n", (char *) &inDesc->mFormatID);
51 printf (" Format Flags:%lX\n", inDesc->mFormatFlags); 52 printf(" Format Flags:%lX\n", inDesc->mFormatFlags);
52 printf (" Bytes per Packet:%ld\n", inDesc->mBytesPerPacket); 53 printf(" Bytes per Packet:%ld\n", inDesc->mBytesPerPacket);
53 printf (" Frames per Packet:%ld\n", inDesc->mFramesPerPacket); 54 printf(" Frames per Packet:%ld\n", inDesc->mFramesPerPacket);
54 printf (" Bytes per Frame:%ld\n", inDesc->mBytesPerFrame); 55 printf(" Bytes per Frame:%ld\n", inDesc->mBytesPerFrame);
55 printf (" Channels per Frame:%ld\n", inDesc->mChannelsPerFrame); 56 printf(" Channels per Frame:%ld\n", inDesc->mChannelsPerFrame);
56 printf (" Bits per Channel:%ld\n", inDesc->mBitsPerChannel); 57 printf(" Bits per Channel:%ld\n", inDesc->mBitsPerChannel);
57 printf ("- - - - - - - - - - - - - - - - - - - -\n"); 58 printf("- - - - - - - - - - - - - - - - - - - -\n");
58 } 59 }
59 #endif 60 #endif
60 61
61 62
62 static int AudioFilePlayer_SetDestination (AudioFilePlayer *afp, AudioUnit *inDestUnit) 63 static int
63 { 64 AudioFilePlayer_SetDestination(AudioFilePlayer * afp, AudioUnit * inDestUnit)
64 /*if (afp->mConnected) throw static_cast<OSStatus>(-1);*/ /* can't set dest if already engaged */ 65 {
66 /*if (afp->mConnected) throw static_cast<OSStatus>(-1); *//* can't set dest if already engaged */
65 if (afp->mConnected) 67 if (afp->mConnected)
66 return 0 ; 68 return 0;
67 69
68 SDL_memcpy(&afp->mPlayUnit, inDestUnit, sizeof (afp->mPlayUnit)); 70 SDL_memcpy(&afp->mPlayUnit, inDestUnit, sizeof(afp->mPlayUnit));
69 71
70 OSStatus result = noErr; 72 OSStatus result = noErr;
71 73
72 74
73 /* we can "down" cast a component instance to a component */ 75 /* we can "down" cast a component instance to a component */
74 ComponentDescription desc; 76 ComponentDescription desc;
75 result = GetComponentInfo ((Component)*inDestUnit, &desc, 0, 0, 0); 77 result = GetComponentInfo((Component) * inDestUnit, &desc, 0, 0, 0);
76 if (result) return 0; /*THROW_RESULT("GetComponentInfo")*/ 78 if (result)
77 79 return 0; /*THROW_RESULT("GetComponentInfo") */
78 /* we're going to use this to know which convert routine to call 80
79 a v1 audio unit will have a type of 'aunt' 81 /* we're going to use this to know which convert routine to call
80 a v2 audio unit will have one of several different types. */ 82 a v1 audio unit will have a type of 'aunt'
83 a v2 audio unit will have one of several different types. */
81 if (desc.componentType != kAudioUnitComponentType) { 84 if (desc.componentType != kAudioUnitComponentType) {
82 result = badComponentInstance; 85 result = badComponentInstance;
83 /*THROW_RESULT("BAD COMPONENT")*/ 86 /*THROW_RESULT("BAD COMPONENT") */
84 if (result) return 0; 87 if (result)
88 return 0;
85 } 89 }
86 90
87 /* Set the input format of the audio unit. */ 91 /* Set the input format of the audio unit. */
88 result = AudioUnitSetProperty (*inDestUnit, 92 result = AudioUnitSetProperty(*inDestUnit,
89 kAudioUnitProperty_StreamFormat, 93 kAudioUnitProperty_StreamFormat,
90 kAudioUnitScope_Input, 94 kAudioUnitScope_Input,
91 0, 95 0,
92 &afp->mFileDescription, 96 &afp->mFileDescription,
93 sizeof (afp->mFileDescription)); 97 sizeof(afp->mFileDescription));
94 /*THROW_RESULT("AudioUnitSetProperty")*/ 98 /*THROW_RESULT("AudioUnitSetProperty") */
95 if (result) return 0; 99 if (result)
100 return 0;
96 return 1; 101 return 1;
97 } 102 }
98 103
99 static void AudioFilePlayer_SetNotifier(AudioFilePlayer *afp, AudioFilePlayNotifier inNotifier, void *inRefCon) 104 static void
105 AudioFilePlayer_SetNotifier(AudioFilePlayer * afp,
106 AudioFilePlayNotifier inNotifier, void *inRefCon)
100 { 107 {
101 afp->mNotifier = inNotifier; 108 afp->mNotifier = inNotifier;
102 afp->mRefCon = inRefCon; 109 afp->mRefCon = inRefCon;
103 } 110 }
104 111
105 static int AudioFilePlayer_IsConnected(AudioFilePlayer *afp) 112 static int
113 AudioFilePlayer_IsConnected(AudioFilePlayer * afp)
106 { 114 {
107 return afp->mConnected; 115 return afp->mConnected;
108 } 116 }
109 117
110 static AudioUnit AudioFilePlayer_GetDestUnit(AudioFilePlayer *afp) 118 static AudioUnit
111 { 119 AudioFilePlayer_GetDestUnit(AudioFilePlayer * afp)
112 return afp->mPlayUnit; 120 {
113 } 121 return afp->mPlayUnit;
114 122 }
115 static void AudioFilePlayer_Print(AudioFilePlayer *afp) 123
116 { 124 static void
117 #if DEBUG 125 AudioFilePlayer_Print(AudioFilePlayer * afp)
118 printf ("Is Connected:%s\n", (IsConnected() ? "true" : "false")); 126 {
119 printf ("- - - - - - - - - - - - - - \n"); 127 #if DEBUG
120 #endif 128 printf("Is Connected:%s\n", (IsConnected()? "true" : "false"));
121 } 129 printf("- - - - - - - - - - - - - - \n");
122 130 #endif
123 static void AudioFilePlayer_SetStartFrame (AudioFilePlayer *afp, int frame) 131 }
132
133 static void
134 AudioFilePlayer_SetStartFrame(AudioFilePlayer * afp, int frame)
124 { 135 {
125 SInt64 position = frame * 2352; 136 SInt64 position = frame * 2352;
126 137
127 afp->mStartFrame = frame; 138 afp->mStartFrame = frame;
128 afp->mAudioFileManager->SetPosition (afp->mAudioFileManager, position); 139 afp->mAudioFileManager->SetPosition(afp->mAudioFileManager, position);
129 } 140 }
130 141
131 142
132 static int AudioFilePlayer_GetCurrentFrame (AudioFilePlayer *afp) 143 static int
133 { 144 AudioFilePlayer_GetCurrentFrame(AudioFilePlayer * afp)
134 return afp->mStartFrame + (afp->mAudioFileManager->GetByteCounter(afp->mAudioFileManager) / 2352); 145 {
135 } 146 return afp->mStartFrame +
136 147 (afp->mAudioFileManager->GetByteCounter(afp->mAudioFileManager) /
137 static void AudioFilePlayer_SetStopFrame (AudioFilePlayer *afp, int frame) 148 2352);
138 { 149 }
139 SInt64 position = frame * 2352; 150
140 151 static void
141 afp->mAudioFileManager->SetEndOfFile (afp->mAudioFileManager, position); 152 AudioFilePlayer_SetStopFrame(AudioFilePlayer * afp, int frame)
142 } 153 {
143 154 SInt64 position = frame * 2352;
144 void delete_AudioFilePlayer(AudioFilePlayer *afp) 155
145 { 156 afp->mAudioFileManager->SetEndOfFile(afp->mAudioFileManager, position);
146 if (afp != NULL) 157 }
147 { 158
159 void
160 delete_AudioFilePlayer(AudioFilePlayer * afp)
161 {
162 if (afp != NULL) {
148 afp->Disconnect(afp); 163 afp->Disconnect(afp);
149 164
150 if (afp->mAudioFileManager) { 165 if (afp->mAudioFileManager) {
151 delete_AudioFileManager(afp->mAudioFileManager); 166 delete_AudioFileManager(afp->mAudioFileManager);
152 afp->mAudioFileManager = 0; 167 afp->mAudioFileManager = 0;
153 } 168 }
154 169
155 if (afp->mForkRefNum) { 170 if (afp->mForkRefNum) {
156 FSCloseFork (afp->mForkRefNum); 171 FSCloseFork(afp->mForkRefNum);
157 afp->mForkRefNum = 0; 172 afp->mForkRefNum = 0;
158 } 173 }
159 SDL_free(afp); 174 SDL_free(afp);
160 } 175 }
161 } 176 }
162 177
163 static int AudioFilePlayer_Connect(AudioFilePlayer *afp) 178 static int
164 { 179 AudioFilePlayer_Connect(AudioFilePlayer * afp)
165 #if DEBUG 180 {
166 printf ("Connect:%x, engaged=%d\n", (int)afp->mPlayUnit, (afp->mConnected ? 1 : 0)); 181 #if DEBUG
167 #endif 182 printf("Connect:%x, engaged=%d\n", (int) afp->mPlayUnit,
168 if (!afp->mConnected) 183 (afp->mConnected ? 1 : 0));
169 { 184 #endif
185 if (!afp->mConnected) {
170 if (!afp->mAudioFileManager->DoConnect(afp->mAudioFileManager)) 186 if (!afp->mAudioFileManager->DoConnect(afp->mAudioFileManager))
171 return 0; 187 return 0;
172 188
173 /* set the render callback for the file data to be supplied to the sound converter AU */ 189 /* set the render callback for the file data to be supplied to the sound converter AU */
174 afp->mInputCallback.inputProc = afp->mAudioFileManager->FileInputProc; 190 afp->mInputCallback.inputProc = afp->mAudioFileManager->FileInputProc;
175 afp->mInputCallback.inputProcRefCon = afp->mAudioFileManager; 191 afp->mInputCallback.inputProcRefCon = afp->mAudioFileManager;
176 192
177 OSStatus result = AudioUnitSetProperty (afp->mPlayUnit, 193 OSStatus result = AudioUnitSetProperty(afp->mPlayUnit,
178 kAudioUnitProperty_SetInputCallback, 194 kAudioUnitProperty_SetInputCallback,
179 kAudioUnitScope_Input, 195 kAudioUnitScope_Input,
180 0, 196 0,
181 &afp->mInputCallback, 197 &afp->mInputCallback,
182 sizeof(afp->mInputCallback)); 198 sizeof(afp->mInputCallback));
183 if (result) return 0; /*THROW_RESULT("AudioUnitSetProperty")*/ 199 if (result)
200 return 0; /*THROW_RESULT("AudioUnitSetProperty") */
184 afp->mConnected = 1; 201 afp->mConnected = 1;
185 } 202 }
186 203
187 return 1; 204 return 1;
188 } 205 }
189 206
190 /* warning noted, now please go away ;-) */ 207 /* warning noted, now please go away ;-) */
191 /* #warning This should redirect the calling of notification code to some other thread */ 208 /* #warning This should redirect the calling of notification code to some other thread */
192 static void AudioFilePlayer_DoNotification (AudioFilePlayer *afp, OSStatus inStatus) 209 static void
210 AudioFilePlayer_DoNotification(AudioFilePlayer * afp, OSStatus inStatus)
193 { 211 {
194 if (afp->mNotifier) { 212 if (afp->mNotifier) {
195 (*afp->mNotifier) (afp->mRefCon, inStatus); 213 (*afp->mNotifier) (afp->mRefCon, inStatus);
196 } else { 214 } else {
197 SDL_SetError ("Notification posted with no notifier in place"); 215 SDL_SetError("Notification posted with no notifier in place");
198 216
199 if (inStatus == kAudioFilePlay_FileIsFinished) 217 if (inStatus == kAudioFilePlay_FileIsFinished)
200 afp->Disconnect(afp); 218 afp->Disconnect(afp);
201 else if (inStatus != kAudioFilePlayErr_FilePlayUnderrun) 219 else if (inStatus != kAudioFilePlayErr_FilePlayUnderrun)
202 afp->Disconnect(afp); 220 afp->Disconnect(afp);
203 } 221 }
204 } 222 }
205 223
206 static void AudioFilePlayer_Disconnect (AudioFilePlayer *afp) 224 static void
207 { 225 AudioFilePlayer_Disconnect(AudioFilePlayer * afp)
208 #if DEBUG 226 {
209 printf ("Disconnect:%x,%ld, engaged=%d\n", (int)afp->mPlayUnit, 0, (afp->mConnected ? 1 : 0)); 227 #if DEBUG
210 #endif 228 printf("Disconnect:%x,%ld, engaged=%d\n", (int) afp->mPlayUnit, 0,
211 if (afp->mConnected) 229 (afp->mConnected ? 1 : 0));
212 { 230 #endif
231 if (afp->mConnected) {
213 afp->mConnected = 0; 232 afp->mConnected = 0;
214 233
215 afp->mInputCallback.inputProc = 0; 234 afp->mInputCallback.inputProc = 0;
216 afp->mInputCallback.inputProcRefCon = 0; 235 afp->mInputCallback.inputProcRefCon = 0;
217 OSStatus result = AudioUnitSetProperty (afp->mPlayUnit, 236 OSStatus result = AudioUnitSetProperty(afp->mPlayUnit,
218 kAudioUnitProperty_SetInputCallback, 237 kAudioUnitProperty_SetInputCallback,
219 kAudioUnitScope_Input, 238 kAudioUnitScope_Input,
220 0, 239 0,
221 &afp->mInputCallback, 240 &afp->mInputCallback,
222 sizeof(afp->mInputCallback)); 241 sizeof(afp->mInputCallback));
223 if (result) 242 if (result)
224 SDL_SetError ("AudioUnitSetProperty:RemoveInputCallback:%ld", result); 243 SDL_SetError("AudioUnitSetProperty:RemoveInputCallback:%ld",
244 result);
225 245
226 afp->mAudioFileManager->Disconnect(afp->mAudioFileManager); 246 afp->mAudioFileManager->Disconnect(afp->mAudioFileManager);
227 } 247 }
228 } 248 }
229 249
230 typedef struct { 250 typedef struct
251 {
231 UInt32 offset; 252 UInt32 offset;
232 UInt32 blockSize; 253 UInt32 blockSize;
233 } SSNDData; 254 } SSNDData;
234 255
235 static int AudioFilePlayer_OpenFile (AudioFilePlayer *afp, const FSRef *inRef, SInt64 *outFileDataSize) 256 static int
257 AudioFilePlayer_OpenFile(AudioFilePlayer * afp, const FSRef * inRef,
258 SInt64 * outFileDataSize)
236 { 259 {
237 ContainerChunk chunkHeader; 260 ContainerChunk chunkHeader;
238 ChunkHeader chunk; 261 ChunkHeader chunk;
239 SSNDData ssndData; 262 SSNDData ssndData;
240 263
243 ByteCount actual; 266 ByteCount actual;
244 SInt64 offset; 267 SInt64 offset;
245 268
246 /* Open the data fork of the input file */ 269 /* Open the data fork of the input file */
247 result = FSGetDataForkName(&dfName); 270 result = FSGetDataForkName(&dfName);
248 if (result) return 0; /*THROW_RESULT("AudioFilePlayer::OpenFile(): FSGetDataForkName")*/ 271 if (result)
249 272 return 0; /*THROW_RESULT("AudioFilePlayer::OpenFile(): FSGetDataForkName") */
250 result = FSOpenFork(inRef, dfName.length, dfName.unicode, fsRdPerm, &afp->mForkRefNum); 273
251 if (result) return 0; /*THROW_RESULT("AudioFilePlayer::OpenFile(): FSOpenFork")*/ 274 result =
252 275 FSOpenFork(inRef, dfName.length, dfName.unicode, fsRdPerm,
276 &afp->mForkRefNum);
277 if (result)
278 return 0; /*THROW_RESULT("AudioFilePlayer::OpenFile(): FSOpenFork") */
279
253 /* Read the file header, and check if it's indeed an AIFC file */ 280 /* Read the file header, and check if it's indeed an AIFC file */
254 result = FSReadFork(afp->mForkRefNum, fsAtMark, 0, sizeof(chunkHeader), &chunkHeader, &actual); 281 result =
255 if (result) return 0; /*THROW_RESULT("AudioFilePlayer::OpenFile(): FSReadFork")*/ 282 FSReadFork(afp->mForkRefNum, fsAtMark, 0, sizeof(chunkHeader),
283 &chunkHeader, &actual);
284 if (result)
285 return 0; /*THROW_RESULT("AudioFilePlayer::OpenFile(): FSReadFork") */
256 286
257 if (chunkHeader.ckID != 'FORM') { 287 if (chunkHeader.ckID != 'FORM') {
258 result = -1; 288 result = -1;
259 if (result) return 0; /*THROW_RESULT("AudioFilePlayer::OpenFile(): chunk id is not 'FORM'");*/ 289 if (result)
290 return 0; /*THROW_RESULT("AudioFilePlayer::OpenFile(): chunk id is not 'FORM'"); */
260 } 291 }
261 292
262 if (chunkHeader.formType != 'AIFC') { 293 if (chunkHeader.formType != 'AIFC') {
263 result = -1; 294 result = -1;
264 if (result) return 0; /*THROW_RESULT("AudioFilePlayer::OpenFile(): file format is not 'AIFC'");*/ 295 if (result)
296 return 0; /*THROW_RESULT("AudioFilePlayer::OpenFile(): file format is not 'AIFC'"); */
265 } 297 }
266 298
267 /* Search for the SSND chunk. We ignore all compression etc. information 299 /* Search for the SSND chunk. We ignore all compression etc. information
268 in other chunks. Of course that is kind of evil, but for now we are lazy 300 in other chunks. Of course that is kind of evil, but for now we are lazy
269 and rely on the cdfs to always give us the same fixed format. 301 and rely on the cdfs to always give us the same fixed format.
270 TODO: Parse the COMM chunk we currently skip to fill in mFileDescription. 302 TODO: Parse the COMM chunk we currently skip to fill in mFileDescription.
271 */ 303 */
272 offset = 0; 304 offset = 0;
273 do { 305 do {
274 result = FSReadFork(afp->mForkRefNum, fsFromMark, offset, sizeof(chunk), &chunk, &actual); 306 result =
275 if (result) return 0; /*THROW_RESULT("AudioFilePlayer::OpenFile(): FSReadFork")*/ 307 FSReadFork(afp->mForkRefNum, fsFromMark, offset,
276 308 sizeof(chunk), &chunk, &actual);
309 if (result)
310 return 0; /*THROW_RESULT("AudioFilePlayer::OpenFile(): FSReadFork") */
311
277 /* Skip the chunk data */ 312 /* Skip the chunk data */
278 offset = chunk.ckSize; 313 offset = chunk.ckSize;
279 } while (chunk.ckID != 'SSND'); 314 }
315 while (chunk.ckID != 'SSND');
280 316
281 /* Read the header of the SSND chunk. After this, we are positioned right 317 /* Read the header of the SSND chunk. After this, we are positioned right
282 at the start of the audio data. */ 318 at the start of the audio data. */
283 result = FSReadFork(afp->mForkRefNum, fsAtMark, 0, sizeof(ssndData), &ssndData, &actual); 319 result =
284 if (result) return 0; /*THROW_RESULT("AudioFilePlayer::OpenFile(): FSReadFork")*/ 320 FSReadFork(afp->mForkRefNum, fsAtMark, 0, sizeof(ssndData),
321 &ssndData, &actual);
322 if (result)
323 return 0; /*THROW_RESULT("AudioFilePlayer::OpenFile(): FSReadFork") */
285 324
286 result = FSSetForkPosition(afp->mForkRefNum, fsFromMark, ssndData.offset); 325 result = FSSetForkPosition(afp->mForkRefNum, fsFromMark, ssndData.offset);
287 if (result) return 0; /*THROW_RESULT("AudioFilePlayer::OpenFile(): FSSetForkPosition")*/ 326 if (result)
327 return 0; /*THROW_RESULT("AudioFilePlayer::OpenFile(): FSSetForkPosition") */
288 328
289 /* Data size */ 329 /* Data size */
290 *outFileDataSize = chunk.ckSize - ssndData.offset - 8; 330 *outFileDataSize = chunk.ckSize - ssndData.offset - 8;
291 331
292 /* File format */ 332 /* File format */
293 afp->mFileDescription.mSampleRate = 44100; 333 afp->mFileDescription.mSampleRate = 44100;
294 afp->mFileDescription.mFormatID = kAudioFormatLinearPCM; 334 afp->mFileDescription.mFormatID = kAudioFormatLinearPCM;
295 afp->mFileDescription.mFormatFlags = kLinearPCMFormatFlagIsPacked | kLinearPCMFormatFlagIsSignedInteger; 335 afp->mFileDescription.mFormatFlags =
336 kLinearPCMFormatFlagIsPacked | kLinearPCMFormatFlagIsSignedInteger;
296 afp->mFileDescription.mBytesPerPacket = 4; 337 afp->mFileDescription.mBytesPerPacket = 4;
297 afp->mFileDescription.mFramesPerPacket = 1; 338 afp->mFileDescription.mFramesPerPacket = 1;
298 afp->mFileDescription.mBytesPerFrame = 4; 339 afp->mFileDescription.mBytesPerFrame = 4;
299 afp->mFileDescription.mChannelsPerFrame = 2; 340 afp->mFileDescription.mChannelsPerFrame = 2;
300 afp->mFileDescription.mBitsPerChannel = 16; 341 afp->mFileDescription.mBitsPerChannel = 16;
301 342
302 return 1; 343 return 1;
303 } 344 }
304 345
305 AudioFilePlayer *new_AudioFilePlayer (const FSRef *inFileRef) 346 AudioFilePlayer *
306 { 347 new_AudioFilePlayer(const FSRef * inFileRef)
307 SInt64 fileDataSize = 0; 348 {
308 349 SInt64 fileDataSize = 0;
309 AudioFilePlayer *afp = (AudioFilePlayer *) SDL_malloc(sizeof (AudioFilePlayer)); 350
351 AudioFilePlayer *afp =
352 (AudioFilePlayer *) SDL_malloc(sizeof(AudioFilePlayer));
310 if (afp == NULL) 353 if (afp == NULL)
311 return NULL; 354 return NULL;
312 SDL_memset(afp, '\0', sizeof (*afp)); 355 SDL_memset(afp, '\0', sizeof(*afp));
313 356
314 #define SET_AUDIOFILEPLAYER_METHOD(m) afp->m = AudioFilePlayer_##m 357 #define SET_AUDIOFILEPLAYER_METHOD(m) afp->m = AudioFilePlayer_##m
315 SET_AUDIOFILEPLAYER_METHOD(SetDestination); 358 SET_AUDIOFILEPLAYER_METHOD(SetDestination);
316 SET_AUDIOFILEPLAYER_METHOD(SetNotifier); 359 SET_AUDIOFILEPLAYER_METHOD(SetNotifier);
317 SET_AUDIOFILEPLAYER_METHOD(SetStartFrame); 360 SET_AUDIOFILEPLAYER_METHOD(SetStartFrame);
318 SET_AUDIOFILEPLAYER_METHOD(GetCurrentFrame); 361 SET_AUDIOFILEPLAYER_METHOD(GetCurrentFrame);
319 SET_AUDIOFILEPLAYER_METHOD(SetStopFrame); 362 SET_AUDIOFILEPLAYER_METHOD(SetStopFrame);
322 SET_AUDIOFILEPLAYER_METHOD(DoNotification); 365 SET_AUDIOFILEPLAYER_METHOD(DoNotification);
323 SET_AUDIOFILEPLAYER_METHOD(IsConnected); 366 SET_AUDIOFILEPLAYER_METHOD(IsConnected);
324 SET_AUDIOFILEPLAYER_METHOD(GetDestUnit); 367 SET_AUDIOFILEPLAYER_METHOD(GetDestUnit);
325 SET_AUDIOFILEPLAYER_METHOD(Print); 368 SET_AUDIOFILEPLAYER_METHOD(Print);
326 SET_AUDIOFILEPLAYER_METHOD(OpenFile); 369 SET_AUDIOFILEPLAYER_METHOD(OpenFile);
327 #undef SET_AUDIOFILEPLAYER_METHOD 370 #undef SET_AUDIOFILEPLAYER_METHOD
328 371
329 if (!afp->OpenFile (afp, inFileRef, &fileDataSize)) 372 if (!afp->OpenFile(afp, inFileRef, &fileDataSize)) {
330 {
331 SDL_free(afp); 373 SDL_free(afp);
332 return NULL; 374 return NULL;
333 } 375 }
334 376
335 /* we want about 4 seconds worth of data for the buffer */ 377 /* we want about 4 seconds worth of data for the buffer */
336 int bytesPerSecond = (UInt32) (4 * afp->mFileDescription.mSampleRate * afp->mFileDescription.mBytesPerFrame); 378 int bytesPerSecond =
337 379 (UInt32) (4 * afp->mFileDescription.mSampleRate *
380 afp->mFileDescription.mBytesPerFrame);
381
338 #if DEBUG 382 #if DEBUG
339 printf("File format:\n"); 383 printf("File format:\n");
340 PrintStreamDesc (&afp->mFileDescription); 384 PrintStreamDesc(&afp->mFileDescription);
341 #endif 385 #endif
342 386
343 afp->mAudioFileManager = new_AudioFileManager(afp, afp->mForkRefNum, 387 afp->mAudioFileManager = new_AudioFileManager(afp, afp->mForkRefNum,
344 fileDataSize, 388 fileDataSize,
345 bytesPerSecond); 389 bytesPerSecond);
346 if (afp->mAudioFileManager == NULL) 390 if (afp->mAudioFileManager == NULL) {
347 {
348 delete_AudioFilePlayer(afp); 391 delete_AudioFilePlayer(afp);
349 return NULL; 392 return NULL;
350 } 393 }
351 394
352 return afp; 395 return afp;
353 } 396 }
354 397
398 /* vi: set ts=4 sw=4 expandtab: */