annotate src/audio/dsp/SDL_dspaudio.c @ 3810:2c5387c0a642 SDL-ryan-multiple-audio-device

Multiple audio device code is now working for dsp and dma targets.
author Ryan C. Gordon <icculus@icculus.org>
date Thu, 05 Oct 2006 04:47:13 +0000
parents c8b3d3d13ed1
children 9d070c1a45fa
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: 1281
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: 1281
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: 1281
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: 1281
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: 1281
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: 1281
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: 1281
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: 248
diff changeset
20 slouken@libsdl.org
968
4675910b0b7b Date: Mon, 11 Oct 2004 15:17:27 +0300 (EEST)
Sam Lantinga <slouken@libsdl.org>
parents: 960
diff changeset
21
4675910b0b7b Date: Mon, 11 Oct 2004 15:17:27 +0300 (EEST)
Sam Lantinga <slouken@libsdl.org>
parents: 960
diff changeset
22 Modified in Oct 2004 by Hannu Savolainen
4675910b0b7b Date: Mon, 11 Oct 2004 15:17:27 +0300 (EEST)
Sam Lantinga <slouken@libsdl.org>
parents: 960
diff changeset
23 hannu@opensound.com
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
24 */
1402
d910939febfa Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents: 1361
diff changeset
25 #include "SDL_config.h"
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
26
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
27 /* Allow access to a raw mixing buffer */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
28
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1612
diff changeset
29 #include <stdio.h> /* For perror() */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1612
diff changeset
30 #include <string.h> /* For strerror() */
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
31 #include <errno.h>
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
32 #include <unistd.h>
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
33 #include <fcntl.h>
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
34 #include <signal.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>
1361
19418e4422cb New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents: 1358
diff changeset
38
19418e4422cb New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents: 1358
diff changeset
39 #if SDL_AUDIO_DRIVER_OSS_SOUNDCARD_H
94
ae6e6b73333f Cleaned up the OpenBSD port, thanks to Peter Valchev
Sam Lantinga <slouken@lokigames.com>
parents: 93
diff changeset
40 /* This is installed on some systems */
ae6e6b73333f Cleaned up the OpenBSD port, thanks to Peter Valchev
Sam Lantinga <slouken@lokigames.com>
parents: 93
diff changeset
41 #include <soundcard.h>
ae6e6b73333f Cleaned up the OpenBSD port, thanks to Peter Valchev
Sam Lantinga <slouken@lokigames.com>
parents: 93
diff changeset
42 #else
ae6e6b73333f Cleaned up the OpenBSD port, thanks to Peter Valchev
Sam Lantinga <slouken@lokigames.com>
parents: 93
diff changeset
43 /* This is recommended by OSS */
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
44 #include <sys/soundcard.h>
94
ae6e6b73333f Cleaned up the OpenBSD port, thanks to Peter Valchev
Sam Lantinga <slouken@lokigames.com>
parents: 93
diff changeset
45 #endif
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
46
1358
c71e05b4dc2e More header massaging... works great on Windows. ;-)
Sam Lantinga <slouken@libsdl.org>
parents: 1341
diff changeset
47 #include "SDL_timer.h"
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
48 #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
49 #include "../SDL_audiomem.h"
19418e4422cb New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents: 1358
diff changeset
50 #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
51 #include "../SDL_audiodev_c.h"
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
52 #include "SDL_dspaudio.h"
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
53
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
54 /* The tag name used by DSP audio */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
55 #define DSP_DRIVER_NAME "dsp"
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
56
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
57 /* 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
58 #define OPEN_FLAGS_OUTPUT (O_WRONLY|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
59 #define OPEN_FLAGS_INPUT (O_RDONLY|O_NONBLOCK)
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
60
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
61 /* Audio driver functions */
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
62 static int DSP_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
63 static const char *DSP_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
64 static int DSP_OpenDevice(_THIS, const char *devname, 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
65 static void DSP_WaitDevice(_THIS);
589bc3d060cd More 1.3 audio work...moved dsp and dma drivers over to new model. Untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
66 static void DSP_PlayDevice(_THIS);
589bc3d060cd More 1.3 audio work...moved dsp and dma drivers over to new model. Untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
67 static Uint8 *DSP_GetDeviceBuf(_THIS);
589bc3d060cd More 1.3 audio work...moved dsp and dma drivers over to new model. Untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
68 static void DSP_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
69 static void DSP_Deinitialize(void);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
70
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
71 /* Audio driver bootstrap functions */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
72
3810
2c5387c0a642 Multiple audio device code is now working for dsp and dma targets.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
73 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
74 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
75 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
76 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
77
2c5387c0a642 Multiple audio device code is now working for dsp and dma targets.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
78 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
79 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
80 {
2c5387c0a642 Multiple audio device code is now working for dsp and dma targets.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
81 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
82 }
2c5387c0a642 Multiple audio device code is now working for dsp and dma targets.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
83
2c5387c0a642 Multiple audio device code is now working for dsp and dma targets.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
84 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
85 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
86 {
2c5387c0a642 Multiple audio device code is now working for dsp and dma targets.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
87 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
88 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
89 SDL_EnumUnixAudioDevices(flags, 0, NULL, 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
90 }
2c5387c0a642 Multiple audio device code is now working for dsp and dma targets.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
91
2c5387c0a642 Multiple audio device code is now working for dsp and dma targets.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
92 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
93 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
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 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
96 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
97 }
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
2c5387c0a642 Multiple audio device code is now working for dsp and dma targets.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
100 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
101 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
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 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
104 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
105 }
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
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1612
diff changeset
108 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
109 DSP_Available(void)
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
110 {
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
111 int available = 0;
3810
2c5387c0a642 Multiple audio device code is now working for dsp and dma targets.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
112 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
113 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
114 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
115 return available;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
116 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
117
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
118
589bc3d060cd More 1.3 audio work...moved dsp and dma drivers over to new model. Untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
119 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
120 DSP_Init(SDL_AudioDriverImpl *impl)
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
121 {
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
122 /* Set the function pointers */
589bc3d060cd More 1.3 audio work...moved dsp and dma drivers over to new model. Untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
123 impl->DetectDevices = DSP_DetectDevices;
589bc3d060cd More 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 impl->GetDeviceName = DSP_GetDeviceName;
589bc3d060cd More 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 impl->OpenDevice = DSP_OpenDevice;
589bc3d060cd More 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 impl->PlayDevice = DSP_PlayDevice;
589bc3d060cd More 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 impl->GetDeviceBuf = DSP_GetDeviceBuf;
589bc3d060cd More 1.3 audio work...moved dsp and dma drivers over to new model. Untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
128 impl->CloseDevice = DSP_CloseDevice;
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 impl->Deinitialize = DSP_Deinitialize;
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
130
3810
2c5387c0a642 Multiple audio device code is now working for dsp and dma targets.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
131 build_device_lists();
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
132 return 1;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
133 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
134
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
135
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
136 AudioBootStrap DSP_bootstrap = {
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1612
diff changeset
137 DSP_DRIVER_NAME, "OSS /dev/dsp standard audio",
3798
c8b3d3d13ed1 Audio bootstraps can now specify that a driver is only to be used if
Ryan C. Gordon <icculus@icculus.org>
parents: 3795
diff changeset
138 DSP_Available, DSP_Init, 0
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
139 };
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
140
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
141
3810
2c5387c0a642 Multiple audio device code is now working for dsp and dma targets.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
142 static void DSP_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
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 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
145 }
2c5387c0a642 Multiple audio device code is now working for dsp and dma targets.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
146
2c5387c0a642 Multiple audio device code is now working for dsp and dma targets.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
147
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
148 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
149 DSP_DetectDevices(int iscapture)
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
150 {
3810
2c5387c0a642 Multiple audio device code is now working for dsp and dma targets.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
151 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
152 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
153 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
154 } else {
2c5387c0a642 Multiple audio device code is now working for dsp and dma targets.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
155 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
156 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
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
2c5387c0a642 Multiple audio device code is now working for dsp and dma targets.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
159 return 0; /* shouldn't ever hit this. */
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
160 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
161
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
162 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
163 DSP_GetDeviceName(int index, int iscapture)
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
164 {
3810
2c5387c0a642 Multiple audio device code is now working for dsp and dma targets.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
165 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
166 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
167 } 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
168 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
169 }
2c5387c0a642 Multiple audio device code is now working for dsp and dma targets.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
170
2c5387c0a642 Multiple audio device code is now working for dsp and dma targets.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
171 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
172 return NULL;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
173 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
174
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
175
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1612
diff changeset
176 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
177 DSP_OpenDevice(_THIS, const char *devname, int iscapture)
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
178 {
3810
2c5387c0a642 Multiple audio device code is now working for dsp and dma targets.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
179 const int flags = ((iscapture) ? OPEN_FLAGS_INPUT : OPEN_FLAGS_OUTPUT);
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1612
diff changeset
180 int format;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1612
diff changeset
181 int value;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1612
diff changeset
182 int frag_spec;
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
183 SDL_AudioFormat test_format;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
184
3810
2c5387c0a642 Multiple audio device code is now working for dsp and dma targets.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
185 /* 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
186 /* ...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
187 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
188 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
189 ((!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
190 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
191 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
192 }
2c5387c0a642 Multiple audio device code is now working for dsp and dma targets.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
193 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
194 }
2c5387c0a642 Multiple audio device code is now working for dsp and dma targets.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
195
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
196 /* 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
197 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
198 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
199 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
200 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
201 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
202 }
589bc3d060cd More 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 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
204 this->hidden->audio_fd = -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
205
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1612
diff changeset
206 /* 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
207 this->hidden->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
208 if (this->hidden->audio_fd < 0) {
3810
2c5387c0a642 Multiple audio device code is now working for dsp and dma targets.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
209 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
210 return 0;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1612
diff changeset
211 }
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
212 this->hidden->mixbuf = NULL;
968
4675910b0b7b Date: Mon, 11 Oct 2004 15:17:27 +0300 (EEST)
Sam Lantinga <slouken@libsdl.org>
parents: 960
diff changeset
213
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1612
diff changeset
214 /* Make the file descriptor use blocking writes with fcntl() */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1612
diff changeset
215 {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1612
diff changeset
216 long flags;
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
217 flags = fcntl(this->hidden->audio_fd, F_GETFL);
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1612
diff changeset
218 flags &= ~O_NONBLOCK;
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
219 if (fcntl(this->hidden->audio_fd, F_SETFL, flags) < 0) {
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1612
diff changeset
220 SDL_SetError("Couldn't set audio blocking mode");
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
221 DSP_CloseDevice(this);
589bc3d060cd More 1.3 audio work...moved dsp and dma drivers over to new model. Untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
222 return 0;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1612
diff changeset
223 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1612
diff changeset
224 }
968
4675910b0b7b Date: Mon, 11 Oct 2004 15:17:27 +0300 (EEST)
Sam Lantinga <slouken@libsdl.org>
parents: 960
diff changeset
225
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1612
diff changeset
226 /* Get a list of supported hardware formats */
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
227 if (ioctl(this->hidden->audio_fd, SNDCTL_DSP_GETFMTS, &value) < 0) {
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1612
diff changeset
228 perror("SNDCTL_DSP_GETFMTS");
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1612
diff changeset
229 SDL_SetError("Couldn't get audio format list");
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
230 DSP_CloseDevice(this);
589bc3d060cd More 1.3 audio work...moved dsp and dma drivers over to new model. Untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
231 return 0;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1612
diff changeset
232 }
968
4675910b0b7b Date: Mon, 11 Oct 2004 15:17:27 +0300 (EEST)
Sam Lantinga <slouken@libsdl.org>
parents: 960
diff changeset
233
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1612
diff changeset
234 /* Try for a closest match on audio format */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1612
diff changeset
235 format = 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
236 for (test_format = SDL_FirstAudioFormat(this->spec.format);
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1612
diff changeset
237 !format && test_format;) {
968
4675910b0b7b Date: Mon, 11 Oct 2004 15:17:27 +0300 (EEST)
Sam Lantinga <slouken@libsdl.org>
parents: 960
diff changeset
238 #ifdef DEBUG_AUDIO
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1612
diff changeset
239 fprintf(stderr, "Trying format 0x%4.4x\n", test_format);
968
4675910b0b7b Date: Mon, 11 Oct 2004 15:17:27 +0300 (EEST)
Sam Lantinga <slouken@libsdl.org>
parents: 960
diff changeset
240 #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: 1612
diff changeset
241 switch (test_format) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1612
diff changeset
242 case AUDIO_U8:
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1612
diff changeset
243 if (value & AFMT_U8) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1612
diff changeset
244 format = AFMT_U8;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1612
diff changeset
245 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1612
diff changeset
246 break;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1612
diff changeset
247 case AUDIO_S16LSB:
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1612
diff changeset
248 if (value & AFMT_S16_LE) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1612
diff changeset
249 format = AFMT_S16_LE;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1612
diff changeset
250 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1612
diff changeset
251 break;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1612
diff changeset
252 case AUDIO_S16MSB:
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1612
diff changeset
253 if (value & AFMT_S16_BE) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1612
diff changeset
254 format = AFMT_S16_BE;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1612
diff changeset
255 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1612
diff changeset
256 break;
968
4675910b0b7b Date: Mon, 11 Oct 2004 15:17:27 +0300 (EEST)
Sam Lantinga <slouken@libsdl.org>
parents: 960
diff changeset
257 #if 0
4675910b0b7b Date: Mon, 11 Oct 2004 15:17:27 +0300 (EEST)
Sam Lantinga <slouken@libsdl.org>
parents: 960
diff changeset
258 /*
4675910b0b7b Date: Mon, 11 Oct 2004 15:17:27 +0300 (EEST)
Sam Lantinga <slouken@libsdl.org>
parents: 960
diff changeset
259 * These formats are not used by any real life systems so they are not
4675910b0b7b Date: Mon, 11 Oct 2004 15:17:27 +0300 (EEST)
Sam Lantinga <slouken@libsdl.org>
parents: 960
diff changeset
260 * needed here.
4675910b0b7b Date: Mon, 11 Oct 2004 15:17:27 +0300 (EEST)
Sam Lantinga <slouken@libsdl.org>
parents: 960
diff changeset
261 */
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1612
diff changeset
262 case AUDIO_S8:
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1612
diff changeset
263 if (value & AFMT_S8) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1612
diff changeset
264 format = AFMT_S8;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1612
diff changeset
265 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1612
diff changeset
266 break;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1612
diff changeset
267 case AUDIO_U16LSB:
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1612
diff changeset
268 if (value & AFMT_U16_LE) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1612
diff changeset
269 format = AFMT_U16_LE;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1612
diff changeset
270 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1612
diff changeset
271 break;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1612
diff changeset
272 case AUDIO_U16MSB:
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1612
diff changeset
273 if (value & AFMT_U16_BE) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1612
diff changeset
274 format = AFMT_U16_BE;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1612
diff changeset
275 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1612
diff changeset
276 break;
968
4675910b0b7b Date: Mon, 11 Oct 2004 15:17:27 +0300 (EEST)
Sam Lantinga <slouken@libsdl.org>
parents: 960
diff changeset
277 #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: 1612
diff changeset
278 default:
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1612
diff changeset
279 format = 0;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1612
diff changeset
280 break;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1612
diff changeset
281 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1612
diff changeset
282 if (!format) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1612
diff changeset
283 test_format = SDL_NextAudioFormat();
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1612
diff changeset
284 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1612
diff changeset
285 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1612
diff changeset
286 if (format == 0) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1612
diff changeset
287 SDL_SetError("Couldn't find any hardware audio formats");
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
288 DSP_CloseDevice(this);
589bc3d060cd More 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 return 0;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1612
diff changeset
290 }
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
291 this->spec.format = test_format;
968
4675910b0b7b Date: Mon, 11 Oct 2004 15:17:27 +0300 (EEST)
Sam Lantinga <slouken@libsdl.org>
parents: 960
diff changeset
292
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1612
diff changeset
293 /* Set the audio format */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1612
diff changeset
294 value = format;
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
295 if ( (ioctl(this->hidden->audio_fd, SNDCTL_DSP_SETFMT, &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
296 (value != format) ) {
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1612
diff changeset
297 perror("SNDCTL_DSP_SETFMT");
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1612
diff changeset
298 SDL_SetError("Couldn't set audio format");
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
299 DSP_CloseDevice(this);
589bc3d060cd More 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 return 0;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1612
diff changeset
301 }
968
4675910b0b7b Date: Mon, 11 Oct 2004 15:17:27 +0300 (EEST)
Sam Lantinga <slouken@libsdl.org>
parents: 960
diff changeset
302
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1612
diff changeset
303 /* Set the number of channels of 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
304 value = 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
305 if (ioctl(this->hidden->audio_fd, SNDCTL_DSP_CHANNELS, &value) < 0) {
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1612
diff changeset
306 perror("SNDCTL_DSP_CHANNELS");
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1612
diff changeset
307 SDL_SetError("Cannot set the number of channels");
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
308 DSP_CloseDevice(this);
589bc3d060cd More 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 return 0;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1612
diff changeset
310 }
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
311 this->spec.channels = value;
968
4675910b0b7b Date: Mon, 11 Oct 2004 15:17:27 +0300 (EEST)
Sam Lantinga <slouken@libsdl.org>
parents: 960
diff changeset
312
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1612
diff changeset
313 /* Set the DSP frequency */
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
314 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
315 if (ioctl(this->hidden->audio_fd, SNDCTL_DSP_SPEED, &value) < 0) {
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1612
diff changeset
316 perror("SNDCTL_DSP_SPEED");
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1612
diff changeset
317 SDL_SetError("Couldn't set audio frequency");
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
318 DSP_CloseDevice(this);
589bc3d060cd More 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 return 0;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1612
diff changeset
320 }
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
321 this->spec.freq = value;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
322
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1612
diff changeset
323 /* Calculate the final parameters for this audio specification */
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
324 SDL_CalculateAudioSpec(&this->spec);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
325
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1612
diff changeset
326 /* Determine the power of two of the fragment size */
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
327 for (frag_spec = 0; (0x01U << 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
328 if ((0x01U << frag_spec) != this->spec.size) {
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1612
diff changeset
329 SDL_SetError("Fragment size must be a power of two");
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
330 DSP_CloseDevice(this);
589bc3d060cd More 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 return 0;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1612
diff changeset
332 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1612
diff changeset
333 frag_spec |= 0x00020000; /* two fragments, for low latency */
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
334
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1612
diff changeset
335 /* Set the audio buffering parameters */
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
336 #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: 1612
diff changeset
337 fprintf(stderr, "Requesting %d fragments of size %d\n",
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1612
diff changeset
338 (frag_spec >> 16), 1 << (frag_spec & 0xFFFF));
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
339 #endif
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
340 if (ioctl(this->hidden->audio_fd, SNDCTL_DSP_SETFRAGMENT, &frag_spec) < 0) {
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1612
diff changeset
341 perror("SNDCTL_DSP_SETFRAGMENT");
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1612
diff changeset
342 }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
343 #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: 1612
diff changeset
344 {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1612
diff changeset
345 audio_buf_info info;
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
346 ioctl(this->hidden->audio_fd, SNDCTL_DSP_GETOSPACE, &info);
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1612
diff changeset
347 fprintf(stderr, "fragments = %d\n", info.fragments);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1612
diff changeset
348 fprintf(stderr, "fragstotal = %d\n", info.fragstotal);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1612
diff changeset
349 fprintf(stderr, "fragsize = %d\n", info.fragsize);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1612
diff changeset
350 fprintf(stderr, "bytes = %d\n", info.bytes);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1612
diff changeset
351 }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
352 #endif
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
353
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1612
diff changeset
354 /* Allocate mixing buffer */
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
355 this->hidden->mixlen = 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
356 this->hidden->mixbuf = (Uint8 *) SDL_AllocAudioMem(this->hidden->mixlen);
589bc3d060cd More 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 if (this->hidden->mixbuf == 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
358 DSP_CloseDevice(this);
589bc3d060cd More 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 return 0;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1612
diff changeset
360 }
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
361 SDL_memset(this->hidden->mixbuf, this->spec.silence, this->spec.size);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
362
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1612
diff changeset
363 /* We're ready to rock and roll. :-) */
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
364 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
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
589bc3d060cd More 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
589bc3d060cd More 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 static void
589bc3d060cd More 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 DSP_PlayDevice(_THIS)
589bc3d060cd More 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 {
589bc3d060cd More 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 const Uint8 *mixbuf = this->hidden->mixbuf;
589bc3d060cd More 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 const int mixlen = this->hidden->mixlen;
589bc3d060cd More 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 if (write(this->hidden->audio_fd, mixbuf, mixlen) == -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
374 perror("Audio write");
589bc3d060cd More 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 this->enabled = 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
376 }
589bc3d060cd More 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 #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
378 fprintf(stderr, "Wrote %d bytes of audio data\n", mixlen);
589bc3d060cd More 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 #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
380 }
589bc3d060cd More 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
589bc3d060cd More 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 static Uint8 *
589bc3d060cd More 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 DSP_GetDeviceBuf(_THIS)
589bc3d060cd More 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 return (this->hidden->mixbuf);
589bc3d060cd More 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 static void
589bc3d060cd More 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 DSP_CloseDevice(_THIS)
589bc3d060cd More 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 {
589bc3d060cd More 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 (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
392 if (this->hidden->mixbuf != 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
393 SDL_FreeAudioMem(this->hidden->mixbuf);
589bc3d060cd More 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 this->hidden->mixbuf = 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
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 if (this->hidden->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
397 close(this->hidden->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
398 this->hidden->audio_fd = -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
399 }
589bc3d060cd More 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 SDL_free(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
401 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
402 }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
403 }
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1612
diff changeset
404
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1612
diff changeset
405 /* vi: set ts=4 sw=4 expandtab: */