Skip to content

Latest commit

 

History

History
610 lines (497 loc) · 19.6 KB

AudioFileReaderThread.c

File metadata and controls

610 lines (497 loc) · 19.6 KB
 
1
2
/*
SDL - Simple DirectMedia Layer
Dec 31, 2011
Dec 31, 2011
3
Copyright (C) 1997-2012 Sam Lantinga
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Sam Lantinga
slouken@libsdl.org
This file based on Apple sample code. We haven't changed the file name,
so if you want to see the original search for it on apple.com/developer
*/
Feb 21, 2006
Feb 21, 2006
25
#include "SDL_config.h"
Mar 9, 2006
Mar 9, 2006
27
28
29
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
AudioFileManager.cpp
*/
30
#include "AudioFilePlayer.h"
Mar 9, 2006
Mar 9, 2006
31
#include <mach/mach.h> /* used for setting policy of thread */
32
33
34
#include "SDLOSXCAGuard.h"
#include <pthread.h>
Mar 9, 2006
Mar 9, 2006
35
/*#include <list>*/
Mar 9, 2006
Mar 9, 2006
37
/*typedef void *FileData;*/
38
39
40
41
42
43
44
45
typedef struct S_FileData
{
AudioFileManager *obj;
struct S_FileData *next;
} FileData;
typedef struct S_FileReaderThread {
Mar 9, 2006
Mar 9, 2006
46
/*public:*/
47
48
49
50
51
52
53
SDLOSXCAGuard* (*GetGuard)(struct S_FileReaderThread *frt);
void (*AddReader)(struct S_FileReaderThread *frt);
void (*RemoveReader)(struct S_FileReaderThread *frt, AudioFileManager* inItem);
int (*TryNextRead)(struct S_FileReaderThread *frt, AudioFileManager* inItem);
int mThreadShouldDie;
Mar 9, 2006
Mar 9, 2006
54
55
/*private:*/
/*typedef std::list<AudioFileManager*> FileData;*/
56
57
58
59
60
61
62
63
64
65
SDLOSXCAGuard *mGuard;
UInt32 mThreadPriority;
int mNumReaders;
FileData *mFileData;
void (*ReadNextChunk)(struct S_FileReaderThread *frt);
int (*StartFixedPriorityThread)(struct S_FileReaderThread *frt);
Mar 9, 2006
Mar 9, 2006
66
/*static*/
67
UInt32 (*GetThreadBasePriority)(pthread_t inThread);
Mar 9, 2006
Mar 9, 2006
68
/*static*/
69
70
71
72
73
74
75
76
77
void* (*DiskReaderEntry)(void *inRefCon);
} FileReaderThread;
static SDLOSXCAGuard* FileReaderThread_GetGuard(FileReaderThread *frt)
{
return frt->mGuard;
}
Mar 9, 2006
Mar 9, 2006
78
/* returns 1 if succeeded */
79
80
81
82
83
84
static int FileReaderThread_TryNextRead (FileReaderThread *frt, AudioFileManager* inItem)
{
int didLock = 0;
int succeeded = 0;
if (frt->mGuard->Try(frt->mGuard, &didLock))
{
Mar 9, 2006
Mar 9, 2006
85
86
/*frt->mFileData.push_back (inItem);*/
/* !!! FIXME: this could be faster with a "tail" member. --ryan. */
87
88
89
FileData *i = frt->mFileData;
FileData *prev = NULL;
Feb 7, 2006
Feb 7, 2006
90
FileData *newfd = (FileData *) SDL_malloc(sizeof (FileData));
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
newfd->obj = inItem;
newfd->next = NULL;
while (i != NULL) { prev = i; i = i->next; }
if (prev == NULL)
frt->mFileData = newfd;
else
prev->next = newfd;
frt->mGuard->Notify(frt->mGuard);
succeeded = 1;
if (didLock)
frt->mGuard->Unlock(frt->mGuard);
}
return succeeded;
}
static void FileReaderThread_AddReader(FileReaderThread *frt)
{
if (frt->mNumReaders == 0)
{
frt->mThreadShouldDie = 0;
frt->StartFixedPriorityThread (frt);
}
frt->mNumReaders++;
}
static void FileReaderThread_RemoveReader (FileReaderThread *frt, AudioFileManager* inItem)
{
if (frt->mNumReaders > 0)
{
int bNeedsRelease = frt->mGuard->Lock(frt->mGuard);
Mar 9, 2006
Mar 9, 2006
126
/*frt->mFileData.remove (inItem);*/
127
128
129
130
131
132
133
134
135
136
137
138
139
FileData *i = frt->mFileData;
FileData *prev = NULL;
while (i != NULL)
{
FileData *next = i->next;
if (i->obj != inItem)
prev = i;
else
{
if (prev == NULL)
frt->mFileData = next;
else
prev->next = next;
Feb 7, 2006
Feb 7, 2006
140
SDL_free(i);
141
142
143
144
145
146
}
i = next;
}
if (--frt->mNumReaders == 0) {
frt->mThreadShouldDie = 1;
Mar 9, 2006
Mar 9, 2006
147
148
frt->mGuard->Notify(frt->mGuard); /* wake up thread so it will quit */
frt->mGuard->Wait(frt->mGuard); /* wait for thread to die */
149
150
151
152
153
154
155
156
157
158
159
160
}
if (bNeedsRelease) frt->mGuard->Unlock(frt->mGuard);
}
}
static int FileReaderThread_StartFixedPriorityThread (FileReaderThread *frt)
{
pthread_attr_t theThreadAttrs;
pthread_t pThread;
OSStatus result = pthread_attr_init(&theThreadAttrs);
Mar 9, 2006
Mar 9, 2006
161
if (result) return 0; /*THROW_RESULT("pthread_attr_init - Thread attributes could not be created.")*/
162
163
result = pthread_attr_setdetachstate(&theThreadAttrs, PTHREAD_CREATE_DETACHED);
Mar 9, 2006
Mar 9, 2006
164
if (result) return 0; /*THROW_RESULT("pthread_attr_setdetachstate - Thread attributes could not be detached.")*/
165
166
result = pthread_create (&pThread, &theThreadAttrs, frt->DiskReaderEntry, frt);
Mar 9, 2006
Mar 9, 2006
167
if (result) return 0; /*THROW_RESULT("pthread_create - Create and start the thread.")*/
168
169
170
pthread_attr_destroy(&theThreadAttrs);
Mar 9, 2006
Mar 9, 2006
171
172
173
/* we've now created the thread and started it
we'll now set the priority of the thread to the nominated priority
and we'll also make the thread fixed */
174
175
176
177
thread_extended_policy_data_t theFixedPolicy;
thread_precedence_policy_data_t thePrecedencePolicy;
SInt32 relativePriority;
Mar 9, 2006
Mar 9, 2006
178
179
/* make thread fixed */
theFixedPolicy.timeshare = 0; /* set to 1 for a non-fixed thread */
180
result = thread_policy_set (pthread_mach_thread_np(pThread), THREAD_EXTENDED_POLICY, (thread_policy_t)&theFixedPolicy, THREAD_EXTENDED_POLICY_COUNT);
Mar 9, 2006
Mar 9, 2006
181
182
183
if (result) return 0; /*THROW_RESULT("thread_policy - Couldn't set thread as fixed priority.")*/
/* set priority */
/* precedency policy's "importance" value is relative to spawning thread's priority */
184
185
186
187
relativePriority = frt->mThreadPriority - frt->GetThreadBasePriority(pthread_self());
thePrecedencePolicy.importance = relativePriority;
result = thread_policy_set (pthread_mach_thread_np(pThread), THREAD_PRECEDENCE_POLICY, (thread_policy_t)&thePrecedencePolicy, THREAD_PRECEDENCE_POLICY_COUNT);
Mar 9, 2006
Mar 9, 2006
188
if (result) return 0; /*THROW_RESULT("thread_policy - Couldn't set thread priority.")*/
189
190
191
192
193
194
195
196
197
198
return 1;
}
static UInt32 FileReaderThread_GetThreadBasePriority (pthread_t inThread)
{
thread_basic_info_data_t threadInfo;
policy_info_data_t thePolicyInfo;
unsigned int count;
Mar 9, 2006
Mar 9, 2006
199
/* get basic info */
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
count = THREAD_BASIC_INFO_COUNT;
thread_info (pthread_mach_thread_np (inThread), THREAD_BASIC_INFO, (integer_t*)&threadInfo, &count);
switch (threadInfo.policy) {
case POLICY_TIMESHARE:
count = POLICY_TIMESHARE_INFO_COUNT;
thread_info(pthread_mach_thread_np (inThread), THREAD_SCHED_TIMESHARE_INFO, (integer_t*)&(thePolicyInfo.ts), &count);
return thePolicyInfo.ts.base_priority;
break;
case POLICY_FIFO:
count = POLICY_FIFO_INFO_COUNT;
thread_info(pthread_mach_thread_np (inThread), THREAD_SCHED_FIFO_INFO, (integer_t*)&(thePolicyInfo.fifo), &count);
if (thePolicyInfo.fifo.depressed) {
return thePolicyInfo.fifo.depress_priority;
} else {
return thePolicyInfo.fifo.base_priority;
}
break;
case POLICY_RR:
count = POLICY_RR_INFO_COUNT;
thread_info(pthread_mach_thread_np (inThread), THREAD_SCHED_RR_INFO, (integer_t*)&(thePolicyInfo.rr), &count);
if (thePolicyInfo.rr.depressed) {
return thePolicyInfo.rr.depress_priority;
} else {
return thePolicyInfo.rr.base_priority;
}
break;
}
return 0;
}
static void *FileReaderThread_DiskReaderEntry (void *inRefCon)
{
FileReaderThread *frt = (FileReaderThread *)inRefCon;
frt->ReadNextChunk(frt);
#if DEBUG
printf ("finished with reading file\n");
#endif
return 0;
}
static void FileReaderThread_ReadNextChunk (FileReaderThread *frt)
{
OSStatus result;
Sep 12, 2009
Sep 12, 2009
248
ByteCount dataChunkSize;
249
250
251
252
AudioFileManager* theItem = 0;
for (;;)
{
Mar 9, 2006
Mar 9, 2006
253
{ /* this is a scoped based lock */
254
255
256
257
258
259
260
261
int bNeedsRelease = frt->mGuard->Lock(frt->mGuard);
if (frt->mThreadShouldDie) {
frt->mGuard->Notify(frt->mGuard);
if (bNeedsRelease) frt->mGuard->Unlock(frt->mGuard);
return;
}
Mar 9, 2006
Mar 9, 2006
262
/*if (frt->mFileData.empty())*/
263
264
265
266
267
if (frt->mFileData == NULL)
{
frt->mGuard->Wait(frt->mGuard);
}
Mar 9, 2006
Mar 9, 2006
268
/* kill thread */
269
270
271
272
273
274
275
if (frt->mThreadShouldDie) {
frt->mGuard->Notify(frt->mGuard);
if (bNeedsRelease) frt->mGuard->Unlock(frt->mGuard);
return;
}
Mar 9, 2006
Mar 9, 2006
276
277
/*theItem = frt->mFileData.front();*/
/*frt->mFileData.pop_front();*/
278
279
280
281
282
theItem = NULL;
if (frt->mFileData != NULL)
{
FileData *next = frt->mFileData->next;
theItem = frt->mFileData->obj;
Feb 7, 2006
Feb 7, 2006
283
SDL_free(frt->mFileData);
284
285
286
287
288
289
290
291
292
293
294
frt->mFileData = next;
}
if (bNeedsRelease) frt->mGuard->Unlock(frt->mGuard);
}
if ((theItem->mFileLength - theItem->mReadFilePosition) < theItem->mChunkSize)
dataChunkSize = theItem->mFileLength - theItem->mReadFilePosition;
else
dataChunkSize = theItem->mChunkSize;
Mar 9, 2006
Mar 9, 2006
295
/* this is the exit condition for the thread */
296
297
298
299
if (dataChunkSize <= 0) {
theItem->mFinishedReadingData = 1;
continue;
}
Mar 9, 2006
Mar 9, 2006
300
/* construct pointer */
301
302
303
char* writePtr = (char *) (theItem->GetFileBuffer(theItem) +
(theItem->mWriteToFirstBuffer ? 0 : theItem->mChunkSize));
Mar 9, 2006
Mar 9, 2006
304
/* read data */
305
306
307
308
309
310
311
312
313
314
315
result = theItem->Read(theItem, writePtr, &dataChunkSize);
if (result != noErr && result != eofErr) {
AudioFilePlayer *afp = (AudioFilePlayer *) theItem->GetParent(theItem);
afp->DoNotification(afp, result);
continue;
}
if (dataChunkSize != theItem->mChunkSize)
{
writePtr += dataChunkSize;
Mar 9, 2006
Mar 9, 2006
316
317
/* can't exit yet.. we still have to pass the partial buffer back */
SDL_memset(writePtr, 0, (theItem->mChunkSize - dataChunkSize));
Mar 9, 2006
Mar 9, 2006
320
theItem->mWriteToFirstBuffer = !theItem->mWriteToFirstBuffer; /* switch buffers */
321
322
323
324
if (result == eofErr)
theItem->mReadFilePosition = theItem->mFileLength;
else
Mar 9, 2006
Mar 9, 2006
325
theItem->mReadFilePosition += dataChunkSize; /* increment count */
326
327
328
329
330
331
332
333
}
}
void delete_FileReaderThread(FileReaderThread *frt)
{
if (frt != NULL)
{
delete_SDLOSXCAGuard(frt->mGuard);
Feb 7, 2006
Feb 7, 2006
334
SDL_free(frt);
335
336
337
338
339
}
}
FileReaderThread *new_FileReaderThread ()
{
Feb 7, 2006
Feb 7, 2006
340
FileReaderThread *frt = (FileReaderThread *) SDL_malloc(sizeof (FileReaderThread));
341
342
if (frt == NULL)
return NULL;
Feb 7, 2006
Feb 7, 2006
343
SDL_memset(frt, '\0', sizeof (*frt));
344
345
346
347
frt->mGuard = new_SDLOSXCAGuard();
if (frt->mGuard == NULL)
{
Feb 7, 2006
Feb 7, 2006
348
SDL_free(frt);
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
return NULL;
}
#define SET_FILEREADERTHREAD_METHOD(m) frt->m = FileReaderThread_##m
SET_FILEREADERTHREAD_METHOD(GetGuard);
SET_FILEREADERTHREAD_METHOD(AddReader);
SET_FILEREADERTHREAD_METHOD(RemoveReader);
SET_FILEREADERTHREAD_METHOD(TryNextRead);
SET_FILEREADERTHREAD_METHOD(ReadNextChunk);
SET_FILEREADERTHREAD_METHOD(StartFixedPriorityThread);
SET_FILEREADERTHREAD_METHOD(GetThreadBasePriority);
SET_FILEREADERTHREAD_METHOD(DiskReaderEntry);
#undef SET_FILEREADERTHREAD_METHOD
frt->mThreadPriority = 62;
return frt;
}
static FileReaderThread *sReaderThread;
static int AudioFileManager_DoConnect (AudioFileManager *afm)
{
if (!afm->mIsEngaged)
{
Mar 9, 2006
Mar 9, 2006
375
376
377
OSStatus result;
/*afm->mReadFilePosition = 0;*/
378
379
380
381
382
afm->mFinishedReadingData = 0;
afm->mNumTimesAskedSinceFinished = 0;
afm->mLockUnsuccessful = 0;
Sep 12, 2009
Sep 12, 2009
383
ByteCount dataChunkSize;
384
385
386
387
388
389
390
if ((afm->mFileLength - afm->mReadFilePosition) < afm->mChunkSize)
dataChunkSize = afm->mFileLength - afm->mReadFilePosition;
else
dataChunkSize = afm->mChunkSize;
result = afm->Read(afm, afm->mFileBuffer, &dataChunkSize);
Mar 9, 2006
Mar 9, 2006
391
if (result) return 0; /*THROW_RESULT("AudioFileManager::DoConnect(): Read")*/
392
393
394
395
396
397
398
399
400
401
afm->mReadFilePosition += dataChunkSize;
afm->mWriteToFirstBuffer = 0;
afm->mReadFromFirstBuffer = 1;
sReaderThread->AddReader(sReaderThread);
afm->mIsEngaged = 1;
}
Mar 9, 2006
Mar 9, 2006
402
403
404
/*
else
throw static_cast<OSStatus>(-1); */ /* thread has already been started */
405
406
407
408
409
410
411
412
413
414
415
416
417
return 1;
}
static void AudioFileManager_Disconnect (AudioFileManager *afm)
{
if (afm->mIsEngaged)
{
sReaderThread->RemoveReader (sReaderThread, afm);
afm->mIsEngaged = 0;
}
}
Sep 12, 2009
Sep 12, 2009
418
static OSStatus AudioFileManager_Read(AudioFileManager *afm, char *buffer, ByteCount *len)
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
{
return FSReadFork (afm->mForkRefNum,
fsFromStart,
afm->mReadFilePosition + afm->mAudioDataOffset,
*len,
buffer,
len);
}
static OSStatus AudioFileManager_GetFileData (AudioFileManager *afm, void** inOutData, UInt32 *inOutDataSize)
{
if (afm->mFinishedReadingData)
{
++afm->mNumTimesAskedSinceFinished;
*inOutDataSize = 0;
*inOutData = 0;
return noErr;
}
if (afm->mReadFromFirstBuffer == afm->mWriteToFirstBuffer) {
#if DEBUG
printf ("* * * * * * * Can't keep up with reading file\n");
#endif
afm->mParent->DoNotification (afm->mParent, kAudioFilePlayErr_FilePlayUnderrun);
*inOutDataSize = 0;
*inOutData = 0;
} else {
*inOutDataSize = afm->mChunkSize;
*inOutData = afm->mReadFromFirstBuffer ? afm->mFileBuffer : (afm->mFileBuffer + afm->mChunkSize);
}
afm->mLockUnsuccessful = !sReaderThread->TryNextRead (sReaderThread, afm);
afm->mReadFromFirstBuffer = !afm->mReadFromFirstBuffer;
return noErr;
}
static void AudioFileManager_AfterRender (AudioFileManager *afm)
{
if (afm->mNumTimesAskedSinceFinished > 0)
{
int didLock = 0;
SDLOSXCAGuard *guard = sReaderThread->GetGuard(sReaderThread);
if (guard->Try(guard, &didLock)) {
afm->mParent->DoNotification (afm->mParent, kAudioFilePlay_FileIsFinished);
if (didLock)
guard->Unlock(guard);
}
}
if (afm->mLockUnsuccessful)
afm->mLockUnsuccessful = !sReaderThread->TryNextRead (sReaderThread, afm);
}
static void AudioFileManager_SetPosition (AudioFileManager *afm, SInt64 pos)
{
if (pos < 0 || pos >= afm->mFileLength) {
SDL_SetError ("AudioFileManager::SetPosition - position invalid: %d filelen=%d\n",
(unsigned int)pos, (unsigned int)afm->mFileLength);
pos = 0;
}
afm->mReadFilePosition = pos;
}
static void AudioFileManager_SetEndOfFile (AudioFileManager *afm, SInt64 pos)
{
if (pos <= 0 || pos > afm->mFileLength) {
SDL_SetError ("AudioFileManager::SetEndOfFile - position beyond actual eof\n");
pos = afm->mFileLength;
}
afm->mFileLength = pos;
}
static const char *AudioFileManager_GetFileBuffer(AudioFileManager *afm)
{
return afm->mFileBuffer;
}
const AudioFilePlayer *AudioFileManager_GetParent(AudioFileManager *afm)
{
return afm->mParent;
}
static int AudioFileManager_GetByteCounter(AudioFileManager *afm)
{
return afm->mByteCounter;
}
Sep 12, 2009
Sep 12, 2009
511
512
513
514
515
516
static OSStatus AudioFileManager_FileInputProc (void *inRefCon,
AudioUnitRenderActionFlags *ioActionFlags,
const AudioTimeStamp *inTimeStamp,
UInt32 inBusNumber,
UInt32 inNumberFrames,
AudioBufferList *ioData)
517
518
519
520
521
{
AudioFileManager* afm = (AudioFileManager*)inRefCon;
return afm->Render(afm, ioData);
}
Sep 12, 2009
Sep 12, 2009
522
static OSStatus AudioFileManager_Render (AudioFileManager *afm, AudioBufferList *ioData)
523
524
{
OSStatus result = noErr;
Sep 12, 2009
Sep 12, 2009
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
AudioBuffer *abuf;
UInt32 i;
for (i = 0; i < ioData->mNumberBuffers; i++) {
abuf = &ioData->mBuffers[i];
if (afm->mBufferOffset >= afm->mBufferSize) {
result = afm->GetFileData(afm, &afm->mTmpBuffer, &afm->mBufferSize);
if (result) {
SDL_SetError ("AudioConverterFillBuffer:%ld\n", result);
afm->mParent->DoNotification(afm->mParent, result);
return result;
}
afm->mBufferOffset = 0;
}
if (abuf->mDataByteSize > afm->mBufferSize - afm->mBufferOffset)
abuf->mDataByteSize = afm->mBufferSize - afm->mBufferOffset;
abuf->mData = (char *)afm->mTmpBuffer + afm->mBufferOffset;
afm->mBufferOffset += abuf->mDataByteSize;
Sep 12, 2009
Sep 12, 2009
546
547
548
afm->mByteCounter += abuf->mDataByteSize;
afm->AfterRender(afm);
}
549
550
551
552
553
554
555
556
return result;
}
void delete_AudioFileManager (AudioFileManager *afm)
{
if (afm != NULL) {
if (afm->mFileBuffer) {
Feb 7, 2006
Feb 7, 2006
557
free(afm->mFileBuffer);
Feb 7, 2006
Feb 7, 2006
560
SDL_free(afm);
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
}
}
AudioFileManager *new_AudioFileManager(AudioFilePlayer *inParent,
SInt16 inForkRefNum,
SInt64 inFileLength,
UInt32 inChunkSize)
{
AudioFileManager *afm;
if (sReaderThread == NULL)
{
sReaderThread = new_FileReaderThread();
if (sReaderThread == NULL)
return NULL;
}
Feb 7, 2006
Feb 7, 2006
579
afm = (AudioFileManager *) SDL_malloc(sizeof (AudioFileManager));
580
581
if (afm == NULL)
return NULL;
Feb 7, 2006
Feb 7, 2006
582
SDL_memset(afm, '\0', sizeof (*afm));
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
#define SET_AUDIOFILEMANAGER_METHOD(m) afm->m = AudioFileManager_##m
SET_AUDIOFILEMANAGER_METHOD(Disconnect);
SET_AUDIOFILEMANAGER_METHOD(DoConnect);
SET_AUDIOFILEMANAGER_METHOD(Read);
SET_AUDIOFILEMANAGER_METHOD(GetFileBuffer);
SET_AUDIOFILEMANAGER_METHOD(GetParent);
SET_AUDIOFILEMANAGER_METHOD(SetPosition);
SET_AUDIOFILEMANAGER_METHOD(GetByteCounter);
SET_AUDIOFILEMANAGER_METHOD(SetEndOfFile);
SET_AUDIOFILEMANAGER_METHOD(Render);
SET_AUDIOFILEMANAGER_METHOD(GetFileData);
SET_AUDIOFILEMANAGER_METHOD(AfterRender);
SET_AUDIOFILEMANAGER_METHOD(FileInputProc);
#undef SET_AUDIOFILEMANAGER_METHOD
afm->mParent = inParent;
afm->mForkRefNum = inForkRefNum;
afm->mBufferSize = inChunkSize;
afm->mBufferOffset = inChunkSize;
afm->mChunkSize = inChunkSize;
afm->mFileLength = inFileLength;
Feb 7, 2006
Feb 7, 2006
605
afm->mFileBuffer = (char*) SDL_malloc(afm->mChunkSize * 2);
606
607
608
609
FSGetForkPosition(afm->mForkRefNum, &afm->mAudioDataOffset);
assert (afm->mFileBuffer != NULL);
return afm;
}