testaudiocapture: open capture device to same spec as output device.

...since our resampler is still terrible (sorry!).
Ryan C. Gordon 2016-08-09 16:57:49 -04:00
parent a05bde2170
commit 3139e5d16b
1 changed files with 24 additions and 13 deletions

View File

@ -11,6 +11,8 @@
*/ */
#include "SDL.h" #include "SDL.h"
#include <stdlib.h>
#ifdef __EMSCRIPTEN__ #ifdef __EMSCRIPTEN__
#include <emscripten/emscripten.h> #include <emscripten/emscripten.h>
#endif #endif
@ -89,6 +91,7 @@ main(int argc, char **argv)
{ {
/* (argv[1] == NULL means "open default device.") */ /* (argv[1] == NULL means "open default device.") */
const char *devname = argv[1]; const char *devname = argv[1];
SDL_AudioSpec wanted;
int devcount; int devcount;
int i; 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_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); SDL_zero(spec);
spec.freq = 44100;
spec.format = AUDIO_F32SYS; /* DirectSound can fail in some instances if you open the same hardware
spec.channels = 1; for both capture and output and didn't open the output end first,
spec.samples = 1024; according to the docs, so if you're doing something like this, always
spec.callback = NULL; 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", SDL_Log("Opening capture device %s%s%s...\n",
devname ? "'" : "", devname ? "'" : "",
@ -133,14 +152,6 @@ main(int argc, char **argv)
exit(1); 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"); SDL_Log("Ready! Hold down mouse or finger to record!\n");
#ifdef __EMSCRIPTEN__ #ifdef __EMSCRIPTEN__