Mercurial > sdl-ios-xcode
annotate src/audio/disk/SDL_diskaudio.c @ 1338:604d73db6802
Removed uses of stdlib.h and string.h
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Tue, 07 Feb 2006 09:29:18 +0000 |
parents | 3692456e7b0f |
children | d02b552e5304 |
rev | line source |
---|---|
68
ac6645260d31
Added an audio driver that writes to disk (thanks Ryan!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
1 /* |
ac6645260d31
Added an audio driver that writes to disk (thanks Ryan!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
2 SDL - Simple DirectMedia Layer |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
3 Copyright (C) 1997-2006 Sam Lantinga |
68
ac6645260d31
Added an audio driver that writes to disk (thanks Ryan!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
4 |
ac6645260d31
Added an audio driver that writes to disk (thanks Ryan!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
5 This library is free software; you can redistribute it and/or |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
6 modify it under the terms of the GNU Lesser General Public |
68
ac6645260d31
Added an audio driver that writes to disk (thanks Ryan!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
7 License as published by the Free Software Foundation; either |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
8 version 2.1 of the License, or (at your option) any later version. |
68
ac6645260d31
Added an audio driver that writes to disk (thanks Ryan!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
9 |
ac6645260d31
Added an audio driver that writes to disk (thanks Ryan!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
10 This library is distributed in the hope that it will be useful, |
ac6645260d31
Added an audio driver that writes to disk (thanks Ryan!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
11 but WITHOUT ANY WARRANTY; without even the implied warranty of |
ac6645260d31
Added an audio driver that writes to disk (thanks Ryan!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
13 Lesser General Public License for more details. |
68
ac6645260d31
Added an audio driver that writes to disk (thanks Ryan!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
14 |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
769
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:
769
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:
769
diff
changeset
|
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
68
ac6645260d31
Added an audio driver that writes to disk (thanks Ryan!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
18 |
ac6645260d31
Added an audio driver that writes to disk (thanks Ryan!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
19 Sam Lantinga |
252
e8157fcb3114
Updated the source with the correct e-mail address
Sam Lantinga <slouken@libsdl.org>
parents:
86
diff
changeset
|
20 slouken@libsdl.org |
68
ac6645260d31
Added an audio driver that writes to disk (thanks Ryan!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
21 |
ac6645260d31
Added an audio driver that writes to disk (thanks Ryan!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
22 This file hacked^H^H^H^H^H^Hwritten by Ryan C. Gordon |
ac6645260d31
Added an audio driver that writes to disk (thanks Ryan!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
23 (icculus@linuxgames.com) |
ac6645260d31
Added an audio driver that writes to disk (thanks Ryan!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
24 */ |
ac6645260d31
Added an audio driver that writes to disk (thanks Ryan!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
25 |
ac6645260d31
Added an audio driver that writes to disk (thanks Ryan!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
26 /* Output raw audio data to a file. */ |
ac6645260d31
Added an audio driver that writes to disk (thanks Ryan!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
27 |
ac6645260d31
Added an audio driver that writes to disk (thanks Ryan!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
28 #include <stdio.h> |
ac6645260d31
Added an audio driver that writes to disk (thanks Ryan!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
29 #include <errno.h> |
ac6645260d31
Added an audio driver that writes to disk (thanks Ryan!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
30 #include <unistd.h> |
ac6645260d31
Added an audio driver that writes to disk (thanks Ryan!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
31 #include <sys/stat.h> |
ac6645260d31
Added an audio driver that writes to disk (thanks Ryan!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
32 #include <sys/types.h> |
ac6645260d31
Added an audio driver that writes to disk (thanks Ryan!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
33 #include <sys/stat.h> |
ac6645260d31
Added an audio driver that writes to disk (thanks Ryan!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
34 #include <fcntl.h> |
ac6645260d31
Added an audio driver that writes to disk (thanks Ryan!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
35 |
ac6645260d31
Added an audio driver that writes to disk (thanks Ryan!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
36 |
1338
604d73db6802
Removed uses of stdlib.h and string.h
Sam Lantinga <slouken@libsdl.org>
parents:
1336
diff
changeset
|
37 #include "SDL_stdlib.h" |
604d73db6802
Removed uses of stdlib.h and string.h
Sam Lantinga <slouken@libsdl.org>
parents:
1336
diff
changeset
|
38 #include "SDL_string.h" |
68
ac6645260d31
Added an audio driver that writes to disk (thanks Ryan!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
39 #include "SDL_audio.h" |
ac6645260d31
Added an audio driver that writes to disk (thanks Ryan!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
40 #include "SDL_error.h" |
ac6645260d31
Added an audio driver that writes to disk (thanks Ryan!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
41 #include "SDL_audiomem.h" |
ac6645260d31
Added an audio driver that writes to disk (thanks Ryan!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
42 #include "SDL_audio_c.h" |
ac6645260d31
Added an audio driver that writes to disk (thanks Ryan!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
43 #include "SDL_timer.h" |
ac6645260d31
Added an audio driver that writes to disk (thanks Ryan!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
44 #include "SDL_audiodev_c.h" |
ac6645260d31
Added an audio driver that writes to disk (thanks Ryan!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
45 #include "SDL_diskaudio.h" |
ac6645260d31
Added an audio driver that writes to disk (thanks Ryan!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
46 |
ac6645260d31
Added an audio driver that writes to disk (thanks Ryan!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
47 /* The tag name used by DISK audio */ |
ac6645260d31
Added an audio driver that writes to disk (thanks Ryan!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
48 #define DISKAUD_DRIVER_NAME "disk" |
ac6645260d31
Added an audio driver that writes to disk (thanks Ryan!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
49 |
ac6645260d31
Added an audio driver that writes to disk (thanks Ryan!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
50 /* environment variables and defaults. */ |
ac6645260d31
Added an audio driver that writes to disk (thanks Ryan!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
51 #define DISKENVR_OUTFILE "SDL_DISKAUDIOFILE" |
ac6645260d31
Added an audio driver that writes to disk (thanks Ryan!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
52 #define DISKDEFAULT_OUTFILE "sdlaudio.raw" |
ac6645260d31
Added an audio driver that writes to disk (thanks Ryan!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
53 #define DISKENVR_WRITEDELAY "SDL_DISKAUDIODELAY" |
ac6645260d31
Added an audio driver that writes to disk (thanks Ryan!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
54 #define DISKDEFAULT_WRITEDELAY 150 |
ac6645260d31
Added an audio driver that writes to disk (thanks Ryan!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
55 |
ac6645260d31
Added an audio driver that writes to disk (thanks Ryan!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
56 /* Audio driver functions */ |
ac6645260d31
Added an audio driver that writes to disk (thanks Ryan!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
57 static int DISKAUD_OpenAudio(_THIS, SDL_AudioSpec *spec); |
ac6645260d31
Added an audio driver that writes to disk (thanks Ryan!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
58 static void DISKAUD_WaitAudio(_THIS); |
ac6645260d31
Added an audio driver that writes to disk (thanks Ryan!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
59 static void DISKAUD_PlayAudio(_THIS); |
ac6645260d31
Added an audio driver that writes to disk (thanks Ryan!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
60 static Uint8 *DISKAUD_GetAudioBuf(_THIS); |
ac6645260d31
Added an audio driver that writes to disk (thanks Ryan!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
61 static void DISKAUD_CloseAudio(_THIS); |
ac6645260d31
Added an audio driver that writes to disk (thanks Ryan!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
62 |
ac6645260d31
Added an audio driver that writes to disk (thanks Ryan!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
63 static const char *DISKAUD_GetOutputFilename(void) |
ac6645260d31
Added an audio driver that writes to disk (thanks Ryan!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
64 { |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
65 const char *envr = SDL_getenv(DISKENVR_OUTFILE); |
68
ac6645260d31
Added an audio driver that writes to disk (thanks Ryan!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
66 return((envr != NULL) ? envr : DISKDEFAULT_OUTFILE); |
ac6645260d31
Added an audio driver that writes to disk (thanks Ryan!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
67 } |
ac6645260d31
Added an audio driver that writes to disk (thanks Ryan!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
68 |
ac6645260d31
Added an audio driver that writes to disk (thanks Ryan!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
69 /* Audio driver bootstrap functions */ |
ac6645260d31
Added an audio driver that writes to disk (thanks Ryan!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
70 static int DISKAUD_Available(void) |
ac6645260d31
Added an audio driver that writes to disk (thanks Ryan!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
71 { |
ac6645260d31
Added an audio driver that writes to disk (thanks Ryan!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
72 #if 0 |
ac6645260d31
Added an audio driver that writes to disk (thanks Ryan!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
73 int fd; |
ac6645260d31
Added an audio driver that writes to disk (thanks Ryan!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
74 int available; |
ac6645260d31
Added an audio driver that writes to disk (thanks Ryan!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
75 int exists = 0; |
ac6645260d31
Added an audio driver that writes to disk (thanks Ryan!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
76 struct stat statbuf; |
ac6645260d31
Added an audio driver that writes to disk (thanks Ryan!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
77 const char *fname = DISKAUD_GetOutputFilename(); |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
78 const char *envr = SDL_getenv("SDL_AUDIODRIVER"); |
68
ac6645260d31
Added an audio driver that writes to disk (thanks Ryan!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
79 available = 0; |
ac6645260d31
Added an audio driver that writes to disk (thanks Ryan!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
80 |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
81 if ((envr) && (SDL_strcmp(envr, DISKAUD_DRIVER_NAME) == 0)) { |
86
13e4c612098d
Dummy audio and video drivers are enabled (thanks Ryan!)
Sam Lantinga <slouken@lokigames.com>
parents:
68
diff
changeset
|
82 if (stat(fname, &statbuf) == 0) |
13e4c612098d
Dummy audio and video drivers are enabled (thanks Ryan!)
Sam Lantinga <slouken@lokigames.com>
parents:
68
diff
changeset
|
83 exists = 1; |
68
ac6645260d31
Added an audio driver that writes to disk (thanks Ryan!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
84 |
86
13e4c612098d
Dummy audio and video drivers are enabled (thanks Ryan!)
Sam Lantinga <slouken@lokigames.com>
parents:
68
diff
changeset
|
85 fd = open(fname, O_WRONLY | O_CREAT | O_APPEND, S_IRUSR | S_IWUSR); |
13e4c612098d
Dummy audio and video drivers are enabled (thanks Ryan!)
Sam Lantinga <slouken@lokigames.com>
parents:
68
diff
changeset
|
86 if ( fd != -1 ) { |
13e4c612098d
Dummy audio and video drivers are enabled (thanks Ryan!)
Sam Lantinga <slouken@lokigames.com>
parents:
68
diff
changeset
|
87 available = 1; |
13e4c612098d
Dummy audio and video drivers are enabled (thanks Ryan!)
Sam Lantinga <slouken@lokigames.com>
parents:
68
diff
changeset
|
88 close(fd); |
13e4c612098d
Dummy audio and video drivers are enabled (thanks Ryan!)
Sam Lantinga <slouken@lokigames.com>
parents:
68
diff
changeset
|
89 if (!exists) { |
13e4c612098d
Dummy audio and video drivers are enabled (thanks Ryan!)
Sam Lantinga <slouken@lokigames.com>
parents:
68
diff
changeset
|
90 unlink(fname); |
13e4c612098d
Dummy audio and video drivers are enabled (thanks Ryan!)
Sam Lantinga <slouken@lokigames.com>
parents:
68
diff
changeset
|
91 } |
13e4c612098d
Dummy audio and video drivers are enabled (thanks Ryan!)
Sam Lantinga <slouken@lokigames.com>
parents:
68
diff
changeset
|
92 } |
68
ac6645260d31
Added an audio driver that writes to disk (thanks Ryan!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
93 } |
ac6645260d31
Added an audio driver that writes to disk (thanks Ryan!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
94 return(available); |
ac6645260d31
Added an audio driver that writes to disk (thanks Ryan!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
95 #else |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
96 const char *envr = SDL_getenv("SDL_AUDIODRIVER"); |
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
97 if ((envr) && (SDL_strcmp(envr, DISKAUD_DRIVER_NAME) == 0)) { |
86
13e4c612098d
Dummy audio and video drivers are enabled (thanks Ryan!)
Sam Lantinga <slouken@lokigames.com>
parents:
68
diff
changeset
|
98 return(1); |
13e4c612098d
Dummy audio and video drivers are enabled (thanks Ryan!)
Sam Lantinga <slouken@lokigames.com>
parents:
68
diff
changeset
|
99 } |
13e4c612098d
Dummy audio and video drivers are enabled (thanks Ryan!)
Sam Lantinga <slouken@lokigames.com>
parents:
68
diff
changeset
|
100 |
13e4c612098d
Dummy audio and video drivers are enabled (thanks Ryan!)
Sam Lantinga <slouken@lokigames.com>
parents:
68
diff
changeset
|
101 return(0); |
68
ac6645260d31
Added an audio driver that writes to disk (thanks Ryan!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
102 #endif |
ac6645260d31
Added an audio driver that writes to disk (thanks Ryan!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
103 } |
ac6645260d31
Added an audio driver that writes to disk (thanks Ryan!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
104 |
ac6645260d31
Added an audio driver that writes to disk (thanks Ryan!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
105 static void DISKAUD_DeleteDevice(SDL_AudioDevice *device) |
ac6645260d31
Added an audio driver that writes to disk (thanks Ryan!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
106 { |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
107 SDL_free(device->hidden); |
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
108 SDL_free(device); |
68
ac6645260d31
Added an audio driver that writes to disk (thanks Ryan!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
109 } |
ac6645260d31
Added an audio driver that writes to disk (thanks Ryan!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
110 |
ac6645260d31
Added an audio driver that writes to disk (thanks Ryan!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
111 static SDL_AudioDevice *DISKAUD_CreateDevice(int devindex) |
ac6645260d31
Added an audio driver that writes to disk (thanks Ryan!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
112 { |
ac6645260d31
Added an audio driver that writes to disk (thanks Ryan!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
113 SDL_AudioDevice *this; |
ac6645260d31
Added an audio driver that writes to disk (thanks Ryan!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
114 const char *envr; |
ac6645260d31
Added an audio driver that writes to disk (thanks Ryan!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
115 |
ac6645260d31
Added an audio driver that writes to disk (thanks Ryan!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
116 /* 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
|
117 this = (SDL_AudioDevice *)SDL_malloc(sizeof(SDL_AudioDevice)); |
68
ac6645260d31
Added an audio driver that writes to disk (thanks Ryan!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
118 if ( this ) { |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
119 SDL_memset(this, 0, (sizeof *this)); |
68
ac6645260d31
Added an audio driver that writes to disk (thanks Ryan!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
120 this->hidden = (struct SDL_PrivateAudioData *) |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
121 SDL_malloc((sizeof *this->hidden)); |
68
ac6645260d31
Added an audio driver that writes to disk (thanks Ryan!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
122 } |
ac6645260d31
Added an audio driver that writes to disk (thanks Ryan!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
123 if ( (this == NULL) || (this->hidden == NULL) ) { |
ac6645260d31
Added an audio driver that writes to disk (thanks Ryan!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
124 SDL_OutOfMemory(); |
ac6645260d31
Added an audio driver that writes to disk (thanks Ryan!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
125 if ( this ) { |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
126 SDL_free(this); |
68
ac6645260d31
Added an audio driver that writes to disk (thanks Ryan!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
127 } |
ac6645260d31
Added an audio driver that writes to disk (thanks Ryan!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
128 return(0); |
ac6645260d31
Added an audio driver that writes to disk (thanks Ryan!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
129 } |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
130 SDL_memset(this->hidden, 0, (sizeof *this->hidden)); |
68
ac6645260d31
Added an audio driver that writes to disk (thanks Ryan!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
131 |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
132 envr = SDL_getenv(DISKENVR_WRITEDELAY); |
68
ac6645260d31
Added an audio driver that writes to disk (thanks Ryan!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
133 this->hidden->write_delay = (envr) ? atoi(envr) : DISKDEFAULT_WRITEDELAY; |
ac6645260d31
Added an audio driver that writes to disk (thanks Ryan!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
134 |
ac6645260d31
Added an audio driver that writes to disk (thanks Ryan!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
135 /* Set the function pointers */ |
ac6645260d31
Added an audio driver that writes to disk (thanks Ryan!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
136 this->OpenAudio = DISKAUD_OpenAudio; |
ac6645260d31
Added an audio driver that writes to disk (thanks Ryan!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
137 this->WaitAudio = DISKAUD_WaitAudio; |
ac6645260d31
Added an audio driver that writes to disk (thanks Ryan!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
138 this->PlayAudio = DISKAUD_PlayAudio; |
ac6645260d31
Added an audio driver that writes to disk (thanks Ryan!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
139 this->GetAudioBuf = DISKAUD_GetAudioBuf; |
ac6645260d31
Added an audio driver that writes to disk (thanks Ryan!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
140 this->CloseAudio = DISKAUD_CloseAudio; |
ac6645260d31
Added an audio driver that writes to disk (thanks Ryan!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
141 |
ac6645260d31
Added an audio driver that writes to disk (thanks Ryan!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
142 this->free = DISKAUD_DeleteDevice; |
ac6645260d31
Added an audio driver that writes to disk (thanks Ryan!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
143 |
ac6645260d31
Added an audio driver that writes to disk (thanks Ryan!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
144 return this; |
ac6645260d31
Added an audio driver that writes to disk (thanks Ryan!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
145 } |
ac6645260d31
Added an audio driver that writes to disk (thanks Ryan!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
146 |
ac6645260d31
Added an audio driver that writes to disk (thanks Ryan!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
147 AudioBootStrap DISKAUD_bootstrap = { |
ac6645260d31
Added an audio driver that writes to disk (thanks Ryan!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
148 DISKAUD_DRIVER_NAME, "direct-to-disk audio", |
ac6645260d31
Added an audio driver that writes to disk (thanks Ryan!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
149 DISKAUD_Available, DISKAUD_CreateDevice |
ac6645260d31
Added an audio driver that writes to disk (thanks Ryan!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
150 }; |
ac6645260d31
Added an audio driver that writes to disk (thanks Ryan!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
151 |
ac6645260d31
Added an audio driver that writes to disk (thanks Ryan!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
152 /* This function waits until it is possible to write a full sound buffer */ |
ac6645260d31
Added an audio driver that writes to disk (thanks Ryan!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
153 static void DISKAUD_WaitAudio(_THIS) |
ac6645260d31
Added an audio driver that writes to disk (thanks Ryan!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
154 { |
ac6645260d31
Added an audio driver that writes to disk (thanks Ryan!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
155 SDL_Delay(this->hidden->write_delay); |
ac6645260d31
Added an audio driver that writes to disk (thanks Ryan!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
156 } |
ac6645260d31
Added an audio driver that writes to disk (thanks Ryan!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
157 |
ac6645260d31
Added an audio driver that writes to disk (thanks Ryan!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
158 static void DISKAUD_PlayAudio(_THIS) |
ac6645260d31
Added an audio driver that writes to disk (thanks Ryan!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
159 { |
ac6645260d31
Added an audio driver that writes to disk (thanks Ryan!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
160 int written; |
ac6645260d31
Added an audio driver that writes to disk (thanks Ryan!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
161 |
ac6645260d31
Added an audio driver that writes to disk (thanks Ryan!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
162 /* Write the audio data, checking for EAGAIN on broken audio drivers */ |
ac6645260d31
Added an audio driver that writes to disk (thanks Ryan!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
163 do { |
ac6645260d31
Added an audio driver that writes to disk (thanks Ryan!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
164 written = write(this->hidden->audio_fd, |
ac6645260d31
Added an audio driver that writes to disk (thanks Ryan!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
165 this->hidden->mixbuf, |
ac6645260d31
Added an audio driver that writes to disk (thanks Ryan!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
166 this->hidden->mixlen); |
ac6645260d31
Added an audio driver that writes to disk (thanks Ryan!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
167 if ( (written < 0) && ((errno == 0) || (errno == EAGAIN)) ) { |
ac6645260d31
Added an audio driver that writes to disk (thanks Ryan!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
168 SDL_Delay(1); /* Let a little CPU time go by */ |
ac6645260d31
Added an audio driver that writes to disk (thanks Ryan!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
169 } |
ac6645260d31
Added an audio driver that writes to disk (thanks Ryan!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
170 } while ( (written < 0) && |
ac6645260d31
Added an audio driver that writes to disk (thanks Ryan!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
171 ((errno == 0) || (errno == EAGAIN) || (errno == EINTR)) ); |
ac6645260d31
Added an audio driver that writes to disk (thanks Ryan!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
172 |
ac6645260d31
Added an audio driver that writes to disk (thanks Ryan!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
173 /* If we couldn't write, assume fatal error for now */ |
ac6645260d31
Added an audio driver that writes to disk (thanks Ryan!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
174 if ( written < 0 ) { |
ac6645260d31
Added an audio driver that writes to disk (thanks Ryan!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
175 this->enabled = 0; |
ac6645260d31
Added an audio driver that writes to disk (thanks Ryan!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
176 } |
ac6645260d31
Added an audio driver that writes to disk (thanks Ryan!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
177 #ifdef DEBUG_AUDIO |
ac6645260d31
Added an audio driver that writes to disk (thanks Ryan!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
178 fprintf(stderr, "Wrote %d bytes of audio data\n", written); |
ac6645260d31
Added an audio driver that writes to disk (thanks Ryan!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
179 #endif |
ac6645260d31
Added an audio driver that writes to disk (thanks Ryan!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
180 } |
ac6645260d31
Added an audio driver that writes to disk (thanks Ryan!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
181 |
ac6645260d31
Added an audio driver that writes to disk (thanks Ryan!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
182 static Uint8 *DISKAUD_GetAudioBuf(_THIS) |
ac6645260d31
Added an audio driver that writes to disk (thanks Ryan!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
183 { |
ac6645260d31
Added an audio driver that writes to disk (thanks Ryan!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
184 return(this->hidden->mixbuf); |
ac6645260d31
Added an audio driver that writes to disk (thanks Ryan!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
185 } |
ac6645260d31
Added an audio driver that writes to disk (thanks Ryan!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
186 |
ac6645260d31
Added an audio driver that writes to disk (thanks Ryan!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
187 static void DISKAUD_CloseAudio(_THIS) |
ac6645260d31
Added an audio driver that writes to disk (thanks Ryan!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
188 { |
ac6645260d31
Added an audio driver that writes to disk (thanks Ryan!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
189 if ( this->hidden->mixbuf != NULL ) { |
ac6645260d31
Added an audio driver that writes to disk (thanks Ryan!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
190 SDL_FreeAudioMem(this->hidden->mixbuf); |
ac6645260d31
Added an audio driver that writes to disk (thanks Ryan!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
191 this->hidden->mixbuf = NULL; |
ac6645260d31
Added an audio driver that writes to disk (thanks Ryan!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
192 } |
ac6645260d31
Added an audio driver that writes to disk (thanks Ryan!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
193 if ( this->hidden->audio_fd >= 0 ) { |
ac6645260d31
Added an audio driver that writes to disk (thanks Ryan!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
194 close(this->hidden->audio_fd); |
ac6645260d31
Added an audio driver that writes to disk (thanks Ryan!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
195 this->hidden->audio_fd = -1; |
ac6645260d31
Added an audio driver that writes to disk (thanks Ryan!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
196 } |
ac6645260d31
Added an audio driver that writes to disk (thanks Ryan!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
197 } |
ac6645260d31
Added an audio driver that writes to disk (thanks Ryan!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
198 |
ac6645260d31
Added an audio driver that writes to disk (thanks Ryan!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
199 static int DISKAUD_OpenAudio(_THIS, SDL_AudioSpec *spec) |
ac6645260d31
Added an audio driver that writes to disk (thanks Ryan!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
200 { |
ac6645260d31
Added an audio driver that writes to disk (thanks Ryan!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
201 const char *fname = DISKAUD_GetOutputFilename(); |
ac6645260d31
Added an audio driver that writes to disk (thanks Ryan!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
202 |
ac6645260d31
Added an audio driver that writes to disk (thanks Ryan!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
203 /* Open the audio device */ |
ac6645260d31
Added an audio driver that writes to disk (thanks Ryan!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
204 this->hidden->audio_fd = open(fname, O_WRONLY | O_CREAT, S_IRUSR | S_IWUSR); |
ac6645260d31
Added an audio driver that writes to disk (thanks Ryan!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
205 if ( this->hidden->audio_fd < 0 ) { |
ac6645260d31
Added an audio driver that writes to disk (thanks Ryan!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
206 SDL_SetError("Couldn't open %s: %s", fname, strerror(errno)); |
ac6645260d31
Added an audio driver that writes to disk (thanks Ryan!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
207 return(-1); |
ac6645260d31
Added an audio driver that writes to disk (thanks Ryan!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
208 } |
ac6645260d31
Added an audio driver that writes to disk (thanks Ryan!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
209 |
ac6645260d31
Added an audio driver that writes to disk (thanks Ryan!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
210 fprintf(stderr, "WARNING: You are using the SDL disk writer" |
ac6645260d31
Added an audio driver that writes to disk (thanks Ryan!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
211 " audio driver!\n Writing to file [%s].\n", fname); |
ac6645260d31
Added an audio driver that writes to disk (thanks Ryan!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
212 |
ac6645260d31
Added an audio driver that writes to disk (thanks Ryan!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
213 /* Allocate mixing buffer */ |
ac6645260d31
Added an audio driver that writes to disk (thanks Ryan!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
214 this->hidden->mixlen = spec->size; |
ac6645260d31
Added an audio driver that writes to disk (thanks Ryan!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
215 this->hidden->mixbuf = (Uint8 *) SDL_AllocAudioMem(this->hidden->mixlen); |
ac6645260d31
Added an audio driver that writes to disk (thanks Ryan!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
216 if ( this->hidden->mixbuf == NULL ) { |
ac6645260d31
Added an audio driver that writes to disk (thanks Ryan!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
217 return(-1); |
ac6645260d31
Added an audio driver that writes to disk (thanks Ryan!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
218 } |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
219 SDL_memset(this->hidden->mixbuf, spec->silence, spec->size); |
68
ac6645260d31
Added an audio driver that writes to disk (thanks Ryan!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
220 |
ac6645260d31
Added an audio driver that writes to disk (thanks Ryan!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
221 /* We're ready to rock and roll. :-) */ |
ac6645260d31
Added an audio driver that writes to disk (thanks Ryan!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
222 return(0); |
ac6645260d31
Added an audio driver that writes to disk (thanks Ryan!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
223 } |
ac6645260d31
Added an audio driver that writes to disk (thanks Ryan!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
224 |