comparison src/audio/disk/SDL_diskaudio.c @ 1668:4da1ee79c9af SDL-1.3

more tweaking indent options
author Sam Lantinga <slouken@libsdl.org>
date Mon, 29 May 2006 04:04:35 +0000
parents 782fd950bd46
children
comparison
equal deleted inserted replaced
1667:1fddae038bc8 1668:4da1ee79c9af
45 #define DISKDEFAULT_OUTFILE "sdlaudio.raw" 45 #define DISKDEFAULT_OUTFILE "sdlaudio.raw"
46 #define DISKENVR_WRITEDELAY "SDL_DISKAUDIODELAY" 46 #define DISKENVR_WRITEDELAY "SDL_DISKAUDIODELAY"
47 #define DISKDEFAULT_WRITEDELAY 150 47 #define DISKDEFAULT_WRITEDELAY 150
48 48
49 /* Audio driver functions */ 49 /* Audio driver functions */
50 static int DISKAUD_OpenAudio (_THIS, SDL_AudioSpec * spec); 50 static int DISKAUD_OpenAudio(_THIS, SDL_AudioSpec * spec);
51 static void DISKAUD_WaitAudio (_THIS); 51 static void DISKAUD_WaitAudio(_THIS);
52 static void DISKAUD_PlayAudio (_THIS); 52 static void DISKAUD_PlayAudio(_THIS);
53 static Uint8 *DISKAUD_GetAudioBuf (_THIS); 53 static Uint8 *DISKAUD_GetAudioBuf(_THIS);
54 static void DISKAUD_CloseAudio (_THIS); 54 static void DISKAUD_CloseAudio(_THIS);
55 55
56 static const char * 56 static const char *
57 DISKAUD_GetOutputFilename (void) 57 DISKAUD_GetOutputFilename(void)
58 { 58 {
59 const char *envr = SDL_getenv (DISKENVR_OUTFILE); 59 const char *envr = SDL_getenv(DISKENVR_OUTFILE);
60 return ((envr != NULL) ? envr : DISKDEFAULT_OUTFILE); 60 return ((envr != NULL) ? envr : DISKDEFAULT_OUTFILE);
61 } 61 }
62 62
63 /* Audio driver bootstrap functions */ 63 /* Audio driver bootstrap functions */
64 static int 64 static int
65 DISKAUD_Available (void) 65 DISKAUD_Available(void)
66 { 66 {
67 const char *envr = SDL_getenv ("SDL_AUDIODRIVER"); 67 const char *envr = SDL_getenv("SDL_AUDIODRIVER");
68 if (envr && (SDL_strcmp (envr, DISKAUD_DRIVER_NAME) == 0)) { 68 if (envr && (SDL_strcmp(envr, DISKAUD_DRIVER_NAME) == 0)) {
69 return (1); 69 return (1);
70 } 70 }
71 return (0); 71 return (0);
72 } 72 }
73 73
74 static void 74 static void
75 DISKAUD_DeleteDevice (SDL_AudioDevice * device) 75 DISKAUD_DeleteDevice(SDL_AudioDevice * device)
76 { 76 {
77 SDL_free (device->hidden); 77 SDL_free(device->hidden);
78 SDL_free (device); 78 SDL_free(device);
79 } 79 }
80 80
81 static SDL_AudioDevice * 81 static SDL_AudioDevice *
82 DISKAUD_CreateDevice (int devindex) 82 DISKAUD_CreateDevice(int devindex)
83 { 83 {
84 SDL_AudioDevice *this; 84 SDL_AudioDevice *this;
85 const char *envr; 85 const char *envr;
86 86
87 /* Initialize all variables that we clean on shutdown */ 87 /* Initialize all variables that we clean on shutdown */
88 this = (SDL_AudioDevice *) SDL_malloc (sizeof (SDL_AudioDevice)); 88 this = (SDL_AudioDevice *) SDL_malloc(sizeof(SDL_AudioDevice));
89 if (this) { 89 if (this) {
90 SDL_memset (this, 0, (sizeof *this)); 90 SDL_memset(this, 0, (sizeof *this));
91 this->hidden = (struct SDL_PrivateAudioData *) 91 this->hidden = (struct SDL_PrivateAudioData *)
92 SDL_malloc ((sizeof *this->hidden)); 92 SDL_malloc((sizeof *this->hidden));
93 } 93 }
94 if ((this == NULL) || (this->hidden == NULL)) { 94 if ((this == NULL) || (this->hidden == NULL)) {
95 SDL_OutOfMemory (); 95 SDL_OutOfMemory();
96 if (this) { 96 if (this) {
97 SDL_free (this); 97 SDL_free(this);
98 } 98 }
99 return (0); 99 return (0);
100 } 100 }
101 SDL_memset (this->hidden, 0, (sizeof *this->hidden)); 101 SDL_memset(this->hidden, 0, (sizeof *this->hidden));
102 102
103 envr = SDL_getenv (DISKENVR_WRITEDELAY); 103 envr = SDL_getenv(DISKENVR_WRITEDELAY);
104 this->hidden->write_delay = 104 this->hidden->write_delay =
105 (envr) ? SDL_atoi (envr) : DISKDEFAULT_WRITEDELAY; 105 (envr) ? SDL_atoi(envr) : DISKDEFAULT_WRITEDELAY;
106 106
107 /* Set the function pointers */ 107 /* Set the function pointers */
108 this->OpenAudio = DISKAUD_OpenAudio; 108 this->OpenAudio = DISKAUD_OpenAudio;
109 this->WaitAudio = DISKAUD_WaitAudio; 109 this->WaitAudio = DISKAUD_WaitAudio;
110 this->PlayAudio = DISKAUD_PlayAudio; 110 this->PlayAudio = DISKAUD_PlayAudio;
121 DISKAUD_Available, DISKAUD_CreateDevice 121 DISKAUD_Available, DISKAUD_CreateDevice
122 }; 122 };
123 123
124 /* This function waits until it is possible to write a full sound buffer */ 124 /* This function waits until it is possible to write a full sound buffer */
125 static void 125 static void
126 DISKAUD_WaitAudio (_THIS) 126 DISKAUD_WaitAudio(_THIS)
127 { 127 {
128 SDL_Delay (this->hidden->write_delay); 128 SDL_Delay(this->hidden->write_delay);
129 } 129 }
130 130
131 static void 131 static void
132 DISKAUD_PlayAudio (_THIS) 132 DISKAUD_PlayAudio(_THIS)
133 { 133 {
134 int written; 134 int written;
135 135
136 /* Write the audio data */ 136 /* Write the audio data */
137 written = SDL_RWwrite (this->hidden->output, 137 written = SDL_RWwrite(this->hidden->output,
138 this->hidden->mixbuf, 1, this->hidden->mixlen); 138 this->hidden->mixbuf, 1, this->hidden->mixlen);
139 139
140 /* If we couldn't write, assume fatal error for now */ 140 /* If we couldn't write, assume fatal error for now */
141 if ((Uint32) written != this->hidden->mixlen) { 141 if ((Uint32) written != this->hidden->mixlen) {
142 this->enabled = 0; 142 this->enabled = 0;
143 } 143 }
144 #ifdef DEBUG_AUDIO 144 #ifdef DEBUG_AUDIO
145 fprintf (stderr, "Wrote %d bytes of audio data\n", written); 145 fprintf(stderr, "Wrote %d bytes of audio data\n", written);
146 #endif 146 #endif
147 } 147 }
148 148
149 static Uint8 * 149 static Uint8 *
150 DISKAUD_GetAudioBuf (_THIS) 150 DISKAUD_GetAudioBuf(_THIS)
151 { 151 {
152 return (this->hidden->mixbuf); 152 return (this->hidden->mixbuf);
153 } 153 }
154 154
155 static void 155 static void
156 DISKAUD_CloseAudio (_THIS) 156 DISKAUD_CloseAudio(_THIS)
157 { 157 {
158 if (this->hidden->mixbuf != NULL) { 158 if (this->hidden->mixbuf != NULL) {
159 SDL_FreeAudioMem (this->hidden->mixbuf); 159 SDL_FreeAudioMem(this->hidden->mixbuf);
160 this->hidden->mixbuf = NULL; 160 this->hidden->mixbuf = NULL;
161 } 161 }
162 if (this->hidden->output != NULL) { 162 if (this->hidden->output != NULL) {
163 SDL_RWclose (this->hidden->output); 163 SDL_RWclose(this->hidden->output);
164 this->hidden->output = NULL; 164 this->hidden->output = NULL;
165 } 165 }
166 } 166 }
167 167
168 static int 168 static int
169 DISKAUD_OpenAudio (_THIS, SDL_AudioSpec * spec) 169 DISKAUD_OpenAudio(_THIS, SDL_AudioSpec * spec)
170 { 170 {
171 const char *fname = DISKAUD_GetOutputFilename (); 171 const char *fname = DISKAUD_GetOutputFilename();
172 172
173 /* Open the audio device */ 173 /* Open the audio device */
174 this->hidden->output = SDL_RWFromFile (fname, "wb"); 174 this->hidden->output = SDL_RWFromFile(fname, "wb");
175 if (this->hidden->output == NULL) { 175 if (this->hidden->output == NULL) {
176 return (-1); 176 return (-1);
177 } 177 }
178 #if HAVE_STDIO_H 178 #if HAVE_STDIO_H
179 fprintf (stderr, "WARNING: You are using the SDL disk writer" 179 fprintf(stderr, "WARNING: You are using the SDL disk writer"
180 " audio driver!\n Writing to file [%s].\n", fname); 180 " audio driver!\n Writing to file [%s].\n", fname);
181 #endif 181 #endif
182 182
183 /* Allocate mixing buffer */ 183 /* Allocate mixing buffer */
184 this->hidden->mixlen = spec->size; 184 this->hidden->mixlen = spec->size;
185 this->hidden->mixbuf = (Uint8 *) SDL_AllocAudioMem (this->hidden->mixlen); 185 this->hidden->mixbuf = (Uint8 *) SDL_AllocAudioMem(this->hidden->mixlen);
186 if (this->hidden->mixbuf == NULL) { 186 if (this->hidden->mixbuf == NULL) {
187 return (-1); 187 return (-1);
188 } 188 }
189 SDL_memset (this->hidden->mixbuf, spec->silence, spec->size); 189 SDL_memset(this->hidden->mixbuf, spec->silence, spec->size);
190 190
191 /* We're ready to rock and roll. :-) */ 191 /* We're ready to rock and roll. :-) */
192 return (0); 192 return (0);
193 } 193 }
194 194