src/audio/SDL_audio.c
author Ryan C. Gordon <icculus@icculus.org>
Mon, 16 Mar 2015 02:11:39 -0400
changeset 9393 ed79a66e57e5
parent 9392 92e23eff9b89
child 9394 bb28e5281770
permissions -rw-r--r--
Initial work on audio device hotplug support. This fills in the core pieces and fully implements it for Mac OS X. Most other platforms, at the moment, will report a disconnected device if it fails to write audio, but don't notice if the system's device list changed at all.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
     1
/*
5535
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5526
diff changeset
     2
  Simple DirectMedia Layer
8149
681eb46b8ac4 Fixed bug 2374 - Update copyright for 2014...
Sam Lantinga <slouken@libsdl.org>
parents: 8094
diff changeset
     3
  Copyright (C) 1997-2014 Sam Lantinga <slouken@libsdl.org>
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
     4
5535
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5526
diff changeset
     5
  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: 5526
diff changeset
     6
  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: 5526
diff changeset
     7
  arising from the use of this software.
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
     8
5535
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5526
diff changeset
     9
  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: 5526
diff changeset
    10
  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: 5526
diff changeset
    11
  freely, subject to the following restrictions:
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    12
5535
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5526
diff changeset
    13
  1. The origin of this software must not be misrepresented; you must not
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5526
diff changeset
    14
     claim that you wrote the original software. If you use this software
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5526
diff changeset
    15
     in a product, an acknowledgment in the product documentation would be
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5526
diff changeset
    16
     appreciated but is not required.
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5526
diff changeset
    17
  2. Altered source versions must be plainly marked as such, and must not be
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5526
diff changeset
    18
     misrepresented as being the original software.
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5526
diff changeset
    19
  3. This notice may not be removed or altered from any source distribution.
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    20
*/
8093
b43765095a6f Make internal SDL sources include SDL_internal.h instead of SDL_config.h
Ryan C. Gordon <icculus@icculus.org>
parents: 7981
diff changeset
    21
#include "../SDL_internal.h"
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    22
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    23
/* Allow access to a raw mixing buffer */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    24
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    25
#include "SDL.h"
2984
0b160c970b7e Fixed some dependency issues with SDL_revision.h
Sam Lantinga <slouken@libsdl.org>
parents: 2979
diff changeset
    26
#include "SDL_audio.h"
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    27
#include "SDL_audio_c.h"
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    28
#include "SDL_audiomem.h"
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    29
#include "SDL_sysaudio.h"
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    30
4865
fff50e86c891 Update VS2010 project to add new files; update new files so code builds on Win32/Win64
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 4729
diff changeset
    31
#define _THIS SDL_AudioDevice *_this
2049
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
    32
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
    33
static SDL_AudioDriver current_audio;
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
    34
static SDL_AudioDevice *open_devices[16];
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
    35
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
    36
/* !!! FIXME: These are wordy and unlocalized... */
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
    37
#define DEFAULT_OUTPUT_DEVNAME "System audio output device"
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
    38
#define DEFAULT_INPUT_DEVNAME "System audio capture device"
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
    39
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
    40
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
    41
/*
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
    42
 * Not all of these will be compiled and linked in, but it's convenient
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
    43
 *  to have a complete list here and saves yet-another block of #ifdefs...
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
    44
 *  Please see bootstrap[], below, for the actual #ifdef mess.
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
    45
 */
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
    46
extern AudioBootStrap BSD_AUDIO_bootstrap;
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
    47
extern AudioBootStrap DSP_bootstrap;
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
    48
extern AudioBootStrap ALSA_bootstrap;
2271
60b4c52a7906 Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2147
diff changeset
    49
extern AudioBootStrap PULSEAUDIO_bootstrap;
3099
82e60908fab1 Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 3096
diff changeset
    50
extern AudioBootStrap QSAAUDIO_bootstrap;
2049
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
    51
extern AudioBootStrap SUNAUDIO_bootstrap;
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
    52
extern AudioBootStrap ARTS_bootstrap;
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
    53
extern AudioBootStrap ESD_bootstrap;
8833
ae720d61d14d Chrome's Native Client backend implementation
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8761
diff changeset
    54
extern AudioBootStrap NACLAUD_bootstrap;
2049
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
    55
extern AudioBootStrap NAS_bootstrap;
5592
2e88d0742f4d Implemented XAudio2 target for Windows (and Xbox360, theoretically!).
Ryan C. Gordon <icculus@icculus.org>
parents: 5588
diff changeset
    56
extern AudioBootStrap XAUDIO2_bootstrap;
2049
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
    57
extern AudioBootStrap DSOUND_bootstrap;
5588
57bfc2a2a452 Reworked Windows waveOut code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5586
diff changeset
    58
extern AudioBootStrap WINMM_bootstrap;
2049
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
    59
extern AudioBootStrap PAUDIO_bootstrap;
7981
6d538bc1b395 Renamed things named after BeOS to be named after Haiku instead.
Ryan C. Gordon <icculus@icculus.org>
parents: 7904
diff changeset
    60
extern AudioBootStrap HAIKUAUDIO_bootstrap;
2049
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
    61
extern AudioBootStrap COREAUDIO_bootstrap;
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
    62
extern AudioBootStrap SNDMGR_bootstrap;
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
    63
extern AudioBootStrap DISKAUD_bootstrap;
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
    64
extern AudioBootStrap DUMMYAUD_bootstrap;
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
    65
extern AudioBootStrap DCAUD_bootstrap;
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
    66
extern AudioBootStrap DART_bootstrap;
2735
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2728
diff changeset
    67
extern AudioBootStrap NDSAUD_bootstrap;
2947
fec0db6c44b7 Date: Thu, 01 Jan 2009 21:32:12 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2942
diff changeset
    68
extern AudioBootStrap FUSIONSOUND_bootstrap;
4718
79aa6c61f33b Added stub android sound system
Paul Hunkin <paul@bieh.net>
parents: 3699
diff changeset
    69
extern AudioBootStrap ANDROIDAUD_bootstrap;
7009
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents: 6977
diff changeset
    70
extern AudioBootStrap PSPAUD_bootstrap;
7367
d6eabafa8776 Added an SDL2 OpenBSD sndio(7) audio target.
Ryan C. Gordon <icculus@icculus.org>
parents: 7348
diff changeset
    71
extern AudioBootStrap SNDIO_bootstrap;
9278
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 9148
diff changeset
    72
extern AudioBootStrap EmscriptenAudio_bootstrap;
1190
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents: 955
diff changeset
    73
8833
ae720d61d14d Chrome's Native Client backend implementation
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8761
diff changeset
    74
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    75
/* Available audio drivers */
3162
dc1eb82ffdaa Von: Thomas Zimmermann
Sam Lantinga <slouken@libsdl.org>
parents: 3139
diff changeset
    76
static const AudioBootStrap *const bootstrap[] = {
2939
084e5b4fc5be Audio driver priority: favor PulseAudio and ALSA over OSS.
Ryan C. Gordon <icculus@icculus.org>
parents: 2938
diff changeset
    77
#if SDL_AUDIO_DRIVER_PULSEAUDIO
084e5b4fc5be Audio driver priority: favor PulseAudio and ALSA over OSS.
Ryan C. Gordon <icculus@icculus.org>
parents: 2938
diff changeset
    78
    &PULSEAUDIO_bootstrap,
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    79
#endif
1361
19418e4422cb New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents: 1358
diff changeset
    80
#if SDL_AUDIO_DRIVER_ALSA
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1794
diff changeset
    81
    &ALSA_bootstrap,
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    82
#endif
7367
d6eabafa8776 Added an SDL2 OpenBSD sndio(7) audio target.
Ryan C. Gordon <icculus@icculus.org>
parents: 7348
diff changeset
    83
#if SDL_AUDIO_DRIVER_SNDIO
d6eabafa8776 Added an SDL2 OpenBSD sndio(7) audio target.
Ryan C. Gordon <icculus@icculus.org>
parents: 7348
diff changeset
    84
    &SNDIO_bootstrap,
d6eabafa8776 Added an SDL2 OpenBSD sndio(7) audio target.
Ryan C. Gordon <icculus@icculus.org>
parents: 7348
diff changeset
    85
#endif
4548
b135d19f9764 RedHat patch: SDL-1.2.14-audiodriver.patch
Sam Lantinga <slouken@libsdl.org>
parents: 4507
diff changeset
    86
#if SDL_AUDIO_DRIVER_BSD
b135d19f9764 RedHat patch: SDL-1.2.14-audiodriver.patch
Sam Lantinga <slouken@libsdl.org>
parents: 4507
diff changeset
    87
    &BSD_AUDIO_bootstrap,
b135d19f9764 RedHat patch: SDL-1.2.14-audiodriver.patch
Sam Lantinga <slouken@libsdl.org>
parents: 4507
diff changeset
    88
#endif
2939
084e5b4fc5be Audio driver priority: favor PulseAudio and ALSA over OSS.
Ryan C. Gordon <icculus@icculus.org>
parents: 2938
diff changeset
    89
#if SDL_AUDIO_DRIVER_OSS
084e5b4fc5be Audio driver priority: favor PulseAudio and ALSA over OSS.
Ryan C. Gordon <icculus@icculus.org>
parents: 2938
diff changeset
    90
    &DSP_bootstrap,
2271
60b4c52a7906 Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2147
diff changeset
    91
#endif
3099
82e60908fab1 Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 3096
diff changeset
    92
#if SDL_AUDIO_DRIVER_QSA
82e60908fab1 Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 3096
diff changeset
    93
    &QSAAUDIO_bootstrap,
663
8bedd6d61642 Date: Sat, 2 Aug 2003 16:22:51 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 654
diff changeset
    94
#endif
1361
19418e4422cb New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents: 1358
diff changeset
    95
#if SDL_AUDIO_DRIVER_SUNAUDIO
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1794
diff changeset
    96
    &SUNAUDIO_bootstrap,
148
8758b8d42cd9 Audio subsystem no longer assumes sun audio API on UNIX systems
Sam Lantinga <slouken@libsdl.org>
parents: 121
diff changeset
    97
#endif
1361
19418e4422cb New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents: 1358
diff changeset
    98
#if SDL_AUDIO_DRIVER_ARTS
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1794
diff changeset
    99
    &ARTS_bootstrap,
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   100
#endif
1361
19418e4422cb New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents: 1358
diff changeset
   101
#if SDL_AUDIO_DRIVER_ESD
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1794
diff changeset
   102
    &ESD_bootstrap,
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   103
#endif
8833
ae720d61d14d Chrome's Native Client backend implementation
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8761
diff changeset
   104
#if SDL_AUDIO_DRIVER_NACL
ae720d61d14d Chrome's Native Client backend implementation
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8761
diff changeset
   105
   &NACLAUD_bootstrap,
ae720d61d14d Chrome's Native Client backend implementation
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8761
diff changeset
   106
#endif
1361
19418e4422cb New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents: 1358
diff changeset
   107
#if SDL_AUDIO_DRIVER_NAS
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1794
diff changeset
   108
    &NAS_bootstrap,
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   109
#endif
5592
2e88d0742f4d Implemented XAudio2 target for Windows (and Xbox360, theoretically!).
Ryan C. Gordon <icculus@icculus.org>
parents: 5588
diff changeset
   110
#if SDL_AUDIO_DRIVER_XAUDIO2
2e88d0742f4d Implemented XAudio2 target for Windows (and Xbox360, theoretically!).
Ryan C. Gordon <icculus@icculus.org>
parents: 5588
diff changeset
   111
    &XAUDIO2_bootstrap,
2e88d0742f4d Implemented XAudio2 target for Windows (and Xbox360, theoretically!).
Ryan C. Gordon <icculus@icculus.org>
parents: 5588
diff changeset
   112
#endif
1361
19418e4422cb New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents: 1358
diff changeset
   113
#if SDL_AUDIO_DRIVER_DSOUND
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1794
diff changeset
   114
    &DSOUND_bootstrap,
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   115
#endif
5588
57bfc2a2a452 Reworked Windows waveOut code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5586
diff changeset
   116
#if SDL_AUDIO_DRIVER_WINMM
57bfc2a2a452 Reworked Windows waveOut code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5586
diff changeset
   117
    &WINMM_bootstrap,
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   118
#endif
2049
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
   119
#if SDL_AUDIO_DRIVER_PAUDIO
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
   120
    &PAUDIO_bootstrap,
1361
19418e4422cb New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents: 1358
diff changeset
   121
#endif
7981
6d538bc1b395 Renamed things named after BeOS to be named after Haiku instead.
Ryan C. Gordon <icculus@icculus.org>
parents: 7904
diff changeset
   122
#if SDL_AUDIO_DRIVER_HAIKU
6d538bc1b395 Renamed things named after BeOS to be named after Haiku instead.
Ryan C. Gordon <icculus@icculus.org>
parents: 7904
diff changeset
   123
    &HAIKUAUDIO_bootstrap,
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   124
#endif
1361
19418e4422cb New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents: 1358
diff changeset
   125
#if SDL_AUDIO_DRIVER_COREAUDIO
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1794
diff changeset
   126
    &COREAUDIO_bootstrap,
935
f8d5ddc7aef1 Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
Sam Lantinga <slouken@libsdl.org>
parents: 808
diff changeset
   127
#endif
1361
19418e4422cb New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents: 1358
diff changeset
   128
#if SDL_AUDIO_DRIVER_DISK
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1794
diff changeset
   129
    &DISKAUD_bootstrap,
68
ac6645260d31 Added an audio driver that writes to disk (thanks Ryan!)
Sam Lantinga <slouken@lokigames.com>
parents: 38
diff changeset
   130
#endif
1532
30f189cdd82b Implemented dummy audio driver.
Ryan C. Gordon <icculus@icculus.org>
parents: 1487
diff changeset
   131
#if SDL_AUDIO_DRIVER_DUMMY
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1794
diff changeset
   132
    &DUMMYAUD_bootstrap,
1532
30f189cdd82b Implemented dummy audio driver.
Ryan C. Gordon <icculus@icculus.org>
parents: 1487
diff changeset
   133
#endif
2947
fec0db6c44b7 Date: Thu, 01 Jan 2009 21:32:12 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2942
diff changeset
   134
#if SDL_AUDIO_DRIVER_FUSIONSOUND
fec0db6c44b7 Date: Thu, 01 Jan 2009 21:32:12 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2942
diff changeset
   135
    &FUSIONSOUND_bootstrap,
fec0db6c44b7 Date: Thu, 01 Jan 2009 21:32:12 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2942
diff changeset
   136
#endif
4718
79aa6c61f33b Added stub android sound system
Paul Hunkin <paul@bieh.net>
parents: 3699
diff changeset
   137
#if SDL_AUDIO_DRIVER_ANDROID
79aa6c61f33b Added stub android sound system
Paul Hunkin <paul@bieh.net>
parents: 3699
diff changeset
   138
    &ANDROIDAUD_bootstrap,
79aa6c61f33b Added stub android sound system
Paul Hunkin <paul@bieh.net>
parents: 3699
diff changeset
   139
#endif
7009
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents: 6977
diff changeset
   140
#if SDL_AUDIO_DRIVER_PSP
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents: 6977
diff changeset
   141
    &PSPAUD_bootstrap,
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents: 6977
diff changeset
   142
#endif
9278
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 9148
diff changeset
   143
#if SDL_AUDIO_DRIVER_EMSCRIPTEN
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 9148
diff changeset
   144
    &EmscriptenAudio_bootstrap,
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 9148
diff changeset
   145
#endif
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1794
diff changeset
   146
    NULL
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   147
};
2049
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
   148
2060
866052b01ee5 indent is evil
Sam Lantinga <slouken@libsdl.org>
parents: 2053
diff changeset
   149
static SDL_AudioDevice *
866052b01ee5 indent is evil
Sam Lantinga <slouken@libsdl.org>
parents: 2053
diff changeset
   150
get_audio_device(SDL_AudioDeviceID id)
2049
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
   151
{
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
   152
    id--;
2060
866052b01ee5 indent is evil
Sam Lantinga <slouken@libsdl.org>
parents: 2053
diff changeset
   153
    if ((id >= SDL_arraysize(open_devices)) || (open_devices[id] == NULL)) {
2049
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
   154
        SDL_SetError("Invalid audio device ID");
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
   155
        return NULL;
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
   156
    }
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
   157
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
   158
    return open_devices[id];
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
   159
}
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
   160
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
   161
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
   162
/* stubs for audio drivers that don't need a specific entry point... */
5593
ab22ca13c47f Cleaned up audio device detection. Cleared out a lot of cut-and-paste.
Ryan C. Gordon <icculus@icculus.org>
parents: 5592
diff changeset
   163
static void
ab22ca13c47f Cleaned up audio device detection. Cleared out a lot of cut-and-paste.
Ryan C. Gordon <icculus@icculus.org>
parents: 5592
diff changeset
   164
SDL_AudioDetectDevices_Default(int iscapture, SDL_AddAudioDevice addfn)
ab22ca13c47f Cleaned up audio device detection. Cleared out a lot of cut-and-paste.
Ryan C. Gordon <icculus@icculus.org>
parents: 5592
diff changeset
   165
{                               /* no-op. */
2060
866052b01ee5 indent is evil
Sam Lantinga <slouken@libsdl.org>
parents: 2053
diff changeset
   166
}
2735
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2728
diff changeset
   167
2060
866052b01ee5 indent is evil
Sam Lantinga <slouken@libsdl.org>
parents: 2053
diff changeset
   168
static void
866052b01ee5 indent is evil
Sam Lantinga <slouken@libsdl.org>
parents: 2053
diff changeset
   169
SDL_AudioThreadInit_Default(_THIS)
866052b01ee5 indent is evil
Sam Lantinga <slouken@libsdl.org>
parents: 2053
diff changeset
   170
{                               /* no-op. */
866052b01ee5 indent is evil
Sam Lantinga <slouken@libsdl.org>
parents: 2053
diff changeset
   171
}
2735
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2728
diff changeset
   172
2060
866052b01ee5 indent is evil
Sam Lantinga <slouken@libsdl.org>
parents: 2053
diff changeset
   173
static void
866052b01ee5 indent is evil
Sam Lantinga <slouken@libsdl.org>
parents: 2053
diff changeset
   174
SDL_AudioWaitDevice_Default(_THIS)
866052b01ee5 indent is evil
Sam Lantinga <slouken@libsdl.org>
parents: 2053
diff changeset
   175
{                               /* no-op. */
866052b01ee5 indent is evil
Sam Lantinga <slouken@libsdl.org>
parents: 2053
diff changeset
   176
}
2735
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2728
diff changeset
   177
2060
866052b01ee5 indent is evil
Sam Lantinga <slouken@libsdl.org>
parents: 2053
diff changeset
   178
static void
866052b01ee5 indent is evil
Sam Lantinga <slouken@libsdl.org>
parents: 2053
diff changeset
   179
SDL_AudioPlayDevice_Default(_THIS)
866052b01ee5 indent is evil
Sam Lantinga <slouken@libsdl.org>
parents: 2053
diff changeset
   180
{                               /* no-op. */
866052b01ee5 indent is evil
Sam Lantinga <slouken@libsdl.org>
parents: 2053
diff changeset
   181
}
2735
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2728
diff changeset
   182
9031
e963a13a720c Added a GetPendingBytes method to the audio backend.
Ryan C. Gordon <icculus@icculus.org>
parents: 9012
diff changeset
   183
static int
e963a13a720c Added a GetPendingBytes method to the audio backend.
Ryan C. Gordon <icculus@icculus.org>
parents: 9012
diff changeset
   184
SDL_AudioGetPendingBytes_Default(_THIS)
e963a13a720c Added a GetPendingBytes method to the audio backend.
Ryan C. Gordon <icculus@icculus.org>
parents: 9012
diff changeset
   185
{
e963a13a720c Added a GetPendingBytes method to the audio backend.
Ryan C. Gordon <icculus@icculus.org>
parents: 9012
diff changeset
   186
    return 0;
e963a13a720c Added a GetPendingBytes method to the audio backend.
Ryan C. Gordon <icculus@icculus.org>
parents: 9012
diff changeset
   187
}
e963a13a720c Added a GetPendingBytes method to the audio backend.
Ryan C. Gordon <icculus@icculus.org>
parents: 9012
diff changeset
   188
2060
866052b01ee5 indent is evil
Sam Lantinga <slouken@libsdl.org>
parents: 2053
diff changeset
   189
static Uint8 *
866052b01ee5 indent is evil
Sam Lantinga <slouken@libsdl.org>
parents: 2053
diff changeset
   190
SDL_AudioGetDeviceBuf_Default(_THIS)
866052b01ee5 indent is evil
Sam Lantinga <slouken@libsdl.org>
parents: 2053
diff changeset
   191
{
866052b01ee5 indent is evil
Sam Lantinga <slouken@libsdl.org>
parents: 2053
diff changeset
   192
    return NULL;
866052b01ee5 indent is evil
Sam Lantinga <slouken@libsdl.org>
parents: 2053
diff changeset
   193
}
2735
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2728
diff changeset
   194
2060
866052b01ee5 indent is evil
Sam Lantinga <slouken@libsdl.org>
parents: 2053
diff changeset
   195
static void
866052b01ee5 indent is evil
Sam Lantinga <slouken@libsdl.org>
parents: 2053
diff changeset
   196
SDL_AudioWaitDone_Default(_THIS)
866052b01ee5 indent is evil
Sam Lantinga <slouken@libsdl.org>
parents: 2053
diff changeset
   197
{                               /* no-op. */
866052b01ee5 indent is evil
Sam Lantinga <slouken@libsdl.org>
parents: 2053
diff changeset
   198
}
2735
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2728
diff changeset
   199
2060
866052b01ee5 indent is evil
Sam Lantinga <slouken@libsdl.org>
parents: 2053
diff changeset
   200
static void
866052b01ee5 indent is evil
Sam Lantinga <slouken@libsdl.org>
parents: 2053
diff changeset
   201
SDL_AudioCloseDevice_Default(_THIS)
866052b01ee5 indent is evil
Sam Lantinga <slouken@libsdl.org>
parents: 2053
diff changeset
   202
{                               /* no-op. */
866052b01ee5 indent is evil
Sam Lantinga <slouken@libsdl.org>
parents: 2053
diff changeset
   203
}
2735
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2728
diff changeset
   204
2060
866052b01ee5 indent is evil
Sam Lantinga <slouken@libsdl.org>
parents: 2053
diff changeset
   205
static void
866052b01ee5 indent is evil
Sam Lantinga <slouken@libsdl.org>
parents: 2053
diff changeset
   206
SDL_AudioDeinitialize_Default(void)
866052b01ee5 indent is evil
Sam Lantinga <slouken@libsdl.org>
parents: 2053
diff changeset
   207
{                               /* no-op. */
866052b01ee5 indent is evil
Sam Lantinga <slouken@libsdl.org>
parents: 2053
diff changeset
   208
}
2049
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
   209
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
   210
static int
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
   211
SDL_AudioOpenDevice_Default(_THIS, const char *devname, int iscapture)
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
   212
{
7038
7f22b9ba218f Changed audio subsystem's OpenDevice interface to return -1 on error.
Ryan C. Gordon <icculus@icculus.org>
parents: 7011
diff changeset
   213
    return -1;
2049
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
   214
}
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
   215
9010
6d059ed9b6ca Clarifying hard-to-understand piece of code.
Ryan C. Gordon <icculus@icculus.org>
parents: 8919
diff changeset
   216
static SDL_INLINE SDL_bool
6d059ed9b6ca Clarifying hard-to-understand piece of code.
Ryan C. Gordon <icculus@icculus.org>
parents: 8919
diff changeset
   217
is_in_audio_device_thread(SDL_AudioDevice * device)
6d059ed9b6ca Clarifying hard-to-understand piece of code.
Ryan C. Gordon <icculus@icculus.org>
parents: 8919
diff changeset
   218
{
6d059ed9b6ca Clarifying hard-to-understand piece of code.
Ryan C. Gordon <icculus@icculus.org>
parents: 8919
diff changeset
   219
    /* The device thread locks the same mutex, but not through the public API.
6d059ed9b6ca Clarifying hard-to-understand piece of code.
Ryan C. Gordon <icculus@icculus.org>
parents: 8919
diff changeset
   220
       This check is in case the application, in the audio callback,
6d059ed9b6ca Clarifying hard-to-understand piece of code.
Ryan C. Gordon <icculus@icculus.org>
parents: 8919
diff changeset
   221
       tries to lock the thread that we've already locked from the
6d059ed9b6ca Clarifying hard-to-understand piece of code.
Ryan C. Gordon <icculus@icculus.org>
parents: 8919
diff changeset
   222
       device thread...just in case we only have non-recursive mutexes. */
6d059ed9b6ca Clarifying hard-to-understand piece of code.
Ryan C. Gordon <icculus@icculus.org>
parents: 8919
diff changeset
   223
    if (device->thread && (SDL_ThreadID() == device->threadid)) {
6d059ed9b6ca Clarifying hard-to-understand piece of code.
Ryan C. Gordon <icculus@icculus.org>
parents: 8919
diff changeset
   224
        return SDL_TRUE;
6d059ed9b6ca Clarifying hard-to-understand piece of code.
Ryan C. Gordon <icculus@icculus.org>
parents: 8919
diff changeset
   225
    }
6d059ed9b6ca Clarifying hard-to-understand piece of code.
Ryan C. Gordon <icculus@icculus.org>
parents: 8919
diff changeset
   226
6d059ed9b6ca Clarifying hard-to-understand piece of code.
Ryan C. Gordon <icculus@icculus.org>
parents: 8919
diff changeset
   227
    return SDL_FALSE;
6d059ed9b6ca Clarifying hard-to-understand piece of code.
Ryan C. Gordon <icculus@icculus.org>
parents: 8919
diff changeset
   228
}
6d059ed9b6ca Clarifying hard-to-understand piece of code.
Ryan C. Gordon <icculus@icculus.org>
parents: 8919
diff changeset
   229
2049
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
   230
static void
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
   231
SDL_AudioLockDevice_Default(SDL_AudioDevice * device)
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
   232
{
9010
6d059ed9b6ca Clarifying hard-to-understand piece of code.
Ryan C. Gordon <icculus@icculus.org>
parents: 8919
diff changeset
   233
    if (!is_in_audio_device_thread(device)) {
6d059ed9b6ca Clarifying hard-to-understand piece of code.
Ryan C. Gordon <icculus@icculus.org>
parents: 8919
diff changeset
   234
        SDL_LockMutex(device->mixer_lock);
2049
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
   235
    }
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
   236
}
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
   237
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
   238
static void
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
   239
SDL_AudioUnlockDevice_Default(SDL_AudioDevice * device)
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
   240
{
9010
6d059ed9b6ca Clarifying hard-to-understand piece of code.
Ryan C. Gordon <icculus@icculus.org>
parents: 8919
diff changeset
   241
    if (!is_in_audio_device_thread(device)) {
6d059ed9b6ca Clarifying hard-to-understand piece of code.
Ryan C. Gordon <icculus@icculus.org>
parents: 8919
diff changeset
   242
        SDL_UnlockMutex(device->mixer_lock);
2049
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
   243
    }
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
   244
}
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
   245
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   246
2060
866052b01ee5 indent is evil
Sam Lantinga <slouken@libsdl.org>
parents: 2053
diff changeset
   247
static void
866052b01ee5 indent is evil
Sam Lantinga <slouken@libsdl.org>
parents: 2053
diff changeset
   248
finalize_audio_entry_points(void)
2049
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
   249
{
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
   250
    /*
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
   251
     * Fill in stub functions for unused driver entry points. This lets us
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
   252
     *  blindly call them without having to check for validity first.
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
   253
     */
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
   254
2060
866052b01ee5 indent is evil
Sam Lantinga <slouken@libsdl.org>
parents: 2053
diff changeset
   255
#define FILL_STUB(x) \
2049
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
   256
        if (current_audio.impl.x == NULL) { \
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
   257
            current_audio.impl.x = SDL_Audio##x##_Default; \
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
   258
        }
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
   259
    FILL_STUB(DetectDevices);
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
   260
    FILL_STUB(OpenDevice);
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
   261
    FILL_STUB(ThreadInit);
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
   262
    FILL_STUB(WaitDevice);
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
   263
    FILL_STUB(PlayDevice);
9031
e963a13a720c Added a GetPendingBytes method to the audio backend.
Ryan C. Gordon <icculus@icculus.org>
parents: 9012
diff changeset
   264
    FILL_STUB(GetPendingBytes);
2049
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
   265
    FILL_STUB(GetDeviceBuf);
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
   266
    FILL_STUB(WaitDone);
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
   267
    FILL_STUB(CloseDevice);
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
   268
    FILL_STUB(LockDevice);
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
   269
    FILL_STUB(UnlockDevice);
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
   270
    FILL_STUB(Deinitialize);
2060
866052b01ee5 indent is evil
Sam Lantinga <slouken@libsdl.org>
parents: 2053
diff changeset
   271
#undef FILL_STUB
2049
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
   272
}
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
   273
8660
6bd1f8bad873 Patched to compile on C89 compilers, removed more streamer code.
Ryan C. Gordon <icculus@icculus.org>
parents: 8658
diff changeset
   274
#if 0  /* !!! FIXME: rewrite/remove this streamer code. */
2716
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   275
/* Streaming functions (for when the input and output buffer sizes are different) */
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   276
/* Write [length] bytes from buf into the streamer */
4472
791b3256fb22 Mostly cleaned up warnings with -Wmissing-prototypes
Sam Lantinga <slouken@libsdl.org>
parents: 3699
diff changeset
   277
static void
2716
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   278
SDL_StreamWrite(SDL_AudioStreamer * stream, Uint8 * buf, int length)
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   279
{
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   280
    int i;
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   281
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   282
    for (i = 0; i < length; ++i) {
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   283
        stream->buffer[stream->write_pos] = buf[i];
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   284
        ++stream->write_pos;
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   285
    }
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   286
}
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   287
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   288
/* Read [length] bytes out of the streamer into buf */
4472
791b3256fb22 Mostly cleaned up warnings with -Wmissing-prototypes
Sam Lantinga <slouken@libsdl.org>
parents: 3699
diff changeset
   289
static void
2716
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   290
SDL_StreamRead(SDL_AudioStreamer * stream, Uint8 * buf, int length)
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   291
{
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   292
    int i;
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   293
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   294
    for (i = 0; i < length; ++i) {
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   295
        buf[i] = stream->buffer[stream->read_pos];
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   296
        ++stream->read_pos;
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   297
    }
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   298
}
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   299
4472
791b3256fb22 Mostly cleaned up warnings with -Wmissing-prototypes
Sam Lantinga <slouken@libsdl.org>
parents: 3699
diff changeset
   300
static int
2716
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   301
SDL_StreamLength(SDL_AudioStreamer * stream)
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   302
{
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   303
    return (stream->write_pos - stream->read_pos) % stream->max_len;
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   304
}
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   305
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   306
/* Initialize the stream by allocating the buffer and setting the read/write heads to the beginning */
4507
dbf3fa541096 Fixed compile warnings
Sam Lantinga <slouken@libsdl.org>
parents: 4472
diff changeset
   307
#if 0
4472
791b3256fb22 Mostly cleaned up warnings with -Wmissing-prototypes
Sam Lantinga <slouken@libsdl.org>
parents: 3699
diff changeset
   308
static int
2716
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   309
SDL_StreamInit(SDL_AudioStreamer * stream, int max_len, Uint8 silence)
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   310
{
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   311
    /* First try to allocate the buffer */
2728
2768bd7281e0 Fixed Visual Studio compilation problems
Sam Lantinga <slouken@libsdl.org>
parents: 2716
diff changeset
   312
    stream->buffer = (Uint8 *) SDL_malloc(max_len);
2716
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   313
    if (stream->buffer == NULL) {
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   314
        return -1;
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   315
    }
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   316
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   317
    stream->max_len = max_len;
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   318
    stream->read_pos = 0;
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   319
    stream->write_pos = 0;
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   320
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   321
    /* Zero out the buffer */
2728
2768bd7281e0 Fixed Visual Studio compilation problems
Sam Lantinga <slouken@libsdl.org>
parents: 2716
diff changeset
   322
    SDL_memset(stream->buffer, silence, max_len);
2768bd7281e0 Fixed Visual Studio compilation problems
Sam Lantinga <slouken@libsdl.org>
parents: 2716
diff changeset
   323
2768bd7281e0 Fixed Visual Studio compilation problems
Sam Lantinga <slouken@libsdl.org>
parents: 2716
diff changeset
   324
    return 0;
2716
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   325
}
4507
dbf3fa541096 Fixed compile warnings
Sam Lantinga <slouken@libsdl.org>
parents: 4472
diff changeset
   326
#endif
2716
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   327
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   328
/* Deinitialize the stream simply by freeing the buffer */
4472
791b3256fb22 Mostly cleaned up warnings with -Wmissing-prototypes
Sam Lantinga <slouken@libsdl.org>
parents: 3699
diff changeset
   329
static void
2716
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   330
SDL_StreamDeinit(SDL_AudioStreamer * stream)
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   331
{
7719
31b5f9ff36ca Christoph Mallon: Remove pointless if (x) before SDL_free(x)
Sam Lantinga <slouken@libsdl.org>
parents: 7678
diff changeset
   332
    SDL_free(stream->buffer);
2716
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   333
}
8660
6bd1f8bad873 Patched to compile on C89 compilers, removed more streamer code.
Ryan C. Gordon <icculus@icculus.org>
parents: 8658
diff changeset
   334
#endif
2716
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   335
9393
ed79a66e57e5 Initial work on audio device hotplug support.
Ryan C. Gordon <icculus@icculus.org>
parents: 9392
diff changeset
   336
/* device hotplug support... */
ed79a66e57e5 Initial work on audio device hotplug support.
Ryan C. Gordon <icculus@icculus.org>
parents: 9392
diff changeset
   337
ed79a66e57e5 Initial work on audio device hotplug support.
Ryan C. Gordon <icculus@icculus.org>
parents: 9392
diff changeset
   338
/* this function expects its caller to hold current_audio.detection_lock */
ed79a66e57e5 Initial work on audio device hotplug support.
Ryan C. Gordon <icculus@icculus.org>
parents: 9392
diff changeset
   339
static int
ed79a66e57e5 Initial work on audio device hotplug support.
Ryan C. Gordon <icculus@icculus.org>
parents: 9392
diff changeset
   340
add_audio_device(const char *_name, char ***_devices, int *_devCount)
ed79a66e57e5 Initial work on audio device hotplug support.
Ryan C. Gordon <icculus@icculus.org>
parents: 9392
diff changeset
   341
{
ed79a66e57e5 Initial work on audio device hotplug support.
Ryan C. Gordon <icculus@icculus.org>
parents: 9392
diff changeset
   342
    char *name = SDL_strdup(_name);
ed79a66e57e5 Initial work on audio device hotplug support.
Ryan C. Gordon <icculus@icculus.org>
parents: 9392
diff changeset
   343
    int retval = -1;
ed79a66e57e5 Initial work on audio device hotplug support.
Ryan C. Gordon <icculus@icculus.org>
parents: 9392
diff changeset
   344
ed79a66e57e5 Initial work on audio device hotplug support.
Ryan C. Gordon <icculus@icculus.org>
parents: 9392
diff changeset
   345
    if (name != NULL) {
ed79a66e57e5 Initial work on audio device hotplug support.
Ryan C. Gordon <icculus@icculus.org>
parents: 9392
diff changeset
   346
        char **devices = *_devices;
ed79a66e57e5 Initial work on audio device hotplug support.
Ryan C. Gordon <icculus@icculus.org>
parents: 9392
diff changeset
   347
        int devCount = *_devCount;
ed79a66e57e5 Initial work on audio device hotplug support.
Ryan C. Gordon <icculus@icculus.org>
parents: 9392
diff changeset
   348
        void *ptr = SDL_realloc(devices, (devCount+1) * sizeof(char*));
ed79a66e57e5 Initial work on audio device hotplug support.
Ryan C. Gordon <icculus@icculus.org>
parents: 9392
diff changeset
   349
        if (ptr == NULL) {
ed79a66e57e5 Initial work on audio device hotplug support.
Ryan C. Gordon <icculus@icculus.org>
parents: 9392
diff changeset
   350
            SDL_free(name);
ed79a66e57e5 Initial work on audio device hotplug support.
Ryan C. Gordon <icculus@icculus.org>
parents: 9392
diff changeset
   351
        } else {
ed79a66e57e5 Initial work on audio device hotplug support.
Ryan C. Gordon <icculus@icculus.org>
parents: 9392
diff changeset
   352
            retval = devCount;
ed79a66e57e5 Initial work on audio device hotplug support.
Ryan C. Gordon <icculus@icculus.org>
parents: 9392
diff changeset
   353
            devices = (char **) ptr;
ed79a66e57e5 Initial work on audio device hotplug support.
Ryan C. Gordon <icculus@icculus.org>
parents: 9392
diff changeset
   354
            devices[devCount++] = name;
ed79a66e57e5 Initial work on audio device hotplug support.
Ryan C. Gordon <icculus@icculus.org>
parents: 9392
diff changeset
   355
            *_devices = devices;
ed79a66e57e5 Initial work on audio device hotplug support.
Ryan C. Gordon <icculus@icculus.org>
parents: 9392
diff changeset
   356
            *_devCount = devCount;
ed79a66e57e5 Initial work on audio device hotplug support.
Ryan C. Gordon <icculus@icculus.org>
parents: 9392
diff changeset
   357
        }
ed79a66e57e5 Initial work on audio device hotplug support.
Ryan C. Gordon <icculus@icculus.org>
parents: 9392
diff changeset
   358
    }
ed79a66e57e5 Initial work on audio device hotplug support.
Ryan C. Gordon <icculus@icculus.org>
parents: 9392
diff changeset
   359
ed79a66e57e5 Initial work on audio device hotplug support.
Ryan C. Gordon <icculus@icculus.org>
parents: 9392
diff changeset
   360
    return retval;
ed79a66e57e5 Initial work on audio device hotplug support.
Ryan C. Gordon <icculus@icculus.org>
parents: 9392
diff changeset
   361
}
ed79a66e57e5 Initial work on audio device hotplug support.
Ryan C. Gordon <icculus@icculus.org>
parents: 9392
diff changeset
   362
ed79a66e57e5 Initial work on audio device hotplug support.
Ryan C. Gordon <icculus@icculus.org>
parents: 9392
diff changeset
   363
static int
ed79a66e57e5 Initial work on audio device hotplug support.
Ryan C. Gordon <icculus@icculus.org>
parents: 9392
diff changeset
   364
add_capture_device(const char *name)
ed79a66e57e5 Initial work on audio device hotplug support.
Ryan C. Gordon <icculus@icculus.org>
parents: 9392
diff changeset
   365
{
ed79a66e57e5 Initial work on audio device hotplug support.
Ryan C. Gordon <icculus@icculus.org>
parents: 9392
diff changeset
   366
    /* !!! FIXME: add this later. SDL_assert(current_audio.impl.HasCaptureSupport);*/
ed79a66e57e5 Initial work on audio device hotplug support.
Ryan C. Gordon <icculus@icculus.org>
parents: 9392
diff changeset
   367
    return add_audio_device(name, &current_audio.inputDevices, &current_audio.inputDeviceCount);
ed79a66e57e5 Initial work on audio device hotplug support.
Ryan C. Gordon <icculus@icculus.org>
parents: 9392
diff changeset
   368
}
ed79a66e57e5 Initial work on audio device hotplug support.
Ryan C. Gordon <icculus@icculus.org>
parents: 9392
diff changeset
   369
ed79a66e57e5 Initial work on audio device hotplug support.
Ryan C. Gordon <icculus@icculus.org>
parents: 9392
diff changeset
   370
static int
ed79a66e57e5 Initial work on audio device hotplug support.
Ryan C. Gordon <icculus@icculus.org>
parents: 9392
diff changeset
   371
add_output_device(const char *name)
ed79a66e57e5 Initial work on audio device hotplug support.
Ryan C. Gordon <icculus@icculus.org>
parents: 9392
diff changeset
   372
{
ed79a66e57e5 Initial work on audio device hotplug support.
Ryan C. Gordon <icculus@icculus.org>
parents: 9392
diff changeset
   373
    return add_audio_device(name, &current_audio.outputDevices, &current_audio.outputDeviceCount);
ed79a66e57e5 Initial work on audio device hotplug support.
Ryan C. Gordon <icculus@icculus.org>
parents: 9392
diff changeset
   374
}
ed79a66e57e5 Initial work on audio device hotplug support.
Ryan C. Gordon <icculus@icculus.org>
parents: 9392
diff changeset
   375
ed79a66e57e5 Initial work on audio device hotplug support.
Ryan C. Gordon <icculus@icculus.org>
parents: 9392
diff changeset
   376
static void
ed79a66e57e5 Initial work on audio device hotplug support.
Ryan C. Gordon <icculus@icculus.org>
parents: 9392
diff changeset
   377
free_device_list(char ***devices, int *devCount)
ed79a66e57e5 Initial work on audio device hotplug support.
Ryan C. Gordon <icculus@icculus.org>
parents: 9392
diff changeset
   378
{
ed79a66e57e5 Initial work on audio device hotplug support.
Ryan C. Gordon <icculus@icculus.org>
parents: 9392
diff changeset
   379
    int i = *devCount;
ed79a66e57e5 Initial work on audio device hotplug support.
Ryan C. Gordon <icculus@icculus.org>
parents: 9392
diff changeset
   380
    if ((i > 0) && (*devices != NULL)) {
ed79a66e57e5 Initial work on audio device hotplug support.
Ryan C. Gordon <icculus@icculus.org>
parents: 9392
diff changeset
   381
        while (i--) {
ed79a66e57e5 Initial work on audio device hotplug support.
Ryan C. Gordon <icculus@icculus.org>
parents: 9392
diff changeset
   382
            SDL_free((*devices)[i]);
ed79a66e57e5 Initial work on audio device hotplug support.
Ryan C. Gordon <icculus@icculus.org>
parents: 9392
diff changeset
   383
        }
ed79a66e57e5 Initial work on audio device hotplug support.
Ryan C. Gordon <icculus@icculus.org>
parents: 9392
diff changeset
   384
    }
ed79a66e57e5 Initial work on audio device hotplug support.
Ryan C. Gordon <icculus@icculus.org>
parents: 9392
diff changeset
   385
ed79a66e57e5 Initial work on audio device hotplug support.
Ryan C. Gordon <icculus@icculus.org>
parents: 9392
diff changeset
   386
    SDL_free(*devices);
ed79a66e57e5 Initial work on audio device hotplug support.
Ryan C. Gordon <icculus@icculus.org>
parents: 9392
diff changeset
   387
ed79a66e57e5 Initial work on audio device hotplug support.
Ryan C. Gordon <icculus@icculus.org>
parents: 9392
diff changeset
   388
    *devices = NULL;
ed79a66e57e5 Initial work on audio device hotplug support.
Ryan C. Gordon <icculus@icculus.org>
parents: 9392
diff changeset
   389
    *devCount = 0;
ed79a66e57e5 Initial work on audio device hotplug support.
Ryan C. Gordon <icculus@icculus.org>
parents: 9392
diff changeset
   390
}
ed79a66e57e5 Initial work on audio device hotplug support.
Ryan C. Gordon <icculus@icculus.org>
parents: 9392
diff changeset
   391
ed79a66e57e5 Initial work on audio device hotplug support.
Ryan C. Gordon <icculus@icculus.org>
parents: 9392
diff changeset
   392
static void
ed79a66e57e5 Initial work on audio device hotplug support.
Ryan C. Gordon <icculus@icculus.org>
parents: 9392
diff changeset
   393
perform_full_device_redetect(const int iscapture)
ed79a66e57e5 Initial work on audio device hotplug support.
Ryan C. Gordon <icculus@icculus.org>
parents: 9392
diff changeset
   394
{
ed79a66e57e5 Initial work on audio device hotplug support.
Ryan C. Gordon <icculus@icculus.org>
parents: 9392
diff changeset
   395
    SDL_LockMutex(current_audio.detection_lock);
ed79a66e57e5 Initial work on audio device hotplug support.
Ryan C. Gordon <icculus@icculus.org>
parents: 9392
diff changeset
   396
ed79a66e57e5 Initial work on audio device hotplug support.
Ryan C. Gordon <icculus@icculus.org>
parents: 9392
diff changeset
   397
    if (iscapture) {
ed79a66e57e5 Initial work on audio device hotplug support.
Ryan C. Gordon <icculus@icculus.org>
parents: 9392
diff changeset
   398
        if (!current_audio.impl.OnlyHasDefaultOutputDevice) {
ed79a66e57e5 Initial work on audio device hotplug support.
Ryan C. Gordon <icculus@icculus.org>
parents: 9392
diff changeset
   399
            free_device_list(&current_audio.outputDevices, &current_audio.outputDeviceCount);
ed79a66e57e5 Initial work on audio device hotplug support.
Ryan C. Gordon <icculus@icculus.org>
parents: 9392
diff changeset
   400
            current_audio.impl.DetectDevices(SDL_FALSE, add_output_device);
ed79a66e57e5 Initial work on audio device hotplug support.
Ryan C. Gordon <icculus@icculus.org>
parents: 9392
diff changeset
   401
        }
ed79a66e57e5 Initial work on audio device hotplug support.
Ryan C. Gordon <icculus@icculus.org>
parents: 9392
diff changeset
   402
    } else {
ed79a66e57e5 Initial work on audio device hotplug support.
Ryan C. Gordon <icculus@icculus.org>
parents: 9392
diff changeset
   403
        if ((current_audio.impl.HasCaptureSupport) && (!current_audio.impl.OnlyHasDefaultInputDevice)) {
ed79a66e57e5 Initial work on audio device hotplug support.
Ryan C. Gordon <icculus@icculus.org>
parents: 9392
diff changeset
   404
            free_device_list(&current_audio.inputDevices, &current_audio.inputDeviceCount);
ed79a66e57e5 Initial work on audio device hotplug support.
Ryan C. Gordon <icculus@icculus.org>
parents: 9392
diff changeset
   405
            current_audio.impl.DetectDevices(SDL_TRUE, add_capture_device);
ed79a66e57e5 Initial work on audio device hotplug support.
Ryan C. Gordon <icculus@icculus.org>
parents: 9392
diff changeset
   406
        }
ed79a66e57e5 Initial work on audio device hotplug support.
Ryan C. Gordon <icculus@icculus.org>
parents: 9392
diff changeset
   407
    }
ed79a66e57e5 Initial work on audio device hotplug support.
Ryan C. Gordon <icculus@icculus.org>
parents: 9392
diff changeset
   408
ed79a66e57e5 Initial work on audio device hotplug support.
Ryan C. Gordon <icculus@icculus.org>
parents: 9392
diff changeset
   409
    SDL_UnlockMutex(current_audio.detection_lock);
ed79a66e57e5 Initial work on audio device hotplug support.
Ryan C. Gordon <icculus@icculus.org>
parents: 9392
diff changeset
   410
}
ed79a66e57e5 Initial work on audio device hotplug support.
Ryan C. Gordon <icculus@icculus.org>
parents: 9392
diff changeset
   411
ed79a66e57e5 Initial work on audio device hotplug support.
Ryan C. Gordon <icculus@icculus.org>
parents: 9392
diff changeset
   412
/* The audio backends call this when a new device is plugged in. */
ed79a66e57e5 Initial work on audio device hotplug support.
Ryan C. Gordon <icculus@icculus.org>
parents: 9392
diff changeset
   413
void
ed79a66e57e5 Initial work on audio device hotplug support.
Ryan C. Gordon <icculus@icculus.org>
parents: 9392
diff changeset
   414
SDL_AudioDeviceConnected(const int iscapture, const char *name)
ed79a66e57e5 Initial work on audio device hotplug support.
Ryan C. Gordon <icculus@icculus.org>
parents: 9392
diff changeset
   415
{
ed79a66e57e5 Initial work on audio device hotplug support.
Ryan C. Gordon <icculus@icculus.org>
parents: 9392
diff changeset
   416
    int device_index = -1;
ed79a66e57e5 Initial work on audio device hotplug support.
Ryan C. Gordon <icculus@icculus.org>
parents: 9392
diff changeset
   417
ed79a66e57e5 Initial work on audio device hotplug support.
Ryan C. Gordon <icculus@icculus.org>
parents: 9392
diff changeset
   418
    SDL_LockMutex(current_audio.detection_lock);
ed79a66e57e5 Initial work on audio device hotplug support.
Ryan C. Gordon <icculus@icculus.org>
parents: 9392
diff changeset
   419
    if (iscapture) {
ed79a66e57e5 Initial work on audio device hotplug support.
Ryan C. Gordon <icculus@icculus.org>
parents: 9392
diff changeset
   420
        device_index = add_capture_device(name);
ed79a66e57e5 Initial work on audio device hotplug support.
Ryan C. Gordon <icculus@icculus.org>
parents: 9392
diff changeset
   421
    } else {
ed79a66e57e5 Initial work on audio device hotplug support.
Ryan C. Gordon <icculus@icculus.org>
parents: 9392
diff changeset
   422
        device_index = add_output_device(name);
ed79a66e57e5 Initial work on audio device hotplug support.
Ryan C. Gordon <icculus@icculus.org>
parents: 9392
diff changeset
   423
    }
ed79a66e57e5 Initial work on audio device hotplug support.
Ryan C. Gordon <icculus@icculus.org>
parents: 9392
diff changeset
   424
    SDL_UnlockMutex(current_audio.detection_lock);
ed79a66e57e5 Initial work on audio device hotplug support.
Ryan C. Gordon <icculus@icculus.org>
parents: 9392
diff changeset
   425
ed79a66e57e5 Initial work on audio device hotplug support.
Ryan C. Gordon <icculus@icculus.org>
parents: 9392
diff changeset
   426
    if (device_index != -1) {
ed79a66e57e5 Initial work on audio device hotplug support.
Ryan C. Gordon <icculus@icculus.org>
parents: 9392
diff changeset
   427
        /* Post the event, if desired */
ed79a66e57e5 Initial work on audio device hotplug support.
Ryan C. Gordon <icculus@icculus.org>
parents: 9392
diff changeset
   428
        if (SDL_GetEventState(SDL_AUDIODEVICEADDED) == SDL_ENABLE) {
ed79a66e57e5 Initial work on audio device hotplug support.
Ryan C. Gordon <icculus@icculus.org>
parents: 9392
diff changeset
   429
            SDL_Event event;
ed79a66e57e5 Initial work on audio device hotplug support.
Ryan C. Gordon <icculus@icculus.org>
parents: 9392
diff changeset
   430
            event.adevice.type = SDL_AUDIODEVICEADDED;
ed79a66e57e5 Initial work on audio device hotplug support.
Ryan C. Gordon <icculus@icculus.org>
parents: 9392
diff changeset
   431
            event.adevice.which = device_index;
ed79a66e57e5 Initial work on audio device hotplug support.
Ryan C. Gordon <icculus@icculus.org>
parents: 9392
diff changeset
   432
            event.adevice.iscapture = iscapture;
ed79a66e57e5 Initial work on audio device hotplug support.
Ryan C. Gordon <icculus@icculus.org>
parents: 9392
diff changeset
   433
            SDL_PushEvent(&event);
ed79a66e57e5 Initial work on audio device hotplug support.
Ryan C. Gordon <icculus@icculus.org>
parents: 9392
diff changeset
   434
        }
ed79a66e57e5 Initial work on audio device hotplug support.
Ryan C. Gordon <icculus@icculus.org>
parents: 9392
diff changeset
   435
    }
ed79a66e57e5 Initial work on audio device hotplug support.
Ryan C. Gordon <icculus@icculus.org>
parents: 9392
diff changeset
   436
}
ed79a66e57e5 Initial work on audio device hotplug support.
Ryan C. Gordon <icculus@icculus.org>
parents: 9392
diff changeset
   437
ed79a66e57e5 Initial work on audio device hotplug support.
Ryan C. Gordon <icculus@icculus.org>
parents: 9392
diff changeset
   438
/* The audio backends call this when a device is unplugged. */
ed79a66e57e5 Initial work on audio device hotplug support.
Ryan C. Gordon <icculus@icculus.org>
parents: 9392
diff changeset
   439
void
ed79a66e57e5 Initial work on audio device hotplug support.
Ryan C. Gordon <icculus@icculus.org>
parents: 9392
diff changeset
   440
SDL_AudioDeviceDisconnected(const int iscapture, SDL_AudioDevice *device)
ed79a66e57e5 Initial work on audio device hotplug support.
Ryan C. Gordon <icculus@icculus.org>
parents: 9392
diff changeset
   441
{
ed79a66e57e5 Initial work on audio device hotplug support.
Ryan C. Gordon <icculus@icculus.org>
parents: 9392
diff changeset
   442
    /* device==NULL means an unopened device was lost; do the redetect only. */
ed79a66e57e5 Initial work on audio device hotplug support.
Ryan C. Gordon <icculus@icculus.org>
parents: 9392
diff changeset
   443
    if (device != NULL) {
ed79a66e57e5 Initial work on audio device hotplug support.
Ryan C. Gordon <icculus@icculus.org>
parents: 9392
diff changeset
   444
        SDL_assert(get_audio_device(device->id) == device);
ed79a66e57e5 Initial work on audio device hotplug support.
Ryan C. Gordon <icculus@icculus.org>
parents: 9392
diff changeset
   445
        SDL_assert(device->enabled);  /* called more than once?! */
ed79a66e57e5 Initial work on audio device hotplug support.
Ryan C. Gordon <icculus@icculus.org>
parents: 9392
diff changeset
   446
ed79a66e57e5 Initial work on audio device hotplug support.
Ryan C. Gordon <icculus@icculus.org>
parents: 9392
diff changeset
   447
        /* Ends the audio callback and mark the device as STOPPED, but the
ed79a66e57e5 Initial work on audio device hotplug support.
Ryan C. Gordon <icculus@icculus.org>
parents: 9392
diff changeset
   448
           app still needs to close the device to free resources. */
ed79a66e57e5 Initial work on audio device hotplug support.
Ryan C. Gordon <icculus@icculus.org>
parents: 9392
diff changeset
   449
        current_audio.impl.LockDevice(device);
ed79a66e57e5 Initial work on audio device hotplug support.
Ryan C. Gordon <icculus@icculus.org>
parents: 9392
diff changeset
   450
        device->enabled = 0;
ed79a66e57e5 Initial work on audio device hotplug support.
Ryan C. Gordon <icculus@icculus.org>
parents: 9392
diff changeset
   451
        current_audio.impl.UnlockDevice(device);
ed79a66e57e5 Initial work on audio device hotplug support.
Ryan C. Gordon <icculus@icculus.org>
parents: 9392
diff changeset
   452
ed79a66e57e5 Initial work on audio device hotplug support.
Ryan C. Gordon <icculus@icculus.org>
parents: 9392
diff changeset
   453
        /* Post the event, if desired */
ed79a66e57e5 Initial work on audio device hotplug support.
Ryan C. Gordon <icculus@icculus.org>
parents: 9392
diff changeset
   454
        if (SDL_GetEventState(SDL_AUDIODEVICEREMOVED) == SDL_ENABLE) {
ed79a66e57e5 Initial work on audio device hotplug support.
Ryan C. Gordon <icculus@icculus.org>
parents: 9392
diff changeset
   455
            SDL_Event event;
ed79a66e57e5 Initial work on audio device hotplug support.
Ryan C. Gordon <icculus@icculus.org>
parents: 9392
diff changeset
   456
            event.adevice.type = SDL_AUDIODEVICEREMOVED;
ed79a66e57e5 Initial work on audio device hotplug support.
Ryan C. Gordon <icculus@icculus.org>
parents: 9392
diff changeset
   457
            event.adevice.which = device->id;
ed79a66e57e5 Initial work on audio device hotplug support.
Ryan C. Gordon <icculus@icculus.org>
parents: 9392
diff changeset
   458
            event.adevice.iscapture = device->iscapture ? 1 : 0;
ed79a66e57e5 Initial work on audio device hotplug support.
Ryan C. Gordon <icculus@icculus.org>
parents: 9392
diff changeset
   459
            SDL_PushEvent(&event);
ed79a66e57e5 Initial work on audio device hotplug support.
Ryan C. Gordon <icculus@icculus.org>
parents: 9392
diff changeset
   460
        }
ed79a66e57e5 Initial work on audio device hotplug support.
Ryan C. Gordon <icculus@icculus.org>
parents: 9392
diff changeset
   461
    }
ed79a66e57e5 Initial work on audio device hotplug support.
Ryan C. Gordon <icculus@icculus.org>
parents: 9392
diff changeset
   462
ed79a66e57e5 Initial work on audio device hotplug support.
Ryan C. Gordon <icculus@icculus.org>
parents: 9392
diff changeset
   463
    /* we don't really know which name (if any) was associated with this
ed79a66e57e5 Initial work on audio device hotplug support.
Ryan C. Gordon <icculus@icculus.org>
parents: 9392
diff changeset
   464
       device in the device list, so drop the entire list and rebuild it.
ed79a66e57e5 Initial work on audio device hotplug support.
Ryan C. Gordon <icculus@icculus.org>
parents: 9392
diff changeset
   465
       (we should probably change the API in 2.1 to make this more clear?) */
ed79a66e57e5 Initial work on audio device hotplug support.
Ryan C. Gordon <icculus@icculus.org>
parents: 9392
diff changeset
   466
    if (iscapture) {
ed79a66e57e5 Initial work on audio device hotplug support.
Ryan C. Gordon <icculus@icculus.org>
parents: 9392
diff changeset
   467
        current_audio.need_capture_device_redetect = SDL_TRUE;
ed79a66e57e5 Initial work on audio device hotplug support.
Ryan C. Gordon <icculus@icculus.org>
parents: 9392
diff changeset
   468
    } else {
ed79a66e57e5 Initial work on audio device hotplug support.
Ryan C. Gordon <icculus@icculus.org>
parents: 9392
diff changeset
   469
        current_audio.need_output_device_redetect = SDL_TRUE;
ed79a66e57e5 Initial work on audio device hotplug support.
Ryan C. Gordon <icculus@icculus.org>
parents: 9392
diff changeset
   470
    }
ed79a66e57e5 Initial work on audio device hotplug support.
Ryan C. Gordon <icculus@icculus.org>
parents: 9392
diff changeset
   471
}
ed79a66e57e5 Initial work on audio device hotplug support.
Ryan C. Gordon <icculus@icculus.org>
parents: 9392
diff changeset
   472
ed79a66e57e5 Initial work on audio device hotplug support.
Ryan C. Gordon <icculus@icculus.org>
parents: 9392
diff changeset
   473
9012
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   474
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   475
/* buffer queueing support... */
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   476
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   477
/* this expects that you managed thread safety elsewhere. */
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   478
static void
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   479
free_audio_queue(SDL_AudioBufferQueue *buffer)
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   480
{
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   481
    while (buffer) {
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   482
        SDL_AudioBufferQueue *next = buffer->next;
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   483
        SDL_free(buffer);
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   484
        buffer = next;
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   485
    }
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   486
}
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   487
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   488
static void SDLCALL
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   489
SDL_BufferQueueDrainCallback(void *userdata, Uint8 *stream, int _len)
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   490
{
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   491
    /* this function always holds the mixer lock before being called. */
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   492
    Uint32 len = (Uint32) _len;
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   493
    SDL_AudioDevice *device = (SDL_AudioDevice *) userdata;
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   494
    SDL_AudioBufferQueue *buffer;
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   495
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   496
    SDL_assert(device != NULL);  /* this shouldn't ever happen, right?! */
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   497
    SDL_assert(_len >= 0);  /* this shouldn't ever happen, right?! */
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   498
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   499
    while ((len > 0) && ((buffer = device->buffer_queue_head) != NULL)) {
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   500
        const Uint32 avail = buffer->datalen - buffer->startpos;
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   501
        const Uint32 cpy = SDL_min(len, avail);
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   502
        SDL_assert(device->queued_bytes >= avail);
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   503
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   504
        SDL_memcpy(stream, buffer->data + buffer->startpos, cpy);
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   505
        buffer->startpos += cpy;
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   506
        stream += cpy;
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   507
        device->queued_bytes -= cpy;
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   508
        len -= cpy;
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   509
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   510
        if (buffer->startpos == buffer->datalen) {  /* packet is done, put it in the pool. */
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   511
            device->buffer_queue_head = buffer->next;
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   512
            SDL_assert((buffer->next != NULL) || (buffer == device->buffer_queue_tail));
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   513
            buffer->next = device->buffer_queue_pool;
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   514
            device->buffer_queue_pool = buffer;
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   515
        }
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   516
    }
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   517
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   518
    SDL_assert((device->buffer_queue_head != NULL) == (device->queued_bytes != 0));
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   519
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   520
    if (len > 0) {  /* fill any remaining space in the stream with silence. */
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   521
        SDL_assert(device->buffer_queue_head == NULL);
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   522
        SDL_memset(stream, device->spec.silence, len);
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   523
    }
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   524
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   525
    if (device->buffer_queue_head == NULL) {
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   526
        device->buffer_queue_tail = NULL;  /* in case we drained the queue entirely. */
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   527
    }
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   528
}
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   529
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   530
int
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   531
SDL_QueueAudio(SDL_AudioDeviceID devid, const void *_data, Uint32 len)
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   532
{
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   533
    SDL_AudioDevice *device = get_audio_device(devid);
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   534
    const Uint8 *data = (const Uint8 *) _data;
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   535
    SDL_AudioBufferQueue *orighead;
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   536
    SDL_AudioBufferQueue *origtail;
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   537
    Uint32 origlen;
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   538
    Uint32 datalen;
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   539
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   540
    if (!device) {
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   541
        return -1;  /* get_audio_device() will have set the error state */
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   542
    }
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   543
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   544
    if (device->spec.callback != SDL_BufferQueueDrainCallback) {
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   545
        return SDL_SetError("Audio device has a callback, queueing not allowed");
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   546
    }
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   547
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   548
    current_audio.impl.LockDevice(device);
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   549
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   550
    orighead = device->buffer_queue_head;
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   551
    origtail = device->buffer_queue_tail;
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   552
    origlen = origtail ? origtail->datalen : 0;
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   553
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   554
    while (len > 0) {
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   555
        SDL_AudioBufferQueue *packet = device->buffer_queue_tail;
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   556
        SDL_assert(!packet || (packet->datalen <= SDL_AUDIOBUFFERQUEUE_PACKETLEN));
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   557
        if (!packet || (packet->datalen >= SDL_AUDIOBUFFERQUEUE_PACKETLEN)) {
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   558
            /* tail packet missing or completely full; we need a new packet. */
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   559
            packet = device->buffer_queue_pool;
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   560
            if (packet != NULL) {
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   561
                /* we have one available in the pool. */
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   562
                device->buffer_queue_pool = packet->next;
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   563
            } else {
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   564
                /* Have to allocate a new one! */
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   565
                packet = (SDL_AudioBufferQueue *) SDL_malloc(sizeof (SDL_AudioBufferQueue));
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   566
                if (packet == NULL) {
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   567
                    /* uhoh, reset so we've queued nothing new, free what we can. */
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   568
                    if (!origtail) {
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   569
                        packet = device->buffer_queue_head;  /* whole queue. */
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   570
                    } else {
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   571
                        packet = origtail->next;  /* what we added to existing queue. */
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   572
                        origtail->next = NULL;
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   573
                        origtail->datalen = origlen;
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   574
                    }
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   575
                    device->buffer_queue_head = orighead;
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   576
                    device->buffer_queue_tail = origtail;
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   577
                    device->buffer_queue_pool = NULL;
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   578
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   579
                    current_audio.impl.UnlockDevice(device);
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   580
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   581
                    free_audio_queue(packet);  /* give back what we can. */
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   582
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   583
                    return SDL_OutOfMemory();
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   584
                }
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   585
            }
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   586
            packet->datalen = 0;
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   587
            packet->startpos = 0;
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   588
            packet->next = NULL;
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   589
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   590
            SDL_assert((device->buffer_queue_head != NULL) == (device->queued_bytes != 0));
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   591
            if (device->buffer_queue_tail == NULL) {
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   592
                device->buffer_queue_head = packet;
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   593
            } else {
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   594
                device->buffer_queue_tail->next = packet;
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   595
            }
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   596
            device->buffer_queue_tail = packet;
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   597
        }
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   598
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   599
        datalen = SDL_min(len, SDL_AUDIOBUFFERQUEUE_PACKETLEN - packet->datalen);
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   600
        SDL_memcpy(packet->data + packet->datalen, data, datalen);
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   601
        data += datalen;
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   602
        len -= datalen;
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   603
        packet->datalen += datalen;
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   604
        device->queued_bytes += datalen;
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   605
    }
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   606
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   607
    current_audio.impl.UnlockDevice(device);
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   608
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   609
    return 0;
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   610
}
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   611
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   612
Uint32
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   613
SDL_GetQueuedAudioSize(SDL_AudioDeviceID devid)
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   614
{
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   615
    Uint32 retval = 0;
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   616
    SDL_AudioDevice *device = get_audio_device(devid);
9032
36c472422d64 SDL_GetQueuedAudioSize() shouldn't grab lock when not set up for queueing.
Ryan C. Gordon <icculus@icculus.org>
parents: 9031
diff changeset
   617
36c472422d64 SDL_GetQueuedAudioSize() shouldn't grab lock when not set up for queueing.
Ryan C. Gordon <icculus@icculus.org>
parents: 9031
diff changeset
   618
    /* Nothing to do unless we're set up for queueing. */
36c472422d64 SDL_GetQueuedAudioSize() shouldn't grab lock when not set up for queueing.
Ryan C. Gordon <icculus@icculus.org>
parents: 9031
diff changeset
   619
    if (device && (device->spec.callback == SDL_BufferQueueDrainCallback)) {
9012
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   620
        current_audio.impl.LockDevice(device);
9031
e963a13a720c Added a GetPendingBytes method to the audio backend.
Ryan C. Gordon <icculus@icculus.org>
parents: 9012
diff changeset
   621
        retval = device->queued_bytes + current_audio.impl.GetPendingBytes(device);
9012
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   622
        current_audio.impl.UnlockDevice(device);
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   623
    }
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   624
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   625
    return retval;
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   626
}
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   627
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   628
void
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   629
SDL_ClearQueuedAudio(SDL_AudioDeviceID devid)
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   630
{
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   631
    SDL_AudioDevice *device = get_audio_device(devid);
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   632
    SDL_AudioBufferQueue *buffer = NULL;
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   633
    if (!device) {
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   634
        return;  /* nothing to do. */
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   635
    }
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   636
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   637
    /* Blank out the device and release the mutex. Free it afterwards. */
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   638
    current_audio.impl.LockDevice(device);
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   639
    buffer = device->buffer_queue_head;
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   640
    device->buffer_queue_tail = NULL;
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   641
    device->buffer_queue_head = NULL;
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   642
    device->queued_bytes = 0;
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   643
    current_audio.impl.UnlockDevice(device);
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   644
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   645
    free_audio_queue(buffer);
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   646
}
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   647
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   648
8761
bce4122e6e87 __ANDROID__ is the correct macro to check for an android system.ANDROID is only defined in NDK build system (.mk) and not in the standalone NDK.
Dimitris Zenios <dimitris.zenios@gmail.com>
parents: 8660
diff changeset
   649
#if defined(__ANDROID__)
4722
faa228f7ce5b - Cleaned up a bunch of code
Paul Hunkin <paul@bieh.net>
parents: 4718
diff changeset
   650
#include <android/log.h>
4865
fff50e86c891 Update VS2010 project to add new files; update new files so code builds on Win32/Win64
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 4729
diff changeset
   651
#endif
4722
faa228f7ce5b - Cleaned up a bunch of code
Paul Hunkin <paul@bieh.net>
parents: 4718
diff changeset
   652
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   653
/* The general mixing thread function */
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1794
diff changeset
   654
int SDLCALL
2049
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
   655
SDL_RunAudio(void *devicep)
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   656
{
2049
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
   657
    SDL_AudioDevice *device = (SDL_AudioDevice *) devicep;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1794
diff changeset
   658
    Uint8 *stream;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1794
diff changeset
   659
    int stream_len;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1794
diff changeset
   660
    void *udata;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1794
diff changeset
   661
    void (SDLCALL * fill) (void *userdata, Uint8 * stream, int len);
3336
00fab0ebfe54 Fixed a bug where when the audio starts paused all the DirectSound buffers
Sam Lantinga <slouken@libsdl.org>
parents: 3283
diff changeset
   662
    Uint32 delay;
8660
6bd1f8bad873 Patched to compile on C89 compilers, removed more streamer code.
Ryan C. Gordon <icculus@icculus.org>
parents: 8658
diff changeset
   663
6bd1f8bad873 Patched to compile on C89 compilers, removed more streamer code.
Ryan C. Gordon <icculus@icculus.org>
parents: 8658
diff changeset
   664
#if 0  /* !!! FIXME: rewrite/remove this streamer code. */
5526
5645b3a5dc03 Move variable declaration position to stick with C standart.
Airlangga Cahya Utama <airlangga.cahya@gmail.com>
parents: 5509
diff changeset
   665
    /* For streaming when the buffer sizes don't match up */
5645b3a5dc03 Move variable declaration position to stick with C standart.
Airlangga Cahya Utama <airlangga.cahya@gmail.com>
parents: 5509
diff changeset
   666
    Uint8 *istream;
5645b3a5dc03 Move variable declaration position to stick with C standart.
Airlangga Cahya Utama <airlangga.cahya@gmail.com>
parents: 5509
diff changeset
   667
    int istream_len = 0;
8660
6bd1f8bad873 Patched to compile on C89 compilers, removed more streamer code.
Ryan C. Gordon <icculus@icculus.org>
parents: 8658
diff changeset
   668
#endif
2716
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   669
5509
5b1b4d820d10 The API sets the priority for the current thread, not an arbitrary thread.
Sam Lantinga <slouken@libsdl.org>
parents: 5506
diff changeset
   670
    /* The audio mixing is always a high priority thread */
5b1b4d820d10 The API sets the priority for the current thread, not an arbitrary thread.
Sam Lantinga <slouken@libsdl.org>
parents: 5506
diff changeset
   671
    SDL_SetThreadPriority(SDL_THREAD_PRIORITY_HIGH);
5b1b4d820d10 The API sets the priority for the current thread, not an arbitrary thread.
Sam Lantinga <slouken@libsdl.org>
parents: 5506
diff changeset
   672
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1794
diff changeset
   673
    /* Perform any thread setup */
2049
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
   674
    device->threadid = SDL_ThreadID();
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
   675
    current_audio.impl.ThreadInit(device);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   676
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1794
diff changeset
   677
    /* Set up the mixing function */
2049
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
   678
    fill = device->spec.callback;
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
   679
    udata = device->spec.userdata;
21
75a95f82bc1f Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
   680
2716
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   681
    /* By default do not stream */
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   682
    device->use_streamer = 0;
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   683
2049
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
   684
    if (device->convert.needed) {
3040
Sam Lantinga <slouken@libsdl.org>
parents: 3032
diff changeset
   685
#if 0                           /* !!! FIXME: I took len_div out of the structure. Use rate_incr instead? */
2716
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   686
        /* If the result of the conversion alters the length, i.e. resampling is being used, use the streamer */
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   687
        if (device->convert.len_mult != 1 || device->convert.len_div != 1) {
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   688
            /* The streamer's maximum length should be twice whichever is larger: spec.size or len_cvt */
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   689
            stream_max_len = 2 * device->spec.size;
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   690
            if (device->convert.len_mult > device->convert.len_div) {
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   691
                stream_max_len *= device->convert.len_mult;
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   692
                stream_max_len /= device->convert.len_div;
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   693
            }
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   694
            if (SDL_StreamInit(&device->streamer, stream_max_len, silence) <
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   695
                0)
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   696
                return -1;
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   697
            device->use_streamer = 1;
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   698
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   699
            /* istream_len should be the length of what we grab from the callback and feed to conversion,
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   700
               so that we get close to spec_size. I.e. we want device.spec_size = istream_len * u / d
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   701
             */
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   702
            istream_len =
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   703
                device->spec.size * device->convert.len_div /
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   704
                device->convert.len_mult;
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   705
        }
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2984
diff changeset
   706
#endif
7518
febc83bc2a43 Fixed crash and garbled output when converting from F32 to S16 audio.
Sam Lantinga <slouken@libsdl.org>
parents: 7447
diff changeset
   707
        stream_len = device->convert.len;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1794
diff changeset
   708
    } else {
2049
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
   709
        stream_len = device->spec.size;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1794
diff changeset
   710
    }
1561
c724c4a99759 Try to fill the hardware audio buffer immediately.
Ryan C. Gordon <icculus@icculus.org>
parents: 1532
diff changeset
   711
3336
00fab0ebfe54 Fixed a bug where when the audio starts paused all the DirectSound buffers
Sam Lantinga <slouken@libsdl.org>
parents: 3283
diff changeset
   712
    /* Calculate the delay while paused */
00fab0ebfe54 Fixed a bug where when the audio starts paused all the DirectSound buffers
Sam Lantinga <slouken@libsdl.org>
parents: 3283
diff changeset
   713
    delay = ((device->spec.samples * 1000) / device->spec.freq);
00fab0ebfe54 Fixed a bug where when the audio starts paused all the DirectSound buffers
Sam Lantinga <slouken@libsdl.org>
parents: 3283
diff changeset
   714
2716
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   715
    /* Determine if the streamer is necessary here */
8658
7939f33e81ac #ifdef'd out the audio streamer code.
Ryan C. Gordon <icculus@icculus.org>
parents: 8149
diff changeset
   716
#if 0  /* !!! FIXME: rewrite/remove this streamer code. */
2716
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   717
    if (device->use_streamer == 1) {
3336
00fab0ebfe54 Fixed a bug where when the audio starts paused all the DirectSound buffers
Sam Lantinga <slouken@libsdl.org>
parents: 3283
diff changeset
   718
        /* This code is almost the same as the old code. The difference is, instead of reading
2716
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   719
           directly from the callback into "stream", then converting and sending the audio off,
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   720
           we go: callback -> "istream" -> (conversion) -> streamer -> stream -> device.
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   721
           However, reading and writing with streamer are done separately:
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   722
           - We only call the callback and write to the streamer when the streamer does not
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   723
           contain enough samples to output to the device.
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   724
           - We only read from the streamer and tell the device to play when the streamer
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   725
           does have enough samples to output.
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   726
           This allows us to perform resampling in the conversion step, where the output of the
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   727
           resampling process can be any number. We will have to see what a good size for the
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   728
           stream's maximum length is, but I suspect 2*max(len_cvt, stream_len) is a good figure.
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   729
         */
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   730
        while (device->enabled) {
3336
00fab0ebfe54 Fixed a bug where when the audio starts paused all the DirectSound buffers
Sam Lantinga <slouken@libsdl.org>
parents: 3283
diff changeset
   731
00fab0ebfe54 Fixed a bug where when the audio starts paused all the DirectSound buffers
Sam Lantinga <slouken@libsdl.org>
parents: 3283
diff changeset
   732
            if (device->paused) {
00fab0ebfe54 Fixed a bug where when the audio starts paused all the DirectSound buffers
Sam Lantinga <slouken@libsdl.org>
parents: 3283
diff changeset
   733
                SDL_Delay(delay);
00fab0ebfe54 Fixed a bug where when the audio starts paused all the DirectSound buffers
Sam Lantinga <slouken@libsdl.org>
parents: 3283
diff changeset
   734
                continue;
00fab0ebfe54 Fixed a bug where when the audio starts paused all the DirectSound buffers
Sam Lantinga <slouken@libsdl.org>
parents: 3283
diff changeset
   735
            }
00fab0ebfe54 Fixed a bug where when the audio starts paused all the DirectSound buffers
Sam Lantinga <slouken@libsdl.org>
parents: 3283
diff changeset
   736
2716
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   737
            /* Only read in audio if the streamer doesn't have enough already (if it does not have enough samples to output) */
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   738
            if (SDL_StreamLength(&device->streamer) < stream_len) {
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   739
                /* Set up istream */
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   740
                if (device->convert.needed) {
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   741
                    if (device->convert.buf) {
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   742
                        istream = device->convert.buf;
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   743
                    } else {
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   744
                        continue;
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   745
                    }
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   746
                } else {
3336
00fab0ebfe54 Fixed a bug where when the audio starts paused all the DirectSound buffers
Sam Lantinga <slouken@libsdl.org>
parents: 3283
diff changeset
   747
/* FIXME: Ryan, this is probably wrong.  I imagine we don't want to get
00fab0ebfe54 Fixed a bug where when the audio starts paused all the DirectSound buffers
Sam Lantinga <slouken@libsdl.org>
parents: 3283
diff changeset
   748
 * a device buffer both here and below in the stream output.
00fab0ebfe54 Fixed a bug where when the audio starts paused all the DirectSound buffers
Sam Lantinga <slouken@libsdl.org>
parents: 3283
diff changeset
   749
 */
2716
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   750
                    istream = current_audio.impl.GetDeviceBuf(device);
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   751
                    if (istream == NULL) {
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   752
                        istream = device->fake_stream;
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   753
                    }
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   754
                }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   755
2716
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   756
                /* Read from the callback into the _input_ stream */
9391
3a54985e999e Tweaked a couple comments, added some FIXMEs.
Ryan C. Gordon <icculus@icculus.org>
parents: 9382
diff changeset
   757
                // !!! FIXME: this should be LockDevice.
6977
b73d51026c68 Changed the name of SDL_mutexP() SDL_mutexV()
Sam Lantinga <slouken@libsdl.org>
parents: 6905
diff changeset
   758
                SDL_LockMutex(device->mixer_lock);
3336
00fab0ebfe54 Fixed a bug where when the audio starts paused all the DirectSound buffers
Sam Lantinga <slouken@libsdl.org>
parents: 3283
diff changeset
   759
                (*fill) (udata, istream, istream_len);
6977
b73d51026c68 Changed the name of SDL_mutexP() SDL_mutexV()
Sam Lantinga <slouken@libsdl.org>
parents: 6905
diff changeset
   760
                SDL_UnlockMutex(device->mixer_lock);
2716
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   761
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   762
                /* Convert the audio if necessary and write to the streamer */
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   763
                if (device->convert.needed) {
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   764
                    SDL_ConvertAudio(&device->convert);
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   765
                    if (istream == NULL) {
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   766
                        istream = device->fake_stream;
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   767
                    }
7678
286c42d7c5ed OCD fixes: Adds a space after /* (glory to regular expressions!)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7518
diff changeset
   768
                    /* SDL_memcpy(istream, device->convert.buf, device->convert.len_cvt); */
2716
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   769
                    SDL_StreamWrite(&device->streamer, device->convert.buf,
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   770
                                    device->convert.len_cvt);
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   771
                } else {
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   772
                    SDL_StreamWrite(&device->streamer, istream, istream_len);
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   773
                }
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1794
diff changeset
   774
            }
2716
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   775
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   776
            /* Only output audio if the streamer has enough to output */
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   777
            if (SDL_StreamLength(&device->streamer) >= stream_len) {
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   778
                /* Set up the output stream */
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   779
                if (device->convert.needed) {
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   780
                    if (device->convert.buf) {
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   781
                        stream = device->convert.buf;
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   782
                    } else {
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   783
                        continue;
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   784
                    }
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   785
                } else {
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   786
                    stream = current_audio.impl.GetDeviceBuf(device);
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   787
                    if (stream == NULL) {
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   788
                        stream = device->fake_stream;
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   789
                    }
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   790
                }
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   791
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   792
                /* Now read from the streamer */
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   793
                SDL_StreamRead(&device->streamer, stream, stream_len);
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   794
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   795
                /* Ready current buffer for play and change current buffer */
3336
00fab0ebfe54 Fixed a bug where when the audio starts paused all the DirectSound buffers
Sam Lantinga <slouken@libsdl.org>
parents: 3283
diff changeset
   796
                if (stream != device->fake_stream) {
2716
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   797
                    current_audio.impl.PlayDevice(device);
3096
ae4e80dbe330 Date: Tue, 17 Feb 2009 14:00:25 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 3040
diff changeset
   798
                    /* Wait for an audio buffer to become available */
ae4e80dbe330 Date: Tue, 17 Feb 2009 14:00:25 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 3040
diff changeset
   799
                    current_audio.impl.WaitDevice(device);
2716
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   800
                } else {
3336
00fab0ebfe54 Fixed a bug where when the audio starts paused all the DirectSound buffers
Sam Lantinga <slouken@libsdl.org>
parents: 3283
diff changeset
   801
                    SDL_Delay(delay);
2716
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   802
                }
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1794
diff changeset
   803
            }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   804
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1794
diff changeset
   805
        }
8660
6bd1f8bad873 Patched to compile on C89 compilers, removed more streamer code.
Ryan C. Gordon <icculus@icculus.org>
parents: 8658
diff changeset
   806
    } else
8658
7939f33e81ac #ifdef'd out the audio streamer code.
Ryan C. Gordon <icculus@icculus.org>
parents: 8149
diff changeset
   807
#endif
8660
6bd1f8bad873 Patched to compile on C89 compilers, removed more streamer code.
Ryan C. Gordon <icculus@icculus.org>
parents: 8658
diff changeset
   808
    {
2716
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   809
        /* Otherwise, do not use the streamer. This is the old code. */
7406
fb02213c11d3 Explicitly write silence to the audio device while it is paused.
Ryan C. Gordon <icculus@icculus.org>
parents: 7367
diff changeset
   810
        const int silence = (int) device->spec.silence;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   811
2716
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   812
        /* Loop, filling the audio buffers */
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   813
        while (device->enabled) {
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   814
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   815
            /* Fill the current buffer with sound */
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   816
            if (device->convert.needed) {
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   817
                if (device->convert.buf) {
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   818
                    stream = device->convert.buf;
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   819
                } else {
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   820
                    continue;
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   821
                }
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   822
            } else {
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   823
                stream = current_audio.impl.GetDeviceBuf(device);
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   824
                if (stream == NULL) {
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   825
                    stream = device->fake_stream;
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   826
                }
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1794
diff changeset
   827
            }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   828
9391
3a54985e999e Tweaked a couple comments, added some FIXMEs.
Ryan C. Gordon <icculus@icculus.org>
parents: 9382
diff changeset
   829
            /* !!! FIXME: this should be LockDevice. */
7447
6860de5bcb8c Protect SDL_PauseAudio*() with the audio callback lock.
Ryan C. Gordon <icculus@icculus.org>
parents: 7446
diff changeset
   830
            SDL_LockMutex(device->mixer_lock);
9393
ed79a66e57e5 Initial work on audio device hotplug support.
Ryan C. Gordon <icculus@icculus.org>
parents: 9392
diff changeset
   831
ed79a66e57e5 Initial work on audio device hotplug support.
Ryan C. Gordon <icculus@icculus.org>
parents: 9392
diff changeset
   832
            /* Check again, in case device was removed while a lock was held. */
ed79a66e57e5 Initial work on audio device hotplug support.
Ryan C. Gordon <icculus@icculus.org>
parents: 9392
diff changeset
   833
            if (!device->enabled) {
ed79a66e57e5 Initial work on audio device hotplug support.
Ryan C. Gordon <icculus@icculus.org>
parents: 9392
diff changeset
   834
                SDL_UnlockMutex(device->mixer_lock);
ed79a66e57e5 Initial work on audio device hotplug support.
Ryan C. Gordon <icculus@icculus.org>
parents: 9392
diff changeset
   835
                break;
ed79a66e57e5 Initial work on audio device hotplug support.
Ryan C. Gordon <icculus@icculus.org>
parents: 9392
diff changeset
   836
            }
ed79a66e57e5 Initial work on audio device hotplug support.
Ryan C. Gordon <icculus@icculus.org>
parents: 9392
diff changeset
   837
7406
fb02213c11d3 Explicitly write silence to the audio device while it is paused.
Ryan C. Gordon <icculus@icculus.org>
parents: 7367
diff changeset
   838
            if (device->paused) {
fb02213c11d3 Explicitly write silence to the audio device while it is paused.
Ryan C. Gordon <icculus@icculus.org>
parents: 7367
diff changeset
   839
                SDL_memset(stream, silence, stream_len);
fb02213c11d3 Explicitly write silence to the audio device while it is paused.
Ryan C. Gordon <icculus@icculus.org>
parents: 7367
diff changeset
   840
            } else {
fb02213c11d3 Explicitly write silence to the audio device while it is paused.
Ryan C. Gordon <icculus@icculus.org>
parents: 7367
diff changeset
   841
                (*fill) (udata, stream, stream_len);
fb02213c11d3 Explicitly write silence to the audio device while it is paused.
Ryan C. Gordon <icculus@icculus.org>
parents: 7367
diff changeset
   842
            }
7447
6860de5bcb8c Protect SDL_PauseAudio*() with the audio callback lock.
Ryan C. Gordon <icculus@icculus.org>
parents: 7446
diff changeset
   843
            SDL_UnlockMutex(device->mixer_lock);
1562
1d487a3fab41 Fixed bug #18
Sam Lantinga <slouken@libsdl.org>
parents: 1561
diff changeset
   844
2716
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   845
            /* Convert the audio if necessary */
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   846
            if (device->convert.needed) {
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   847
                SDL_ConvertAudio(&device->convert);
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   848
                stream = current_audio.impl.GetDeviceBuf(device);
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   849
                if (stream == NULL) {
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   850
                    stream = device->fake_stream;
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   851
                }
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   852
                SDL_memcpy(stream, device->convert.buf,
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   853
                           device->convert.len_cvt);
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   854
            }
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   855
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   856
            /* Ready current buffer for play and change current buffer */
3336
00fab0ebfe54 Fixed a bug where when the audio starts paused all the DirectSound buffers
Sam Lantinga <slouken@libsdl.org>
parents: 3283
diff changeset
   857
            if (stream != device->fake_stream) {
2716
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   858
                current_audio.impl.PlayDevice(device);
3096
ae4e80dbe330 Date: Tue, 17 Feb 2009 14:00:25 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 3040
diff changeset
   859
                /* Wait for an audio buffer to become available */
ae4e80dbe330 Date: Tue, 17 Feb 2009 14:00:25 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 3040
diff changeset
   860
                current_audio.impl.WaitDevice(device);
2716
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   861
            } else {
3336
00fab0ebfe54 Fixed a bug where when the audio starts paused all the DirectSound buffers
Sam Lantinga <slouken@libsdl.org>
parents: 3283
diff changeset
   862
                SDL_Delay(delay);
2716
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   863
            }
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1794
diff changeset
   864
        }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1794
diff changeset
   865
    }
1562
1d487a3fab41 Fixed bug #18
Sam Lantinga <slouken@libsdl.org>
parents: 1561
diff changeset
   866
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1794
diff changeset
   867
    /* Wait for the audio to drain.. */
2049
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
   868
    current_audio.impl.WaitDone(device);
21
75a95f82bc1f Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
   869
2716
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   870
    /* If necessary, deinit the streamer */
8658
7939f33e81ac #ifdef'd out the audio streamer code.
Ryan C. Gordon <icculus@icculus.org>
parents: 8149
diff changeset
   871
#if 0  /* !!! FIXME: rewrite/remove this streamer code. */
2716
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   872
    if (device->use_streamer == 1)
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   873
        SDL_StreamDeinit(&device->streamer);
8658
7939f33e81ac #ifdef'd out the audio streamer code.
Ryan C. Gordon <icculus@icculus.org>
parents: 8149
diff changeset
   874
#endif
2716
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   875
9382
1c0f6952e65e Cleaning out a silly coding style I used to use.
Ryan C. Gordon <icculus@icculus.org>
parents: 9381
diff changeset
   876
    return 0;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   877
}
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   878
322
fd93a09655e3 The audio lock and unlock functions are now a part of the driver.
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
   879
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1978
diff changeset
   880
static SDL_AudioFormat
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1794
diff changeset
   881
SDL_ParseAudioFormat(const char *string)
1794
5605a9820134 Fixed bug #137
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
   882
{
2076
939420dee849 Use SDL_strcmp(), not strcmp().
Ryan C. Gordon <icculus@icculus.org>
parents: 2070
diff changeset
   883
#define CHECK_FMT_STRING(x) if (SDL_strcmp(string, #x) == 0) return AUDIO_##x
2049
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
   884
    CHECK_FMT_STRING(U8);
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
   885
    CHECK_FMT_STRING(S8);
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
   886
    CHECK_FMT_STRING(U16LSB);
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
   887
    CHECK_FMT_STRING(S16LSB);
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
   888
    CHECK_FMT_STRING(U16MSB);
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
   889
    CHECK_FMT_STRING(S16MSB);
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
   890
    CHECK_FMT_STRING(U16SYS);
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
   891
    CHECK_FMT_STRING(S16SYS);
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
   892
    CHECK_FMT_STRING(U16);
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
   893
    CHECK_FMT_STRING(S16);
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
   894
    CHECK_FMT_STRING(S32LSB);
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
   895
    CHECK_FMT_STRING(S32MSB);
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
   896
    CHECK_FMT_STRING(S32SYS);
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
   897
    CHECK_FMT_STRING(S32);
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
   898
    CHECK_FMT_STRING(F32LSB);
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
   899
    CHECK_FMT_STRING(F32MSB);
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
   900
    CHECK_FMT_STRING(F32SYS);
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
   901
    CHECK_FMT_STRING(F32);
2060
866052b01ee5 indent is evil
Sam Lantinga <slouken@libsdl.org>
parents: 2053
diff changeset
   902
#undef CHECK_FMT_STRING
2049
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
   903
    return 0;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1794
diff changeset
   904
}
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1794
diff changeset
   905
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1794
diff changeset
   906
int
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1794
diff changeset
   907
SDL_GetNumAudioDrivers(void)
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1794
diff changeset
   908
{
9382
1c0f6952e65e Cleaning out a silly coding style I used to use.
Ryan C. Gordon <icculus@icculus.org>
parents: 9381
diff changeset
   909
    return SDL_arraysize(bootstrap) - 1;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1794
diff changeset
   910
}
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1794
diff changeset
   911
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1794
diff changeset
   912
const char *
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1794
diff changeset
   913
SDL_GetAudioDriver(int index)
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1794
diff changeset
   914
{
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1794
diff changeset
   915
    if (index >= 0 && index < SDL_GetNumAudioDrivers()) {
9382
1c0f6952e65e Cleaning out a silly coding style I used to use.
Ryan C. Gordon <icculus@icculus.org>
parents: 9381
diff changeset
   916
        return bootstrap[index]->name;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1794
diff changeset
   917
    }
9382
1c0f6952e65e Cleaning out a silly coding style I used to use.
Ryan C. Gordon <icculus@icculus.org>
parents: 9381
diff changeset
   918
    return NULL;
1794
5605a9820134 Fixed bug #137
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
   919
}
5605a9820134 Fixed bug #137
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
   920
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1794
diff changeset
   921
int
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1794
diff changeset
   922
SDL_AudioInit(const char *driver_name)
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   923
{
2049
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
   924
    int i = 0;
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
   925
    int initialized = 0;
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
   926
    int tried_to_init = 0;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   927
2049
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
   928
    if (SDL_WasInit(SDL_INIT_AUDIO)) {
2060
866052b01ee5 indent is evil
Sam Lantinga <slouken@libsdl.org>
parents: 2053
diff changeset
   929
        SDL_AudioQuit();        /* shutdown driver if already running. */
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1794
diff changeset
   930
    }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   931
9392
92e23eff9b89 Changed some SDL_memset() calls to SDL_zero().
Ryan C. Gordon <icculus@icculus.org>
parents: 9391
diff changeset
   932
    SDL_zero(current_audio);
92e23eff9b89 Changed some SDL_memset() calls to SDL_zero().
Ryan C. Gordon <icculus@icculus.org>
parents: 9391
diff changeset
   933
    SDL_zero(open_devices);
2049
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
   934
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1794
diff changeset
   935
    /* Select the proper audio driver */
1909
8f1ab2f7c722 Look at environment variables in SDL_VideoInit() and SDL_AudioInit()
Sam Lantinga <slouken@libsdl.org>
parents: 1903
diff changeset
   936
    if (driver_name == NULL) {
8f1ab2f7c722 Look at environment variables in SDL_VideoInit() and SDL_AudioInit()
Sam Lantinga <slouken@libsdl.org>
parents: 1903
diff changeset
   937
        driver_name = SDL_getenv("SDL_AUDIODRIVER");
8f1ab2f7c722 Look at environment variables in SDL_VideoInit() and SDL_AudioInit()
Sam Lantinga <slouken@libsdl.org>
parents: 1903
diff changeset
   938
    }
2049
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
   939
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
   940
    for (i = 0; (!initialized) && (bootstrap[i]); ++i) {
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
   941
        /* make sure we should even try this driver before doing so... */
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
   942
        const AudioBootStrap *backend = bootstrap[i];
6900
767690d1c013 Allow abbreviated strings to be used for driver names.
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
   943
        if ((driver_name && (SDL_strncasecmp(backend->name, driver_name, SDL_strlen(driver_name)) != 0)) ||
767690d1c013 Allow abbreviated strings to be used for driver names.
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
   944
            (!driver_name && backend->demand_only)) {
2049
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
   945
            continue;
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
   946
        }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   947
2049
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
   948
        tried_to_init = 1;
9392
92e23eff9b89 Changed some SDL_memset() calls to SDL_zero().
Ryan C. Gordon <icculus@icculus.org>
parents: 9391
diff changeset
   949
        SDL_zero(current_audio);
2049
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
   950
        current_audio.name = backend->name;
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
   951
        current_audio.desc = backend->desc;
3699
4160ba33b597 Removed test for "driver is valid, but doesn't see any audio devices."
Ryan C. Gordon <icculus@icculus.org>
parents: 3697
diff changeset
   952
        initialized = backend->init(&current_audio.impl);
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1794
diff changeset
   953
    }
2049
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
   954
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
   955
    if (!initialized) {
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
   956
        /* specific drivers will set the error message if they fail... */
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
   957
        if (!tried_to_init) {
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1794
diff changeset
   958
            if (driver_name) {
3699
4160ba33b597 Removed test for "driver is valid, but doesn't see any audio devices."
Ryan C. Gordon <icculus@icculus.org>
parents: 3697
diff changeset
   959
                SDL_SetError("Audio target '%s' not available", driver_name);
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1794
diff changeset
   960
            } else {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1794
diff changeset
   961
                SDL_SetError("No available audio device");
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1794
diff changeset
   962
            }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1794
diff changeset
   963
        }
2049
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
   964
9392
92e23eff9b89 Changed some SDL_memset() calls to SDL_zero().
Ryan C. Gordon <icculus@icculus.org>
parents: 9391
diff changeset
   965
        SDL_zero(current_audio);
9382
1c0f6952e65e Cleaning out a silly coding style I used to use.
Ryan C. Gordon <icculus@icculus.org>
parents: 9381
diff changeset
   966
        return -1;            /* No driver was available, so fail. */
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1794
diff changeset
   967
    }
2049
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
   968
9393
ed79a66e57e5 Initial work on audio device hotplug support.
Ryan C. Gordon <icculus@icculus.org>
parents: 9392
diff changeset
   969
    current_audio.detection_lock = SDL_CreateMutex();
ed79a66e57e5 Initial work on audio device hotplug support.
Ryan C. Gordon <icculus@icculus.org>
parents: 9392
diff changeset
   970
2049
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
   971
    finalize_audio_entry_points();
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
   972
9393
ed79a66e57e5 Initial work on audio device hotplug support.
Ryan C. Gordon <icculus@icculus.org>
parents: 9392
diff changeset
   973
    /* Make sure we have a list of devices available at startup. */
ed79a66e57e5 Initial work on audio device hotplug support.
Ryan C. Gordon <icculus@icculus.org>
parents: 9392
diff changeset
   974
    perform_full_device_redetect(SDL_TRUE);
ed79a66e57e5 Initial work on audio device hotplug support.
Ryan C. Gordon <icculus@icculus.org>
parents: 9392
diff changeset
   975
    perform_full_device_redetect(SDL_FALSE);
ed79a66e57e5 Initial work on audio device hotplug support.
Ryan C. Gordon <icculus@icculus.org>
parents: 9392
diff changeset
   976
ed79a66e57e5 Initial work on audio device hotplug support.
Ryan C. Gordon <icculus@icculus.org>
parents: 9392
diff changeset
   977
    /* Post an add event for each initial device, if desired */
ed79a66e57e5 Initial work on audio device hotplug support.
Ryan C. Gordon <icculus@icculus.org>
parents: 9392
diff changeset
   978
    if (SDL_GetEventState(SDL_AUDIODEVICEADDED) == SDL_ENABLE) {
ed79a66e57e5 Initial work on audio device hotplug support.
Ryan C. Gordon <icculus@icculus.org>
parents: 9392
diff changeset
   979
        SDL_Event event;
ed79a66e57e5 Initial work on audio device hotplug support.
Ryan C. Gordon <icculus@icculus.org>
parents: 9392
diff changeset
   980
ed79a66e57e5 Initial work on audio device hotplug support.
Ryan C. Gordon <icculus@icculus.org>
parents: 9392
diff changeset
   981
        SDL_zero(event);
ed79a66e57e5 Initial work on audio device hotplug support.
Ryan C. Gordon <icculus@icculus.org>
parents: 9392
diff changeset
   982
        event.adevice.type = SDL_AUDIODEVICEADDED;
ed79a66e57e5 Initial work on audio device hotplug support.
Ryan C. Gordon <icculus@icculus.org>
parents: 9392
diff changeset
   983
ed79a66e57e5 Initial work on audio device hotplug support.
Ryan C. Gordon <icculus@icculus.org>
parents: 9392
diff changeset
   984
        event.adevice.iscapture = 0;
ed79a66e57e5 Initial work on audio device hotplug support.
Ryan C. Gordon <icculus@icculus.org>
parents: 9392
diff changeset
   985
        for (i = 0; i < current_audio.outputDeviceCount; i++) {
ed79a66e57e5 Initial work on audio device hotplug support.
Ryan C. Gordon <icculus@icculus.org>
parents: 9392
diff changeset
   986
            event.adevice.which = i;
ed79a66e57e5 Initial work on audio device hotplug support.
Ryan C. Gordon <icculus@icculus.org>
parents: 9392
diff changeset
   987
            SDL_PushEvent(&event);
ed79a66e57e5 Initial work on audio device hotplug support.
Ryan C. Gordon <icculus@icculus.org>
parents: 9392
diff changeset
   988
        }
ed79a66e57e5 Initial work on audio device hotplug support.
Ryan C. Gordon <icculus@icculus.org>
parents: 9392
diff changeset
   989
ed79a66e57e5 Initial work on audio device hotplug support.
Ryan C. Gordon <icculus@icculus.org>
parents: 9392
diff changeset
   990
        event.adevice.iscapture = 1;
ed79a66e57e5 Initial work on audio device hotplug support.
Ryan C. Gordon <icculus@icculus.org>
parents: 9392
diff changeset
   991
        for (i = 0; i < current_audio.inputDeviceCount; i++) {
ed79a66e57e5 Initial work on audio device hotplug support.
Ryan C. Gordon <icculus@icculus.org>
parents: 9392
diff changeset
   992
            event.adevice.which = i;
ed79a66e57e5 Initial work on audio device hotplug support.
Ryan C. Gordon <icculus@icculus.org>
parents: 9392
diff changeset
   993
            SDL_PushEvent(&event);
ed79a66e57e5 Initial work on audio device hotplug support.
Ryan C. Gordon <icculus@icculus.org>
parents: 9392
diff changeset
   994
        }
ed79a66e57e5 Initial work on audio device hotplug support.
Ryan C. Gordon <icculus@icculus.org>
parents: 9392
diff changeset
   995
    }
ed79a66e57e5 Initial work on audio device hotplug support.
Ryan C. Gordon <icculus@icculus.org>
parents: 9392
diff changeset
   996
9382
1c0f6952e65e Cleaning out a silly coding style I used to use.
Ryan C. Gordon <icculus@icculus.org>
parents: 9381
diff changeset
   997
    return 0;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   998
}
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   999
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1794
diff changeset
  1000
/*
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1794
diff changeset
  1001
 * Get the current audio driver name
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1794
diff changeset
  1002
 */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1794
diff changeset
  1003
const char *
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1794
diff changeset
  1004
SDL_GetCurrentAudioDriver()
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1005
{
2049
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
  1006
    return current_audio.name;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1007
}
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1008
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1794
diff changeset
  1009
int
2049
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
  1010
SDL_GetNumAudioDevices(int iscapture)
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1011
{
5593
ab22ca13c47f Cleaned up audio device detection. Cleared out a lot of cut-and-paste.
Ryan C. Gordon <icculus@icculus.org>
parents: 5592
diff changeset
  1012
    int retval = 0;
ab22ca13c47f Cleaned up audio device detection. Cleared out a lot of cut-and-paste.
Ryan C. Gordon <icculus@icculus.org>
parents: 5592
diff changeset
  1013
2049
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
  1014
    if (!SDL_WasInit(SDL_INIT_AUDIO)) {
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
  1015
        return -1;
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
  1016
    }
5593
ab22ca13c47f Cleaned up audio device detection. Cleared out a lot of cut-and-paste.
Ryan C. Gordon <icculus@icculus.org>
parents: 5592
diff changeset
  1017
2049
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
  1018
    if ((iscapture) && (!current_audio.impl.HasCaptureSupport)) {
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
  1019
        return 0;
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
  1020
    }
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
  1021
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
  1022
    if ((iscapture) && (current_audio.impl.OnlyHasDefaultInputDevice)) {
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
  1023
        return 1;
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
  1024
    }
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
  1025
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
  1026
    if ((!iscapture) && (current_audio.impl.OnlyHasDefaultOutputDevice)) {
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
  1027
        return 1;
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
  1028
    }
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
  1029
9393
ed79a66e57e5 Initial work on audio device hotplug support.
Ryan C. Gordon <icculus@icculus.org>
parents: 9392
diff changeset
  1030
    if (current_audio.need_capture_device_redetect) {
ed79a66e57e5 Initial work on audio device hotplug support.
Ryan C. Gordon <icculus@icculus.org>
parents: 9392
diff changeset
  1031
        current_audio.need_capture_device_redetect = SDL_FALSE;
ed79a66e57e5 Initial work on audio device hotplug support.
Ryan C. Gordon <icculus@icculus.org>
parents: 9392
diff changeset
  1032
        perform_full_device_redetect(SDL_TRUE);
5593
ab22ca13c47f Cleaned up audio device detection. Cleared out a lot of cut-and-paste.
Ryan C. Gordon <icculus@icculus.org>
parents: 5592
diff changeset
  1033
    }
ab22ca13c47f Cleaned up audio device detection. Cleared out a lot of cut-and-paste.
Ryan C. Gordon <icculus@icculus.org>
parents: 5592
diff changeset
  1034
9393
ed79a66e57e5 Initial work on audio device hotplug support.
Ryan C. Gordon <icculus@icculus.org>
parents: 9392
diff changeset
  1035
    if (current_audio.need_output_device_redetect) {
ed79a66e57e5 Initial work on audio device hotplug support.
Ryan C. Gordon <icculus@icculus.org>
parents: 9392
diff changeset
  1036
        current_audio.need_output_device_redetect = SDL_FALSE;
ed79a66e57e5 Initial work on audio device hotplug support.
Ryan C. Gordon <icculus@icculus.org>
parents: 9392
diff changeset
  1037
        perform_full_device_redetect(SDL_FALSE);
ed79a66e57e5 Initial work on audio device hotplug support.
Ryan C. Gordon <icculus@icculus.org>
parents: 9392
diff changeset
  1038
    }
ed79a66e57e5 Initial work on audio device hotplug support.
Ryan C. Gordon <icculus@icculus.org>
parents: 9392
diff changeset
  1039
ed79a66e57e5 Initial work on audio device hotplug support.
Ryan C. Gordon <icculus@icculus.org>
parents: 9392
diff changeset
  1040
    SDL_LockMutex(current_audio.detection_lock);
ed79a66e57e5 Initial work on audio device hotplug support.
Ryan C. Gordon <icculus@icculus.org>
parents: 9392
diff changeset
  1041
    retval = iscapture ? current_audio.inputDeviceCount : current_audio.outputDeviceCount;
ed79a66e57e5 Initial work on audio device hotplug support.
Ryan C. Gordon <icculus@icculus.org>
parents: 9392
diff changeset
  1042
    SDL_UnlockMutex(current_audio.detection_lock);
ed79a66e57e5 Initial work on audio device hotplug support.
Ryan C. Gordon <icculus@icculus.org>
parents: 9392
diff changeset
  1043
5593
ab22ca13c47f Cleaned up audio device detection. Cleared out a lot of cut-and-paste.
Ryan C. Gordon <icculus@icculus.org>
parents: 5592
diff changeset
  1044
    return retval;
2049
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
  1045
}
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
  1046
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1047
2049
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
  1048
const char *
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
  1049
SDL_GetAudioDeviceName(int index, int iscapture)
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
  1050
{
9393
ed79a66e57e5 Initial work on audio device hotplug support.
Ryan C. Gordon <icculus@icculus.org>
parents: 9392
diff changeset
  1051
    const char *retval = NULL;