Mercurial > sdl-ios-xcode
annotate src/cdrom/macosx/AudioFilePlayer.c @ 2735:204be4fc2726
Final merge of Google Summer of Code 2008 work...
Port SDL 1.3 to the Nintendo DS
by Darren Alton, mentored by Sam Lantinga
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Wed, 27 Aug 2008 15:10:03 +0000 |
parents | c121d94672cb |
children | 99210400e8b9 |
rev | line source |
---|---|
1143
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
1 /* |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
2 SDL - Simple DirectMedia Layer |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
3 Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002 Sam Lantinga |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
4 |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
5 This library is free software; you can redistribute it and/or |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
6 modify it under the terms of the GNU Library General Public |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
7 License as published by the Free Software Foundation; either |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
8 version 2 of the License, or (at your option) any later version. |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
9 |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
10 This library is distributed in the hope that it will be useful, |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
11 but WITHOUT ANY WARRANTY; without even the implied warranty of |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
13 Library General Public License for more details. |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
14 |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
15 You should have received a copy of the GNU Library General Public |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
16 License along with this library; if not, write to the Free |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
18 |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
19 Sam Lantinga |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
20 slouken@libsdl.org |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
21 |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
22 This file based on Apple sample code. We haven't changed the file name, |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
23 so if you want to see the original search for it on apple.com/developer |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
24 */ |
1402
d910939febfa
Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents:
1336
diff
changeset
|
25 #include "SDL_config.h" |
1143
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
26 |
1487
dc6b59e925a2
Cleaning up warnings on MacOS X
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
27 /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
dc6b59e925a2
Cleaning up warnings on MacOS X
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
28 AudioFilePlayer.cpp |
dc6b59e925a2
Cleaning up warnings on MacOS X
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
29 */ |
1143
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
30 #include "AudioFilePlayer.h" |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
31 |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
32 /* |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
33 void ThrowResult (OSStatus result, const char* str) |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
34 { |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
35 SDL_SetError ("Error: %s %d", str, result); |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
36 throw result; |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
37 } |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
38 */ |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
39 |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
40 #if DEBUG |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1793
diff
changeset
|
41 static void |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1793
diff
changeset
|
42 PrintStreamDesc(AudioStreamBasicDescription * inDesc) |
1143
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
43 { |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
44 if (!inDesc) { |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1793
diff
changeset
|
45 printf("Can't print a NULL desc!\n"); |
1143
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
46 return; |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
47 } |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1793
diff
changeset
|
48 |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1793
diff
changeset
|
49 printf("- - - - - - - - - - - - - - - - - - - -\n"); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1793
diff
changeset
|
50 printf(" Sample Rate:%f\n", inDesc->mSampleRate); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1793
diff
changeset
|
51 printf(" Format ID:%s\n", (char *) &inDesc->mFormatID); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1793
diff
changeset
|
52 printf(" Format Flags:%lX\n", inDesc->mFormatFlags); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1793
diff
changeset
|
53 printf(" Bytes per Packet:%ld\n", inDesc->mBytesPerPacket); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1793
diff
changeset
|
54 printf(" Frames per Packet:%ld\n", inDesc->mFramesPerPacket); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1793
diff
changeset
|
55 printf(" Bytes per Frame:%ld\n", inDesc->mBytesPerFrame); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1793
diff
changeset
|
56 printf(" Channels per Frame:%ld\n", inDesc->mChannelsPerFrame); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1793
diff
changeset
|
57 printf(" Bits per Channel:%ld\n", inDesc->mBitsPerChannel); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1793
diff
changeset
|
58 printf("- - - - - - - - - - - - - - - - - - - -\n"); |
1143
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
59 } |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
60 #endif |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
61 |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
62 |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1793
diff
changeset
|
63 static int |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1793
diff
changeset
|
64 AudioFilePlayer_SetDestination(AudioFilePlayer * afp, AudioUnit * inDestUnit) |
1143
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
65 { |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1793
diff
changeset
|
66 /*if (afp->mConnected) throw static_cast<OSStatus>(-1); *//* can't set dest if already engaged */ |
1143
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
67 if (afp->mConnected) |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1793
diff
changeset
|
68 return 0; |
1143
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
69 |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1793
diff
changeset
|
70 SDL_memcpy(&afp->mPlayUnit, inDestUnit, sizeof(afp->mPlayUnit)); |
1143
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
71 |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
72 OSStatus result = noErr; |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1793
diff
changeset
|
73 |
1143
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
74 |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1793
diff
changeset
|
75 /* we can "down" cast a component instance to a component */ |
1143
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
76 ComponentDescription desc; |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1793
diff
changeset
|
77 result = GetComponentInfo((Component) * inDestUnit, &desc, 0, 0, 0); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1793
diff
changeset
|
78 if (result) |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1793
diff
changeset
|
79 return 0; /*THROW_RESULT("GetComponentInfo") */ |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1793
diff
changeset
|
80 |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1793
diff
changeset
|
81 /* we're going to use this to know which convert routine to call |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1793
diff
changeset
|
82 a v1 audio unit will have a type of 'aunt' |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1793
diff
changeset
|
83 a v2 audio unit will have one of several different types. */ |
1143
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
84 if (desc.componentType != kAudioUnitComponentType) { |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
85 result = badComponentInstance; |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1793
diff
changeset
|
86 /*THROW_RESULT("BAD COMPONENT") */ |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1793
diff
changeset
|
87 if (result) |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1793
diff
changeset
|
88 return 0; |
1143
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
89 } |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
90 |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
91 /* Set the input format of the audio unit. */ |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1793
diff
changeset
|
92 result = AudioUnitSetProperty(*inDestUnit, |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1793
diff
changeset
|
93 kAudioUnitProperty_StreamFormat, |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1793
diff
changeset
|
94 kAudioUnitScope_Input, |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1793
diff
changeset
|
95 0, |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1793
diff
changeset
|
96 &afp->mFileDescription, |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1793
diff
changeset
|
97 sizeof(afp->mFileDescription)); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1793
diff
changeset
|
98 /*THROW_RESULT("AudioUnitSetProperty") */ |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1793
diff
changeset
|
99 if (result) |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1793
diff
changeset
|
100 return 0; |
1143
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
101 return 1; |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
102 } |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
103 |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1793
diff
changeset
|
104 static void |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1793
diff
changeset
|
105 AudioFilePlayer_SetNotifier(AudioFilePlayer * afp, |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1793
diff
changeset
|
106 AudioFilePlayNotifier inNotifier, void *inRefCon) |
1143
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
107 { |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
108 afp->mNotifier = inNotifier; |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
109 afp->mRefCon = inRefCon; |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
110 } |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
111 |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1793
diff
changeset
|
112 static int |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1793
diff
changeset
|
113 AudioFilePlayer_IsConnected(AudioFilePlayer * afp) |
1143
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
114 { |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
115 return afp->mConnected; |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
116 } |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
117 |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1793
diff
changeset
|
118 static AudioUnit |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1793
diff
changeset
|
119 AudioFilePlayer_GetDestUnit(AudioFilePlayer * afp) |
1143
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
120 { |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1793
diff
changeset
|
121 return afp->mPlayUnit; |
1143
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
122 } |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
123 |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1793
diff
changeset
|
124 static void |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1793
diff
changeset
|
125 AudioFilePlayer_Print(AudioFilePlayer * afp) |
1143
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
126 { |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1793
diff
changeset
|
127 #if DEBUG |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1793
diff
changeset
|
128 printf("Is Connected:%s\n", (IsConnected()? "true" : "false")); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1793
diff
changeset
|
129 printf("- - - - - - - - - - - - - - \n"); |
1143
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
130 #endif |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
131 } |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
132 |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1793
diff
changeset
|
133 static void |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1793
diff
changeset
|
134 AudioFilePlayer_SetStartFrame(AudioFilePlayer * afp, int frame) |
1143
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
135 { |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
136 SInt64 position = frame * 2352; |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
137 |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
138 afp->mStartFrame = frame; |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1793
diff
changeset
|
139 afp->mAudioFileManager->SetPosition(afp->mAudioFileManager, position); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1793
diff
changeset
|
140 } |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1793
diff
changeset
|
141 |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1793
diff
changeset
|
142 |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1793
diff
changeset
|
143 static int |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1793
diff
changeset
|
144 AudioFilePlayer_GetCurrentFrame(AudioFilePlayer * afp) |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1793
diff
changeset
|
145 { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1793
diff
changeset
|
146 return afp->mStartFrame + |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1793
diff
changeset
|
147 (afp->mAudioFileManager->GetByteCounter(afp->mAudioFileManager) / |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1793
diff
changeset
|
148 2352); |
1143
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
149 } |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
150 |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1793
diff
changeset
|
151 static void |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1793
diff
changeset
|
152 AudioFilePlayer_SetStopFrame(AudioFilePlayer * afp, int frame) |
1143
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
153 { |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1793
diff
changeset
|
154 SInt64 position = frame * 2352; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1793
diff
changeset
|
155 |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1793
diff
changeset
|
156 afp->mAudioFileManager->SetEndOfFile(afp->mAudioFileManager, position); |
1143
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
157 } |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1793
diff
changeset
|
158 |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1793
diff
changeset
|
159 void |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1793
diff
changeset
|
160 delete_AudioFilePlayer(AudioFilePlayer * afp) |
1143
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
161 { |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1793
diff
changeset
|
162 if (afp != NULL) { |
1143
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
163 afp->Disconnect(afp); |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1793
diff
changeset
|
164 |
1143
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
165 if (afp->mAudioFileManager) { |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
166 delete_AudioFileManager(afp->mAudioFileManager); |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
167 afp->mAudioFileManager = 0; |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
168 } |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1793
diff
changeset
|
169 |
1143
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
170 if (afp->mForkRefNum) { |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1793
diff
changeset
|
171 FSCloseFork(afp->mForkRefNum); |
1143
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
172 afp->mForkRefNum = 0; |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
173 } |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1143
diff
changeset
|
174 SDL_free(afp); |
1143
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
175 } |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
176 } |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
177 |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1793
diff
changeset
|
178 static int |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1793
diff
changeset
|
179 AudioFilePlayer_Connect(AudioFilePlayer * afp) |
1143
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
180 { |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
181 #if DEBUG |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1793
diff
changeset
|
182 printf("Connect:%x, engaged=%d\n", (int) afp->mPlayUnit, |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1793
diff
changeset
|
183 (afp->mConnected ? 1 : 0)); |
1143
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
184 #endif |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1793
diff
changeset
|
185 if (!afp->mConnected) { |
1143
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
186 if (!afp->mAudioFileManager->DoConnect(afp->mAudioFileManager)) |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
187 return 0; |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
188 |
1487
dc6b59e925a2
Cleaning up warnings on MacOS X
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
189 /* set the render callback for the file data to be supplied to the sound converter AU */ |
1143
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
190 afp->mInputCallback.inputProc = afp->mAudioFileManager->FileInputProc; |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
191 afp->mInputCallback.inputProcRefCon = afp->mAudioFileManager; |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
192 |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1793
diff
changeset
|
193 OSStatus result = AudioUnitSetProperty(afp->mPlayUnit, |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1793
diff
changeset
|
194 kAudioUnitProperty_SetInputCallback, |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1793
diff
changeset
|
195 kAudioUnitScope_Input, |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1793
diff
changeset
|
196 0, |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1793
diff
changeset
|
197 &afp->mInputCallback, |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1793
diff
changeset
|
198 sizeof(afp->mInputCallback)); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1793
diff
changeset
|
199 if (result) |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1793
diff
changeset
|
200 return 0; /*THROW_RESULT("AudioUnitSetProperty") */ |
1143
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
201 afp->mConnected = 1; |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
202 } |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
203 |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
204 return 1; |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
205 } |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
206 |
1487
dc6b59e925a2
Cleaning up warnings on MacOS X
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
207 /* warning noted, now please go away ;-) */ |
dc6b59e925a2
Cleaning up warnings on MacOS X
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
208 /* #warning This should redirect the calling of notification code to some other thread */ |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1793
diff
changeset
|
209 static void |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1793
diff
changeset
|
210 AudioFilePlayer_DoNotification(AudioFilePlayer * afp, OSStatus inStatus) |
1143
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
211 { |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
212 if (afp->mNotifier) { |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
213 (*afp->mNotifier) (afp->mRefCon, inStatus); |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
214 } else { |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1793
diff
changeset
|
215 SDL_SetError("Notification posted with no notifier in place"); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1793
diff
changeset
|
216 |
1143
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
217 if (inStatus == kAudioFilePlay_FileIsFinished) |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
218 afp->Disconnect(afp); |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
219 else if (inStatus != kAudioFilePlayErr_FilePlayUnderrun) |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
220 afp->Disconnect(afp); |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
221 } |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
222 } |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
223 |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1793
diff
changeset
|
224 static void |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1793
diff
changeset
|
225 AudioFilePlayer_Disconnect(AudioFilePlayer * afp) |
1143
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
226 { |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
227 #if DEBUG |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1793
diff
changeset
|
228 printf("Disconnect:%x,%ld, engaged=%d\n", (int) afp->mPlayUnit, 0, |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1793
diff
changeset
|
229 (afp->mConnected ? 1 : 0)); |
1143
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
230 #endif |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1793
diff
changeset
|
231 if (afp->mConnected) { |
1143
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
232 afp->mConnected = 0; |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1793
diff
changeset
|
233 |
1143
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
234 afp->mInputCallback.inputProc = 0; |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
235 afp->mInputCallback.inputProcRefCon = 0; |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1793
diff
changeset
|
236 OSStatus result = AudioUnitSetProperty(afp->mPlayUnit, |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1793
diff
changeset
|
237 kAudioUnitProperty_SetInputCallback, |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1793
diff
changeset
|
238 kAudioUnitScope_Input, |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1793
diff
changeset
|
239 0, |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1793
diff
changeset
|
240 &afp->mInputCallback, |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1793
diff
changeset
|
241 sizeof(afp->mInputCallback)); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1793
diff
changeset
|
242 if (result) |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1793
diff
changeset
|
243 SDL_SetError("AudioUnitSetProperty:RemoveInputCallback:%ld", |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1793
diff
changeset
|
244 result); |
1143
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
245 |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
246 afp->mAudioFileManager->Disconnect(afp->mAudioFileManager); |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
247 } |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
248 } |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
249 |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1793
diff
changeset
|
250 typedef struct |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1793
diff
changeset
|
251 { |
1143
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
252 UInt32 offset; |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
253 UInt32 blockSize; |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
254 } SSNDData; |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
255 |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1793
diff
changeset
|
256 static int |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1793
diff
changeset
|
257 AudioFilePlayer_OpenFile(AudioFilePlayer * afp, const FSRef * inRef, |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1793
diff
changeset
|
258 SInt64 * outFileDataSize) |
1143
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
259 { |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
260 ContainerChunk chunkHeader; |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
261 ChunkHeader chunk; |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
262 SSNDData ssndData; |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
263 |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
264 OSErr result; |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
265 HFSUniStr255 dfName; |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
266 ByteCount actual; |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
267 SInt64 offset; |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
268 |
1487
dc6b59e925a2
Cleaning up warnings on MacOS X
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
269 /* Open the data fork of the input file */ |
1143
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
270 result = FSGetDataForkName(&dfName); |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1793
diff
changeset
|
271 if (result) |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1793
diff
changeset
|
272 return 0; /*THROW_RESULT("AudioFilePlayer::OpenFile(): FSGetDataForkName") */ |
1143
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
273 |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1793
diff
changeset
|
274 result = |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1793
diff
changeset
|
275 FSOpenFork(inRef, dfName.length, dfName.unicode, fsRdPerm, |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1793
diff
changeset
|
276 &afp->mForkRefNum); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1793
diff
changeset
|
277 if (result) |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1793
diff
changeset
|
278 return 0; /*THROW_RESULT("AudioFilePlayer::OpenFile(): FSOpenFork") */ |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1793
diff
changeset
|
279 |
1487
dc6b59e925a2
Cleaning up warnings on MacOS X
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
280 /* Read the file header, and check if it's indeed an AIFC file */ |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1793
diff
changeset
|
281 result = |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1793
diff
changeset
|
282 FSReadFork(afp->mForkRefNum, fsAtMark, 0, sizeof(chunkHeader), |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1793
diff
changeset
|
283 &chunkHeader, &actual); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1793
diff
changeset
|
284 if (result) |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1793
diff
changeset
|
285 return 0; /*THROW_RESULT("AudioFilePlayer::OpenFile(): FSReadFork") */ |
1143
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
286 |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
287 if (chunkHeader.ckID != 'FORM') { |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
288 result = -1; |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1793
diff
changeset
|
289 if (result) |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1793
diff
changeset
|
290 return 0; /*THROW_RESULT("AudioFilePlayer::OpenFile(): chunk id is not 'FORM'"); */ |
1143
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
291 } |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
292 |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
293 if (chunkHeader.formType != 'AIFC') { |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
294 result = -1; |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1793
diff
changeset
|
295 if (result) |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1793
diff
changeset
|
296 return 0; /*THROW_RESULT("AudioFilePlayer::OpenFile(): file format is not 'AIFC'"); */ |
1143
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
297 } |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
298 |
1487
dc6b59e925a2
Cleaning up warnings on MacOS X
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
299 /* Search for the SSND chunk. We ignore all compression etc. information |
dc6b59e925a2
Cleaning up warnings on MacOS X
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
300 in other chunks. Of course that is kind of evil, but for now we are lazy |
dc6b59e925a2
Cleaning up warnings on MacOS X
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
301 and rely on the cdfs to always give us the same fixed format. |
dc6b59e925a2
Cleaning up warnings on MacOS X
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
302 TODO: Parse the COMM chunk we currently skip to fill in mFileDescription. |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1793
diff
changeset
|
303 */ |
1143
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
304 offset = 0; |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
305 do { |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1793
diff
changeset
|
306 result = |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1793
diff
changeset
|
307 FSReadFork(afp->mForkRefNum, fsFromMark, offset, |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1793
diff
changeset
|
308 sizeof(chunk), &chunk, &actual); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1793
diff
changeset
|
309 if (result) |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1793
diff
changeset
|
310 return 0; /*THROW_RESULT("AudioFilePlayer::OpenFile(): FSReadFork") */ |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1793
diff
changeset
|
311 |
1487
dc6b59e925a2
Cleaning up warnings on MacOS X
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
312 /* Skip the chunk data */ |
1143
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
313 offset = chunk.ckSize; |
2735
204be4fc2726
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
1895
diff
changeset
|
314 } while (chunk.ckID != 'SSND'); |
1143
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
315 |
1487
dc6b59e925a2
Cleaning up warnings on MacOS X
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
316 /* Read the header of the SSND chunk. After this, we are positioned right |
dc6b59e925a2
Cleaning up warnings on MacOS X
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
317 at the start of the audio data. */ |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1793
diff
changeset
|
318 result = |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1793
diff
changeset
|
319 FSReadFork(afp->mForkRefNum, fsAtMark, 0, sizeof(ssndData), |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1793
diff
changeset
|
320 &ssndData, &actual); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1793
diff
changeset
|
321 if (result) |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1793
diff
changeset
|
322 return 0; /*THROW_RESULT("AudioFilePlayer::OpenFile(): FSReadFork") */ |
1143
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
323 |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
324 result = FSSetForkPosition(afp->mForkRefNum, fsFromMark, ssndData.offset); |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1793
diff
changeset
|
325 if (result) |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1793
diff
changeset
|
326 return 0; /*THROW_RESULT("AudioFilePlayer::OpenFile(): FSSetForkPosition") */ |
1143
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
327 |
1487
dc6b59e925a2
Cleaning up warnings on MacOS X
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
328 /* Data size */ |
1143
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
329 *outFileDataSize = chunk.ckSize - ssndData.offset - 8; |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
330 |
1487
dc6b59e925a2
Cleaning up warnings on MacOS X
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
331 /* File format */ |
1143
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
332 afp->mFileDescription.mSampleRate = 44100; |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
333 afp->mFileDescription.mFormatID = kAudioFormatLinearPCM; |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1793
diff
changeset
|
334 afp->mFileDescription.mFormatFlags = |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1793
diff
changeset
|
335 kLinearPCMFormatFlagIsPacked | kLinearPCMFormatFlagIsSignedInteger; |
1143
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
336 afp->mFileDescription.mBytesPerPacket = 4; |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
337 afp->mFileDescription.mFramesPerPacket = 1; |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
338 afp->mFileDescription.mBytesPerFrame = 4; |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
339 afp->mFileDescription.mChannelsPerFrame = 2; |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
340 afp->mFileDescription.mBitsPerChannel = 16; |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
341 |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
342 return 1; |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
343 } |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
344 |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1793
diff
changeset
|
345 AudioFilePlayer * |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1793
diff
changeset
|
346 new_AudioFilePlayer(const FSRef * inFileRef) |
1143
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
347 { |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1793
diff
changeset
|
348 SInt64 fileDataSize = 0; |
1143
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
349 |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1793
diff
changeset
|
350 AudioFilePlayer *afp = |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1793
diff
changeset
|
351 (AudioFilePlayer *) SDL_malloc(sizeof(AudioFilePlayer)); |
1143
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
352 if (afp == NULL) |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
353 return NULL; |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1793
diff
changeset
|
354 SDL_memset(afp, '\0', sizeof(*afp)); |
1143
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
355 |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1793
diff
changeset
|
356 #define SET_AUDIOFILEPLAYER_METHOD(m) afp->m = AudioFilePlayer_##m |
1143
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
357 SET_AUDIOFILEPLAYER_METHOD(SetDestination); |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
358 SET_AUDIOFILEPLAYER_METHOD(SetNotifier); |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
359 SET_AUDIOFILEPLAYER_METHOD(SetStartFrame); |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
360 SET_AUDIOFILEPLAYER_METHOD(GetCurrentFrame); |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
361 SET_AUDIOFILEPLAYER_METHOD(SetStopFrame); |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
362 SET_AUDIOFILEPLAYER_METHOD(Connect); |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
363 SET_AUDIOFILEPLAYER_METHOD(Disconnect); |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
364 SET_AUDIOFILEPLAYER_METHOD(DoNotification); |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
365 SET_AUDIOFILEPLAYER_METHOD(IsConnected); |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
366 SET_AUDIOFILEPLAYER_METHOD(GetDestUnit); |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
367 SET_AUDIOFILEPLAYER_METHOD(Print); |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
368 SET_AUDIOFILEPLAYER_METHOD(OpenFile); |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1793
diff
changeset
|
369 #undef SET_AUDIOFILEPLAYER_METHOD |
1143
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
370 |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1793
diff
changeset
|
371 if (!afp->OpenFile(afp, inFileRef, &fileDataSize)) { |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1143
diff
changeset
|
372 SDL_free(afp); |
1143
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
373 return NULL; |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
374 } |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1793
diff
changeset
|
375 |
1487
dc6b59e925a2
Cleaning up warnings on MacOS X
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
376 /* we want about 4 seconds worth of data for the buffer */ |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1793
diff
changeset
|
377 int bytesPerSecond = |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1793
diff
changeset
|
378 (UInt32) (4 * afp->mFileDescription.mSampleRate * |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1793
diff
changeset
|
379 afp->mFileDescription.mBytesPerFrame); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1793
diff
changeset
|
380 |
1143
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
381 #if DEBUG |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
382 printf("File format:\n"); |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1793
diff
changeset
|
383 PrintStreamDesc(&afp->mFileDescription); |
1143
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
384 #endif |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1793
diff
changeset
|
385 |
1143
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
386 afp->mAudioFileManager = new_AudioFileManager(afp, afp->mForkRefNum, |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
387 fileDataSize, |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
388 bytesPerSecond); |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1793
diff
changeset
|
389 if (afp->mAudioFileManager == NULL) { |
1143
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
390 delete_AudioFilePlayer(afp); |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
391 return NULL; |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
392 } |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
393 |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
394 return afp; |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
395 } |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
396 |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1793
diff
changeset
|
397 /* vi: set ts=4 sw=4 expandtab: */ |