testaudiocapture: open capture device to same spec as output device. ...since our resampler is still terrible (sorry!).
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
diff --git a/test/testaudiocapture.c b/test/testaudiocapture.c
index 8e614e9..f04d359 100644
--- a/test/testaudiocapture.c
+++ b/test/testaudiocapture.c
@@ -11,6 +11,8 @@
*/
#include "SDL.h"
+#include <stdlib.h>
+
#ifdef __EMSCRIPTEN__
#include <emscripten/emscripten.h>
#endif
@@ -89,6 +91,7 @@ main(int argc, char **argv)
{
/* (argv[1] == NULL means "open default device.") */
const char *devname = argv[1];
+ SDL_AudioSpec wanted;
int devcount;
int i;
@@ -114,12 +117,28 @@ main(int argc, char **argv)
SDL_Log(" Capture device #%d: '%s'\n", i, SDL_GetAudioDeviceName(i, SDL_TRUE));
}
+ SDL_zero(wanted);
+ wanted.freq = 44100;
+ wanted.format = AUDIO_F32SYS;
+ wanted.channels = 1;
+ wanted.samples = 1024;
+ wanted.callback = NULL;
+
SDL_zero(spec);
- spec.freq = 44100;
- spec.format = AUDIO_F32SYS;
- spec.channels = 1;
- spec.samples = 1024;
- spec.callback = NULL;
+
+ /* DirectSound can fail in some instances if you open the same hardware
+ for both capture and output and didn't open the output end first,
+ according to the docs, so if you're doing something like this, always
+ open your capture devices second in case you land in those bizarre
+ circumstances. */
+
+ SDL_Log("Opening default playback device...\n");
+ devid_out = SDL_OpenAudioDevice(NULL, SDL_FALSE, &wanted, &spec, SDL_AUDIO_ALLOW_ANY_CHANGE);
+ if (!devid_out) {
+ SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't open an audio device for capture: %s!\n", SDL_GetError());
+ SDL_Quit();
+ exit(1);
+ }
SDL_Log("Opening capture device %s%s%s...\n",
devname ? "'" : "",
@@ -133,14 +152,6 @@ main(int argc, char **argv)
exit(1);
}
- SDL_Log("Opening default playback device...\n");
- devid_out = SDL_OpenAudioDevice(NULL, SDL_FALSE, &spec, &spec, 0);
- if (!devid_out) {
- SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't open an audio device for capture: %s!\n", SDL_GetError());
- SDL_Quit();
- exit(1);
- }
-
SDL_Log("Ready! Hold down mouse or finger to record!\n");
#ifdef __EMSCRIPTEN__