annotate src/audio/dma/SDL_dmaaudio.c @ 3846:66fb40445587 SDL-ryan-multiple-audio-device

Removed distinction between "available" and "init" in audio backends, since both had to be checked for success as a pair at the higher level and several of the Available methods were just always-succeed placeholders anyhow. Now the availability check is done in the init code, and the higher level tries all possible drivers until one manages to initialize successfully.
author Ryan C. Gordon <icculus@icculus.org>
date Tue, 17 Oct 2006 09:09:21 +0000
parents 103bbe13f5eb
children
rev   line source
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1 /*
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2 SDL - Simple DirectMedia Layer
1312
c9b51268668f Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents: 960
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: 960
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: 960
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: 960
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: 960
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: 960
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: 960
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 Sam Lantinga
252
e8157fcb3114 Updated the source with the correct e-mail address
Sam Lantinga <slouken@libsdl.org>
parents: 94
diff changeset
20 slouken@libsdl.org
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
21 */
1402
d910939febfa Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents: 1361
diff changeset
22 #include "SDL_config.h"
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
23
3795
589bc3d060cd More 1.3 audio work...moved dsp and dma drivers over to new model. Untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
24 /* !!! FIXME: merge this driver with "dsp". */
589bc3d060cd More 1.3 audio work...moved dsp and dma drivers over to new model. Untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
25
0
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 <stdio.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
29 #include <string.h> /* For strerror() */
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
30 #include <errno.h>
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
31 #include <unistd.h>
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
32 #include <fcntl.h>
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
33 #include <signal.h>
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
34 #include <sys/types.h>
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
35 #include <sys/time.h>
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
36 #include <sys/ioctl.h>
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
37 #include <sys/stat.h>
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
38 #include <sys/mman.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
19418e4422cb New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents: 1358
diff changeset
40 #if SDL_AUDIO_DRIVER_OSS_SOUNDCARD_H
94
ae6e6b73333f Cleaned up the OpenBSD port, thanks to Peter Valchev
Sam Lantinga <slouken@lokigames.com>
parents: 92
diff changeset
41 /* This is installed on some systems */
ae6e6b73333f Cleaned up the OpenBSD port, thanks to Peter Valchev
Sam Lantinga <slouken@lokigames.com>
parents: 92
diff changeset
42 #include <soundcard.h>
ae6e6b73333f Cleaned up the OpenBSD port, thanks to Peter Valchev
Sam Lantinga <slouken@lokigames.com>
parents: 92
diff changeset
43 #else
ae6e6b73333f Cleaned up the OpenBSD port, thanks to Peter Valchev
Sam Lantinga <slouken@lokigames.com>
parents: 92
diff changeset
44 /* This is recommended by OSS */
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
45 #include <sys/soundcard.h>
94
ae6e6b73333f Cleaned up the OpenBSD port, thanks to Peter Valchev
Sam Lantinga <slouken@lokigames.com>
parents: 92
diff changeset
46 #endif
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
47
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
48 #ifndef MAP_FAILED
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
49 #define MAP_FAILED ((Uint8 *)-1)
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
50 #endif
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
51
1358
c71e05b4dc2e More header massaging... works great on Windows. ;-)
Sam Lantinga <slouken@libsdl.org>
parents: 1341
diff changeset
52 #include "SDL_timer.h"
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
53 #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
54 #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
55 #include "../SDL_audiodev_c.h"
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
56 #include "SDL_dmaaudio.h"
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
57
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
58 /* The tag name used by DMA audio */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
59 #define DMA_DRIVER_NAME "dma"
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
60
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
61 /* Open the audio device for playback, and don't block if busy */
3810
2c5387c0a642 Multiple audio device code is now working for dsp and dma targets.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
62 #define OPEN_FLAGS_INPUT (O_RDWR|O_NONBLOCK)
2c5387c0a642 Multiple audio device code is now working for dsp and dma targets.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
63 #define OPEN_FLAGS_OUTPUT (O_RDWR|O_NONBLOCK)
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
64
3810
2c5387c0a642 Multiple audio device code is now working for dsp and dma targets.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
65 static char **outputDevices = NULL;
2c5387c0a642 Multiple audio device code is now working for dsp and dma targets.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
66 static int outputDeviceCount = 0;
2c5387c0a642 Multiple audio device code is now working for dsp and dma targets.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
67 static char **inputDevices = NULL;
2c5387c0a642 Multiple audio device code is now working for dsp and dma targets.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
68 static int inputDeviceCount = 0;
2c5387c0a642 Multiple audio device code is now working for dsp and dma targets.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
69
2c5387c0a642 Multiple audio device code is now working for dsp and dma targets.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
70 static int
2c5387c0a642 Multiple audio device code is now working for dsp and dma targets.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
71 test_for_mmap(int fd)
2c5387c0a642 Multiple audio device code is now working for dsp and dma targets.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
72 {
2c5387c0a642 Multiple audio device code is now working for dsp and dma targets.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
73 int caps = 0;
2c5387c0a642 Multiple audio device code is now working for dsp and dma targets.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
74 struct audio_buf_info info;
2c5387c0a642 Multiple audio device code is now working for dsp and dma targets.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
75 if ((ioctl(fd, SNDCTL_DSP_GETCAPS, &caps) == 0) &&
2c5387c0a642 Multiple audio device code is now working for dsp and dma targets.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
76 (caps & DSP_CAP_TRIGGER) && (caps & DSP_CAP_MMAP) &&
2c5387c0a642 Multiple audio device code is now working for dsp and dma targets.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
77 (ioctl(fd, SNDCTL_DSP_GETOSPACE, &info) == 0))
2c5387c0a642 Multiple audio device code is now working for dsp and dma targets.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
78 {
2c5387c0a642 Multiple audio device code is now working for dsp and dma targets.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
79 size_t len = info.fragstotal * info.fragsize;
2c5387c0a642 Multiple audio device code is now working for dsp and dma targets.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
80 Uint8 *buf = (Uint8 *) mmap(NULL, len, PROT_WRITE, MAP_SHARED, fd, 0);
2c5387c0a642 Multiple audio device code is now working for dsp and dma targets.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
81 if (buf != MAP_FAILED) {
2c5387c0a642 Multiple audio device code is now working for dsp and dma targets.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
82 munmap(buf, len);
2c5387c0a642 Multiple audio device code is now working for dsp and dma targets.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
83 return 1;
2c5387c0a642 Multiple audio device code is now working for dsp and dma targets.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
84 }
2c5387c0a642 Multiple audio device code is now working for dsp and dma targets.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
85 }
2c5387c0a642 Multiple audio device code is now working for dsp and dma targets.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
86 return 0;
2c5387c0a642 Multiple audio device code is now working for dsp and dma targets.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
87 }
2c5387c0a642 Multiple audio device code is now working for dsp and dma targets.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
88
2c5387c0a642 Multiple audio device code is now working for dsp and dma targets.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
89
2c5387c0a642 Multiple audio device code is now working for dsp and dma targets.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
90 static inline void
2c5387c0a642 Multiple audio device code is now working for dsp and dma targets.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
91 free_device_list(char ***devs, int *count)
2c5387c0a642 Multiple audio device code is now working for dsp and dma targets.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
92 {
2c5387c0a642 Multiple audio device code is now working for dsp and dma targets.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
93 SDL_FreeUnixAudioDevices(devs, count);
2c5387c0a642 Multiple audio device code is now working for dsp and dma targets.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
94 }
2c5387c0a642 Multiple audio device code is now working for dsp and dma targets.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
95
2c5387c0a642 Multiple audio device code is now working for dsp and dma targets.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
96 static inline void
2c5387c0a642 Multiple audio device code is now working for dsp and dma targets.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
97 build_device_list(int iscapture, char ***devs, int *count)
2c5387c0a642 Multiple audio device code is now working for dsp and dma targets.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
98 {
2c5387c0a642 Multiple audio device code is now working for dsp and dma targets.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
99 const int flags = ((iscapture) ? OPEN_FLAGS_INPUT : OPEN_FLAGS_OUTPUT);
2c5387c0a642 Multiple audio device code is now working for dsp and dma targets.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
100 free_device_list(devs, count);
2c5387c0a642 Multiple audio device code is now working for dsp and dma targets.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
101 SDL_EnumUnixAudioDevices(flags, 0, test_for_mmap, devs, count);
2c5387c0a642 Multiple audio device code is now working for dsp and dma targets.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
102 }
2c5387c0a642 Multiple audio device code is now working for dsp and dma targets.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
103
2c5387c0a642 Multiple audio device code is now working for dsp and dma targets.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
104 static inline void
2c5387c0a642 Multiple audio device code is now working for dsp and dma targets.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
105 build_device_lists(void)
2c5387c0a642 Multiple audio device code is now working for dsp and dma targets.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
106 {
2c5387c0a642 Multiple audio device code is now working for dsp and dma targets.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
107 build_device_list(0, &outputDevices, &outputDeviceCount);
2c5387c0a642 Multiple audio device code is now working for dsp and dma targets.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
108 build_device_list(1, &inputDevices, &inputDeviceCount);
2c5387c0a642 Multiple audio device code is now working for dsp and dma targets.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
109 }
2c5387c0a642 Multiple audio device code is now working for dsp and dma targets.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
110
2c5387c0a642 Multiple audio device code is now working for dsp and dma targets.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
111
2c5387c0a642 Multiple audio device code is now working for dsp and dma targets.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
112 static inline void
2c5387c0a642 Multiple audio device code is now working for dsp and dma targets.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
113 free_device_lists(void)
2c5387c0a642 Multiple audio device code is now working for dsp and dma targets.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
114 {
2c5387c0a642 Multiple audio device code is now working for dsp and dma targets.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
115 free_device_list(&outputDevices, &outputDeviceCount);
2c5387c0a642 Multiple audio device code is now working for dsp and dma targets.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
116 free_device_list(&inputDevices, &inputDeviceCount);
2c5387c0a642 Multiple audio device code is now working for dsp and dma targets.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
117 }
2c5387c0a642 Multiple audio device code is now working for dsp and dma targets.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
118
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
119
3810
2c5387c0a642 Multiple audio device code is now working for dsp and dma targets.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
120 static void DMA_Deinitialize(void)
2c5387c0a642 Multiple audio device code is now working for dsp and dma targets.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
121 {
2c5387c0a642 Multiple audio device code is now working for dsp and dma targets.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
122 free_device_lists();
2c5387c0a642 Multiple audio device code is now working for dsp and dma targets.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
123 }
3795
589bc3d060cd More 1.3 audio work...moved dsp and dma drivers over to new model. Untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
124
589bc3d060cd More 1.3 audio work...moved dsp and dma drivers over to new model. Untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
125 static int
589bc3d060cd More 1.3 audio work...moved dsp and dma drivers over to new model. Untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
126 DMA_DetectDevices(int iscapture)
589bc3d060cd More 1.3 audio work...moved dsp and dma drivers over to new model. Untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
127 {
3810
2c5387c0a642 Multiple audio device code is now working for dsp and dma targets.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
128 if (iscapture) {
2c5387c0a642 Multiple audio device code is now working for dsp and dma targets.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
129 build_device_list(1, &inputDevices, &inputDeviceCount);
2c5387c0a642 Multiple audio device code is now working for dsp and dma targets.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
130 return inputDeviceCount;
2c5387c0a642 Multiple audio device code is now working for dsp and dma targets.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
131 } else {
2c5387c0a642 Multiple audio device code is now working for dsp and dma targets.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
132 build_device_list(0, &outputDevices, &outputDeviceCount);
2c5387c0a642 Multiple audio device code is now working for dsp and dma targets.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
133 return outputDeviceCount;
2c5387c0a642 Multiple audio device code is now working for dsp and dma targets.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
134 }
2c5387c0a642 Multiple audio device code is now working for dsp and dma targets.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
135
2c5387c0a642 Multiple audio device code is now working for dsp and dma targets.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
136 return 0; /* shouldn't ever hit this. */
3795
589bc3d060cd More 1.3 audio work...moved dsp and dma drivers over to new model. Untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
137 }
589bc3d060cd More 1.3 audio work...moved dsp and dma drivers over to new model. Untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
138
589bc3d060cd More 1.3 audio work...moved dsp and dma drivers over to new model. Untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
139
589bc3d060cd More 1.3 audio work...moved dsp and dma drivers over to new model. Untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
140 static const char *
589bc3d060cd More 1.3 audio work...moved dsp and dma drivers over to new model. Untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
141 DMA_GetDeviceName(int index, int iscapture)
589bc3d060cd More 1.3 audio work...moved dsp and dma drivers over to new model. Untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
142 {
3810
2c5387c0a642 Multiple audio device code is now working for dsp and dma targets.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
143 if ((iscapture) && (index < inputDeviceCount)) {
2c5387c0a642 Multiple audio device code is now working for dsp and dma targets.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
144 return inputDevices[index];
2c5387c0a642 Multiple audio device code is now working for dsp and dma targets.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
145 } else if ((!iscapture) && (index < outputDeviceCount)) {
2c5387c0a642 Multiple audio device code is now working for dsp and dma targets.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
146 return outputDevices[index];
2c5387c0a642 Multiple audio device code is now working for dsp and dma targets.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
147 }
2c5387c0a642 Multiple audio device code is now working for dsp and dma targets.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
148
2c5387c0a642 Multiple audio device code is now working for dsp and dma targets.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
149 SDL_SetError("No such device");
3795
589bc3d060cd More 1.3 audio work...moved dsp and dma drivers over to new model. Untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
150 return NULL;
589bc3d060cd More 1.3 audio work...moved dsp and dma drivers over to new model. Untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
151 }
589bc3d060cd More 1.3 audio work...moved dsp and dma drivers over to new model. Untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
152
589bc3d060cd More 1.3 audio work...moved dsp and dma drivers over to new model. Untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
153
589bc3d060cd More 1.3 audio work...moved dsp and dma drivers over to new model. Untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
154 static int
589bc3d060cd More 1.3 audio work...moved dsp and dma drivers over to new model. Untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
155 DMA_ReopenAudio(_THIS, const char *audiodev, int format, int stereo)
589bc3d060cd More 1.3 audio work...moved dsp and dma drivers over to new model. Untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
156 {
589bc3d060cd More 1.3 audio work...moved dsp and dma drivers over to new model. Untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
157 int frag_spec;
589bc3d060cd More 1.3 audio work...moved dsp and dma drivers over to new model. Untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
158 int value;
589bc3d060cd More 1.3 audio work...moved dsp and dma drivers over to new model. Untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
159
589bc3d060cd More 1.3 audio work...moved dsp and dma drivers over to new model. Untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
160 /* Close and then reopen the audio device */
589bc3d060cd More 1.3 audio work...moved dsp and dma drivers over to new model. Untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
161 close(audio_fd);
589bc3d060cd More 1.3 audio work...moved dsp and dma drivers over to new model. Untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
162 audio_fd = open(audiodev, O_RDWR, 0);
589bc3d060cd More 1.3 audio work...moved dsp and dma drivers over to new model. Untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
163 if (audio_fd < 0) {
589bc3d060cd More 1.3 audio work...moved dsp and dma drivers over to new model. Untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
164 SDL_SetError("Couldn't open %s: %s", audiodev, strerror(errno));
589bc3d060cd More 1.3 audio work...moved dsp and dma drivers over to new model. Untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
165 return (-1);
589bc3d060cd More 1.3 audio work...moved dsp and dma drivers over to new model. Untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
166 }
589bc3d060cd More 1.3 audio work...moved dsp and dma drivers over to new model. Untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
167
589bc3d060cd More 1.3 audio work...moved dsp and dma drivers over to new model. Untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
168 /* Calculate the final parameters for this audio specification */
589bc3d060cd More 1.3 audio work...moved dsp and dma drivers over to new model. Untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
169 SDL_CalculateAudioSpec(&this->spec);
589bc3d060cd More 1.3 audio work...moved dsp and dma drivers over to new model. Untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
170
589bc3d060cd More 1.3 audio work...moved dsp and dma drivers over to new model. Untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
171 /* Determine the power of two of the fragment size */
589bc3d060cd More 1.3 audio work...moved dsp and dma drivers over to new model. Untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
172 for (frag_spec = 0; (0x01 << frag_spec) < this->spec.size; ++frag_spec);
589bc3d060cd More 1.3 audio work...moved dsp and dma drivers over to new model. Untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
173 if ((0x01 << frag_spec) != this->spec.size) {
589bc3d060cd More 1.3 audio work...moved dsp and dma drivers over to new model. Untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
174 SDL_SetError("Fragment size must be a power of two");
589bc3d060cd More 1.3 audio work...moved dsp and dma drivers over to new model. Untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
175 return (-1);
589bc3d060cd More 1.3 audio work...moved dsp and dma drivers over to new model. Untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
176 }
589bc3d060cd More 1.3 audio work...moved dsp and dma drivers over to new model. Untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
177
589bc3d060cd More 1.3 audio work...moved dsp and dma drivers over to new model. Untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
178 /* Set the audio buffering parameters */
589bc3d060cd More 1.3 audio work...moved dsp and dma drivers over to new model. Untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
179 if (ioctl(audio_fd, SNDCTL_DSP_SETFRAGMENT, &frag_spec) < 0) {
589bc3d060cd More 1.3 audio work...moved dsp and dma drivers over to new model. Untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
180 SDL_SetError("Couldn't set audio fragment spec");
589bc3d060cd More 1.3 audio work...moved dsp and dma drivers over to new model. Untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
181 return (-1);
589bc3d060cd More 1.3 audio work...moved dsp and dma drivers over to new model. Untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
182 }
589bc3d060cd More 1.3 audio work...moved dsp and dma drivers over to new model. Untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
183
589bc3d060cd More 1.3 audio work...moved dsp and dma drivers over to new model. Untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
184 /* Set the audio format */
589bc3d060cd More 1.3 audio work...moved dsp and dma drivers over to new model. Untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
185 value = format;
589bc3d060cd More 1.3 audio work...moved dsp and dma drivers over to new model. Untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
186 if ((ioctl(audio_fd, SNDCTL_DSP_SETFMT, &value) < 0) || (value != format)) {
589bc3d060cd More 1.3 audio work...moved dsp and dma drivers over to new model. Untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
187 SDL_SetError("Couldn't set audio format");
589bc3d060cd More 1.3 audio work...moved dsp and dma drivers over to new model. Untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
188 return (-1);
589bc3d060cd More 1.3 audio work...moved dsp and dma drivers over to new model. Untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
189 }
589bc3d060cd More 1.3 audio work...moved dsp and dma drivers over to new model. Untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
190
589bc3d060cd More 1.3 audio work...moved dsp and dma drivers over to new model. Untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
191 /* Set mono or stereo audio */
589bc3d060cd More 1.3 audio work...moved dsp and dma drivers over to new model. Untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
192 value = (this->spec.channels > 1);
589bc3d060cd More 1.3 audio work...moved dsp and dma drivers over to new model. Untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
193 if ((ioctl(audio_fd, SNDCTL_DSP_STEREO, &stereo) < 0) ||
589bc3d060cd More 1.3 audio work...moved dsp and dma drivers over to new model. Untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
194 (value != stereo)) {
589bc3d060cd More 1.3 audio work...moved dsp and dma drivers over to new model. Untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
195 SDL_SetError("Couldn't set audio channels");
589bc3d060cd More 1.3 audio work...moved dsp and dma drivers over to new model. Untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
196 return (-1);
589bc3d060cd More 1.3 audio work...moved dsp and dma drivers over to new model. Untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
197 }
589bc3d060cd More 1.3 audio work...moved dsp and dma drivers over to new model. Untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
198
589bc3d060cd More 1.3 audio work...moved dsp and dma drivers over to new model. Untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
199 /* Set the DSP frequency */
589bc3d060cd More 1.3 audio work...moved dsp and dma drivers over to new model. Untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
200 value = this->spec.freq;
589bc3d060cd More 1.3 audio work...moved dsp and dma drivers over to new model. Untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
201 if (ioctl(audio_fd, SNDCTL_DSP_SPEED, &value) < 0) {
589bc3d060cd More 1.3 audio work...moved dsp and dma drivers over to new model. Untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
202 SDL_SetError("Couldn't set audio frequency");
589bc3d060cd More 1.3 audio work...moved dsp and dma drivers over to new model. Untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
203 return (-1);
589bc3d060cd More 1.3 audio work...moved dsp and dma drivers over to new model. Untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
204 }
589bc3d060cd More 1.3 audio work...moved dsp and dma drivers over to new model. Untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
205 this->spec.freq = value;
589bc3d060cd More 1.3 audio work...moved dsp and dma drivers over to new model. Untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
206
589bc3d060cd More 1.3 audio work...moved dsp and dma drivers over to new model. Untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
207 /* We successfully re-opened the audio */
589bc3d060cd More 1.3 audio work...moved dsp and dma drivers over to new model. Untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
208 return (0);
589bc3d060cd More 1.3 audio work...moved dsp and dma drivers over to new model. Untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
209 }
589bc3d060cd More 1.3 audio work...moved dsp and dma drivers over to new model. Untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
210
589bc3d060cd More 1.3 audio work...moved dsp and dma drivers over to new model. Untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
211
3817
103bbe13f5eb Patched to compile.
Ryan C. Gordon <icculus@icculus.org>
parents: 3816
diff changeset
212 static void
103bbe13f5eb Patched to compile.
Ryan C. Gordon <icculus@icculus.org>
parents: 3816
diff changeset
213 DMA_CloseDevice(_THIS)
103bbe13f5eb Patched to compile.
Ryan C. Gordon <icculus@icculus.org>
parents: 3816
diff changeset
214 {
103bbe13f5eb Patched to compile.
Ryan C. Gordon <icculus@icculus.org>
parents: 3816
diff changeset
215 if (this->hidden != NULL) {
103bbe13f5eb Patched to compile.
Ryan C. Gordon <icculus@icculus.org>
parents: 3816
diff changeset
216 if (dma_buf != NULL) {
103bbe13f5eb Patched to compile.
Ryan C. Gordon <icculus@icculus.org>
parents: 3816
diff changeset
217 munmap(dma_buf, dma_len);
103bbe13f5eb Patched to compile.
Ryan C. Gordon <icculus@icculus.org>
parents: 3816
diff changeset
218 dma_buf = NULL;
103bbe13f5eb Patched to compile.
Ryan C. Gordon <icculus@icculus.org>
parents: 3816
diff changeset
219 }
103bbe13f5eb Patched to compile.
Ryan C. Gordon <icculus@icculus.org>
parents: 3816
diff changeset
220 if (audio_fd >= 0) {
103bbe13f5eb Patched to compile.
Ryan C. Gordon <icculus@icculus.org>
parents: 3816
diff changeset
221 close(audio_fd);
103bbe13f5eb Patched to compile.
Ryan C. Gordon <icculus@icculus.org>
parents: 3816
diff changeset
222 audio_fd = -1;
103bbe13f5eb Patched to compile.
Ryan C. Gordon <icculus@icculus.org>
parents: 3816
diff changeset
223 }
103bbe13f5eb Patched to compile.
Ryan C. Gordon <icculus@icculus.org>
parents: 3816
diff changeset
224 SDL_free(this->hidden);
103bbe13f5eb Patched to compile.
Ryan C. Gordon <icculus@icculus.org>
parents: 3816
diff changeset
225 this->hidden = NULL;
103bbe13f5eb Patched to compile.
Ryan C. Gordon <icculus@icculus.org>
parents: 3816
diff changeset
226 }
103bbe13f5eb Patched to compile.
Ryan C. Gordon <icculus@icculus.org>
parents: 3816
diff changeset
227 }
103bbe13f5eb Patched to compile.
Ryan C. Gordon <icculus@icculus.org>
parents: 3816
diff changeset
228
3795
589bc3d060cd More 1.3 audio work...moved dsp and dma drivers over to new model. Untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
229
589bc3d060cd More 1.3 audio work...moved dsp and dma drivers over to new model. Untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
230 static int
3817
103bbe13f5eb Patched to compile.
Ryan C. Gordon <icculus@icculus.org>
parents: 3816
diff changeset
231 DMA_OpenDevice(_THIS, const char *devname, int iscapture)
3795
589bc3d060cd More 1.3 audio work...moved dsp and dma drivers over to new model. Untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
232 {
3810
2c5387c0a642 Multiple audio device code is now working for dsp and dma targets.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
233 const int flags = ((iscapture) ? OPEN_FLAGS_INPUT : OPEN_FLAGS_OUTPUT);
3795
589bc3d060cd More 1.3 audio work...moved dsp and dma drivers over to new model. Untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
234 int format;
589bc3d060cd More 1.3 audio work...moved dsp and dma drivers over to new model. Untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
235 int stereo;
589bc3d060cd More 1.3 audio work...moved dsp and dma drivers over to new model. Untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
236 int value;
589bc3d060cd More 1.3 audio work...moved dsp and dma drivers over to new model. Untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
237 SDL_AudioFormat test_format;
589bc3d060cd More 1.3 audio work...moved dsp and dma drivers over to new model. Untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
238 struct audio_buf_info info;
589bc3d060cd More 1.3 audio work...moved dsp and dma drivers over to new model. Untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
239
3810
2c5387c0a642 Multiple audio device code is now working for dsp and dma targets.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
240 /* We don't care what the devname is...we'll try to open anything. */
2c5387c0a642 Multiple audio device code is now working for dsp and dma targets.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
241 /* ...but default to first name in the list... */
2c5387c0a642 Multiple audio device code is now working for dsp and dma targets.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
242 if (devname == NULL) {
2c5387c0a642 Multiple audio device code is now working for dsp and dma targets.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
243 if ( ((iscapture) && (inputDeviceCount == 0)) ||
2c5387c0a642 Multiple audio device code is now working for dsp and dma targets.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
244 ((!iscapture) && (outputDeviceCount == 0)) ) {
2c5387c0a642 Multiple audio device code is now working for dsp and dma targets.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
245 SDL_SetError("No such audio device");
2c5387c0a642 Multiple audio device code is now working for dsp and dma targets.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
246 return 0;
2c5387c0a642 Multiple audio device code is now working for dsp and dma targets.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
247 }
2c5387c0a642 Multiple audio device code is now working for dsp and dma targets.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
248 devname = ((iscapture) ? inputDevices[0] : outputDevices[0]);
2c5387c0a642 Multiple audio device code is now working for dsp and dma targets.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
249 }
2c5387c0a642 Multiple audio device code is now working for dsp and dma targets.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
250
3795
589bc3d060cd More 1.3 audio work...moved dsp and dma drivers over to new model. Untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
251 /* Initialize all variables that we clean on shutdown */
589bc3d060cd More 1.3 audio work...moved dsp and dma drivers over to new model. Untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
252 this->hidden = (struct SDL_PrivateAudioData *)
589bc3d060cd More 1.3 audio work...moved dsp and dma drivers over to new model. Untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
253 SDL_malloc((sizeof *this->hidden));
589bc3d060cd More 1.3 audio work...moved dsp and dma drivers over to new model. Untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
254 if (this->hidden == NULL) {
589bc3d060cd More 1.3 audio work...moved dsp and dma drivers over to new model. Untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
255 SDL_OutOfMemory();
589bc3d060cd More 1.3 audio work...moved dsp and dma drivers over to new model. Untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
256 return 0;
589bc3d060cd More 1.3 audio work...moved dsp and dma drivers over to new model. Untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
257 }
589bc3d060cd More 1.3 audio work...moved dsp and dma drivers over to new model. Untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
258 SDL_memset(this->hidden, 0, (sizeof *this->hidden));
589bc3d060cd More 1.3 audio work...moved dsp and dma drivers over to new model. Untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
259
589bc3d060cd More 1.3 audio work...moved dsp and dma drivers over to new model. Untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
260 /* Open the audio device */
3810
2c5387c0a642 Multiple audio device code is now working for dsp and dma targets.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
261 audio_fd = open(devname, flags, 0);
3795
589bc3d060cd More 1.3 audio work...moved dsp and dma drivers over to new model. Untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
262 if (audio_fd < 0) {
3817
103bbe13f5eb Patched to compile.
Ryan C. Gordon <icculus@icculus.org>
parents: 3816
diff changeset
263 DMA_CloseDevice(this);
3810
2c5387c0a642 Multiple audio device code is now working for dsp and dma targets.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
264 SDL_SetError("Couldn't open %s: %s", devname, strerror(errno));
3795
589bc3d060cd More 1.3 audio work...moved dsp and dma drivers over to new model. Untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
265 return 0;
589bc3d060cd More 1.3 audio work...moved dsp and dma drivers over to new model. Untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
266 }
589bc3d060cd More 1.3 audio work...moved dsp and dma drivers over to new model. Untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
267 dma_buf = NULL;
589bc3d060cd More 1.3 audio work...moved dsp and dma drivers over to new model. Untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
268 ioctl(audio_fd, SNDCTL_DSP_RESET, 0);
589bc3d060cd More 1.3 audio work...moved dsp and dma drivers over to new model. Untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
269
589bc3d060cd More 1.3 audio work...moved dsp and dma drivers over to new model. Untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
270 /* Get a list of supported hardware formats */
589bc3d060cd More 1.3 audio work...moved dsp and dma drivers over to new model. Untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
271 if (ioctl(audio_fd, SNDCTL_DSP_GETFMTS, &value) < 0) {
3817
103bbe13f5eb Patched to compile.
Ryan C. Gordon <icculus@icculus.org>
parents: 3816
diff changeset
272 DMA_CloseDevice(this);
3795
589bc3d060cd More 1.3 audio work...moved dsp and dma drivers over to new model. Untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
273 SDL_SetError("Couldn't get audio format list");
589bc3d060cd More 1.3 audio work...moved dsp and dma drivers over to new model. Untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
274 return 0;
589bc3d060cd More 1.3 audio work...moved dsp and dma drivers over to new model. Untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
275 }
589bc3d060cd More 1.3 audio work...moved dsp and dma drivers over to new model. Untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
276
589bc3d060cd More 1.3 audio work...moved dsp and dma drivers over to new model. Untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
277 /* Try for a closest match on audio format */
589bc3d060cd More 1.3 audio work...moved dsp and dma drivers over to new model. Untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
278 format = 0;
589bc3d060cd More 1.3 audio work...moved dsp and dma drivers over to new model. Untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
279 for (test_format = SDL_FirstAudioFormat(this->spec.format);
589bc3d060cd More 1.3 audio work...moved dsp and dma drivers over to new model. Untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
280 !format && test_format;) {
589bc3d060cd More 1.3 audio work...moved dsp and dma drivers over to new model. Untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
281 #ifdef DEBUG_AUDIO
589bc3d060cd More 1.3 audio work...moved dsp and dma drivers over to new model. Untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
282 fprintf(stderr, "Trying format 0x%4.4x\n", test_format);
589bc3d060cd More 1.3 audio work...moved dsp and dma drivers over to new model. Untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
283 #endif
589bc3d060cd More 1.3 audio work...moved dsp and dma drivers over to new model. Untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
284 switch (test_format) {
589bc3d060cd More 1.3 audio work...moved dsp and dma drivers over to new model. Untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
285 case AUDIO_U8:
589bc3d060cd More 1.3 audio work...moved dsp and dma drivers over to new model. Untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
286 if (value & AFMT_U8) {
589bc3d060cd More 1.3 audio work...moved dsp and dma drivers over to new model. Untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
287 format = AFMT_U8;
589bc3d060cd More 1.3 audio work...moved dsp and dma drivers over to new model. Untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
288 }
589bc3d060cd More 1.3 audio work...moved dsp and dma drivers over to new model. Untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
289 break;
589bc3d060cd More 1.3 audio work...moved dsp and dma drivers over to new model. Untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
290 case AUDIO_S8:
589bc3d060cd More 1.3 audio work...moved dsp and dma drivers over to new model. Untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
291 if (value & AFMT_S8) {
589bc3d060cd More 1.3 audio work...moved dsp and dma drivers over to new model. Untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
292 format = AFMT_S8;
589bc3d060cd More 1.3 audio work...moved dsp and dma drivers over to new model. Untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
293 }
589bc3d060cd More 1.3 audio work...moved dsp and dma drivers over to new model. Untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
294 break;
589bc3d060cd More 1.3 audio work...moved dsp and dma drivers over to new model. Untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
295 case AUDIO_S16LSB:
589bc3d060cd More 1.3 audio work...moved dsp and dma drivers over to new model. Untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
296 if (value & AFMT_S16_LE) {
589bc3d060cd More 1.3 audio work...moved dsp and dma drivers over to new model. Untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
297 format = AFMT_S16_LE;
589bc3d060cd More 1.3 audio work...moved dsp and dma drivers over to new model. Untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
298 }
589bc3d060cd More 1.3 audio work...moved dsp and dma drivers over to new model. Untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
299 break;
589bc3d060cd More 1.3 audio work...moved dsp and dma drivers over to new model. Untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
300 case AUDIO_S16MSB:
589bc3d060cd More 1.3 audio work...moved dsp and dma drivers over to new model. Untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
301 if (value & AFMT_S16_BE) {
589bc3d060cd More 1.3 audio work...moved dsp and dma drivers over to new model. Untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
302 format = AFMT_S16_BE;
589bc3d060cd More 1.3 audio work...moved dsp and dma drivers over to new model. Untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
303 }
589bc3d060cd More 1.3 audio work...moved dsp and dma drivers over to new model. Untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
304 break;
589bc3d060cd More 1.3 audio work...moved dsp and dma drivers over to new model. Untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
305 case AUDIO_U16LSB:
589bc3d060cd More 1.3 audio work...moved dsp and dma drivers over to new model. Untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
306 if (value & AFMT_U16_LE) {
589bc3d060cd More 1.3 audio work...moved dsp and dma drivers over to new model. Untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
307 format = AFMT_U16_LE;
589bc3d060cd More 1.3 audio work...moved dsp and dma drivers over to new model. Untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
308 }
589bc3d060cd More 1.3 audio work...moved dsp and dma drivers over to new model. Untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
309 break;
589bc3d060cd More 1.3 audio work...moved dsp and dma drivers over to new model. Untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
310 case AUDIO_U16MSB:
589bc3d060cd More 1.3 audio work...moved dsp and dma drivers over to new model. Untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
311 if (value & AFMT_U16_BE) {
589bc3d060cd More 1.3 audio work...moved dsp and dma drivers over to new model. Untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
312 format = AFMT_U16_BE;
589bc3d060cd More 1.3 audio work...moved dsp and dma drivers over to new model. Untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
313 }
589bc3d060cd More 1.3 audio work...moved dsp and dma drivers over to new model. Untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
314 break;
589bc3d060cd More 1.3 audio work...moved dsp and dma drivers over to new model. Untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
315 default:
589bc3d060cd More 1.3 audio work...moved dsp and dma drivers over to new model. Untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
316 format = 0;
589bc3d060cd More 1.3 audio work...moved dsp and dma drivers over to new model. Untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
317 break;
589bc3d060cd More 1.3 audio work...moved dsp and dma drivers over to new model. Untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
318 }
589bc3d060cd More 1.3 audio work...moved dsp and dma drivers over to new model. Untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
319 if (!format) {
589bc3d060cd More 1.3 audio work...moved dsp and dma drivers over to new model. Untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
320 test_format = SDL_NextAudioFormat();
589bc3d060cd More 1.3 audio work...moved dsp and dma drivers over to new model. Untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
321 }
589bc3d060cd More 1.3 audio work...moved dsp and dma drivers over to new model. Untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
322 }
589bc3d060cd More 1.3 audio work...moved dsp and dma drivers over to new model. Untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
323 if (format == 0) {
3817
103bbe13f5eb Patched to compile.
Ryan C. Gordon <icculus@icculus.org>
parents: 3816
diff changeset
324 DMA_CloseDevice(this);
3795
589bc3d060cd More 1.3 audio work...moved dsp and dma drivers over to new model. Untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
325 SDL_SetError("Couldn't find any hardware audio formats");
589bc3d060cd More 1.3 audio work...moved dsp and dma drivers over to new model. Untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
326 return 0;
589bc3d060cd More 1.3 audio work...moved dsp and dma drivers over to new model. Untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
327 }
589bc3d060cd More 1.3 audio work...moved dsp and dma drivers over to new model. Untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
328 this->spec.format = test_format;
589bc3d060cd More 1.3 audio work...moved dsp and dma drivers over to new model. Untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
329
589bc3d060cd More 1.3 audio work...moved dsp and dma drivers over to new model. Untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
330 /* Set the audio format */
589bc3d060cd More 1.3 audio work...moved dsp and dma drivers over to new model. Untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
331 value = format;
589bc3d060cd More 1.3 audio work...moved dsp and dma drivers over to new model. Untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
332 if ((ioctl(audio_fd, SNDCTL_DSP_SETFMT, &value) < 0) || (value != format)) {
3817
103bbe13f5eb Patched to compile.
Ryan C. Gordon <icculus@icculus.org>
parents: 3816
diff changeset
333 DMA_CloseDevice(this);
3795
589bc3d060cd More 1.3 audio work...moved dsp and dma drivers over to new model. Untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
334 SDL_SetError("Couldn't set audio format");
589bc3d060cd More 1.3 audio work...moved dsp and dma drivers over to new model. Untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
335 return 0;
589bc3d060cd More 1.3 audio work...moved dsp and dma drivers over to new model. Untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
336 }
589bc3d060cd More 1.3 audio work...moved dsp and dma drivers over to new model. Untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
337
589bc3d060cd More 1.3 audio work...moved dsp and dma drivers over to new model. Untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
338 /* Set mono or stereo audio (currently only two channels supported) */
589bc3d060cd More 1.3 audio work...moved dsp and dma drivers over to new model. Untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
339 stereo = (this->spec.channels > 1);
589bc3d060cd More 1.3 audio work...moved dsp and dma drivers over to new model. Untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
340 ioctl(audio_fd, SNDCTL_DSP_STEREO, &stereo);
589bc3d060cd More 1.3 audio work...moved dsp and dma drivers over to new model. Untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
341 if (stereo) {
589bc3d060cd More 1.3 audio work...moved dsp and dma drivers over to new model. Untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
342 this->spec.channels = 2;
589bc3d060cd More 1.3 audio work...moved dsp and dma drivers over to new model. Untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
343 } else {
589bc3d060cd More 1.3 audio work...moved dsp and dma drivers over to new model. Untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
344 this->spec.channels = 1;
589bc3d060cd More 1.3 audio work...moved dsp and dma drivers over to new model. Untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
345 }
589bc3d060cd More 1.3 audio work...moved dsp and dma drivers over to new model. Untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
346
589bc3d060cd More 1.3 audio work...moved dsp and dma drivers over to new model. Untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
347 /* Because some drivers don't allow setting the buffer size
589bc3d060cd More 1.3 audio work...moved dsp and dma drivers over to new model. Untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
348 after setting the format, we must re-open the audio device
589bc3d060cd More 1.3 audio work...moved dsp and dma drivers over to new model. Untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
349 once we know what format and channels are supported
589bc3d060cd More 1.3 audio work...moved dsp and dma drivers over to new model. Untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
350 */
3810
2c5387c0a642 Multiple audio device code is now working for dsp and dma targets.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
351 if (DMA_ReopenAudio(this, devname, format, stereo) < 0) {
3817
103bbe13f5eb Patched to compile.
Ryan C. Gordon <icculus@icculus.org>
parents: 3816
diff changeset
352 DMA_CloseDevice(this);
3795
589bc3d060cd More 1.3 audio work...moved dsp and dma drivers over to new model. Untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
353 /* Error is set by DMA_ReopenAudio() */
589bc3d060cd More 1.3 audio work...moved dsp and dma drivers over to new model. Untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
354 return 0;
589bc3d060cd More 1.3 audio work...moved dsp and dma drivers over to new model. Untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
355 }
589bc3d060cd More 1.3 audio work...moved dsp and dma drivers over to new model. Untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
356
589bc3d060cd More 1.3 audio work...moved dsp and dma drivers over to new model. Untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
357 /* Memory map the audio buffer */
589bc3d060cd More 1.3 audio work...moved dsp and dma drivers over to new model. Untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
358 if (ioctl(audio_fd, SNDCTL_DSP_GETOSPACE, &info) < 0) {
3817
103bbe13f5eb Patched to compile.
Ryan C. Gordon <icculus@icculus.org>
parents: 3816
diff changeset
359 DMA_CloseDevice(this);
3795
589bc3d060cd More 1.3 audio work...moved dsp and dma drivers over to new model. Untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
360 SDL_SetError("Couldn't get OSPACE parameters");
589bc3d060cd More 1.3 audio work...moved dsp and dma drivers over to new model. Untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
361 return 0;
589bc3d060cd More 1.3 audio work...moved dsp and dma drivers over to new model. Untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
362 }
589bc3d060cd More 1.3 audio work...moved dsp and dma drivers over to new model. Untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
363 this->spec.size = info.fragsize;
589bc3d060cd More 1.3 audio work...moved dsp and dma drivers over to new model. Untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
364 this->spec.samples = this->spec.size / ((this->spec.format & 0xFF) / 8);
589bc3d060cd More 1.3 audio work...moved dsp and dma drivers over to new model. Untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
365 this->spec.samples /= this->spec.channels;
589bc3d060cd More 1.3 audio work...moved dsp and dma drivers over to new model. Untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
366 num_buffers = info.fragstotal;
589bc3d060cd More 1.3 audio work...moved dsp and dma drivers over to new model. Untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
367 dma_len = num_buffers * this->spec.size;
589bc3d060cd More 1.3 audio work...moved dsp and dma drivers over to new model. Untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
368 dma_buf = (Uint8 *) mmap(NULL, dma_len, PROT_WRITE, MAP_SHARED,
589bc3d060cd More 1.3 audio work...moved dsp and dma drivers over to new model. Untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
369 audio_fd, 0);
589bc3d060cd More 1.3 audio work...moved dsp and dma drivers over to new model. Untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
370 if (dma_buf == MAP_FAILED) {
3817
103bbe13f5eb Patched to compile.
Ryan C. Gordon <icculus@icculus.org>
parents: 3816
diff changeset
371 DMA_CloseDevice(this);
3795
589bc3d060cd More 1.3 audio work...moved dsp and dma drivers over to new model. Untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
372 SDL_SetError("DMA memory map failed");
589bc3d060cd More 1.3 audio work...moved dsp and dma drivers over to new model. Untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
373 dma_buf = NULL;
589bc3d060cd More 1.3 audio work...moved dsp and dma drivers over to new model. Untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
374 return 0;
589bc3d060cd More 1.3 audio work...moved dsp and dma drivers over to new model. Untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
375 }
589bc3d060cd More 1.3 audio work...moved dsp and dma drivers over to new model. Untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
376 SDL_memset(dma_buf, this->spec.silence, dma_len);
589bc3d060cd More 1.3 audio work...moved dsp and dma drivers over to new model. Untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
377
589bc3d060cd More 1.3 audio work...moved dsp and dma drivers over to new model. Untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
378 /* Check to see if we need to use select() workaround */
589bc3d060cd More 1.3 audio work...moved dsp and dma drivers over to new model. Untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
379 {
589bc3d060cd More 1.3 audio work...moved dsp and dma drivers over to new model. Untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
380 char *workaround;
589bc3d060cd More 1.3 audio work...moved dsp and dma drivers over to new model. Untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
381 workaround = SDL_getenv("SDL_DSP_NOSELECT");
589bc3d060cd More 1.3 audio work...moved dsp and dma drivers over to new model. Untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
382 if (workaround) {
589bc3d060cd More 1.3 audio work...moved dsp and dma drivers over to new model. Untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
383 frame_ticks = (float) (this->spec.samples*1000) / this->spec.freq;
589bc3d060cd More 1.3 audio work...moved dsp and dma drivers over to new model. Untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
384 next_frame = SDL_GetTicks() + frame_ticks;
589bc3d060cd More 1.3 audio work...moved dsp and dma drivers over to new model. Untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
385 }
589bc3d060cd More 1.3 audio work...moved dsp and dma drivers over to new model. Untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
386 }
589bc3d060cd More 1.3 audio work...moved dsp and dma drivers over to new model. Untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
387
589bc3d060cd More 1.3 audio work...moved dsp and dma drivers over to new model. Untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
388 /* Trigger audio playback */
589bc3d060cd More 1.3 audio work...moved dsp and dma drivers over to new model. Untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
389 value = 0;
589bc3d060cd More 1.3 audio work...moved dsp and dma drivers over to new model. Untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
390 ioctl(audio_fd, SNDCTL_DSP_SETTRIGGER, &value);
589bc3d060cd More 1.3 audio work...moved dsp and dma drivers over to new model. Untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
391 value = PCM_ENABLE_OUTPUT;
589bc3d060cd More 1.3 audio work...moved dsp and dma drivers over to new model. Untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
392 if (ioctl(audio_fd, SNDCTL_DSP_SETTRIGGER, &value) < 0) {
3817
103bbe13f5eb Patched to compile.
Ryan C. Gordon <icculus@icculus.org>
parents: 3816
diff changeset
393 DMA_CloseDevice(this);
3795
589bc3d060cd More 1.3 audio work...moved dsp and dma drivers over to new model. Untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
394 SDL_SetError("Couldn't trigger audio output");
589bc3d060cd More 1.3 audio work...moved dsp and dma drivers over to new model. Untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
395 return 0;
589bc3d060cd More 1.3 audio work...moved dsp and dma drivers over to new model. Untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
396 }
589bc3d060cd More 1.3 audio work...moved dsp and dma drivers over to new model. Untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
397
589bc3d060cd More 1.3 audio work...moved dsp and dma drivers over to new model. Untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
398 /* Get the parent process id (we're the parent of the audio thread) */
589bc3d060cd More 1.3 audio work...moved dsp and dma drivers over to new model. Untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
399 parent = getpid();
589bc3d060cd More 1.3 audio work...moved dsp and dma drivers over to new model. Untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
400
589bc3d060cd More 1.3 audio work...moved dsp and dma drivers over to new model. Untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
401 /* We're ready to rock and roll. :-) */
589bc3d060cd More 1.3 audio work...moved dsp and dma drivers over to new model. Untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
402 return 1;
589bc3d060cd More 1.3 audio work...moved dsp and dma drivers over to new model. Untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
403 }
589bc3d060cd More 1.3 audio work...moved dsp and dma drivers over to new model. Untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
404
589bc3d060cd More 1.3 audio work...moved dsp and dma drivers over to new model. Untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
405
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
406 /* 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
407 static void
3795
589bc3d060cd More 1.3 audio work...moved dsp and dma drivers over to new model. Untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
408 DMA_WaitDevice(_THIS)
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
409 {
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
410 fd_set fdset;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
411
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
412 /* Check to see if the thread-parent process is still alive */
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 {
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 static int cnt = 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
415 /* Note that this only works with thread implementations
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 that use a different process id for each thread.
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
417 */
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 if (parent && (((++cnt) % 10) == 0)) { /* Check every 10 loops */
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
419 if (kill(parent, 0) < 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
420 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
421 }
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
422 }
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 }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
424
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
425 /* See if we need to use timed audio synchronization */
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 if (frame_ticks) {
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 /* Use timer for general audio synchronization */
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
428 Sint32 ticks;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
429
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
430 ticks = ((Sint32) (next_frame - SDL_GetTicks())) - FUDGE_TICKS;
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 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
432 SDL_Delay(ticks);
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
433 }
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
434 } else {
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 /* Use select() for audio synchronization */
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 struct timeval timeout;
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
437 FD_ZERO(&fdset);
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
438 FD_SET(audio_fd, &fdset);
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 timeout.tv_sec = 10;
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
440 timeout.tv_usec = 0;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
441 #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
442 fprintf(stderr, "Waiting for audio to get ready\n");
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
443 #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
444 if (select(audio_fd + 1, NULL, &fdset, NULL, &timeout) <= 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
445 const char *message =
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
446 #ifdef AUDIO_OSPACE_HACK
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 "Audio timeout - buggy audio driver? (trying ospace)";
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
448 #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
449 "Audio timeout - buggy audio driver? (disabled)";
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
450 #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
451 /* In general we should never print to the screen,
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 but in this case we have no other way of letting
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 the user know what happened.
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 */
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
455 fprintf(stderr, "SDL: %s\n", message);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
456 #ifdef AUDIO_OSPACE_HACK
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
457 /* We may be able to use GET_OSPACE trick */
3795
589bc3d060cd More 1.3 audio work...moved dsp and dma drivers over to new model. Untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
458 frame_ticks = (float) (this->spec.samples * 1000) /
589bc3d060cd More 1.3 audio work...moved dsp and dma drivers over to new model. Untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
459 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
460 next_frame = SDL_GetTicks() + frame_ticks;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
461 #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
462 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
463 /* Don't try to close - may hang */
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
464 audio_fd = -1;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
465 #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
466 fprintf(stderr, "Done disabling audio\n");
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
467 #endif
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
468 #endif /* AUDIO_OSPACE_HACK */
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
469 }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
470 #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
471 fprintf(stderr, "Ready!\n");
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
472 #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
473 }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
474 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
475
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
476 static void
3795
589bc3d060cd More 1.3 audio work...moved dsp and dma drivers over to new model. Untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
477 DMA_PlayDevice(_THIS)
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
478 {
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
479 /* If timer synchronization is enabled, set the next write frame */
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
480 if (frame_ticks) {
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
481 next_frame += frame_ticks;
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
482 }
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
483 return;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
484 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
485
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
486 static Uint8 *
3795
589bc3d060cd More 1.3 audio work...moved dsp and dma drivers over to new model. Untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
487 DMA_GetDeviceBuf(_THIS)
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
488 {
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
489 count_info info;
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
490 int playing;
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 int filling;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
492
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
493 /* Get number of blocks, looping if we're not using select() */
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 do {
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 if (ioctl(audio_fd, SNDCTL_DSP_GETOPTR, &info) < 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
496 /* Uh oh... */
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 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
498 return (NULL);
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 }
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 }
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 while (frame_ticks && (info.blocks < 1));
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
502 #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
503 if (info.blocks > 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
504 printf("Warning: audio underflow (%d frags)\n", info.blocks - 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
505 }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
506 #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
507 playing = info.ptr / this->spec.size;
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
508 filling = (playing + 1) % num_buffers;
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 return (dma_buf + (filling * this->spec.size));
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
510 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
511
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
512
3816
9d070c1a45fa Moved AudioBootstrap section in converted drivers to bottom of source, so I
Ryan C. Gordon <icculus@icculus.org>
parents: 3810
diff changeset
513 static int
9d070c1a45fa Moved AudioBootstrap section in converted drivers to bottom of source, so I
Ryan C. Gordon <icculus@icculus.org>
parents: 3810
diff changeset
514 DMA_Init(SDL_AudioDriverImpl *impl)
9d070c1a45fa Moved AudioBootstrap section in converted drivers to bottom of source, so I
Ryan C. Gordon <icculus@icculus.org>
parents: 3810
diff changeset
515 {
9d070c1a45fa Moved AudioBootstrap section in converted drivers to bottom of source, so I
Ryan C. Gordon <icculus@icculus.org>
parents: 3810
diff changeset
516 /* Set the function pointers */
9d070c1a45fa Moved AudioBootstrap section in converted drivers to bottom of source, so I
Ryan C. Gordon <icculus@icculus.org>
parents: 3810
diff changeset
517 impl->DetectDevices = DMA_DetectDevices;
9d070c1a45fa Moved AudioBootstrap section in converted drivers to bottom of source, so I
Ryan C. Gordon <icculus@icculus.org>
parents: 3810
diff changeset
518 impl->GetDeviceName = DMA_GetDeviceName;
9d070c1a45fa Moved AudioBootstrap section in converted drivers to bottom of source, so I
Ryan C. Gordon <icculus@icculus.org>
parents: 3810
diff changeset
519 impl->OpenDevice = DMA_OpenDevice;
9d070c1a45fa Moved AudioBootstrap section in converted drivers to bottom of source, so I
Ryan C. Gordon <icculus@icculus.org>
parents: 3810
diff changeset
520 impl->WaitDevice = DMA_WaitDevice;
9d070c1a45fa Moved AudioBootstrap section in converted drivers to bottom of source, so I
Ryan C. Gordon <icculus@icculus.org>
parents: 3810
diff changeset
521 impl->PlayDevice = DMA_PlayDevice;
9d070c1a45fa Moved AudioBootstrap section in converted drivers to bottom of source, so I
Ryan C. Gordon <icculus@icculus.org>
parents: 3810
diff changeset
522 impl->GetDeviceBuf = DMA_GetDeviceBuf;
9d070c1a45fa Moved AudioBootstrap section in converted drivers to bottom of source, so I
Ryan C. Gordon <icculus@icculus.org>
parents: 3810
diff changeset
523 impl->CloseDevice = DMA_CloseDevice;
9d070c1a45fa Moved AudioBootstrap section in converted drivers to bottom of source, so I
Ryan C. Gordon <icculus@icculus.org>
parents: 3810
diff changeset
524 impl->Deinitialize = DMA_Deinitialize;
9d070c1a45fa Moved AudioBootstrap section in converted drivers to bottom of source, so I
Ryan C. Gordon <icculus@icculus.org>
parents: 3810
diff changeset
525
9d070c1a45fa Moved AudioBootstrap section in converted drivers to bottom of source, so I
Ryan C. Gordon <icculus@icculus.org>
parents: 3810
diff changeset
526 build_device_lists();
9d070c1a45fa Moved AudioBootstrap section in converted drivers to bottom of source, so I
Ryan C. Gordon <icculus@icculus.org>
parents: 3810
diff changeset
527 return 1;
9d070c1a45fa Moved AudioBootstrap section in converted drivers to bottom of source, so I
Ryan C. Gordon <icculus@icculus.org>
parents: 3810
diff changeset
528 }
9d070c1a45fa Moved AudioBootstrap section in converted drivers to bottom of source, so I
Ryan C. Gordon <icculus@icculus.org>
parents: 3810
diff changeset
529
9d070c1a45fa Moved AudioBootstrap section in converted drivers to bottom of source, so I
Ryan C. Gordon <icculus@icculus.org>
parents: 3810
diff changeset
530 AudioBootStrap DMA_bootstrap = {
3846
66fb40445587 Removed distinction between "available" and "init" in audio backends, since
Ryan C. Gordon <icculus@icculus.org>
parents: 3817
diff changeset
531 DMA_DRIVER_NAME, "OSS /dev/dsp DMA audio", DMA_Init, 0
3816
9d070c1a45fa Moved AudioBootstrap section in converted drivers to bottom of source, so I
Ryan C. Gordon <icculus@icculus.org>
parents: 3810
diff changeset
532 };
9d070c1a45fa Moved AudioBootstrap section in converted drivers to bottom of source, so I
Ryan C. Gordon <icculus@icculus.org>
parents: 3810
diff changeset
533
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
534 /* vi: set ts=4 sw=4 expandtab: */