test/testaudiocapture.c
author Ryan C. Gordon <icculus@icculus.org>
Sat, 06 Aug 2016 02:48:00 -0400
changeset 10245 ec1844380edb
parent 10243 e8facf18d5bd
child 10254 2b8bb76140a5
permissions -rw-r--r--
testaudiocapture: use capture device buffer queueing, for better test coverage.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10213
4b0893d63092 audio: Initial bits to enable audio capture support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     1
/*
4b0893d63092 audio: Initial bits to enable audio capture support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     2
  Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org>
4b0893d63092 audio: Initial bits to enable audio capture support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     3
4b0893d63092 audio: Initial bits to enable audio capture support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     4
  This software is provided 'as-is', without any express or implied
4b0893d63092 audio: Initial bits to enable audio capture support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     5
  warranty.  In no event will the authors be held liable for any damages
4b0893d63092 audio: Initial bits to enable audio capture support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     6
  arising from the use of this software.
4b0893d63092 audio: Initial bits to enable audio capture support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     7
4b0893d63092 audio: Initial bits to enable audio capture support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     8
  Permission is granted to anyone to use this software for any purpose,
4b0893d63092 audio: Initial bits to enable audio capture support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     9
  including commercial applications, and to alter it and redistribute it
4b0893d63092 audio: Initial bits to enable audio capture support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    10
  freely.
4b0893d63092 audio: Initial bits to enable audio capture support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    11
*/
4b0893d63092 audio: Initial bits to enable audio capture support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    12
#include "SDL.h"
4b0893d63092 audio: Initial bits to enable audio capture support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    13
4b0893d63092 audio: Initial bits to enable audio capture support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    14
#ifdef __EMSCRIPTEN__
4b0893d63092 audio: Initial bits to enable audio capture support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    15
#include <emscripten/emscripten.h>
4b0893d63092 audio: Initial bits to enable audio capture support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    16
#endif
4b0893d63092 audio: Initial bits to enable audio capture support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    17
10226
656799817375 testaudiocapture: Make a simple green/red window when recording/playing.
Ryan C. Gordon <icculus@icculus.org>
parents: 10219
diff changeset
    18
static SDL_Window *window = NULL;
656799817375 testaudiocapture: Make a simple green/red window when recording/playing.
Ryan C. Gordon <icculus@icculus.org>
parents: 10219
diff changeset
    19
static SDL_Renderer *renderer = NULL;
10213
4b0893d63092 audio: Initial bits to enable audio capture support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    20
static SDL_AudioSpec spec;
10228
d7ae395db9f2 testaudiocapture: made test app interactive.
Ryan C. Gordon <icculus@icculus.org>
parents: 10226
diff changeset
    21
static SDL_AudioDeviceID devid_in = 0;
d7ae395db9f2 testaudiocapture: made test app interactive.
Ryan C. Gordon <icculus@icculus.org>
parents: 10226
diff changeset
    22
static SDL_AudioDeviceID devid_out = 0;
10213
4b0893d63092 audio: Initial bits to enable audio capture support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    23
4b0893d63092 audio: Initial bits to enable audio capture support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    24
static void
4b0893d63092 audio: Initial bits to enable audio capture support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    25
loop()
4b0893d63092 audio: Initial bits to enable audio capture support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    26
{
10228
d7ae395db9f2 testaudiocapture: made test app interactive.
Ryan C. Gordon <icculus@icculus.org>
parents: 10226
diff changeset
    27
    SDL_bool please_quit = SDL_FALSE;
10213
4b0893d63092 audio: Initial bits to enable audio capture support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    28
    SDL_Event e;
4b0893d63092 audio: Initial bits to enable audio capture support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    29
4b0893d63092 audio: Initial bits to enable audio capture support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    30
    while (SDL_PollEvent(&e)) {
4b0893d63092 audio: Initial bits to enable audio capture support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    31
        if (e.type == SDL_QUIT) {
4b0893d63092 audio: Initial bits to enable audio capture support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    32
            please_quit = SDL_TRUE;
10228
d7ae395db9f2 testaudiocapture: made test app interactive.
Ryan C. Gordon <icculus@icculus.org>
parents: 10226
diff changeset
    33
        } else if (e.type == SDL_KEYDOWN) {
d7ae395db9f2 testaudiocapture: made test app interactive.
Ryan C. Gordon <icculus@icculus.org>
parents: 10226
diff changeset
    34
            if (e.key.keysym.sym == SDLK_ESCAPE) {
d7ae395db9f2 testaudiocapture: made test app interactive.
Ryan C. Gordon <icculus@icculus.org>
parents: 10226
diff changeset
    35
                please_quit = SDL_TRUE;
d7ae395db9f2 testaudiocapture: made test app interactive.
Ryan C. Gordon <icculus@icculus.org>
parents: 10226
diff changeset
    36
            }
d7ae395db9f2 testaudiocapture: made test app interactive.
Ryan C. Gordon <icculus@icculus.org>
parents: 10226
diff changeset
    37
        } else if (e.type == SDL_MOUSEBUTTONDOWN) {
d7ae395db9f2 testaudiocapture: made test app interactive.
Ryan C. Gordon <icculus@icculus.org>
parents: 10226
diff changeset
    38
            if (e.button.button == 1) {
d7ae395db9f2 testaudiocapture: made test app interactive.
Ryan C. Gordon <icculus@icculus.org>
parents: 10226
diff changeset
    39
                SDL_PauseAudioDevice(devid_out, SDL_TRUE);
d7ae395db9f2 testaudiocapture: made test app interactive.
Ryan C. Gordon <icculus@icculus.org>
parents: 10226
diff changeset
    40
                SDL_PauseAudioDevice(devid_in, SDL_FALSE);
d7ae395db9f2 testaudiocapture: made test app interactive.
Ryan C. Gordon <icculus@icculus.org>
parents: 10226
diff changeset
    41
            }
d7ae395db9f2 testaudiocapture: made test app interactive.
Ryan C. Gordon <icculus@icculus.org>
parents: 10226
diff changeset
    42
        } else if (e.type == SDL_MOUSEBUTTONUP) {
d7ae395db9f2 testaudiocapture: made test app interactive.
Ryan C. Gordon <icculus@icculus.org>
parents: 10226
diff changeset
    43
            if (e.button.button == 1) {
d7ae395db9f2 testaudiocapture: made test app interactive.
Ryan C. Gordon <icculus@icculus.org>
parents: 10226
diff changeset
    44
                SDL_PauseAudioDevice(devid_in, SDL_TRUE);
d7ae395db9f2 testaudiocapture: made test app interactive.
Ryan C. Gordon <icculus@icculus.org>
parents: 10226
diff changeset
    45
                SDL_PauseAudioDevice(devid_out, SDL_FALSE);
d7ae395db9f2 testaudiocapture: made test app interactive.
Ryan C. Gordon <icculus@icculus.org>
parents: 10226
diff changeset
    46
            }
10213
4b0893d63092 audio: Initial bits to enable audio capture support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    47
        }
4b0893d63092 audio: Initial bits to enable audio capture support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    48
    }
4b0893d63092 audio: Initial bits to enable audio capture support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    49
10228
d7ae395db9f2 testaudiocapture: made test app interactive.
Ryan C. Gordon <icculus@icculus.org>
parents: 10226
diff changeset
    50
    if (SDL_GetAudioDeviceStatus(devid_in) == SDL_AUDIO_PLAYING) {
10226
656799817375 testaudiocapture: Make a simple green/red window when recording/playing.
Ryan C. Gordon <icculus@icculus.org>
parents: 10219
diff changeset
    51
        SDL_SetRenderDrawColor(renderer, 0, 255, 0, 255);
656799817375 testaudiocapture: Make a simple green/red window when recording/playing.
Ryan C. Gordon <icculus@icculus.org>
parents: 10219
diff changeset
    52
    } else {
656799817375 testaudiocapture: Make a simple green/red window when recording/playing.
Ryan C. Gordon <icculus@icculus.org>
parents: 10219
diff changeset
    53
        SDL_SetRenderDrawColor(renderer, 255, 0, 0, 255);
656799817375 testaudiocapture: Make a simple green/red window when recording/playing.
Ryan C. Gordon <icculus@icculus.org>
parents: 10219
diff changeset
    54
    }
656799817375 testaudiocapture: Make a simple green/red window when recording/playing.
Ryan C. Gordon <icculus@icculus.org>
parents: 10219
diff changeset
    55
    SDL_RenderClear(renderer);
656799817375 testaudiocapture: Make a simple green/red window when recording/playing.
Ryan C. Gordon <icculus@icculus.org>
parents: 10219
diff changeset
    56
    SDL_RenderPresent(renderer);
10213
4b0893d63092 audio: Initial bits to enable audio capture support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    57
4b0893d63092 audio: Initial bits to enable audio capture support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    58
    if (please_quit) {
4b0893d63092 audio: Initial bits to enable audio capture support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    59
        /* stop playing back, quit. */
4b0893d63092 audio: Initial bits to enable audio capture support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    60
        SDL_Log("Shutting down.\n");
10228
d7ae395db9f2 testaudiocapture: made test app interactive.
Ryan C. Gordon <icculus@icculus.org>
parents: 10226
diff changeset
    61
        SDL_PauseAudioDevice(devid_in, 1);
d7ae395db9f2 testaudiocapture: made test app interactive.
Ryan C. Gordon <icculus@icculus.org>
parents: 10226
diff changeset
    62
        SDL_CloseAudioDevice(devid_in);
d7ae395db9f2 testaudiocapture: made test app interactive.
Ryan C. Gordon <icculus@icculus.org>
parents: 10226
diff changeset
    63
        SDL_PauseAudioDevice(devid_out, 1);
d7ae395db9f2 testaudiocapture: made test app interactive.
Ryan C. Gordon <icculus@icculus.org>
parents: 10226
diff changeset
    64
        SDL_CloseAudioDevice(devid_out);
d7ae395db9f2 testaudiocapture: made test app interactive.
Ryan C. Gordon <icculus@icculus.org>
parents: 10226
diff changeset
    65
        SDL_DestroyRenderer(renderer);
d7ae395db9f2 testaudiocapture: made test app interactive.
Ryan C. Gordon <icculus@icculus.org>
parents: 10226
diff changeset
    66
        SDL_DestroyWindow(window);
10213
4b0893d63092 audio: Initial bits to enable audio capture support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    67
        SDL_Quit();
4b0893d63092 audio: Initial bits to enable audio capture support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    68
        #ifdef __EMSCRIPTEN__
4b0893d63092 audio: Initial bits to enable audio capture support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    69
        emscripten_cancel_main_loop();
4b0893d63092 audio: Initial bits to enable audio capture support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    70
        #endif
4b0893d63092 audio: Initial bits to enable audio capture support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    71
        exit(0);
4b0893d63092 audio: Initial bits to enable audio capture support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    72
    }
10245
ec1844380edb testaudiocapture: use capture device buffer queueing, for better test coverage.
Ryan C. Gordon <icculus@icculus.org>
parents: 10243
diff changeset
    73
ec1844380edb testaudiocapture: use capture device buffer queueing, for better test coverage.
Ryan C. Gordon <icculus@icculus.org>
parents: 10243
diff changeset
    74
    /* Note that it would be easier to just have a one-line function that
ec1844380edb testaudiocapture: use capture device buffer queueing, for better test coverage.
Ryan C. Gordon <icculus@icculus.org>
parents: 10243
diff changeset
    75
        calls SDL_QueueAudio() as a capture device callback, but we're
ec1844380edb testaudiocapture: use capture device buffer queueing, for better test coverage.
Ryan C. Gordon <icculus@icculus.org>
parents: 10243
diff changeset
    76
        trying to test the API, so we use SDL_DequeueAudio() here. */
ec1844380edb testaudiocapture: use capture device buffer queueing, for better test coverage.
Ryan C. Gordon <icculus@icculus.org>
parents: 10243
diff changeset
    77
    while (SDL_TRUE) {
ec1844380edb testaudiocapture: use capture device buffer queueing, for better test coverage.
Ryan C. Gordon <icculus@icculus.org>
parents: 10243
diff changeset
    78
        Uint8 buf[1024];
ec1844380edb testaudiocapture: use capture device buffer queueing, for better test coverage.
Ryan C. Gordon <icculus@icculus.org>
parents: 10243
diff changeset
    79
        const Uint32 br = SDL_DequeueAudio(devid_in, buf, sizeof (buf));
ec1844380edb testaudiocapture: use capture device buffer queueing, for better test coverage.
Ryan C. Gordon <icculus@icculus.org>
parents: 10243
diff changeset
    80
        SDL_QueueAudio(devid_out, buf, br);
ec1844380edb testaudiocapture: use capture device buffer queueing, for better test coverage.
Ryan C. Gordon <icculus@icculus.org>
parents: 10243
diff changeset
    81
        if (br < sizeof (buf)) {
ec1844380edb testaudiocapture: use capture device buffer queueing, for better test coverage.
Ryan C. Gordon <icculus@icculus.org>
parents: 10243
diff changeset
    82
            break;
ec1844380edb testaudiocapture: use capture device buffer queueing, for better test coverage.
Ryan C. Gordon <icculus@icculus.org>
parents: 10243
diff changeset
    83
        }
ec1844380edb testaudiocapture: use capture device buffer queueing, for better test coverage.
Ryan C. Gordon <icculus@icculus.org>
parents: 10243
diff changeset
    84
    }
10213
4b0893d63092 audio: Initial bits to enable audio capture support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    85
}
4b0893d63092 audio: Initial bits to enable audio capture support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    86
4b0893d63092 audio: Initial bits to enable audio capture support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    87
int
4b0893d63092 audio: Initial bits to enable audio capture support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    88
main(int argc, char **argv)
4b0893d63092 audio: Initial bits to enable audio capture support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    89
{
10219
0d344873cd93 testaudiocapture: Let specific devices be opened.
Ryan C. Gordon <icculus@icculus.org>
parents: 10213
diff changeset
    90
    /* (argv[1] == NULL means "open default device.") */
0d344873cd93 testaudiocapture: Let specific devices be opened.
Ryan C. Gordon <icculus@icculus.org>
parents: 10213
diff changeset
    91
    const char *devname = argv[1];
0d344873cd93 testaudiocapture: Let specific devices be opened.
Ryan C. Gordon <icculus@icculus.org>
parents: 10213
diff changeset
    92
    int devcount;
0d344873cd93 testaudiocapture: Let specific devices be opened.
Ryan C. Gordon <icculus@icculus.org>
parents: 10213
diff changeset
    93
    int i;
0d344873cd93 testaudiocapture: Let specific devices be opened.
Ryan C. Gordon <icculus@icculus.org>
parents: 10213
diff changeset
    94
10213
4b0893d63092 audio: Initial bits to enable audio capture support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    95
    /* Enable standard application logging */
4b0893d63092 audio: Initial bits to enable audio capture support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    96
    SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
4b0893d63092 audio: Initial bits to enable audio capture support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    97
4b0893d63092 audio: Initial bits to enable audio capture support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    98
    /* Load the SDL library */
4b0893d63092 audio: Initial bits to enable audio capture support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    99
    if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO) < 0) {
4b0893d63092 audio: Initial bits to enable audio capture support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   100
        SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL: %s\n", SDL_GetError());
4b0893d63092 audio: Initial bits to enable audio capture support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   101
        return (1);
4b0893d63092 audio: Initial bits to enable audio capture support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   102
    }
4b0893d63092 audio: Initial bits to enable audio capture support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   103
10243
e8facf18d5bd testaudiocapture: don't use fullscreen for the window.
Ryan C. Gordon <icculus@icculus.org>
parents: 10228
diff changeset
   104
    window = SDL_CreateWindow("testaudiocapture", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 320, 240, 0);
10226
656799817375 testaudiocapture: Make a simple green/red window when recording/playing.
Ryan C. Gordon <icculus@icculus.org>
parents: 10219
diff changeset
   105
    renderer = SDL_CreateRenderer(window, -1, 0);
656799817375 testaudiocapture: Make a simple green/red window when recording/playing.
Ryan C. Gordon <icculus@icculus.org>
parents: 10219
diff changeset
   106
    SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255);
656799817375 testaudiocapture: Make a simple green/red window when recording/playing.
Ryan C. Gordon <icculus@icculus.org>
parents: 10219
diff changeset
   107
    SDL_RenderClear(renderer);
656799817375 testaudiocapture: Make a simple green/red window when recording/playing.
Ryan C. Gordon <icculus@icculus.org>
parents: 10219
diff changeset
   108
    SDL_RenderPresent(renderer);
10213
4b0893d63092 audio: Initial bits to enable audio capture support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   109
4b0893d63092 audio: Initial bits to enable audio capture support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   110
    SDL_Log("Using audio driver: %s\n", SDL_GetCurrentAudioDriver());
4b0893d63092 audio: Initial bits to enable audio capture support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   111
10219
0d344873cd93 testaudiocapture: Let specific devices be opened.
Ryan C. Gordon <icculus@icculus.org>
parents: 10213
diff changeset
   112
    devcount = SDL_GetNumAudioDevices(SDL_TRUE);
0d344873cd93 testaudiocapture: Let specific devices be opened.
Ryan C. Gordon <icculus@icculus.org>
parents: 10213
diff changeset
   113
    for (i = 0; i < devcount; i++) {
0d344873cd93 testaudiocapture: Let specific devices be opened.
Ryan C. Gordon <icculus@icculus.org>
parents: 10213
diff changeset
   114
        SDL_Log(" Capture device #%d: '%s'\n", i, SDL_GetAudioDeviceName(i, SDL_TRUE));
0d344873cd93 testaudiocapture: Let specific devices be opened.
Ryan C. Gordon <icculus@icculus.org>
parents: 10213
diff changeset
   115
    }
0d344873cd93 testaudiocapture: Let specific devices be opened.
Ryan C. Gordon <icculus@icculus.org>
parents: 10213
diff changeset
   116
10213
4b0893d63092 audio: Initial bits to enable audio capture support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   117
    SDL_zero(spec);
4b0893d63092 audio: Initial bits to enable audio capture support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   118
    spec.freq = 44100;
4b0893d63092 audio: Initial bits to enable audio capture support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   119
    spec.format = AUDIO_F32SYS;
4b0893d63092 audio: Initial bits to enable audio capture support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   120
    spec.channels = 1;
4b0893d63092 audio: Initial bits to enable audio capture support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   121
    spec.samples = 1024;
10245
ec1844380edb testaudiocapture: use capture device buffer queueing, for better test coverage.
Ryan C. Gordon <icculus@icculus.org>
parents: 10243
diff changeset
   122
    spec.callback = NULL;
10213
4b0893d63092 audio: Initial bits to enable audio capture support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   123
10228
d7ae395db9f2 testaudiocapture: made test app interactive.
Ryan C. Gordon <icculus@icculus.org>
parents: 10226
diff changeset
   124
    SDL_Log("Opening capture device %s%s%s...\n",
10219
0d344873cd93 testaudiocapture: Let specific devices be opened.
Ryan C. Gordon <icculus@icculus.org>
parents: 10213
diff changeset
   125
            devname ? "'" : "",
0d344873cd93 testaudiocapture: Let specific devices be opened.
Ryan C. Gordon <icculus@icculus.org>
parents: 10213
diff changeset
   126
            devname ? devname : "[[default]]",
0d344873cd93 testaudiocapture: Let specific devices be opened.
Ryan C. Gordon <icculus@icculus.org>
parents: 10213
diff changeset
   127
            devname ? "'" : "");
0d344873cd93 testaudiocapture: Let specific devices be opened.
Ryan C. Gordon <icculus@icculus.org>
parents: 10213
diff changeset
   128
10228
d7ae395db9f2 testaudiocapture: made test app interactive.
Ryan C. Gordon <icculus@icculus.org>
parents: 10226
diff changeset
   129
    devid_in = SDL_OpenAudioDevice(argv[1], SDL_TRUE, &spec, &spec, 0);
d7ae395db9f2 testaudiocapture: made test app interactive.
Ryan C. Gordon <icculus@icculus.org>
parents: 10226
diff changeset
   130
    if (!devid_in) {
10213
4b0893d63092 audio: Initial bits to enable audio capture support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   131
        SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't open an audio device for capture: %s!\n", SDL_GetError());
4b0893d63092 audio: Initial bits to enable audio capture support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   132
        SDL_Quit();
4b0893d63092 audio: Initial bits to enable audio capture support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   133
        exit(1);
4b0893d63092 audio: Initial bits to enable audio capture support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   134
    }
4b0893d63092 audio: Initial bits to enable audio capture support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   135
10228
d7ae395db9f2 testaudiocapture: made test app interactive.
Ryan C. Gordon <icculus@icculus.org>
parents: 10226
diff changeset
   136
    SDL_Log("Opening default playback device...\n");
d7ae395db9f2 testaudiocapture: made test app interactive.
Ryan C. Gordon <icculus@icculus.org>
parents: 10226
diff changeset
   137
    devid_out = SDL_OpenAudioDevice(NULL, SDL_FALSE, &spec, &spec, 0);
d7ae395db9f2 testaudiocapture: made test app interactive.
Ryan C. Gordon <icculus@icculus.org>
parents: 10226
diff changeset
   138
    if (!devid_out) {
d7ae395db9f2 testaudiocapture: made test app interactive.
Ryan C. Gordon <icculus@icculus.org>
parents: 10226
diff changeset
   139
        SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't open an audio device for capture: %s!\n", SDL_GetError());
d7ae395db9f2 testaudiocapture: made test app interactive.
Ryan C. Gordon <icculus@icculus.org>
parents: 10226
diff changeset
   140
        SDL_Quit();
d7ae395db9f2 testaudiocapture: made test app interactive.
Ryan C. Gordon <icculus@icculus.org>
parents: 10226
diff changeset
   141
        exit(1);
d7ae395db9f2 testaudiocapture: made test app interactive.
Ryan C. Gordon <icculus@icculus.org>
parents: 10226
diff changeset
   142
    }
d7ae395db9f2 testaudiocapture: made test app interactive.
Ryan C. Gordon <icculus@icculus.org>
parents: 10226
diff changeset
   143
d7ae395db9f2 testaudiocapture: made test app interactive.
Ryan C. Gordon <icculus@icculus.org>
parents: 10226
diff changeset
   144
    SDL_Log("Ready! Hold down mouse or finger to record!\n");
10213
4b0893d63092 audio: Initial bits to enable audio capture support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   145
4b0893d63092 audio: Initial bits to enable audio capture support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   146
#ifdef __EMSCRIPTEN__
4b0893d63092 audio: Initial bits to enable audio capture support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   147
    emscripten_set_main_loop(loop, 0, 1);
4b0893d63092 audio: Initial bits to enable audio capture support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   148
#else
4b0893d63092 audio: Initial bits to enable audio capture support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   149
    while (1) { loop(); SDL_Delay(16); }
4b0893d63092 audio: Initial bits to enable audio capture support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   150
#endif
4b0893d63092 audio: Initial bits to enable audio capture support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   151
4b0893d63092 audio: Initial bits to enable audio capture support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   152
    return 0;
4b0893d63092 audio: Initial bits to enable audio capture support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   153
}
4b0893d63092 audio: Initial bits to enable audio capture support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   154