Mercurial > sdl-ios-xcode
comparison src/cdrom/macosx/AudioFilePlayer.h @ 935:f8d5ddc7aef1
Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Sat, 21 Aug 2004 02:06:30 +0000 |
parents | b8d311d90021 |
children | 71a2648acc75 |
comparison
equal
deleted
inserted
replaced
934:af585d6efec8 | 935:f8d5ddc7aef1 |
---|---|
29 #ifndef __AudioFilePlayer_H__ | 29 #ifndef __AudioFilePlayer_H__ |
30 #define __AudioFilePlayer_H__ | 30 #define __AudioFilePlayer_H__ |
31 | 31 |
32 #include <CoreServices/CoreServices.h> | 32 #include <CoreServices/CoreServices.h> |
33 | 33 |
34 #include <AudioToolbox/AudioConverter.h> | |
35 #include <AudioUnit/AudioUnit.h> | 34 #include <AudioUnit/AudioUnit.h> |
36 | 35 |
37 #include "SDL_error.h" | 36 #include "SDL_error.h" |
38 | 37 |
39 const char* AudioFilePlayerErrorStr (OSStatus error); | 38 const char* AudioFilePlayerErrorStr (OSStatus error); |
63 public: | 62 public: |
64 AudioFilePlayer (const FSRef *inFileRef); | 63 AudioFilePlayer (const FSRef *inFileRef); |
65 | 64 |
66 ~AudioFilePlayer(); | 65 ~AudioFilePlayer(); |
67 | 66 |
68 void SetDestination (AudioUnit &inDestUnit, | 67 void SetDestination (AudioUnit &inDestUnit); |
69 int inBusNumber); | |
70 | 68 |
71 void SetNotifier (AudioFilePlayNotifier inNotifier, void *inRefCon) | 69 void SetNotifier (AudioFilePlayNotifier inNotifier, void *inRefCon) |
72 { | 70 { |
73 mNotifier = inNotifier; | 71 mNotifier = inNotifier; |
74 mRefCon = inRefCon; | 72 mRefCon = inRefCon; |
86 | 84 |
87 void DoNotification (OSStatus inError) const; | 85 void DoNotification (OSStatus inError) const; |
88 | 86 |
89 bool IsConnected () const { return mConnected; } | 87 bool IsConnected () const { return mConnected; } |
90 | 88 |
91 UInt32 GetBusNumber () const { return mBusNumber; } | |
92 | |
93 AudioUnit GetDestUnit () const { return mPlayUnit; } | 89 AudioUnit GetDestUnit () const { return mPlayUnit; } |
94 | 90 |
95 AudioConverterRef GetAudioConverter() const { return mConverter; } | |
96 | |
97 #if DEBUG | 91 #if DEBUG |
98 void Print() const | 92 void Print() const |
99 { | 93 { |
100 printf ("Destination Bus:%ld\n", GetBusNumber()); | |
101 printf ("Is Connected:%s\n", (IsConnected() ? "true" : "false")); | 94 printf ("Is Connected:%s\n", (IsConnected() ? "true" : "false")); |
102 printf ("- - - - - - - - - - - - - - \n"); | 95 printf ("- - - - - - - - - - - - - - \n"); |
103 } | 96 } |
104 #endif | 97 #endif |
105 | |
106 const AudioStreamBasicDescription& GetFileFormat() const { return mFileDescription; } | |
107 | 98 |
108 private: | 99 private: |
109 AudioUnit mPlayUnit; | 100 AudioUnit mPlayUnit; |
110 UInt32 mBusNumber; | |
111 SInt16 mForkRefNum; | 101 SInt16 mForkRefNum; |
112 | 102 |
113 AudioUnitInputCallback mInputCallback; | 103 AudioUnitInputCallback mInputCallback; |
114 | 104 |
115 AudioStreamBasicDescription mFileDescription; | 105 AudioStreamBasicDescription mFileDescription; |
116 | 106 |
117 bool mConnected; | 107 bool mConnected; |
118 | 108 |
119 AudioFileManager* mAudioFileManager; | 109 AudioFileManager* mAudioFileManager; |
120 AudioConverterRef mConverter; | |
121 | 110 |
122 AudioFilePlayNotifier mNotifier; | 111 AudioFilePlayNotifier mNotifier; |
123 void* mRefCon; | 112 void* mRefCon; |
124 | 113 |
125 int mStartFrame; | 114 int mStartFrame; |
139 UInt32 inChunkSize); | 128 UInt32 inChunkSize); |
140 | 129 |
141 ~AudioFileManager(); | 130 ~AudioFileManager(); |
142 | 131 |
143 | 132 |
144 void Connect (AudioConverterRef inConverter) | |
145 { | |
146 mParentConverter = inConverter; | |
147 DoConnect(); | |
148 } | |
149 | |
150 // this method should NOT be called by an object of this class | 133 // this method should NOT be called by an object of this class |
151 // as it is called by the parent's Disconnect() method | 134 // as it is called by the parent's Disconnect() method |
152 void Disconnect (); | 135 void Disconnect (); |
136 | |
137 void DoConnect (); | |
153 | 138 |
154 OSStatus Read(char *buffer, UInt32 *len); | 139 OSStatus Read(char *buffer, UInt32 *len); |
155 | 140 |
156 const char* GetFileBuffer () { return mFileBuffer; } | 141 const char* GetFileBuffer () { return mFileBuffer; } |
157 | 142 |
163 | 148 |
164 void SetEndOfFile (SInt64 pos); // set the "EOF" (will behave just like it reached eof) | 149 void SetEndOfFile (SInt64 pos); // set the "EOF" (will behave just like it reached eof) |
165 | 150 |
166 protected: | 151 protected: |
167 AudioFilePlayer& mParent; | 152 AudioFilePlayer& mParent; |
168 AudioConverterRef mParentConverter; | |
169 SInt16 mForkRefNum; | 153 SInt16 mForkRefNum; |
170 SInt64 mAudioDataOffset; | 154 SInt64 mAudioDataOffset; |
171 | 155 |
172 char* mFileBuffer; | 156 char* mFileBuffer; |
173 | 157 |
177 bool mLockUnsuccessful; | 161 bool mLockUnsuccessful; |
178 bool mIsEngaged; | 162 bool mIsEngaged; |
179 | 163 |
180 int mNumTimesAskedSinceFinished; | 164 int mNumTimesAskedSinceFinished; |
181 | 165 |
166 | |
167 void* mTmpBuffer; | |
168 UInt32 mBufferSize; | |
169 UInt32 mBufferOffset; | |
182 public: | 170 public: |
183 const UInt32 mChunkSize; | 171 const UInt32 mChunkSize; |
184 SInt64 mFileLength; | 172 SInt64 mFileLength; |
185 SInt64 mReadFilePosition; | 173 SInt64 mReadFilePosition; |
186 bool mWriteToFirstBuffer; | 174 bool mWriteToFirstBuffer; |
188 | 176 |
189 protected: | 177 protected: |
190 OSStatus Render (AudioBuffer &ioData); | 178 OSStatus Render (AudioBuffer &ioData); |
191 | 179 |
192 OSStatus GetFileData (void** inOutData, UInt32 *inOutDataSize); | 180 OSStatus GetFileData (void** inOutData, UInt32 *inOutDataSize); |
193 | |
194 void DoConnect (); | |
195 | 181 |
196 void AfterRender (); | 182 void AfterRender (); |
197 | 183 |
198 public: | 184 public: |
199 static OSStatus FileInputProc (void *inRefCon, | 185 static OSStatus FileInputProc (void *inRefCon, |
200 AudioUnitRenderActionFlags inActionFlags, | 186 AudioUnitRenderActionFlags inActionFlags, |
201 const AudioTimeStamp *inTimeStamp, | 187 const AudioTimeStamp *inTimeStamp, |
202 UInt32 inBusNumber, | 188 UInt32 inBusNumber, |
203 AudioBuffer *ioData); | 189 AudioBuffer *ioData); |
204 static OSStatus ACInputProc (AudioConverterRef inAudioConverter, | |
205 UInt32* outDataSize, | |
206 void** outData, | |
207 void* inUserData); | |
208 }; | 190 }; |
209 | 191 |
210 | 192 |
211 #endif | 193 #endif |