annotate libao2/ao_macosx.c @ 19911:2ca75d2fbcc6

removed old dvdnav_event definitions
author nicodvb
date Tue, 19 Sep 2006 22:59:05 +0000
parents ada359817b61
children 2d786b7625d7
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
10147
f2725d6717bd Native MacOSX audio output by Dan Christiansen <danchr@daimi.au.dk>
alex
parents:
diff changeset
1 /*
f2725d6717bd Native MacOSX audio output by Dan Christiansen <danchr@daimi.au.dk>
alex
parents:
diff changeset
2 *
f2725d6717bd Native MacOSX audio output by Dan Christiansen <danchr@daimi.au.dk>
alex
parents:
diff changeset
3 * ao_macosx.c
f2725d6717bd Native MacOSX audio output by Dan Christiansen <danchr@daimi.au.dk>
alex
parents:
diff changeset
4 *
f2725d6717bd Native MacOSX audio output by Dan Christiansen <danchr@daimi.au.dk>
alex
parents:
diff changeset
5 * Original Copyright (C) Timothy J. Wood - Aug 2000
f2725d6717bd Native MacOSX audio output by Dan Christiansen <danchr@daimi.au.dk>
alex
parents:
diff changeset
6 *
f2725d6717bd Native MacOSX audio output by Dan Christiansen <danchr@daimi.au.dk>
alex
parents:
diff changeset
7 * This file is part of libao, a cross-platform library. See
f2725d6717bd Native MacOSX audio output by Dan Christiansen <danchr@daimi.au.dk>
alex
parents:
diff changeset
8 * README for a history of this source code.
f2725d6717bd Native MacOSX audio output by Dan Christiansen <danchr@daimi.au.dk>
alex
parents:
diff changeset
9 *
f2725d6717bd Native MacOSX audio output by Dan Christiansen <danchr@daimi.au.dk>
alex
parents:
diff changeset
10 * libao is free software; you can redistribute it and/or modify
f2725d6717bd Native MacOSX audio output by Dan Christiansen <danchr@daimi.au.dk>
alex
parents:
diff changeset
11 * it under the terms of the GNU General Public License as published by
f2725d6717bd Native MacOSX audio output by Dan Christiansen <danchr@daimi.au.dk>
alex
parents:
diff changeset
12 * the Free Software Foundation; either version 2, or (at your option)
f2725d6717bd Native MacOSX audio output by Dan Christiansen <danchr@daimi.au.dk>
alex
parents:
diff changeset
13 * any later version.
f2725d6717bd Native MacOSX audio output by Dan Christiansen <danchr@daimi.au.dk>
alex
parents:
diff changeset
14 *
f2725d6717bd Native MacOSX audio output by Dan Christiansen <danchr@daimi.au.dk>
alex
parents:
diff changeset
15 * libao is distributed in the hope that it will be useful,
f2725d6717bd Native MacOSX audio output by Dan Christiansen <danchr@daimi.au.dk>
alex
parents:
diff changeset
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
f2725d6717bd Native MacOSX audio output by Dan Christiansen <danchr@daimi.au.dk>
alex
parents:
diff changeset
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
f2725d6717bd Native MacOSX audio output by Dan Christiansen <danchr@daimi.au.dk>
alex
parents:
diff changeset
18 * GNU General Public License for more details.
f2725d6717bd Native MacOSX audio output by Dan Christiansen <danchr@daimi.au.dk>
alex
parents:
diff changeset
19 *
f2725d6717bd Native MacOSX audio output by Dan Christiansen <danchr@daimi.au.dk>
alex
parents:
diff changeset
20 * You should have received a copy of the GNU General Public License
f2725d6717bd Native MacOSX audio output by Dan Christiansen <danchr@daimi.au.dk>
alex
parents:
diff changeset
21 * along with GNU Make; see the file COPYING. If not, write to
f2725d6717bd Native MacOSX audio output by Dan Christiansen <danchr@daimi.au.dk>
alex
parents:
diff changeset
22 * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
f2725d6717bd Native MacOSX audio output by Dan Christiansen <danchr@daimi.au.dk>
alex
parents:
diff changeset
23 */
f2725d6717bd Native MacOSX audio output by Dan Christiansen <danchr@daimi.au.dk>
alex
parents:
diff changeset
24
f2725d6717bd Native MacOSX audio output by Dan Christiansen <danchr@daimi.au.dk>
alex
parents:
diff changeset
25 /*
f2725d6717bd Native MacOSX audio output by Dan Christiansen <danchr@daimi.au.dk>
alex
parents:
diff changeset
26 * The MacOS X CoreAudio framework doesn't mesh as simply as some
f2725d6717bd Native MacOSX audio output by Dan Christiansen <danchr@daimi.au.dk>
alex
parents:
diff changeset
27 * simpler frameworks do. This is due to the fact that CoreAudio pulls
f2725d6717bd Native MacOSX audio output by Dan Christiansen <danchr@daimi.au.dk>
alex
parents:
diff changeset
28 * audio samples rather than having them pushed at it (which is nice
f2725d6717bd Native MacOSX audio output by Dan Christiansen <danchr@daimi.au.dk>
alex
parents:
diff changeset
29 * when you are wanting to do good buffering of audio).
f2725d6717bd Native MacOSX audio output by Dan Christiansen <danchr@daimi.au.dk>
alex
parents:
diff changeset
30 */
f2725d6717bd Native MacOSX audio output by Dan Christiansen <danchr@daimi.au.dk>
alex
parents:
diff changeset
31
f2725d6717bd Native MacOSX audio output by Dan Christiansen <danchr@daimi.au.dk>
alex
parents:
diff changeset
32 /* Change log:
f2725d6717bd Native MacOSX audio output by Dan Christiansen <danchr@daimi.au.dk>
alex
parents:
diff changeset
33 *
f2725d6717bd Native MacOSX audio output by Dan Christiansen <danchr@daimi.au.dk>
alex
parents:
diff changeset
34 * 14/5-2003: Ported to MPlayer libao2 by Dan Christiansen
f2725d6717bd Native MacOSX audio output by Dan Christiansen <danchr@daimi.au.dk>
alex
parents:
diff changeset
35 *
f2725d6717bd Native MacOSX audio output by Dan Christiansen <danchr@daimi.au.dk>
alex
parents:
diff changeset
36 * AC-3 and MPEG audio passthrough is possible, but I don't have
f2725d6717bd Native MacOSX audio output by Dan Christiansen <danchr@daimi.au.dk>
alex
parents:
diff changeset
37 * access to a sound card that supports it.
f2725d6717bd Native MacOSX audio output by Dan Christiansen <danchr@daimi.au.dk>
alex
parents:
diff changeset
38 */
f2725d6717bd Native MacOSX audio output by Dan Christiansen <danchr@daimi.au.dk>
alex
parents:
diff changeset
39
15646
f46eae5e271b Mac OS X Audio with AudioUnits and AudioToolbox format converters, Patch by Chris Roccati<roccati@pobox.com
nplourde
parents: 15486
diff changeset
40 #include <CoreServices/CoreServices.h>
f46eae5e271b Mac OS X Audio with AudioUnits and AudioToolbox format converters, Patch by Chris Roccati<roccati@pobox.com
nplourde
parents: 15486
diff changeset
41 #include <AudioUnit/AudioUnit.h>
f46eae5e271b Mac OS X Audio with AudioUnits and AudioToolbox format converters, Patch by Chris Roccati<roccati@pobox.com
nplourde
parents: 15486
diff changeset
42 #include <AudioToolbox/AudioToolbox.h>
10147
f2725d6717bd Native MacOSX audio output by Dan Christiansen <danchr@daimi.au.dk>
alex
parents:
diff changeset
43 #include <stdio.h>
f2725d6717bd Native MacOSX audio output by Dan Christiansen <danchr@daimi.au.dk>
alex
parents:
diff changeset
44 #include <string.h>
14903
21f44596f356 do not always request little-endian despite the actual sound format. by Alexander Strange - astrange@ithinksw.com
nplourde
parents: 14769
diff changeset
45 #include <stdlib.h>
10147
f2725d6717bd Native MacOSX audio output by Dan Christiansen <danchr@daimi.au.dk>
alex
parents:
diff changeset
46 #include <inttypes.h>
f2725d6717bd Native MacOSX audio output by Dan Christiansen <danchr@daimi.au.dk>
alex
parents:
diff changeset
47 #include <pthread.h>
f2725d6717bd Native MacOSX audio output by Dan Christiansen <danchr@daimi.au.dk>
alex
parents:
diff changeset
48
14479
cae0dbeb44bb af_format.h needs config.h to be included first.
reimar
parents: 14317
diff changeset
49 #include "config.h"
14123
a92101a7eb49 Make include paths consistent.
diego
parents: 13651
diff changeset
50 #include "mp_msg.h"
10147
f2725d6717bd Native MacOSX audio output by Dan Christiansen <danchr@daimi.au.dk>
alex
parents:
diff changeset
51
f2725d6717bd Native MacOSX audio output by Dan Christiansen <danchr@daimi.au.dk>
alex
parents:
diff changeset
52 #include "audio_out.h"
f2725d6717bd Native MacOSX audio output by Dan Christiansen <danchr@daimi.au.dk>
alex
parents:
diff changeset
53 #include "audio_out_internal.h"
14245
815f03b7cee5 removing AFMT_ dependancy
alex
parents: 14123
diff changeset
54 #include "libaf/af_format.h"
10147
f2725d6717bd Native MacOSX audio output by Dan Christiansen <danchr@daimi.au.dk>
alex
parents:
diff changeset
55
f2725d6717bd Native MacOSX audio output by Dan Christiansen <danchr@daimi.au.dk>
alex
parents:
diff changeset
56 static ao_info_t info =
f2725d6717bd Native MacOSX audio output by Dan Christiansen <danchr@daimi.au.dk>
alex
parents:
diff changeset
57 {
f2725d6717bd Native MacOSX audio output by Dan Christiansen <danchr@daimi.au.dk>
alex
parents:
diff changeset
58 "Darwin/Mac OS X native audio output",
f2725d6717bd Native MacOSX audio output by Dan Christiansen <danchr@daimi.au.dk>
alex
parents:
diff changeset
59 "macosx",
15646
f46eae5e271b Mac OS X Audio with AudioUnits and AudioToolbox format converters, Patch by Chris Roccati<roccati@pobox.com
nplourde
parents: 15486
diff changeset
60 "Timothy J. Wood & Dan Christiansen & Chris Roccati",
10147
f2725d6717bd Native MacOSX audio output by Dan Christiansen <danchr@daimi.au.dk>
alex
parents:
diff changeset
61 ""
f2725d6717bd Native MacOSX audio output by Dan Christiansen <danchr@daimi.au.dk>
alex
parents:
diff changeset
62 };
f2725d6717bd Native MacOSX audio output by Dan Christiansen <danchr@daimi.au.dk>
alex
parents:
diff changeset
63
f2725d6717bd Native MacOSX audio output by Dan Christiansen <danchr@daimi.au.dk>
alex
parents:
diff changeset
64 LIBAO_EXTERN(macosx)
f2725d6717bd Native MacOSX audio output by Dan Christiansen <danchr@daimi.au.dk>
alex
parents:
diff changeset
65
10152
b252d1b6829e cleanup/cosmetic patch by the author :)
alex
parents: 10147
diff changeset
66 /* Prefix for all mp_msg() calls */
b252d1b6829e cleanup/cosmetic patch by the author :)
alex
parents: 10147
diff changeset
67 #define ao_msg(a, b, c...) mp_msg(a, b, "AO: [macosx] " c)
b252d1b6829e cleanup/cosmetic patch by the author :)
alex
parents: 10147
diff changeset
68
10147
f2725d6717bd Native MacOSX audio output by Dan Christiansen <danchr@daimi.au.dk>
alex
parents:
diff changeset
69 /* This is large, but best (maybe it should be even larger).
f2725d6717bd Native MacOSX audio output by Dan Christiansen <danchr@daimi.au.dk>
alex
parents:
diff changeset
70 * CoreAudio supposedly has an internal latency in the order of 2ms */
14290
488651c51aa3 rate/format matching and volume get/set support
arpi
parents: 14245
diff changeset
71 #define NUM_BUFS 32
10147
f2725d6717bd Native MacOSX audio output by Dan Christiansen <danchr@daimi.au.dk>
alex
parents:
diff changeset
72
f2725d6717bd Native MacOSX audio output by Dan Christiansen <danchr@daimi.au.dk>
alex
parents:
diff changeset
73 typedef struct ao_macosx_s
f2725d6717bd Native MacOSX audio output by Dan Christiansen <danchr@daimi.au.dk>
alex
parents:
diff changeset
74 {
15646
f46eae5e271b Mac OS X Audio with AudioUnits and AudioToolbox format converters, Patch by Chris Roccati<roccati@pobox.com
nplourde
parents: 15486
diff changeset
75 /* AudioUnit */
f46eae5e271b Mac OS X Audio with AudioUnits and AudioToolbox format converters, Patch by Chris Roccati<roccati@pobox.com
nplourde
parents: 15486
diff changeset
76 AudioUnit theOutputUnit;
f46eae5e271b Mac OS X Audio with AudioUnits and AudioToolbox format converters, Patch by Chris Roccati<roccati@pobox.com
nplourde
parents: 15486
diff changeset
77 int packetSize;
19427
ada359817b61 fix buffering issues with short audio samples on macosx. patch by Chris Roccati <roccati@pobox.com>
nplourde
parents: 18915
diff changeset
78 int paused;
10147
f2725d6717bd Native MacOSX audio output by Dan Christiansen <danchr@daimi.au.dk>
alex
parents:
diff changeset
79
f2725d6717bd Native MacOSX audio output by Dan Christiansen <danchr@daimi.au.dk>
alex
parents:
diff changeset
80 /* Ring-buffer */
14769
e701873aa8ca rids ao_macosx of the buffer mutex by using the same buffering scheme as ao_sdl - Patch by Reimar Doffinger
nplourde
parents: 14642
diff changeset
81 /* does not need explicit synchronization, but needs to allocate
e701873aa8ca rids ao_macosx of the buffer mutex by using the same buffering scheme as ao_sdl - Patch by Reimar Doffinger
nplourde
parents: 14642
diff changeset
82 * (num_chunks + 1) * chunk_size memory to store num_chunks * chunk_size
e701873aa8ca rids ao_macosx of the buffer mutex by using the same buffering scheme as ao_sdl - Patch by Reimar Doffinger
nplourde
parents: 14642
diff changeset
83 * data */
e701873aa8ca rids ao_macosx of the buffer mutex by using the same buffering scheme as ao_sdl - Patch by Reimar Doffinger
nplourde
parents: 14642
diff changeset
84 unsigned char *buffer;
e701873aa8ca rids ao_macosx of the buffer mutex by using the same buffering scheme as ao_sdl - Patch by Reimar Doffinger
nplourde
parents: 14642
diff changeset
85 unsigned int buffer_len; ///< must always be (num_chunks + 1) * chunk_size
e701873aa8ca rids ao_macosx of the buffer mutex by using the same buffering scheme as ao_sdl - Patch by Reimar Doffinger
nplourde
parents: 14642
diff changeset
86 unsigned int num_chunks;
e701873aa8ca rids ao_macosx of the buffer mutex by using the same buffering scheme as ao_sdl - Patch by Reimar Doffinger
nplourde
parents: 14642
diff changeset
87 unsigned int chunk_size;
10147
f2725d6717bd Native MacOSX audio output by Dan Christiansen <danchr@daimi.au.dk>
alex
parents:
diff changeset
88
f2725d6717bd Native MacOSX audio output by Dan Christiansen <danchr@daimi.au.dk>
alex
parents:
diff changeset
89 unsigned int buf_read_pos;
f2725d6717bd Native MacOSX audio output by Dan Christiansen <danchr@daimi.au.dk>
alex
parents:
diff changeset
90 unsigned int buf_write_pos;
f2725d6717bd Native MacOSX audio output by Dan Christiansen <danchr@daimi.au.dk>
alex
parents:
diff changeset
91 } ao_macosx_t;
f2725d6717bd Native MacOSX audio output by Dan Christiansen <danchr@daimi.au.dk>
alex
parents:
diff changeset
92
15853
6e994905f77b more general ao_macosx cleanup. Patch by Alexander Strange <astrange@ithinksw.com>
nplourde
parents: 15722
diff changeset
93 static ao_macosx_t *ao = NULL;
10147
f2725d6717bd Native MacOSX audio output by Dan Christiansen <danchr@daimi.au.dk>
alex
parents:
diff changeset
94
14769
e701873aa8ca rids ao_macosx of the buffer mutex by using the same buffering scheme as ao_sdl - Patch by Reimar Doffinger
nplourde
parents: 14642
diff changeset
95 /**
e701873aa8ca rids ao_macosx of the buffer mutex by using the same buffering scheme as ao_sdl - Patch by Reimar Doffinger
nplourde
parents: 14642
diff changeset
96 * \brief return number of free bytes in the buffer
e701873aa8ca rids ao_macosx of the buffer mutex by using the same buffering scheme as ao_sdl - Patch by Reimar Doffinger
nplourde
parents: 14642
diff changeset
97 * may only be called by mplayer's thread
e701873aa8ca rids ao_macosx of the buffer mutex by using the same buffering scheme as ao_sdl - Patch by Reimar Doffinger
nplourde
parents: 14642
diff changeset
98 * \return minimum number of free bytes in buffer, value may change between
e701873aa8ca rids ao_macosx of the buffer mutex by using the same buffering scheme as ao_sdl - Patch by Reimar Doffinger
nplourde
parents: 14642
diff changeset
99 * two immediately following calls, and the real number of free bytes
e701873aa8ca rids ao_macosx of the buffer mutex by using the same buffering scheme as ao_sdl - Patch by Reimar Doffinger
nplourde
parents: 14642
diff changeset
100 * might actually be larger!
e701873aa8ca rids ao_macosx of the buffer mutex by using the same buffering scheme as ao_sdl - Patch by Reimar Doffinger
nplourde
parents: 14642
diff changeset
101 */
18915
99e20a22d5d0 modifies function declarations without parameters from ()
reynaldo
parents: 18885
diff changeset
102 static int buf_free(void) {
14769
e701873aa8ca rids ao_macosx of the buffer mutex by using the same buffering scheme as ao_sdl - Patch by Reimar Doffinger
nplourde
parents: 14642
diff changeset
103 int free = ao->buf_read_pos - ao->buf_write_pos - ao->chunk_size;
e701873aa8ca rids ao_macosx of the buffer mutex by using the same buffering scheme as ao_sdl - Patch by Reimar Doffinger
nplourde
parents: 14642
diff changeset
104 if (free < 0) free += ao->buffer_len;
e701873aa8ca rids ao_macosx of the buffer mutex by using the same buffering scheme as ao_sdl - Patch by Reimar Doffinger
nplourde
parents: 14642
diff changeset
105 return free;
e701873aa8ca rids ao_macosx of the buffer mutex by using the same buffering scheme as ao_sdl - Patch by Reimar Doffinger
nplourde
parents: 14642
diff changeset
106 }
10147
f2725d6717bd Native MacOSX audio output by Dan Christiansen <danchr@daimi.au.dk>
alex
parents:
diff changeset
107
14769
e701873aa8ca rids ao_macosx of the buffer mutex by using the same buffering scheme as ao_sdl - Patch by Reimar Doffinger
nplourde
parents: 14642
diff changeset
108 /**
e701873aa8ca rids ao_macosx of the buffer mutex by using the same buffering scheme as ao_sdl - Patch by Reimar Doffinger
nplourde
parents: 14642
diff changeset
109 * \brief return number of buffered bytes
e701873aa8ca rids ao_macosx of the buffer mutex by using the same buffering scheme as ao_sdl - Patch by Reimar Doffinger
nplourde
parents: 14642
diff changeset
110 * may only be called by playback thread
e701873aa8ca rids ao_macosx of the buffer mutex by using the same buffering scheme as ao_sdl - Patch by Reimar Doffinger
nplourde
parents: 14642
diff changeset
111 * \return minimum number of buffered bytes, value may change between
e701873aa8ca rids ao_macosx of the buffer mutex by using the same buffering scheme as ao_sdl - Patch by Reimar Doffinger
nplourde
parents: 14642
diff changeset
112 * two immediately following calls, and the real number of buffered bytes
e701873aa8ca rids ao_macosx of the buffer mutex by using the same buffering scheme as ao_sdl - Patch by Reimar Doffinger
nplourde
parents: 14642
diff changeset
113 * might actually be larger!
e701873aa8ca rids ao_macosx of the buffer mutex by using the same buffering scheme as ao_sdl - Patch by Reimar Doffinger
nplourde
parents: 14642
diff changeset
114 */
18915
99e20a22d5d0 modifies function declarations without parameters from ()
reynaldo
parents: 18885
diff changeset
115 static int buf_used(void) {
14769
e701873aa8ca rids ao_macosx of the buffer mutex by using the same buffering scheme as ao_sdl - Patch by Reimar Doffinger
nplourde
parents: 14642
diff changeset
116 int used = ao->buf_write_pos - ao->buf_read_pos;
e701873aa8ca rids ao_macosx of the buffer mutex by using the same buffering scheme as ao_sdl - Patch by Reimar Doffinger
nplourde
parents: 14642
diff changeset
117 if (used < 0) used += ao->buffer_len;
e701873aa8ca rids ao_macosx of the buffer mutex by using the same buffering scheme as ao_sdl - Patch by Reimar Doffinger
nplourde
parents: 14642
diff changeset
118 return used;
10147
f2725d6717bd Native MacOSX audio output by Dan Christiansen <danchr@daimi.au.dk>
alex
parents:
diff changeset
119 }
f2725d6717bd Native MacOSX audio output by Dan Christiansen <danchr@daimi.au.dk>
alex
parents:
diff changeset
120
14769
e701873aa8ca rids ao_macosx of the buffer mutex by using the same buffering scheme as ao_sdl - Patch by Reimar Doffinger
nplourde
parents: 14642
diff changeset
121 /**
e701873aa8ca rids ao_macosx of the buffer mutex by using the same buffering scheme as ao_sdl - Patch by Reimar Doffinger
nplourde
parents: 14642
diff changeset
122 * \brief add data to ringbuffer
e701873aa8ca rids ao_macosx of the buffer mutex by using the same buffering scheme as ao_sdl - Patch by Reimar Doffinger
nplourde
parents: 14642
diff changeset
123 */
e701873aa8ca rids ao_macosx of the buffer mutex by using the same buffering scheme as ao_sdl - Patch by Reimar Doffinger
nplourde
parents: 14642
diff changeset
124 static int write_buffer(unsigned char* data, int len){
e701873aa8ca rids ao_macosx of the buffer mutex by using the same buffering scheme as ao_sdl - Patch by Reimar Doffinger
nplourde
parents: 14642
diff changeset
125 int first_len = ao->buffer_len - ao->buf_write_pos;
e701873aa8ca rids ao_macosx of the buffer mutex by using the same buffering scheme as ao_sdl - Patch by Reimar Doffinger
nplourde
parents: 14642
diff changeset
126 int free = buf_free();
e701873aa8ca rids ao_macosx of the buffer mutex by using the same buffering scheme as ao_sdl - Patch by Reimar Doffinger
nplourde
parents: 14642
diff changeset
127 if (len > free) len = free;
e701873aa8ca rids ao_macosx of the buffer mutex by using the same buffering scheme as ao_sdl - Patch by Reimar Doffinger
nplourde
parents: 14642
diff changeset
128 if (first_len > len) first_len = len;
e701873aa8ca rids ao_macosx of the buffer mutex by using the same buffering scheme as ao_sdl - Patch by Reimar Doffinger
nplourde
parents: 14642
diff changeset
129 // till end of buffer
e701873aa8ca rids ao_macosx of the buffer mutex by using the same buffering scheme as ao_sdl - Patch by Reimar Doffinger
nplourde
parents: 14642
diff changeset
130 memcpy (&ao->buffer[ao->buf_write_pos], data, first_len);
e701873aa8ca rids ao_macosx of the buffer mutex by using the same buffering scheme as ao_sdl - Patch by Reimar Doffinger
nplourde
parents: 14642
diff changeset
131 if (len > first_len) { // we have to wrap around
e701873aa8ca rids ao_macosx of the buffer mutex by using the same buffering scheme as ao_sdl - Patch by Reimar Doffinger
nplourde
parents: 14642
diff changeset
132 // remaining part from beginning of buffer
e701873aa8ca rids ao_macosx of the buffer mutex by using the same buffering scheme as ao_sdl - Patch by Reimar Doffinger
nplourde
parents: 14642
diff changeset
133 memcpy (ao->buffer, &data[first_len], len - first_len);
e701873aa8ca rids ao_macosx of the buffer mutex by using the same buffering scheme as ao_sdl - Patch by Reimar Doffinger
nplourde
parents: 14642
diff changeset
134 }
e701873aa8ca rids ao_macosx of the buffer mutex by using the same buffering scheme as ao_sdl - Patch by Reimar Doffinger
nplourde
parents: 14642
diff changeset
135 ao->buf_write_pos = (ao->buf_write_pos + len) % ao->buffer_len;
e701873aa8ca rids ao_macosx of the buffer mutex by using the same buffering scheme as ao_sdl - Patch by Reimar Doffinger
nplourde
parents: 14642
diff changeset
136 return len;
e701873aa8ca rids ao_macosx of the buffer mutex by using the same buffering scheme as ao_sdl - Patch by Reimar Doffinger
nplourde
parents: 14642
diff changeset
137 }
10147
f2725d6717bd Native MacOSX audio output by Dan Christiansen <danchr@daimi.au.dk>
alex
parents:
diff changeset
138
14769
e701873aa8ca rids ao_macosx of the buffer mutex by using the same buffering scheme as ao_sdl - Patch by Reimar Doffinger
nplourde
parents: 14642
diff changeset
139 /**
e701873aa8ca rids ao_macosx of the buffer mutex by using the same buffering scheme as ao_sdl - Patch by Reimar Doffinger
nplourde
parents: 14642
diff changeset
140 * \brief remove data from ringbuffer
e701873aa8ca rids ao_macosx of the buffer mutex by using the same buffering scheme as ao_sdl - Patch by Reimar Doffinger
nplourde
parents: 14642
diff changeset
141 */
e701873aa8ca rids ao_macosx of the buffer mutex by using the same buffering scheme as ao_sdl - Patch by Reimar Doffinger
nplourde
parents: 14642
diff changeset
142 static int read_buffer(unsigned char* data,int len){
e701873aa8ca rids ao_macosx of the buffer mutex by using the same buffering scheme as ao_sdl - Patch by Reimar Doffinger
nplourde
parents: 14642
diff changeset
143 int first_len = ao->buffer_len - ao->buf_read_pos;
e701873aa8ca rids ao_macosx of the buffer mutex by using the same buffering scheme as ao_sdl - Patch by Reimar Doffinger
nplourde
parents: 14642
diff changeset
144 int buffered = buf_used();
e701873aa8ca rids ao_macosx of the buffer mutex by using the same buffering scheme as ao_sdl - Patch by Reimar Doffinger
nplourde
parents: 14642
diff changeset
145 if (len > buffered) len = buffered;
e701873aa8ca rids ao_macosx of the buffer mutex by using the same buffering scheme as ao_sdl - Patch by Reimar Doffinger
nplourde
parents: 14642
diff changeset
146 if (first_len > len) first_len = len;
e701873aa8ca rids ao_macosx of the buffer mutex by using the same buffering scheme as ao_sdl - Patch by Reimar Doffinger
nplourde
parents: 14642
diff changeset
147 // till end of buffer
e701873aa8ca rids ao_macosx of the buffer mutex by using the same buffering scheme as ao_sdl - Patch by Reimar Doffinger
nplourde
parents: 14642
diff changeset
148 memcpy (data, &ao->buffer[ao->buf_read_pos], first_len);
e701873aa8ca rids ao_macosx of the buffer mutex by using the same buffering scheme as ao_sdl - Patch by Reimar Doffinger
nplourde
parents: 14642
diff changeset
149 if (len > first_len) { // we have to wrap around
e701873aa8ca rids ao_macosx of the buffer mutex by using the same buffering scheme as ao_sdl - Patch by Reimar Doffinger
nplourde
parents: 14642
diff changeset
150 // remaining part from beginning of buffer
e701873aa8ca rids ao_macosx of the buffer mutex by using the same buffering scheme as ao_sdl - Patch by Reimar Doffinger
nplourde
parents: 14642
diff changeset
151 memcpy (&data[first_len], ao->buffer, len - first_len);
10147
f2725d6717bd Native MacOSX audio output by Dan Christiansen <danchr@daimi.au.dk>
alex
parents:
diff changeset
152 }
14769
e701873aa8ca rids ao_macosx of the buffer mutex by using the same buffering scheme as ao_sdl - Patch by Reimar Doffinger
nplourde
parents: 14642
diff changeset
153 ao->buf_read_pos = (ao->buf_read_pos + len) % ao->buffer_len;
e701873aa8ca rids ao_macosx of the buffer mutex by using the same buffering scheme as ao_sdl - Patch by Reimar Doffinger
nplourde
parents: 14642
diff changeset
154 return len;
10147
f2725d6717bd Native MacOSX audio output by Dan Christiansen <danchr@daimi.au.dk>
alex
parents:
diff changeset
155 }
f2725d6717bd Native MacOSX audio output by Dan Christiansen <danchr@daimi.au.dk>
alex
parents:
diff changeset
156
15722
b53c4b26dc96 removes the use of AudioConverters. patch by Alexander Strange <alexander.strange@ithinksw.com>
nplourde
parents: 15646
diff changeset
157 OSStatus theRenderProc(void *inRefCon, AudioUnitRenderActionFlags *inActionFlags, const AudioTimeStamp *inTimeStamp, UInt32 inBusNumber, UInt32 inNumFrames, AudioBufferList *ioData)
10147
f2725d6717bd Native MacOSX audio output by Dan Christiansen <danchr@daimi.au.dk>
alex
parents:
diff changeset
158 {
15646
f46eae5e271b Mac OS X Audio with AudioUnits and AudioToolbox format converters, Patch by Chris Roccati<roccati@pobox.com
nplourde
parents: 15486
diff changeset
159 int amt=buf_used();
15722
b53c4b26dc96 removes the use of AudioConverters. patch by Alexander Strange <alexander.strange@ithinksw.com>
nplourde
parents: 15646
diff changeset
160 int req=(inNumFrames)*ao->packetSize;
15646
f46eae5e271b Mac OS X Audio with AudioUnits and AudioToolbox format converters, Patch by Chris Roccati<roccati@pobox.com
nplourde
parents: 15486
diff changeset
161
f46eae5e271b Mac OS X Audio with AudioUnits and AudioToolbox format converters, Patch by Chris Roccati<roccati@pobox.com
nplourde
parents: 15486
diff changeset
162 if(amt>req)
f46eae5e271b Mac OS X Audio with AudioUnits and AudioToolbox format converters, Patch by Chris Roccati<roccati@pobox.com
nplourde
parents: 15486
diff changeset
163 amt=req;
f46eae5e271b Mac OS X Audio with AudioUnits and AudioToolbox format converters, Patch by Chris Roccati<roccati@pobox.com
nplourde
parents: 15486
diff changeset
164
f46eae5e271b Mac OS X Audio with AudioUnits and AudioToolbox format converters, Patch by Chris Roccati<roccati@pobox.com
nplourde
parents: 15486
diff changeset
165 if(amt)
f46eae5e271b Mac OS X Audio with AudioUnits and AudioToolbox format converters, Patch by Chris Roccati<roccati@pobox.com
nplourde
parents: 15486
diff changeset
166 read_buffer((unsigned char *)ioData->mBuffers[0].mData, amt);
15853
6e994905f77b more general ao_macosx cleanup. Patch by Alexander Strange <astrange@ithinksw.com>
nplourde
parents: 15722
diff changeset
167 else audio_pause();
15722
b53c4b26dc96 removes the use of AudioConverters. patch by Alexander Strange <alexander.strange@ithinksw.com>
nplourde
parents: 15646
diff changeset
168 ioData->mBuffers[0].mDataByteSize = amt;
15646
f46eae5e271b Mac OS X Audio with AudioUnits and AudioToolbox format converters, Patch by Chris Roccati<roccati@pobox.com
nplourde
parents: 15486
diff changeset
169
f46eae5e271b Mac OS X Audio with AudioUnits and AudioToolbox format converters, Patch by Chris Roccati<roccati@pobox.com
nplourde
parents: 15486
diff changeset
170 return noErr;
10147
f2725d6717bd Native MacOSX audio output by Dan Christiansen <danchr@daimi.au.dk>
alex
parents:
diff changeset
171 }
f2725d6717bd Native MacOSX audio output by Dan Christiansen <danchr@daimi.au.dk>
alex
parents:
diff changeset
172
f2725d6717bd Native MacOSX audio output by Dan Christiansen <danchr@daimi.au.dk>
alex
parents:
diff changeset
173 static int control(int cmd,void *arg){
f2725d6717bd Native MacOSX audio output by Dan Christiansen <danchr@daimi.au.dk>
alex
parents:
diff changeset
174 switch (cmd) {
f2725d6717bd Native MacOSX audio output by Dan Christiansen <danchr@daimi.au.dk>
alex
parents:
diff changeset
175 case AOCONTROL_SET_DEVICE:
f2725d6717bd Native MacOSX audio output by Dan Christiansen <danchr@daimi.au.dk>
alex
parents:
diff changeset
176 case AOCONTROL_GET_DEVICE:
14290
488651c51aa3 rate/format matching and volume get/set support
arpi
parents: 14245
diff changeset
177 case AOCONTROL_GET_VOLUME:
488651c51aa3 rate/format matching and volume get/set support
arpi
parents: 14245
diff changeset
178 case AOCONTROL_SET_VOLUME:
15646
f46eae5e271b Mac OS X Audio with AudioUnits and AudioToolbox format converters, Patch by Chris Roccati<roccati@pobox.com
nplourde
parents: 15486
diff changeset
179 /* Everything is currently unimplemented */
10152
b252d1b6829e cleanup/cosmetic patch by the author :)
alex
parents: 10147
diff changeset
180 return CONTROL_FALSE;
10147
f2725d6717bd Native MacOSX audio output by Dan Christiansen <danchr@daimi.au.dk>
alex
parents:
diff changeset
181 default:
10152
b252d1b6829e cleanup/cosmetic patch by the author :)
alex
parents: 10147
diff changeset
182 return CONTROL_FALSE;
10147
f2725d6717bd Native MacOSX audio output by Dan Christiansen <danchr@daimi.au.dk>
alex
parents:
diff changeset
183 }
f2725d6717bd Native MacOSX audio output by Dan Christiansen <danchr@daimi.au.dk>
alex
parents:
diff changeset
184
f2725d6717bd Native MacOSX audio output by Dan Christiansen <danchr@daimi.au.dk>
alex
parents:
diff changeset
185 }
f2725d6717bd Native MacOSX audio output by Dan Christiansen <danchr@daimi.au.dk>
alex
parents:
diff changeset
186
f2725d6717bd Native MacOSX audio output by Dan Christiansen <danchr@daimi.au.dk>
alex
parents:
diff changeset
187
14317
9b3966174684 many 10ls fixed... also better debugging
arpi
parents: 14290
diff changeset
188 static void print_format(const char* str,AudioStreamBasicDescription *f){
14290
488651c51aa3 rate/format matching and volume get/set support
arpi
parents: 14245
diff changeset
189 uint32_t flags=(uint32_t) f->mFormatFlags;
14317
9b3966174684 many 10ls fixed... also better debugging
arpi
parents: 14290
diff changeset
190 ao_msg(MSGT_AO,MSGL_V, "%s %7.1fHz %dbit [%c%c%c%c] %s %s %s%s%s%s\n",
9b3966174684 many 10ls fixed... also better debugging
arpi
parents: 14290
diff changeset
191 str, f->mSampleRate, f->mBitsPerChannel,
14290
488651c51aa3 rate/format matching and volume get/set support
arpi
parents: 14245
diff changeset
192 (int)(f->mFormatID & 0xff000000) >> 24,
488651c51aa3 rate/format matching and volume get/set support
arpi
parents: 14245
diff changeset
193 (int)(f->mFormatID & 0x00ff0000) >> 16,
488651c51aa3 rate/format matching and volume get/set support
arpi
parents: 14245
diff changeset
194 (int)(f->mFormatID & 0x0000ff00) >> 8,
488651c51aa3 rate/format matching and volume get/set support
arpi
parents: 14245
diff changeset
195 (int)(f->mFormatID & 0x000000ff) >> 0,
488651c51aa3 rate/format matching and volume get/set support
arpi
parents: 14245
diff changeset
196 (flags&kAudioFormatFlagIsFloat) ? "float" : "int",
488651c51aa3 rate/format matching and volume get/set support
arpi
parents: 14245
diff changeset
197 (flags&kAudioFormatFlagIsBigEndian) ? "BE" : "LE",
488651c51aa3 rate/format matching and volume get/set support
arpi
parents: 14245
diff changeset
198 (flags&kAudioFormatFlagIsSignedInteger) ? "S" : "U",
488651c51aa3 rate/format matching and volume get/set support
arpi
parents: 14245
diff changeset
199 (flags&kAudioFormatFlagIsPacked) ? " packed" : "",
488651c51aa3 rate/format matching and volume get/set support
arpi
parents: 14245
diff changeset
200 (flags&kAudioFormatFlagIsAlignedHigh) ? " aligned" : "",
488651c51aa3 rate/format matching and volume get/set support
arpi
parents: 14245
diff changeset
201 (flags&kAudioFormatFlagIsNonInterleaved) ? " ni" : "" );
488651c51aa3 rate/format matching and volume get/set support
arpi
parents: 14245
diff changeset
202
14317
9b3966174684 many 10ls fixed... also better debugging
arpi
parents: 14290
diff changeset
203 ao_msg(MSGT_AO,MSGL_DBG2, "%5d mBytesPerPacket\n",
14290
488651c51aa3 rate/format matching and volume get/set support
arpi
parents: 14245
diff changeset
204 (int)f->mBytesPerPacket);
14317
9b3966174684 many 10ls fixed... also better debugging
arpi
parents: 14290
diff changeset
205 ao_msg(MSGT_AO,MSGL_DBG2, "%5d mFramesPerPacket\n",
14290
488651c51aa3 rate/format matching and volume get/set support
arpi
parents: 14245
diff changeset
206 (int)f->mFramesPerPacket);
14317
9b3966174684 many 10ls fixed... also better debugging
arpi
parents: 14290
diff changeset
207 ao_msg(MSGT_AO,MSGL_DBG2, "%5d mBytesPerFrame\n",
14290
488651c51aa3 rate/format matching and volume get/set support
arpi
parents: 14245
diff changeset
208 (int)f->mBytesPerFrame);
14317
9b3966174684 many 10ls fixed... also better debugging
arpi
parents: 14290
diff changeset
209 ao_msg(MSGT_AO,MSGL_DBG2, "%5d mChannelsPerFrame\n",
14290
488651c51aa3 rate/format matching and volume get/set support
arpi
parents: 14245
diff changeset
210 (int)f->mChannelsPerFrame);
488651c51aa3 rate/format matching and volume get/set support
arpi
parents: 14245
diff changeset
211
488651c51aa3 rate/format matching and volume get/set support
arpi
parents: 14245
diff changeset
212 }
488651c51aa3 rate/format matching and volume get/set support
arpi
parents: 14245
diff changeset
213
488651c51aa3 rate/format matching and volume get/set support
arpi
parents: 14245
diff changeset
214
10147
f2725d6717bd Native MacOSX audio output by Dan Christiansen <danchr@daimi.au.dk>
alex
parents:
diff changeset
215 static int init(int rate,int channels,int format,int flags)
f2725d6717bd Native MacOSX audio output by Dan Christiansen <danchr@daimi.au.dk>
alex
parents:
diff changeset
216 {
15646
f46eae5e271b Mac OS X Audio with AudioUnits and AudioToolbox format converters, Patch by Chris Roccati<roccati@pobox.com
nplourde
parents: 15486
diff changeset
217 AudioStreamBasicDescription inDesc, outDesc;
f46eae5e271b Mac OS X Audio with AudioUnits and AudioToolbox format converters, Patch by Chris Roccati<roccati@pobox.com
nplourde
parents: 15486
diff changeset
218 ComponentDescription desc;
f46eae5e271b Mac OS X Audio with AudioUnits and AudioToolbox format converters, Patch by Chris Roccati<roccati@pobox.com
nplourde
parents: 15486
diff changeset
219 Component comp;
f46eae5e271b Mac OS X Audio with AudioUnits and AudioToolbox format converters, Patch by Chris Roccati<roccati@pobox.com
nplourde
parents: 15486
diff changeset
220 AURenderCallbackStruct renderCallback;
f46eae5e271b Mac OS X Audio with AudioUnits and AudioToolbox format converters, Patch by Chris Roccati<roccati@pobox.com
nplourde
parents: 15486
diff changeset
221 OSStatus err;
f46eae5e271b Mac OS X Audio with AudioUnits and AudioToolbox format converters, Patch by Chris Roccati<roccati@pobox.com
nplourde
parents: 15486
diff changeset
222 UInt32 size, maxFrames;
15853
6e994905f77b more general ao_macosx cleanup. Patch by Alexander Strange <astrange@ithinksw.com>
nplourde
parents: 15722
diff changeset
223 int aoIsCreated = ao != NULL;
14317
9b3966174684 many 10ls fixed... also better debugging
arpi
parents: 14290
diff changeset
224
18885
5c8acc972551 rm unnecesary casts from void* - part 4
reynaldo
parents: 16014
diff changeset
225 if (!aoIsCreated) ao = malloc(sizeof(ao_macosx_t));
14290
488651c51aa3 rate/format matching and volume get/set support
arpi
parents: 14245
diff changeset
226
15646
f46eae5e271b Mac OS X Audio with AudioUnits and AudioToolbox format converters, Patch by Chris Roccati<roccati@pobox.com
nplourde
parents: 15486
diff changeset
227 // Build Description for the input format
f46eae5e271b Mac OS X Audio with AudioUnits and AudioToolbox format converters, Patch by Chris Roccati<roccati@pobox.com
nplourde
parents: 15486
diff changeset
228 inDesc.mSampleRate=rate;
f46eae5e271b Mac OS X Audio with AudioUnits and AudioToolbox format converters, Patch by Chris Roccati<roccati@pobox.com
nplourde
parents: 15486
diff changeset
229 inDesc.mFormatID=kAudioFormatLinearPCM;
f46eae5e271b Mac OS X Audio with AudioUnits and AudioToolbox format converters, Patch by Chris Roccati<roccati@pobox.com
nplourde
parents: 15486
diff changeset
230 inDesc.mChannelsPerFrame=channels;
f46eae5e271b Mac OS X Audio with AudioUnits and AudioToolbox format converters, Patch by Chris Roccati<roccati@pobox.com
nplourde
parents: 15486
diff changeset
231 switch(format&AF_FORMAT_BITS_MASK){
f46eae5e271b Mac OS X Audio with AudioUnits and AudioToolbox format converters, Patch by Chris Roccati<roccati@pobox.com
nplourde
parents: 15486
diff changeset
232 case AF_FORMAT_8BIT:
f46eae5e271b Mac OS X Audio with AudioUnits and AudioToolbox format converters, Patch by Chris Roccati<roccati@pobox.com
nplourde
parents: 15486
diff changeset
233 inDesc.mBitsPerChannel=8;
f46eae5e271b Mac OS X Audio with AudioUnits and AudioToolbox format converters, Patch by Chris Roccati<roccati@pobox.com
nplourde
parents: 15486
diff changeset
234 break;
f46eae5e271b Mac OS X Audio with AudioUnits and AudioToolbox format converters, Patch by Chris Roccati<roccati@pobox.com
nplourde
parents: 15486
diff changeset
235 case AF_FORMAT_16BIT:
f46eae5e271b Mac OS X Audio with AudioUnits and AudioToolbox format converters, Patch by Chris Roccati<roccati@pobox.com
nplourde
parents: 15486
diff changeset
236 inDesc.mBitsPerChannel=16;
f46eae5e271b Mac OS X Audio with AudioUnits and AudioToolbox format converters, Patch by Chris Roccati<roccati@pobox.com
nplourde
parents: 15486
diff changeset
237 break;
f46eae5e271b Mac OS X Audio with AudioUnits and AudioToolbox format converters, Patch by Chris Roccati<roccati@pobox.com
nplourde
parents: 15486
diff changeset
238 case AF_FORMAT_24BIT:
f46eae5e271b Mac OS X Audio with AudioUnits and AudioToolbox format converters, Patch by Chris Roccati<roccati@pobox.com
nplourde
parents: 15486
diff changeset
239 inDesc.mBitsPerChannel=24;
f46eae5e271b Mac OS X Audio with AudioUnits and AudioToolbox format converters, Patch by Chris Roccati<roccati@pobox.com
nplourde
parents: 15486
diff changeset
240 break;
f46eae5e271b Mac OS X Audio with AudioUnits and AudioToolbox format converters, Patch by Chris Roccati<roccati@pobox.com
nplourde
parents: 15486
diff changeset
241 case AF_FORMAT_32BIT:
f46eae5e271b Mac OS X Audio with AudioUnits and AudioToolbox format converters, Patch by Chris Roccati<roccati@pobox.com
nplourde
parents: 15486
diff changeset
242 inDesc.mBitsPerChannel=32;
f46eae5e271b Mac OS X Audio with AudioUnits and AudioToolbox format converters, Patch by Chris Roccati<roccati@pobox.com
nplourde
parents: 15486
diff changeset
243 break;
f46eae5e271b Mac OS X Audio with AudioUnits and AudioToolbox format converters, Patch by Chris Roccati<roccati@pobox.com
nplourde
parents: 15486
diff changeset
244 default:
f46eae5e271b Mac OS X Audio with AudioUnits and AudioToolbox format converters, Patch by Chris Roccati<roccati@pobox.com
nplourde
parents: 15486
diff changeset
245 ao_msg(MSGT_AO, MSGL_WARN, "Unsupported format (0x%08x)\n", format);
14290
488651c51aa3 rate/format matching and volume get/set support
arpi
parents: 14245
diff changeset
246 return CONTROL_FALSE;
15646
f46eae5e271b Mac OS X Audio with AudioUnits and AudioToolbox format converters, Patch by Chris Roccati<roccati@pobox.com
nplourde
parents: 15486
diff changeset
247 break;
f46eae5e271b Mac OS X Audio with AudioUnits and AudioToolbox format converters, Patch by Chris Roccati<roccati@pobox.com
nplourde
parents: 15486
diff changeset
248 }
10147
f2725d6717bd Native MacOSX audio output by Dan Christiansen <danchr@daimi.au.dk>
alex
parents:
diff changeset
249
15646
f46eae5e271b Mac OS X Audio with AudioUnits and AudioToolbox format converters, Patch by Chris Roccati<roccati@pobox.com
nplourde
parents: 15486
diff changeset
250 if((format&AF_FORMAT_POINT_MASK)==AF_FORMAT_F) {
f46eae5e271b Mac OS X Audio with AudioUnits and AudioToolbox format converters, Patch by Chris Roccati<roccati@pobox.com
nplourde
parents: 15486
diff changeset
251 // float
f46eae5e271b Mac OS X Audio with AudioUnits and AudioToolbox format converters, Patch by Chris Roccati<roccati@pobox.com
nplourde
parents: 15486
diff changeset
252 inDesc.mFormatFlags = kAudioFormatFlagIsFloat|kAudioFormatFlagIsPacked;
10147
f2725d6717bd Native MacOSX audio output by Dan Christiansen <danchr@daimi.au.dk>
alex
parents:
diff changeset
253 }
15646
f46eae5e271b Mac OS X Audio with AudioUnits and AudioToolbox format converters, Patch by Chris Roccati<roccati@pobox.com
nplourde
parents: 15486
diff changeset
254 else if((format&AF_FORMAT_SIGN_MASK)==AF_FORMAT_SI) {
f46eae5e271b Mac OS X Audio with AudioUnits and AudioToolbox format converters, Patch by Chris Roccati<roccati@pobox.com
nplourde
parents: 15486
diff changeset
255 // signed int
f46eae5e271b Mac OS X Audio with AudioUnits and AudioToolbox format converters, Patch by Chris Roccati<roccati@pobox.com
nplourde
parents: 15486
diff changeset
256 inDesc.mFormatFlags = kAudioFormatFlagIsSignedInteger|kAudioFormatFlagIsPacked;
f46eae5e271b Mac OS X Audio with AudioUnits and AudioToolbox format converters, Patch by Chris Roccati<roccati@pobox.com
nplourde
parents: 15486
diff changeset
257 }
f46eae5e271b Mac OS X Audio with AudioUnits and AudioToolbox format converters, Patch by Chris Roccati<roccati@pobox.com
nplourde
parents: 15486
diff changeset
258 else {
f46eae5e271b Mac OS X Audio with AudioUnits and AudioToolbox format converters, Patch by Chris Roccati<roccati@pobox.com
nplourde
parents: 15486
diff changeset
259 // unsigned int
f46eae5e271b Mac OS X Audio with AudioUnits and AudioToolbox format converters, Patch by Chris Roccati<roccati@pobox.com
nplourde
parents: 15486
diff changeset
260 inDesc.mFormatFlags = kAudioFormatFlagIsPacked;
10147
f2725d6717bd Native MacOSX audio output by Dan Christiansen <danchr@daimi.au.dk>
alex
parents:
diff changeset
261 }
f2725d6717bd Native MacOSX audio output by Dan Christiansen <danchr@daimi.au.dk>
alex
parents:
diff changeset
262
15646
f46eae5e271b Mac OS X Audio with AudioUnits and AudioToolbox format converters, Patch by Chris Roccati<roccati@pobox.com
nplourde
parents: 15486
diff changeset
263 if((format&AF_FORMAT_END_MASK)==AF_FORMAT_BE)
f46eae5e271b Mac OS X Audio with AudioUnits and AudioToolbox format converters, Patch by Chris Roccati<roccati@pobox.com
nplourde
parents: 15486
diff changeset
264 inDesc.mFormatFlags |= kAudioFormatFlagIsBigEndian;
f46eae5e271b Mac OS X Audio with AudioUnits and AudioToolbox format converters, Patch by Chris Roccati<roccati@pobox.com
nplourde
parents: 15486
diff changeset
265
f46eae5e271b Mac OS X Audio with AudioUnits and AudioToolbox format converters, Patch by Chris Roccati<roccati@pobox.com
nplourde
parents: 15486
diff changeset
266 inDesc.mFramesPerPacket = 1;
f46eae5e271b Mac OS X Audio with AudioUnits and AudioToolbox format converters, Patch by Chris Roccati<roccati@pobox.com
nplourde
parents: 15486
diff changeset
267 ao->packetSize = inDesc.mBytesPerPacket = inDesc.mBytesPerFrame = inDesc.mFramesPerPacket*channels*(inDesc.mBitsPerChannel/8);
f46eae5e271b Mac OS X Audio with AudioUnits and AudioToolbox format converters, Patch by Chris Roccati<roccati@pobox.com
nplourde
parents: 15486
diff changeset
268 print_format("source: ",&inDesc);
f46eae5e271b Mac OS X Audio with AudioUnits and AudioToolbox format converters, Patch by Chris Roccati<roccati@pobox.com
nplourde
parents: 15486
diff changeset
269
15853
6e994905f77b more general ao_macosx cleanup. Patch by Alexander Strange <astrange@ithinksw.com>
nplourde
parents: 15722
diff changeset
270 if (!aoIsCreated) {
15646
f46eae5e271b Mac OS X Audio with AudioUnits and AudioToolbox format converters, Patch by Chris Roccati<roccati@pobox.com
nplourde
parents: 15486
diff changeset
271 desc.componentType = kAudioUnitType_Output;
f46eae5e271b Mac OS X Audio with AudioUnits and AudioToolbox format converters, Patch by Chris Roccati<roccati@pobox.com
nplourde
parents: 15486
diff changeset
272 desc.componentSubType = kAudioUnitSubType_DefaultOutput;
f46eae5e271b Mac OS X Audio with AudioUnits and AudioToolbox format converters, Patch by Chris Roccati<roccati@pobox.com
nplourde
parents: 15486
diff changeset
273 desc.componentManufacturer = kAudioUnitManufacturer_Apple;
f46eae5e271b Mac OS X Audio with AudioUnits and AudioToolbox format converters, Patch by Chris Roccati<roccati@pobox.com
nplourde
parents: 15486
diff changeset
274 desc.componentFlags = 0;
f46eae5e271b Mac OS X Audio with AudioUnits and AudioToolbox format converters, Patch by Chris Roccati<roccati@pobox.com
nplourde
parents: 15486
diff changeset
275 desc.componentFlagsMask = 0;
f46eae5e271b Mac OS X Audio with AudioUnits and AudioToolbox format converters, Patch by Chris Roccati<roccati@pobox.com
nplourde
parents: 15486
diff changeset
276
f46eae5e271b Mac OS X Audio with AudioUnits and AudioToolbox format converters, Patch by Chris Roccati<roccati@pobox.com
nplourde
parents: 15486
diff changeset
277 comp = FindNextComponent(NULL, &desc); //Finds an component that meets the desc spec's
f46eae5e271b Mac OS X Audio with AudioUnits and AudioToolbox format converters, Patch by Chris Roccati<roccati@pobox.com
nplourde
parents: 15486
diff changeset
278 if (comp == NULL) {
f46eae5e271b Mac OS X Audio with AudioUnits and AudioToolbox format converters, Patch by Chris Roccati<roccati@pobox.com
nplourde
parents: 15486
diff changeset
279 ao_msg(MSGT_AO, MSGL_WARN, "Unable to find Output Unit component\n");
f46eae5e271b Mac OS X Audio with AudioUnits and AudioToolbox format converters, Patch by Chris Roccati<roccati@pobox.com
nplourde
parents: 15486
diff changeset
280 return CONTROL_FALSE;
f46eae5e271b Mac OS X Audio with AudioUnits and AudioToolbox format converters, Patch by Chris Roccati<roccati@pobox.com
nplourde
parents: 15486
diff changeset
281 }
f46eae5e271b Mac OS X Audio with AudioUnits and AudioToolbox format converters, Patch by Chris Roccati<roccati@pobox.com
nplourde
parents: 15486
diff changeset
282
f46eae5e271b Mac OS X Audio with AudioUnits and AudioToolbox format converters, Patch by Chris Roccati<roccati@pobox.com
nplourde
parents: 15486
diff changeset
283 err = OpenAComponent(comp, &(ao->theOutputUnit)); //gains access to the services provided by the component
f46eae5e271b Mac OS X Audio with AudioUnits and AudioToolbox format converters, Patch by Chris Roccati<roccati@pobox.com
nplourde
parents: 15486
diff changeset
284 if (err) {
f46eae5e271b Mac OS X Audio with AudioUnits and AudioToolbox format converters, Patch by Chris Roccati<roccati@pobox.com
nplourde
parents: 15486
diff changeset
285 ao_msg(MSGT_AO, MSGL_WARN, "Unable to open Output Unit component (err=%d)\n", err);
f46eae5e271b Mac OS X Audio with AudioUnits and AudioToolbox format converters, Patch by Chris Roccati<roccati@pobox.com
nplourde
parents: 15486
diff changeset
286 return CONTROL_FALSE;
f46eae5e271b Mac OS X Audio with AudioUnits and AudioToolbox format converters, Patch by Chris Roccati<roccati@pobox.com
nplourde
parents: 15486
diff changeset
287 }
f46eae5e271b Mac OS X Audio with AudioUnits and AudioToolbox format converters, Patch by Chris Roccati<roccati@pobox.com
nplourde
parents: 15486
diff changeset
288
f46eae5e271b Mac OS X Audio with AudioUnits and AudioToolbox format converters, Patch by Chris Roccati<roccati@pobox.com
nplourde
parents: 15486
diff changeset
289 // Initialize AudioUnit
f46eae5e271b Mac OS X Audio with AudioUnits and AudioToolbox format converters, Patch by Chris Roccati<roccati@pobox.com
nplourde
parents: 15486
diff changeset
290 err = AudioUnitInitialize(ao->theOutputUnit);
f46eae5e271b Mac OS X Audio with AudioUnits and AudioToolbox format converters, Patch by Chris Roccati<roccati@pobox.com
nplourde
parents: 15486
diff changeset
291 if (err) {
f46eae5e271b Mac OS X Audio with AudioUnits and AudioToolbox format converters, Patch by Chris Roccati<roccati@pobox.com
nplourde
parents: 15486
diff changeset
292 ao_msg(MSGT_AO, MSGL_WARN, "Unable to initialize Output Unit component (err=%d)\n", err);
f46eae5e271b Mac OS X Audio with AudioUnits and AudioToolbox format converters, Patch by Chris Roccati<roccati@pobox.com
nplourde
parents: 15486
diff changeset
293 return CONTROL_FALSE;
f46eae5e271b Mac OS X Audio with AudioUnits and AudioToolbox format converters, Patch by Chris Roccati<roccati@pobox.com
nplourde
parents: 15486
diff changeset
294 }
15853
6e994905f77b more general ao_macosx cleanup. Patch by Alexander Strange <astrange@ithinksw.com>
nplourde
parents: 15722
diff changeset
295 }
15646
f46eae5e271b Mac OS X Audio with AudioUnits and AudioToolbox format converters, Patch by Chris Roccati<roccati@pobox.com
nplourde
parents: 15486
diff changeset
296
f46eae5e271b Mac OS X Audio with AudioUnits and AudioToolbox format converters, Patch by Chris Roccati<roccati@pobox.com
nplourde
parents: 15486
diff changeset
297 size = sizeof(AudioStreamBasicDescription);
15722
b53c4b26dc96 removes the use of AudioConverters. patch by Alexander Strange <alexander.strange@ithinksw.com>
nplourde
parents: 15646
diff changeset
298 err = AudioUnitSetProperty(ao->theOutputUnit, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Input, 0, &inDesc, size);
15646
f46eae5e271b Mac OS X Audio with AudioUnits and AudioToolbox format converters, Patch by Chris Roccati<roccati@pobox.com
nplourde
parents: 15486
diff changeset
299
f46eae5e271b Mac OS X Audio with AudioUnits and AudioToolbox format converters, Patch by Chris Roccati<roccati@pobox.com
nplourde
parents: 15486
diff changeset
300 if (err) {
15722
b53c4b26dc96 removes the use of AudioConverters. patch by Alexander Strange <alexander.strange@ithinksw.com>
nplourde
parents: 15646
diff changeset
301 ao_msg(MSGT_AO, MSGL_WARN, "Unable to set the input format (err=%d)\n", err);
15646
f46eae5e271b Mac OS X Audio with AudioUnits and AudioToolbox format converters, Patch by Chris Roccati<roccati@pobox.com
nplourde
parents: 15486
diff changeset
302 return CONTROL_FALSE;
f46eae5e271b Mac OS X Audio with AudioUnits and AudioToolbox format converters, Patch by Chris Roccati<roccati@pobox.com
nplourde
parents: 15486
diff changeset
303 }
f46eae5e271b Mac OS X Audio with AudioUnits and AudioToolbox format converters, Patch by Chris Roccati<roccati@pobox.com
nplourde
parents: 15486
diff changeset
304
16014
67266a949b51 remove delay when setting audio volume
nplourde
parents: 15853
diff changeset
305 size = sizeof(UInt32);
67266a949b51 remove delay when setting audio volume
nplourde
parents: 15853
diff changeset
306 err = AudioUnitGetProperty(ao->theOutputUnit, kAudioDevicePropertyBufferSize, kAudioUnitScope_Input, 0, &maxFrames, &size);
15646
f46eae5e271b Mac OS X Audio with AudioUnits and AudioToolbox format converters, Patch by Chris Roccati<roccati@pobox.com
nplourde
parents: 15486
diff changeset
307
16014
67266a949b51 remove delay when setting audio volume
nplourde
parents: 15853
diff changeset
308 if (err)
67266a949b51 remove delay when setting audio volume
nplourde
parents: 15853
diff changeset
309 {
67266a949b51 remove delay when setting audio volume
nplourde
parents: 15853
diff changeset
310 ao_msg(MSGT_AO,MSGL_WARN, "AudioUnitGetProperty returned %d when getting kAudioDevicePropertyBufferSize\n", (int)err);
15646
f46eae5e271b Mac OS X Audio with AudioUnits and AudioToolbox format converters, Patch by Chris Roccati<roccati@pobox.com
nplourde
parents: 15486
diff changeset
311 return CONTROL_FALSE;
f46eae5e271b Mac OS X Audio with AudioUnits and AudioToolbox format converters, Patch by Chris Roccati<roccati@pobox.com
nplourde
parents: 15486
diff changeset
312 }
f46eae5e271b Mac OS X Audio with AudioUnits and AudioToolbox format converters, Patch by Chris Roccati<roccati@pobox.com
nplourde
parents: 15486
diff changeset
313
16014
67266a949b51 remove delay when setting audio volume
nplourde
parents: 15853
diff changeset
314 ao->chunk_size = maxFrames;//*inDesc.mBytesPerFrame;
67266a949b51 remove delay when setting audio volume
nplourde
parents: 15853
diff changeset
315
19427
ada359817b61 fix buffering issues with short audio samples on macosx. patch by Chris Roccati <roccati@pobox.com>
nplourde
parents: 18915
diff changeset
316 ao_data.samplerate = inDesc.mSampleRate;
ada359817b61 fix buffering issues with short audio samples on macosx. patch by Chris Roccati <roccati@pobox.com>
nplourde
parents: 18915
diff changeset
317 ao_data.channels = inDesc.mChannelsPerFrame;
ada359817b61 fix buffering issues with short audio samples on macosx. patch by Chris Roccati <roccati@pobox.com>
nplourde
parents: 18915
diff changeset
318 ao_data.bps = ao_data.samplerate * inDesc.mBytesPerFrame;
ada359817b61 fix buffering issues with short audio samples on macosx. patch by Chris Roccati <roccati@pobox.com>
nplourde
parents: 18915
diff changeset
319 ao_data.outburst = ao->chunk_size;
ada359817b61 fix buffering issues with short audio samples on macosx. patch by Chris Roccati <roccati@pobox.com>
nplourde
parents: 18915
diff changeset
320 ao_data.buffersize = ao_data.bps;
ada359817b61 fix buffering issues with short audio samples on macosx. patch by Chris Roccati <roccati@pobox.com>
nplourde
parents: 18915
diff changeset
321
ada359817b61 fix buffering issues with short audio samples on macosx. patch by Chris Roccati <roccati@pobox.com>
nplourde
parents: 18915
diff changeset
322 ao->num_chunks = (ao_data.bps+ao->chunk_size-1)/ao->chunk_size;
14769
e701873aa8ca rids ao_macosx of the buffer mutex by using the same buffering scheme as ao_sdl - Patch by Reimar Doffinger
nplourde
parents: 14642
diff changeset
323 ao->buffer_len = (ao->num_chunks + 1) * ao->chunk_size;
18885
5c8acc972551 rm unnecesary casts from void* - part 4
reynaldo
parents: 16014
diff changeset
324 ao->buffer = aoIsCreated ? realloc(ao->buffer,(ao->num_chunks + 1)*ao->chunk_size)
5c8acc972551 rm unnecesary casts from void* - part 4
reynaldo
parents: 16014
diff changeset
325 : calloc(ao->num_chunks + 1, ao->chunk_size);
15853
6e994905f77b more general ao_macosx cleanup. Patch by Alexander Strange <astrange@ithinksw.com>
nplourde
parents: 15722
diff changeset
326
19427
ada359817b61 fix buffering issues with short audio samples on macosx. patch by Chris Roccati <roccati@pobox.com>
nplourde
parents: 18915
diff changeset
327 ao_msg(MSGT_AO,MSGL_V, "using %5d chunks of %d bytes (buffer len %d bytes)\n", (int)ao->num_chunks, (int)ao->chunk_size, (int)ao->buffer_len);
10147
f2725d6717bd Native MacOSX audio output by Dan Christiansen <danchr@daimi.au.dk>
alex
parents:
diff changeset
328
15646
f46eae5e271b Mac OS X Audio with AudioUnits and AudioToolbox format converters, Patch by Chris Roccati<roccati@pobox.com
nplourde
parents: 15486
diff changeset
329 renderCallback.inputProc = theRenderProc;
f46eae5e271b Mac OS X Audio with AudioUnits and AudioToolbox format converters, Patch by Chris Roccati<roccati@pobox.com
nplourde
parents: 15486
diff changeset
330 renderCallback.inputProcRefCon = 0;
f46eae5e271b Mac OS X Audio with AudioUnits and AudioToolbox format converters, Patch by Chris Roccati<roccati@pobox.com
nplourde
parents: 15486
diff changeset
331 err = AudioUnitSetProperty(ao->theOutputUnit, kAudioUnitProperty_SetRenderCallback, kAudioUnitScope_Input, 0, &renderCallback, sizeof(AURenderCallbackStruct));
f46eae5e271b Mac OS X Audio with AudioUnits and AudioToolbox format converters, Patch by Chris Roccati<roccati@pobox.com
nplourde
parents: 15486
diff changeset
332 if (err) {
f46eae5e271b Mac OS X Audio with AudioUnits and AudioToolbox format converters, Patch by Chris Roccati<roccati@pobox.com
nplourde
parents: 15486
diff changeset
333 ao_msg(MSGT_AO, MSGL_WARN, "Unable to set the render callback (err=%d)\n", err);
f46eae5e271b Mac OS X Audio with AudioUnits and AudioToolbox format converters, Patch by Chris Roccati<roccati@pobox.com
nplourde
parents: 15486
diff changeset
334 return CONTROL_FALSE;
f46eae5e271b Mac OS X Audio with AudioUnits and AudioToolbox format converters, Patch by Chris Roccati<roccati@pobox.com
nplourde
parents: 15486
diff changeset
335 }
f46eae5e271b Mac OS X Audio with AudioUnits and AudioToolbox format converters, Patch by Chris Roccati<roccati@pobox.com
nplourde
parents: 15486
diff changeset
336
19427
ada359817b61 fix buffering issues with short audio samples on macosx. patch by Chris Roccati <roccati@pobox.com>
nplourde
parents: 18915
diff changeset
337 reset();
10147
f2725d6717bd Native MacOSX audio output by Dan Christiansen <danchr@daimi.au.dk>
alex
parents:
diff changeset
338
f2725d6717bd Native MacOSX audio output by Dan Christiansen <danchr@daimi.au.dk>
alex
parents:
diff changeset
339 return CONTROL_OK;
f2725d6717bd Native MacOSX audio output by Dan Christiansen <danchr@daimi.au.dk>
alex
parents:
diff changeset
340 }
f2725d6717bd Native MacOSX audio output by Dan Christiansen <danchr@daimi.au.dk>
alex
parents:
diff changeset
341
f2725d6717bd Native MacOSX audio output by Dan Christiansen <danchr@daimi.au.dk>
alex
parents:
diff changeset
342
f2725d6717bd Native MacOSX audio output by Dan Christiansen <danchr@daimi.au.dk>
alex
parents:
diff changeset
343 static int play(void* output_samples,int num_bytes,int flags)
f2725d6717bd Native MacOSX audio output by Dan Christiansen <danchr@daimi.au.dk>
alex
parents:
diff changeset
344 {
19427
ada359817b61 fix buffering issues with short audio samples on macosx. patch by Chris Roccati <roccati@pobox.com>
nplourde
parents: 18915
diff changeset
345 int wrote=write_buffer(output_samples, num_bytes);
ada359817b61 fix buffering issues with short audio samples on macosx. patch by Chris Roccati <roccati@pobox.com>
nplourde
parents: 18915
diff changeset
346
15853
6e994905f77b more general ao_macosx cleanup. Patch by Alexander Strange <astrange@ithinksw.com>
nplourde
parents: 15722
diff changeset
347 audio_resume();
19427
ada359817b61 fix buffering issues with short audio samples on macosx. patch by Chris Roccati <roccati@pobox.com>
nplourde
parents: 18915
diff changeset
348 return wrote;
10147
f2725d6717bd Native MacOSX audio output by Dan Christiansen <danchr@daimi.au.dk>
alex
parents:
diff changeset
349 }
f2725d6717bd Native MacOSX audio output by Dan Christiansen <danchr@daimi.au.dk>
alex
parents:
diff changeset
350
f2725d6717bd Native MacOSX audio output by Dan Christiansen <danchr@daimi.au.dk>
alex
parents:
diff changeset
351 /* set variables and buffer to initial state */
18915
99e20a22d5d0 modifies function declarations without parameters from ()
reynaldo
parents: 18885
diff changeset
352 static void reset(void)
10147
f2725d6717bd Native MacOSX audio output by Dan Christiansen <danchr@daimi.au.dk>
alex
parents:
diff changeset
353 {
14769
e701873aa8ca rids ao_macosx of the buffer mutex by using the same buffering scheme as ao_sdl - Patch by Reimar Doffinger
nplourde
parents: 14642
diff changeset
354 audio_pause();
10147
f2725d6717bd Native MacOSX audio output by Dan Christiansen <danchr@daimi.au.dk>
alex
parents:
diff changeset
355 /* reset ring-buffer state */
f2725d6717bd Native MacOSX audio output by Dan Christiansen <danchr@daimi.au.dk>
alex
parents:
diff changeset
356 ao->buf_read_pos=0;
f2725d6717bd Native MacOSX audio output by Dan Christiansen <danchr@daimi.au.dk>
alex
parents:
diff changeset
357 ao->buf_write_pos=0;
f2725d6717bd Native MacOSX audio output by Dan Christiansen <danchr@daimi.au.dk>
alex
parents:
diff changeset
358
f2725d6717bd Native MacOSX audio output by Dan Christiansen <danchr@daimi.au.dk>
alex
parents:
diff changeset
359 return;
f2725d6717bd Native MacOSX audio output by Dan Christiansen <danchr@daimi.au.dk>
alex
parents:
diff changeset
360 }
f2725d6717bd Native MacOSX audio output by Dan Christiansen <danchr@daimi.au.dk>
alex
parents:
diff changeset
361
f2725d6717bd Native MacOSX audio output by Dan Christiansen <danchr@daimi.au.dk>
alex
parents:
diff changeset
362
f2725d6717bd Native MacOSX audio output by Dan Christiansen <danchr@daimi.au.dk>
alex
parents:
diff changeset
363 /* return available space */
18915
99e20a22d5d0 modifies function declarations without parameters from ()
reynaldo
parents: 18885
diff changeset
364 static int get_space(void)
10147
f2725d6717bd Native MacOSX audio output by Dan Christiansen <danchr@daimi.au.dk>
alex
parents:
diff changeset
365 {
14769
e701873aa8ca rids ao_macosx of the buffer mutex by using the same buffering scheme as ao_sdl - Patch by Reimar Doffinger
nplourde
parents: 14642
diff changeset
366 return buf_free();
10147
f2725d6717bd Native MacOSX audio output by Dan Christiansen <danchr@daimi.au.dk>
alex
parents:
diff changeset
367 }
f2725d6717bd Native MacOSX audio output by Dan Christiansen <danchr@daimi.au.dk>
alex
parents:
diff changeset
368
f2725d6717bd Native MacOSX audio output by Dan Christiansen <danchr@daimi.au.dk>
alex
parents:
diff changeset
369
10152
b252d1b6829e cleanup/cosmetic patch by the author :)
alex
parents: 10147
diff changeset
370 /* return delay until audio is played */
18915
99e20a22d5d0 modifies function declarations without parameters from ()
reynaldo
parents: 18885
diff changeset
371 static float get_delay(void)
10147
f2725d6717bd Native MacOSX audio output by Dan Christiansen <danchr@daimi.au.dk>
alex
parents:
diff changeset
372 {
14769
e701873aa8ca rids ao_macosx of the buffer mutex by using the same buffering scheme as ao_sdl - Patch by Reimar Doffinger
nplourde
parents: 14642
diff changeset
373 int buffered = ao->buffer_len - ao->chunk_size - buf_free(); // could be less
e701873aa8ca rids ao_macosx of the buffer mutex by using the same buffering scheme as ao_sdl - Patch by Reimar Doffinger
nplourde
parents: 14642
diff changeset
374 // inaccurate, should also contain the data buffered e.g. by the OS
e701873aa8ca rids ao_macosx of the buffer mutex by using the same buffering scheme as ao_sdl - Patch by Reimar Doffinger
nplourde
parents: 14642
diff changeset
375 return (float)(buffered)/(float)ao_data.bps;
10147
f2725d6717bd Native MacOSX audio output by Dan Christiansen <danchr@daimi.au.dk>
alex
parents:
diff changeset
376 }
f2725d6717bd Native MacOSX audio output by Dan Christiansen <danchr@daimi.au.dk>
alex
parents:
diff changeset
377
f2725d6717bd Native MacOSX audio output by Dan Christiansen <danchr@daimi.au.dk>
alex
parents:
diff changeset
378
f2725d6717bd Native MacOSX audio output by Dan Christiansen <danchr@daimi.au.dk>
alex
parents:
diff changeset
379 /* unload plugin and deregister from coreaudio */
12145
99798c3cdb93 uninit immed flag
alex
parents: 10152
diff changeset
380 static void uninit(int immed)
10147
f2725d6717bd Native MacOSX audio output by Dan Christiansen <danchr@daimi.au.dk>
alex
parents:
diff changeset
381 {
f2725d6717bd Native MacOSX audio output by Dan Christiansen <danchr@daimi.au.dk>
alex
parents:
diff changeset
382 int i;
f2725d6717bd Native MacOSX audio output by Dan Christiansen <danchr@daimi.au.dk>
alex
parents:
diff changeset
383 OSErr status;
f2725d6717bd Native MacOSX audio output by Dan Christiansen <danchr@daimi.au.dk>
alex
parents:
diff changeset
384
19427
ada359817b61 fix buffering issues with short audio samples on macosx. patch by Chris Roccati <roccati@pobox.com>
nplourde
parents: 18915
diff changeset
385 if (!immed) {
ada359817b61 fix buffering issues with short audio samples on macosx. patch by Chris Roccati <roccati@pobox.com>
nplourde
parents: 18915
diff changeset
386 long long timeleft=(1000000LL*buf_used())/ao_data.bps;
ada359817b61 fix buffering issues with short audio samples on macosx. patch by Chris Roccati <roccati@pobox.com>
nplourde
parents: 18915
diff changeset
387 ao_msg(MSGT_AO,MSGL_DBG2, "%d bytes left @%d bps (%ld usec)\n", buf_used(), ao_data.bps, (int)timeleft);
ada359817b61 fix buffering issues with short audio samples on macosx. patch by Chris Roccati <roccati@pobox.com>
nplourde
parents: 18915
diff changeset
388 usec_sleep((int)timeleft);
ada359817b61 fix buffering issues with short audio samples on macosx. patch by Chris Roccati <roccati@pobox.com>
nplourde
parents: 18915
diff changeset
389 }
10147
f2725d6717bd Native MacOSX audio output by Dan Christiansen <danchr@daimi.au.dk>
alex
parents:
diff changeset
390
15646
f46eae5e271b Mac OS X Audio with AudioUnits and AudioToolbox format converters, Patch by Chris Roccati<roccati@pobox.com
nplourde
parents: 15486
diff changeset
391 AudioOutputUnitStop(ao->theOutputUnit);
f46eae5e271b Mac OS X Audio with AudioUnits and AudioToolbox format converters, Patch by Chris Roccati<roccati@pobox.com
nplourde
parents: 15486
diff changeset
392 AudioUnitUninitialize(ao->theOutputUnit);
f46eae5e271b Mac OS X Audio with AudioUnits and AudioToolbox format converters, Patch by Chris Roccati<roccati@pobox.com
nplourde
parents: 15486
diff changeset
393 CloseComponent(ao->theOutputUnit);
10147
f2725d6717bd Native MacOSX audio output by Dan Christiansen <danchr@daimi.au.dk>
alex
parents:
diff changeset
394
14769
e701873aa8ca rids ao_macosx of the buffer mutex by using the same buffering scheme as ao_sdl - Patch by Reimar Doffinger
nplourde
parents: 14642
diff changeset
395 free(ao->buffer);
10147
f2725d6717bd Native MacOSX audio output by Dan Christiansen <danchr@daimi.au.dk>
alex
parents:
diff changeset
396 free(ao);
15853
6e994905f77b more general ao_macosx cleanup. Patch by Alexander Strange <astrange@ithinksw.com>
nplourde
parents: 15722
diff changeset
397 ao = NULL;
10147
f2725d6717bd Native MacOSX audio output by Dan Christiansen <danchr@daimi.au.dk>
alex
parents:
diff changeset
398 }
f2725d6717bd Native MacOSX audio output by Dan Christiansen <danchr@daimi.au.dk>
alex
parents:
diff changeset
399
f2725d6717bd Native MacOSX audio output by Dan Christiansen <danchr@daimi.au.dk>
alex
parents:
diff changeset
400
f2725d6717bd Native MacOSX audio output by Dan Christiansen <danchr@daimi.au.dk>
alex
parents:
diff changeset
401 /* stop playing, keep buffers (for pause) */
18915
99e20a22d5d0 modifies function declarations without parameters from ()
reynaldo
parents: 18885
diff changeset
402 static void audio_pause(void)
10147
f2725d6717bd Native MacOSX audio output by Dan Christiansen <danchr@daimi.au.dk>
alex
parents:
diff changeset
403 {
15646
f46eae5e271b Mac OS X Audio with AudioUnits and AudioToolbox format converters, Patch by Chris Roccati<roccati@pobox.com
nplourde
parents: 15486
diff changeset
404 OSErr status=noErr;
10147
f2725d6717bd Native MacOSX audio output by Dan Christiansen <danchr@daimi.au.dk>
alex
parents:
diff changeset
405
f2725d6717bd Native MacOSX audio output by Dan Christiansen <danchr@daimi.au.dk>
alex
parents:
diff changeset
406 /* stop callback */
15646
f46eae5e271b Mac OS X Audio with AudioUnits and AudioToolbox format converters, Patch by Chris Roccati<roccati@pobox.com
nplourde
parents: 15486
diff changeset
407 status=AudioOutputUnitStop(ao->theOutputUnit);
10147
f2725d6717bd Native MacOSX audio output by Dan Christiansen <danchr@daimi.au.dk>
alex
parents:
diff changeset
408 if (status)
15646
f46eae5e271b Mac OS X Audio with AudioUnits and AudioToolbox format converters, Patch by Chris Roccati<roccati@pobox.com
nplourde
parents: 15486
diff changeset
409 ao_msg(MSGT_AO,MSGL_WARN, "AudioOutputUnitStop returned %d\n",
10147
f2725d6717bd Native MacOSX audio output by Dan Christiansen <danchr@daimi.au.dk>
alex
parents:
diff changeset
410 (int)status);
19427
ada359817b61 fix buffering issues with short audio samples on macosx. patch by Chris Roccati <roccati@pobox.com>
nplourde
parents: 18915
diff changeset
411 ao->paused=1;
10147
f2725d6717bd Native MacOSX audio output by Dan Christiansen <danchr@daimi.au.dk>
alex
parents:
diff changeset
412 }
f2725d6717bd Native MacOSX audio output by Dan Christiansen <danchr@daimi.au.dk>
alex
parents:
diff changeset
413
f2725d6717bd Native MacOSX audio output by Dan Christiansen <danchr@daimi.au.dk>
alex
parents:
diff changeset
414
f2725d6717bd Native MacOSX audio output by Dan Christiansen <danchr@daimi.au.dk>
alex
parents:
diff changeset
415 /* resume playing, after audio_pause() */
18915
99e20a22d5d0 modifies function declarations without parameters from ()
reynaldo
parents: 18885
diff changeset
416 static void audio_resume(void)
10147
f2725d6717bd Native MacOSX audio output by Dan Christiansen <danchr@daimi.au.dk>
alex
parents:
diff changeset
417 {
19427
ada359817b61 fix buffering issues with short audio samples on macosx. patch by Chris Roccati <roccati@pobox.com>
nplourde
parents: 18915
diff changeset
418 if(ao->paused) {
15646
f46eae5e271b Mac OS X Audio with AudioUnits and AudioToolbox format converters, Patch by Chris Roccati<roccati@pobox.com
nplourde
parents: 15486
diff changeset
419 OSErr status=noErr;
19427
ada359817b61 fix buffering issues with short audio samples on macosx. patch by Chris Roccati <roccati@pobox.com>
nplourde
parents: 18915
diff changeset
420 /* start callback */
15646
f46eae5e271b Mac OS X Audio with AudioUnits and AudioToolbox format converters, Patch by Chris Roccati<roccati@pobox.com
nplourde
parents: 15486
diff changeset
421 status=AudioOutputUnitStart(ao->theOutputUnit);
10147
f2725d6717bd Native MacOSX audio output by Dan Christiansen <danchr@daimi.au.dk>
alex
parents:
diff changeset
422 if (status)
15646
f46eae5e271b Mac OS X Audio with AudioUnits and AudioToolbox format converters, Patch by Chris Roccati<roccati@pobox.com
nplourde
parents: 15486
diff changeset
423 ao_msg(MSGT_AO,MSGL_WARN, "AudioOutputUnitStart returned %d\n",
10147
f2725d6717bd Native MacOSX audio output by Dan Christiansen <danchr@daimi.au.dk>
alex
parents:
diff changeset
424 (int)status);
19427
ada359817b61 fix buffering issues with short audio samples on macosx. patch by Chris Roccati <roccati@pobox.com>
nplourde
parents: 18915
diff changeset
425 ao->paused=0;
ada359817b61 fix buffering issues with short audio samples on macosx. patch by Chris Roccati <roccati@pobox.com>
nplourde
parents: 18915
diff changeset
426 }
10147
f2725d6717bd Native MacOSX audio output by Dan Christiansen <danchr@daimi.au.dk>
alex
parents:
diff changeset
427 }