Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
testaudiocapture: open capture device to same spec as output device.
...since our resampler is still terrible (sorry!).
  • Loading branch information
icculus committed Aug 9, 2016
1 parent a05bde2 commit 3139e5d
Showing 1 changed file with 24 additions and 13 deletions.
37 changes: 24 additions & 13 deletions test/testaudiocapture.c
Expand Up @@ -11,6 +11,8 @@
*/
#include "SDL.h"

#include <stdlib.h>

#ifdef __EMSCRIPTEN__
#include <emscripten/emscripten.h>
#endif
Expand Down Expand Up @@ -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;

Expand All @@ -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 ? "'" : "",
Expand All @@ -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__
Expand Down

0 comments on commit 3139e5d

Please sign in to comment.