Mercurial > SDL_sound_CoreAudio
annotate decoders/coreaudio.c @ 581:2264b134b7ac
merged
author | Eric Wing <ewing . public |-at-| gmail . com> |
---|---|
date | Tue, 23 Nov 2010 18:25:44 -0800 |
parents | 33a77ceaed26 6927c489964c |
children |
rev | line source |
---|---|
576
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1 /* |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2 * SDL_sound Core Audio backend |
577
af33b35a55c1
Minor cleanups. Ready to release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
576
diff
changeset
|
3 * Copyright (C) 2010 Eric Wing <ewing . public @ playcontrol.net> |
576
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4 * |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5 * This library is free software; you can redistribute it and/or |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6 * modify it under the terms of the GNU Lesser General Public |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7 * License as published by the Free Software Foundation; either |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
8 * version 2.1 of the License, or (at your option) any later version. |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
9 * |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
10 * This library is distributed in the hope that it will be useful, |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
13 * Lesser General Public License for more details. |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
14 * |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
15 * You should have received a copy of the GNU Lesser General Public |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
16 * License along with this library; if not, write to the Free Software |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
18 */ |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
19 |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
20 #if HAVE_CONFIG_H |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
21 # include <config.h> |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
22 #endif |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
23 |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
24 #ifdef SOUND_SUPPORTS_COREAUDIO |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
25 |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
26 #include <stddef.h> /* NULL */ |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
27 #include <stdio.h> /* printf */ |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
28 #include <arpa/inet.h> /* htonl */ |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
29 #include <AudioToolbox/AudioToolbox.h> |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
30 |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
31 #include "SDL_sound.h" |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
32 |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
33 #define __SDL_SOUND_INTERNAL__ |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
34 #include "SDL_sound_internal.h" |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
35 |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
36 typedef struct CoreAudioFileContainer |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
37 { |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
38 AudioFileID* audioFileID; |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
39 ExtAudioFileRef extAudioFileRef; |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
40 AudioStreamBasicDescription* outputFormat; |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
41 } CoreAudioFileContainer; |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
42 |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
43 static int CoreAudio_init(void); |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
44 static void CoreAudio_quit(void); |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
45 static int CoreAudio_open(Sound_Sample *sample, const char *ext); |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
46 static void CoreAudio_close(Sound_Sample *sample); |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
47 static Uint32 CoreAudio_read(Sound_Sample *sample); |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
48 static int CoreAudio_rewind(Sound_Sample *sample); |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
49 static int CoreAudio_seek(Sound_Sample *sample, Uint32 ms); |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
50 |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
51 static const char *extensions_coreaudio[] = |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
52 { |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
53 "aif", |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
54 "aiff", |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
55 "aifc", |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
56 "wav", |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
57 "wave", |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
58 "mp3", |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
59 "mp4", |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
60 "m4a", |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
61 "aac", |
580
33a77ceaed26
Added more file extension variations for CoreAudio.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
578
diff
changeset
|
62 "adts", |
576
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
63 "caf", |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
64 "Sd2f", |
577
af33b35a55c1
Minor cleanups. Ready to release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
576
diff
changeset
|
65 "Sd2", |
576
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
66 "au", |
580
33a77ceaed26
Added more file extension variations for CoreAudio.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
578
diff
changeset
|
67 "snd", |
576
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
68 "next", |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
69 "mp2", |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
70 "mp1", |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
71 "ac3", |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
72 "3gpp", |
580
33a77ceaed26
Added more file extension variations for CoreAudio.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
578
diff
changeset
|
73 "3gp", |
576
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
74 "3gp2", |
580
33a77ceaed26
Added more file extension variations for CoreAudio.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
578
diff
changeset
|
75 "3g2", |
576
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
76 "amrf", |
577
af33b35a55c1
Minor cleanups. Ready to release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
576
diff
changeset
|
77 "amr", |
af33b35a55c1
Minor cleanups. Ready to release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
576
diff
changeset
|
78 "ima4", |
af33b35a55c1
Minor cleanups. Ready to release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
576
diff
changeset
|
79 "ima", |
576
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
80 NULL |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
81 }; |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
82 const Sound_DecoderFunctions __Sound_DecoderFunctions_CoreAudio = |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
83 { |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
84 { |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
85 extensions_coreaudio, |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
86 "Decode audio through Core Audio through", |
577
af33b35a55c1
Minor cleanups. Ready to release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
576
diff
changeset
|
87 "Eric Wing <ewing . public @ playcontrol.net>", |
576
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
88 "http://playcontrol.net" |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
89 }, |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
90 |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
91 CoreAudio_init, /* init() method */ |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
92 CoreAudio_quit, /* quit() method */ |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
93 CoreAudio_open, /* open() method */ |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
94 CoreAudio_close, /* close() method */ |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
95 CoreAudio_read, /* read() method */ |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
96 CoreAudio_rewind, /* rewind() method */ |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
97 CoreAudio_seek /* seek() method */ |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
98 }; |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
99 |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
100 |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
101 static int CoreAudio_init(void) |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
102 { |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
103 return(1); /* always succeeds. */ |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
104 } /* CoreAudio_init */ |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
105 |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
106 |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
107 static void CoreAudio_quit(void) |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
108 { |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
109 /* it's a no-op. */ |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
110 } /* CoreAudio_quit */ |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
111 |
577
af33b35a55c1
Minor cleanups. Ready to release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
576
diff
changeset
|
112 /* |
af33b35a55c1
Minor cleanups. Ready to release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
576
diff
changeset
|
113 http://developer.apple.com/library/ios/#documentation/MusicAudio/Reference/AudioFileConvertRef/Reference/reference.html |
af33b35a55c1
Minor cleanups. Ready to release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
576
diff
changeset
|
114 kAudioFileAIFFType = 'AIFF', |
af33b35a55c1
Minor cleanups. Ready to release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
576
diff
changeset
|
115 kAudioFileAIFCType = 'AIFC', |
af33b35a55c1
Minor cleanups. Ready to release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
576
diff
changeset
|
116 kAudioFileWAVEType = 'WAVE', |
af33b35a55c1
Minor cleanups. Ready to release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
576
diff
changeset
|
117 kAudioFileSoundDesigner2Type = 'Sd2f', |
af33b35a55c1
Minor cleanups. Ready to release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
576
diff
changeset
|
118 kAudioFileNextType = 'NeXT', |
af33b35a55c1
Minor cleanups. Ready to release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
576
diff
changeset
|
119 kAudioFileMP3Type = 'MPG3', |
af33b35a55c1
Minor cleanups. Ready to release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
576
diff
changeset
|
120 kAudioFileMP2Type = 'MPG2', |
af33b35a55c1
Minor cleanups. Ready to release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
576
diff
changeset
|
121 kAudioFileMP1Type = 'MPG1', |
af33b35a55c1
Minor cleanups. Ready to release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
576
diff
changeset
|
122 kAudioFileAC3Type = 'ac-3', |
af33b35a55c1
Minor cleanups. Ready to release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
576
diff
changeset
|
123 kAudioFileAAC_ADTSType = 'adts', |
af33b35a55c1
Minor cleanups. Ready to release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
576
diff
changeset
|
124 kAudioFileMPEG4Type = 'mp4f', |
af33b35a55c1
Minor cleanups. Ready to release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
576
diff
changeset
|
125 kAudioFileM4AType = 'm4af', |
af33b35a55c1
Minor cleanups. Ready to release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
576
diff
changeset
|
126 kAudioFileCAFType = 'caff', |
af33b35a55c1
Minor cleanups. Ready to release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
576
diff
changeset
|
127 kAudioFile3GPType = '3gpp', |
af33b35a55c1
Minor cleanups. Ready to release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
576
diff
changeset
|
128 kAudioFile3GP2Type = '3gp2', |
af33b35a55c1
Minor cleanups. Ready to release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
576
diff
changeset
|
129 kAudioFileAMRType = 'amrf' |
af33b35a55c1
Minor cleanups. Ready to release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
576
diff
changeset
|
130 */ |
576
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
131 static AudioFileTypeID CoreAudio_GetAudioTypeForExtension(const char* file_extension) |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
132 { |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
133 if( (__Sound_strcasecmp(file_extension, "aif") == 0) |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
134 || (__Sound_strcasecmp(file_extension, "aiff") == 0) |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
135 || (__Sound_strcasecmp(file_extension, "aifc") == 0) |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
136 ) |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
137 { |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
138 return kAudioFileAIFCType; |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
139 } |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
140 else if( (__Sound_strcasecmp(file_extension, "wav") == 0) |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
141 || (__Sound_strcasecmp(file_extension, "wave") == 0) |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
142 ) |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
143 { |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
144 return kAudioFileWAVEType; |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
145 } |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
146 else if( (__Sound_strcasecmp(file_extension, "mp3") == 0) |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
147 ) |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
148 { |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
149 return kAudioFileMP3Type; |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
150 } |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
151 else if( (__Sound_strcasecmp(file_extension, "mp4") == 0) |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
152 ) |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
153 { |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
154 return kAudioFileMPEG4Type; |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
155 } |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
156 else if( (__Sound_strcasecmp(file_extension, "m4a") == 0) |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
157 ) |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
158 { |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
159 return kAudioFileM4AType; |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
160 } |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
161 else if( (__Sound_strcasecmp(file_extension, "aac") == 0) |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
162 ) |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
163 { |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
164 return kAudioFileAAC_ADTSType; |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
165 } |
580
33a77ceaed26
Added more file extension variations for CoreAudio.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
578
diff
changeset
|
166 else if( (__Sound_strcasecmp(file_extension, "adts") == 0) |
576
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
167 ) |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
168 { |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
169 return kAudioFileAAC_ADTSType; |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
170 } |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
171 else if( (__Sound_strcasecmp(file_extension, "caf") == 0) |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
172 || (__Sound_strcasecmp(file_extension, "caff") == 0) |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
173 ) |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
174 { |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
175 return kAudioFileCAFType; |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
176 } |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
177 else if( (__Sound_strcasecmp(file_extension, "Sd2f") == 0) |
577
af33b35a55c1
Minor cleanups. Ready to release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
576
diff
changeset
|
178 || (__Sound_strcasecmp(file_extension, "sd2") == 0) |
576
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
179 ) |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
180 { |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
181 return kAudioFileSoundDesigner2Type; |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
182 } |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
183 else if( (__Sound_strcasecmp(file_extension, "au") == 0) |
580
33a77ceaed26
Added more file extension variations for CoreAudio.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
578
diff
changeset
|
184 || (__Sound_strcasecmp(file_extension, "snd") == 0) |
576
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
185 || (__Sound_strcasecmp(file_extension, "next") == 0) |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
186 ) |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
187 { |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
188 return kAudioFileNextType; |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
189 } |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
190 else if( (__Sound_strcasecmp(file_extension, "mp2") == 0) |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
191 ) |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
192 { |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
193 return kAudioFileMP2Type; |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
194 } |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
195 else if( (__Sound_strcasecmp(file_extension, "mp1") == 0) |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
196 ) |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
197 { |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
198 return kAudioFileMP1Type; |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
199 } |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
200 else if( (__Sound_strcasecmp(file_extension, "ac3") == 0) |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
201 ) |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
202 { |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
203 return kAudioFileAC3Type; |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
204 } |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
205 else if( (__Sound_strcasecmp(file_extension, "3gpp") == 0) |
580
33a77ceaed26
Added more file extension variations for CoreAudio.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
578
diff
changeset
|
206 || (__Sound_strcasecmp(file_extension, "3gp") == 0) |
576
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
207 ) |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
208 { |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
209 return kAudioFile3GPType; |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
210 } |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
211 else if( (__Sound_strcasecmp(file_extension, "3gp2") == 0) |
580
33a77ceaed26
Added more file extension variations for CoreAudio.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
578
diff
changeset
|
212 || (__Sound_strcasecmp(file_extension, "3g2") == 0) |
576
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
213 ) |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
214 { |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
215 return kAudioFile3GP2Type; |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
216 } |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
217 else if( (__Sound_strcasecmp(file_extension, "amrf") == 0) |
577
af33b35a55c1
Minor cleanups. Ready to release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
576
diff
changeset
|
218 || (__Sound_strcasecmp(file_extension, "amr") == 0) |
576
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
219 ) |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
220 { |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
221 return kAudioFileAMRType; |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
222 } |
577
af33b35a55c1
Minor cleanups. Ready to release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
576
diff
changeset
|
223 else if( (__Sound_strcasecmp(file_extension, "ima4") == 0) |
af33b35a55c1
Minor cleanups. Ready to release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
576
diff
changeset
|
224 || (__Sound_strcasecmp(file_extension, "ima") == 0) |
af33b35a55c1
Minor cleanups. Ready to release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
576
diff
changeset
|
225 ) |
af33b35a55c1
Minor cleanups. Ready to release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
576
diff
changeset
|
226 { |
af33b35a55c1
Minor cleanups. Ready to release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
576
diff
changeset
|
227 /* not sure about this one */ |
af33b35a55c1
Minor cleanups. Ready to release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
576
diff
changeset
|
228 return kAudioFileCAFType; |
af33b35a55c1
Minor cleanups. Ready to release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
576
diff
changeset
|
229 } |
576
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
230 else |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
231 { |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
232 return 0; |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
233 } |
577
af33b35a55c1
Minor cleanups. Ready to release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
576
diff
changeset
|
234 |
576
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
235 } |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
236 |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
237 static const char* CoreAudio_FourCCToString(int32_t error_code) |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
238 { |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
239 static char return_string[16]; |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
240 uint32_t big_endian_code = htonl(error_code); |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
241 char* big_endian_str = (char*)&big_endian_code; |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
242 // see if it appears to be a 4-char-code |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
243 if(isprint(big_endian_str[0]) |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
244 && isprint(big_endian_str[1]) |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
245 && isprint(big_endian_str[2]) |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
246 && isprint (big_endian_str[3])) |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
247 { |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
248 return_string[0] = '\''; |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
249 return_string[1] = big_endian_str[0]; |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
250 return_string[2] = big_endian_str[1]; |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
251 return_string[3] = big_endian_str[2]; |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
252 return_string[4] = big_endian_str[3]; |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
253 return_string[5] = '\''; |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
254 return_string[6] = '\0'; |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
255 } |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
256 else if(error_code > -200000 && error_code < 200000) |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
257 { |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
258 // no, format it as an integer |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
259 snprintf(return_string, 16, "%d", error_code); |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
260 } |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
261 else |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
262 { |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
263 // no, format it as an integer but in hex |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
264 snprintf(return_string, 16, "0x%x", error_code); |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
265 } |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
266 return return_string; |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
267 } |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
268 |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
269 |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
270 |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
271 SInt64 CoreAudio_SizeCallback(void* inClientData) |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
272 { |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
273 SDL_RWops* rw_ops = (SDL_RWops*)inClientData; |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
274 SInt64 current_position = SDL_RWtell(rw_ops); |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
275 SInt64 end_position = SDL_RWseek(rw_ops, 0, SEEK_END); |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
276 SDL_RWseek(rw_ops, current_position, SEEK_SET); |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
277 // fprintf(stderr, "CoreAudio_SizeCallback:%d\n", end_position); |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
278 |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
279 return end_position; |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
280 } |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
281 |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
282 OSStatus CoreAudio_ReadCallback( |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
283 void* inClientData, |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
284 SInt64 inPosition, |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
285 UInt32 requestCount, |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
286 void* data_buffer, |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
287 UInt32* actualCount |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
288 ) |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
289 { |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
290 SDL_RWops* rw_ops = (SDL_RWops*)inClientData; |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
291 SDL_RWseek(rw_ops, inPosition, SEEK_SET); |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
292 size_t bytes_actually_read = SDL_RWread(rw_ops, data_buffer, 1, requestCount); |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
293 // Not sure how to test for a read error with SDL_RWops |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
294 // fprintf(stderr, "CoreAudio_ReadCallback:%d, %d\n", requestCount, bytes_actually_read); |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
295 |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
296 *actualCount = bytes_actually_read; |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
297 return noErr; |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
298 } |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
299 |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
300 |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
301 static int CoreAudio_open(Sound_Sample *sample, const char *ext) |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
302 { |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
303 CoreAudioFileContainer* core_audio_file_container; |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
304 AudioFileID* audio_file_id; |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
305 OSStatus error_result; |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
306 Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque; |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
307 AudioStreamBasicDescription actual_format; |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
308 AudioStreamBasicDescription output_format; |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
309 Float64 estimated_duration; |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
310 UInt32 format_size; |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
311 |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
312 |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
313 core_audio_file_container = (CoreAudioFileContainer*)malloc(sizeof(CoreAudioFileContainer)); |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
314 BAIL_IF_MACRO(core_audio_file_container == NULL, ERR_OUT_OF_MEMORY, 0); |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
315 |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
316 |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
317 audio_file_id = (AudioFileID*)malloc(sizeof(AudioFileID)); |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
318 BAIL_IF_MACRO(audio_file_id == NULL, ERR_OUT_OF_MEMORY, 0); |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
319 |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
320 error_result = AudioFileOpenWithCallbacks( |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
321 internal->rw, |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
322 CoreAudio_ReadCallback, |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
323 NULL, |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
324 CoreAudio_SizeCallback, |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
325 NULL, |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
326 CoreAudio_GetAudioTypeForExtension(ext), |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
327 audio_file_id |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
328 ); |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
329 if (error_result != noErr) |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
330 { |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
331 AudioFileClose(*audio_file_id); |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
332 free(audio_file_id); |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
333 free(core_audio_file_container); |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
334 SNDDBG(("Core Audio: can't grok data. reason: [%s].\n", CoreAudio_FourCCToString(error_result))); |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
335 BAIL_MACRO("Core Audio: Not valid audio data.", 0); |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
336 } /* if */ |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
337 |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
338 format_size = sizeof(actual_format); |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
339 error_result = AudioFileGetProperty( |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
340 *audio_file_id, |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
341 kAudioFilePropertyDataFormat, |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
342 &format_size, |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
343 &actual_format |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
344 ); |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
345 if (error_result != noErr) |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
346 { |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
347 AudioFileClose(*audio_file_id); |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
348 free(audio_file_id); |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
349 free(core_audio_file_container); |
577
af33b35a55c1
Minor cleanups. Ready to release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
576
diff
changeset
|
350 SNDDBG(("Core Audio: AudioFileGetProperty failed. reason: [%s]", CoreAudio_FourCCToString(error_result))); |
576
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
351 BAIL_MACRO("Core Audio: Not valid audio data.", 0); |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
352 } /* if */ |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
353 |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
354 format_size = sizeof(estimated_duration); |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
355 error_result = AudioFileGetProperty( |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
356 *audio_file_id, |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
357 kAudioFilePropertyEstimatedDuration, |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
358 &format_size, |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
359 &estimated_duration |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
360 ); |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
361 if (error_result != noErr) |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
362 { |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
363 AudioFileClose(*audio_file_id); |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
364 free(audio_file_id); |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
365 free(core_audio_file_container); |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
366 SNDDBG(("Core Audio: AudioFileGetProperty failed. reason: [%s].\n", CoreAudio_FourCCToString(error_result))); |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
367 BAIL_MACRO("Core Audio: Not valid audio data.", 0); |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
368 } /* if */ |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
369 |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
370 |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
371 core_audio_file_container->audioFileID = audio_file_id; |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
372 |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
373 internal->decoder_private = core_audio_file_container; |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
374 |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
375 sample->flags = SOUND_SAMPLEFLAG_CANSEEK; |
577
af33b35a55c1
Minor cleanups. Ready to release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
576
diff
changeset
|
376 sample->actual.rate = (UInt32) actual_format.mSampleRate; |
af33b35a55c1
Minor cleanups. Ready to release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
576
diff
changeset
|
377 sample->actual.channels = (UInt8)actual_format.mChannelsPerFrame; |
af33b35a55c1
Minor cleanups. Ready to release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
576
diff
changeset
|
378 internal->total_time = (SInt32)(estimated_duration * 1000.0 + 0.5); |
576
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
379 |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
380 #if 0 |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
381 /* FIXME: Both Core Audio and SDL 1.3 support float and 32-bit formats */ |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
382 if(actual_format.mFormatFlags & kAudioFormatFlagIsBigEndian) |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
383 { |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
384 if(16 == actual_format.mBitsPerChannel) |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
385 { |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
386 if(kAudioFormatFlagIsSignedInteger & actual_format.mFormatFlags) |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
387 { |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
388 sample->actual.format = AUDIO_S16MSB; |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
389 } |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
390 else |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
391 { |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
392 sample->actual.format = AUDIO_U16MSB; |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
393 } |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
394 } |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
395 else if(8 == actual_format.mBitsPerChannel) |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
396 { |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
397 if(kAudioFormatFlagIsSignedInteger & actual_format.mFormatFlags) |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
398 { |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
399 sample->actual.format = AUDIO_S8; |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
400 } |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
401 else |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
402 { |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
403 sample->actual.format = AUDIO_U8; |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
404 } |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
405 } |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
406 else // might be 0 for undefined? |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
407 { |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
408 // This case seems to come up a lot for me. Maybe for file types like .m4a? |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
409 sample->actual.format = AUDIO_S16SYS; |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
410 SNDDBG(("Core Audio: Unsupported actual_format.mBitsPerChannel: [%d].\n", actual_format.mBitsPerChannel)); |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
411 |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
412 } |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
413 } |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
414 else // little endian |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
415 { |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
416 if(16 == actual_format.mBitsPerChannel) |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
417 { |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
418 if(kAudioFormatFlagIsSignedInteger & actual_format.mFormatFlags) |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
419 { |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
420 sample->actual.format = AUDIO_S16LSB; |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
421 } |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
422 else |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
423 { |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
424 sample->actual.format = AUDIO_U16LSB; |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
425 } |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
426 } |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
427 else if(8 == actual_format.mBitsPerChannel) |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
428 { |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
429 if(kAudioFormatFlagIsSignedInteger & actual_format.mFormatFlags) |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
430 { |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
431 sample->actual.format = AUDIO_S8; |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
432 } |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
433 else |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
434 { |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
435 sample->actual.format = AUDIO_U8; |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
436 } |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
437 } |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
438 else // might be 0 for undefined? |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
439 { |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
440 sample->actual.format = AUDIO_S16SYS; |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
441 |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
442 SNDDBG(("Core Audio: Unsupported actual_format.mBitsPerChannel: [%d].\n", actual_format.mBitsPerChannel)); |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
443 } |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
444 |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
445 } |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
446 #else |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
447 |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
448 |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
449 |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
450 /* |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
451 * I want to use Core Audio to do conversion and decoding for performance reasons. |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
452 * This is particularly important on mobile devices like iOS. |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
453 * Taking from the Ogg Vorbis decode, I pretend the "actual" format is the same |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
454 * as the desired format. |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
455 */ |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
456 sample->actual.format = (sample->desired.format == 0) ? |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
457 AUDIO_S16SYS : sample->desired.format; |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
458 #endif |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
459 |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
460 |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
461 SNDDBG(("CoreAudio: channels == (%d).\n", sample->actual.channels)); |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
462 SNDDBG(("CoreAudio: sampling rate == (%d).\n",sample->actual.rate)); |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
463 SNDDBG(("CoreAudio: total seconds of sample == (%d).\n", internal->total_time)); |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
464 SNDDBG(("CoreAudio: sample->actual.format == (%d).\n", sample->actual.format)); |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
465 |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
466 |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
467 |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
468 error_result = ExtAudioFileWrapAudioFileID(*audio_file_id, |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
469 false, // set to false for read-only |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
470 &core_audio_file_container->extAudioFileRef |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
471 ); |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
472 if(error_result != noErr) |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
473 { |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
474 AudioFileClose(*audio_file_id); |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
475 free(audio_file_id); |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
476 free(core_audio_file_container); |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
477 SNDDBG(("Core Audio: can't wrap data. reason: [%s].\n", CoreAudio_FourCCToString(error_result))); |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
478 BAIL_MACRO("Core Audio: Failed to wrap data.", 0); |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
479 } /* if */ |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
480 |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
481 |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
482 /* The output format must be linear PCM because that's the only type OpenAL knows how to deal with. |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
483 * Set the client format to 16 bit signed integer (native-endian) data because that is the most |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
484 * optimal format on iPhone/iPod Touch hardware. |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
485 * Maintain the channel count and sample rate of the original source format. |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
486 */ |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
487 output_format.mSampleRate = actual_format.mSampleRate; // preserve the original sample rate |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
488 output_format.mChannelsPerFrame = actual_format.mChannelsPerFrame; // preserve the number of channels |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
489 output_format.mFormatID = kAudioFormatLinearPCM; // We want linear PCM data |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
490 output_format.mFramesPerPacket = 1; // We know for linear PCM, the definition is 1 frame per packet |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
491 |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
492 if(sample->desired.format == 0) |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
493 { |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
494 // do AUDIO_S16SYS |
577
af33b35a55c1
Minor cleanups. Ready to release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
576
diff
changeset
|
495 output_format.mFormatFlags = kAudioFormatFlagsNativeEndian | kAudioFormatFlagIsSignedInteger | kAudioFormatFlagIsPacked; // I seem to read failures problems without kAudioFormatFlagIsPacked. From a mailing list post, this seems to be a Core Audio bug. |
576
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
496 output_format.mBitsPerChannel = 16; // We know we want 16-bit |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
497 } |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
498 else |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
499 { |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
500 output_format.mFormatFlags = 0; // clear flags |
577
af33b35a55c1
Minor cleanups. Ready to release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
576
diff
changeset
|
501 output_format.mFormatFlags |= kAudioFormatFlagIsPacked; // I seem to read failures problems without kAudioFormatFlagIsPacked. From a mailing list post, this seems to be a Core Audio bug. |
576
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
502 // Mask against bitsize |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
503 if(0xFF & sample->desired.format) |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
504 { |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
505 output_format.mBitsPerChannel = 16; /* 16-bit */ |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
506 } |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
507 else |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
508 { |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
509 output_format.mBitsPerChannel = 8; /* 8-bit */ |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
510 } |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
511 |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
512 // Mask for signed/unsigned |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
513 if((1<<15) & sample->desired.format) |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
514 { |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
515 output_format.mFormatFlags = output_format.mFormatFlags | kAudioFormatFlagIsSignedInteger; |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
516 |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
517 } |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
518 else |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
519 { |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
520 // no flag set for unsigned |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
521 } |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
522 // Mask for big/little endian |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
523 if((1<<12) & sample->desired.format) |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
524 { |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
525 output_format.mFormatFlags = output_format.mFormatFlags | kAudioFormatFlagIsBigEndian; |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
526 } |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
527 else |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
528 { |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
529 // no flag set for little endian |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
530 } |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
531 } |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
532 |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
533 output_format.mBytesPerPacket = output_format.mBitsPerChannel/8 * output_format.mChannelsPerFrame; // e.g. 16-bits/8 * channels => so 2-bytes per channel per frame |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
534 output_format.mBytesPerFrame = output_format.mBitsPerChannel/8 * output_format.mChannelsPerFrame; // For PCM, since 1 frame is 1 packet, it is the same as mBytesPerPacket |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
535 |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
536 |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
537 /* |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
538 output_format.mSampleRate = actual_format.mSampleRate; // preserve the original sample rate |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
539 output_format.mChannelsPerFrame = actual_format.mChannelsPerFrame; // preserve the number of channels |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
540 output_format.mFormatID = kAudioFormatLinearPCM; // We want linear PCM data |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
541 // output_format.mFormatFlags = kAudioFormatFlagsNativeEndian | kAudioFormatFlagIsPacked | kAudioFormatFlagIsSignedInteger; |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
542 output_format.mFormatFlags = kAudioFormatFlagsNativeEndian | kAudioFormatFlagIsSignedInteger; |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
543 output_format.mFramesPerPacket = 1; // We know for linear PCM, the definition is 1 frame per packet |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
544 output_format.mBitsPerChannel = 16; // We know we want 16-bit |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
545 output_format.mBytesPerPacket = 2 * output_format.mChannelsPerFrame; // We know we are using 16-bit, so 2-bytes per channel per frame |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
546 output_format.mBytesPerFrame = 2 * output_format.mChannelsPerFrame; // For PCM, since 1 frame is 1 packet, it is the same as mBytesPerPacket |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
547 */ |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
548 SNDDBG(("output_format: mSampleRate: %lf\n", output_format.mSampleRate)); |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
549 SNDDBG(("output_format: mChannelsPerFrame: %d\n", output_format.mChannelsPerFrame)); |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
550 SNDDBG(("output_format: mFormatID: %d\n", output_format.mFormatID)); |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
551 SNDDBG(("output_format: mFormatFlags: %d\n", output_format.mFormatFlags)); |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
552 SNDDBG(("output_format: mFramesPerPacket: %d\n", output_format.mFramesPerPacket)); |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
553 SNDDBG(("output_format: mBitsPerChannel: %d\n", output_format.mBitsPerChannel)); |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
554 SNDDBG(("output_format: mBytesPerPacket: %d\n", output_format.mBytesPerPacket)); |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
555 SNDDBG(("output_format: mBytesPerFrame: %d\n", output_format.mBytesPerFrame)); |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
556 |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
557 |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
558 /* Set the desired client (output) data format */ |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
559 error_result = ExtAudioFileSetProperty(core_audio_file_container->extAudioFileRef, kExtAudioFileProperty_ClientDataFormat, sizeof(output_format), &output_format); |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
560 if(noErr != error_result) |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
561 { |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
562 ExtAudioFileDispose(core_audio_file_container->extAudioFileRef); |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
563 AudioFileClose(*audio_file_id); |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
564 free(audio_file_id); |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
565 free(core_audio_file_container); |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
566 SNDDBG(("Core Audio: ExtAudioFileSetProperty(kExtAudioFileProperty_ClientDataFormat) failed, reason: [%s].\n", CoreAudio_FourCCToString(error_result))); |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
567 BAIL_MACRO("Core Audio: Not valid audio data.", 0); |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
568 } |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
569 |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
570 |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
571 core_audio_file_container->outputFormat = (AudioStreamBasicDescription*)malloc(sizeof(AudioStreamBasicDescription)); |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
572 BAIL_IF_MACRO(core_audio_file_container->outputFormat == NULL, ERR_OUT_OF_MEMORY, 0); |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
573 |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
574 |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
575 |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
576 /* Copy the output format to the audio_description that was passed in so the |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
577 * info will be returned to the user. |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
578 */ |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
579 memcpy(core_audio_file_container->outputFormat, &output_format, sizeof(AudioStreamBasicDescription)); |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
580 |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
581 |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
582 |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
583 return(1); |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
584 } /* CoreAudio_open */ |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
585 |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
586 |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
587 static void CoreAudio_close(Sound_Sample *sample) |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
588 { |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
589 Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque; |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
590 CoreAudioFileContainer* core_audio_file_container = (CoreAudioFileContainer *) internal->decoder_private; |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
591 |
578
7ff36153215a
Fixed 48-byte memory leak.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
577
diff
changeset
|
592 free(core_audio_file_container->outputFormat); |
576
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
593 ExtAudioFileDispose(core_audio_file_container->extAudioFileRef); |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
594 AudioFileClose(*core_audio_file_container->audioFileID); |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
595 free(core_audio_file_container->audioFileID); |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
596 free(core_audio_file_container); |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
597 |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
598 } /* CoreAudio_close */ |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
599 |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
600 |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
601 static Uint32 CoreAudio_read(Sound_Sample *sample) |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
602 { |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
603 OSStatus error_result = noErr; |
577
af33b35a55c1
Minor cleanups. Ready to release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
576
diff
changeset
|
604 /* Documentation/example shows SInt64, but is problematic for big endian |
af33b35a55c1
Minor cleanups. Ready to release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
576
diff
changeset
|
605 * on 32-bit cast for ExtAudioFileRead() because it takes the upper |
af33b35a55c1
Minor cleanups. Ready to release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
576
diff
changeset
|
606 * bits which turn to 0. |
af33b35a55c1
Minor cleanups. Ready to release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
576
diff
changeset
|
607 */ |
af33b35a55c1
Minor cleanups. Ready to release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
576
diff
changeset
|
608 UInt32 buffer_size_in_frames = 0; |
af33b35a55c1
Minor cleanups. Ready to release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
576
diff
changeset
|
609 UInt32 buffer_size_in_frames_remaining = 0; |
af33b35a55c1
Minor cleanups. Ready to release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
576
diff
changeset
|
610 UInt32 total_frames_read = 0; |
af33b35a55c1
Minor cleanups. Ready to release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
576
diff
changeset
|
611 UInt32 data_buffer_size = 0; |
af33b35a55c1
Minor cleanups. Ready to release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
576
diff
changeset
|
612 UInt32 bytes_remaining = 0; |
af33b35a55c1
Minor cleanups. Ready to release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
576
diff
changeset
|
613 size_t total_bytes_read = 0; |
576
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
614 Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque; |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
615 CoreAudioFileContainer* core_audio_file_container = (CoreAudioFileContainer *) internal->decoder_private; |
577
af33b35a55c1
Minor cleanups. Ready to release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
576
diff
changeset
|
616 UInt32 max_buffer_size = internal->buffer_size; |
576
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
617 |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
618 // printf("internal->buffer_size=%d, internal->buffer=0x%x, sample->buffer_size=%d\n", internal->buffer_size, internal->buffer, sample->buffer_size); |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
619 // printf("internal->max_buffer_size=%d\n", max_buffer_size); |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
620 |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
621 /* Compute how many frames will fit into our max buffer size */ |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
622 /* Warning: If this is not evenly divisible, the buffer will not be completely filled which violates the SDL_sound assumption. */ |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
623 buffer_size_in_frames = max_buffer_size / core_audio_file_container->outputFormat->mBytesPerFrame; |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
624 // printf("buffer_size_in_frames=%ld, internal->buffer_size=%d, internal->buffer=0x%x outputFormat->mBytesPerFrame=%d, sample->buffer_size=%d\n", buffer_size_in_frames, internal->buffer_size, internal->buffer, core_audio_file_container->outputFormat->mBytesPerFrame, sample->buffer_size); |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
625 |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
626 |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
627 // void* temp_buffer = malloc(max_buffer_size); |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
628 |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
629 AudioBufferList audio_buffer_list; |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
630 audio_buffer_list.mNumberBuffers = 1; |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
631 audio_buffer_list.mBuffers[0].mDataByteSize = max_buffer_size; |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
632 audio_buffer_list.mBuffers[0].mNumberChannels = core_audio_file_container->outputFormat->mChannelsPerFrame; |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
633 audio_buffer_list.mBuffers[0].mData = internal->buffer; |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
634 |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
635 |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
636 bytes_remaining = max_buffer_size; |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
637 buffer_size_in_frames_remaining = buffer_size_in_frames; |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
638 |
577
af33b35a55c1
Minor cleanups. Ready to release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
576
diff
changeset
|
639 // oops. Due to the kAudioFormatFlagIsPacked bug, |
af33b35a55c1
Minor cleanups. Ready to release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
576
diff
changeset
|
640 // I was misled to believe that Core Audio |
af33b35a55c1
Minor cleanups. Ready to release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
576
diff
changeset
|
641 // was not always filling my entire requested buffer. |
af33b35a55c1
Minor cleanups. Ready to release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
576
diff
changeset
|
642 // So this while-loop might be unnecessary. |
af33b35a55c1
Minor cleanups. Ready to release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
576
diff
changeset
|
643 // However, I have not exhaustively tested all formats, |
af33b35a55c1
Minor cleanups. Ready to release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
576
diff
changeset
|
644 // so maybe it is possible this loop is useful. |
af33b35a55c1
Minor cleanups. Ready to release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
576
diff
changeset
|
645 // It might also handle the not-evenly disvisible case above. |
576
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
646 while(buffer_size_in_frames_remaining > 0 && !(sample->flags & SOUND_SAMPLEFLAG_EOF)) |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
647 { |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
648 |
577
af33b35a55c1
Minor cleanups. Ready to release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
576
diff
changeset
|
649 data_buffer_size = (UInt32)(buffer_size_in_frames * core_audio_file_container->outputFormat->mBytesPerFrame); |
576
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
650 // printf("data_buffer_size=%d\n", data_buffer_size); |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
651 |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
652 buffer_size_in_frames = buffer_size_in_frames_remaining; |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
653 |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
654 // printf("reading buffer_size_in_frames=%"PRId64"\n", buffer_size_in_frames); |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
655 |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
656 |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
657 audio_buffer_list.mBuffers[0].mDataByteSize = bytes_remaining; |
577
af33b35a55c1
Minor cleanups. Ready to release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
576
diff
changeset
|
658 audio_buffer_list.mBuffers[0].mData = &(((UInt8*)internal->buffer)[total_bytes_read]); |
576
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
659 |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
660 |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
661 /* Read the data into an AudioBufferList */ |
577
af33b35a55c1
Minor cleanups. Ready to release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
576
diff
changeset
|
662 error_result = ExtAudioFileRead(core_audio_file_container->extAudioFileRef, &buffer_size_in_frames, &audio_buffer_list); |
576
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
663 if(error_result == noErr) |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
664 { |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
665 |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
666 |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
667 /* Success */ |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
668 |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
669 total_frames_read += buffer_size_in_frames; |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
670 buffer_size_in_frames_remaining = buffer_size_in_frames_remaining - buffer_size_in_frames; |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
671 |
577
af33b35a55c1
Minor cleanups. Ready to release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
576
diff
changeset
|
672 // printf("read buffer_size_in_frames=%"PRId64", buffer_size_in_frames_remaining=%"PRId64"\n", buffer_size_in_frames, buffer_size_in_frames_remaining); |
576
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
673 |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
674 /* ExtAudioFileRead returns the number of frames actually read. Need to convert back to bytes. */ |
577
af33b35a55c1
Minor cleanups. Ready to release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
576
diff
changeset
|
675 data_buffer_size = (UInt32)(buffer_size_in_frames * core_audio_file_container->outputFormat->mBytesPerFrame); |
576
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
676 // printf("data_buffer_size=%d\n", data_buffer_size); |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
677 |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
678 total_bytes_read += data_buffer_size; |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
679 bytes_remaining = bytes_remaining - data_buffer_size; |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
680 |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
681 /* Note: 0 == buffer_size_in_frames is a legitimate value meaning we are EOF. */ |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
682 if(0 == buffer_size_in_frames) |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
683 { |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
684 sample->flags |= SOUND_SAMPLEFLAG_EOF; |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
685 } |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
686 |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
687 } |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
688 else |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
689 { |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
690 SNDDBG(("Core Audio: ExtAudioFileReadfailed, reason: [%s].\n", CoreAudio_FourCCToString(error_result))); |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
691 |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
692 sample->flags |= SOUND_SAMPLEFLAG_ERROR; |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
693 break; |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
694 |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
695 } |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
696 } |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
697 |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
698 if( (!(sample->flags & SOUND_SAMPLEFLAG_EOF)) && (total_bytes_read < max_buffer_size)) |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
699 { |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
700 SNDDBG(("Core Audio: ExtAudioFileReadfailed SOUND_SAMPLEFLAG_EAGAIN, reason: [total_bytes_read < max_buffer_size], %d, %d.\n", total_bytes_read , max_buffer_size)); |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
701 |
577
af33b35a55c1
Minor cleanups. Ready to release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
576
diff
changeset
|
702 /* Don't know what to do here. */ |
576
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
703 sample->flags |= SOUND_SAMPLEFLAG_EAGAIN; |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
704 } |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
705 return total_bytes_read; |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
706 } /* CoreAudio_read */ |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
707 |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
708 |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
709 static int CoreAudio_rewind(Sound_Sample *sample) |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
710 { |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
711 OSStatus error_result = noErr; |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
712 Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque; |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
713 CoreAudioFileContainer* core_audio_file_container = (CoreAudioFileContainer *) internal->decoder_private; |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
714 |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
715 error_result = ExtAudioFileSeek(core_audio_file_container->extAudioFileRef, 0); |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
716 if(error_result != noErr) |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
717 { |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
718 sample->flags |= SOUND_SAMPLEFLAG_ERROR; |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
719 } |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
720 return(1); |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
721 } /* CoreAudio_rewind */ |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
722 |
579
6927c489964c
Bug fix for CoreAudio seeking. Comments inline in code.
Eric Wing <ewing@anscamobile.com>
parents:
578
diff
changeset
|
723 /* Note: I found this tech note: |
6927c489964c
Bug fix for CoreAudio seeking. Comments inline in code.
Eric Wing <ewing@anscamobile.com>
parents:
578
diff
changeset
|
724 http://developer.apple.com/library/mac/#qa/qa2009/qa1678.html |
6927c489964c
Bug fix for CoreAudio seeking. Comments inline in code.
Eric Wing <ewing@anscamobile.com>
parents:
578
diff
changeset
|
725 I don't know if this applies to us. So far, I haven't noticed the problem, |
6927c489964c
Bug fix for CoreAudio seeking. Comments inline in code.
Eric Wing <ewing@anscamobile.com>
parents:
578
diff
changeset
|
726 so I haven't applied any of the techniques. |
6927c489964c
Bug fix for CoreAudio seeking. Comments inline in code.
Eric Wing <ewing@anscamobile.com>
parents:
578
diff
changeset
|
727 */ |
576
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
728 static int CoreAudio_seek(Sound_Sample *sample, Uint32 ms) |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
729 { |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
730 OSStatus error_result = noErr; |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
731 Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque; |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
732 CoreAudioFileContainer* core_audio_file_container = (CoreAudioFileContainer *) internal->decoder_private; |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
733 SInt64 frame_offset = 0; |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
734 AudioStreamBasicDescription actual_format; |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
735 UInt32 format_size; |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
736 |
579
6927c489964c
Bug fix for CoreAudio seeking. Comments inline in code.
Eric Wing <ewing@anscamobile.com>
parents:
578
diff
changeset
|
737 |
6927c489964c
Bug fix for CoreAudio seeking. Comments inline in code.
Eric Wing <ewing@anscamobile.com>
parents:
578
diff
changeset
|
738 /* I'm confused. The Apple documentation says this: |
6927c489964c
Bug fix for CoreAudio seeking. Comments inline in code.
Eric Wing <ewing@anscamobile.com>
parents:
578
diff
changeset
|
739 "Seek position is specified in the sample rate and frame count of the file’s audio data format |
6927c489964c
Bug fix for CoreAudio seeking. Comments inline in code.
Eric Wing <ewing@anscamobile.com>
parents:
578
diff
changeset
|
740 — not your application’s audio data format." |
6927c489964c
Bug fix for CoreAudio seeking. Comments inline in code.
Eric Wing <ewing@anscamobile.com>
parents:
578
diff
changeset
|
741 My interpretation is that I want to get the "actual format of the file and compute the frame offset. |
6927c489964c
Bug fix for CoreAudio seeking. Comments inline in code.
Eric Wing <ewing@anscamobile.com>
parents:
578
diff
changeset
|
742 But when I try that, seeking goes to the wrong place. |
6927c489964c
Bug fix for CoreAudio seeking. Comments inline in code.
Eric Wing <ewing@anscamobile.com>
parents:
578
diff
changeset
|
743 When I use outputFormat, things seem to work correctly. |
6927c489964c
Bug fix for CoreAudio seeking. Comments inline in code.
Eric Wing <ewing@anscamobile.com>
parents:
578
diff
changeset
|
744 I must be misinterpreting the documentation or doing something wrong. |
6927c489964c
Bug fix for CoreAudio seeking. Comments inline in code.
Eric Wing <ewing@anscamobile.com>
parents:
578
diff
changeset
|
745 */ |
6927c489964c
Bug fix for CoreAudio seeking. Comments inline in code.
Eric Wing <ewing@anscamobile.com>
parents:
578
diff
changeset
|
746 #if 0 /* not working */ |
576
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
747 format_size = sizeof(AudioStreamBasicDescription); |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
748 error_result = AudioFileGetProperty( |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
749 *core_audio_file_container->audioFileID, |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
750 kAudioFilePropertyDataFormat, |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
751 &format_size, |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
752 &actual_format |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
753 ); |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
754 if(error_result != noErr) |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
755 { |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
756 sample->flags |= SOUND_SAMPLEFLAG_ERROR; |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
757 BAIL_MACRO("Core Audio: Could not GetProperty for kAudioFilePropertyDataFormat.", 0); |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
758 } /* if */ |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
759 |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
760 // packetIndex = (pos * sampleRate) / framesPerPacket |
579
6927c489964c
Bug fix for CoreAudio seeking. Comments inline in code.
Eric Wing <ewing@anscamobile.com>
parents:
578
diff
changeset
|
761 // frame_offset = (SInt64)((ms/1000.0 * actual_format.mSampleRate) / actual_format.mFramesPerPacket); |
6927c489964c
Bug fix for CoreAudio seeking. Comments inline in code.
Eric Wing <ewing@anscamobile.com>
parents:
578
diff
changeset
|
762 #else /* seems to work, but I'm confused */ |
6927c489964c
Bug fix for CoreAudio seeking. Comments inline in code.
Eric Wing <ewing@anscamobile.com>
parents:
578
diff
changeset
|
763 // packetIndex = (pos * sampleRate) / framesPerPacket |
6927c489964c
Bug fix for CoreAudio seeking. Comments inline in code.
Eric Wing <ewing@anscamobile.com>
parents:
578
diff
changeset
|
764 frame_offset = (SInt64)((ms/1000.0 * core_audio_file_container->outputFormat->mSampleRate) / core_audio_file_container->outputFormat->mFramesPerPacket); |
6927c489964c
Bug fix for CoreAudio seeking. Comments inline in code.
Eric Wing <ewing@anscamobile.com>
parents:
578
diff
changeset
|
765 #endif |
6927c489964c
Bug fix for CoreAudio seeking. Comments inline in code.
Eric Wing <ewing@anscamobile.com>
parents:
578
diff
changeset
|
766 |
576
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
767 // computed against actual format and not the client format |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
768 error_result = ExtAudioFileSeek(core_audio_file_container->extAudioFileRef, frame_offset); |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
769 if(error_result != noErr) |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
770 { |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
771 sample->flags |= SOUND_SAMPLEFLAG_ERROR; |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
772 } |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
773 |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
774 return(1); |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
775 } /* CoreAudio_seek */ |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
776 |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
777 #endif /* SOUND_SUPPORTS_COREAUDIO */ |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
778 |
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
779 |
577
af33b35a55c1
Minor cleanups. Ready to release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
576
diff
changeset
|
780 /* end of coreaudio.c ... */ |
576
8d62447b75f2
Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
781 |