Mercurial > sdl-ios-xcode
comparison src/cdrom/macosx/AudioFilePlayer.c @ 1662:782fd950bd46 SDL-1.3
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
WARNING: None of the video drivers have been updated for the new API yet! The API is still under design and very fluid.
The code is now run through a consistent indent format:
indent -i4 -nut -nsc -br -ce
The headers are being converted to automatically generate doxygen documentation.
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Sun, 28 May 2006 13:04:16 +0000 |
parents | 14717b52abc0 |
children | 4da1ee79c9af |
comparison
equal
deleted
inserted
replaced
1661:281d3f4870e5 | 1662:782fd950bd46 |
---|---|
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); |
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 { |
127 #if DEBUG | |
128 printf ("Is Connected:%s\n", (IsConnected ()? "true" : "false")); | |
119 printf ("- - - - - - - - - - - - - - \n"); | 129 printf ("- - - - - - - - - - - - - - \n"); |
120 #endif | 130 #endif |
121 } | 131 } |
122 | 132 |
123 static void AudioFilePlayer_SetStartFrame (AudioFilePlayer *afp, int frame) | 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 |
152 AudioFilePlayer_SetStopFrame (AudioFilePlayer * afp, int frame) | |
153 { | |
154 SInt64 position = frame * 2352; | |
155 | |
141 afp->mAudioFileManager->SetEndOfFile (afp->mAudioFileManager, position); | 156 afp->mAudioFileManager->SetEndOfFile (afp->mAudioFileManager, position); |
142 } | 157 } |
143 | 158 |
144 void delete_AudioFilePlayer(AudioFilePlayer *afp) | 159 void |
145 { | 160 delete_AudioFilePlayer (AudioFilePlayer * afp) |
146 if (afp != NULL) | 161 { |
147 { | 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 |
170 if (!afp->mAudioFileManager->DoConnect(afp->mAudioFileManager)) | 185 if (!afp->mConnected) { |
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", |
225 | 244 result); |
226 afp->mAudioFileManager->Disconnect(afp->mAudioFileManager); | 245 |
227 } | 246 afp->mAudioFileManager->Disconnect (afp->mAudioFileManager); |
228 } | 247 } |
229 | 248 } |
230 typedef struct { | 249 |
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 |
242 HFSUniStr255 dfName; | 265 HFSUniStr255 dfName; |
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), |
285 | 321 &ssndData, &actual); |
286 result = FSSetForkPosition(afp->mForkRefNum, fsFromMark, ssndData.offset); | 322 if (result) |
287 if (result) return 0; /*THROW_RESULT("AudioFilePlayer::OpenFile(): FSSetForkPosition")*/ | 323 return 0; /*THROW_RESULT("AudioFilePlayer::OpenFile(): FSReadFork") */ |
324 | |
325 result = | |
326 FSSetForkPosition (afp->mForkRefNum, fsFromMark, ssndData.offset); | |
327 if (result) | |
328 return 0; /*THROW_RESULT("AudioFilePlayer::OpenFile(): FSSetForkPosition") */ | |
288 | 329 |
289 /* Data size */ | 330 /* Data size */ |
290 *outFileDataSize = chunk.ckSize - ssndData.offset - 8; | 331 *outFileDataSize = chunk.ckSize - ssndData.offset - 8; |
291 | 332 |
292 /* File format */ | 333 /* File format */ |
293 afp->mFileDescription.mSampleRate = 44100; | 334 afp->mFileDescription.mSampleRate = 44100; |
294 afp->mFileDescription.mFormatID = kAudioFormatLinearPCM; | 335 afp->mFileDescription.mFormatID = kAudioFormatLinearPCM; |
295 afp->mFileDescription.mFormatFlags = kLinearPCMFormatFlagIsPacked | kLinearPCMFormatFlagIsSignedInteger; | 336 afp->mFileDescription.mFormatFlags = |
337 kLinearPCMFormatFlagIsPacked | kLinearPCMFormatFlagIsSignedInteger; | |
296 afp->mFileDescription.mBytesPerPacket = 4; | 338 afp->mFileDescription.mBytesPerPacket = 4; |
297 afp->mFileDescription.mFramesPerPacket = 1; | 339 afp->mFileDescription.mFramesPerPacket = 1; |
298 afp->mFileDescription.mBytesPerFrame = 4; | 340 afp->mFileDescription.mBytesPerFrame = 4; |
299 afp->mFileDescription.mChannelsPerFrame = 2; | 341 afp->mFileDescription.mChannelsPerFrame = 2; |
300 afp->mFileDescription.mBitsPerChannel = 16; | 342 afp->mFileDescription.mBitsPerChannel = 16; |
301 | 343 |
302 return 1; | 344 return 1; |
303 } | 345 } |
304 | 346 |
305 AudioFilePlayer *new_AudioFilePlayer (const FSRef *inFileRef) | 347 AudioFilePlayer * |
306 { | 348 new_AudioFilePlayer (const FSRef * inFileRef) |
307 SInt64 fileDataSize = 0; | 349 { |
308 | 350 SInt64 fileDataSize = 0; |
309 AudioFilePlayer *afp = (AudioFilePlayer *) SDL_malloc(sizeof (AudioFilePlayer)); | 351 |
352 AudioFilePlayer *afp = | |
353 (AudioFilePlayer *) SDL_malloc (sizeof (AudioFilePlayer)); | |
310 if (afp == NULL) | 354 if (afp == NULL) |
311 return NULL; | 355 return NULL; |
312 SDL_memset(afp, '\0', sizeof (*afp)); | 356 SDL_memset (afp, '\0', sizeof (*afp)); |
313 | 357 |
314 #define SET_AUDIOFILEPLAYER_METHOD(m) afp->m = AudioFilePlayer_##m | 358 #define SET_AUDIOFILEPLAYER_METHOD(m) afp->m = AudioFilePlayer_##m |
315 SET_AUDIOFILEPLAYER_METHOD(SetDestination); | 359 SET_AUDIOFILEPLAYER_METHOD (SetDestination); |
316 SET_AUDIOFILEPLAYER_METHOD(SetNotifier); | 360 SET_AUDIOFILEPLAYER_METHOD (SetNotifier); |
317 SET_AUDIOFILEPLAYER_METHOD(SetStartFrame); | 361 SET_AUDIOFILEPLAYER_METHOD (SetStartFrame); |
318 SET_AUDIOFILEPLAYER_METHOD(GetCurrentFrame); | 362 SET_AUDIOFILEPLAYER_METHOD (GetCurrentFrame); |
319 SET_AUDIOFILEPLAYER_METHOD(SetStopFrame); | 363 SET_AUDIOFILEPLAYER_METHOD (SetStopFrame); |
320 SET_AUDIOFILEPLAYER_METHOD(Connect); | 364 SET_AUDIOFILEPLAYER_METHOD (Connect); |
321 SET_AUDIOFILEPLAYER_METHOD(Disconnect); | 365 SET_AUDIOFILEPLAYER_METHOD (Disconnect); |
322 SET_AUDIOFILEPLAYER_METHOD(DoNotification); | 366 SET_AUDIOFILEPLAYER_METHOD (DoNotification); |
323 SET_AUDIOFILEPLAYER_METHOD(IsConnected); | 367 SET_AUDIOFILEPLAYER_METHOD (IsConnected); |
324 SET_AUDIOFILEPLAYER_METHOD(GetDestUnit); | 368 SET_AUDIOFILEPLAYER_METHOD (GetDestUnit); |
325 SET_AUDIOFILEPLAYER_METHOD(Print); | 369 SET_AUDIOFILEPLAYER_METHOD (Print); |
326 SET_AUDIOFILEPLAYER_METHOD(OpenFile); | 370 SET_AUDIOFILEPLAYER_METHOD (OpenFile); |
327 #undef SET_AUDIOFILEPLAYER_METHOD | 371 #undef SET_AUDIOFILEPLAYER_METHOD |
328 | 372 |
329 if (!afp->OpenFile (afp, inFileRef, &fileDataSize)) | 373 if (!afp->OpenFile (afp, inFileRef, &fileDataSize)) { |
330 { | 374 SDL_free (afp); |
331 SDL_free(afp); | |
332 return NULL; | 375 return NULL; |
333 } | 376 } |
334 | 377 |
335 /* we want about 4 seconds worth of data for the buffer */ | 378 /* we want about 4 seconds worth of data for the buffer */ |
336 int bytesPerSecond = (UInt32) (4 * afp->mFileDescription.mSampleRate * afp->mFileDescription.mBytesPerFrame); | 379 int bytesPerSecond = |
337 | 380 (UInt32) (4 * afp->mFileDescription.mSampleRate * |
338 #if DEBUG | 381 afp->mFileDescription.mBytesPerFrame); |
339 printf("File format:\n"); | 382 |
383 #if DEBUG | |
384 printf ("File format:\n"); | |
340 PrintStreamDesc (&afp->mFileDescription); | 385 PrintStreamDesc (&afp->mFileDescription); |
341 #endif | 386 #endif |
342 | 387 |
343 afp->mAudioFileManager = new_AudioFileManager(afp, afp->mForkRefNum, | 388 afp->mAudioFileManager = new_AudioFileManager (afp, afp->mForkRefNum, |
344 fileDataSize, | 389 fileDataSize, |
345 bytesPerSecond); | 390 bytesPerSecond); |
346 if (afp->mAudioFileManager == NULL) | 391 if (afp->mAudioFileManager == NULL) { |
347 { | 392 delete_AudioFilePlayer (afp); |
348 delete_AudioFilePlayer(afp); | |
349 return NULL; | 393 return NULL; |
350 } | 394 } |
351 | 395 |
352 return afp; | 396 return afp; |
353 } | 397 } |
354 | 398 |
399 /* vi: set ts=4 sw=4 expandtab: */ |