Mercurial > mplayer.hg
annotate libao2/ao_macosx.c @ 24173:49aa1cef1867
Fix warning:
In file included from layer3.c:1171,
from sr1.c:391:
decod386.c:106: warning: redundant redeclaration of 'synth_1to1_MMX'
mpg123.h:120: warning: previous declaration of 'synth_1to1_MMX' was here
author | diego |
---|---|
date | Sat, 25 Aug 2007 17:05:02 +0000 |
parents | 300e9b7c499f |
children | 09f9d0de17f1 |
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 * |
21977
cea0eb833758
Fix FSF address and otherwise broken license headers.
diego
parents:
21352
diff
changeset
|
20 * You should have received a copy of the GNU General Public License along |
cea0eb833758
Fix FSF address and otherwise broken license headers.
diego
parents:
21352
diff
changeset
|
21 * with libao; if not, write to the Free Software Foundation, Inc., |
cea0eb833758
Fix FSF address and otherwise broken license headers.
diego
parents:
21352
diff
changeset
|
22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
10147
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 | 49 #include "config.h" |
14123 | 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 | 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 | 66 /* Prefix for all mp_msg() calls */ |
67 #define ao_msg(a, b, c...) mp_msg(a, b, "AO: [macosx] " c) | |
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 | 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){ |
21352
2d786b7625d7
adds support for AOCONTROL_GET_VOLUME/AOCONTROL_SET_VOLUME in ao_macosx, patcg by Crhis Roccati<roccati@pobox.com>
nplourde
parents:
19427
diff
changeset
|
174 ao_control_vol_t *control_vol; |
2d786b7625d7
adds support for AOCONTROL_GET_VOLUME/AOCONTROL_SET_VOLUME in ao_macosx, patcg by Crhis Roccati<roccati@pobox.com>
nplourde
parents:
19427
diff
changeset
|
175 OSStatus err; |
23381
300e9b7c499f
Remove some unused variables, patch by timwoj ieee org.
diego
parents:
21977
diff
changeset
|
176 Float32 vol; |
10147
f2725d6717bd
Native MacOSX audio output by Dan Christiansen <danchr@daimi.au.dk>
alex
parents:
diff
changeset
|
177 switch (cmd) { |
14290 | 178 case AOCONTROL_GET_VOLUME: |
21352
2d786b7625d7
adds support for AOCONTROL_GET_VOLUME/AOCONTROL_SET_VOLUME in ao_macosx, patcg by Crhis Roccati<roccati@pobox.com>
nplourde
parents:
19427
diff
changeset
|
179 control_vol = (ao_control_vol_t*)arg; |
2d786b7625d7
adds support for AOCONTROL_GET_VOLUME/AOCONTROL_SET_VOLUME in ao_macosx, patcg by Crhis Roccati<roccati@pobox.com>
nplourde
parents:
19427
diff
changeset
|
180 err = AudioUnitGetParameter(ao->theOutputUnit, kHALOutputParam_Volume, kAudioUnitScope_Global, 0, &vol); |
2d786b7625d7
adds support for AOCONTROL_GET_VOLUME/AOCONTROL_SET_VOLUME in ao_macosx, patcg by Crhis Roccati<roccati@pobox.com>
nplourde
parents:
19427
diff
changeset
|
181 |
2d786b7625d7
adds support for AOCONTROL_GET_VOLUME/AOCONTROL_SET_VOLUME in ao_macosx, patcg by Crhis Roccati<roccati@pobox.com>
nplourde
parents:
19427
diff
changeset
|
182 if(err==0) { |
2d786b7625d7
adds support for AOCONTROL_GET_VOLUME/AOCONTROL_SET_VOLUME in ao_macosx, patcg by Crhis Roccati<roccati@pobox.com>
nplourde
parents:
19427
diff
changeset
|
183 // printf("GET VOL=%f\n", vol); |
2d786b7625d7
adds support for AOCONTROL_GET_VOLUME/AOCONTROL_SET_VOLUME in ao_macosx, patcg by Crhis Roccati<roccati@pobox.com>
nplourde
parents:
19427
diff
changeset
|
184 control_vol->left=control_vol->right=vol*100.0/4.0; |
2d786b7625d7
adds support for AOCONTROL_GET_VOLUME/AOCONTROL_SET_VOLUME in ao_macosx, patcg by Crhis Roccati<roccati@pobox.com>
nplourde
parents:
19427
diff
changeset
|
185 return CONTROL_TRUE; |
2d786b7625d7
adds support for AOCONTROL_GET_VOLUME/AOCONTROL_SET_VOLUME in ao_macosx, patcg by Crhis Roccati<roccati@pobox.com>
nplourde
parents:
19427
diff
changeset
|
186 } |
2d786b7625d7
adds support for AOCONTROL_GET_VOLUME/AOCONTROL_SET_VOLUME in ao_macosx, patcg by Crhis Roccati<roccati@pobox.com>
nplourde
parents:
19427
diff
changeset
|
187 else { |
2d786b7625d7
adds support for AOCONTROL_GET_VOLUME/AOCONTROL_SET_VOLUME in ao_macosx, patcg by Crhis Roccati<roccati@pobox.com>
nplourde
parents:
19427
diff
changeset
|
188 return CONTROL_FALSE; |
2d786b7625d7
adds support for AOCONTROL_GET_VOLUME/AOCONTROL_SET_VOLUME in ao_macosx, patcg by Crhis Roccati<roccati@pobox.com>
nplourde
parents:
19427
diff
changeset
|
189 } |
2d786b7625d7
adds support for AOCONTROL_GET_VOLUME/AOCONTROL_SET_VOLUME in ao_macosx, patcg by Crhis Roccati<roccati@pobox.com>
nplourde
parents:
19427
diff
changeset
|
190 |
14290 | 191 case AOCONTROL_SET_VOLUME: |
21352
2d786b7625d7
adds support for AOCONTROL_GET_VOLUME/AOCONTROL_SET_VOLUME in ao_macosx, patcg by Crhis Roccati<roccati@pobox.com>
nplourde
parents:
19427
diff
changeset
|
192 control_vol = (ao_control_vol_t*)arg; |
2d786b7625d7
adds support for AOCONTROL_GET_VOLUME/AOCONTROL_SET_VOLUME in ao_macosx, patcg by Crhis Roccati<roccati@pobox.com>
nplourde
parents:
19427
diff
changeset
|
193 |
2d786b7625d7
adds support for AOCONTROL_GET_VOLUME/AOCONTROL_SET_VOLUME in ao_macosx, patcg by Crhis Roccati<roccati@pobox.com>
nplourde
parents:
19427
diff
changeset
|
194 vol=(control_vol->left+control_vol->right)*4.0/200.0; |
2d786b7625d7
adds support for AOCONTROL_GET_VOLUME/AOCONTROL_SET_VOLUME in ao_macosx, patcg by Crhis Roccati<roccati@pobox.com>
nplourde
parents:
19427
diff
changeset
|
195 err = AudioUnitSetParameter(ao->theOutputUnit, kHALOutputParam_Volume, kAudioUnitScope_Global, 0, vol, 0); |
2d786b7625d7
adds support for AOCONTROL_GET_VOLUME/AOCONTROL_SET_VOLUME in ao_macosx, patcg by Crhis Roccati<roccati@pobox.com>
nplourde
parents:
19427
diff
changeset
|
196 if(err==0) { |
2d786b7625d7
adds support for AOCONTROL_GET_VOLUME/AOCONTROL_SET_VOLUME in ao_macosx, patcg by Crhis Roccati<roccati@pobox.com>
nplourde
parents:
19427
diff
changeset
|
197 // printf("SET VOL=%f\n", vol); |
2d786b7625d7
adds support for AOCONTROL_GET_VOLUME/AOCONTROL_SET_VOLUME in ao_macosx, patcg by Crhis Roccati<roccati@pobox.com>
nplourde
parents:
19427
diff
changeset
|
198 return CONTROL_TRUE; |
2d786b7625d7
adds support for AOCONTROL_GET_VOLUME/AOCONTROL_SET_VOLUME in ao_macosx, patcg by Crhis Roccati<roccati@pobox.com>
nplourde
parents:
19427
diff
changeset
|
199 } |
2d786b7625d7
adds support for AOCONTROL_GET_VOLUME/AOCONTROL_SET_VOLUME in ao_macosx, patcg by Crhis Roccati<roccati@pobox.com>
nplourde
parents:
19427
diff
changeset
|
200 else { |
2d786b7625d7
adds support for AOCONTROL_GET_VOLUME/AOCONTROL_SET_VOLUME in ao_macosx, patcg by Crhis Roccati<roccati@pobox.com>
nplourde
parents:
19427
diff
changeset
|
201 return CONTROL_FALSE; |
2d786b7625d7
adds support for AOCONTROL_GET_VOLUME/AOCONTROL_SET_VOLUME in ao_macosx, patcg by Crhis Roccati<roccati@pobox.com>
nplourde
parents:
19427
diff
changeset
|
202 } |
15646
f46eae5e271b
Mac OS X Audio with AudioUnits and AudioToolbox format converters, Patch by Chris Roccati<roccati@pobox.com
nplourde
parents:
15486
diff
changeset
|
203 /* Everything is currently unimplemented */ |
10147
f2725d6717bd
Native MacOSX audio output by Dan Christiansen <danchr@daimi.au.dk>
alex
parents:
diff
changeset
|
204 default: |
10152 | 205 return CONTROL_FALSE; |
10147
f2725d6717bd
Native MacOSX audio output by Dan Christiansen <danchr@daimi.au.dk>
alex
parents:
diff
changeset
|
206 } |
f2725d6717bd
Native MacOSX audio output by Dan Christiansen <danchr@daimi.au.dk>
alex
parents:
diff
changeset
|
207 |
f2725d6717bd
Native MacOSX audio output by Dan Christiansen <danchr@daimi.au.dk>
alex
parents:
diff
changeset
|
208 } |
f2725d6717bd
Native MacOSX audio output by Dan Christiansen <danchr@daimi.au.dk>
alex
parents:
diff
changeset
|
209 |
f2725d6717bd
Native MacOSX audio output by Dan Christiansen <danchr@daimi.au.dk>
alex
parents:
diff
changeset
|
210 |
14317 | 211 static void print_format(const char* str,AudioStreamBasicDescription *f){ |
14290 | 212 uint32_t flags=(uint32_t) f->mFormatFlags; |
14317 | 213 ao_msg(MSGT_AO,MSGL_V, "%s %7.1fHz %dbit [%c%c%c%c] %s %s %s%s%s%s\n", |
214 str, f->mSampleRate, f->mBitsPerChannel, | |
14290 | 215 (int)(f->mFormatID & 0xff000000) >> 24, |
216 (int)(f->mFormatID & 0x00ff0000) >> 16, | |
217 (int)(f->mFormatID & 0x0000ff00) >> 8, | |
218 (int)(f->mFormatID & 0x000000ff) >> 0, | |
219 (flags&kAudioFormatFlagIsFloat) ? "float" : "int", | |
220 (flags&kAudioFormatFlagIsBigEndian) ? "BE" : "LE", | |
221 (flags&kAudioFormatFlagIsSignedInteger) ? "S" : "U", | |
222 (flags&kAudioFormatFlagIsPacked) ? " packed" : "", | |
223 (flags&kAudioFormatFlagIsAlignedHigh) ? " aligned" : "", | |
224 (flags&kAudioFormatFlagIsNonInterleaved) ? " ni" : "" ); | |
225 | |
14317 | 226 ao_msg(MSGT_AO,MSGL_DBG2, "%5d mBytesPerPacket\n", |
14290 | 227 (int)f->mBytesPerPacket); |
14317 | 228 ao_msg(MSGT_AO,MSGL_DBG2, "%5d mFramesPerPacket\n", |
14290 | 229 (int)f->mFramesPerPacket); |
14317 | 230 ao_msg(MSGT_AO,MSGL_DBG2, "%5d mBytesPerFrame\n", |
14290 | 231 (int)f->mBytesPerFrame); |
14317 | 232 ao_msg(MSGT_AO,MSGL_DBG2, "%5d mChannelsPerFrame\n", |
14290 | 233 (int)f->mChannelsPerFrame); |
234 | |
235 } | |
236 | |
237 | |
10147
f2725d6717bd
Native MacOSX audio output by Dan Christiansen <danchr@daimi.au.dk>
alex
parents:
diff
changeset
|
238 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
|
239 { |
23381
300e9b7c499f
Remove some unused variables, patch by timwoj ieee org.
diego
parents:
21977
diff
changeset
|
240 AudioStreamBasicDescription inDesc; |
15646
f46eae5e271b
Mac OS X Audio with AudioUnits and AudioToolbox format converters, Patch by Chris Roccati<roccati@pobox.com
nplourde
parents:
15486
diff
changeset
|
241 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
|
242 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
|
243 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
|
244 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
|
245 UInt32 size, maxFrames; |
15853
6e994905f77b
more general ao_macosx cleanup. Patch by Alexander Strange <astrange@ithinksw.com>
nplourde
parents:
15722
diff
changeset
|
246 int aoIsCreated = ao != NULL; |
14317 | 247 |
18885 | 248 if (!aoIsCreated) ao = malloc(sizeof(ao_macosx_t)); |
14290 | 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 // 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
|
251 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
|
252 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
|
253 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
|
254 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
|
255 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
|
256 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
|
257 break; |
f46eae5e271b
Mac OS X Audio with AudioUnits and AudioToolbox format converters, Patch by Chris Roccati<roccati@pobox.com
nplourde
parents:
15486
diff
changeset
|
258 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
|
259 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
|
260 break; |
f46eae5e271b
Mac OS X Audio with AudioUnits and AudioToolbox format converters, Patch by Chris Roccati<roccati@pobox.com
nplourde
parents:
15486
diff
changeset
|
261 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
|
262 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
|
263 break; |
f46eae5e271b
Mac OS X Audio with AudioUnits and AudioToolbox format converters, Patch by Chris Roccati<roccati@pobox.com
nplourde
parents:
15486
diff
changeset
|
264 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
|
265 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
|
266 break; |
f46eae5e271b
Mac OS X Audio with AudioUnits and AudioToolbox format converters, Patch by Chris Roccati<roccati@pobox.com
nplourde
parents:
15486
diff
changeset
|
267 default: |
f46eae5e271b
Mac OS X Audio with AudioUnits and AudioToolbox format converters, Patch by Chris Roccati<roccati@pobox.com
nplourde
parents:
15486
diff
changeset
|
268 ao_msg(MSGT_AO, MSGL_WARN, "Unsupported format (0x%08x)\n", format); |
14290 | 269 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
|
270 break; |
f46eae5e271b
Mac OS X Audio with AudioUnits and AudioToolbox format converters, Patch by Chris Roccati<roccati@pobox.com
nplourde
parents:
15486
diff
changeset
|
271 } |
10147
f2725d6717bd
Native MacOSX audio output by Dan Christiansen <danchr@daimi.au.dk>
alex
parents:
diff
changeset
|
272 |
15646
f46eae5e271b
Mac OS X Audio with AudioUnits and AudioToolbox format converters, Patch by Chris Roccati<roccati@pobox.com
nplourde
parents:
15486
diff
changeset
|
273 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
|
274 // float |
f46eae5e271b
Mac OS X Audio with AudioUnits and AudioToolbox format converters, Patch by Chris Roccati<roccati@pobox.com
nplourde
parents:
15486
diff
changeset
|
275 inDesc.mFormatFlags = kAudioFormatFlagIsFloat|kAudioFormatFlagIsPacked; |
10147
f2725d6717bd
Native MacOSX audio output by Dan Christiansen <danchr@daimi.au.dk>
alex
parents:
diff
changeset
|
276 } |
15646
f46eae5e271b
Mac OS X Audio with AudioUnits and AudioToolbox format converters, Patch by Chris Roccati<roccati@pobox.com
nplourde
parents:
15486
diff
changeset
|
277 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
|
278 // 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
|
279 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
|
280 } |
f46eae5e271b
Mac OS X Audio with AudioUnits and AudioToolbox format converters, Patch by Chris Roccati<roccati@pobox.com
nplourde
parents:
15486
diff
changeset
|
281 else { |
f46eae5e271b
Mac OS X Audio with AudioUnits and AudioToolbox format converters, Patch by Chris Roccati<roccati@pobox.com
nplourde
parents:
15486
diff
changeset
|
282 // 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
|
283 inDesc.mFormatFlags = kAudioFormatFlagIsPacked; |
10147
f2725d6717bd
Native MacOSX audio output by Dan Christiansen <danchr@daimi.au.dk>
alex
parents:
diff
changeset
|
284 } |
f2725d6717bd
Native MacOSX audio output by Dan Christiansen <danchr@daimi.au.dk>
alex
parents:
diff
changeset
|
285 |
15646
f46eae5e271b
Mac OS X Audio with AudioUnits and AudioToolbox format converters, Patch by Chris Roccati<roccati@pobox.com
nplourde
parents:
15486
diff
changeset
|
286 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
|
287 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
|
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 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
|
290 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
|
291 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
|
292 |
15853
6e994905f77b
more general ao_macosx cleanup. Patch by Alexander Strange <astrange@ithinksw.com>
nplourde
parents:
15722
diff
changeset
|
293 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
|
294 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
|
295 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
|
296 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
|
297 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
|
298 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
|
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 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
|
301 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
|
302 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
|
303 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
|
304 } |
f46eae5e271b
Mac OS X Audio with AudioUnits and AudioToolbox format converters, Patch by Chris Roccati<roccati@pobox.com
nplourde
parents:
15486
diff
changeset
|
305 |
f46eae5e271b
Mac OS X Audio with AudioUnits and AudioToolbox format converters, Patch by Chris Roccati<roccati@pobox.com
nplourde
parents:
15486
diff
changeset
|
306 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
|
307 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
|
308 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
|
309 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
|
310 } |
f46eae5e271b
Mac OS X Audio with AudioUnits and AudioToolbox format converters, Patch by Chris Roccati<roccati@pobox.com
nplourde
parents:
15486
diff
changeset
|
311 |
f46eae5e271b
Mac OS X Audio with AudioUnits and AudioToolbox format converters, Patch by Chris Roccati<roccati@pobox.com
nplourde
parents:
15486
diff
changeset
|
312 // 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
|
313 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
|
314 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
|
315 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
|
316 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
|
317 } |
15853
6e994905f77b
more general ao_macosx cleanup. Patch by Alexander Strange <astrange@ithinksw.com>
nplourde
parents:
15722
diff
changeset
|
318 } |
15646
f46eae5e271b
Mac OS X Audio with AudioUnits and AudioToolbox format converters, Patch by Chris Roccati<roccati@pobox.com
nplourde
parents:
15486
diff
changeset
|
319 |
f46eae5e271b
Mac OS X Audio with AudioUnits and AudioToolbox format converters, Patch by Chris Roccati<roccati@pobox.com
nplourde
parents:
15486
diff
changeset
|
320 size = sizeof(AudioStreamBasicDescription); |
15722
b53c4b26dc96
removes the use of AudioConverters. patch by Alexander Strange <alexander.strange@ithinksw.com>
nplourde
parents:
15646
diff
changeset
|
321 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
|
322 |
f46eae5e271b
Mac OS X Audio with AudioUnits and AudioToolbox format converters, Patch by Chris Roccati<roccati@pobox.com
nplourde
parents:
15486
diff
changeset
|
323 if (err) { |
15722
b53c4b26dc96
removes the use of AudioConverters. patch by Alexander Strange <alexander.strange@ithinksw.com>
nplourde
parents:
15646
diff
changeset
|
324 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
|
325 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
|
326 } |
f46eae5e271b
Mac OS X Audio with AudioUnits and AudioToolbox format converters, Patch by Chris Roccati<roccati@pobox.com
nplourde
parents:
15486
diff
changeset
|
327 |
16014 | 328 size = sizeof(UInt32); |
329 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
|
330 |
16014 | 331 if (err) |
332 { | |
333 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
|
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 |
16014 | 337 ao->chunk_size = maxFrames;//*inDesc.mBytesPerFrame; |
338 | |
19427
ada359817b61
fix buffering issues with short audio samples on macosx. patch by Chris Roccati <roccati@pobox.com>
nplourde
parents:
18915
diff
changeset
|
339 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
|
340 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
|
341 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
|
342 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
|
343 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
|
344 |
ada359817b61
fix buffering issues with short audio samples on macosx. patch by Chris Roccati <roccati@pobox.com>
nplourde
parents:
18915
diff
changeset
|
345 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
|
346 ao->buffer_len = (ao->num_chunks + 1) * ao->chunk_size; |
18885 | 347 ao->buffer = aoIsCreated ? realloc(ao->buffer,(ao->num_chunks + 1)*ao->chunk_size) |
348 : 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
|
349 |
19427
ada359817b61
fix buffering issues with short audio samples on macosx. patch by Chris Roccati <roccati@pobox.com>
nplourde
parents:
18915
diff
changeset
|
350 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
|
351 |
15646
f46eae5e271b
Mac OS X Audio with AudioUnits and AudioToolbox format converters, Patch by Chris Roccati<roccati@pobox.com
nplourde
parents:
15486
diff
changeset
|
352 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
|
353 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
|
354 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
|
355 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
|
356 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
|
357 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
|
358 } |
f46eae5e271b
Mac OS X Audio with AudioUnits and AudioToolbox format converters, Patch by Chris Roccati<roccati@pobox.com
nplourde
parents:
15486
diff
changeset
|
359 |
19427
ada359817b61
fix buffering issues with short audio samples on macosx. patch by Chris Roccati <roccati@pobox.com>
nplourde
parents:
18915
diff
changeset
|
360 reset(); |
10147
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 return CONTROL_OK; |
f2725d6717bd
Native MacOSX audio output by Dan Christiansen <danchr@daimi.au.dk>
alex
parents:
diff
changeset
|
363 } |
f2725d6717bd
Native MacOSX audio output by Dan Christiansen <danchr@daimi.au.dk>
alex
parents:
diff
changeset
|
364 |
f2725d6717bd
Native MacOSX audio output by Dan Christiansen <danchr@daimi.au.dk>
alex
parents:
diff
changeset
|
365 |
f2725d6717bd
Native MacOSX audio output by Dan Christiansen <danchr@daimi.au.dk>
alex
parents:
diff
changeset
|
366 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
|
367 { |
19427
ada359817b61
fix buffering issues with short audio samples on macosx. patch by Chris Roccati <roccati@pobox.com>
nplourde
parents:
18915
diff
changeset
|
368 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
|
369 |
15853
6e994905f77b
more general ao_macosx cleanup. Patch by Alexander Strange <astrange@ithinksw.com>
nplourde
parents:
15722
diff
changeset
|
370 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
|
371 return wrote; |
10147
f2725d6717bd
Native MacOSX audio output by Dan Christiansen <danchr@daimi.au.dk>
alex
parents:
diff
changeset
|
372 } |
f2725d6717bd
Native MacOSX audio output by Dan Christiansen <danchr@daimi.au.dk>
alex
parents:
diff
changeset
|
373 |
f2725d6717bd
Native MacOSX audio output by Dan Christiansen <danchr@daimi.au.dk>
alex
parents:
diff
changeset
|
374 /* set variables and buffer to initial state */ |
18915
99e20a22d5d0
modifies function declarations without parameters from ()
reynaldo
parents:
18885
diff
changeset
|
375 static void reset(void) |
10147
f2725d6717bd
Native MacOSX audio output by Dan Christiansen <danchr@daimi.au.dk>
alex
parents:
diff
changeset
|
376 { |
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
|
377 audio_pause(); |
10147
f2725d6717bd
Native MacOSX audio output by Dan Christiansen <danchr@daimi.au.dk>
alex
parents:
diff
changeset
|
378 /* reset ring-buffer state */ |
f2725d6717bd
Native MacOSX audio output by Dan Christiansen <danchr@daimi.au.dk>
alex
parents:
diff
changeset
|
379 ao->buf_read_pos=0; |
f2725d6717bd
Native MacOSX audio output by Dan Christiansen <danchr@daimi.au.dk>
alex
parents:
diff
changeset
|
380 ao->buf_write_pos=0; |
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 return; |
f2725d6717bd
Native MacOSX audio output by Dan Christiansen <danchr@daimi.au.dk>
alex
parents:
diff
changeset
|
383 } |
f2725d6717bd
Native MacOSX audio output by Dan Christiansen <danchr@daimi.au.dk>
alex
parents:
diff
changeset
|
384 |
f2725d6717bd
Native MacOSX audio output by Dan Christiansen <danchr@daimi.au.dk>
alex
parents:
diff
changeset
|
385 |
f2725d6717bd
Native MacOSX audio output by Dan Christiansen <danchr@daimi.au.dk>
alex
parents:
diff
changeset
|
386 /* return available space */ |
18915
99e20a22d5d0
modifies function declarations without parameters from ()
reynaldo
parents:
18885
diff
changeset
|
387 static int get_space(void) |
10147
f2725d6717bd
Native MacOSX audio output by Dan Christiansen <danchr@daimi.au.dk>
alex
parents:
diff
changeset
|
388 { |
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
|
389 return buf_free(); |
10147
f2725d6717bd
Native MacOSX audio output by Dan Christiansen <danchr@daimi.au.dk>
alex
parents:
diff
changeset
|
390 } |
f2725d6717bd
Native MacOSX audio output by Dan Christiansen <danchr@daimi.au.dk>
alex
parents:
diff
changeset
|
391 |
f2725d6717bd
Native MacOSX audio output by Dan Christiansen <danchr@daimi.au.dk>
alex
parents:
diff
changeset
|
392 |
10152 | 393 /* return delay until audio is played */ |
18915
99e20a22d5d0
modifies function declarations without parameters from ()
reynaldo
parents:
18885
diff
changeset
|
394 static float get_delay(void) |
10147
f2725d6717bd
Native MacOSX audio output by Dan Christiansen <danchr@daimi.au.dk>
alex
parents:
diff
changeset
|
395 { |
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
|
396 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
|
397 // 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
|
398 return (float)(buffered)/(float)ao_data.bps; |
10147
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 |
f2725d6717bd
Native MacOSX audio output by Dan Christiansen <danchr@daimi.au.dk>
alex
parents:
diff
changeset
|
402 /* unload plugin and deregister from coreaudio */ |
12145 | 403 static void uninit(int immed) |
10147
f2725d6717bd
Native MacOSX audio output by Dan Christiansen <danchr@daimi.au.dk>
alex
parents:
diff
changeset
|
404 { |
f2725d6717bd
Native MacOSX audio output by Dan Christiansen <danchr@daimi.au.dk>
alex
parents:
diff
changeset
|
405 |
19427
ada359817b61
fix buffering issues with short audio samples on macosx. patch by Chris Roccati <roccati@pobox.com>
nplourde
parents:
18915
diff
changeset
|
406 if (!immed) { |
ada359817b61
fix buffering issues with short audio samples on macosx. patch by Chris Roccati <roccati@pobox.com>
nplourde
parents:
18915
diff
changeset
|
407 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
|
408 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
|
409 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
|
410 } |
10147
f2725d6717bd
Native MacOSX audio output by Dan Christiansen <danchr@daimi.au.dk>
alex
parents:
diff
changeset
|
411 |
15646
f46eae5e271b
Mac OS X Audio with AudioUnits and AudioToolbox format converters, Patch by Chris Roccati<roccati@pobox.com
nplourde
parents:
15486
diff
changeset
|
412 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
|
413 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
|
414 CloseComponent(ao->theOutputUnit); |
10147
f2725d6717bd
Native MacOSX audio output by Dan Christiansen <danchr@daimi.au.dk>
alex
parents:
diff
changeset
|
415 |
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
|
416 free(ao->buffer); |
10147
f2725d6717bd
Native MacOSX audio output by Dan Christiansen <danchr@daimi.au.dk>
alex
parents:
diff
changeset
|
417 free(ao); |
15853
6e994905f77b
more general ao_macosx cleanup. Patch by Alexander Strange <astrange@ithinksw.com>
nplourde
parents:
15722
diff
changeset
|
418 ao = NULL; |
10147
f2725d6717bd
Native MacOSX audio output by Dan Christiansen <danchr@daimi.au.dk>
alex
parents:
diff
changeset
|
419 } |
f2725d6717bd
Native MacOSX audio output by Dan Christiansen <danchr@daimi.au.dk>
alex
parents:
diff
changeset
|
420 |
f2725d6717bd
Native MacOSX audio output by Dan Christiansen <danchr@daimi.au.dk>
alex
parents:
diff
changeset
|
421 |
f2725d6717bd
Native MacOSX audio output by Dan Christiansen <danchr@daimi.au.dk>
alex
parents:
diff
changeset
|
422 /* stop playing, keep buffers (for pause) */ |
18915
99e20a22d5d0
modifies function declarations without parameters from ()
reynaldo
parents:
18885
diff
changeset
|
423 static void audio_pause(void) |
10147
f2725d6717bd
Native MacOSX audio output by Dan Christiansen <danchr@daimi.au.dk>
alex
parents:
diff
changeset
|
424 { |
15646
f46eae5e271b
Mac OS X Audio with AudioUnits and AudioToolbox format converters, Patch by Chris Roccati<roccati@pobox.com
nplourde
parents:
15486
diff
changeset
|
425 OSErr status=noErr; |
10147
f2725d6717bd
Native MacOSX audio output by Dan Christiansen <danchr@daimi.au.dk>
alex
parents:
diff
changeset
|
426 |
f2725d6717bd
Native MacOSX audio output by Dan Christiansen <danchr@daimi.au.dk>
alex
parents:
diff
changeset
|
427 /* 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
|
428 status=AudioOutputUnitStop(ao->theOutputUnit); |
10147
f2725d6717bd
Native MacOSX audio output by Dan Christiansen <danchr@daimi.au.dk>
alex
parents:
diff
changeset
|
429 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
|
430 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
|
431 (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
|
432 ao->paused=1; |
10147
f2725d6717bd
Native MacOSX audio output by Dan Christiansen <danchr@daimi.au.dk>
alex
parents:
diff
changeset
|
433 } |
f2725d6717bd
Native MacOSX audio output by Dan Christiansen <danchr@daimi.au.dk>
alex
parents:
diff
changeset
|
434 |
f2725d6717bd
Native MacOSX audio output by Dan Christiansen <danchr@daimi.au.dk>
alex
parents:
diff
changeset
|
435 |
f2725d6717bd
Native MacOSX audio output by Dan Christiansen <danchr@daimi.au.dk>
alex
parents:
diff
changeset
|
436 /* resume playing, after audio_pause() */ |
18915
99e20a22d5d0
modifies function declarations without parameters from ()
reynaldo
parents:
18885
diff
changeset
|
437 static void audio_resume(void) |
10147
f2725d6717bd
Native MacOSX audio output by Dan Christiansen <danchr@daimi.au.dk>
alex
parents:
diff
changeset
|
438 { |
19427
ada359817b61
fix buffering issues with short audio samples on macosx. patch by Chris Roccati <roccati@pobox.com>
nplourde
parents:
18915
diff
changeset
|
439 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
|
440 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
|
441 /* 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
|
442 status=AudioOutputUnitStart(ao->theOutputUnit); |
10147
f2725d6717bd
Native MacOSX audio output by Dan Christiansen <danchr@daimi.au.dk>
alex
parents:
diff
changeset
|
443 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
|
444 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
|
445 (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
|
446 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
|
447 } |
10147
f2725d6717bd
Native MacOSX audio output by Dan Christiansen <danchr@daimi.au.dk>
alex
parents:
diff
changeset
|
448 } |