test/testmultiaudio.c
author Ryan C. Gordon <icculus@icculus.org>
Fri, 12 Aug 2016 19:59:00 -0400
changeset 10266 c09f06c4e8c8
parent 10003 d91a2c45825e
permissions -rw-r--r--
emscripten: send fake mouse events for touches, like other targets do. (This really should be handled at the higher level and not in the individual targets, but this fixes the immediate bug.)
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
5535
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 3099
diff changeset
     1
/*
9998
f67cf37e9cd4 Updated copyright to 2016
Sam Lantinga <slouken@libsdl.org>
parents: 9922
diff changeset
     2
  Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org>
5535
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 3099
diff changeset
     3
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 3099
diff changeset
     4
  This software is provided 'as-is', without any express or implied
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 3099
diff changeset
     5
  warranty.  In no event will the authors be held liable for any damages
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 3099
diff changeset
     6
  arising from the use of this software.
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 3099
diff changeset
     7
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 3099
diff changeset
     8
  Permission is granted to anyone to use this software for any purpose,
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 3099
diff changeset
     9
  including commercial applications, and to alter it and redistribute it
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 3099
diff changeset
    10
  freely.
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 3099
diff changeset
    11
*/
2049
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    12
#include "SDL.h"
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    13
8787
8e20b31043cb Added missing stdio include in test program.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents: 8149
diff changeset
    14
#include <stdio.h> /* for fflush() and stdout */
8e20b31043cb Added missing stdio include in test program.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents: 8149
diff changeset
    15
9278
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 9269
diff changeset
    16
#ifdef __EMSCRIPTEN__
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 9269
diff changeset
    17
#include <emscripten/emscripten.h>
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 9269
diff changeset
    18
#endif
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 9269
diff changeset
    19
2049
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    20
static SDL_AudioSpec spec;
2060
866052b01ee5 indent is evil
Sam Lantinga <slouken@libsdl.org>
parents: 2049
diff changeset
    21
static Uint8 *sound = NULL;     /* Pointer to wave data */
866052b01ee5 indent is evil
Sam Lantinga <slouken@libsdl.org>
parents: 2049
diff changeset
    22
static Uint32 soundlen = 0;     /* Length of wave data */
2049
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    23
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    24
typedef struct
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    25
{
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    26
    SDL_AudioDeviceID dev;
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    27
    int soundpos;
10003
d91a2c45825e Remove almost all instances of "volatile" keyword.
Ryan C. Gordon <icculus@icculus.org>
parents: 9998
diff changeset
    28
    SDL_atomic_t done;
2049
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    29
} callback_data;
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    30
9278
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 9269
diff changeset
    31
callback_data cbd[64];
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 9269
diff changeset
    32
2060
866052b01ee5 indent is evil
Sam Lantinga <slouken@libsdl.org>
parents: 2049
diff changeset
    33
void SDLCALL
866052b01ee5 indent is evil
Sam Lantinga <slouken@libsdl.org>
parents: 2049
diff changeset
    34
play_through_once(void *arg, Uint8 * stream, int len)
2049
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    35
{
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    36
    callback_data *cbd = (callback_data *) arg;
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    37
    Uint8 *waveptr = sound + cbd->soundpos;
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    38
    int waveleft = soundlen - cbd->soundpos;
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    39
    int cpy = len;
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    40
    if (cpy > waveleft)
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    41
        cpy = waveleft;
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    42
2146
9fcde304c7b6 Replaced a few memset/memcpy calls with SDL_memset/SDL_memcpy.
Ryan C. Gordon <icculus@icculus.org>
parents: 2060
diff changeset
    43
    SDL_memcpy(stream, waveptr, cpy);
2049
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    44
    len -= cpy;
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    45
    cbd->soundpos += cpy;
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    46
    if (len > 0) {
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    47
        stream += cpy;
2146
9fcde304c7b6 Replaced a few memset/memcpy calls with SDL_memset/SDL_memcpy.
Ryan C. Gordon <icculus@icculus.org>
parents: 2060
diff changeset
    48
        SDL_memset(stream, spec.silence, len);
10003
d91a2c45825e Remove almost all instances of "volatile" keyword.
Ryan C. Gordon <icculus@icculus.org>
parents: 9998
diff changeset
    49
        SDL_AtomicSet(&cbd->done, 1);
2049
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    50
    }
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    51
}
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    52
9278
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 9269
diff changeset
    53
void
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 9269
diff changeset
    54
loop()
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 9269
diff changeset
    55
{
10003
d91a2c45825e Remove almost all instances of "volatile" keyword.
Ryan C. Gordon <icculus@icculus.org>
parents: 9998
diff changeset
    56
    if (SDL_AtomicGet(&cbd[0].done)) {
9290
fe975b2313fa Fixed compile errors in example programs.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents: 9278
diff changeset
    57
#ifdef __EMSCRIPTEN__
9278
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 9269
diff changeset
    58
        emscripten_cancel_main_loop();
9290
fe975b2313fa Fixed compile errors in example programs.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents: 9278
diff changeset
    59
#endif
9278
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 9269
diff changeset
    60
        SDL_PauseAudioDevice(cbd[0].dev, 1);
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 9269
diff changeset
    61
        SDL_CloseAudioDevice(cbd[0].dev);
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 9269
diff changeset
    62
        SDL_FreeWAV(sound);
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 9269
diff changeset
    63
        SDL_Quit();
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 9269
diff changeset
    64
    }
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 9269
diff changeset
    65
}
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 9269
diff changeset
    66
2060
866052b01ee5 indent is evil
Sam Lantinga <slouken@libsdl.org>
parents: 2049
diff changeset
    67
static void
866052b01ee5 indent is evil
Sam Lantinga <slouken@libsdl.org>
parents: 2049
diff changeset
    68
test_multi_audio(int devcount)
2049
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    69
{
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    70
    int keep_going = 1;
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    71
    int i;
9145
aa99e029b12e [Android] Fixes #2480, music does not pause when process backgrounded
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8851
diff changeset
    72
    
aa99e029b12e [Android] Fixes #2480, music does not pause when process backgrounded
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8851
diff changeset
    73
#ifdef __ANDROID__  
aa99e029b12e [Android] Fixes #2480, music does not pause when process backgrounded
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8851
diff changeset
    74
    SDL_Event event;
aa99e029b12e [Android] Fixes #2480, music does not pause when process backgrounded
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8851
diff changeset
    75
  
9269
d51f84c20b10 Added comments in example program.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents: 9145
diff changeset
    76
    /* Create a Window to get fully initialized event processing for testing pause on Android. */
9145
aa99e029b12e [Android] Fixes #2480, music does not pause when process backgrounded
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8851
diff changeset
    77
    SDL_CreateWindow("testmultiaudio", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 320, 240, 0);
aa99e029b12e [Android] Fixes #2480, music does not pause when process backgrounded
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8851
diff changeset
    78
#endif
2049
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    79
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    80
    if (devcount > 64) {
7639
9406b7dd2f2d Fix bug 2034: replace printf by SDL_Log in tests; update loopwave VS solution: copy missing dependency
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 7517
diff changeset
    81
        SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Too many devices (%d), clamping to 64...\n",
2060
866052b01ee5 indent is evil
Sam Lantinga <slouken@libsdl.org>
parents: 2049
diff changeset
    82
                devcount);
2049
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    83
        devcount = 64;
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    84
    }
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    85
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    86
    spec.callback = play_through_once;
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    87
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    88
    for (i = 0; i < devcount; i++) {
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    89
        const char *devname = SDL_GetAudioDeviceName(i, 0);
7639
9406b7dd2f2d Fix bug 2034: replace printf by SDL_Log in tests; update loopwave VS solution: copy missing dependency
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 7517
diff changeset
    90
        SDL_Log("playing on device #%d: ('%s')...", i, devname);
2049
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    91
        fflush(stdout);
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    92
2146
9fcde304c7b6 Replaced a few memset/memcpy calls with SDL_memset/SDL_memcpy.
Ryan C. Gordon <icculus@icculus.org>
parents: 2060
diff changeset
    93
        SDL_memset(&cbd[0], '\0', sizeof(callback_data));
2049
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    94
        spec.userdata = &cbd[0];
2867
eec7adc3d1c5 Updated test for API changes
Sam Lantinga <slouken@libsdl.org>
parents: 2146
diff changeset
    95
        cbd[0].dev = SDL_OpenAudioDevice(devname, 0, &spec, NULL, 0);
2049
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    96
        if (cbd[0].dev == 0) {
7639
9406b7dd2f2d Fix bug 2034: replace printf by SDL_Log in tests; update loopwave VS solution: copy missing dependency
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 7517
diff changeset
    97
            SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Open device failed: %s\n", SDL_GetError());
2049
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    98
        } else {
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    99
            SDL_PauseAudioDevice(cbd[0].dev, 0);
9278
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 9269
diff changeset
   100
#ifdef __EMSCRIPTEN__
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 9269
diff changeset
   101
            emscripten_set_main_loop(loop, 0, 1);
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 9269
diff changeset
   102
#else
10003
d91a2c45825e Remove almost all instances of "volatile" keyword.
Ryan C. Gordon <icculus@icculus.org>
parents: 9998
diff changeset
   103
            while (!SDL_AtomicGet(&cbd[0].done)) {
9278
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 9269
diff changeset
   104
                #ifdef __ANDROID__                
9269
d51f84c20b10 Added comments in example program.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents: 9145
diff changeset
   105
                /* Empty queue, some application events would prevent pause. */
9145
aa99e029b12e [Android] Fixes #2480, music does not pause when process backgrounded
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8851
diff changeset
   106
                while (SDL_PollEvent(&event)){}
9278
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 9269
diff changeset
   107
                #endif                
2049
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   108
                SDL_Delay(100);
9145
aa99e029b12e [Android] Fixes #2480, music does not pause when process backgrounded
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8851
diff changeset
   109
            }
2049
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   110
            SDL_PauseAudioDevice(cbd[0].dev, 1);
9278
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 9269
diff changeset
   111
#endif
7639
9406b7dd2f2d Fix bug 2034: replace printf by SDL_Log in tests; update loopwave VS solution: copy missing dependency
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 7517
diff changeset
   112
            SDL_Log("done.\n");
2049
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   113
            SDL_CloseAudioDevice(cbd[0].dev);
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   114
        }
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   115
    }
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   116
2146
9fcde304c7b6 Replaced a few memset/memcpy calls with SDL_memset/SDL_memcpy.
Ryan C. Gordon <icculus@icculus.org>
parents: 2060
diff changeset
   117
    SDL_memset(cbd, '\0', sizeof(cbd));
2049
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   118
7639
9406b7dd2f2d Fix bug 2034: replace printf by SDL_Log in tests; update loopwave VS solution: copy missing dependency
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 7517
diff changeset
   119
    SDL_Log("playing on all devices...\n");
2049
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   120
    for (i = 0; i < devcount; i++) {
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   121
        const char *devname = SDL_GetAudioDeviceName(i, 0);
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   122
        spec.userdata = &cbd[i];
2867
eec7adc3d1c5 Updated test for API changes
Sam Lantinga <slouken@libsdl.org>
parents: 2146
diff changeset
   123
        cbd[i].dev = SDL_OpenAudioDevice(devname, 0, &spec, NULL, 0);
2049
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   124
        if (cbd[i].dev == 0) {
7639
9406b7dd2f2d Fix bug 2034: replace printf by SDL_Log in tests; update loopwave VS solution: copy missing dependency
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 7517
diff changeset
   125
            SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Open device %d failed: %s\n", i, SDL_GetError());
2049
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   126
        }
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   127
    }
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   128
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   129
    for (i = 0; i < devcount; i++) {
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   130
        if (cbd[i].dev) {
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   131
            SDL_PauseAudioDevice(cbd[i].dev, 0);
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   132
        }
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   133
    }
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   134
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   135
    while (keep_going) {
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   136
        keep_going = 0;
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   137
        for (i = 0; i < devcount; i++) {
10003
d91a2c45825e Remove almost all instances of "volatile" keyword.
Ryan C. Gordon <icculus@icculus.org>
parents: 9998
diff changeset
   138
            if ((cbd[i].dev) && (!SDL_AtomicGet(&cbd[i].done))) {
2049
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   139
                keep_going = 1;
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   140
            }
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   141
        }
9278
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 9269
diff changeset
   142
        #ifdef __ANDROID__        
9269
d51f84c20b10 Added comments in example program.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents: 9145
diff changeset
   143
        /* Empty queue, some application events would prevent pause. */
9145
aa99e029b12e [Android] Fixes #2480, music does not pause when process backgrounded
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8851
diff changeset
   144
        while (SDL_PollEvent(&event)){}
9278
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 9269
diff changeset
   145
        #endif        
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 9269
diff changeset
   146
2049
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   147
        SDL_Delay(100);
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   148
    }
9290
fe975b2313fa Fixed compile errors in example programs.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents: 9278
diff changeset
   149
fe975b2313fa Fixed compile errors in example programs.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents: 9278
diff changeset
   150
#ifndef __EMSCRIPTEN__
fe975b2313fa Fixed compile errors in example programs.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents: 9278
diff changeset
   151
    for (i = 0; i < devcount; i++) {
fe975b2313fa Fixed compile errors in example programs.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents: 9278
diff changeset
   152
        if (cbd[i].dev) {
fe975b2313fa Fixed compile errors in example programs.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents: 9278
diff changeset
   153
            SDL_PauseAudioDevice(cbd[i].dev, 1);
fe975b2313fa Fixed compile errors in example programs.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents: 9278
diff changeset
   154
            SDL_CloseAudioDevice(cbd[i].dev);
fe975b2313fa Fixed compile errors in example programs.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents: 9278
diff changeset
   155
        }
fe975b2313fa Fixed compile errors in example programs.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents: 9278
diff changeset
   156
    }
fe975b2313fa Fixed compile errors in example programs.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents: 9278
diff changeset
   157
fe975b2313fa Fixed compile errors in example programs.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents: 9278
diff changeset
   158
    SDL_Log("All done!\n");
fe975b2313fa Fixed compile errors in example programs.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents: 9278
diff changeset
   159
#endif
2049
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   160
}
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   161
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   162
2060
866052b01ee5 indent is evil
Sam Lantinga <slouken@libsdl.org>
parents: 2049
diff changeset
   163
int
866052b01ee5 indent is evil
Sam Lantinga <slouken@libsdl.org>
parents: 2049
diff changeset
   164
main(int argc, char **argv)
2049
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   165
{
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   166
    int devcount = 0;
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   167
9922
b066d5fd5fa7 Replaced tabs with spaces in test programs.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents: 9619
diff changeset
   168
    /* Enable standard application logging */
7639
9406b7dd2f2d Fix bug 2034: replace printf by SDL_Log in tests; update loopwave VS solution: copy missing dependency
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 7517
diff changeset
   169
    SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
9406b7dd2f2d Fix bug 2034: replace printf by SDL_Log in tests; update loopwave VS solution: copy missing dependency
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 7517
diff changeset
   170
2049
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   171
    /* Load the SDL library */
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   172
    if (SDL_Init(SDL_INIT_AUDIO) < 0) {
7639
9406b7dd2f2d Fix bug 2034: replace printf by SDL_Log in tests; update loopwave VS solution: copy missing dependency
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 7517
diff changeset
   173
        SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL: %s\n", SDL_GetError());
2049
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   174
        return (1);
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   175
    }
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   176
7639
9406b7dd2f2d Fix bug 2034: replace printf by SDL_Log in tests; update loopwave VS solution: copy missing dependency
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 7517
diff changeset
   177
    SDL_Log("Using audio driver: %s\n", SDL_GetCurrentAudioDriver());
8834
b300e097899d Adds missing Makefile for NACL test and a couple of smaller fixes
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8787
diff changeset
   178
    
2049
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   179
    devcount = SDL_GetNumAudioDevices(0);
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   180
    if (devcount < 1) {
7639
9406b7dd2f2d Fix bug 2034: replace printf by SDL_Log in tests; update loopwave VS solution: copy missing dependency
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 7517
diff changeset
   181
        SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Don't see any specific audio devices!\n");
2049
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   182
    } else {
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   183
        if (argv[1] == NULL) {
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   184
            argv[1] = "sample.wav";
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   185
        }
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   186
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   187
        /* Load the wave file into memory */
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   188
        if (SDL_LoadWAV(argv[1], &spec, &sound, &soundlen) == NULL) {
7639
9406b7dd2f2d Fix bug 2034: replace printf by SDL_Log in tests; update loopwave VS solution: copy missing dependency
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 7517
diff changeset
   189
            SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't load %s: %s\n", argv[1],
2060
866052b01ee5 indent is evil
Sam Lantinga <slouken@libsdl.org>
parents: 2049
diff changeset
   190
                    SDL_GetError());
2049
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   191
        } else {
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   192
            test_multi_audio(devcount);
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   193
            SDL_FreeWAV(sound);
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   194
        }
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   195
    }
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   196
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   197
    SDL_Quit();
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   198
    return 0;
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   199
}