annotate decoders/coreaudio.c @ 576:8d62447b75f2

Added new Core Audio backend.
author Eric Wing <ewing . public |-at-| gmail . com>
date Sun, 10 Oct 2010 21:30:17 -0700
parents
children af33b35a55c1
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
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
3 * Copyright (C) 2010 Eric Wing
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 //http://developer.apple.com/library/ios/#documentation/MusicAudio/Reference/AudioFileConvertRef/Reference/reference.html
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
44
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
45 static int CoreAudio_init(void);
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
46 static void CoreAudio_quit(void);
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
47 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
48 static void CoreAudio_close(Sound_Sample *sample);
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
49 static Uint32 CoreAudio_read(Sound_Sample *sample);
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
50 static int CoreAudio_rewind(Sound_Sample *sample);
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
51 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
52
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
53 static const char *extensions_coreaudio[] =
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
54 {
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
55 "aif",
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
56 "aiff",
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
57 "aifc",
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
58 "wav",
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
59 "wave",
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
60 "mp3",
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
61 "mp4",
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
62 "m4a",
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
63 "aac",
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
64 "caf",
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
65 "Sd2f",
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
66 "au",
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
67 "next",
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
68 "mp2",
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
69 "mp1",
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
70 "ac3",
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
71 "3gpp",
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
72 "3gp2",
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
73 "amrf",
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
74 NULL
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
75 };
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
76 const Sound_DecoderFunctions __Sound_DecoderFunctions_CoreAudio =
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
77 {
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
78 {
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
79 extensions_coreaudio,
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
80 "Decode audio through Core Audio through",
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
81 "Eric Wing <ewing.public@playcontrol.net>",
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
82 "http://playcontrol.net"
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 CoreAudio_init, /* init() method */
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
86 CoreAudio_quit, /* quit() method */
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
87 CoreAudio_open, /* open() method */
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
88 CoreAudio_close, /* close() method */
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
89 CoreAudio_read, /* read() method */
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
90 CoreAudio_rewind, /* rewind() method */
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
91 CoreAudio_seek /* seek() method */
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
92 };
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
93
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
94
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
95 static int CoreAudio_init(void)
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
96 {
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
97 return(1); /* always succeeds. */
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
98 } /* CoreAudio_init */
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 void CoreAudio_quit(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 /* it's a no-op. */
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
104 } /* CoreAudio_quit */
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 AudioFileTypeID CoreAudio_GetAudioTypeForExtension(const char* file_extension)
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 if( (__Sound_strcasecmp(file_extension, "aif") == 0)
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
110 || (__Sound_strcasecmp(file_extension, "aiff") == 0)
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
111 || (__Sound_strcasecmp(file_extension, "aifc") == 0)
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
112 )
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
113 {
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
114 return kAudioFileAIFCType;
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
115 }
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
116 else if( (__Sound_strcasecmp(file_extension, "wav") == 0)
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
117 || (__Sound_strcasecmp(file_extension, "wave") == 0)
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
118 )
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
119 {
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
120 return kAudioFileWAVEType;
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
121 }
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
122 else if( (__Sound_strcasecmp(file_extension, "mp3") == 0)
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
123 )
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
124 {
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
125 return kAudioFileMP3Type;
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
126 }
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
127 else if( (__Sound_strcasecmp(file_extension, "mp4") == 0)
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
128 )
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
129 {
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
130 return kAudioFileMPEG4Type;
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
131 }
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
132 else if( (__Sound_strcasecmp(file_extension, "m4a") == 0)
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
133 )
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
134 {
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
135 return kAudioFileM4AType;
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 else if( (__Sound_strcasecmp(file_extension, "aac") == 0)
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
138 )
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 return kAudioFileAAC_ADTSType;
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
141 }
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
142 else if( (__Sound_strcasecmp(file_extension, "aac") == 0)
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 {
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
145 return kAudioFileAAC_ADTSType;
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
146 }
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
147 else if( (__Sound_strcasecmp(file_extension, "caf") == 0)
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
148 || (__Sound_strcasecmp(file_extension, "caff") == 0)
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
149 )
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 return kAudioFileCAFType;
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 else if( (__Sound_strcasecmp(file_extension, "Sd2f") == 0)
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
154 )
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 return kAudioFileSoundDesigner2Type;
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 else if( (__Sound_strcasecmp(file_extension, "au") == 0)
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
159 || (__Sound_strcasecmp(file_extension, "next") == 0)
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 {
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
162 return kAudioFileNextType;
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 else if( (__Sound_strcasecmp(file_extension, "mp2") == 0)
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
165 )
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
166 {
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
167 return kAudioFileMP2Type;
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 else if( (__Sound_strcasecmp(file_extension, "mp1") == 0)
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 {
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
172 return kAudioFileMP1Type;
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 else if( (__Sound_strcasecmp(file_extension, "ac3") == 0)
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
175 )
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 return kAudioFileAC3Type;
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
178 }
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
179 else if( (__Sound_strcasecmp(file_extension, "3gpp") == 0)
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 {
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
182 return kAudioFile3GPType;
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
183 }
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
184 else if( (__Sound_strcasecmp(file_extension, "3gp2") == 0)
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
185 )
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 return kAudioFile3GP2Type;
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
188 }
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
189 else if( (__Sound_strcasecmp(file_extension, "amrf") == 0)
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
190 )
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 return kAudioFileAMRType;
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
193 }
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
194 else
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
195 {
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
196 return 0;
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 /*
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
199 kAudioFilhttp://developer.apple.com/library/ios/#documentation/MusicAudio/Reference/AudioFileConvertRef/Reference/reference.htmleAIFFType = 'AIFF',
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
200 kAudioFileAIFCType = 'AIFC',
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
201 kAudioFileWAVEType = 'WAVE',
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
202 kAudioFileSoundDesigner2Type = 'Sd2f',
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
203 kAudioFileNextType = 'NeXT',
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
204 kAudioFileMP3Type = 'MPG3',
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
205 kAudioFileMP2Type = 'MPG2',
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
206 kAudioFileMP1Type = 'MPG1',
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
207 kAudioFileAC3Type = 'ac-3',
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
208 kAudioFileAAC_ADTSType = 'adts',
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
209 kAudioFileMPEG4Type = 'mp4f',
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
210 kAudioFileM4AType = 'm4af',
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
211 kAudioFileCAFType = 'caff',
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
212 kAudioFile3GPType = '3gpp',
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
213 kAudioFile3GP2Type = '3gp2',
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
214 kAudioFileAMRType = 'amrf'
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
215
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 }
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
218
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
219 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
220 {
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
221 static char return_string[16];
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
222 uint32_t big_endian_code = htonl(error_code);
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
223 char* big_endian_str = (char*)&big_endian_code;
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
224 // 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
225 if(isprint(big_endian_str[0])
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
226 && isprint(big_endian_str[1])
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
227 && isprint(big_endian_str[2])
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
228 && isprint (big_endian_str[3]))
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
229 {
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
230 return_string[0] = '\'';
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
231 return_string[1] = big_endian_str[0];
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
232 return_string[2] = big_endian_str[1];
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
233 return_string[3] = big_endian_str[2];
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
234 return_string[4] = big_endian_str[3];
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
235 return_string[5] = '\'';
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
236 return_string[6] = '\0';
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
237 }
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
238 else if(error_code > -200000 && error_code < 200000)
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
239 {
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
240 // no, format it as an integer
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
241 snprintf(return_string, 16, "%d", error_code);
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
242 }
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
243 else
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
244 {
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
245 // 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
246 snprintf(return_string, 16, "0x%x", error_code);
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 return_string;
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
249 }
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
250
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
251
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
252
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
253 SInt64 CoreAudio_SizeCallback(void* inClientData)
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
254 {
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
255 SDL_RWops* rw_ops = (SDL_RWops*)inClientData;
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
256 SInt64 current_position = SDL_RWtell(rw_ops);
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
257 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
258 SDL_RWseek(rw_ops, current_position, SEEK_SET);
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
259 // fprintf(stderr, "CoreAudio_SizeCallback:%d\n", end_position);
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 return end_position;
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
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
264 OSStatus CoreAudio_ReadCallback(
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
265 void* inClientData,
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
266 SInt64 inPosition,
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
267 UInt32 requestCount,
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
268 void* data_buffer,
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
269 UInt32* actualCount
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 {
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
272 SDL_RWops* rw_ops = (SDL_RWops*)inClientData;
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
273 SDL_RWseek(rw_ops, inPosition, SEEK_SET);
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
274 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
275 // 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
276 // 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
277
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
278 *actualCount = bytes_actually_read;
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
279 return noErr;
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
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
283 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
284 {
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
285 CoreAudioFileContainer* core_audio_file_container;
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
286 AudioFileID* audio_file_id;
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
287 OSStatus error_result;
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
288 Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque;
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
289 AudioStreamBasicDescription actual_format;
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
290 AudioStreamBasicDescription output_format;
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
291 Float64 estimated_duration;
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
292 UInt32 format_size;
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
293
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
294
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
295 core_audio_file_container = (CoreAudioFileContainer*)malloc(sizeof(CoreAudioFileContainer));
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
296 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
297
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 audio_file_id = (AudioFileID*)malloc(sizeof(AudioFileID));
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
300 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
301
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
302 error_result = AudioFileOpenWithCallbacks(
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
303 internal->rw,
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
304 CoreAudio_ReadCallback,
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
305 NULL,
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
306 CoreAudio_SizeCallback,
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
307 NULL,
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
308 CoreAudio_GetAudioTypeForExtension(ext),
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
309 audio_file_id
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
310 );
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
311 if (error_result != noErr)
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 AudioFileClose(*audio_file_id);
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
314 free(audio_file_id);
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
315 free(core_audio_file_container);
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
316 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
317 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
318 } /* if */
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 format_size = sizeof(actual_format);
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
321 error_result = AudioFileGetProperty(
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
322 *audio_file_id,
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
323 kAudioFilePropertyDataFormat,
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
324 &format_size,
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
325 &actual_format
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
326 );
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
327 if (error_result != noErr)
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 AudioFileClose(*audio_file_id);
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
330 free(audio_file_id);
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
331 free(core_audio_file_container);
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
332 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
333 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
334 } /* if */
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
335
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
336 format_size = sizeof(estimated_duration);
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
337 error_result = AudioFileGetProperty(
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
338 *audio_file_id,
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
339 kAudioFilePropertyEstimatedDuration,
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
340 &format_size,
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
341 &estimated_duration
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
342 );
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
343 if (error_result != noErr)
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 AudioFileClose(*audio_file_id);
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
346 free(audio_file_id);
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
347 free(core_audio_file_container);
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
348 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
349 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
350 } /* if */
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
351
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
352
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
353 core_audio_file_container->audioFileID = audio_file_id;
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
354
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
355 internal->decoder_private = core_audio_file_container;
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
356
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
357 sample->flags = SOUND_SAMPLEFLAG_CANSEEK;
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
358 sample->actual.rate = (Uint32) actual_format.mSampleRate;
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
359 sample->actual.channels = (Uint8)actual_format.mChannelsPerFrame;
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
360 internal->total_time = (Sint32)(estimated_duration * 1000.0 + 0.5);
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
361
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
362 #if 0
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
363 /* 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
364 if(actual_format.mFormatFlags & kAudioFormatFlagIsBigEndian)
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
365 {
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
366 if(16 == actual_format.mBitsPerChannel)
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
367 {
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
368 if(kAudioFormatFlagIsSignedInteger & actual_format.mFormatFlags)
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 sample->actual.format = AUDIO_S16MSB;
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
371 }
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
372 else
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
373 {
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
374 sample->actual.format = AUDIO_U16MSB;
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
375 }
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
376 }
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
377 else if(8 == actual_format.mBitsPerChannel)
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
378 {
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
379 if(kAudioFormatFlagIsSignedInteger & actual_format.mFormatFlags)
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
380 {
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
381 sample->actual.format = AUDIO_S8;
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
382 }
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
383 else
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
384 {
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
385 sample->actual.format = AUDIO_U8;
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
386 }
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 else // might be 0 for undefined?
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 // 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
391 sample->actual.format = AUDIO_S16SYS;
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
392 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
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 }
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
396 else // little endian
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
397 {
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
398 if(16 == actual_format.mBitsPerChannel)
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
399 {
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
400 if(kAudioFormatFlagIsSignedInteger & actual_format.mFormatFlags)
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
401 {
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
402 sample->actual.format = AUDIO_S16LSB;
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
403 }
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
404 else
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 sample->actual.format = AUDIO_U16LSB;
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 }
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
409 else if(8 == actual_format.mBitsPerChannel)
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
410 {
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
411 if(kAudioFormatFlagIsSignedInteger & actual_format.mFormatFlags)
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 sample->actual.format = AUDIO_S8;
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
414 }
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
415 else
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
416 {
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
417 sample->actual.format = AUDIO_U8;
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
418 }
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 else // might be 0 for undefined?
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 sample->actual.format = AUDIO_S16SYS;
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 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
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 }
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
428 #else
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
429
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
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 * 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
434 * 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
435 * 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
436 * as the desired format.
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 sample->actual.format = (sample->desired.format == 0) ?
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
439 AUDIO_S16SYS : sample->desired.format;
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
440 #endif
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
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
443 SNDDBG(("CoreAudio: channels == (%d).\n", sample->actual.channels));
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
444 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
445 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
446 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
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 error_result = ExtAudioFileWrapAudioFileID(*audio_file_id,
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
451 false, // set to false for read-only
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
452 &core_audio_file_container->extAudioFileRef
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
453 );
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
454 if(error_result != noErr)
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 AudioFileClose(*audio_file_id);
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
457 free(audio_file_id);
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
458 free(core_audio_file_container);
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
459 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
460 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
461 } /* if */
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
462
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
463
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
464 /* 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
465 * 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
466 * optimal format on iPhone/iPod Touch hardware.
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
467 * 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
468 */
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
469 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
470 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
471 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
472 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
473
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
474 if(sample->desired.format == 0)
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
475 {
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
476 // do AUDIO_S16SYS
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
477 output_format.mFormatFlags = kAudioFormatFlagsNativeEndian | kAudioFormatFlagIsSignedInteger | kAudioFormatFlagIsPacked;
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
478 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
479 }
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
480 else
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 output_format.mFormatFlags = 0; // clear flags
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
483 output_format.mFormatFlags |= kAudioFormatFlagIsPacked; // I seem to read failures problems without this
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
484 // Mask against bitsize
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
485 if(0xFF & sample->desired.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.mBitsPerChannel = 16; /* 16-bit */
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
488 }
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
489 else
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
490 {
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
491 output_format.mBitsPerChannel = 8; /* 8-bit */
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
492 }
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 // Mask for signed/unsigned
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
495 if((1<<15) & sample->desired.format)
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
496 {
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
497 output_format.mFormatFlags = output_format.mFormatFlags | kAudioFormatFlagIsSignedInteger;
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
498
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 else
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
501 {
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
502 // no flag set for unsigned
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
503 }
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
504 // Mask for big/little endian
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
505 if((1<<12) & sample->desired.format)
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 output_format.mFormatFlags = output_format.mFormatFlags | kAudioFormatFlagIsBigEndian;
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 else
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 // no flag set for little endian
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
512 }
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
513 }
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.mBitsPerChannel = 16; // We know we want 16-bit
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
516 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
517 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
518
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 /*
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
521 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
522 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
523 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
524 // output_format.mFormatFlags = kAudioFormatFlagsNativeEndian | kAudioFormatFlagIsPacked | kAudioFormatFlagIsSignedInteger;
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
525 output_format.mFormatFlags = kAudioFormatFlagsNativeEndian | kAudioFormatFlagIsSignedInteger;
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
526 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
527 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
528 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
529 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
530 */
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
531 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
532 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
533 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
534 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
535 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
536 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
537 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
538 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
539
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
540
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
541 /* Set the desired client (output) data format */
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
542 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
543 if(noErr != error_result)
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
544 {
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
545 ExtAudioFileDispose(core_audio_file_container->extAudioFileRef);
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
546 AudioFileClose(*audio_file_id);
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
547 free(audio_file_id);
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
548 free(core_audio_file_container);
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
549 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
550 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
551 }
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
552
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
553
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
554 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
555 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
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
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
559 /* 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
560 * info will be returned to the user.
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 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
563
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
564
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
565
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
566 return(1);
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
567 } /* CoreAudio_open */
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 static void CoreAudio_close(Sound_Sample *sample)
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
571 {
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
572 Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque;
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
573 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
574
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
575 ExtAudioFileDispose(core_audio_file_container->extAudioFileRef);
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
576 AudioFileClose(*core_audio_file_container->audioFileID);
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
577 free(core_audio_file_container->audioFileID);
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
578 free(core_audio_file_container);
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
579
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
580 } /* CoreAudio_close */
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 static Uint32 CoreAudio_read(Sound_Sample *sample)
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
584 {
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
585 OSStatus error_result = noErr;
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
586 SInt64 buffer_size_in_frames = 0;
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
587 SInt64 buffer_size_in_frames_remaining = 0;
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
588 SInt64 total_frames_read = 0;
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
589 Uint32 data_buffer_size = 0;
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
590 Uint32 bytes_remaining = 0;
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
591 Uint32 total_bytes_read = 0;
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
592 Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque;
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
593 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
594 Uint32 max_buffer_size = internal->buffer_size;
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
595
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
596 // 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
597 // 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
598
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
599 /* 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
600 /* 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
601 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
602 // 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
603
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
604
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
605 // void* temp_buffer = malloc(max_buffer_size);
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
606
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
607 AudioBufferList audio_buffer_list;
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
608 audio_buffer_list.mNumberBuffers = 1;
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
609 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
610 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
611 audio_buffer_list.mBuffers[0].mData = internal->buffer;
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
612
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
613
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
614 bytes_remaining = max_buffer_size;
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
615 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
616
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
617 // oops. Due to a bug in how I opened the file, I was misled to believe that Core Audio
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
618 // was not always filling my entire requested buffer. So this while-loop might be unnecessary.
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
619 // However, I have not exhaustively tested all formats, so maybe it is possible this loop is useful.
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
620 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
621 {
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
622
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
623 data_buffer_size = (Uint32)(buffer_size_in_frames * core_audio_file_container->outputFormat->mBytesPerFrame);
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
624 // 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
625
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
626 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
627
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
628 // 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
629
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
630
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
631 audio_buffer_list.mBuffers[0].mDataByteSize = bytes_remaining;
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
632 audio_buffer_list.mBuffers[0].mData = &(((Uint8*)internal->buffer)[total_bytes_read]);
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
633
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 /* Read the data into an AudioBufferList */
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
636 error_result = ExtAudioFileRead(core_audio_file_container->extAudioFileRef, (UInt32*)&buffer_size_in_frames, &audio_buffer_list);
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
637 if(error_result == noErr)
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
638 {
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
639
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
640
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
641 /* Success */
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
642
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
643 total_frames_read += buffer_size_in_frames;
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
644 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
645
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
646 printf("read buffer_size_in_frames=%"PRId64", buffer_size_in_frames_remaining=%"PRId64"\n", 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
647
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
648 /* ExtAudioFileRead returns the number of frames actually read. Need to convert back to bytes. */
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
649 data_buffer_size = (Uint32)(buffer_size_in_frames * core_audio_file_container->outputFormat->mBytesPerFrame);
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 total_bytes_read += data_buffer_size;
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
653 bytes_remaining = bytes_remaining - data_buffer_size;
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
654
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
655 /* 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
656 if(0 == buffer_size_in_frames)
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
657 {
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
658 sample->flags |= SOUND_SAMPLEFLAG_EOF;
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 }
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
662 else
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
663 {
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
664 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
665
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
666 sample->flags |= SOUND_SAMPLEFLAG_ERROR;
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
667 break;
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 }
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
670 }
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
671
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
672 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
673 {
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
674 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
675
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
676 // Don't know what to do here.
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
677 sample->flags |= SOUND_SAMPLEFLAG_EAGAIN;
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
678 }
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
679 return total_bytes_read;
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
680 } /* CoreAudio_read */
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
681
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
682
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
683 static int CoreAudio_rewind(Sound_Sample *sample)
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
684 {
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
685 OSStatus error_result = noErr;
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
686 Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque;
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
687 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
688
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
689 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
690 if(error_result != noErr)
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 }
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
694 return(1);
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
695 } /* CoreAudio_rewind */
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 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
699 {
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
700 OSStatus error_result = noErr;
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
701 Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque;
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
702 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
703 SInt64 frame_offset = 0;
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
704 AudioStreamBasicDescription actual_format;
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
705 UInt32 format_size;
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
706
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
707 format_size = sizeof(AudioStreamBasicDescription);
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
708 error_result = AudioFileGetProperty(
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
709 *core_audio_file_container->audioFileID,
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
710 kAudioFilePropertyDataFormat,
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
711 &format_size,
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
712 &actual_format
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
713 );
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
714 if(error_result != noErr)
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
715 {
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
716 sample->flags |= SOUND_SAMPLEFLAG_ERROR;
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
717 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
718 } /* if */
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 // packetIndex = (pos * sampleRate) / framesPerPacket
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
721 frame_offset = (SInt64)((ms/1000.0 * actual_format.mSampleRate) / actual_format.mFramesPerPacket);
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
722 // 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
723 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
724 if(error_result != noErr)
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
725 {
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
726 sample->flags |= SOUND_SAMPLEFLAG_ERROR;
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
727 }
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
728
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
729 return(1);
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
730 } /* CoreAudio_seek */
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
731
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
732 #endif /* SOUND_SUPPORTS_COREAUDIO */
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
733
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
734
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
735 /* end of ogg.c ... */
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
736