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