annotate src/audio/bsd/SDL_bsdaudio.c @ 1668:4da1ee79c9af SDL-1.3

more tweaking indent options
author Sam Lantinga <slouken@libsdl.org>
date Mon, 29 May 2006 04:04:35 +0000
parents 782fd950bd46
children
rev   line source
1567
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1 /*
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2 SDL - Simple DirectMedia Layer
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3 Copyright (C) 1997-2004 Sam Lantinga
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5 This library is free software; you can redistribute it and/or
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
6 modify it under the terms of the GNU Library General Public
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
7 License as published by the Free Software Foundation; either
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
8 version 2 of the License, or (at your option) any later version.
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
9
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
10 This library is distributed in the hope that it will be useful,
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
13 Library General Public License for more details.
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
14
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
15 You should have received a copy of the GNU Library General Public
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
16 License along with this library; if not, write to the Free
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
18
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
19 Sam Lantinga
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
20 slouken@libsdl.org
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
21 */
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
22 #include "SDL_config.h"
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
23
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
24 /*
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
25 * Driver for native OpenBSD/NetBSD audio(4).
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
26 * vedge@vedge.com.ar.
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
27 */
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
28
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
29 #include <errno.h>
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
30 #include <unistd.h>
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
31 #include <fcntl.h>
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
32 #include <sys/time.h>
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
33 #include <sys/ioctl.h>
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
34 #include <sys/stat.h>
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
35 #include <sys/types.h>
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
36 #include <sys/audioio.h>
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
37
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
38 #include "SDL_timer.h"
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
39 #include "SDL_audio.h"
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
40 #include "../SDL_audiomem.h"
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
41 #include "../SDL_audio_c.h"
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
42 #include "../SDL_audiodev_c.h"
1583
95451df282c3 *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 1567
diff changeset
43 #include "SDL_bsdaudio.h"
1567
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
44
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
45 /* The tag name used by NetBSD/OpenBSD audio */
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
46 #ifdef __NetBSD__
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
47 #define BSD_AUDIO_DRIVER_NAME "netbsd"
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
48 #define BSD_AUDIO_DRIVER_DESC "Native NetBSD audio"
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
49 #else
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
50 #define BSD_AUDIO_DRIVER_NAME "openbsd"
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
51 #define BSD_AUDIO_DRIVER_DESC "Native OpenBSD audio"
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
52 #endif
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
53
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
54 /* Open the audio device for playback, and don't block if busy */
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
55 /* #define USE_BLOCKING_WRITES */
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
56
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
57 /* Use timer for synchronization */
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
58 /* #define USE_TIMER_SYNC */
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
59
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
60 /* #define DEBUG_AUDIO */
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
61 /* #define DEBUG_AUDIO_STREAM */
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
62
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
63 #ifdef USE_BLOCKING_WRITES
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
64 #define OPEN_FLAGS O_WRONLY
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
65 #else
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
66 #define OPEN_FLAGS (O_WRONLY|O_NONBLOCK)
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
67 #endif
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
68
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
69 /* Audio driver functions */
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
70 static void OBSD_WaitAudio(_THIS);
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
71 static int OBSD_OpenAudio(_THIS, SDL_AudioSpec * spec);
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
72 static void OBSD_PlayAudio(_THIS);
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
73 static Uint8 *OBSD_GetAudioBuf(_THIS);
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
74 static void OBSD_CloseAudio(_THIS);
1567
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
75
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
76 #ifdef DEBUG_AUDIO
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
77 static void OBSD_Status(_THIS);
1567
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
78 #endif
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
79
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
80 /* Audio driver bootstrap functions */
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
81
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
82 static int
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
83 Audio_Available(void)
1567
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
84 {
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
85 int fd;
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
86 int available;
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
87
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
88 available = 0;
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
89 fd = SDL_OpenAudioPath(NULL, 0, OPEN_FLAGS, 0);
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
90 if (fd >= 0) {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
91 available = 1;
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
92 close(fd);
1567
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
93 }
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
94 return (available);
1567
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
95 }
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
96
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
97 static void
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
98 Audio_DeleteDevice(SDL_AudioDevice * device)
1567
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
99 {
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
100 SDL_free(device->hidden);
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
101 SDL_free(device);
1567
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
102 }
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
103
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
104 static SDL_AudioDevice *
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
105 Audio_CreateDevice(int devindex)
1567
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
106 {
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
107 SDL_AudioDevice *this;
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
108
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
109 /* Initialize all variables that we clean on shutdown */
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
110 this = (SDL_AudioDevice *) SDL_malloc(sizeof(SDL_AudioDevice));
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
111 if (this) {
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
112 SDL_memset(this, 0, (sizeof *this));
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
113 this->hidden = (struct SDL_PrivateAudioData *)
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
114 SDL_malloc((sizeof *this->hidden));
1567
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
115 }
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
116 if ((this == NULL) || (this->hidden == NULL)) {
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
117 SDL_OutOfMemory();
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
118 if (this)
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
119 SDL_free(this);
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
120 return (0);
1567
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
121 }
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
122 SDL_memset(this->hidden, 0, (sizeof *this->hidden));
1567
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
123 audio_fd = -1;
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
124
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
125 /* Set the function pointers */
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
126 this->OpenAudio = OBSD_OpenAudio;
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
127 this->WaitAudio = OBSD_WaitAudio;
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
128 this->PlayAudio = OBSD_PlayAudio;
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
129 this->GetAudioBuf = OBSD_GetAudioBuf;
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
130 this->CloseAudio = OBSD_CloseAudio;
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
131
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
132 this->free = Audio_DeleteDevice;
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
133
1567
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
134 return this;
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
135 }
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
136
1583
95451df282c3 *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 1567
diff changeset
137 AudioBootStrap BSD_AUDIO_bootstrap = {
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
138 BSD_AUDIO_DRIVER_NAME, BSD_AUDIO_DRIVER_DESC,
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
139 Audio_Available, Audio_CreateDevice
1567
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
140 };
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
141
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
142 /* This function waits until it is possible to write a full sound buffer */
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
143 static void
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
144 OBSD_WaitAudio(_THIS)
1567
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
145 {
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
146 #ifndef USE_BLOCKING_WRITES /* Not necessary when using blocking writes */
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
147 /* See if we need to use timed audio synchronization */
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
148 if (frame_ticks) {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
149 /* Use timer for general audio synchronization */
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
150 Sint32 ticks;
1567
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
151
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
152 ticks = ((Sint32) (next_frame - SDL_GetTicks())) - FUDGE_TICKS;
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
153 if (ticks > 0) {
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
154 SDL_Delay(ticks);
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
155 }
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
156 } else {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
157 /* Use select() for audio synchronization */
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
158 fd_set fdset;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
159 struct timeval timeout;
1567
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
160
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
161 FD_ZERO(&fdset);
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
162 FD_SET(audio_fd, &fdset);
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
163 timeout.tv_sec = 10;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
164 timeout.tv_usec = 0;
1567
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
165 #ifdef DEBUG_AUDIO
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
166 fprintf(stderr, "Waiting for audio to get ready\n");
1567
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
167 #endif
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
168 if (select(audio_fd + 1, NULL, &fdset, NULL, &timeout) <= 0) {
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
169 const char *message =
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
170 "Audio timeout - buggy audio driver? (disabled)";
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
171 /* In general we should never print to the screen,
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
172 but in this case we have no other way of letting
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
173 the user know what happened.
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
174 */
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
175 fprintf(stderr, "SDL: %s\n", message);
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
176 this->enabled = 0;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
177 /* Don't try to close - may hang */
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
178 audio_fd = -1;
1567
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
179 #ifdef DEBUG_AUDIO
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
180 fprintf(stderr, "Done disabling audio\n");
1567
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
181 #endif
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
182 }
1567
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
183 #ifdef DEBUG_AUDIO
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
184 fprintf(stderr, "Ready!\n");
1567
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
185 #endif
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
186 }
1567
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
187 #endif /* !USE_BLOCKING_WRITES */
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
188 }
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
189
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
190 static void
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
191 OBSD_PlayAudio(_THIS)
1567
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
192 {
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
193 int written, p = 0;
1567
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
194
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
195 /* Write the audio data, checking for EAGAIN on broken audio drivers */
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
196 do {
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
197 written = write(audio_fd, &mixbuf[p], mixlen - p);
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
198 if (written > 0)
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
199 p += written;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
200 if (written == -1 && errno != 0 && errno != EAGAIN && errno != EINTR) {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
201 /* Non recoverable error has occurred. It should be reported!!! */
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
202 perror("audio");
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
203 break;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
204 }
1567
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
205
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
206 if (p < written
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
207 || ((written < 0) && ((errno == 0) || (errno == EAGAIN)))) {
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
208 SDL_Delay(1); /* Let a little CPU time go by */
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
209 }
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
210 }
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
211 while (p < written);
1567
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
212
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
213 /* If timer synchronization is enabled, set the next write frame */
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
214 if (frame_ticks) {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
215 next_frame += frame_ticks;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
216 }
1567
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
217
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
218 /* If we couldn't write, assume fatal error for now */
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
219 if (written < 0) {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
220 this->enabled = 0;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
221 }
1567
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
222 #ifdef DEBUG_AUDIO
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
223 fprintf(stderr, "Wrote %d bytes of audio data\n", written);
1567
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
224 #endif
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
225 }
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
226
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
227 static Uint8 *
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
228 OBSD_GetAudioBuf(_THIS)
1567
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
229 {
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
230 return (mixbuf);
1567
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
231 }
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
232
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
233 static void
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
234 OBSD_CloseAudio(_THIS)
1567
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
235 {
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
236 if (mixbuf != NULL) {
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
237 SDL_FreeAudioMem(mixbuf);
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
238 mixbuf = NULL;
1567
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
239 }
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
240 if (audio_fd >= 0) {
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
241 close(audio_fd);
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
242 audio_fd = -1;
1567
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
243 }
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
244 }
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
245
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
246 #ifdef DEBUG_AUDIO
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
247 void
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
248 OBSD_Status(_THIS)
1567
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
249 {
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
250 audio_info_t info;
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
251
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
252 if (ioctl(audio_fd, AUDIO_GETINFO, &info) < 0) {
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
253 fprintf(stderr, "AUDIO_GETINFO failed.\n");
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
254 return;
1567
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
255 }
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
256
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
257 fprintf(stderr, "\n"
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
258 "[play/record info]\n"
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
259 "buffer size : %d bytes\n"
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
260 "sample rate : %i Hz\n"
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
261 "channels : %i\n"
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
262 "precision : %i-bit\n"
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
263 "encoding : 0x%x\n"
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
264 "seek : %i\n"
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
265 "sample count : %i\n"
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
266 "EOF count : %i\n"
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
267 "paused : %s\n"
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
268 "error occured : %s\n"
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
269 "waiting : %s\n"
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
270 "active : %s\n"
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
271 "",
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
272 info.
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
273 play.
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
274 buffer_size,
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
275 info.
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
276 play.
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
277 sample_rate,
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
278 info.
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
279 play.
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
280 channels,
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
281 info.
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
282 play.
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
283 precision,
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
284 info.
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
285 play.
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
286 encoding,
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
287 info.
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
288 play.
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
289 seek,
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
290 info.
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
291 play.
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
292 samples,
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
293 info.
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
294 play.
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
295 eof,
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
296 info.
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
297 play.
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
298 pause
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
299 ?
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
300 "yes"
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
301 :
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
302 "no",
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
303 info.
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
304 play.
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
305 error
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
306 ?
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
307 "yes"
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
308 :
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
309 "no",
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
310 info.
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
311 play.waiting ? "yes" : "no", info.play.active ? "yes" : "no");
1567
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
312
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
313 fprintf(stderr, "\n"
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
314 "[audio info]\n"
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
315 "monitor_gain : %i\n"
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
316 "hw block size : %d bytes\n"
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
317 "hi watermark : %i\n"
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
318 "lo watermark : %i\n"
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
319 "audio mode : %s\n"
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
320 "",
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
321 info.monitor_gain,
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
322 info.blocksize,
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
323 info.hiwat, info.lowat,
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
324 (info.mode == AUMODE_PLAY) ? "PLAY"
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
325 : (info.mode = AUMODE_RECORD) ? "RECORD"
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
326 : (info.mode == AUMODE_PLAY_ALL ? "PLAY_ALL" : "?"));
1567
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
327 }
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
328 #endif /* DEBUG_AUDIO */
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
329
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
330 static int
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
331 OBSD_OpenAudio(_THIS, SDL_AudioSpec * spec)
1567
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
332 {
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
333 char audiodev[64];
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
334 Uint16 format;
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
335 audio_info_t info;
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
336
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
337 AUDIO_INITINFO(&info);
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
338
1567
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
339 /* Calculate the final parameters for this audio specification */
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
340 SDL_CalculateAudioSpec(spec);
1567
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
341
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
342 #ifdef USE_TIMER_SYNC
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
343 frame_ticks = 0.0;
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
344 #endif
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
345
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
346 /* Open the audio device */
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
347 audio_fd = SDL_OpenAudioPath(audiodev, sizeof(audiodev), OPEN_FLAGS, 0);
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
348 if (audio_fd < 0) {
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
349 SDL_SetError("Couldn't open %s: %s", audiodev, strerror(errno));
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
350 return (-1);
1567
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
351 }
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
352
1567
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
353 /* Set to play mode */
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
354 info.mode = AUMODE_PLAY;
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
355 if (ioctl(audio_fd, AUDIO_SETINFO, &info) < 0) {
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
356 SDL_SetError("Couldn't put device into play mode");
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
357 return (-1);
1567
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
358 }
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
359
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
360 mixbuf = NULL;
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
361 AUDIO_INITINFO(&info);
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
362 for (format = SDL_FirstAudioFormat(spec->format);
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
363 format; format = SDL_NextAudioFormat()) {
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
364 switch (format) {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
365 case AUDIO_U8:
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
366 info.play.encoding = AUDIO_ENCODING_ULINEAR;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
367 info.play.precision = 8;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
368 break;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
369 case AUDIO_S8:
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
370 info.play.encoding = AUDIO_ENCODING_SLINEAR;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
371 info.play.precision = 8;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
372 break;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
373 case AUDIO_S16LSB:
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
374 info.play.encoding = AUDIO_ENCODING_SLINEAR_LE;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
375 info.play.precision = 16;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
376 break;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
377 case AUDIO_S16MSB:
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
378 info.play.encoding = AUDIO_ENCODING_SLINEAR_BE;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
379 info.play.precision = 16;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
380 break;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
381 case AUDIO_U16LSB:
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
382 info.play.encoding = AUDIO_ENCODING_ULINEAR_LE;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
383 info.play.precision = 16;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
384 break;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
385 case AUDIO_U16MSB:
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
386 info.play.encoding = AUDIO_ENCODING_ULINEAR_BE;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
387 info.play.precision = 16;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
388 break;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
389 default:
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
390 continue;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
391 }
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
392 if (ioctl(audio_fd, AUDIO_SETINFO, &info) == 0)
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
393 break;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
394 }
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
395
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
396 if (!format) {
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
397 SDL_SetError("No supported encoding for 0x%x", spec->format);
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
398 return (-1);
1567
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
399 }
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
400
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
401 spec->format = format;
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
402
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
403 AUDIO_INITINFO(&info);
1567
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
404 info.play.channels = spec->channels;
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
405 if (ioctl(audio_fd, AUDIO_SETINFO, &info) == -1)
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
406 spec->channels = 1;
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
407 AUDIO_INITINFO(&info);
1567
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
408 info.play.sample_rate = spec->freq;
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
409 info.blocksize = spec->size;
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
410 info.hiwat = 5;
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
411 info.lowat = 3;
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
412 (void) ioctl(audio_fd, AUDIO_SETINFO, &info);
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
413 (void) ioctl(audio_fd, AUDIO_GETINFO, &info);
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
414 spec->freq = info.play.sample_rate;
1567
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
415 /* Allocate mixing buffer */
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
416 mixlen = spec->size;
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
417 mixbuf = (Uint8 *) SDL_AllocAudioMem(mixlen);
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
418 if (mixbuf == NULL) {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
419 return (-1);
1567
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
420 }
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
421 SDL_memset(mixbuf, spec->silence, spec->size);
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
422
1567
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
423 /* Get the parent process id (we're the parent of the audio thread) */
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
424 parent = getpid();
1567
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
425
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
426 #ifdef DEBUG_AUDIO
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
427 OBSD_Status(this);
1567
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
428 #endif
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
429
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
430 /* We're ready to rock and roll. :-) */
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
431 return (0);
1567
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
432 }
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
433
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
434 /* vi: set ts=4 sw=4 expandtab: */