annotate src/audio/paudio/SDL_paudio.c @ 3832:ca74a71063ac SDL-ryan-multiple-audio-device

Paudio driver moved to 1.3 API.
author Ryan C. Gordon <icculus@icculus.org>
date Sat, 07 Oct 2006 20:20:59 +0000
parents 7852b5b78af5
children 66fb40445587
rev   line source
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
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
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
4
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
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
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
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
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
9
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
10 This library is distributed in the hope that it will be useful,
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
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
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
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
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
18
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
19 Carsten Griwodz
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
20 griff@kom.tu-darmstadt.de
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
21
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
22 based on linux/SDL_dspaudio.c by Sam Lantinga
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
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
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
25
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
26 /* Allow access to a raw mixing buffer */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
27
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
28 #include <errno.h>
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
29 #include <unistd.h>
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
30 #include <fcntl.h>
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
31 #include <sys/time.h>
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
32 #include <sys/ioctl.h>
3809
7852b5b78af5 Cleaning out SDL_audiodev.c and related references ...
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
33 #include <sys/types.h>
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
34 #include <sys/stat.h>
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
35
1358
c71e05b4dc2e More header massaging... works great on Windows. ;-)
Sam Lantinga <slouken@libsdl.org>
parents: 1338
diff changeset
36 #include "SDL_timer.h"
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
37 #include "SDL_audio.h"
3809
7852b5b78af5 Cleaning out SDL_audiodev.c and related references ...
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
38 #include "SDL_stdinc.h"
1361
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_audiomem.h"
19418e4422cb New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents: 1358
diff changeset
40 #include "../SDL_audio_c.h"
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
41 #include "SDL_paudio.h"
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
42
3832
ca74a71063ac Paudio driver moved to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
43 #define DEBUG_AUDIO 0
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
44
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
45 /* A conflict within AIX 4.3.3 <sys/> headers and probably others as well.
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
46 * I guess nobody ever uses audio... Shame over AIX header files. */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
47 #include <sys/machine.h>
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
48 #undef BIG_ENDIAN
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
49 #include <sys/audio.h>
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
50
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
51 /* The tag name used by paud audio */
3832
ca74a71063ac Paudio driver moved to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
52 #define PAUDIO_DRIVER_NAME "paud"
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
53
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
54 /* Open the audio device for playback, and don't block if busy */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
55 /* #define OPEN_FLAGS (O_WRONLY|O_NONBLOCK) */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
56 #define OPEN_FLAGS O_WRONLY
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
57
3809
7852b5b78af5 Cleaning out SDL_audiodev.c and related references ...
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
58 /* Get the name of the audio device we use for output */
7852b5b78af5 Cleaning out SDL_audiodev.c and related references ...
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
59
7852b5b78af5 Cleaning out SDL_audiodev.c and related references ...
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
60 #ifndef _PATH_DEV_DSP
7852b5b78af5 Cleaning out SDL_audiodev.c and related references ...
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
61 #define _PATH_DEV_DSP "/dev/%caud%c/%c"
7852b5b78af5 Cleaning out SDL_audiodev.c and related references ...
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
62 #endif
7852b5b78af5 Cleaning out SDL_audiodev.c and related references ...
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
63
7852b5b78af5 Cleaning out SDL_audiodev.c and related references ...
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
64 static char devsettings[][3] = {
7852b5b78af5 Cleaning out SDL_audiodev.c and related references ...
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
65 {'p', '0', '1'}, {'p', '0', '2'}, {'p', '0', '3'}, {'p', '0', '4'},
7852b5b78af5 Cleaning out SDL_audiodev.c and related references ...
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
66 {'p', '1', '1'}, {'p', '1', '2'}, {'p', '1', '3'}, {'p', '1', '4'},
7852b5b78af5 Cleaning out SDL_audiodev.c and related references ...
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
67 {'p', '2', '1'}, {'p', '2', '2'}, {'p', '2', '3'}, {'p', '2', '4'},
7852b5b78af5 Cleaning out SDL_audiodev.c and related references ...
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
68 {'p', '3', '1'}, {'p', '3', '2'}, {'p', '3', '3'}, {'p', '3', '4'},
7852b5b78af5 Cleaning out SDL_audiodev.c and related references ...
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
69 {'b', '0', '1'}, {'b', '0', '2'}, {'b', '0', '3'}, {'b', '0', '4'},
7852b5b78af5 Cleaning out SDL_audiodev.c and related references ...
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
70 {'b', '1', '1'}, {'b', '1', '2'}, {'b', '1', '3'}, {'b', '1', '4'},
7852b5b78af5 Cleaning out SDL_audiodev.c and related references ...
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
71 {'b', '2', '1'}, {'b', '2', '2'}, {'b', '2', '3'}, {'b', '2', '4'},
7852b5b78af5 Cleaning out SDL_audiodev.c and related references ...
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
72 {'b', '3', '1'}, {'b', '3', '2'}, {'b', '3', '3'}, {'b', '3', '4'},
7852b5b78af5 Cleaning out SDL_audiodev.c and related references ...
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
73 {'\0', '\0', '\0'}
7852b5b78af5 Cleaning out SDL_audiodev.c and related references ...
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
74 };
7852b5b78af5 Cleaning out SDL_audiodev.c and related references ...
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
75
7852b5b78af5 Cleaning out SDL_audiodev.c and related references ...
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
76 static int
7852b5b78af5 Cleaning out SDL_audiodev.c and related references ...
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
77 OpenUserDefinedDevice(char *path, int maxlen, int flags)
7852b5b78af5 Cleaning out SDL_audiodev.c and related references ...
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
78 {
7852b5b78af5 Cleaning out SDL_audiodev.c and related references ...
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
79 const char *audiodev;
3832
ca74a71063ac Paudio driver moved to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
80 int fd;
3809
7852b5b78af5 Cleaning out SDL_audiodev.c and related references ...
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
81
7852b5b78af5 Cleaning out SDL_audiodev.c and related references ...
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
82 /* Figure out what our audio device is */
7852b5b78af5 Cleaning out SDL_audiodev.c and related references ...
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
83 if ((audiodev = SDL_getenv("SDL_PATH_DSP")) == NULL) {
7852b5b78af5 Cleaning out SDL_audiodev.c and related references ...
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
84 audiodev = SDL_getenv("AUDIODEV");
7852b5b78af5 Cleaning out SDL_audiodev.c and related references ...
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
85 }
7852b5b78af5 Cleaning out SDL_audiodev.c and related references ...
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
86 if (audiodev == NULL) {
7852b5b78af5 Cleaning out SDL_audiodev.c and related references ...
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
87 return -1;
7852b5b78af5 Cleaning out SDL_audiodev.c and related references ...
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
88 }
3832
ca74a71063ac Paudio driver moved to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
89 fd = open(audiodev, flags, 0);
3809
7852b5b78af5 Cleaning out SDL_audiodev.c and related references ...
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
90 if (path != NULL) {
7852b5b78af5 Cleaning out SDL_audiodev.c and related references ...
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
91 SDL_strlcpy(path, audiodev, maxlen);
7852b5b78af5 Cleaning out SDL_audiodev.c and related references ...
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
92 path[maxlen - 1] = '\0';
7852b5b78af5 Cleaning out SDL_audiodev.c and related references ...
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
93 }
3832
ca74a71063ac Paudio driver moved to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
94 return fd;
3809
7852b5b78af5 Cleaning out SDL_audiodev.c and related references ...
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
95 }
7852b5b78af5 Cleaning out SDL_audiodev.c and related references ...
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
96
3832
ca74a71063ac Paudio driver moved to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
97 static int
3809
7852b5b78af5 Cleaning out SDL_audiodev.c and related references ...
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
98 OpenAudioPath(char *path, int maxlen, int flags, int classic)
7852b5b78af5 Cleaning out SDL_audiodev.c and related references ...
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
99 {
7852b5b78af5 Cleaning out SDL_audiodev.c and related references ...
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
100 struct stat sb;
3832
ca74a71063ac Paudio driver moved to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
101 int cycle = 0;
ca74a71063ac Paudio driver moved to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
102 int fd = OpenUserDefinedDevice(path, maxlen, flags);
3809
7852b5b78af5 Cleaning out SDL_audiodev.c and related references ...
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
103
3832
ca74a71063ac Paudio driver moved to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
104 if (fd != -1) {
ca74a71063ac Paudio driver moved to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
105 return fd;
3809
7852b5b78af5 Cleaning out SDL_audiodev.c and related references ...
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
106 }
7852b5b78af5 Cleaning out SDL_audiodev.c and related references ...
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
107
7852b5b78af5 Cleaning out SDL_audiodev.c and related references ...
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
108 /* !!! FIXME: do we really need a table here? */
7852b5b78af5 Cleaning out SDL_audiodev.c and related references ...
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
109 while (devsettings[cycle][0] != '\0') {
3832
ca74a71063ac Paudio driver moved to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
110 char audiopath[1024];
3809
7852b5b78af5 Cleaning out SDL_audiodev.c and related references ...
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
111 SDL_snprintf(audiopath, SDL_arraysize(audiopath),
7852b5b78af5 Cleaning out SDL_audiodev.c and related references ...
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
112 _PATH_DEV_DSP,
7852b5b78af5 Cleaning out SDL_audiodev.c and related references ...
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
113 devsettings[cycle][0],
7852b5b78af5 Cleaning out SDL_audiodev.c and related references ...
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
114 devsettings[cycle][1], devsettings[cycle][2]);
7852b5b78af5 Cleaning out SDL_audiodev.c and related references ...
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
115
7852b5b78af5 Cleaning out SDL_audiodev.c and related references ...
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
116 if (stat(audiopath, &sb) == 0) {
3832
ca74a71063ac Paudio driver moved to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
117 fd = open(audiopath, flags, 0);
ca74a71063ac Paudio driver moved to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
118 if (fd > 0) {
3809
7852b5b78af5 Cleaning out SDL_audiodev.c and related references ...
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
119 if (path != NULL) {
7852b5b78af5 Cleaning out SDL_audiodev.c and related references ...
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
120 SDL_strlcpy(path, audiopath, maxlen);
7852b5b78af5 Cleaning out SDL_audiodev.c and related references ...
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
121 }
3832
ca74a71063ac Paudio driver moved to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
122 return fd;
3809
7852b5b78af5 Cleaning out SDL_audiodev.c and related references ...
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
123 }
7852b5b78af5 Cleaning out SDL_audiodev.c and related references ...
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
124 }
7852b5b78af5 Cleaning out SDL_audiodev.c and related references ...
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
125 }
7852b5b78af5 Cleaning out SDL_audiodev.c and related references ...
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
126 return -1;
7852b5b78af5 Cleaning out SDL_audiodev.c and related references ...
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
127 }
7852b5b78af5 Cleaning out SDL_audiodev.c and related references ...
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
128
7852b5b78af5 Cleaning out SDL_audiodev.c and related references ...
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
129
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
130 static int
3832
ca74a71063ac Paudio driver moved to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
131 PAUDIO_Available(void)
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
132 {
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
133 int fd;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
134 int available;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
135
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
136 available = 0;
3809
7852b5b78af5 Cleaning out SDL_audiodev.c and related references ...
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
137 fd = OpenAudioPath(NULL, 0, OPEN_FLAGS, 0);
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
138 if (fd >= 0) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
139 available = 1;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
140 close(fd);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
141 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
142 return (available);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
143 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
144
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
145
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
146 /* This function waits until it is possible to write a full sound buffer */
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
147 static void
3832
ca74a71063ac Paudio driver moved to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
148 PAUDIO_WaitDevice(_THIS)
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
149 {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
150 fd_set fdset;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
151
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
152 /* See if we need to use timed audio synchronization */
3832
ca74a71063ac Paudio driver moved to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
153 if (this->hidden->frame_ticks) {
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
154 /* Use timer for general audio synchronization */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
155 Sint32 ticks;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
156
3832
ca74a71063ac Paudio driver moved to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
157 ticks = ((Sint32)(this->hidden->next_frame-SDL_GetTicks()))-FUDGE_TICKS;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
158 if (ticks > 0) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
159 SDL_Delay(ticks);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
160 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
161 } else {
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
162 audio_buffer paud_bufinfo;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
163
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
164 /* Use select() for audio synchronization */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
165 struct timeval timeout;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
166 FD_ZERO(&fdset);
3832
ca74a71063ac Paudio driver moved to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
167 FD_SET(this->hidden->audio_fd, &fdset);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
168
3832
ca74a71063ac Paudio driver moved to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
169 if (ioctl(this->hidden->audio_fd, AUDIO_BUFFER, &paud_bufinfo) < 0) {
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
170 #ifdef DEBUG_AUDIO
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
171 fprintf(stderr, "Couldn't get audio buffer information\n");
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
172 #endif
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
173 timeout.tv_sec = 10;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
174 timeout.tv_usec = 0;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
175 } else {
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
176 long ms_in_buf = paud_bufinfo.write_buf_time;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
177 timeout.tv_sec = ms_in_buf / 1000;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
178 ms_in_buf = ms_in_buf - timeout.tv_sec * 1000;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
179 timeout.tv_usec = ms_in_buf * 1000;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
180 #ifdef DEBUG_AUDIO
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
181 fprintf(stderr,
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
182 "Waiting for write_buf_time=%ld,%ld\n",
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
183 timeout.tv_sec, timeout.tv_usec);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
184 #endif
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
185 }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
186
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
187 #ifdef DEBUG_AUDIO
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
188 fprintf(stderr, "Waiting for audio to get ready\n");
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
189 #endif
3832
ca74a71063ac Paudio driver moved to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
190 if (select(this->hidden->audio_fd+1,NULL,&fdset,NULL,&timeout) <= 0) {
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
191 const char *message =
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
192 "Audio timeout - buggy audio driver? (disabled)";
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
193 /*
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
194 * In general we should never print to the screen,
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
195 * but in this case we have no other way of letting
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
196 * the user know what happened.
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
197 */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
198 fprintf(stderr, "SDL: %s - %s\n", strerror(errno), message);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
199 this->enabled = 0;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
200 /* Don't try to close - may hang */
3832
ca74a71063ac Paudio driver moved to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
201 this->hidden->audio_fd = -1;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
202 #ifdef DEBUG_AUDIO
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
203 fprintf(stderr, "Done disabling audio\n");
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
204 #endif
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
205 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
206 #ifdef DEBUG_AUDIO
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
207 fprintf(stderr, "Ready!\n");
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
208 #endif
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
209 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
210 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
211
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
212 static void
3832
ca74a71063ac Paudio driver moved to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
213 PAUDIO_PlayDevice(_THIS)
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
214 {
3832
ca74a71063ac Paudio driver moved to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
215 int written = 0;
ca74a71063ac Paudio driver moved to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
216 const Uint8 *mixbuf = this->hidden->mixbuf;
ca74a71063ac Paudio driver moved to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
217 const size_t mixlen = this->hidden->mixlen;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
218
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
219 /* Write the audio data, checking for EAGAIN on broken audio drivers */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
220 do {
3832
ca74a71063ac Paudio driver moved to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
221 written = write(this->hidden->audio_fd, mixbuf, mixlen);
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
222 if ((written < 0) && ((errno == 0) || (errno == EAGAIN))) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
223 SDL_Delay(1); /* Let a little CPU time go by */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
224 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
225 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
226 while ((written < 0) &&
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
227 ((errno == 0) || (errno == EAGAIN) || (errno == EINTR)));
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
228
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
229 /* If timer synchronization is enabled, set the next write frame */
3832
ca74a71063ac Paudio driver moved to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
230 if (this->hidden->frame_ticks) {
ca74a71063ac Paudio driver moved to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
231 this->hidden->next_frame += this->hidden->frame_ticks;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
232 }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
233
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
234 /* If we couldn't write, assume fatal error for now */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
235 if (written < 0) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
236 this->enabled = 0;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
237 }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
238 #ifdef DEBUG_AUDIO
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
239 fprintf(stderr, "Wrote %d bytes of audio data\n", written);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
240 #endif
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
241 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
242
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
243 static Uint8 *
3832
ca74a71063ac Paudio driver moved to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
244 PAUDIO_GetDeviceBuf(_THIS)
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
245 {
3832
ca74a71063ac Paudio driver moved to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
246 return this->hidden->mixbuf;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
247 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
248
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
249 static void
3832
ca74a71063ac Paudio driver moved to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
250 PAUDIO_CloseDevice(_THIS)
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
251 {
3832
ca74a71063ac Paudio driver moved to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
252 if (this->hidden != NULL) {
ca74a71063ac Paudio driver moved to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
253 if (this->hidden->mixbuf != NULL) {
ca74a71063ac Paudio driver moved to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
254 SDL_FreeAudioMem(this->hidden->mixbuf);
ca74a71063ac Paudio driver moved to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
255 this->hidden->mixbuf = NULL;
ca74a71063ac Paudio driver moved to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
256 }
ca74a71063ac Paudio driver moved to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
257 if (this->hidden->audio_fd >= 0) {
ca74a71063ac Paudio driver moved to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
258 close(this->hidden->audio_fd);
ca74a71063ac Paudio driver moved to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
259 this->hidden->audio_fd = -1;
ca74a71063ac Paudio driver moved to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
260 }
ca74a71063ac Paudio driver moved to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
261 SDL_free(this->hidden);
ca74a71063ac Paudio driver moved to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
262 this->hidden = NULL;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
263 }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
264 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
265
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
266 static int
3832
ca74a71063ac Paudio driver moved to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
267 PAUDIO_OpenDevice(_THIS, const char *devname, int iscapture)
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
268 {
3832
ca74a71063ac Paudio driver moved to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
269 const char *workaround = SDL_getenv("SDL_DSP_NOSELECT");
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
270 char audiodev[1024];
3832
ca74a71063ac Paudio driver moved to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
271 const char *err = NULL;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
272 int format;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
273 int bytes_per_sample;
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
274 SDL_AudioFormat test_format;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
275 audio_init paud_init;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
276 audio_buffer paud_bufinfo;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
277 audio_status paud_status;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
278 audio_control paud_control;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
279 audio_change paud_change;
3832
ca74a71063ac Paudio driver moved to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
280 int fd = -1;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
281
3832
ca74a71063ac Paudio driver moved to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
282 /* Initialize all variables that we clean on shutdown */
ca74a71063ac Paudio driver moved to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
283 this->hidden = (struct SDL_PrivateAudioData *)
ca74a71063ac Paudio driver moved to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
284 SDL_malloc((sizeof *this->hidden));
ca74a71063ac Paudio driver moved to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
285 if (this->hidden == NULL) {
ca74a71063ac Paudio driver moved to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
286 SDL_OutOfMemory();
ca74a71063ac Paudio driver moved to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
287 return 0;
ca74a71063ac Paudio driver moved to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
288 }
ca74a71063ac Paudio driver moved to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
289 SDL_memset(this->hidden, 0, (sizeof *this->hidden));
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
290
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
291 /* Open the audio device */
3832
ca74a71063ac Paudio driver moved to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
292 fd = OpenAudioPath(audiodev, sizeof(audiodev), OPEN_FLAGS, 0);
ca74a71063ac Paudio driver moved to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
293 this->hidden->audio_fd = fd;
ca74a71063ac Paudio driver moved to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
294 if (fd < 0) {
ca74a71063ac Paudio driver moved to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
295 PAUDIO_CloseDevice(this);
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
296 SDL_SetError("Couldn't open %s: %s", audiodev, strerror(errno));
3832
ca74a71063ac Paudio driver moved to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
297 return 0;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
298 }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
299
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
300 /*
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
301 * We can't set the buffer size - just ask the device for the maximum
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
302 * that we can have.
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
303 */
3832
ca74a71063ac Paudio driver moved to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
304 if (ioctl(fd, AUDIO_BUFFER, &paud_bufinfo) < 0) {
ca74a71063ac Paudio driver moved to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
305 PAUDIO_CloseDevice(this);
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
306 SDL_SetError("Couldn't get audio buffer information");
3832
ca74a71063ac Paudio driver moved to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
307 return 0;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
308 }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
309
3832
ca74a71063ac Paudio driver moved to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
310 if (this->spec.channels > 1)
ca74a71063ac Paudio driver moved to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
311 this->spec.channels = 2;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
312 else
3832
ca74a71063ac Paudio driver moved to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
313 this->spec.channels = 1;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
314
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
315 /*
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
316 * Fields in the audio_init structure:
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
317 *
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
318 * Ignored by us:
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
319 *
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
320 * paud.loadpath[LOAD_PATH]; * DSP code to load, MWave chip only?
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
321 * paud.slot_number; * slot number of the adapter
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
322 * paud.device_id; * adapter identification number
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
323 *
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
324 * Input:
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
325 *
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
326 * paud.srate; * the sampling rate in Hz
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
327 * paud.bits_per_sample; * 8, 16, 32, ...
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
328 * paud.bsize; * block size for this rate
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
329 * paud.mode; * ADPCM, PCM, MU_LAW, A_LAW, SOURCE_MIX
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
330 * paud.channels; * 1=mono, 2=stereo
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
331 * paud.flags; * FIXED - fixed length data
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
332 * * LEFT_ALIGNED, RIGHT_ALIGNED (var len only)
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
333 * * TWOS_COMPLEMENT - 2's complement data
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
334 * * SIGNED - signed? comment seems wrong in sys/audio.h
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
335 * * BIG_ENDIAN
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
336 * paud.operation; * PLAY, RECORD
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
337 *
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
338 * Output:
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
339 *
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
340 * paud.flags; * PITCH - pitch is supported
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
341 * * INPUT - input is supported
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
342 * * OUTPUT - output is supported
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
343 * * MONITOR - monitor is supported
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
344 * * VOLUME - volume is supported
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
345 * * VOLUME_DELAY - volume delay is supported
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
346 * * BALANCE - balance is supported
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
347 * * BALANCE_DELAY - balance delay is supported
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
348 * * TREBLE - treble control is supported
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
349 * * BASS - bass control is supported
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
350 * * BESTFIT_PROVIDED - best fit returned
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
351 * * LOAD_CODE - DSP load needed
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
352 * paud.rc; * NO_PLAY - DSP code can't do play requests
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
353 * * NO_RECORD - DSP code can't do record requests
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
354 * * INVALID_REQUEST - request was invalid
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
355 * * CONFLICT - conflict with open's flags
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
356 * * OVERLOADED - out of DSP MIPS or memory
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
357 * paud.position_resolution; * smallest increment for position
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
358 */
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
359
3832
ca74a71063ac Paudio driver moved to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
360 paud_init.srate = this->spec.freq;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
361 paud_init.mode = PCM;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
362 paud_init.operation = PLAY;
3832
ca74a71063ac Paudio driver moved to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
363 paud_init.channels = this->spec.channels;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
364
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
365 /* Try for a closest match on audio format */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
366 format = 0;
3832
ca74a71063ac Paudio driver moved to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
367 for (test_format = SDL_FirstAudioFormat(this->spec.format);
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
368 !format && test_format;) {
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
369 #ifdef DEBUG_AUDIO
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
370 fprintf(stderr, "Trying format 0x%4.4x\n", test_format);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
371 #endif
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
372 switch (test_format) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
373 case AUDIO_U8:
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
374 bytes_per_sample = 1;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
375 paud_init.bits_per_sample = 8;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
376 paud_init.flags = TWOS_COMPLEMENT | FIXED;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
377 format = 1;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
378 break;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
379 case AUDIO_S8:
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
380 bytes_per_sample = 1;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
381 paud_init.bits_per_sample = 8;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
382 paud_init.flags = SIGNED | TWOS_COMPLEMENT | FIXED;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
383 format = 1;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
384 break;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
385 case AUDIO_S16LSB:
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
386 bytes_per_sample = 2;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
387 paud_init.bits_per_sample = 16;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
388 paud_init.flags = SIGNED | TWOS_COMPLEMENT | FIXED;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
389 format = 1;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
390 break;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
391 case AUDIO_S16MSB:
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
392 bytes_per_sample = 2;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
393 paud_init.bits_per_sample = 16;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
394 paud_init.flags = BIG_ENDIAN | SIGNED | TWOS_COMPLEMENT | FIXED;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
395 format = 1;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
396 break;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
397 case AUDIO_U16LSB:
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
398 bytes_per_sample = 2;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
399 paud_init.bits_per_sample = 16;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
400 paud_init.flags = TWOS_COMPLEMENT | FIXED;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
401 format = 1;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
402 break;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
403 case AUDIO_U16MSB:
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
404 bytes_per_sample = 2;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
405 paud_init.bits_per_sample = 16;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
406 paud_init.flags = BIG_ENDIAN | TWOS_COMPLEMENT | FIXED;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
407 format = 1;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
408 break;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
409 default:
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
410 break;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
411 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
412 if (!format) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
413 test_format = SDL_NextAudioFormat();
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
414 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
415 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
416 if (format == 0) {
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
417 #ifdef DEBUG_AUDIO
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
418 fprintf(stderr, "Couldn't find any hardware audio formats\n");
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
419 #endif
3832
ca74a71063ac Paudio driver moved to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
420 PAUDIO_CloseDevice(this);
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
421 SDL_SetError("Couldn't find any hardware audio formats");
3832
ca74a71063ac Paudio driver moved to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
422 return 0;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
423 }
3832
ca74a71063ac Paudio driver moved to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
424 this->spec.format = test_format;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
425
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
426 /*
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
427 * We know the buffer size and the max number of subsequent writes
3832
ca74a71063ac Paudio driver moved to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
428 * that can be pending. If more than one can pend, allow the application
ca74a71063ac Paudio driver moved to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
429 * to do something like double buffering between our write buffer and
ca74a71063ac Paudio driver moved to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
430 * the device's own buffer that we are filling with write() anyway.
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
431 *
3832
ca74a71063ac Paudio driver moved to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
432 * We calculate this->spec.samples like this because
ca74a71063ac Paudio driver moved to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
433 * SDL_CalculateAudioSpec() will give put paud_bufinfo.write_buf_cap
ca74a71063ac Paudio driver moved to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
434 * (or paud_bufinfo.write_buf_cap/2) into this->spec.size in return.
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
435 */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
436 if (paud_bufinfo.request_buf_cap == 1) {
3832
ca74a71063ac Paudio driver moved to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
437 this->spec.samples = paud_bufinfo.write_buf_cap
ca74a71063ac Paudio driver moved to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
438 / bytes_per_sample / this->spec.channels;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
439 } else {
3832
ca74a71063ac Paudio driver moved to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
440 this->spec.samples = paud_bufinfo.write_buf_cap
ca74a71063ac Paudio driver moved to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
441 / bytes_per_sample / this->spec.channels / 2;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
442 }
3832
ca74a71063ac Paudio driver moved to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
443 paud_init.bsize = bytes_per_sample * this->spec.channels;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
444
3832
ca74a71063ac Paudio driver moved to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
445 SDL_CalculateAudioSpec(&this->spec);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
446
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
447 /*
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
448 * The AIX paud device init can't modify the values of the audio_init
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
449 * structure that we pass to it. So we don't need any recalculation
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
450 * of this stuff and no reinit call as in linux dsp and dma code.
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
451 *
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
452 * /dev/paud supports all of the encoding formats, so we don't need
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
453 * to do anything like reopening the device, either.
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
454 */
3832
ca74a71063ac Paudio driver moved to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
455 if (ioctl(fd, AUDIO_INIT, &paud_init) < 0) {
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
456 switch (paud_init.rc) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
457 case 1:
3832
ca74a71063ac Paudio driver moved to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
458 err = "Couldn't set audio format: DSP can't do play requests";
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
459 break;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
460 case 2:
3832
ca74a71063ac Paudio driver moved to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
461 err = "Couldn't set audio format: DSP can't do record requests";
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
462 break;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
463 case 4:
3832
ca74a71063ac Paudio driver moved to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
464 err = "Couldn't set audio format: request was invalid";
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
465 break;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
466 case 5:
3832
ca74a71063ac Paudio driver moved to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
467 err = "Couldn't set audio format: conflict with open's flags";
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
468 break;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
469 case 6:
3832
ca74a71063ac Paudio driver moved to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
470 err = "Couldn't set audio format: out of DSP MIPS or memory";
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
471 break;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
472 default:
3832
ca74a71063ac Paudio driver moved to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
473 err = "Couldn't set audio format: not documented in sys/audio.h";
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
474 break;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
475 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
476 }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
477
3832
ca74a71063ac Paudio driver moved to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
478 if (err != NULL) {
ca74a71063ac Paudio driver moved to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
479 PAUDIO_CloseDevice(this);
ca74a71063ac Paudio driver moved to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
480 SDL_SetError("Paudio: %s", err);
ca74a71063ac Paudio driver moved to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
481 return 0;
ca74a71063ac Paudio driver moved to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
482 }
ca74a71063ac Paudio driver moved to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
483
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
484 /* Allocate mixing buffer */
3832
ca74a71063ac Paudio driver moved to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
485 this->hidden->mixlen = this->spec.size;
ca74a71063ac Paudio driver moved to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
486 this->hidden->mixbuf = (Uint8 *) SDL_AllocAudioMem(this->hidden->mixlen);
ca74a71063ac Paudio driver moved to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
487 if (this->hidden->mixbuf == NULL) {
ca74a71063ac Paudio driver moved to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
488 PAUDIO_CloseDevice(this);
ca74a71063ac Paudio driver moved to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
489 SDL_OutOfMemory();
ca74a71063ac Paudio driver moved to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
490 return 0;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
491 }
3832
ca74a71063ac Paudio driver moved to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
492 SDL_memset(this->hidden->mixbuf, this->spec.silence, this->spec.size);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
493
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
494 /*
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
495 * Set some paramters: full volume, first speaker that we can find.
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
496 * Ignore the other settings for now.
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
497 */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
498 paud_change.input = AUDIO_IGNORE; /* the new input source */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
499 paud_change.output = OUTPUT_1; /* EXTERNAL_SPEAKER,INTERNAL_SPEAKER,OUTPUT_1 */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
500 paud_change.monitor = AUDIO_IGNORE; /* the new monitor state */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
501 paud_change.volume = 0x7fffffff; /* volume level [0-0x7fffffff] */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
502 paud_change.volume_delay = AUDIO_IGNORE; /* the new volume delay */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
503 paud_change.balance = 0x3fffffff; /* the new balance */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
504 paud_change.balance_delay = AUDIO_IGNORE; /* the new balance delay */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
505 paud_change.treble = AUDIO_IGNORE; /* the new treble state */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
506 paud_change.bass = AUDIO_IGNORE; /* the new bass state */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
507 paud_change.pitch = AUDIO_IGNORE; /* the new pitch state */
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
508
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
509 paud_control.ioctl_request = AUDIO_CHANGE;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
510 paud_control.request_info = (char *) &paud_change;
3832
ca74a71063ac Paudio driver moved to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
511 if (ioctl(fd, AUDIO_CONTROL, &paud_control) < 0) {
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
512 #ifdef DEBUG_AUDIO
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
513 fprintf(stderr, "Can't change audio display settings\n");
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
514 #endif
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
515 }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
516
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
517 /*
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
518 * Tell the device to expect data. Actual start will wait for
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
519 * the first write() call.
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
520 */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
521 paud_control.ioctl_request = AUDIO_START;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
522 paud_control.position = 0;
3832
ca74a71063ac Paudio driver moved to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
523 if (ioctl(fd, AUDIO_CONTROL, &paud_control) < 0) {
ca74a71063ac Paudio driver moved to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
524 PAUDIO_CloseDevice(this);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
525 #ifdef DEBUG_AUDIO
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
526 fprintf(stderr, "Can't start audio play\n");
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
527 #endif
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
528 SDL_SetError("Can't start audio play");
3832
ca74a71063ac Paudio driver moved to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
529 return 0;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
530 }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
531
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
532 /* Check to see if we need to use select() workaround */
3832
ca74a71063ac Paudio driver moved to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
533 if (workaround != NULL) {
ca74a71063ac Paudio driver moved to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
534 this->hidden->frame_ticks = (float) (this->spec.samples * 1000) /
ca74a71063ac Paudio driver moved to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
535 this->spec.freq;
ca74a71063ac Paudio driver moved to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
536 this->hidden->next_frame = SDL_GetTicks() + this->hidden->frame_ticks;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
537 }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
538
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
539 /* We're ready to rock and roll. :-) */
3832
ca74a71063ac Paudio driver moved to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
540 return 1;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
541 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
542
3832
ca74a71063ac Paudio driver moved to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
543 static int
ca74a71063ac Paudio driver moved to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
544 PAUDIO_Init(SDL_AudioDriverImpl *impl)
ca74a71063ac Paudio driver moved to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
545 {
ca74a71063ac Paudio driver moved to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
546 /* Set the function pointers */
ca74a71063ac Paudio driver moved to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
547 impl->OpenDevice = DSP_OpenDevice;
ca74a71063ac Paudio driver moved to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
548 impl->PlayDevice = DSP_PlayDevice;
ca74a71063ac Paudio driver moved to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
549 impl->PlayDevice = DSP_WaitDevice;
ca74a71063ac Paudio driver moved to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
550 impl->GetDeviceBuf = DSP_GetDeviceBuf;
ca74a71063ac Paudio driver moved to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
551 impl->CloseDevice = DSP_CloseDevice;
ca74a71063ac Paudio driver moved to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
552 impl->OnlyHasDefaultOutputDevice = 1; /* !!! FIXME: add device enum! */
ca74a71063ac Paudio driver moved to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
553
ca74a71063ac Paudio driver moved to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
554 return 1;
ca74a71063ac Paudio driver moved to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
555 }
ca74a71063ac Paudio driver moved to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
556
ca74a71063ac Paudio driver moved to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
557 AudioBootStrap PAUDIO_bootstrap = {
ca74a71063ac Paudio driver moved to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
558 PAUDIO_DRIVER_NAME, "AIX Paudio",
ca74a71063ac Paudio driver moved to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
559 PAUDIO_Available, PAUDIO_Init, 0
ca74a71063ac Paudio driver moved to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
560 };
ca74a71063ac Paudio driver moved to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3809
diff changeset
561
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
562 /* vi: set ts=4 sw=4 expandtab: */