annotate decoders/coreaudio.c @ 577:af33b35a55c1

Minor cleanups. Ready to release.
author Eric Wing <ewing . public |-at-| gmail . com>
date Sat, 23 Oct 2010 22:35:38 -0700
parents 8d62447b75f2
children 7ff36153215a
rev   line source
576
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
1 /*
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
2 * SDL_sound Core Audio backend
577
af33b35a55c1 Minor cleanups. Ready to release.
Eric Wing <ewing . public |-at-| gmail . com>
parents: 576
diff changeset
3 * Copyright (C) 2010 Eric Wing <ewing . public @ playcontrol.net>
576
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
4 *
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
5 * This library is free software; you can redistribute it and/or
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
6 * modify it under the terms of the GNU Lesser General Public
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
7 * License as published by the Free Software Foundation; either
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
8 * version 2.1 of the License, or (at your option) any later version.
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
9 *
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
10 * This library is distributed in the hope that it will be useful,
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
13 * Lesser General Public License for more details.
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
14 *
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
15 * You should have received a copy of the GNU Lesser General Public
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
16 * License along with this library; if not, write to the Free Software
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
18 */
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
19
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
20 #if HAVE_CONFIG_H
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
21 # include <config.h>
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
22 #endif
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
23
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
24 #ifdef SOUND_SUPPORTS_COREAUDIO
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
25
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
26 #include <stddef.h> /* NULL */
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
27 #include <stdio.h> /* printf */
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
28 #include <arpa/inet.h> /* htonl */
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
29 #include <AudioToolbox/AudioToolbox.h>
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
30
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
31 #include "SDL_sound.h"
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
32
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
33 #define __SDL_SOUND_INTERNAL__
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
34 #include "SDL_sound_internal.h"
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
35
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
36 typedef struct CoreAudioFileContainer
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
37 {
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
38 AudioFileID* audioFileID;
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
39 ExtAudioFileRef extAudioFileRef;
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
40 AudioStreamBasicDescription* outputFormat;
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
41 } CoreAudioFileContainer;
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
42
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
43 static int CoreAudio_init(void);
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
44 static void CoreAudio_quit(void);
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
45 static int CoreAudio_open(Sound_Sample *sample, const char *ext);
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
46 static void CoreAudio_close(Sound_Sample *sample);
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
47 static Uint32 CoreAudio_read(Sound_Sample *sample);
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
48 static int CoreAudio_rewind(Sound_Sample *sample);
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
49 static int CoreAudio_seek(Sound_Sample *sample, Uint32 ms);
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
50
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
51 static const char *extensions_coreaudio[] =
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
52 {
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
53 "aif",
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
54 "aiff",
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
55 "aifc",
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
56 "wav",
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
57 "wave",
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
58 "mp3",
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
59 "mp4",
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
60 "m4a",
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
61 "aac",
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
62 "caf",
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
63 "Sd2f",
577
af33b35a55c1 Minor cleanups. Ready to release.
Eric Wing <ewing . public |-at-| gmail . com>
parents: 576
diff changeset
64 "Sd2",
576
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
65 "au",
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
66 "next",
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
67 "mp2",
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
68 "mp1",
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
69 "ac3",
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
70 "3gpp",
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
71 "3gp2",
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
72 "amrf",
577
af33b35a55c1 Minor cleanups. Ready to release.
Eric Wing <ewing . public |-at-| gmail . com>
parents: 576
diff changeset
73 "amr",
af33b35a55c1 Minor cleanups. Ready to release.
Eric Wing <ewing . public |-at-| gmail . com>
parents: 576
diff changeset
74 "ima4",
af33b35a55c1 Minor cleanups. Ready to release.
Eric Wing <ewing . public |-at-| gmail . com>
parents: 576
diff changeset
75 "ima",
576
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
76 NULL
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 const Sound_DecoderFunctions __Sound_DecoderFunctions_CoreAudio =
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
79 {
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
80 {
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
81 extensions_coreaudio,
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
82 "Decode audio through Core Audio through",
577
af33b35a55c1 Minor cleanups. Ready to release.
Eric Wing <ewing . public |-at-| gmail . com>
parents: 576
diff changeset
83 "Eric Wing <ewing . public @ playcontrol.net>",
576
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
84 "http://playcontrol.net"
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
85 },
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
86
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
87 CoreAudio_init, /* init() method */
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
88 CoreAudio_quit, /* quit() method */
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
89 CoreAudio_open, /* open() method */
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
90 CoreAudio_close, /* close() method */
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
91 CoreAudio_read, /* read() method */
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
92 CoreAudio_rewind, /* rewind() method */
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
93 CoreAudio_seek /* seek() method */
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
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 static int CoreAudio_init(void)
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
98 {
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
99 return(1); /* always succeeds. */
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
100 } /* CoreAudio_init */
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
101
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 static void CoreAudio_quit(void)
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
104 {
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
105 /* it's a no-op. */
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
106 } /* CoreAudio_quit */
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
107
577
af33b35a55c1 Minor cleanups. Ready to release.
Eric Wing <ewing . public |-at-| gmail . com>
parents: 576
diff changeset
108 /*
af33b35a55c1 Minor cleanups. Ready to release.
Eric Wing <ewing . public |-at-| gmail . com>
parents: 576
diff changeset
109 http://developer.apple.com/library/ios/#documentation/MusicAudio/Reference/AudioFileConvertRef/Reference/reference.html
af33b35a55c1 Minor cleanups. Ready to release.
Eric Wing <ewing . public |-at-| gmail . com>
parents: 576
diff changeset
110 kAudioFileAIFFType = 'AIFF',
af33b35a55c1 Minor cleanups. Ready to release.
Eric Wing <ewing . public |-at-| gmail . com>
parents: 576
diff changeset
111 kAudioFileAIFCType = 'AIFC',
af33b35a55c1 Minor cleanups. Ready to release.
Eric Wing <ewing . public |-at-| gmail . com>
parents: 576
diff changeset
112 kAudioFileWAVEType = 'WAVE',
af33b35a55c1 Minor cleanups. Ready to release.
Eric Wing <ewing . public |-at-| gmail . com>
parents: 576
diff changeset
113 kAudioFileSoundDesigner2Type = 'Sd2f',
af33b35a55c1 Minor cleanups. Ready to release.
Eric Wing <ewing . public |-at-| gmail . com>
parents: 576
diff changeset
114 kAudioFileNextType = 'NeXT',
af33b35a55c1 Minor cleanups. Ready to release.
Eric Wing <ewing . public |-at-| gmail . com>
parents: 576
diff changeset
115 kAudioFileMP3Type = 'MPG3',
af33b35a55c1 Minor cleanups. Ready to release.
Eric Wing <ewing . public |-at-| gmail . com>
parents: 576
diff changeset
116 kAudioFileMP2Type = 'MPG2',
af33b35a55c1 Minor cleanups. Ready to release.
Eric Wing <ewing . public |-at-| gmail . com>
parents: 576
diff changeset
117 kAudioFileMP1Type = 'MPG1',
af33b35a55c1 Minor cleanups. Ready to release.
Eric Wing <ewing . public |-at-| gmail . com>
parents: 576
diff changeset
118 kAudioFileAC3Type = 'ac-3',
af33b35a55c1 Minor cleanups. Ready to release.
Eric Wing <ewing . public |-at-| gmail . com>
parents: 576
diff changeset
119 kAudioFileAAC_ADTSType = 'adts',
af33b35a55c1 Minor cleanups. Ready to release.
Eric Wing <ewing . public |-at-| gmail . com>
parents: 576
diff changeset
120 kAudioFileMPEG4Type = 'mp4f',
af33b35a55c1 Minor cleanups. Ready to release.
Eric Wing <ewing . public |-at-| gmail . com>
parents: 576
diff changeset
121 kAudioFileM4AType = 'm4af',
af33b35a55c1 Minor cleanups. Ready to release.
Eric Wing <ewing . public |-at-| gmail . com>
parents: 576
diff changeset
122 kAudioFileCAFType = 'caff',
af33b35a55c1 Minor cleanups. Ready to release.
Eric Wing <ewing . public |-at-| gmail . com>
parents: 576
diff changeset
123 kAudioFile3GPType = '3gpp',
af33b35a55c1 Minor cleanups. Ready to release.
Eric Wing <ewing . public |-at-| gmail . com>
parents: 576
diff changeset
124 kAudioFile3GP2Type = '3gp2',
af33b35a55c1 Minor cleanups. Ready to release.
Eric Wing <ewing . public |-at-| gmail . com>
parents: 576
diff changeset
125 kAudioFileAMRType = 'amrf'
af33b35a55c1 Minor cleanups. Ready to release.
Eric Wing <ewing . public |-at-| gmail . com>
parents: 576
diff changeset
126 */
576
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
127 static AudioFileTypeID CoreAudio_GetAudioTypeForExtension(const char* file_extension)
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 if( (__Sound_strcasecmp(file_extension, "aif") == 0)
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
130 || (__Sound_strcasecmp(file_extension, "aiff") == 0)
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
131 || (__Sound_strcasecmp(file_extension, "aifc") == 0)
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
132 )
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
133 {
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
134 return kAudioFileAIFCType;
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
135 }
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
136 else if( (__Sound_strcasecmp(file_extension, "wav") == 0)
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
137 || (__Sound_strcasecmp(file_extension, "wave") == 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 kAudioFileWAVEType;
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, "mp3") == 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 kAudioFileMP3Type;
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, "mp4") == 0)
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
148 )
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
149 {
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
150 return kAudioFileMPEG4Type;
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
151 }
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
152 else if( (__Sound_strcasecmp(file_extension, "m4a") == 0)
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
153 )
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
154 {
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
155 return kAudioFileM4AType;
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
156 }
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
157 else if( (__Sound_strcasecmp(file_extension, "aac") == 0)
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
158 )
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
159 {
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
160 return kAudioFileAAC_ADTSType;
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 else if( (__Sound_strcasecmp(file_extension, "aac") == 0)
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 {
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
165 return kAudioFileAAC_ADTSType;
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 else if( (__Sound_strcasecmp(file_extension, "caf") == 0)
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
168 || (__Sound_strcasecmp(file_extension, "caff") == 0)
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
169 )
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 return kAudioFileCAFType;
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
172 }
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
173 else if( (__Sound_strcasecmp(file_extension, "Sd2f") == 0)
577
af33b35a55c1 Minor cleanups. Ready to release.
Eric Wing <ewing . public |-at-| gmail . com>
parents: 576
diff changeset
174 || (__Sound_strcasecmp(file_extension, "sd2") == 0)
576
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 kAudioFileSoundDesigner2Type;
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, "au") == 0)
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
180 || (__Sound_strcasecmp(file_extension, "next") == 0)
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 {
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
183 return kAudioFileNextType;
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
184 }
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
185 else if( (__Sound_strcasecmp(file_extension, "mp2") == 0)
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
186 )
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
187 {
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
188 return kAudioFileMP2Type;
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
189 }
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
190 else if( (__Sound_strcasecmp(file_extension, "mp1") == 0)
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
191 )
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
192 {
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
193 return kAudioFileMP1Type;
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
194 }
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
195 else if( (__Sound_strcasecmp(file_extension, "ac3") == 0)
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
196 )
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
197 {
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
198 return kAudioFileAC3Type;
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
199 }
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
200 else if( (__Sound_strcasecmp(file_extension, "3gpp") == 0)
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
201 )
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
202 {
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
203 return kAudioFile3GPType;
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
204 }
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
205 else if( (__Sound_strcasecmp(file_extension, "3gp2") == 0)
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
206 )
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
207 {
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
208 return kAudioFile3GP2Type;
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
209 }
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
210 else if( (__Sound_strcasecmp(file_extension, "amrf") == 0)
577
af33b35a55c1 Minor cleanups. Ready to release.
Eric Wing <ewing . public |-at-| gmail . com>
parents: 576
diff changeset
211 || (__Sound_strcasecmp(file_extension, "amr") == 0)
576
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
212 )
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
213 {
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
214 return kAudioFileAMRType;
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
215 }
577
af33b35a55c1 Minor cleanups. Ready to release.
Eric Wing <ewing . public |-at-| gmail . com>
parents: 576
diff changeset
216 else if( (__Sound_strcasecmp(file_extension, "ima4") == 0)
af33b35a55c1 Minor cleanups. Ready to release.
Eric Wing <ewing . public |-at-| gmail . com>
parents: 576
diff changeset
217 || (__Sound_strcasecmp(file_extension, "ima") == 0)
af33b35a55c1 Minor cleanups. Ready to release.
Eric Wing <ewing . public |-at-| gmail . com>
parents: 576
diff changeset
218 )
af33b35a55c1 Minor cleanups. Ready to release.
Eric Wing <ewing . public |-at-| gmail . com>
parents: 576
diff changeset
219 {
af33b35a55c1 Minor cleanups. Ready to release.
Eric Wing <ewing . public |-at-| gmail . com>
parents: 576
diff changeset
220 /* not sure about this one */
af33b35a55c1 Minor cleanups. Ready to release.
Eric Wing <ewing . public |-at-| gmail . com>
parents: 576
diff changeset
221 return kAudioFileCAFType;
af33b35a55c1 Minor cleanups. Ready to release.
Eric Wing <ewing . public |-at-| gmail . com>
parents: 576
diff changeset
222 }
576
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
223 else
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
224 {
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
225 return 0;
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
226 }
577
af33b35a55c1 Minor cleanups. Ready to release.
Eric Wing <ewing . public |-at-| gmail . com>
parents: 576
diff changeset
227
576
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
228 }
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 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
231 {
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
232 static char return_string[16];
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
233 uint32_t big_endian_code = htonl(error_code);
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
234 char* big_endian_str = (char*)&big_endian_code;
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
235 // 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
236 if(isprint(big_endian_str[0])
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
237 && isprint(big_endian_str[1])
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
238 && isprint(big_endian_str[2])
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
239 && isprint (big_endian_str[3]))
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
240 {
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
241 return_string[0] = '\'';
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
242 return_string[1] = big_endian_str[0];
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
243 return_string[2] = big_endian_str[1];
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
244 return_string[3] = big_endian_str[2];
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
245 return_string[4] = big_endian_str[3];
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
246 return_string[5] = '\'';
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
247 return_string[6] = '\0';
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
248 }
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
249 else if(error_code > -200000 && error_code < 200000)
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 // no, format it as an integer
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
252 snprintf(return_string, 16, "%d", error_code);
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
253 }
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
254 else
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
255 {
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
256 // 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
257 snprintf(return_string, 16, "0x%x", error_code);
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
258 }
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
259 return return_string;
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
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 SInt64 CoreAudio_SizeCallback(void* inClientData)
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
265 {
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
266 SDL_RWops* rw_ops = (SDL_RWops*)inClientData;
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
267 SInt64 current_position = SDL_RWtell(rw_ops);
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
268 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
269 SDL_RWseek(rw_ops, current_position, SEEK_SET);
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
270 // fprintf(stderr, "CoreAudio_SizeCallback:%d\n", end_position);
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 return end_position;
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
273 }
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
274
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
275 OSStatus CoreAudio_ReadCallback(
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
276 void* inClientData,
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
277 SInt64 inPosition,
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
278 UInt32 requestCount,
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
279 void* data_buffer,
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
280 UInt32* actualCount
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 SDL_RWops* rw_ops = (SDL_RWops*)inClientData;
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
284 SDL_RWseek(rw_ops, inPosition, SEEK_SET);
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
285 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
286 // 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
287 // 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
288
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
289 *actualCount = bytes_actually_read;
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
290 return noErr;
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
291 }
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
292
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 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
295 {
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
296 CoreAudioFileContainer* core_audio_file_container;
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
297 AudioFileID* audio_file_id;
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
298 OSStatus error_result;
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
299 Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque;
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
300 AudioStreamBasicDescription actual_format;
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
301 AudioStreamBasicDescription output_format;
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
302 Float64 estimated_duration;
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
303 UInt32 format_size;
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
304
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
305
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
306 core_audio_file_container = (CoreAudioFileContainer*)malloc(sizeof(CoreAudioFileContainer));
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
307 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
308
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
309
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
310 audio_file_id = (AudioFileID*)malloc(sizeof(AudioFileID));
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
311 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
312
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
313 error_result = AudioFileOpenWithCallbacks(
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
314 internal->rw,
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
315 CoreAudio_ReadCallback,
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
316 NULL,
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
317 CoreAudio_SizeCallback,
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
318 NULL,
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
319 CoreAudio_GetAudioTypeForExtension(ext),
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
320 audio_file_id
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
321 );
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
322 if (error_result != noErr)
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
323 {
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
324 AudioFileClose(*audio_file_id);
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
325 free(audio_file_id);
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
326 free(core_audio_file_container);
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
327 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
328 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
329 } /* if */
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
330
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
331 format_size = sizeof(actual_format);
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
332 error_result = AudioFileGetProperty(
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
333 *audio_file_id,
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
334 kAudioFilePropertyDataFormat,
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
335 &format_size,
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
336 &actual_format
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
337 );
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
338 if (error_result != noErr)
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
339 {
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
340 AudioFileClose(*audio_file_id);
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
341 free(audio_file_id);
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
342 free(core_audio_file_container);
577
af33b35a55c1 Minor cleanups. Ready to release.
Eric Wing <ewing . public |-at-| gmail . com>
parents: 576
diff changeset
343 SNDDBG(("Core Audio: AudioFileGetProperty failed. reason: [%s]", CoreAudio_FourCCToString(error_result)));
576
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
344 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
345 } /* if */
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
346
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
347 format_size = sizeof(estimated_duration);
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
348 error_result = AudioFileGetProperty(
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
349 *audio_file_id,
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
350 kAudioFilePropertyEstimatedDuration,
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
351 &format_size,
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
352 &estimated_duration
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
353 );
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
354 if (error_result != noErr)
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
355 {
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
356 AudioFileClose(*audio_file_id);
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
357 free(audio_file_id);
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
358 free(core_audio_file_container);
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
359 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
360 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
361 } /* if */
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
362
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
363
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
364 core_audio_file_container->audioFileID = audio_file_id;
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 internal->decoder_private = core_audio_file_container;
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 sample->flags = SOUND_SAMPLEFLAG_CANSEEK;
577
af33b35a55c1 Minor cleanups. Ready to release.
Eric Wing <ewing . public |-at-| gmail . com>
parents: 576
diff changeset
369 sample->actual.rate = (UInt32) actual_format.mSampleRate;
af33b35a55c1 Minor cleanups. Ready to release.
Eric Wing <ewing . public |-at-| gmail . com>
parents: 576
diff changeset
370 sample->actual.channels = (UInt8)actual_format.mChannelsPerFrame;
af33b35a55c1 Minor cleanups. Ready to release.
Eric Wing <ewing . public |-at-| gmail . com>
parents: 576
diff changeset
371 internal->total_time = (SInt32)(estimated_duration * 1000.0 + 0.5);
576
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
372
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
373 #if 0
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
374 /* 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
375 if(actual_format.mFormatFlags & kAudioFormatFlagIsBigEndian)
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 if(16 == 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_S16MSB;
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_U16MSB;
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 if(8 == actual_format.mBitsPerChannel)
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 if(kAudioFormatFlagIsSignedInteger & actual_format.mFormatFlags)
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
391 {
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
392 sample->actual.format = AUDIO_S8;
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 else
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 sample->actual.format = AUDIO_U8;
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 }
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
399 else // might be 0 for undefined?
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
400 {
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
401 // 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
402 sample->actual.format = AUDIO_S16SYS;
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
403 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
404
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
405 }
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
406 }
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
407 else // little endian
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 if(16 == 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_S16LSB;
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_U16LSB;
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 if(8 == actual_format.mBitsPerChannel)
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 if(kAudioFormatFlagIsSignedInteger & actual_format.mFormatFlags)
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
423 {
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
424 sample->actual.format = AUDIO_S8;
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 else
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 sample->actual.format = AUDIO_U8;
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 else // might be 0 for undefined?
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 sample->actual.format = AUDIO_S16SYS;
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
434
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
435 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
436 }
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
437
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
438 }
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
439 #else
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
440
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 /*
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
444 * 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
445 * 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
446 * 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
447 * as the desired format.
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 sample->actual.format = (sample->desired.format == 0) ?
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
450 AUDIO_S16SYS : sample->desired.format;
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
451 #endif
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
452
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 SNDDBG(("CoreAudio: channels == (%d).\n", sample->actual.channels));
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
455 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
456 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
457 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
458
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
459
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
460
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
461 error_result = ExtAudioFileWrapAudioFileID(*audio_file_id,
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
462 false, // set to false for read-only
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
463 &core_audio_file_container->extAudioFileRef
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
464 );
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
465 if(error_result != noErr)
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
466 {
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
467 AudioFileClose(*audio_file_id);
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
468 free(audio_file_id);
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
469 free(core_audio_file_container);
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
470 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
471 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
472 } /* if */
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
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
475 /* 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
476 * 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
477 * optimal format on iPhone/iPod Touch hardware.
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
478 * 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
479 */
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
480 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
481 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
482 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
483 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
484
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
485 if(sample->desired.format == 0)
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 // do AUDIO_S16SYS
577
af33b35a55c1 Minor cleanups. Ready to release.
Eric Wing <ewing . public |-at-| gmail . com>
parents: 576
diff changeset
488 output_format.mFormatFlags = kAudioFormatFlagsNativeEndian | kAudioFormatFlagIsSignedInteger | kAudioFormatFlagIsPacked; // I seem to read failures problems without kAudioFormatFlagIsPacked. From a mailing list post, this seems to be a Core Audio bug.
576
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
489 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
490 }
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
491 else
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 output_format.mFormatFlags = 0; // clear flags
577
af33b35a55c1 Minor cleanups. Ready to release.
Eric Wing <ewing . public |-at-| gmail . com>
parents: 576
diff changeset
494 output_format.mFormatFlags |= kAudioFormatFlagIsPacked; // I seem to read failures problems without kAudioFormatFlagIsPacked. From a mailing list post, this seems to be a Core Audio bug.
576
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
495 // Mask against bitsize
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
496 if(0xFF & sample->desired.format)
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
497 {
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
498 output_format.mBitsPerChannel = 16; /* 16-bit */
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 output_format.mBitsPerChannel = 8; /* 8-bit */
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
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
505 // Mask for signed/unsigned
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
506 if((1<<15) & sample->desired.format)
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
507 {
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
508 output_format.mFormatFlags = output_format.mFormatFlags | kAudioFormatFlagIsSignedInteger;
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
509
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 else
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 // no flag set for unsigned
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 // Mask for big/little endian
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
516 if((1<<12) & sample->desired.format)
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
517 {
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
518 output_format.mFormatFlags = output_format.mFormatFlags | kAudioFormatFlagIsBigEndian;
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 else
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
521 {
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
522 // no flag set for little endian
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
523 }
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
524 }
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
525
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
526 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
527 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
528
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
529
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 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
532 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
533 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
534 // output_format.mFormatFlags = kAudioFormatFlagsNativeEndian | kAudioFormatFlagIsPacked | kAudioFormatFlagIsSignedInteger;
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
535 output_format.mFormatFlags = kAudioFormatFlagsNativeEndian | kAudioFormatFlagIsSignedInteger;
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
536 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
537 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
538 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
539 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
540 */
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
541 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
542 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
543 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
544 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
545 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
546 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
547 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
548 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
549
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
550
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
551 /* Set the desired client (output) data format */
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
552 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
553 if(noErr != error_result)
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
554 {
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
555 ExtAudioFileDispose(core_audio_file_container->extAudioFileRef);
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
556 AudioFileClose(*audio_file_id);
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
557 free(audio_file_id);
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
558 free(core_audio_file_container);
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
559 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
560 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
561 }
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
562
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 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
565 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
566
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
567
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 /* 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
570 * info will be returned to the user.
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 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
573
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
574
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
575
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
576 return(1);
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
577 } /* CoreAudio_open */
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
578
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
579
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
580 static void CoreAudio_close(Sound_Sample *sample)
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 Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque;
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
583 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
584
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
585 ExtAudioFileDispose(core_audio_file_container->extAudioFileRef);
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
586 AudioFileClose(*core_audio_file_container->audioFileID);
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
587 free(core_audio_file_container->audioFileID);
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
588 free(core_audio_file_container);
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
589
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
590 } /* CoreAudio_close */
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
591
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
592
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
593 static Uint32 CoreAudio_read(Sound_Sample *sample)
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
594 {
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
595 OSStatus error_result = noErr;
577
af33b35a55c1 Minor cleanups. Ready to release.
Eric Wing <ewing . public |-at-| gmail . com>
parents: 576
diff changeset
596 /* Documentation/example shows SInt64, but is problematic for big endian
af33b35a55c1 Minor cleanups. Ready to release.
Eric Wing <ewing . public |-at-| gmail . com>
parents: 576
diff changeset
597 * on 32-bit cast for ExtAudioFileRead() because it takes the upper
af33b35a55c1 Minor cleanups. Ready to release.
Eric Wing <ewing . public |-at-| gmail . com>
parents: 576
diff changeset
598 * bits which turn to 0.
af33b35a55c1 Minor cleanups. Ready to release.
Eric Wing <ewing . public |-at-| gmail . com>
parents: 576
diff changeset
599 */
af33b35a55c1 Minor cleanups. Ready to release.
Eric Wing <ewing . public |-at-| gmail . com>
parents: 576
diff changeset
600 UInt32 buffer_size_in_frames = 0;
af33b35a55c1 Minor cleanups. Ready to release.
Eric Wing <ewing . public |-at-| gmail . com>
parents: 576
diff changeset
601 UInt32 buffer_size_in_frames_remaining = 0;
af33b35a55c1 Minor cleanups. Ready to release.
Eric Wing <ewing . public |-at-| gmail . com>
parents: 576
diff changeset
602 UInt32 total_frames_read = 0;
af33b35a55c1 Minor cleanups. Ready to release.
Eric Wing <ewing . public |-at-| gmail . com>
parents: 576
diff changeset
603 UInt32 data_buffer_size = 0;
af33b35a55c1 Minor cleanups. Ready to release.
Eric Wing <ewing . public |-at-| gmail . com>
parents: 576
diff changeset
604 UInt32 bytes_remaining = 0;
af33b35a55c1 Minor cleanups. Ready to release.
Eric Wing <ewing . public |-at-| gmail . com>
parents: 576
diff changeset
605 size_t total_bytes_read = 0;
576
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
606 Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque;
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
607 CoreAudioFileContainer* core_audio_file_container = (CoreAudioFileContainer *) internal->decoder_private;
577
af33b35a55c1 Minor cleanups. Ready to release.
Eric Wing <ewing . public |-at-| gmail . com>
parents: 576
diff changeset
608 UInt32 max_buffer_size = internal->buffer_size;
576
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
609
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
610 // 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
611 // 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
612
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
613 /* 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
614 /* 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
615 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
616 // 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
617
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
618
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
619 // void* temp_buffer = malloc(max_buffer_size);
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
620
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
621 AudioBufferList audio_buffer_list;
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
622 audio_buffer_list.mNumberBuffers = 1;
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
623 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
624 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
625 audio_buffer_list.mBuffers[0].mData = internal->buffer;
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
626
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
627
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
628 bytes_remaining = max_buffer_size;
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
629 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
630
577
af33b35a55c1 Minor cleanups. Ready to release.
Eric Wing <ewing . public |-at-| gmail . com>
parents: 576
diff changeset
631 // oops. Due to the kAudioFormatFlagIsPacked bug,
af33b35a55c1 Minor cleanups. Ready to release.
Eric Wing <ewing . public |-at-| gmail . com>
parents: 576
diff changeset
632 // I was misled to believe that Core Audio
af33b35a55c1 Minor cleanups. Ready to release.
Eric Wing <ewing . public |-at-| gmail . com>
parents: 576
diff changeset
633 // was not always filling my entire requested buffer.
af33b35a55c1 Minor cleanups. Ready to release.
Eric Wing <ewing . public |-at-| gmail . com>
parents: 576
diff changeset
634 // So this while-loop might be unnecessary.
af33b35a55c1 Minor cleanups. Ready to release.
Eric Wing <ewing . public |-at-| gmail . com>
parents: 576
diff changeset
635 // However, I have not exhaustively tested all formats,
af33b35a55c1 Minor cleanups. Ready to release.
Eric Wing <ewing . public |-at-| gmail . com>
parents: 576
diff changeset
636 // so maybe it is possible this loop is useful.
af33b35a55c1 Minor cleanups. Ready to release.
Eric Wing <ewing . public |-at-| gmail . com>
parents: 576
diff changeset
637 // It might also handle the not-evenly disvisible case above.
576
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
638 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
639 {
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
640
577
af33b35a55c1 Minor cleanups. Ready to release.
Eric Wing <ewing . public |-at-| gmail . com>
parents: 576
diff changeset
641 data_buffer_size = (UInt32)(buffer_size_in_frames * core_audio_file_container->outputFormat->mBytesPerFrame);
576
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
642 // 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
643
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
644 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
645
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
646 // 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
647
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
648
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
649 audio_buffer_list.mBuffers[0].mDataByteSize = bytes_remaining;
577
af33b35a55c1 Minor cleanups. Ready to release.
Eric Wing <ewing . public |-at-| gmail . com>
parents: 576
diff changeset
650 audio_buffer_list.mBuffers[0].mData = &(((UInt8*)internal->buffer)[total_bytes_read]);
576
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
651
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
652
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
653 /* Read the data into an AudioBufferList */
577
af33b35a55c1 Minor cleanups. Ready to release.
Eric Wing <ewing . public |-at-| gmail . com>
parents: 576
diff changeset
654 error_result = ExtAudioFileRead(core_audio_file_container->extAudioFileRef, &buffer_size_in_frames, &audio_buffer_list);
576
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
655 if(error_result == noErr)
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
656 {
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
657
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
658
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
659 /* Success */
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 total_frames_read += buffer_size_in_frames;
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
662 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
663
577
af33b35a55c1 Minor cleanups. Ready to release.
Eric Wing <ewing . public |-at-| gmail . com>
parents: 576
diff changeset
664 // printf("read buffer_size_in_frames=%"PRId64", buffer_size_in_frames_remaining=%"PRId64"\n", buffer_size_in_frames, buffer_size_in_frames_remaining);
576
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
665
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
666 /* ExtAudioFileRead returns the number of frames actually read. Need to convert back to bytes. */
577
af33b35a55c1 Minor cleanups. Ready to release.
Eric Wing <ewing . public |-at-| gmail . com>
parents: 576
diff changeset
667 data_buffer_size = (UInt32)(buffer_size_in_frames * core_audio_file_container->outputFormat->mBytesPerFrame);
576
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
668 // 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
669
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
670 total_bytes_read += data_buffer_size;
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
671 bytes_remaining = bytes_remaining - data_buffer_size;
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
672
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
673 /* 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
674 if(0 == buffer_size_in_frames)
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 sample->flags |= SOUND_SAMPLEFLAG_EOF;
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
677 }
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
678
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
679 }
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
680 else
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 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
683
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
684 sample->flags |= SOUND_SAMPLEFLAG_ERROR;
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
685 break;
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
686
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
687 }
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
688 }
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
689
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
690 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
691 {
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
692 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
693
577
af33b35a55c1 Minor cleanups. Ready to release.
Eric Wing <ewing . public |-at-| gmail . com>
parents: 576
diff changeset
694 /* Don't know what to do here. */
576
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
695 sample->flags |= SOUND_SAMPLEFLAG_EAGAIN;
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 return total_bytes_read;
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
698 } /* CoreAudio_read */
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
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
701 static int CoreAudio_rewind(Sound_Sample *sample)
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
702 {
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
703 OSStatus error_result = noErr;
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
704 Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque;
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
705 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
706
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
707 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
708 if(error_result != noErr)
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
709 {
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
710 sample->flags |= SOUND_SAMPLEFLAG_ERROR;
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
711 }
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
712 return(1);
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
713 } /* CoreAudio_rewind */
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
714
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
715
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
716 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
717 {
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
718 OSStatus error_result = noErr;
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
719 Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque;
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
720 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
721 SInt64 frame_offset = 0;
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
722 AudioStreamBasicDescription actual_format;
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
723 UInt32 format_size;
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
724
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
725 format_size = sizeof(AudioStreamBasicDescription);
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
726 error_result = AudioFileGetProperty(
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
727 *core_audio_file_container->audioFileID,
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
728 kAudioFilePropertyDataFormat,
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
729 &format_size,
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
730 &actual_format
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 if(error_result != noErr)
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 sample->flags |= SOUND_SAMPLEFLAG_ERROR;
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
735 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
736 } /* if */
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
737
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
738 // packetIndex = (pos * sampleRate) / framesPerPacket
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
739 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
740 // 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
741 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
742 if(error_result != noErr)
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
743 {
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
744 sample->flags |= SOUND_SAMPLEFLAG_ERROR;
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
745 }
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
746
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
747 return(1);
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
748 } /* CoreAudio_seek */
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
749
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
750 #endif /* SOUND_SUPPORTS_COREAUDIO */
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
751
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
752
577
af33b35a55c1 Minor cleanups. Ready to release.
Eric Wing <ewing . public |-at-| gmail . com>
parents: 576
diff changeset
753 /* end of coreaudio.c ... */
576
8d62447b75f2 Added new Core Audio backend.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
754