annotate src/audio/disk/SDL_diskaudio.c @ 3809:7852b5b78af5 SDL-ryan-multiple-audio-device

Cleaning out SDL_audiodev.c and related references ...
author Ryan C. Gordon <icculus@icculus.org>
date Thu, 05 Oct 2006 01:13:47 +0000
parents ef7f7be318da
children 9d070c1a45fa
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
1594
c439dad53df8 Updated my email address.
Ryan C. Gordon <icculus@icculus.org>
parents: 1539
diff changeset
22 This file written by Ryan C. Gordon (icculus@icculus.org)
68
ac6645260d31 Added an audio driver that writes to disk (thanks Ryan!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
23 */
1402
d910939febfa Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents: 1361
diff changeset
24 #include "SDL_config.h"
68
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
1465
8dfa9a6d69a5 Updated WinCE support by Dmitry (with some tweaks)
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
28 #if HAVE_STDIO_H
68
ac6645260d31 Added an audio driver that writes to disk (thanks Ryan!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
29 #include <stdio.h>
1465
8dfa9a6d69a5 Updated WinCE support by Dmitry (with some tweaks)
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
30 #endif
68
ac6645260d31 Added an audio driver that writes to disk (thanks Ryan!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
31
1465
8dfa9a6d69a5 Updated WinCE support by Dmitry (with some tweaks)
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
32 #include "SDL_rwops.h"
1358
c71e05b4dc2e More header massaging... works great on Windows. ;-)
Sam Lantinga <slouken@libsdl.org>
parents: 1341
diff changeset
33 #include "SDL_timer.h"
68
ac6645260d31 Added an audio driver that writes to disk (thanks Ryan!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
34 #include "SDL_audio.h"
1361
19418e4422cb New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents: 1358
diff changeset
35 #include "../SDL_audiomem.h"
19418e4422cb New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents: 1358
diff changeset
36 #include "../SDL_audio_c.h"
68
ac6645260d31 Added an audio driver that writes to disk (thanks Ryan!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
37 #include "SDL_diskaudio.h"
ac6645260d31 Added an audio driver that writes to disk (thanks Ryan!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
38
ac6645260d31 Added an audio driver that writes to disk (thanks Ryan!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
39 /* 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
40 #define DISKAUD_DRIVER_NAME "disk"
ac6645260d31 Added an audio driver that writes to disk (thanks Ryan!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
41
ac6645260d31 Added an audio driver that writes to disk (thanks Ryan!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
42 /* environment variables and defaults. */
ac6645260d31 Added an audio driver that writes to disk (thanks Ryan!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
43 #define DISKENVR_OUTFILE "SDL_DISKAUDIOFILE"
ac6645260d31 Added an audio driver that writes to disk (thanks Ryan!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
44 #define DISKDEFAULT_OUTFILE "sdlaudio.raw"
ac6645260d31 Added an audio driver that writes to disk (thanks Ryan!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
45 #define DISKENVR_WRITEDELAY "SDL_DISKAUDIODELAY"
ac6645260d31 Added an audio driver that writes to disk (thanks Ryan!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
46 #define DISKDEFAULT_WRITEDELAY 150
ac6645260d31 Added an audio driver that writes to disk (thanks Ryan!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
47
ac6645260d31 Added an audio driver that writes to disk (thanks Ryan!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
48 /* Audio driver functions */
3792
866c310e2cb5 Changed some 1.3 audio symbol names.
Ryan C. Gordon <icculus@icculus.org>
parents: 3784
diff changeset
49 static int DISKAUD_OpenDevice(_THIS, const char *devname, int iscapture);
866c310e2cb5 Changed some 1.3 audio symbol names.
Ryan C. Gordon <icculus@icculus.org>
parents: 3784
diff changeset
50 static void DISKAUD_WaitDevice(_THIS);
866c310e2cb5 Changed some 1.3 audio symbol names.
Ryan C. Gordon <icculus@icculus.org>
parents: 3784
diff changeset
51 static void DISKAUD_PlayDevice(_THIS);
866c310e2cb5 Changed some 1.3 audio symbol names.
Ryan C. Gordon <icculus@icculus.org>
parents: 3784
diff changeset
52 static Uint8 *DISKAUD_GetDeviceBuf(_THIS);
866c310e2cb5 Changed some 1.3 audio symbol names.
Ryan C. Gordon <icculus@icculus.org>
parents: 3784
diff changeset
53 static void DISKAUD_CloseDevice(_THIS);
68
ac6645260d31 Added an audio driver that writes to disk (thanks Ryan!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
54
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1594
diff changeset
55 static const char *
3805
ef7f7be318da Disk audio can now use device name for target filename.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
56 DISKAUD_GetOutputFilename(const char *devname)
68
ac6645260d31 Added an audio driver that writes to disk (thanks Ryan!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
57 {
3805
ef7f7be318da Disk audio can now use device name for target filename.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
58 if (devname == NULL) {
ef7f7be318da Disk audio can now use device name for target filename.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
59 devname = SDL_getenv(DISKENVR_OUTFILE);
ef7f7be318da Disk audio can now use device name for target filename.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
60 if (devname == NULL) {
ef7f7be318da Disk audio can now use device name for target filename.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
61 devname = DISKDEFAULT_OUTFILE;
ef7f7be318da Disk audio can now use device name for target filename.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
62 }
ef7f7be318da Disk audio can now use device name for target filename.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
63 }
ef7f7be318da Disk audio can now use device name for target filename.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
64 return devname;
68
ac6645260d31 Added an audio driver that writes to disk (thanks Ryan!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
65 }
ac6645260d31 Added an audio driver that writes to disk (thanks Ryan!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
66
ac6645260d31 Added an audio driver that writes to disk (thanks Ryan!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
67 /* Audio driver bootstrap functions */
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1594
diff changeset
68 static int
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1594
diff changeset
69 DISKAUD_Available(void)
68
ac6645260d31 Added an audio driver that writes to disk (thanks Ryan!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
70 {
3798
c8b3d3d13ed1 Audio bootstraps can now specify that a driver is only to be used if
Ryan C. Gordon <icculus@icculus.org>
parents: 3792
diff changeset
71 return 1; /* always available. */
68
ac6645260d31 Added an audio driver that writes to disk (thanks Ryan!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
72 }
ac6645260d31 Added an audio driver that writes to disk (thanks Ryan!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
73
3784
37c9c4590689 First batch of heavy lifting on supporting multiple audio devices at once.
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
74 static int
37c9c4590689 First batch of heavy lifting on supporting multiple audio devices at once.
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
75 DISKAUD_Init(SDL_AudioDriverImpl *impl)
68
ac6645260d31 Added an audio driver that writes to disk (thanks Ryan!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
76 {
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1594
diff changeset
77 /* Initialize all variables that we clean on shutdown */
3784
37c9c4590689 First batch of heavy lifting on supporting multiple audio devices at once.
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
78 SDL_memset(impl, '\0', sizeof (SDL_AudioDriverImpl));
68
ac6645260d31 Added an audio driver that writes to disk (thanks Ryan!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
79
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1594
diff changeset
80 /* Set the function pointers */
3792
866c310e2cb5 Changed some 1.3 audio symbol names.
Ryan C. Gordon <icculus@icculus.org>
parents: 3784
diff changeset
81 impl->OpenDevice = DISKAUD_OpenDevice;
866c310e2cb5 Changed some 1.3 audio symbol names.
Ryan C. Gordon <icculus@icculus.org>
parents: 3784
diff changeset
82 impl->WaitDevice = DISKAUD_WaitDevice;
866c310e2cb5 Changed some 1.3 audio symbol names.
Ryan C. Gordon <icculus@icculus.org>
parents: 3784
diff changeset
83 impl->PlayDevice = DISKAUD_PlayDevice;
866c310e2cb5 Changed some 1.3 audio symbol names.
Ryan C. Gordon <icculus@icculus.org>
parents: 3784
diff changeset
84 impl->GetDeviceBuf = DISKAUD_GetDeviceBuf;
866c310e2cb5 Changed some 1.3 audio symbol names.
Ryan C. Gordon <icculus@icculus.org>
parents: 3784
diff changeset
85 impl->CloseDevice = DISKAUD_CloseDevice;
68
ac6645260d31 Added an audio driver that writes to disk (thanks Ryan!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
86
3784
37c9c4590689 First batch of heavy lifting on supporting multiple audio devices at once.
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
87 return 1;
68
ac6645260d31 Added an audio driver that writes to disk (thanks Ryan!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
88 }
ac6645260d31 Added an audio driver that writes to disk (thanks Ryan!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
89
ac6645260d31 Added an audio driver that writes to disk (thanks Ryan!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
90 AudioBootStrap DISKAUD_bootstrap = {
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1594
diff changeset
91 DISKAUD_DRIVER_NAME, "direct-to-disk audio",
3798
c8b3d3d13ed1 Audio bootstraps can now specify that a driver is only to be used if
Ryan C. Gordon <icculus@icculus.org>
parents: 3792
diff changeset
92 DISKAUD_Available, DISKAUD_Init, 1
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
ac6645260d31 Added an audio driver that writes to disk (thanks Ryan!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
95 /* This function waits until it is possible to write a full sound buffer */
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1594
diff changeset
96 static void
3792
866c310e2cb5 Changed some 1.3 audio symbol names.
Ryan C. Gordon <icculus@icculus.org>
parents: 3784
diff changeset
97 DISKAUD_WaitDevice(_THIS)
68
ac6645260d31 Added an audio driver that writes to disk (thanks Ryan!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
98 {
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1594
diff changeset
99 SDL_Delay(this->hidden->write_delay);
68
ac6645260d31 Added an audio driver that writes to disk (thanks Ryan!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
100 }
ac6645260d31 Added an audio driver that writes to disk (thanks Ryan!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
101
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1594
diff changeset
102 static void
3792
866c310e2cb5 Changed some 1.3 audio symbol names.
Ryan C. Gordon <icculus@icculus.org>
parents: 3784
diff changeset
103 DISKAUD_PlayDevice(_THIS)
68
ac6645260d31 Added an audio driver that writes to disk (thanks Ryan!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
104 {
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1594
diff changeset
105 int written;
68
ac6645260d31 Added an audio driver that writes to disk (thanks Ryan!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
106
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1594
diff changeset
107 /* Write the audio data */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1594
diff changeset
108 written = SDL_RWwrite(this->hidden->output,
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1594
diff changeset
109 this->hidden->mixbuf, 1, this->hidden->mixlen);
68
ac6645260d31 Added an audio driver that writes to disk (thanks Ryan!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
110
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1594
diff changeset
111 /* If we couldn't write, assume fatal error for now */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1594
diff changeset
112 if ((Uint32) written != this->hidden->mixlen) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1594
diff changeset
113 this->enabled = 0;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1594
diff changeset
114 }
68
ac6645260d31 Added an audio driver that writes to disk (thanks Ryan!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
115 #ifdef DEBUG_AUDIO
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1594
diff changeset
116 fprintf(stderr, "Wrote %d bytes of audio data\n", written);
68
ac6645260d31 Added an audio driver that writes to disk (thanks Ryan!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
117 #endif
ac6645260d31 Added an audio driver that writes to disk (thanks Ryan!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
118 }
ac6645260d31 Added an audio driver that writes to disk (thanks Ryan!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
119
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1594
diff changeset
120 static Uint8 *
3792
866c310e2cb5 Changed some 1.3 audio symbol names.
Ryan C. Gordon <icculus@icculus.org>
parents: 3784
diff changeset
121 DISKAUD_GetDeviceBuf(_THIS)
68
ac6645260d31 Added an audio driver that writes to disk (thanks Ryan!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
122 {
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1594
diff changeset
123 return (this->hidden->mixbuf);
68
ac6645260d31 Added an audio driver that writes to disk (thanks Ryan!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
124 }
ac6645260d31 Added an audio driver that writes to disk (thanks Ryan!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
125
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1594
diff changeset
126 static void
3792
866c310e2cb5 Changed some 1.3 audio symbol names.
Ryan C. Gordon <icculus@icculus.org>
parents: 3784
diff changeset
127 DISKAUD_CloseDevice(_THIS)
68
ac6645260d31 Added an audio driver that writes to disk (thanks Ryan!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
128 {
3805
ef7f7be318da Disk audio can now use device name for target filename.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
129 if (this->hidden != NULL) {
ef7f7be318da Disk audio can now use device name for target filename.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
130 if (this->hidden->mixbuf != NULL) {
ef7f7be318da Disk audio can now use device name for target filename.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
131 SDL_FreeAudioMem(this->hidden->mixbuf);
ef7f7be318da Disk audio can now use device name for target filename.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
132 this->hidden->mixbuf = NULL;
ef7f7be318da Disk audio can now use device name for target filename.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
133 }
ef7f7be318da Disk audio can now use device name for target filename.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
134 if (this->hidden->output != NULL) {
ef7f7be318da Disk audio can now use device name for target filename.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
135 SDL_RWclose(this->hidden->output);
ef7f7be318da Disk audio can now use device name for target filename.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
136 this->hidden->output = NULL;
ef7f7be318da Disk audio can now use device name for target filename.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
137 }
ef7f7be318da Disk audio can now use device name for target filename.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
138 SDL_free(this->hidden);
ef7f7be318da Disk audio can now use device name for target filename.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
139 this->hidden = NULL;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1594
diff changeset
140 }
68
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
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1594
diff changeset
143 static int
3792
866c310e2cb5 Changed some 1.3 audio symbol names.
Ryan C. Gordon <icculus@icculus.org>
parents: 3784
diff changeset
144 DISKAUD_OpenDevice(_THIS, const char *devname, int iscapture)
68
ac6645260d31 Added an audio driver that writes to disk (thanks Ryan!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
145 {
3784
37c9c4590689 First batch of heavy lifting on supporting multiple audio devices at once.
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
146 const char *envr = SDL_getenv(DISKENVR_WRITEDELAY);
3805
ef7f7be318da Disk audio can now use device name for target filename.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
147 const char *fname = DISKAUD_GetOutputFilename(devname);
3784
37c9c4590689 First batch of heavy lifting on supporting multiple audio devices at once.
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
148
37c9c4590689 First batch of heavy lifting on supporting multiple audio devices at once.
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
149 this->hidden = (struct SDL_PrivateAudioData *)
37c9c4590689 First batch of heavy lifting on supporting multiple audio devices at once.
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
150 SDL_malloc(sizeof (*this->hidden));
37c9c4590689 First batch of heavy lifting on supporting multiple audio devices at once.
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
151 if (this->hidden == NULL) {
37c9c4590689 First batch of heavy lifting on supporting multiple audio devices at once.
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
152 SDL_OutOfMemory();
37c9c4590689 First batch of heavy lifting on supporting multiple audio devices at once.
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
153 return 0;
37c9c4590689 First batch of heavy lifting on supporting multiple audio devices at once.
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
154 }
37c9c4590689 First batch of heavy lifting on supporting multiple audio devices at once.
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
155 SDL_memset(this->hidden, 0, sizeof (*this->hidden));
37c9c4590689 First batch of heavy lifting on supporting multiple audio devices at once.
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
156
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1594
diff changeset
157 /* Open the audio device */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1594
diff changeset
158 this->hidden->output = SDL_RWFromFile(fname, "wb");
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1594
diff changeset
159 if (this->hidden->output == NULL) {
3792
866c310e2cb5 Changed some 1.3 audio symbol names.
Ryan C. Gordon <icculus@icculus.org>
parents: 3784
diff changeset
160 DISKAUD_CloseDevice(this);
3784
37c9c4590689 First batch of heavy lifting on supporting multiple audio devices at once.
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
161 return 0;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1594
diff changeset
162 }
68
ac6645260d31 Added an audio driver that writes to disk (thanks Ryan!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
163
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1594
diff changeset
164 /* Allocate mixing buffer */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1594
diff changeset
165 this->hidden->mixbuf = (Uint8 *) SDL_AllocAudioMem(this->hidden->mixlen);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1594
diff changeset
166 if (this->hidden->mixbuf == NULL) {
3792
866c310e2cb5 Changed some 1.3 audio symbol names.
Ryan C. Gordon <icculus@icculus.org>
parents: 3784
diff changeset
167 DISKAUD_CloseDevice(this);
3784
37c9c4590689 First batch of heavy lifting on supporting multiple audio devices at once.
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
168 return 0;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1594
diff changeset
169 }
3784
37c9c4590689 First batch of heavy lifting on supporting multiple audio devices at once.
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
170 SDL_memset(this->hidden->mixbuf, this->spec.silence, this->spec.size);
37c9c4590689 First batch of heavy lifting on supporting multiple audio devices at once.
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
171
37c9c4590689 First batch of heavy lifting on supporting multiple audio devices at once.
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
172 this->hidden->mixlen = this->spec.size;
37c9c4590689 First batch of heavy lifting on supporting multiple audio devices at once.
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
173 this->hidden->write_delay =
37c9c4590689 First batch of heavy lifting on supporting multiple audio devices at once.
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
174 (envr) ? SDL_atoi(envr) : DISKDEFAULT_WRITEDELAY;
37c9c4590689 First batch of heavy lifting on supporting multiple audio devices at once.
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
175
37c9c4590689 First batch of heavy lifting on supporting multiple audio devices at once.
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
176 #if HAVE_STDIO_H
37c9c4590689 First batch of heavy lifting on supporting multiple audio devices at once.
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
177 fprintf(stderr,
37c9c4590689 First batch of heavy lifting on supporting multiple audio devices at once.
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
178 "WARNING: You are using the SDL disk writer audio driver!\n"
37c9c4590689 First batch of heavy lifting on supporting multiple audio devices at once.
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
179 " Writing to file [%s].\n", fname);
37c9c4590689 First batch of heavy lifting on supporting multiple audio devices at once.
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
180 #endif
68
ac6645260d31 Added an audio driver that writes to disk (thanks Ryan!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
181
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1594
diff changeset
182 /* We're ready to rock and roll. :-) */
3784
37c9c4590689 First batch of heavy lifting on supporting multiple audio devices at once.
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
183 return 1;
68
ac6645260d31 Added an audio driver that writes to disk (thanks Ryan!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
184 }
ac6645260d31 Added an audio driver that writes to disk (thanks Ryan!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
185
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1594
diff changeset
186 /* vi: set ts=4 sw=4 expandtab: */