Mercurial > sdl-ios-xcode
annotate src/audio/ums/SDL_umsaudio.c @ 1713:3e66ed1690e4 SDL-1.3
Whoops, forgot to indent
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Mon, 26 Jun 2006 14:29:50 +0000 |
parents | 4da1ee79c9af |
children |
rev | line source |
---|---|
0 | 1 /* |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
0
diff
changeset
|
2 SDL - Simple DirectMedia Layer |
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
0
diff
changeset
|
3 Copyright (C) 1997-2006 Sam Lantinga |
0 | 4 |
5 This library is free software; you can redistribute it and/or | |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
0
diff
changeset
|
6 modify it under the terms of the GNU Lesser General Public |
0 | 7 License as published by the Free Software Foundation; either |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
0
diff
changeset
|
8 version 2.1 of the License, or (at your option) any later version. |
0 | 9 |
10 This library is distributed in the hope that it will be useful, | |
11 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
0
diff
changeset
|
13 Lesser General Public License for more details. |
0 | 14 |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
0
diff
changeset
|
15 You should have received a copy of the GNU Lesser General Public |
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
0
diff
changeset
|
16 License along with this library; if not, write to the Free Software |
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
0
diff
changeset
|
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
0 | 18 |
19 Carsten Griwodz | |
20 griff@kom.tu-darmstadt.de | |
21 | |
22 based on linux/SDL_dspaudio.c by Sam Lantinga | |
23 */ | |
1402
d910939febfa
Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents:
1361
diff
changeset
|
24 #include "SDL_config.h" |
0 | 25 |
26 /* Allow access to a raw mixing buffer */ | |
27 | |
28 #include <errno.h> | |
29 #include <unistd.h> | |
30 #include <fcntl.h> | |
31 #include <sys/types.h> | |
32 #include <sys/time.h> | |
33 #include <sys/ioctl.h> | |
34 #include <sys/stat.h> | |
35 #include <sys/mman.h> | |
36 | |
37 #include "SDL_audio.h" | |
1361
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1358
diff
changeset
|
38 #include "../SDL_audio_c.h" |
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1358
diff
changeset
|
39 #include "../SDL_audiodev_c.h" |
0 | 40 #include "SDL_umsaudio.h" |
41 | |
42 /* The tag name used by UMS audio */ | |
43 #define UMS_DRIVER_NAME "ums" | |
44 | |
45 #define DEBUG_AUDIO 1 | |
46 | |
47 /* Audio driver functions */ | |
1668
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1662
diff
changeset
|
48 static int UMS_OpenAudio(_THIS, SDL_AudioSpec * spec); |
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1662
diff
changeset
|
49 static void UMS_PlayAudio(_THIS); |
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1662
diff
changeset
|
50 static Uint8 *UMS_GetAudioBuf(_THIS); |
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1662
diff
changeset
|
51 static void UMS_CloseAudio(_THIS); |
0 | 52 |
1668
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1662
diff
changeset
|
53 static UMSAudioDevice_ReturnCode UADOpen(_THIS, string device, string mode, |
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1662
diff
changeset
|
54 long flags); |
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1662
diff
changeset
|
55 static UMSAudioDevice_ReturnCode UADClose(_THIS); |
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1662
diff
changeset
|
56 static UMSAudioDevice_ReturnCode UADGetBitsPerSample(_THIS, long *bits); |
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1662
diff
changeset
|
57 static UMSAudioDevice_ReturnCode UADSetBitsPerSample(_THIS, long bits); |
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1662
diff
changeset
|
58 static UMSAudioDevice_ReturnCode UADSetSampleRate(_THIS, long rate, |
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1662
diff
changeset
|
59 long *set_rate); |
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1662
diff
changeset
|
60 static UMSAudioDevice_ReturnCode UADSetByteOrder(_THIS, string byte_order); |
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1662
diff
changeset
|
61 static UMSAudioDevice_ReturnCode UADSetAudioFormatType(_THIS, string fmt); |
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1662
diff
changeset
|
62 static UMSAudioDevice_ReturnCode UADSetNumberFormat(_THIS, string fmt); |
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1662
diff
changeset
|
63 static UMSAudioDevice_ReturnCode UADInitialize(_THIS); |
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1662
diff
changeset
|
64 static UMSAudioDevice_ReturnCode UADStart(_THIS); |
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1662
diff
changeset
|
65 static UMSAudioDevice_ReturnCode UADStop(_THIS); |
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1662
diff
changeset
|
66 static UMSAudioDevice_ReturnCode UADSetTimeFormat(_THIS, |
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1662
diff
changeset
|
67 UMSAudioTypes_TimeFormat |
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1662
diff
changeset
|
68 fmt); |
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1662
diff
changeset
|
69 static UMSAudioDevice_ReturnCode UADWriteBuffSize(_THIS, long *buff_size); |
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1662
diff
changeset
|
70 static UMSAudioDevice_ReturnCode UADWriteBuffRemain(_THIS, long *buff_size); |
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1662
diff
changeset
|
71 static UMSAudioDevice_ReturnCode UADWriteBuffUsed(_THIS, long *buff_size); |
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1662
diff
changeset
|
72 static UMSAudioDevice_ReturnCode UADSetDMABufferSize(_THIS, long bytes, |
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1662
diff
changeset
|
73 long *bytes_ret); |
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1662
diff
changeset
|
74 static UMSAudioDevice_ReturnCode UADSetVolume(_THIS, long volume); |
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1662
diff
changeset
|
75 static UMSAudioDevice_ReturnCode UADSetBalance(_THIS, long balance); |
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1662
diff
changeset
|
76 static UMSAudioDevice_ReturnCode UADSetChannels(_THIS, long channels); |
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1662
diff
changeset
|
77 static UMSAudioDevice_ReturnCode UADPlayRemainingData(_THIS, boolean block); |
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1662
diff
changeset
|
78 static UMSAudioDevice_ReturnCode UADEnableOutput(_THIS, string output, |
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1662
diff
changeset
|
79 long *left_gain, |
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1662
diff
changeset
|
80 long *right_gain); |
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1662
diff
changeset
|
81 static UMSAudioDevice_ReturnCode UADWrite(_THIS, UMSAudioTypes_Buffer * buff, |
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1662
diff
changeset
|
82 long samples, |
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1662
diff
changeset
|
83 long *samples_written); |
0 | 84 |
85 /* Audio driver bootstrap functions */ | |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
86 static int |
1668
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1662
diff
changeset
|
87 Audio_Available(void) |
0 | 88 { |
89 return 1; | |
90 } | |
91 | |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
92 static void |
1668
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1662
diff
changeset
|
93 Audio_DeleteDevice(_THIS) |
0 | 94 { |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
95 if (this->hidden->playbuf._buffer) |
1668
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1662
diff
changeset
|
96 SDL_free(this->hidden->playbuf._buffer); |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
97 if (this->hidden->fillbuf._buffer) |
1668
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1662
diff
changeset
|
98 SDL_free(this->hidden->fillbuf._buffer); |
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1662
diff
changeset
|
99 _somFree(this->hidden->umsdev); |
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1662
diff
changeset
|
100 SDL_free(this->hidden); |
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1662
diff
changeset
|
101 SDL_free(this); |
0 | 102 } |
103 | |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
104 static SDL_AudioDevice * |
1668
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1662
diff
changeset
|
105 Audio_CreateDevice(int devindex) |
0 | 106 { |
107 SDL_AudioDevice *this; | |
108 | |
109 /* | |
110 * Allocate and initialize management storage and private management | |
111 * storage for this SDL-using library. | |
112 */ | |
1668
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1662
diff
changeset
|
113 this = (SDL_AudioDevice *) SDL_malloc(sizeof(SDL_AudioDevice)); |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
114 if (this) { |
1668
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1662
diff
changeset
|
115 SDL_memset(this, 0, (sizeof *this)); |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
116 this->hidden = (struct SDL_PrivateAudioData *) |
1668
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1662
diff
changeset
|
117 SDL_malloc((sizeof *this->hidden)); |
0 | 118 } |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
119 if ((this == NULL) || (this->hidden == NULL)) { |
1668
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1662
diff
changeset
|
120 SDL_OutOfMemory(); |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
121 if (this) { |
1668
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1662
diff
changeset
|
122 SDL_free(this); |
0 | 123 } |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
124 return (0); |
0 | 125 } |
1668
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1662
diff
changeset
|
126 SDL_memset(this->hidden, 0, (sizeof *this->hidden)); |
0 | 127 #ifdef DEBUG_AUDIO |
1668
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1662
diff
changeset
|
128 fprintf(stderr, "Creating UMS Audio device\n"); |
0 | 129 #endif |
130 | |
131 /* | |
132 * Calls for UMS env initialization and audio object construction. | |
133 */ | |
1668
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1662
diff
changeset
|
134 this->hidden->ev = somGetGlobalEnvironment(); |
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1662
diff
changeset
|
135 this->hidden->umsdev = UMSAudioDeviceNew(); |
0 | 136 |
137 /* | |
138 * Set the function pointers. | |
139 */ | |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
140 this->OpenAudio = UMS_OpenAudio; |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
141 this->WaitAudio = NULL; /* we do blocking output */ |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
142 this->PlayAudio = UMS_PlayAudio; |
0 | 143 this->GetAudioBuf = UMS_GetAudioBuf; |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
144 this->CloseAudio = UMS_CloseAudio; |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
145 this->free = Audio_DeleteDevice; |
0 | 146 |
147 #ifdef DEBUG_AUDIO | |
1668
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1662
diff
changeset
|
148 fprintf(stderr, "done\n"); |
0 | 149 #endif |
150 return this; | |
151 } | |
152 | |
153 AudioBootStrap UMS_bootstrap = { | |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
154 UMS_DRIVER_NAME, "AUX UMS audio", |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
155 Audio_Available, Audio_CreateDevice |
0 | 156 }; |
157 | |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
158 static Uint8 * |
1668
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1662
diff
changeset
|
159 UMS_GetAudioBuf(_THIS) |
0 | 160 { |
161 #ifdef DEBUG_AUDIO | |
1668
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1662
diff
changeset
|
162 fprintf(stderr, "enter UMS_GetAudioBuf\n"); |
0 | 163 #endif |
164 return this->hidden->fillbuf._buffer; | |
165 /* | |
166 long bufSize; | |
167 UMSAudioDevice_ReturnCode rc; | |
168 | |
169 rc = UADSetTimeFormat(this, UMSAudioTypes_Bytes ); | |
170 rc = UADWriteBuffSize(this, bufSize ); | |
171 */ | |
172 } | |
173 | |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
174 static void |
1668
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1662
diff
changeset
|
175 UMS_CloseAudio(_THIS) |
0 | 176 { |
177 UMSAudioDevice_ReturnCode rc; | |
178 | |
179 #ifdef DEBUG_AUDIO | |
1668
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1662
diff
changeset
|
180 fprintf(stderr, "enter UMS_CloseAudio\n"); |
0 | 181 #endif |
1668
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1662
diff
changeset
|
182 rc = UADPlayRemainingData(this, TRUE); |
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1662
diff
changeset
|
183 rc = UADStop(this); |
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1662
diff
changeset
|
184 rc = UADClose(this); |
0 | 185 } |
186 | |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
187 static void |
1668
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1662
diff
changeset
|
188 UMS_PlayAudio(_THIS) |
0 | 189 { |
190 UMSAudioDevice_ReturnCode rc; | |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
191 long samplesToWrite; |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
192 long samplesWritten; |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
193 UMSAudioTypes_Buffer swpbuf; |
0 | 194 |
195 #ifdef DEBUG_AUDIO | |
1668
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1662
diff
changeset
|
196 fprintf(stderr, "enter UMS_PlayAudio\n"); |
0 | 197 #endif |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
198 samplesToWrite = |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
199 this->hidden->playbuf._length / this->hidden->bytesPerSample; |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
200 do { |
1668
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1662
diff
changeset
|
201 rc = UADWrite(this, &this->hidden->playbuf, |
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1662
diff
changeset
|
202 samplesToWrite, &samplesWritten); |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
203 samplesToWrite -= samplesWritten; |
0 | 204 |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
205 /* rc values: UMSAudioDevice_Success |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
206 * UMSAudioDevice_Failure |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
207 * UMSAudioDevice_Preempted |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
208 * UMSAudioDevice_Interrupted |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
209 * UMSAudioDevice_DeviceError |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
210 */ |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
211 if (rc == UMSAudioDevice_DeviceError) { |
0 | 212 #ifdef DEBUG_AUDIO |
1668
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1662
diff
changeset
|
213 fprintf(stderr, "Returning from PlayAudio with devices error\n"); |
0 | 214 #endif |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
215 return; |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
216 } |
0 | 217 } |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
218 while (samplesToWrite > 0); |
0 | 219 |
1668
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1662
diff
changeset
|
220 SDL_LockAudio(); |
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1662
diff
changeset
|
221 SDL_memcpy(&swpbuf, &this->hidden->playbuf, sizeof(UMSAudioTypes_Buffer)); |
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1662
diff
changeset
|
222 SDL_memcpy(&this->hidden->playbuf, &this->hidden->fillbuf, |
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1662
diff
changeset
|
223 sizeof(UMSAudioTypes_Buffer)); |
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1662
diff
changeset
|
224 SDL_memcpy(&this->hidden->fillbuf, &swpbuf, sizeof(UMSAudioTypes_Buffer)); |
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1662
diff
changeset
|
225 SDL_UnlockAudio(); |
0 | 226 |
227 #ifdef DEBUG_AUDIO | |
1668
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1662
diff
changeset
|
228 fprintf(stderr, "Wrote audio data and swapped buffer\n"); |
0 | 229 #endif |
230 } | |
231 | |
232 #if 0 | |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
233 // /* Set the DSP frequency */ |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
234 // value = spec->freq; |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
235 // if ( ioctl(this->hidden->audio_fd, SOUND_PCM_WRITE_RATE, &value) < 0 ) { |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
236 // SDL_SetError("Couldn't set audio frequency"); |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
237 // return(-1); |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
238 // } |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
239 // spec->freq = value; |
0 | 240 #endif |
241 | |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
242 static int |
1668
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1662
diff
changeset
|
243 UMS_OpenAudio(_THIS, SDL_AudioSpec * spec) |
0 | 244 { |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
245 char *audiodev = "/dev/paud0"; |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
246 long lgain; |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
247 long rgain; |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
248 long outRate; |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
249 long outBufSize; |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
250 long bitsPerSample; |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
251 long samplesPerSec; |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
252 long success; |
0 | 253 Uint16 test_format; |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
254 int frag_spec; |
0 | 255 UMSAudioDevice_ReturnCode rc; |
256 | |
257 #ifdef DEBUG_AUDIO | |
1668
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1662
diff
changeset
|
258 fprintf(stderr, "enter UMS_OpenAudio\n"); |
0 | 259 #endif |
1668
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1662
diff
changeset
|
260 rc = UADOpen(this, audiodev, "PLAY", UMSAudioDevice_BlockingIO); |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
261 if (rc != UMSAudioDevice_Success) { |
1668
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1662
diff
changeset
|
262 SDL_SetError("Couldn't open %s: %s", audiodev, strerror(errno)); |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
263 return -1; |
0 | 264 } |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
265 |
1668
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1662
diff
changeset
|
266 rc = UADSetAudioFormatType(this, "PCM"); |
0 | 267 |
268 success = 0; | |
1668
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1662
diff
changeset
|
269 test_format = SDL_FirstAudioFormat(spec->format); |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
270 do { |
0 | 271 #ifdef DEBUG_AUDIO |
1668
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1662
diff
changeset
|
272 fprintf(stderr, "Trying format 0x%4.4x\n", test_format); |
0 | 273 #endif |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
274 switch (test_format) { |
0 | 275 case AUDIO_U8: |
276 /* from the mac code: better ? */ | |
277 /* sample_bits = spec->size / spec->samples / spec->channels * 8; */ | |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
278 success = 1; |
0 | 279 bitsPerSample = 8; |
1668
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1662
diff
changeset
|
280 rc = UADSetSampleRate(this, spec->freq << 16, &outRate); |
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1662
diff
changeset
|
281 rc = UADSetByteOrder(this, "MSB"); /* irrelevant */ |
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1662
diff
changeset
|
282 rc = UADSetNumberFormat(this, "UNSIGNED"); |
0 | 283 break; |
284 case AUDIO_S8: | |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
285 success = 1; |
0 | 286 bitsPerSample = 8; |
1668
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1662
diff
changeset
|
287 rc = UADSetSampleRate(this, spec->freq << 16, &outRate); |
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1662
diff
changeset
|
288 rc = UADSetByteOrder(this, "MSB"); /* irrelevant */ |
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1662
diff
changeset
|
289 rc = UADSetNumberFormat(this, "SIGNED"); |
0 | 290 break; |
291 case AUDIO_S16LSB: | |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
292 success = 1; |
0 | 293 bitsPerSample = 16; |
1668
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1662
diff
changeset
|
294 rc = UADSetSampleRate(this, spec->freq << 16, &outRate); |
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1662
diff
changeset
|
295 rc = UADSetByteOrder(this, "LSB"); |
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1662
diff
changeset
|
296 rc = UADSetNumberFormat(this, "SIGNED"); |
0 | 297 break; |
298 case AUDIO_S16MSB: | |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
299 success = 1; |
0 | 300 bitsPerSample = 16; |
1668
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1662
diff
changeset
|
301 rc = UADSetSampleRate(this, spec->freq << 16, &outRate); |
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1662
diff
changeset
|
302 rc = UADSetByteOrder(this, "MSB"); |
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1662
diff
changeset
|
303 rc = UADSetNumberFormat(this, "SIGNED"); |
0 | 304 break; |
305 case AUDIO_U16LSB: | |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
306 success = 1; |
0 | 307 bitsPerSample = 16; |
1668
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1662
diff
changeset
|
308 rc = UADSetSampleRate(this, spec->freq << 16, &outRate); |
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1662
diff
changeset
|
309 rc = UADSetByteOrder(this, "LSB"); |
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1662
diff
changeset
|
310 rc = UADSetNumberFormat(this, "UNSIGNED"); |
0 | 311 break; |
312 case AUDIO_U16MSB: | |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
313 success = 1; |
0 | 314 bitsPerSample = 16; |
1668
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1662
diff
changeset
|
315 rc = UADSetSampleRate(this, spec->freq << 16, &outRate); |
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1662
diff
changeset
|
316 rc = UADSetByteOrder(this, "MSB"); |
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1662
diff
changeset
|
317 rc = UADSetNumberFormat(this, "UNSIGNED"); |
0 | 318 break; |
319 default: | |
320 break; | |
321 } | |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
322 if (!success) { |
1668
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1662
diff
changeset
|
323 test_format = SDL_NextAudioFormat(); |
0 | 324 } |
325 } | |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
326 while (!success && test_format); |
0 | 327 |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
328 if (success == 0) { |
1668
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1662
diff
changeset
|
329 SDL_SetError("Couldn't find any hardware audio formats"); |
0 | 330 return -1; |
331 } | |
332 | |
333 spec->format = test_format; | |
334 | |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
335 for (frag_spec = 0; (0x01 << frag_spec) < spec->size; ++frag_spec); |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
336 if ((0x01 << frag_spec) != spec->size) { |
1668
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1662
diff
changeset
|
337 SDL_SetError("Fragment size must be a power of two"); |
0 | 338 return -1; |
339 } | |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
340 if (frag_spec > 2048) |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
341 frag_spec = 2048; |
0 | 342 |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
343 this->hidden->bytesPerSample = (bitsPerSample / 8) * spec->channels; |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
344 samplesPerSec = this->hidden->bytesPerSample * outRate; |
0 | 345 |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
346 this->hidden->playbuf._length = 0; |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
347 this->hidden->playbuf._maximum = spec->size; |
1668
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1662
diff
changeset
|
348 this->hidden->playbuf._buffer = (unsigned char *) SDL_malloc(spec->size); |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
349 this->hidden->fillbuf._length = 0; |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
350 this->hidden->fillbuf._maximum = spec->size; |
1668
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1662
diff
changeset
|
351 this->hidden->fillbuf._buffer = (unsigned char *) SDL_malloc(spec->size); |
0 | 352 |
1668
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1662
diff
changeset
|
353 rc = UADSetBitsPerSample(this, bitsPerSample); |
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1662
diff
changeset
|
354 rc = UADSetDMABufferSize(this, frag_spec, &outBufSize); |
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1662
diff
changeset
|
355 rc = UADSetChannels(this, spec->channels); /* functions reduces to mono or stereo */ |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
356 |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
357 lgain = 100; /*maximum left input gain */ |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
358 rgain = 100; /*maimum right input gain */ |
1668
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1662
diff
changeset
|
359 rc = UADEnableOutput(this, "LINE_OUT", &lgain, &rgain); |
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1662
diff
changeset
|
360 rc = UADInitialize(this); |
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1662
diff
changeset
|
361 rc = UADStart(this); |
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1662
diff
changeset
|
362 rc = UADSetVolume(this, 100); |
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1662
diff
changeset
|
363 rc = UADSetBalance(this, 0); |
0 | 364 |
365 /* We're ready to rock and roll. :-) */ | |
366 return 0; | |
367 } | |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
368 |
0 | 369 |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
370 static UMSAudioDevice_ReturnCode |
1668
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1662
diff
changeset
|
371 UADGetBitsPerSample(_THIS, long *bits) |
0 | 372 { |
1668
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1662
diff
changeset
|
373 return UMSAudioDevice_get_bits_per_sample(this->hidden->umsdev, |
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1662
diff
changeset
|
374 this->hidden->ev, bits); |
0 | 375 } |
376 | |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
377 static UMSAudioDevice_ReturnCode |
1668
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1662
diff
changeset
|
378 UADSetBitsPerSample(_THIS, long bits) |
0 | 379 { |
1668
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1662
diff
changeset
|
380 return UMSAudioDevice_set_bits_per_sample(this->hidden->umsdev, |
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1662
diff
changeset
|
381 this->hidden->ev, bits); |
0 | 382 } |
383 | |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
384 static UMSAudioDevice_ReturnCode |
1668
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1662
diff
changeset
|
385 UADSetSampleRate(_THIS, long rate, long *set_rate) |
0 | 386 { |
387 /* from the mac code: sample rate = spec->freq << 16; */ | |
1668
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1662
diff
changeset
|
388 return UMSAudioDevice_set_sample_rate(this->hidden->umsdev, |
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1662
diff
changeset
|
389 this->hidden->ev, rate, set_rate); |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
390 } |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
391 |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
392 static UMSAudioDevice_ReturnCode |
1668
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1662
diff
changeset
|
393 UADSetByteOrder(_THIS, string byte_order) |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
394 { |
1668
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1662
diff
changeset
|
395 return UMSAudioDevice_set_byte_order(this->hidden->umsdev, |
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1662
diff
changeset
|
396 this->hidden->ev, byte_order); |
0 | 397 } |
398 | |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
399 static UMSAudioDevice_ReturnCode |
1668
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1662
diff
changeset
|
400 UADSetAudioFormatType(_THIS, string fmt) |
0 | 401 { |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
402 /* possible PCM, A_LAW or MU_LAW */ |
1668
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1662
diff
changeset
|
403 return UMSAudioDevice_set_audio_format_type(this->hidden->umsdev, |
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1662
diff
changeset
|
404 this->hidden->ev, fmt); |
0 | 405 } |
406 | |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
407 static UMSAudioDevice_ReturnCode |
1668
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1662
diff
changeset
|
408 UADSetNumberFormat(_THIS, string fmt) |
0 | 409 { |
410 /* possible SIGNED, UNSIGNED, or TWOS_COMPLEMENT */ | |
1668
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1662
diff
changeset
|
411 return UMSAudioDevice_set_number_format(this->hidden->umsdev, |
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1662
diff
changeset
|
412 this->hidden->ev, fmt); |
0 | 413 } |
414 | |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
415 static UMSAudioDevice_ReturnCode |
1668
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1662
diff
changeset
|
416 UADInitialize(_THIS) |
0 | 417 { |
1668
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1662
diff
changeset
|
418 return UMSAudioDevice_initialize(this->hidden->umsdev, this->hidden->ev); |
0 | 419 } |
420 | |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
421 static UMSAudioDevice_ReturnCode |
1668
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1662
diff
changeset
|
422 UADStart(_THIS) |
0 | 423 { |
1668
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1662
diff
changeset
|
424 return UMSAudioDevice_start(this->hidden->umsdev, this->hidden->ev); |
0 | 425 } |
426 | |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
427 static UMSAudioDevice_ReturnCode |
1668
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1662
diff
changeset
|
428 UADSetTimeFormat(_THIS, UMSAudioTypes_TimeFormat fmt) |
0 | 429 { |
430 /* | |
431 * Switches the time format to the new format, immediately. | |
432 * possible UMSAudioTypes_Msecs, UMSAudioTypes_Bytes or UMSAudioTypes_Samples | |
433 */ | |
1668
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1662
diff
changeset
|
434 return UMSAudioDevice_set_time_format(this->hidden->umsdev, |
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1662
diff
changeset
|
435 this->hidden->ev, fmt); |
0 | 436 } |
437 | |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
438 static UMSAudioDevice_ReturnCode |
1668
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1662
diff
changeset
|
439 UADWriteBuffSize(_THIS, long *buff_size) |
0 | 440 { |
441 /* | |
442 * returns write buffer size in the current time format | |
443 */ | |
1668
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1662
diff
changeset
|
444 return UMSAudioDevice_write_buff_size(this->hidden->umsdev, |
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1662
diff
changeset
|
445 this->hidden->ev, buff_size); |
0 | 446 } |
447 | |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
448 static UMSAudioDevice_ReturnCode |
1668
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1662
diff
changeset
|
449 UADWriteBuffRemain(_THIS, long *buff_size) |
0 | 450 { |
451 /* | |
452 * returns amount of available space in the write buffer | |
453 * in the current time format | |
454 */ | |
1668
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1662
diff
changeset
|
455 return UMSAudioDevice_write_buff_remain(this->hidden->umsdev, |
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1662
diff
changeset
|
456 this->hidden->ev, buff_size); |
0 | 457 } |
458 | |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
459 static UMSAudioDevice_ReturnCode |
1668
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1662
diff
changeset
|
460 UADWriteBuffUsed(_THIS, long *buff_size) |
0 | 461 { |
462 /* | |
463 * returns amount of filled space in the write buffer | |
464 * in the current time format | |
465 */ | |
1668
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1662
diff
changeset
|
466 return UMSAudioDevice_write_buff_used(this->hidden->umsdev, |
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1662
diff
changeset
|
467 this->hidden->ev, buff_size); |
0 | 468 } |
469 | |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
470 static UMSAudioDevice_ReturnCode |
1668
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1662
diff
changeset
|
471 UADSetDMABufferSize(_THIS, long bytes, long *bytes_ret) |
0 | 472 { |
473 /* | |
474 * Request a new DMA buffer size, maximum requested size 2048. | |
475 * Takes effect with next initialize() call. | |
476 * Devices may or may not support DMA. | |
477 */ | |
1668
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1662
diff
changeset
|
478 return UMSAudioDevice_set_DMA_buffer_size(this->hidden->umsdev, |
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1662
diff
changeset
|
479 this->hidden->ev, |
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1662
diff
changeset
|
480 bytes, bytes_ret); |
0 | 481 } |
482 | |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
483 static UMSAudioDevice_ReturnCode |
1668
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1662
diff
changeset
|
484 UADSetVolume(_THIS, long volume) |
0 | 485 { |
486 /* | |
487 * Set the volume. | |
488 * Takes effect immediately. | |
489 */ | |
1668
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1662
diff
changeset
|
490 return UMSAudioDevice_set_volume(this->hidden->umsdev, |
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1662
diff
changeset
|
491 this->hidden->ev, volume); |
0 | 492 } |
493 | |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
494 static UMSAudioDevice_ReturnCode |
1668
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1662
diff
changeset
|
495 UADSetBalance(_THIS, long balance) |
0 | 496 { |
497 /* | |
498 * Set the balance. | |
499 * Takes effect immediately. | |
500 */ | |
1668
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1662
diff
changeset
|
501 return UMSAudioDevice_set_balance(this->hidden->umsdev, |
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1662
diff
changeset
|
502 this->hidden->ev, balance); |
0 | 503 } |
504 | |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
505 static UMSAudioDevice_ReturnCode |
1668
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1662
diff
changeset
|
506 UADSetChannels(_THIS, long channels) |
0 | 507 { |
508 /* | |
509 * Set mono or stereo. | |
510 * Takes effect with next initialize() call. | |
511 */ | |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
512 if (channels != 1) |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
513 channels = 2; |
1668
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1662
diff
changeset
|
514 return UMSAudioDevice_set_number_of_channels(this->hidden->umsdev, |
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1662
diff
changeset
|
515 this->hidden->ev, channels); |
0 | 516 } |
517 | |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
518 static UMSAudioDevice_ReturnCode |
1668
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1662
diff
changeset
|
519 UADOpen(_THIS, string device, string mode, long flags) |
0 | 520 { |
1668
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1662
diff
changeset
|
521 return UMSAudioDevice_open(this->hidden->umsdev, |
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1662
diff
changeset
|
522 this->hidden->ev, device, mode, flags); |
0 | 523 } |
524 | |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
525 static UMSAudioDevice_ReturnCode |
1668
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1662
diff
changeset
|
526 UADWrite(_THIS, UMSAudioTypes_Buffer * buff, |
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1662
diff
changeset
|
527 long samples, long *samples_written) |
0 | 528 { |
1668
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1662
diff
changeset
|
529 return UMSAudioDevice_write(this->hidden->umsdev, |
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1662
diff
changeset
|
530 this->hidden->ev, |
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1662
diff
changeset
|
531 buff, samples, samples_written); |
0 | 532 } |
533 | |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
534 static UMSAudioDevice_ReturnCode |
1668
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1662
diff
changeset
|
535 UADPlayRemainingData(_THIS, boolean block) |
0 | 536 { |
1668
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1662
diff
changeset
|
537 return UMSAudioDevice_play_remaining_data(this->hidden->umsdev, |
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1662
diff
changeset
|
538 this->hidden->ev, block); |
0 | 539 } |
540 | |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
541 static UMSAudioDevice_ReturnCode |
1668
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1662
diff
changeset
|
542 UADStop(_THIS) |
0 | 543 { |
1668
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1662
diff
changeset
|
544 return UMSAudioDevice_stop(this->hidden->umsdev, this->hidden->ev); |
0 | 545 } |
546 | |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
547 static UMSAudioDevice_ReturnCode |
1668
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1662
diff
changeset
|
548 UADClose(_THIS) |
0 | 549 { |
1668
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1662
diff
changeset
|
550 return UMSAudioDevice_close(this->hidden->umsdev, this->hidden->ev); |
0 | 551 } |
552 | |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
553 static UMSAudioDevice_ReturnCode |
1668
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1662
diff
changeset
|
554 UADEnableOutput(_THIS, string output, long *left_gain, long *right_gain) |
0 | 555 { |
1668
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1662
diff
changeset
|
556 return UMSAudioDevice_enable_output(this->hidden->umsdev, |
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1662
diff
changeset
|
557 this->hidden->ev, |
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1662
diff
changeset
|
558 output, left_gain, right_gain); |
0 | 559 } |
560 | |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
561 /* vi: set ts=4 sw=4 expandtab: */ |