slouken@613
|
1 |
/*
|
slouken@613
|
2 |
SDL - Simple DirectMedia Layer
|
slouken@4159
|
3 |
Copyright (C) 1997-2009 Sam Lantinga
|
slouken@613
|
4 |
|
slouken@613
|
5 |
This library is free software; you can redistribute it and/or
|
slouken@613
|
6 |
modify it under the terms of the GNU Library General Public
|
slouken@613
|
7 |
License as published by the Free Software Foundation; either
|
slouken@613
|
8 |
version 2 of the License, or (at your option) any later version.
|
slouken@613
|
9 |
|
slouken@613
|
10 |
This library is distributed in the hope that it will be useful,
|
slouken@613
|
11 |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
slouken@613
|
12 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
slouken@613
|
13 |
Library General Public License for more details.
|
slouken@613
|
14 |
|
slouken@613
|
15 |
You should have received a copy of the GNU Library General Public
|
slouken@613
|
16 |
License along with this library; if not, write to the Free
|
slouken@613
|
17 |
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
slouken@613
|
18 |
|
slouken@613
|
19 |
Sam Lantinga
|
slouken@613
|
20 |
slouken@libsdl.org
|
slouken@613
|
21 |
|
slouken@613
|
22 |
This file based on Apple sample code. We haven't changed the file name,
|
slouken@613
|
23 |
so if you want to see the original search for it on apple.com/developer
|
slouken@613
|
24 |
*/
|
slouken@1402
|
25 |
#include "SDL_config.h"
|
slouken@613
|
26 |
|
slouken@1487
|
27 |
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
slouken@1487
|
28 |
AudioFilePlayer.h
|
slouken@1487
|
29 |
*/
|
slouken@613
|
30 |
#ifndef __AudioFilePlayer_H__
|
slouken@613
|
31 |
#define __AudioFilePlayer_H__
|
slouken@613
|
32 |
|
slouken@613
|
33 |
#include <CoreServices/CoreServices.h>
|
slouken@613
|
34 |
|
slouken@613
|
35 |
#include <AudioUnit/AudioUnit.h>
|
icculus@4190
|
36 |
#if MAC_OS_X_VERSION_MAX_ALLOWED <= 1050
|
slouken@4103
|
37 |
#include <AudioUnit/AUNTComponent.h>
|
slouken@4103
|
38 |
#endif
|
slouken@613
|
39 |
|
icculus@5952
|
40 |
/* This typedef is included in the 10.5+ SDK headers. */
|
icculus@5952
|
41 |
#ifndef MAC_OS_X_VERSION_10_5
|
slouken@4369
|
42 |
typedef SInt16 FSIORefNum;
|
slouken@4369
|
43 |
#endif
|
slouken@4369
|
44 |
|
slouken@653
|
45 |
#include "SDL_error.h"
|
slouken@613
|
46 |
|
slouken@613
|
47 |
const char* AudioFilePlayerErrorStr (OSStatus error);
|
slouken@613
|
48 |
|
icculus@1143
|
49 |
/*
|
slouken@613
|
50 |
void ThrowResult (OSStatus result, const char *str);
|
slouken@613
|
51 |
|
slouken@613
|
52 |
#define THROW_RESULT(str) \
|
slouken@613
|
53 |
if (result) { \
|
slouken@613
|
54 |
ThrowResult (result, str); \
|
slouken@613
|
55 |
}
|
icculus@1143
|
56 |
*/
|
slouken@613
|
57 |
|
slouken@613
|
58 |
typedef void (*AudioFilePlayNotifier)(void *inRefCon,
|
slouken@613
|
59 |
OSStatus inStatus);
|
slouken@613
|
60 |
|
slouken@613
|
61 |
enum {
|
slouken@613
|
62 |
kAudioFilePlayErr_FilePlayUnderrun = -10000,
|
slouken@613
|
63 |
kAudioFilePlay_FileIsFinished = -10001,
|
slouken@613
|
64 |
kAudioFilePlay_PlayerIsUninitialized = -10002
|
slouken@613
|
65 |
};
|
slouken@613
|
66 |
|
slouken@613
|
67 |
|
icculus@1143
|
68 |
struct S_AudioFileManager;
|
slouken@613
|
69 |
|
slouken@613
|
70 |
#pragma mark __________ AudioFilePlayer
|
icculus@1143
|
71 |
typedef struct S_AudioFilePlayer
|
slouken@613
|
72 |
{
|
slouken@1487
|
73 |
/*public:*/
|
icculus@1143
|
74 |
int (*SetDestination)(struct S_AudioFilePlayer *afp, AudioUnit *inDestUnit);
|
icculus@1143
|
75 |
void (*SetNotifier)(struct S_AudioFilePlayer *afp, AudioFilePlayNotifier inNotifier, void *inRefCon);
|
slouken@1487
|
76 |
void (*SetStartFrame)(struct S_AudioFilePlayer *afp, int frame); /* seek in the file */
|
slouken@1487
|
77 |
int (*GetCurrentFrame)(struct S_AudioFilePlayer *afp); /* get the current frame position */
|
slouken@1487
|
78 |
void (*SetStopFrame)(struct S_AudioFilePlayer *afp, int frame); /* set limit in the file */
|
icculus@1143
|
79 |
int (*Connect)(struct S_AudioFilePlayer *afp);
|
icculus@1143
|
80 |
void (*Disconnect)(struct S_AudioFilePlayer *afp);
|
icculus@1143
|
81 |
void (*DoNotification)(struct S_AudioFilePlayer *afp, OSStatus inError);
|
icculus@1143
|
82 |
int (*IsConnected)(struct S_AudioFilePlayer *afp);
|
icculus@1143
|
83 |
AudioUnit (*GetDestUnit)(struct S_AudioFilePlayer *afp);
|
icculus@1143
|
84 |
void (*Print)(struct S_AudioFilePlayer *afp);
|
slouken@613
|
85 |
|
slouken@1487
|
86 |
/*private:*/
|
slouken@613
|
87 |
AudioUnit mPlayUnit;
|
slouken@4368
|
88 |
FSIORefNum mForkRefNum;
|
slouken@4369
|
89 |
|
icculus@4190
|
90 |
AURenderCallbackStruct mInputCallback;
|
slouken@613
|
91 |
|
slouken@613
|
92 |
AudioStreamBasicDescription mFileDescription;
|
slouken@613
|
93 |
|
icculus@1143
|
94 |
int mConnected;
|
slouken@613
|
95 |
|
icculus@1143
|
96 |
struct S_AudioFileManager* mAudioFileManager;
|
slouken@613
|
97 |
|
slouken@613
|
98 |
AudioFilePlayNotifier mNotifier;
|
slouken@613
|
99 |
void* mRefCon;
|
slouken@613
|
100 |
|
slouken@613
|
101 |
int mStartFrame;
|
slouken@613
|
102 |
|
slouken@613
|
103 |
#pragma mark __________ Private_Methods
|
slouken@613
|
104 |
|
icculus@1143
|
105 |
int (*OpenFile)(struct S_AudioFilePlayer *afp, const FSRef *inRef, SInt64 *outFileSize);
|
icculus@1143
|
106 |
} AudioFilePlayer;
|
icculus@1143
|
107 |
|
icculus@1143
|
108 |
|
icculus@1143
|
109 |
AudioFilePlayer *new_AudioFilePlayer(const FSRef *inFileRef);
|
icculus@1143
|
110 |
void delete_AudioFilePlayer(AudioFilePlayer *afp);
|
icculus@1143
|
111 |
|
icculus@1143
|
112 |
|
slouken@613
|
113 |
|
slouken@613
|
114 |
#pragma mark __________ AudioFileManager
|
icculus@1143
|
115 |
typedef struct S_AudioFileManager
|
slouken@613
|
116 |
{
|
slouken@1487
|
117 |
/*public:*/
|
slouken@1487
|
118 |
/* this method should NOT be called by an object of this class
|
slouken@1487
|
119 |
as it is called by the parent's Disconnect() method */
|
icculus@1143
|
120 |
void (*Disconnect)(struct S_AudioFileManager *afm);
|
icculus@1143
|
121 |
int (*DoConnect)(struct S_AudioFileManager *afm);
|
icculus@4190
|
122 |
OSStatus (*Read)(struct S_AudioFileManager *afm, char *buffer, ByteCount *len);
|
icculus@1143
|
123 |
const char* (*GetFileBuffer)(struct S_AudioFileManager *afm);
|
icculus@1143
|
124 |
const AudioFilePlayer *(*GetParent)(struct S_AudioFileManager *afm);
|
slouken@1487
|
125 |
void (*SetPosition)(struct S_AudioFileManager *afm, SInt64 pos); /* seek/rewind in the file */
|
slouken@1487
|
126 |
int (*GetByteCounter)(struct S_AudioFileManager *afm); /* return actual bytes streamed to audio hardware */
|
slouken@1487
|
127 |
void (*SetEndOfFile)(struct S_AudioFileManager *afm, SInt64 pos); /* set the "EOF" (will behave just like it reached eof) */
|
slouken@613
|
128 |
|
slouken@1487
|
129 |
/*protected:*/
|
icculus@1143
|
130 |
AudioFilePlayer* mParent;
|
slouken@768
|
131 |
SInt16 mForkRefNum;
|
slouken@768
|
132 |
SInt64 mAudioDataOffset;
|
slouken@613
|
133 |
|
slouken@768
|
134 |
char* mFileBuffer;
|
slouken@768
|
135 |
|
slouken@768
|
136 |
int mByteCounter;
|
slouken@613
|
137 |
|
icculus@1143
|
138 |
int mReadFromFirstBuffer;
|
icculus@1143
|
139 |
int mLockUnsuccessful;
|
icculus@1143
|
140 |
int mIsEngaged;
|
slouken@768
|
141 |
|
slouken@768
|
142 |
int mNumTimesAskedSinceFinished;
|
slouken@613
|
143 |
|
slouken@935
|
144 |
|
slouken@935
|
145 |
void* mTmpBuffer;
|
slouken@935
|
146 |
UInt32 mBufferSize;
|
slouken@935
|
147 |
UInt32 mBufferOffset;
|
slouken@1487
|
148 |
/*public:*/
|
icculus@1143
|
149 |
UInt32 mChunkSize;
|
slouken@768
|
150 |
SInt64 mFileLength;
|
slouken@768
|
151 |
SInt64 mReadFilePosition;
|
icculus@1143
|
152 |
int mWriteToFirstBuffer;
|
icculus@1143
|
153 |
int mFinishedReadingData;
|
icculus@1143
|
154 |
|
slouken@1487
|
155 |
/*protected:*/
|
icculus@4190
|
156 |
OSStatus (*Render)(struct S_AudioFileManager *afm, AudioBufferList *ioData);
|
icculus@1143
|
157 |
OSStatus (*GetFileData)(struct S_AudioFileManager *afm, void** inOutData, UInt32 *inOutDataSize);
|
icculus@1143
|
158 |
void (*AfterRender)(struct S_AudioFileManager *afm);
|
slouken@768
|
159 |
|
slouken@1487
|
160 |
/*public:*/
|
slouken@1487
|
161 |
/*static*/
|
icculus@4190
|
162 |
OSStatus (*FileInputProc)(void *inRefCon,
|
icculus@4190
|
163 |
AudioUnitRenderActionFlags *ioActionFlags,
|
icculus@1143
|
164 |
const AudioTimeStamp *inTimeStamp,
|
icculus@1143
|
165 |
UInt32 inBusNumber,
|
icculus@4190
|
166 |
UInt32 inNumberFrames,
|
icculus@4190
|
167 |
AudioBufferList *ioData);
|
icculus@1143
|
168 |
} AudioFileManager;
|
slouken@613
|
169 |
|
slouken@613
|
170 |
|
icculus@1143
|
171 |
AudioFileManager *new_AudioFileManager (AudioFilePlayer *inParent,
|
icculus@1143
|
172 |
SInt16 inForkRefNum,
|
icculus@1143
|
173 |
SInt64 inFileLength,
|
icculus@1143
|
174 |
UInt32 inChunkSize);
|
icculus@1143
|
175 |
|
icculus@1143
|
176 |
void delete_AudioFileManager(AudioFileManager *afm);
|
icculus@1143
|
177 |
|
slouken@613
|
178 |
#endif
|
icculus@1143
|
179 |
|