| 180 | } |
| 181 | |
| 182 | static int |
| 183 | UpdateAudioStream(_THIS, const SDL_AudioSpec *oldspec) |
| 184 | { |
| 185 | /* Since WASAPI requires us to handle all audio conversion, and our |
| 186 | device format might have changed, we might have to add/remove/change |
| 187 | the audio stream that the higher level uses to convert data, so |
| 188 | SDL keeps firing the callback as if nothing happened here. */ |
| 189 | |
| 190 | if ( (this->callbackspec.channels == this->spec.channels) && |
| 191 | (this->callbackspec.format == this->spec.format) && |
| 192 | (this->callbackspec.freq == this->spec.freq) && |
| 193 | (this->callbackspec.samples == this->spec.samples) ) { |
| 194 | /* no need to buffer/convert in an AudioStream! */ |
| 195 | SDL_FreeAudioStream(this->stream); |
| 196 | this->stream = NULL; |
| 197 | } else if ( (oldspec->channels == this->spec.channels) && |
| 198 | (oldspec->format == this->spec.format) && |
| 199 | (oldspec->freq == this->spec.freq) ) { |
| 200 | /* The existing audio stream is okay to keep using. */ |
| 201 | } else { |
| 202 | /* replace the audiostream for new format */ |
| 203 | SDL_FreeAudioStream(this->stream); |
| 204 | if (this->iscapture) { |
| 205 | this->stream = SDL_NewAudioStream(this->spec.format, |
| 206 | this->spec.channels, this->spec.freq, |
| 207 | this->callbackspec.format, |
| 208 | this->callbackspec.channels, |
| 209 | this->callbackspec.freq); |
| 210 | } else { |
| 211 | this->stream = SDL_NewAudioStream(this->callbackspec.format, |
| 212 | this->callbackspec.channels, |
| 213 | this->callbackspec.freq, this->spec.format, |
| 214 | this->spec.channels, this->spec.freq); |
| 215 | } |
| 216 | |
| 217 | if (!this->stream) { |
| 218 | return -1; |
| 219 | } |
| 220 | } |
| 221 | |
| 222 | /* make sure our scratch buffer can cover the new device spec. */ |
| 223 | if (this->spec.size > this->work_buffer_len) { |
| 224 | Uint8 *ptr = (Uint8 *) SDL_realloc(this->work_buffer, this->spec.size); |
| 225 | if (ptr == NULL) { |
| 226 | return SDL_OutOfMemory(); |
| 227 | } |
| 228 | this->work_buffer = ptr; |
| 229 | this->work_buffer_len = this->spec.size; |
| 230 | } |
| 231 | |
| 232 | return 0; |
| 233 | } |
| 234 | |
| 235 | |
| 236 | static void ReleaseWasapiDevice(_THIS); |
no test coverage detected