Mercurial > sdl-ios-xcode
annotate src/audio/dsp/SDL_dspaudio.c @ 4400:9134017bac3a SDL-1.2
PulseAudio: get the window title for the context name if it wasn't set already.
Will still fall back to get_progname() if it can't figure out the title.
author | Ryan C. Gordon <icculus@icculus.org> |
---|---|
date | Sun, 24 Jan 2010 20:08:14 +0000 |
parents | a1b03ba2fcd0 |
children |
rev | line source |
---|---|
0 | 1 /* |
2 SDL - Simple DirectMedia Layer | |
4159 | 3 Copyright (C) 1997-2009 Sam Lantinga |
0 | 4 |
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 | 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 | 9 |
10 This library is distributed in the hope that it will be useful, | |
11 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
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 | 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 | 18 |
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 | 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 | 26 |
27 /* Allow access to a raw mixing buffer */ | |
28 | |
1341
d02b552e5304
Configure dynamically generates SDL_config.h
Sam Lantinga <slouken@libsdl.org>
parents:
1338
diff
changeset
|
29 #include <stdio.h> /* For perror() */ |
d02b552e5304
Configure dynamically generates SDL_config.h
Sam Lantinga <slouken@libsdl.org>
parents:
1338
diff
changeset
|
30 #include <string.h> /* For strerror() */ |
0 | 31 #include <errno.h> |
32 #include <unistd.h> | |
33 #include <fcntl.h> | |
34 #include <signal.h> | |
35 #include <sys/time.h> | |
36 #include <sys/ioctl.h> | |
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 | 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 | 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 | 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 | 52 #include "SDL_dspaudio.h" |
53 | |
54 /* The tag name used by DSP audio */ | |
55 #define DSP_DRIVER_NAME "dsp" | |
56 | |
57 /* Open the audio device for playback, and don't block if busy */ | |
58 #define OPEN_FLAGS (O_WRONLY|O_NONBLOCK) | |
59 | |
60 /* Audio driver functions */ | |
61 static int DSP_OpenAudio(_THIS, SDL_AudioSpec *spec); | |
62 static void DSP_WaitAudio(_THIS); | |
63 static void DSP_PlayAudio(_THIS); | |
64 static Uint8 *DSP_GetAudioBuf(_THIS); | |
65 static void DSP_CloseAudio(_THIS); | |
66 | |
67 /* Audio driver bootstrap functions */ | |
68 | |
69 static int Audio_Available(void) | |
70 { | |
71 int fd; | |
72 int available; | |
73 | |
74 available = 0; | |
75 fd = SDL_OpenAudioPath(NULL, 0, OPEN_FLAGS, 0); | |
76 if ( fd >= 0 ) { | |
77 available = 1; | |
78 close(fd); | |
79 } | |
80 return(available); | |
81 } | |
82 | |
83 static void Audio_DeleteDevice(SDL_AudioDevice *device) | |
84 { | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
85 SDL_free(device->hidden); |
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
86 SDL_free(device); |
0 | 87 } |
88 | |
89 static SDL_AudioDevice *Audio_CreateDevice(int devindex) | |
90 { | |
91 SDL_AudioDevice *this; | |
92 | |
93 /* Initialize all variables that we clean on shutdown */ | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
94 this = (SDL_AudioDevice *)SDL_malloc(sizeof(SDL_AudioDevice)); |
0 | 95 if ( this ) { |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
96 SDL_memset(this, 0, (sizeof *this)); |
0 | 97 this->hidden = (struct SDL_PrivateAudioData *) |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
98 SDL_malloc((sizeof *this->hidden)); |
0 | 99 } |
100 if ( (this == NULL) || (this->hidden == NULL) ) { | |
101 SDL_OutOfMemory(); | |
102 if ( this ) { | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
103 SDL_free(this); |
0 | 104 } |
105 return(0); | |
106 } | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
107 SDL_memset(this->hidden, 0, (sizeof *this->hidden)); |
0 | 108 audio_fd = -1; |
109 | |
110 /* Set the function pointers */ | |
111 this->OpenAudio = DSP_OpenAudio; | |
112 this->WaitAudio = DSP_WaitAudio; | |
113 this->PlayAudio = DSP_PlayAudio; | |
114 this->GetAudioBuf = DSP_GetAudioBuf; | |
115 this->CloseAudio = DSP_CloseAudio; | |
116 | |
117 this->free = Audio_DeleteDevice; | |
118 | |
119 return this; | |
120 } | |
121 | |
122 AudioBootStrap DSP_bootstrap = { | |
123 DSP_DRIVER_NAME, "OSS /dev/dsp standard audio", | |
124 Audio_Available, Audio_CreateDevice | |
125 }; | |
126 | |
127 /* This function waits until it is possible to write a full sound buffer */ | |
128 static void DSP_WaitAudio(_THIS) | |
129 { | |
968
4675910b0b7b
Date: Mon, 11 Oct 2004 15:17:27 +0300 (EEST)
Sam Lantinga <slouken@libsdl.org>
parents:
960
diff
changeset
|
130 /* Not needed at all since OSS handles waiting automagically */ |
0 | 131 } |
132 | |
133 static void DSP_PlayAudio(_THIS) | |
134 { | |
968
4675910b0b7b
Date: Mon, 11 Oct 2004 15:17:27 +0300 (EEST)
Sam Lantinga <slouken@libsdl.org>
parents:
960
diff
changeset
|
135 if (write(audio_fd, mixbuf, mixlen)==-1) |
4675910b0b7b
Date: Mon, 11 Oct 2004 15:17:27 +0300 (EEST)
Sam Lantinga <slouken@libsdl.org>
parents:
960
diff
changeset
|
136 { |
4675910b0b7b
Date: Mon, 11 Oct 2004 15:17:27 +0300 (EEST)
Sam Lantinga <slouken@libsdl.org>
parents:
960
diff
changeset
|
137 perror("Audio write"); |
4675910b0b7b
Date: Mon, 11 Oct 2004 15:17:27 +0300 (EEST)
Sam Lantinga <slouken@libsdl.org>
parents:
960
diff
changeset
|
138 this->enabled = 0; |
0 | 139 } |
140 | |
141 #ifdef DEBUG_AUDIO | |
968
4675910b0b7b
Date: Mon, 11 Oct 2004 15:17:27 +0300 (EEST)
Sam Lantinga <slouken@libsdl.org>
parents:
960
diff
changeset
|
142 fprintf(stderr, "Wrote %d bytes of audio data\n", mixlen); |
0 | 143 #endif |
144 } | |
145 | |
146 static Uint8 *DSP_GetAudioBuf(_THIS) | |
147 { | |
148 return(mixbuf); | |
149 } | |
150 | |
151 static void DSP_CloseAudio(_THIS) | |
152 { | |
153 if ( mixbuf != NULL ) { | |
154 SDL_FreeAudioMem(mixbuf); | |
155 mixbuf = NULL; | |
156 } | |
157 if ( audio_fd >= 0 ) { | |
158 close(audio_fd); | |
159 audio_fd = -1; | |
160 } | |
161 } | |
162 | |
968
4675910b0b7b
Date: Mon, 11 Oct 2004 15:17:27 +0300 (EEST)
Sam Lantinga <slouken@libsdl.org>
parents:
960
diff
changeset
|
163 static int DSP_OpenAudio(_THIS, SDL_AudioSpec *spec) |
0 | 164 { |
968
4675910b0b7b
Date: Mon, 11 Oct 2004 15:17:27 +0300 (EEST)
Sam Lantinga <slouken@libsdl.org>
parents:
960
diff
changeset
|
165 char audiodev[1024]; |
4675910b0b7b
Date: Mon, 11 Oct 2004 15:17:27 +0300 (EEST)
Sam Lantinga <slouken@libsdl.org>
parents:
960
diff
changeset
|
166 int format; |
0 | 167 int value; |
968
4675910b0b7b
Date: Mon, 11 Oct 2004 15:17:27 +0300 (EEST)
Sam Lantinga <slouken@libsdl.org>
parents:
960
diff
changeset
|
168 int frag_spec; |
4675910b0b7b
Date: Mon, 11 Oct 2004 15:17:27 +0300 (EEST)
Sam Lantinga <slouken@libsdl.org>
parents:
960
diff
changeset
|
169 Uint16 test_format; |
0 | 170 |
3895
aeb55f698ee3
Block fruity channel values in dspaudio, or the fragment size won't be a
Ryan C. Gordon <icculus@icculus.org>
parents:
1612
diff
changeset
|
171 /* Make sure fragment size stays a power of 2, or OSS fails. */ |
aeb55f698ee3
Block fruity channel values in dspaudio, or the fragment size won't be a
Ryan C. Gordon <icculus@icculus.org>
parents:
1612
diff
changeset
|
172 /* I don't know which of these are actually legal values, though... */ |
aeb55f698ee3
Block fruity channel values in dspaudio, or the fragment size won't be a
Ryan C. Gordon <icculus@icculus.org>
parents:
1612
diff
changeset
|
173 if (spec->channels > 8) |
aeb55f698ee3
Block fruity channel values in dspaudio, or the fragment size won't be a
Ryan C. Gordon <icculus@icculus.org>
parents:
1612
diff
changeset
|
174 spec->channels = 8; |
aeb55f698ee3
Block fruity channel values in dspaudio, or the fragment size won't be a
Ryan C. Gordon <icculus@icculus.org>
parents:
1612
diff
changeset
|
175 else if (spec->channels > 4) |
aeb55f698ee3
Block fruity channel values in dspaudio, or the fragment size won't be a
Ryan C. Gordon <icculus@icculus.org>
parents:
1612
diff
changeset
|
176 spec->channels = 4; |
aeb55f698ee3
Block fruity channel values in dspaudio, or the fragment size won't be a
Ryan C. Gordon <icculus@icculus.org>
parents:
1612
diff
changeset
|
177 else if (spec->channels > 2) |
aeb55f698ee3
Block fruity channel values in dspaudio, or the fragment size won't be a
Ryan C. Gordon <icculus@icculus.org>
parents:
1612
diff
changeset
|
178 spec->channels = 2; |
aeb55f698ee3
Block fruity channel values in dspaudio, or the fragment size won't be a
Ryan C. Gordon <icculus@icculus.org>
parents:
1612
diff
changeset
|
179 |
968
4675910b0b7b
Date: Mon, 11 Oct 2004 15:17:27 +0300 (EEST)
Sam Lantinga <slouken@libsdl.org>
parents:
960
diff
changeset
|
180 /* Open the audio device */ |
4675910b0b7b
Date: Mon, 11 Oct 2004 15:17:27 +0300 (EEST)
Sam Lantinga <slouken@libsdl.org>
parents:
960
diff
changeset
|
181 audio_fd = SDL_OpenAudioPath(audiodev, sizeof(audiodev), OPEN_FLAGS, 0); |
0 | 182 if ( audio_fd < 0 ) { |
183 SDL_SetError("Couldn't open %s: %s", audiodev, strerror(errno)); | |
184 return(-1); | |
185 } | |
968
4675910b0b7b
Date: Mon, 11 Oct 2004 15:17:27 +0300 (EEST)
Sam Lantinga <slouken@libsdl.org>
parents:
960
diff
changeset
|
186 mixbuf = NULL; |
4675910b0b7b
Date: Mon, 11 Oct 2004 15:17:27 +0300 (EEST)
Sam Lantinga <slouken@libsdl.org>
parents:
960
diff
changeset
|
187 |
4675910b0b7b
Date: Mon, 11 Oct 2004 15:17:27 +0300 (EEST)
Sam Lantinga <slouken@libsdl.org>
parents:
960
diff
changeset
|
188 /* Make the file descriptor use blocking writes with fcntl() */ |
4675910b0b7b
Date: Mon, 11 Oct 2004 15:17:27 +0300 (EEST)
Sam Lantinga <slouken@libsdl.org>
parents:
960
diff
changeset
|
189 { long flags; |
4675910b0b7b
Date: Mon, 11 Oct 2004 15:17:27 +0300 (EEST)
Sam Lantinga <slouken@libsdl.org>
parents:
960
diff
changeset
|
190 flags = fcntl(audio_fd, F_GETFL); |
4675910b0b7b
Date: Mon, 11 Oct 2004 15:17:27 +0300 (EEST)
Sam Lantinga <slouken@libsdl.org>
parents:
960
diff
changeset
|
191 flags &= ~O_NONBLOCK; |
4675910b0b7b
Date: Mon, 11 Oct 2004 15:17:27 +0300 (EEST)
Sam Lantinga <slouken@libsdl.org>
parents:
960
diff
changeset
|
192 if ( fcntl(audio_fd, F_SETFL, flags) < 0 ) { |
4675910b0b7b
Date: Mon, 11 Oct 2004 15:17:27 +0300 (EEST)
Sam Lantinga <slouken@libsdl.org>
parents:
960
diff
changeset
|
193 SDL_SetError("Couldn't set audio blocking mode"); |
1037
c5dedfdb4e42
Date: Tue, 01 Feb 2005 17:53:07 -0800
Sam Lantinga <slouken@libsdl.org>
parents:
968
diff
changeset
|
194 DSP_CloseAudio(this); |
968
4675910b0b7b
Date: Mon, 11 Oct 2004 15:17:27 +0300 (EEST)
Sam Lantinga <slouken@libsdl.org>
parents:
960
diff
changeset
|
195 return(-1); |
4675910b0b7b
Date: Mon, 11 Oct 2004 15:17:27 +0300 (EEST)
Sam Lantinga <slouken@libsdl.org>
parents:
960
diff
changeset
|
196 } |
4675910b0b7b
Date: Mon, 11 Oct 2004 15:17:27 +0300 (EEST)
Sam Lantinga <slouken@libsdl.org>
parents:
960
diff
changeset
|
197 } |
4675910b0b7b
Date: Mon, 11 Oct 2004 15:17:27 +0300 (EEST)
Sam Lantinga <slouken@libsdl.org>
parents:
960
diff
changeset
|
198 |
4675910b0b7b
Date: Mon, 11 Oct 2004 15:17:27 +0300 (EEST)
Sam Lantinga <slouken@libsdl.org>
parents:
960
diff
changeset
|
199 /* Get a list of supported hardware formats */ |
4675910b0b7b
Date: Mon, 11 Oct 2004 15:17:27 +0300 (EEST)
Sam Lantinga <slouken@libsdl.org>
parents:
960
diff
changeset
|
200 if ( ioctl(audio_fd, SNDCTL_DSP_GETFMTS, &value) < 0 ) { |
4675910b0b7b
Date: Mon, 11 Oct 2004 15:17:27 +0300 (EEST)
Sam Lantinga <slouken@libsdl.org>
parents:
960
diff
changeset
|
201 perror("SNDCTL_DSP_GETFMTS"); |
4675910b0b7b
Date: Mon, 11 Oct 2004 15:17:27 +0300 (EEST)
Sam Lantinga <slouken@libsdl.org>
parents:
960
diff
changeset
|
202 SDL_SetError("Couldn't get audio format list"); |
1037
c5dedfdb4e42
Date: Tue, 01 Feb 2005 17:53:07 -0800
Sam Lantinga <slouken@libsdl.org>
parents:
968
diff
changeset
|
203 DSP_CloseAudio(this); |
968
4675910b0b7b
Date: Mon, 11 Oct 2004 15:17:27 +0300 (EEST)
Sam Lantinga <slouken@libsdl.org>
parents:
960
diff
changeset
|
204 return(-1); |
4675910b0b7b
Date: Mon, 11 Oct 2004 15:17:27 +0300 (EEST)
Sam Lantinga <slouken@libsdl.org>
parents:
960
diff
changeset
|
205 } |
4675910b0b7b
Date: Mon, 11 Oct 2004 15:17:27 +0300 (EEST)
Sam Lantinga <slouken@libsdl.org>
parents:
960
diff
changeset
|
206 |
4675910b0b7b
Date: Mon, 11 Oct 2004 15:17:27 +0300 (EEST)
Sam Lantinga <slouken@libsdl.org>
parents:
960
diff
changeset
|
207 /* Try for a closest match on audio format */ |
4675910b0b7b
Date: Mon, 11 Oct 2004 15:17:27 +0300 (EEST)
Sam Lantinga <slouken@libsdl.org>
parents:
960
diff
changeset
|
208 format = 0; |
4675910b0b7b
Date: Mon, 11 Oct 2004 15:17:27 +0300 (EEST)
Sam Lantinga <slouken@libsdl.org>
parents:
960
diff
changeset
|
209 for ( test_format = SDL_FirstAudioFormat(spec->format); |
4675910b0b7b
Date: Mon, 11 Oct 2004 15:17:27 +0300 (EEST)
Sam Lantinga <slouken@libsdl.org>
parents:
960
diff
changeset
|
210 ! format && test_format; ) { |
4675910b0b7b
Date: Mon, 11 Oct 2004 15:17:27 +0300 (EEST)
Sam Lantinga <slouken@libsdl.org>
parents:
960
diff
changeset
|
211 #ifdef DEBUG_AUDIO |
4675910b0b7b
Date: Mon, 11 Oct 2004 15:17:27 +0300 (EEST)
Sam Lantinga <slouken@libsdl.org>
parents:
960
diff
changeset
|
212 fprintf(stderr, "Trying format 0x%4.4x\n", test_format); |
4675910b0b7b
Date: Mon, 11 Oct 2004 15:17:27 +0300 (EEST)
Sam Lantinga <slouken@libsdl.org>
parents:
960
diff
changeset
|
213 #endif |
4675910b0b7b
Date: Mon, 11 Oct 2004 15:17:27 +0300 (EEST)
Sam Lantinga <slouken@libsdl.org>
parents:
960
diff
changeset
|
214 switch ( test_format ) { |
4675910b0b7b
Date: Mon, 11 Oct 2004 15:17:27 +0300 (EEST)
Sam Lantinga <slouken@libsdl.org>
parents:
960
diff
changeset
|
215 case AUDIO_U8: |
4675910b0b7b
Date: Mon, 11 Oct 2004 15:17:27 +0300 (EEST)
Sam Lantinga <slouken@libsdl.org>
parents:
960
diff
changeset
|
216 if ( value & AFMT_U8 ) { |
4675910b0b7b
Date: Mon, 11 Oct 2004 15:17:27 +0300 (EEST)
Sam Lantinga <slouken@libsdl.org>
parents:
960
diff
changeset
|
217 format = AFMT_U8; |
4675910b0b7b
Date: Mon, 11 Oct 2004 15:17:27 +0300 (EEST)
Sam Lantinga <slouken@libsdl.org>
parents:
960
diff
changeset
|
218 } |
4675910b0b7b
Date: Mon, 11 Oct 2004 15:17:27 +0300 (EEST)
Sam Lantinga <slouken@libsdl.org>
parents:
960
diff
changeset
|
219 break; |
4675910b0b7b
Date: Mon, 11 Oct 2004 15:17:27 +0300 (EEST)
Sam Lantinga <slouken@libsdl.org>
parents:
960
diff
changeset
|
220 case AUDIO_S16LSB: |
4675910b0b7b
Date: Mon, 11 Oct 2004 15:17:27 +0300 (EEST)
Sam Lantinga <slouken@libsdl.org>
parents:
960
diff
changeset
|
221 if ( value & AFMT_S16_LE ) { |
4675910b0b7b
Date: Mon, 11 Oct 2004 15:17:27 +0300 (EEST)
Sam Lantinga <slouken@libsdl.org>
parents:
960
diff
changeset
|
222 format = AFMT_S16_LE; |
4675910b0b7b
Date: Mon, 11 Oct 2004 15:17:27 +0300 (EEST)
Sam Lantinga <slouken@libsdl.org>
parents:
960
diff
changeset
|
223 } |
4675910b0b7b
Date: Mon, 11 Oct 2004 15:17:27 +0300 (EEST)
Sam Lantinga <slouken@libsdl.org>
parents:
960
diff
changeset
|
224 break; |
4675910b0b7b
Date: Mon, 11 Oct 2004 15:17:27 +0300 (EEST)
Sam Lantinga <slouken@libsdl.org>
parents:
960
diff
changeset
|
225 case AUDIO_S16MSB: |
4675910b0b7b
Date: Mon, 11 Oct 2004 15:17:27 +0300 (EEST)
Sam Lantinga <slouken@libsdl.org>
parents:
960
diff
changeset
|
226 if ( value & AFMT_S16_BE ) { |
4675910b0b7b
Date: Mon, 11 Oct 2004 15:17:27 +0300 (EEST)
Sam Lantinga <slouken@libsdl.org>
parents:
960
diff
changeset
|
227 format = AFMT_S16_BE; |
4675910b0b7b
Date: Mon, 11 Oct 2004 15:17:27 +0300 (EEST)
Sam Lantinga <slouken@libsdl.org>
parents:
960
diff
changeset
|
228 } |
4675910b0b7b
Date: Mon, 11 Oct 2004 15:17:27 +0300 (EEST)
Sam Lantinga <slouken@libsdl.org>
parents:
960
diff
changeset
|
229 break; |
4675910b0b7b
Date: Mon, 11 Oct 2004 15:17:27 +0300 (EEST)
Sam Lantinga <slouken@libsdl.org>
parents:
960
diff
changeset
|
230 #if 0 |
4675910b0b7b
Date: Mon, 11 Oct 2004 15:17:27 +0300 (EEST)
Sam Lantinga <slouken@libsdl.org>
parents:
960
diff
changeset
|
231 /* |
4675910b0b7b
Date: Mon, 11 Oct 2004 15:17:27 +0300 (EEST)
Sam Lantinga <slouken@libsdl.org>
parents:
960
diff
changeset
|
232 * 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
|
233 * needed here. |
4675910b0b7b
Date: Mon, 11 Oct 2004 15:17:27 +0300 (EEST)
Sam Lantinga <slouken@libsdl.org>
parents:
960
diff
changeset
|
234 */ |
4675910b0b7b
Date: Mon, 11 Oct 2004 15:17:27 +0300 (EEST)
Sam Lantinga <slouken@libsdl.org>
parents:
960
diff
changeset
|
235 case AUDIO_S8: |
4675910b0b7b
Date: Mon, 11 Oct 2004 15:17:27 +0300 (EEST)
Sam Lantinga <slouken@libsdl.org>
parents:
960
diff
changeset
|
236 if ( value & AFMT_S8 ) { |
4675910b0b7b
Date: Mon, 11 Oct 2004 15:17:27 +0300 (EEST)
Sam Lantinga <slouken@libsdl.org>
parents:
960
diff
changeset
|
237 format = AFMT_S8; |
4675910b0b7b
Date: Mon, 11 Oct 2004 15:17:27 +0300 (EEST)
Sam Lantinga <slouken@libsdl.org>
parents:
960
diff
changeset
|
238 } |
4675910b0b7b
Date: Mon, 11 Oct 2004 15:17:27 +0300 (EEST)
Sam Lantinga <slouken@libsdl.org>
parents:
960
diff
changeset
|
239 break; |
4675910b0b7b
Date: Mon, 11 Oct 2004 15:17:27 +0300 (EEST)
Sam Lantinga <slouken@libsdl.org>
parents:
960
diff
changeset
|
240 case AUDIO_U16LSB: |
4675910b0b7b
Date: Mon, 11 Oct 2004 15:17:27 +0300 (EEST)
Sam Lantinga <slouken@libsdl.org>
parents:
960
diff
changeset
|
241 if ( value & AFMT_U16_LE ) { |
4675910b0b7b
Date: Mon, 11 Oct 2004 15:17:27 +0300 (EEST)
Sam Lantinga <slouken@libsdl.org>
parents:
960
diff
changeset
|
242 format = AFMT_U16_LE; |
4675910b0b7b
Date: Mon, 11 Oct 2004 15:17:27 +0300 (EEST)
Sam Lantinga <slouken@libsdl.org>
parents:
960
diff
changeset
|
243 } |
4675910b0b7b
Date: Mon, 11 Oct 2004 15:17:27 +0300 (EEST)
Sam Lantinga <slouken@libsdl.org>
parents:
960
diff
changeset
|
244 break; |
4675910b0b7b
Date: Mon, 11 Oct 2004 15:17:27 +0300 (EEST)
Sam Lantinga <slouken@libsdl.org>
parents:
960
diff
changeset
|
245 case AUDIO_U16MSB: |
4675910b0b7b
Date: Mon, 11 Oct 2004 15:17:27 +0300 (EEST)
Sam Lantinga <slouken@libsdl.org>
parents:
960
diff
changeset
|
246 if ( value & AFMT_U16_BE ) { |
4675910b0b7b
Date: Mon, 11 Oct 2004 15:17:27 +0300 (EEST)
Sam Lantinga <slouken@libsdl.org>
parents:
960
diff
changeset
|
247 format = AFMT_U16_BE; |
4675910b0b7b
Date: Mon, 11 Oct 2004 15:17:27 +0300 (EEST)
Sam Lantinga <slouken@libsdl.org>
parents:
960
diff
changeset
|
248 } |
4675910b0b7b
Date: Mon, 11 Oct 2004 15:17:27 +0300 (EEST)
Sam Lantinga <slouken@libsdl.org>
parents:
960
diff
changeset
|
249 break; |
4675910b0b7b
Date: Mon, 11 Oct 2004 15:17:27 +0300 (EEST)
Sam Lantinga <slouken@libsdl.org>
parents:
960
diff
changeset
|
250 #endif |
4675910b0b7b
Date: Mon, 11 Oct 2004 15:17:27 +0300 (EEST)
Sam Lantinga <slouken@libsdl.org>
parents:
960
diff
changeset
|
251 default: |
4675910b0b7b
Date: Mon, 11 Oct 2004 15:17:27 +0300 (EEST)
Sam Lantinga <slouken@libsdl.org>
parents:
960
diff
changeset
|
252 format = 0; |
4675910b0b7b
Date: Mon, 11 Oct 2004 15:17:27 +0300 (EEST)
Sam Lantinga <slouken@libsdl.org>
parents:
960
diff
changeset
|
253 break; |
4675910b0b7b
Date: Mon, 11 Oct 2004 15:17:27 +0300 (EEST)
Sam Lantinga <slouken@libsdl.org>
parents:
960
diff
changeset
|
254 } |
4675910b0b7b
Date: Mon, 11 Oct 2004 15:17:27 +0300 (EEST)
Sam Lantinga <slouken@libsdl.org>
parents:
960
diff
changeset
|
255 if ( ! format ) { |
4675910b0b7b
Date: Mon, 11 Oct 2004 15:17:27 +0300 (EEST)
Sam Lantinga <slouken@libsdl.org>
parents:
960
diff
changeset
|
256 test_format = SDL_NextAudioFormat(); |
4675910b0b7b
Date: Mon, 11 Oct 2004 15:17:27 +0300 (EEST)
Sam Lantinga <slouken@libsdl.org>
parents:
960
diff
changeset
|
257 } |
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 if ( format == 0 ) { |
4675910b0b7b
Date: Mon, 11 Oct 2004 15:17:27 +0300 (EEST)
Sam Lantinga <slouken@libsdl.org>
parents:
960
diff
changeset
|
260 SDL_SetError("Couldn't find any hardware audio formats"); |
1037
c5dedfdb4e42
Date: Tue, 01 Feb 2005 17:53:07 -0800
Sam Lantinga <slouken@libsdl.org>
parents:
968
diff
changeset
|
261 DSP_CloseAudio(this); |
968
4675910b0b7b
Date: Mon, 11 Oct 2004 15:17:27 +0300 (EEST)
Sam Lantinga <slouken@libsdl.org>
parents:
960
diff
changeset
|
262 return(-1); |
4675910b0b7b
Date: Mon, 11 Oct 2004 15:17:27 +0300 (EEST)
Sam Lantinga <slouken@libsdl.org>
parents:
960
diff
changeset
|
263 } |
4675910b0b7b
Date: Mon, 11 Oct 2004 15:17:27 +0300 (EEST)
Sam Lantinga <slouken@libsdl.org>
parents:
960
diff
changeset
|
264 spec->format = test_format; |
4675910b0b7b
Date: Mon, 11 Oct 2004 15:17:27 +0300 (EEST)
Sam Lantinga <slouken@libsdl.org>
parents:
960
diff
changeset
|
265 |
4675910b0b7b
Date: Mon, 11 Oct 2004 15:17:27 +0300 (EEST)
Sam Lantinga <slouken@libsdl.org>
parents:
960
diff
changeset
|
266 /* Set the audio format */ |
4675910b0b7b
Date: Mon, 11 Oct 2004 15:17:27 +0300 (EEST)
Sam Lantinga <slouken@libsdl.org>
parents:
960
diff
changeset
|
267 value = format; |
4675910b0b7b
Date: Mon, 11 Oct 2004 15:17:27 +0300 (EEST)
Sam Lantinga <slouken@libsdl.org>
parents:
960
diff
changeset
|
268 if ( (ioctl(audio_fd, SNDCTL_DSP_SETFMT, &value) < 0) || |
4675910b0b7b
Date: Mon, 11 Oct 2004 15:17:27 +0300 (EEST)
Sam Lantinga <slouken@libsdl.org>
parents:
960
diff
changeset
|
269 (value != format) ) { |
4675910b0b7b
Date: Mon, 11 Oct 2004 15:17:27 +0300 (EEST)
Sam Lantinga <slouken@libsdl.org>
parents:
960
diff
changeset
|
270 perror("SNDCTL_DSP_SETFMT"); |
4675910b0b7b
Date: Mon, 11 Oct 2004 15:17:27 +0300 (EEST)
Sam Lantinga <slouken@libsdl.org>
parents:
960
diff
changeset
|
271 SDL_SetError("Couldn't set audio format"); |
1037
c5dedfdb4e42
Date: Tue, 01 Feb 2005 17:53:07 -0800
Sam Lantinga <slouken@libsdl.org>
parents:
968
diff
changeset
|
272 DSP_CloseAudio(this); |
968
4675910b0b7b
Date: Mon, 11 Oct 2004 15:17:27 +0300 (EEST)
Sam Lantinga <slouken@libsdl.org>
parents:
960
diff
changeset
|
273 return(-1); |
4675910b0b7b
Date: Mon, 11 Oct 2004 15:17:27 +0300 (EEST)
Sam Lantinga <slouken@libsdl.org>
parents:
960
diff
changeset
|
274 } |
4675910b0b7b
Date: Mon, 11 Oct 2004 15:17:27 +0300 (EEST)
Sam Lantinga <slouken@libsdl.org>
parents:
960
diff
changeset
|
275 |
4675910b0b7b
Date: Mon, 11 Oct 2004 15:17:27 +0300 (EEST)
Sam Lantinga <slouken@libsdl.org>
parents:
960
diff
changeset
|
276 /* Set the number of channels of output */ |
4675910b0b7b
Date: Mon, 11 Oct 2004 15:17:27 +0300 (EEST)
Sam Lantinga <slouken@libsdl.org>
parents:
960
diff
changeset
|
277 value = spec->channels; |
4675910b0b7b
Date: Mon, 11 Oct 2004 15:17:27 +0300 (EEST)
Sam Lantinga <slouken@libsdl.org>
parents:
960
diff
changeset
|
278 if ( ioctl(audio_fd, SNDCTL_DSP_CHANNELS, &value) < 0 ) { |
4675910b0b7b
Date: Mon, 11 Oct 2004 15:17:27 +0300 (EEST)
Sam Lantinga <slouken@libsdl.org>
parents:
960
diff
changeset
|
279 perror("SNDCTL_DSP_CHANNELS"); |
4675910b0b7b
Date: Mon, 11 Oct 2004 15:17:27 +0300 (EEST)
Sam Lantinga <slouken@libsdl.org>
parents:
960
diff
changeset
|
280 SDL_SetError("Cannot set the number of channels"); |
1037
c5dedfdb4e42
Date: Tue, 01 Feb 2005 17:53:07 -0800
Sam Lantinga <slouken@libsdl.org>
parents:
968
diff
changeset
|
281 DSP_CloseAudio(this); |
968
4675910b0b7b
Date: Mon, 11 Oct 2004 15:17:27 +0300 (EEST)
Sam Lantinga <slouken@libsdl.org>
parents:
960
diff
changeset
|
282 return(-1); |
4675910b0b7b
Date: Mon, 11 Oct 2004 15:17:27 +0300 (EEST)
Sam Lantinga <slouken@libsdl.org>
parents:
960
diff
changeset
|
283 } |
4675910b0b7b
Date: Mon, 11 Oct 2004 15:17:27 +0300 (EEST)
Sam Lantinga <slouken@libsdl.org>
parents:
960
diff
changeset
|
284 spec->channels = value; |
4675910b0b7b
Date: Mon, 11 Oct 2004 15:17:27 +0300 (EEST)
Sam Lantinga <slouken@libsdl.org>
parents:
960
diff
changeset
|
285 |
4675910b0b7b
Date: Mon, 11 Oct 2004 15:17:27 +0300 (EEST)
Sam Lantinga <slouken@libsdl.org>
parents:
960
diff
changeset
|
286 /* Set the DSP frequency */ |
4675910b0b7b
Date: Mon, 11 Oct 2004 15:17:27 +0300 (EEST)
Sam Lantinga <slouken@libsdl.org>
parents:
960
diff
changeset
|
287 value = spec->freq; |
4675910b0b7b
Date: Mon, 11 Oct 2004 15:17:27 +0300 (EEST)
Sam Lantinga <slouken@libsdl.org>
parents:
960
diff
changeset
|
288 if ( ioctl(audio_fd, SNDCTL_DSP_SPEED, &value) < 0 ) { |
4675910b0b7b
Date: Mon, 11 Oct 2004 15:17:27 +0300 (EEST)
Sam Lantinga <slouken@libsdl.org>
parents:
960
diff
changeset
|
289 perror("SNDCTL_DSP_SPEED"); |
4675910b0b7b
Date: Mon, 11 Oct 2004 15:17:27 +0300 (EEST)
Sam Lantinga <slouken@libsdl.org>
parents:
960
diff
changeset
|
290 SDL_SetError("Couldn't set audio frequency"); |
1037
c5dedfdb4e42
Date: Tue, 01 Feb 2005 17:53:07 -0800
Sam Lantinga <slouken@libsdl.org>
parents:
968
diff
changeset
|
291 DSP_CloseAudio(this); |
968
4675910b0b7b
Date: Mon, 11 Oct 2004 15:17:27 +0300 (EEST)
Sam Lantinga <slouken@libsdl.org>
parents:
960
diff
changeset
|
292 return(-1); |
4675910b0b7b
Date: Mon, 11 Oct 2004 15:17:27 +0300 (EEST)
Sam Lantinga <slouken@libsdl.org>
parents:
960
diff
changeset
|
293 } |
4675910b0b7b
Date: Mon, 11 Oct 2004 15:17:27 +0300 (EEST)
Sam Lantinga <slouken@libsdl.org>
parents:
960
diff
changeset
|
294 spec->freq = value; |
0 | 295 |
296 /* Calculate the final parameters for this audio specification */ | |
297 SDL_CalculateAudioSpec(spec); | |
298 | |
299 /* Determine the power of two of the fragment size */ | |
1612
97d0966f4bf7
Fixed some ultra-pedantic gcc warnings
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
300 for ( frag_spec = 0; (0x01U<<frag_spec) < spec->size; ++frag_spec ); |
97d0966f4bf7
Fixed some ultra-pedantic gcc warnings
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
301 if ( (0x01U<<frag_spec) != spec->size ) { |
0 | 302 SDL_SetError("Fragment size must be a power of two"); |
1037
c5dedfdb4e42
Date: Tue, 01 Feb 2005 17:53:07 -0800
Sam Lantinga <slouken@libsdl.org>
parents:
968
diff
changeset
|
303 DSP_CloseAudio(this); |
0 | 304 return(-1); |
305 } | |
306 frag_spec |= 0x00020000; /* two fragments, for low latency */ | |
307 | |
308 /* Set the audio buffering parameters */ | |
309 #ifdef DEBUG_AUDIO | |
310 fprintf(stderr, "Requesting %d fragments of size %d\n", | |
311 (frag_spec >> 16), 1<<(frag_spec&0xFFFF)); | |
312 #endif | |
313 if ( ioctl(audio_fd, SNDCTL_DSP_SETFRAGMENT, &frag_spec) < 0 ) { | |
968
4675910b0b7b
Date: Mon, 11 Oct 2004 15:17:27 +0300 (EEST)
Sam Lantinga <slouken@libsdl.org>
parents:
960
diff
changeset
|
314 perror("SNDCTL_DSP_SETFRAGMENT"); |
0 | 315 } |
316 #ifdef DEBUG_AUDIO | |
317 { audio_buf_info info; | |
318 ioctl(audio_fd, SNDCTL_DSP_GETOSPACE, &info); | |
319 fprintf(stderr, "fragments = %d\n", info.fragments); | |
320 fprintf(stderr, "fragstotal = %d\n", info.fragstotal); | |
321 fprintf(stderr, "fragsize = %d\n", info.fragsize); | |
322 fprintf(stderr, "bytes = %d\n", info.bytes); | |
323 } | |
324 #endif | |
325 | |
326 /* Allocate mixing buffer */ | |
327 mixlen = spec->size; | |
328 mixbuf = (Uint8 *)SDL_AllocAudioMem(mixlen); | |
329 if ( mixbuf == NULL ) { | |
1281
644b39bf7253
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
1037
diff
changeset
|
330 DSP_CloseAudio(this); |
0 | 331 return(-1); |
332 } | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
333 SDL_memset(mixbuf, spec->silence, spec->size); |
0 | 334 |
335 /* Get the parent process id (we're the parent of the audio thread) */ | |
336 parent = getpid(); | |
337 | |
338 /* We're ready to rock and roll. :-) */ | |
339 return(0); | |
340 } |