annotate src/audio/dma/SDL_dmaaudio.c @ 3833:de857f0708f5 SDL-ryan-multiple-audio-device

Whoops, changed that symbol name...
author Ryan C. Gordon <icculus@icculus.org>
date Sat, 07 Oct 2006 20:23:02 +0000
parents 103bbe13f5eb
children 66fb40445587
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
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
119 static int
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
120 DMA_Available(void)
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
121 {
3810
2c5387c0a642 Multiple audio device code is now working for dsp and dma targets.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
122 int available = 0;
2c5387c0a642 Multiple audio device code is now working for dsp and dma targets.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
123 build_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
124 available = ((outputDeviceCount > 0) || (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
125 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
126 return available;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
127 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
128
3810
2c5387c0a642 Multiple audio device code is now working for dsp and dma targets.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
129 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
130 {
2c5387c0a642 Multiple audio device code is now working for dsp and dma targets.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
131 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
132 }
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
133
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
134 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
135 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
136 {
3810
2c5387c0a642 Multiple audio device code is now working for dsp and dma targets.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
137 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
138 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
139 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
140 } else {
2c5387c0a642 Multiple audio device code is now working for dsp and dma targets.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
141 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
142 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
143 }
2c5387c0a642 Multiple audio device code is now working for dsp and dma targets.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
144
2c5387c0a642 Multiple audio device code is now working for dsp and dma targets.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
145 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
146 }
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
147
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
148
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
149 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
150 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
151 {
3810
2c5387c0a642 Multiple audio device code is now working for dsp and dma targets.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
152 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
153 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
154 } 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
155 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
156 }
2c5387c0a642 Multiple audio device code is now working for dsp and dma targets.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
157
2c5387c0a642 Multiple audio device code is now working for dsp and dma targets.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
158 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
159 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
160 }
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
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
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 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
164 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
165 {
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 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
167 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
168
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 /* 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
170 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
171 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
172 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
173 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
174 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
175 }
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 /* 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
178 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
179
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 /* 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
181 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
182 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
183 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
184 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
185 }
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
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 /* 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
188 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
189 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
190 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
191 }
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
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 /* 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
194 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
195 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
196 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
197 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
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
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 /* 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
201 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
202 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
203 (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
204 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
205 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
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
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 /* 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
209 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
210 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
211 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
212 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
213 }
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
214 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
215
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
216 /* 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
217 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
218 }
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
219
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
220
3817
103bbe13f5eb Patched to compile.
Ryan C. Gordon <icculus@icculus.org>
parents: 3816
diff changeset
221 static void
103bbe13f5eb Patched to compile.
Ryan C. Gordon <icculus@icculus.org>
parents: 3816
diff changeset
222 DMA_CloseDevice(_THIS)
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 if (this->hidden != NULL) {
103bbe13f5eb Patched to compile.
Ryan C. Gordon <icculus@icculus.org>
parents: 3816
diff changeset
225 if (dma_buf != NULL) {
103bbe13f5eb Patched to compile.
Ryan C. Gordon <icculus@icculus.org>
parents: 3816
diff changeset
226 munmap(dma_buf, dma_len);
103bbe13f5eb Patched to compile.
Ryan C. Gordon <icculus@icculus.org>
parents: 3816
diff changeset
227 dma_buf = NULL;
103bbe13f5eb Patched to compile.
Ryan C. Gordon <icculus@icculus.org>
parents: 3816
diff changeset
228 }
103bbe13f5eb Patched to compile.
Ryan C. Gordon <icculus@icculus.org>
parents: 3816
diff changeset
229 if (audio_fd >= 0) {
103bbe13f5eb Patched to compile.
Ryan C. Gordon <icculus@icculus.org>
parents: 3816
diff changeset
230 close(audio_fd);
103bbe13f5eb Patched to compile.
Ryan C. Gordon <icculus@icculus.org>
parents: 3816
diff changeset
231 audio_fd = -1;
103bbe13f5eb Patched to compile.
Ryan C. Gordon <icculus@icculus.org>
parents: 3816
diff changeset
232 }
103bbe13f5eb Patched to compile.
Ryan C. Gordon <icculus@icculus.org>
parents: 3816
diff changeset
233 SDL_free(this->hidden);
103bbe13f5eb Patched to compile.
Ryan C. Gordon <icculus@icculus.org>
parents: 3816
diff changeset
234 this->hidden = NULL;
103bbe13f5eb Patched to compile.
Ryan C. Gordon <icculus@icculus.org>
parents: 3816
diff changeset
235 }
103bbe13f5eb Patched to compile.
Ryan C. Gordon <icculus@icculus.org>
parents: 3816
diff changeset
236 }
103bbe13f5eb Patched to compile.
Ryan C. Gordon <icculus@icculus.org>
parents: 3816
diff changeset
237
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
238
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 static int
3817
103bbe13f5eb Patched to compile.
Ryan C. Gordon <icculus@icculus.org>
parents: 3816
diff changeset
240 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
241 {
3810
2c5387c0a642 Multiple audio device code is now working for dsp and dma targets.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
242 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
243 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
244 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
245 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
246 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
247 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
248
3810
2c5387c0a642 Multiple audio device code is now working for dsp and dma targets.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
249 /* 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
250 /* ...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
251 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
252 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
253 ((!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
254 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
255 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
256 }
2c5387c0a642 Multiple audio device code is now working for dsp and dma targets.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
257 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
258 }
2c5387c0a642 Multiple audio device code is now working for dsp and dma targets.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
259
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
260 /* 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
261 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
262 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
263 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
264 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
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 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
268
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 /* 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
270 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
271 if (audio_fd < 0) {
3817
103bbe13f5eb Patched to compile.
Ryan C. Gordon <icculus@icculus.org>
parents: 3816
diff changeset
272 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
273 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
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 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
277 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
278
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 /* 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
280 if (ioctl(audio_fd, SNDCTL_DSP_GETFMTS, &value) < 0) {
3817
103bbe13f5eb Patched to compile.
Ryan C. Gordon <icculus@icculus.org>
parents: 3816
diff changeset
281 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
282 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
283 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
284 }
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
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 /* 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
287 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
288 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
289 !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
290 #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
291 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
292 #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
293 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
294 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
295 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
296 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
297 }
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 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
299 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
300 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
301 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
302 }
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 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
304 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
305 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
306 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
307 }
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 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
309 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
310 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
311 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
312 }
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 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
314 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
315 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
316 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
317 }
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 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
319 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
320 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
321 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
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 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
324 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
325 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
326 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
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 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
329 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
330 }
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 }
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 (format == 0) {
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 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
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 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
338
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 /* 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
340 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
341 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
342 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
343 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
344 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
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 /* 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
348 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
349 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
350 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
351 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
352 } 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
353 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
354 }
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 /* 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
357 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
358 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
359 */
3810
2c5387c0a642 Multiple audio device code is now working for dsp and dma targets.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
360 if (DMA_ReopenAudio(this, devname, format, stereo) < 0) {
3817
103bbe13f5eb Patched to compile.
Ryan C. Gordon <icculus@icculus.org>
parents: 3816
diff changeset
361 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
362 /* 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
363 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
364 }
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
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 /* 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
367 if (ioctl(audio_fd, SNDCTL_DSP_GETOSPACE, &info) < 0) {
3817
103bbe13f5eb Patched to compile.
Ryan C. Gordon <icculus@icculus.org>
parents: 3816
diff changeset
368 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
369 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
370 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
371 }
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 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
373 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
374 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
375 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
376 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
377 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
378 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
379 if (dma_buf == MAP_FAILED) {
3817
103bbe13f5eb Patched to compile.
Ryan C. Gordon <icculus@icculus.org>
parents: 3816
diff changeset
380 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
381 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
382 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
383 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
384 }
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 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
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 /* 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
388 {
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 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
390 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
391 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
392 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
393 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
394 }
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 }
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 /* 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
398 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
399 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
400 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
401 if (ioctl(audio_fd, SNDCTL_DSP_SETTRIGGER, &value) < 0) {
3817
103bbe13f5eb Patched to compile.
Ryan C. Gordon <icculus@icculus.org>
parents: 3816
diff changeset
402 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
403 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
404 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
405 }
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
406
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
407 /* 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
408 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
409
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
410 /* 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
411 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
412 }
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
413
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
414
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
415 /* 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
416 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
417 DMA_WaitDevice(_THIS)
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
418 {
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
419 fd_set fdset;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
420
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 /* 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
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 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
424 /* 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
425 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
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 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
428 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
429 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
430 }
c121d94672cb SDL 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 }
c121d94672cb SDL 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 }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
433
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
434 /* 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
435 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
436 /* 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
437 Sint32 ticks;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
438
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 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
440 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
441 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
442 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
443 } 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
444 /* 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
445 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
446 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
447 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
448 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
449 timeout.tv_usec = 0;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
450 #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
451 fprintf(stderr, "Waiting for audio to get ready\n");
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
452 #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
453 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
454 const char *message =
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
455 #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
456 "Audio timeout - buggy audio driver? (trying ospace)";
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
457 #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
458 "Audio timeout - buggy audio driver? (disabled)";
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
459 #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
460 /* 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
461 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
462 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
463 */
c121d94672cb SDL 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 fprintf(stderr, "SDL: %s\n", message);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
465 #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
466 /* 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
467 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
468 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
469 next_frame = SDL_GetTicks() + frame_ticks;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
470 #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
471 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
472 /* 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
473 audio_fd = -1;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
474 #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
475 fprintf(stderr, "Done disabling audio\n");
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
476 #endif
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
477 #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
478 }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
479 #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
480 fprintf(stderr, "Ready!\n");
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
481 #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
482 }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
483 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
484
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
485 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
486 DMA_PlayDevice(_THIS)
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
487 {
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
488 /* 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
489 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
490 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
491 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
492 return;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
493 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
494
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
495 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
496 DMA_GetDeviceBuf(_THIS)
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
497 {
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
498 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
499 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
500 int filling;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
501
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
502 /* 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
503 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
504 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
505 /* 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
506 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
507 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
508 }
c121d94672cb SDL 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 }
c121d94672cb SDL 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 while (frame_ticks && (info.blocks < 1));
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
511 #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
512 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
513 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
514 }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
515 #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
516 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
517 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
518 return (dma_buf + (filling * this->spec.size));
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
519 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
520
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
521
3816
9d070c1a45fa Moved AudioBootstrap section in converted drivers to bottom of source, so I
Ryan C. Gordon <icculus@icculus.org>
parents: 3810
diff changeset
522 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
523 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
524 {
9d070c1a45fa Moved AudioBootstrap section in converted drivers to bottom of source, so I
Ryan C. Gordon <icculus@icculus.org>
parents: 3810
diff changeset
525 /* 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
526 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
527 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
528 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
529 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
530 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
531 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
532 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
533 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
534
9d070c1a45fa Moved AudioBootstrap section in converted drivers to bottom of source, so I
Ryan C. Gordon <icculus@icculus.org>
parents: 3810
diff changeset
535 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
536 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
537 }
9d070c1a45fa Moved AudioBootstrap section in converted drivers to bottom of source, so I
Ryan C. Gordon <icculus@icculus.org>
parents: 3810
diff changeset
538
9d070c1a45fa Moved AudioBootstrap section in converted drivers to bottom of source, so I
Ryan C. Gordon <icculus@icculus.org>
parents: 3810
diff changeset
539 AudioBootStrap DMA_bootstrap = {
9d070c1a45fa Moved AudioBootstrap section in converted drivers to bottom of source, so I
Ryan C. Gordon <icculus@icculus.org>
parents: 3810
diff changeset
540 DMA_DRIVER_NAME, "OSS /dev/dsp DMA audio",
9d070c1a45fa Moved AudioBootstrap section in converted drivers to bottom of source, so I
Ryan C. Gordon <icculus@icculus.org>
parents: 3810
diff changeset
541 DMA_Available, DMA_Init, 0
9d070c1a45fa Moved AudioBootstrap section in converted drivers to bottom of source, so I
Ryan C. Gordon <icculus@icculus.org>
parents: 3810
diff changeset
542 };
9d070c1a45fa Moved AudioBootstrap section in converted drivers to bottom of source, so I
Ryan C. Gordon <icculus@icculus.org>
parents: 3810
diff changeset
543
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
544 /* vi: set ts=4 sw=4 expandtab: */