src/audio/SDL_audio.c
author Ryan C. Gordon <icculus@icculus.org>
Wed, 18 Mar 2015 02:01:17 -0400
changeset 9394 bb28e5281770
parent 9393 ed79a66e57e5
child 9396 69c501ed36f3
permissions -rw-r--r--
Bunch of reworking to how we manage audio devices. Device enumeration now happens at startup and then is managed exclusively through hotplugging instead of full redetection. The device name list now has a unique "handle" associated with each item and SDL will pass this to the backend so they don't have to figure out how a human readable name maps to real hardware for a second time. Other cleanups, fixes, improvements, plus all the audio backends updated to the new interface...largely untested at this point, though.
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
9394
bb28e5281770 Bunch of reworking to how we manage audio devices.
Ryan C. Gordon <icculus@icculus.org>
parents: 9393
diff changeset
   164
SDL_AudioDetectDevices_Default(void)
bb28e5281770 Bunch of reworking to how we manage audio devices.
Ryan C. Gordon <icculus@icculus.org>
parents: 9393
diff changeset
   165
{
bb28e5281770 Bunch of reworking to how we manage audio devices.
Ryan C. Gordon <icculus@icculus.org>
parents: 9393
diff changeset
   166
    /* you have to write your own implementation if these assertions fail. */
bb28e5281770 Bunch of reworking to how we manage audio devices.
Ryan C. Gordon <icculus@icculus.org>
parents: 9393
diff changeset
   167
    SDL_assert(current_audio.impl.OnlyHasDefaultOutputDevice);
bb28e5281770 Bunch of reworking to how we manage audio devices.
Ryan C. Gordon <icculus@icculus.org>
parents: 9393
diff changeset
   168
    SDL_assert(current_audio.impl.OnlyHasDefaultInputDevice || !current_audio.impl.HasCaptureSupport);
bb28e5281770 Bunch of reworking to how we manage audio devices.
Ryan C. Gordon <icculus@icculus.org>
parents: 9393
diff changeset
   169
bb28e5281770 Bunch of reworking to how we manage audio devices.
Ryan C. Gordon <icculus@icculus.org>
parents: 9393
diff changeset
   170
    SDL_AddAudioDevice(SDL_FALSE, DEFAULT_OUTPUT_DEVNAME, (void *) ((size_t) 0x1));
bb28e5281770 Bunch of reworking to how we manage audio devices.
Ryan C. Gordon <icculus@icculus.org>
parents: 9393
diff changeset
   171
    if (current_audio.impl.HasCaptureSupport) {
bb28e5281770 Bunch of reworking to how we manage audio devices.
Ryan C. Gordon <icculus@icculus.org>
parents: 9393
diff changeset
   172
        SDL_AddAudioDevice(SDL_TRUE, DEFAULT_INPUT_DEVNAME, (void *) ((size_t) 0x2));
bb28e5281770 Bunch of reworking to how we manage audio devices.
Ryan C. Gordon <icculus@icculus.org>
parents: 9393
diff changeset
   173
    }
2060
866052b01ee5 indent is evil
Sam Lantinga <slouken@libsdl.org>
parents: 2053
diff changeset
   174
}
2735
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2728
diff changeset
   175
2060
866052b01ee5 indent is evil
Sam Lantinga <slouken@libsdl.org>
parents: 2053
diff changeset
   176
static void
866052b01ee5 indent is evil
Sam Lantinga <slouken@libsdl.org>
parents: 2053
diff changeset
   177
SDL_AudioThreadInit_Default(_THIS)
866052b01ee5 indent is evil
Sam Lantinga <slouken@libsdl.org>
parents: 2053
diff changeset
   178
{                               /* no-op. */
866052b01ee5 indent is evil
Sam Lantinga <slouken@libsdl.org>
parents: 2053
diff changeset
   179
}
2735
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2728
diff changeset
   180
2060
866052b01ee5 indent is evil
Sam Lantinga <slouken@libsdl.org>
parents: 2053
diff changeset
   181
static void
866052b01ee5 indent is evil
Sam Lantinga <slouken@libsdl.org>
parents: 2053
diff changeset
   182
SDL_AudioWaitDevice_Default(_THIS)
866052b01ee5 indent is evil
Sam Lantinga <slouken@libsdl.org>
parents: 2053
diff changeset
   183
{                               /* no-op. */
866052b01ee5 indent is evil
Sam Lantinga <slouken@libsdl.org>
parents: 2053
diff changeset
   184
}
2735
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2728
diff changeset
   185
2060
866052b01ee5 indent is evil
Sam Lantinga <slouken@libsdl.org>
parents: 2053
diff changeset
   186
static void
866052b01ee5 indent is evil
Sam Lantinga <slouken@libsdl.org>
parents: 2053
diff changeset
   187
SDL_AudioPlayDevice_Default(_THIS)
866052b01ee5 indent is evil
Sam Lantinga <slouken@libsdl.org>
parents: 2053
diff changeset
   188
{                               /* no-op. */
866052b01ee5 indent is evil
Sam Lantinga <slouken@libsdl.org>
parents: 2053
diff changeset
   189
}
2735
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2728
diff changeset
   190
9031
e963a13a720c Added a GetPendingBytes method to the audio backend.
Ryan C. Gordon <icculus@icculus.org>
parents: 9012
diff changeset
   191
static int
e963a13a720c Added a GetPendingBytes method to the audio backend.
Ryan C. Gordon <icculus@icculus.org>
parents: 9012
diff changeset
   192
SDL_AudioGetPendingBytes_Default(_THIS)
e963a13a720c Added a GetPendingBytes method to the audio backend.
Ryan C. Gordon <icculus@icculus.org>
parents: 9012
diff changeset
   193
{
e963a13a720c Added a GetPendingBytes method to the audio backend.
Ryan C. Gordon <icculus@icculus.org>
parents: 9012
diff changeset
   194
    return 0;
e963a13a720c Added a GetPendingBytes method to the audio backend.
Ryan C. Gordon <icculus@icculus.org>
parents: 9012
diff changeset
   195
}
e963a13a720c Added a GetPendingBytes method to the audio backend.
Ryan C. Gordon <icculus@icculus.org>
parents: 9012
diff changeset
   196
2060
866052b01ee5 indent is evil
Sam Lantinga <slouken@libsdl.org>
parents: 2053
diff changeset
   197
static Uint8 *
866052b01ee5 indent is evil
Sam Lantinga <slouken@libsdl.org>
parents: 2053
diff changeset
   198
SDL_AudioGetDeviceBuf_Default(_THIS)
866052b01ee5 indent is evil
Sam Lantinga <slouken@libsdl.org>
parents: 2053
diff changeset
   199
{
866052b01ee5 indent is evil
Sam Lantinga <slouken@libsdl.org>
parents: 2053
diff changeset
   200
    return NULL;
866052b01ee5 indent is evil
Sam Lantinga <slouken@libsdl.org>
parents: 2053
diff changeset
   201
}
2735
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2728
diff changeset
   202
2060
866052b01ee5 indent is evil
Sam Lantinga <slouken@libsdl.org>
parents: 2053
diff changeset
   203
static void
866052b01ee5 indent is evil
Sam Lantinga <slouken@libsdl.org>
parents: 2053
diff changeset
   204
SDL_AudioWaitDone_Default(_THIS)
866052b01ee5 indent is evil
Sam Lantinga <slouken@libsdl.org>
parents: 2053
diff changeset
   205
{                               /* no-op. */
866052b01ee5 indent is evil
Sam Lantinga <slouken@libsdl.org>
parents: 2053
diff changeset
   206
}
2735
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2728
diff changeset
   207
2060
866052b01ee5 indent is evil
Sam Lantinga <slouken@libsdl.org>
parents: 2053
diff changeset
   208
static void
866052b01ee5 indent is evil
Sam Lantinga <slouken@libsdl.org>
parents: 2053
diff changeset
   209
SDL_AudioCloseDevice_Default(_THIS)
866052b01ee5 indent is evil
Sam Lantinga <slouken@libsdl.org>
parents: 2053
diff changeset
   210
{                               /* no-op. */
866052b01ee5 indent is evil
Sam Lantinga <slouken@libsdl.org>
parents: 2053
diff changeset
   211
}
2735
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2728
diff changeset
   212
2060
866052b01ee5 indent is evil
Sam Lantinga <slouken@libsdl.org>
parents: 2053
diff changeset
   213
static void
866052b01ee5 indent is evil
Sam Lantinga <slouken@libsdl.org>
parents: 2053
diff changeset
   214
SDL_AudioDeinitialize_Default(void)
866052b01ee5 indent is evil
Sam Lantinga <slouken@libsdl.org>
parents: 2053
diff changeset
   215
{                               /* no-op. */
866052b01ee5 indent is evil
Sam Lantinga <slouken@libsdl.org>
parents: 2053
diff changeset
   216
}
2049
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
   217
9394
bb28e5281770 Bunch of reworking to how we manage audio devices.
Ryan C. Gordon <icculus@icculus.org>
parents: 9393
diff changeset
   218
static void
bb28e5281770 Bunch of reworking to how we manage audio devices.
Ryan C. Gordon <icculus@icculus.org>
parents: 9393
diff changeset
   219
SDL_AudioFreeDeviceHandle_Default(void *handle)
bb28e5281770 Bunch of reworking to how we manage audio devices.
Ryan C. Gordon <icculus@icculus.org>
parents: 9393
diff changeset
   220
{                               /* no-op. */
bb28e5281770 Bunch of reworking to how we manage audio devices.
Ryan C. Gordon <icculus@icculus.org>
parents: 9393
diff changeset
   221
}
bb28e5281770 Bunch of reworking to how we manage audio devices.
Ryan C. Gordon <icculus@icculus.org>
parents: 9393
diff changeset
   222
bb28e5281770 Bunch of reworking to how we manage audio devices.
Ryan C. Gordon <icculus@icculus.org>
parents: 9393
diff changeset
   223
2049
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
   224
static int
9394
bb28e5281770 Bunch of reworking to how we manage audio devices.
Ryan C. Gordon <icculus@icculus.org>
parents: 9393
diff changeset
   225
SDL_AudioOpenDevice_Default(_THIS, void *handle, const char *devname, int iscapture)
2049
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
   226
{
9394
bb28e5281770 Bunch of reworking to how we manage audio devices.
Ryan C. Gordon <icculus@icculus.org>
parents: 9393
diff changeset
   227
    return SDL_Unsupported();
2049
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
   228
}
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
   229
9010
6d059ed9b6ca Clarifying hard-to-understand piece of code.
Ryan C. Gordon <icculus@icculus.org>
parents: 8919
diff changeset
   230
static SDL_INLINE SDL_bool
6d059ed9b6ca Clarifying hard-to-understand piece of code.
Ryan C. Gordon <icculus@icculus.org>
parents: 8919
diff changeset
   231
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
   232
{
6d059ed9b6ca Clarifying hard-to-understand piece of code.
Ryan C. Gordon <icculus@icculus.org>
parents: 8919
diff changeset
   233
    /* 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
   234
       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
   235
       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
   236
       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
   237
    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
   238
        return SDL_TRUE;
6d059ed9b6ca Clarifying hard-to-understand piece of code.
Ryan C. Gordon <icculus@icculus.org>
parents: 8919
diff changeset
   239
    }
6d059ed9b6ca Clarifying hard-to-understand piece of code.
Ryan C. Gordon <icculus@icculus.org>
parents: 8919
diff changeset
   240
6d059ed9b6ca Clarifying hard-to-understand piece of code.
Ryan C. Gordon <icculus@icculus.org>
parents: 8919
diff changeset
   241
    return SDL_FALSE;
6d059ed9b6ca Clarifying hard-to-understand piece of code.
Ryan C. Gordon <icculus@icculus.org>
parents: 8919
diff changeset
   242
}
6d059ed9b6ca Clarifying hard-to-understand piece of code.
Ryan C. Gordon <icculus@icculus.org>
parents: 8919
diff changeset
   243
2049
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
   244
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
   245
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
   246
{
9010
6d059ed9b6ca Clarifying hard-to-understand piece of code.
Ryan C. Gordon <icculus@icculus.org>
parents: 8919
diff changeset
   247
    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
   248
        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
   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
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
   252
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
   253
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
   254
{
9010
6d059ed9b6ca Clarifying hard-to-understand piece of code.
Ryan C. Gordon <icculus@icculus.org>
parents: 8919
diff changeset
   255
    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
   256
        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
   257
    }
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
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   260
2060
866052b01ee5 indent is evil
Sam Lantinga <slouken@libsdl.org>
parents: 2053
diff changeset
   261
static void
866052b01ee5 indent is evil
Sam Lantinga <slouken@libsdl.org>
parents: 2053
diff changeset
   262
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
   263
{
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
   264
    /*
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 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
   266
     *  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
   267
     */
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
   268
2060
866052b01ee5 indent is evil
Sam Lantinga <slouken@libsdl.org>
parents: 2053
diff changeset
   269
#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
   270
        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
   271
            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
   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
    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
   274
    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
   275
    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
   276
    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
   277
    FILL_STUB(PlayDevice);
9031
e963a13a720c Added a GetPendingBytes method to the audio backend.
Ryan C. Gordon <icculus@icculus.org>
parents: 9012
diff changeset
   278
    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
   279
    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
   280
    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
   281
    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
   282
    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
   283
    FILL_STUB(UnlockDevice);
9394
bb28e5281770 Bunch of reworking to how we manage audio devices.
Ryan C. Gordon <icculus@icculus.org>
parents: 9393
diff changeset
   284
    FILL_STUB(FreeDeviceHandle);
2049
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
   285
    FILL_STUB(Deinitialize);
2060
866052b01ee5 indent is evil
Sam Lantinga <slouken@libsdl.org>
parents: 2053
diff changeset
   286
#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
   287
}
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
   288
8660
6bd1f8bad873 Patched to compile on C89 compilers, removed more streamer code.
Ryan C. Gordon <icculus@icculus.org>
parents: 8658
diff changeset
   289
#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
   290
/* 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
   291
/* 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
   292
static void
2716
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   293
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
   294
{
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   295
    int i;
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   296
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   297
    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
   298
        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
   299
        ++stream->write_pos;
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   300
    }
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   301
}
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
/* 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
   304
static void
2716
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   305
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
   306
{
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   307
    int i;
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   308
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   309
    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
   310
        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
   311
        ++stream->read_pos;
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   312
    }
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   313
}
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   314
4472
791b3256fb22 Mostly cleaned up warnings with -Wmissing-prototypes
Sam Lantinga <slouken@libsdl.org>
parents: 3699
diff changeset
   315
static int
2716
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   316
SDL_StreamLength(SDL_AudioStreamer * stream)
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   317
{
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   318
    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
   319
}
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
/* 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
   322
#if 0
4472
791b3256fb22 Mostly cleaned up warnings with -Wmissing-prototypes
Sam Lantinga <slouken@libsdl.org>
parents: 3699
diff changeset
   323
static int
2716
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   324
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
   325
{
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   326
    /* First try to allocate the buffer */
2728
2768bd7281e0 Fixed Visual Studio compilation problems
Sam Lantinga <slouken@libsdl.org>
parents: 2716
diff changeset
   327
    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
   328
    if (stream->buffer == NULL) {
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   329
        return -1;
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   330
    }
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   331
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   332
    stream->max_len = max_len;
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   333
    stream->read_pos = 0;
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   334
    stream->write_pos = 0;
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   335
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   336
    /* Zero out the buffer */
2728
2768bd7281e0 Fixed Visual Studio compilation problems
Sam Lantinga <slouken@libsdl.org>
parents: 2716
diff changeset
   337
    SDL_memset(stream->buffer, silence, max_len);
2768bd7281e0 Fixed Visual Studio compilation problems
Sam Lantinga <slouken@libsdl.org>
parents: 2716
diff changeset
   338
2768bd7281e0 Fixed Visual Studio compilation problems
Sam Lantinga <slouken@libsdl.org>
parents: 2716
diff changeset
   339
    return 0;
2716
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   340
}
4507
dbf3fa541096 Fixed compile warnings
Sam Lantinga <slouken@libsdl.org>
parents: 4472
diff changeset
   341
#endif
2716
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   342
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   343
/* 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
   344
static void
2716
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   345
SDL_StreamDeinit(SDL_AudioStreamer * stream)
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   346
{
7719
31b5f9ff36ca Christoph Mallon: Remove pointless if (x) before SDL_free(x)
Sam Lantinga <slouken@libsdl.org>
parents: 7678
diff changeset
   347
    SDL_free(stream->buffer);
2716
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   348
}
8660
6bd1f8bad873 Patched to compile on C89 compilers, removed more streamer code.
Ryan C. Gordon <icculus@icculus.org>
parents: 8658
diff changeset
   349
#endif
2716
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   350
9393
ed79a66e57e5 Initial work on audio device hotplug support.
Ryan C. Gordon <icculus@icculus.org>
parents: 9392
diff changeset
   351
/* device hotplug support... */
ed79a66e57e5 Initial work on audio device hotplug support.
Ryan C. Gordon <icculus@icculus.org>
parents: 9392
diff changeset
   352
ed79a66e57e5 Initial work on audio device hotplug support.
Ryan C. Gordon <icculus@icculus.org>
parents: 9392
diff changeset
   353
static int
9394
bb28e5281770 Bunch of reworking to how we manage audio devices.
Ryan C. Gordon <icculus@icculus.org>
parents: 9393
diff changeset
   354
add_audio_device(const char *name, void *handle, SDL_AudioDeviceItem **devices, int *devCount)
9393
ed79a66e57e5 Initial work on audio device hotplug support.
Ryan C. Gordon <icculus@icculus.org>
parents: 9392
diff changeset
   355
{
ed79a66e57e5 Initial work on audio device hotplug support.
Ryan C. Gordon <icculus@icculus.org>
parents: 9392
diff changeset
   356
    int retval = -1;
9394
bb28e5281770 Bunch of reworking to how we manage audio devices.
Ryan C. Gordon <icculus@icculus.org>
parents: 9393
diff changeset
   357
    const size_t size = sizeof (SDL_AudioDeviceItem) + SDL_strlen(name) + 1;
bb28e5281770 Bunch of reworking to how we manage audio devices.
Ryan C. Gordon <icculus@icculus.org>
parents: 9393
diff changeset
   358
    SDL_AudioDeviceItem *item = (SDL_AudioDeviceItem *) SDL_malloc(size);
bb28e5281770 Bunch of reworking to how we manage audio devices.
Ryan C. Gordon <icculus@icculus.org>
parents: 9393
diff changeset
   359
    if (item == NULL) {
bb28e5281770 Bunch of reworking to how we manage audio devices.
Ryan C. Gordon <icculus@icculus.org>
parents: 9393
diff changeset
   360
        return -1;
bb28e5281770 Bunch of reworking to how we manage audio devices.
Ryan C. Gordon <icculus@icculus.org>
parents: 9393
diff changeset
   361
    }
9393
ed79a66e57e5 Initial work on audio device hotplug support.
Ryan C. Gordon <icculus@icculus.org>
parents: 9392
diff changeset
   362
9394
bb28e5281770 Bunch of reworking to how we manage audio devices.
Ryan C. Gordon <icculus@icculus.org>
parents: 9393
diff changeset
   363
    SDL_assert(handle != NULL);
bb28e5281770 Bunch of reworking to how we manage audio devices.
Ryan C. Gordon <icculus@icculus.org>
parents: 9393
diff changeset
   364
bb28e5281770 Bunch of reworking to how we manage audio devices.
Ryan C. Gordon <icculus@icculus.org>
parents: 9393
diff changeset
   365
    item->handle = handle;
bb28e5281770 Bunch of reworking to how we manage audio devices.
Ryan C. Gordon <icculus@icculus.org>
parents: 9393
diff changeset
   366
    SDL_strlcpy(item->name, name, size - sizeof (SDL_AudioDeviceItem));
bb28e5281770 Bunch of reworking to how we manage audio devices.
Ryan C. Gordon <icculus@icculus.org>
parents: 9393
diff changeset
   367
bb28e5281770 Bunch of reworking to how we manage audio devices.
Ryan C. Gordon <icculus@icculus.org>
parents: 9393
diff changeset
   368
    SDL_LockMutex(current_audio.detectionLock);
bb28e5281770 Bunch of reworking to how we manage audio devices.
Ryan C. Gordon <icculus@icculus.org>
parents: 9393
diff changeset
   369
    item->next = *devices;
bb28e5281770 Bunch of reworking to how we manage audio devices.
Ryan C. Gordon <icculus@icculus.org>
parents: 9393
diff changeset
   370
    *devices = item;
bb28e5281770 Bunch of reworking to how we manage audio devices.
Ryan C. Gordon <icculus@icculus.org>
parents: 9393
diff changeset
   371
    retval = (*devCount)++;
bb28e5281770 Bunch of reworking to how we manage audio devices.
Ryan C. Gordon <icculus@icculus.org>
parents: 9393
diff changeset
   372
    SDL_UnlockMutex(current_audio.detectionLock);
9393
ed79a66e57e5 Initial work on audio device hotplug support.
Ryan C. Gordon <icculus@icculus.org>
parents: 9392
diff changeset
   373
ed79a66e57e5 Initial work on audio device hotplug support.
Ryan C. Gordon <icculus@icculus.org>
parents: 9392
diff changeset
   374
    return retval;
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
9394
bb28e5281770 Bunch of reworking to how we manage audio devices.
Ryan C. Gordon <icculus@icculus.org>
parents: 9393
diff changeset
   377
static SDL_INLINE int
bb28e5281770 Bunch of reworking to how we manage audio devices.
Ryan C. Gordon <icculus@icculus.org>
parents: 9393
diff changeset
   378
add_capture_device(const char *name, void *handle)
9393
ed79a66e57e5 Initial work on audio device hotplug support.
Ryan C. Gordon <icculus@icculus.org>
parents: 9392
diff changeset
   379
{
ed79a66e57e5 Initial work on audio device hotplug support.
Ryan C. Gordon <icculus@icculus.org>
parents: 9392
diff changeset
   380
    /* !!! FIXME: add this later. SDL_assert(current_audio.impl.HasCaptureSupport);*/
9394
bb28e5281770 Bunch of reworking to how we manage audio devices.
Ryan C. Gordon <icculus@icculus.org>
parents: 9393
diff changeset
   381
    return add_audio_device(name, handle, &current_audio.inputDevices, &current_audio.inputDeviceCount);
9393
ed79a66e57e5 Initial work on audio device hotplug support.
Ryan C. Gordon <icculus@icculus.org>
parents: 9392
diff changeset
   382
}
ed79a66e57e5 Initial work on audio device hotplug support.
Ryan C. Gordon <icculus@icculus.org>
parents: 9392
diff changeset
   383
9394
bb28e5281770 Bunch of reworking to how we manage audio devices.
Ryan C. Gordon <icculus@icculus.org>
parents: 9393
diff changeset
   384
static SDL_INLINE int
bb28e5281770 Bunch of reworking to how we manage audio devices.
Ryan C. Gordon <icculus@icculus.org>
parents: 9393
diff changeset
   385
add_output_device(const char *name, void *handle)
9393
ed79a66e57e5 Initial work on audio device hotplug support.
Ryan C. Gordon <icculus@icculus.org>
parents: 9392
diff changeset
   386
{
9394
bb28e5281770 Bunch of reworking to how we manage audio devices.
Ryan C. Gordon <icculus@icculus.org>
parents: 9393
diff changeset
   387
    return add_audio_device(name, handle, &current_audio.outputDevices, &current_audio.outputDeviceCount);
9393
ed79a66e57e5 Initial work on audio device hotplug support.
Ryan C. Gordon <icculus@icculus.org>
parents: 9392
diff changeset
   388
}
ed79a66e57e5 Initial work on audio device hotplug support.
Ryan C. Gordon <icculus@icculus.org>
parents: 9392
diff changeset
   389
ed79a66e57e5 Initial work on audio device hotplug support.
Ryan C. Gordon <icculus@icculus.org>
parents: 9392
diff changeset
   390
static void
9394
bb28e5281770 Bunch of reworking to how we manage audio devices.
Ryan C. Gordon <icculus@icculus.org>
parents: 9393
diff changeset
   391
free_device_list(SDL_AudioDeviceItem **devices, int *devCount)
9393
ed79a66e57e5 Initial work on audio device hotplug support.
Ryan C. Gordon <icculus@icculus.org>
parents: 9392
diff changeset
   392
{
9394
bb28e5281770 Bunch of reworking to how we manage audio devices.
Ryan C. Gordon <icculus@icculus.org>
parents: 9393
diff changeset
   393
    SDL_AudioDeviceItem *item, *next;
bb28e5281770 Bunch of reworking to how we manage audio devices.
Ryan C. Gordon <icculus@icculus.org>
parents: 9393
diff changeset
   394
    for (item = *devices; item != NULL; item = next) {
bb28e5281770 Bunch of reworking to how we manage audio devices.
Ryan C. Gordon <icculus@icculus.org>
parents: 9393
diff changeset
   395
        next = item->next;
bb28e5281770 Bunch of reworking to how we manage audio devices.
Ryan C. Gordon <icculus@icculus.org>
parents: 9393
diff changeset
   396
        if (item->handle != NULL) {
bb28e5281770 Bunch of reworking to how we manage audio devices.
Ryan C. Gordon <icculus@icculus.org>
parents: 9393
diff changeset
   397
            current_audio.impl.FreeDeviceHandle(item->handle);
9393
ed79a66e57e5 Initial work on audio device hotplug support.
Ryan C. Gordon <icculus@icculus.org>
parents: 9392
diff changeset
   398
        }
9394
bb28e5281770 Bunch of reworking to how we manage audio devices.
Ryan C. Gordon <icculus@icculus.org>
parents: 9393
diff changeset
   399
        SDL_free(item);
9393
ed79a66e57e5 Initial work on audio device hotplug support.
Ryan C. Gordon <icculus@icculus.org>
parents: 9392
diff changeset
   400
    }
ed79a66e57e5 Initial work on audio device hotplug support.
Ryan C. Gordon <icculus@icculus.org>
parents: 9392
diff changeset
   401
    *devices = NULL;
ed79a66e57e5 Initial work on audio device hotplug support.
Ryan C. Gordon <icculus@icculus.org>
parents: 9392
diff changeset
   402
    *devCount = 0;
ed79a66e57e5 Initial work on audio device hotplug support.
Ryan C. Gordon <icculus@icculus.org>
parents: 9392
diff changeset
   403
}
ed79a66e57e5 Initial work on audio device hotplug support.
Ryan C. Gordon <icculus@icculus.org>
parents: 9392
diff changeset
   404
ed79a66e57e5 Initial work on audio device hotplug support.
Ryan C. Gordon <icculus@icculus.org>
parents: 9392
diff changeset
   405
ed79a66e57e5 Initial work on audio device hotplug support.
Ryan C. Gordon <icculus@icculus.org>
parents: 9392
diff changeset
   406
/* 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
   407
void
9394
bb28e5281770 Bunch of reworking to how we manage audio devices.
Ryan C. Gordon <icculus@icculus.org>
parents: 9393
diff changeset
   408
SDL_AddAudioDevice(const int iscapture, const char *name, void *handle)
9393
ed79a66e57e5 Initial work on audio device hotplug support.
Ryan C. Gordon <icculus@icculus.org>
parents: 9392
diff changeset
   409
{
9394
bb28e5281770 Bunch of reworking to how we manage audio devices.
Ryan C. Gordon <icculus@icculus.org>
parents: 9393
diff changeset
   410
    const int device_index = iscapture ? add_capture_device(name, handle) : add_output_device(name, handle);
9393
ed79a66e57e5 Initial work on audio device hotplug support.
Ryan C. Gordon <icculus@icculus.org>
parents: 9392
diff changeset
   411
    if (device_index != -1) {
ed79a66e57e5 Initial work on audio device hotplug support.
Ryan C. Gordon <icculus@icculus.org>
parents: 9392
diff changeset
   412
        /* Post the event, if desired */
ed79a66e57e5 Initial work on audio device hotplug support.
Ryan C. Gordon <icculus@icculus.org>
parents: 9392
diff changeset
   413
        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
   414
            SDL_Event event;
ed79a66e57e5 Initial work on audio device hotplug support.
Ryan C. Gordon <icculus@icculus.org>
parents: 9392
diff changeset
   415
            event.adevice.type = SDL_AUDIODEVICEADDED;
ed79a66e57e5 Initial work on audio device hotplug support.
Ryan C. Gordon <icculus@icculus.org>
parents: 9392
diff changeset
   416
            event.adevice.which = device_index;
ed79a66e57e5 Initial work on audio device hotplug support.
Ryan C. Gordon <icculus@icculus.org>
parents: 9392
diff changeset
   417
            event.adevice.iscapture = iscapture;
ed79a66e57e5 Initial work on audio device hotplug support.
Ryan C. Gordon <icculus@icculus.org>
parents: 9392
diff changeset
   418
            SDL_PushEvent(&event);
ed79a66e57e5 Initial work on audio device hotplug support.
Ryan C. Gordon <icculus@icculus.org>
parents: 9392
diff changeset
   419
        }
ed79a66e57e5 Initial work on audio device hotplug support.
Ryan C. Gordon <icculus@icculus.org>
parents: 9392
diff changeset
   420
    }
ed79a66e57e5 Initial work on audio device hotplug support.
Ryan C. Gordon <icculus@icculus.org>
parents: 9392
diff changeset
   421
}
ed79a66e57e5 Initial work on audio device hotplug support.
Ryan C. Gordon <icculus@icculus.org>
parents: 9392
diff changeset
   422
9394
bb28e5281770 Bunch of reworking to how we manage audio devices.
Ryan C. Gordon <icculus@icculus.org>
parents: 9393
diff changeset
   423
/* The audio backends call this when a currently-opened device is lost. */
bb28e5281770 Bunch of reworking to how we manage audio devices.
Ryan C. Gordon <icculus@icculus.org>
parents: 9393
diff changeset
   424
void SDL_OpenedAudioDeviceDisconnected(SDL_AudioDevice *device)
9393
ed79a66e57e5 Initial work on audio device hotplug support.
Ryan C. Gordon <icculus@icculus.org>
parents: 9392
diff changeset
   425
{
9394
bb28e5281770 Bunch of reworking to how we manage audio devices.
Ryan C. Gordon <icculus@icculus.org>
parents: 9393
diff changeset
   426
    SDL_assert(get_audio_device(device->id) == device);
bb28e5281770 Bunch of reworking to how we manage audio devices.
Ryan C. Gordon <icculus@icculus.org>
parents: 9393
diff changeset
   427
    SDL_assert(device->enabled);  /* called more than once?! */
bb28e5281770 Bunch of reworking to how we manage audio devices.
Ryan C. Gordon <icculus@icculus.org>
parents: 9393
diff changeset
   428
bb28e5281770 Bunch of reworking to how we manage audio devices.
Ryan C. Gordon <icculus@icculus.org>
parents: 9393
diff changeset
   429
    /* Ends the audio callback and mark the device as STOPPED, but the
bb28e5281770 Bunch of reworking to how we manage audio devices.
Ryan C. Gordon <icculus@icculus.org>
parents: 9393
diff changeset
   430
       app still needs to close the device to free resources. */
bb28e5281770 Bunch of reworking to how we manage audio devices.
Ryan C. Gordon <icculus@icculus.org>
parents: 9393
diff changeset
   431
    current_audio.impl.LockDevice(device);
bb28e5281770 Bunch of reworking to how we manage audio devices.
Ryan C. Gordon <icculus@icculus.org>
parents: 9393
diff changeset
   432
    device->enabled = 0;
bb28e5281770 Bunch of reworking to how we manage audio devices.
Ryan C. Gordon <icculus@icculus.org>
parents: 9393
diff changeset
   433
    current_audio.impl.UnlockDevice(device);
9393
ed79a66e57e5 Initial work on audio device hotplug support.
Ryan C. Gordon <icculus@icculus.org>
parents: 9392
diff changeset
   434
9394
bb28e5281770 Bunch of reworking to how we manage audio devices.
Ryan C. Gordon <icculus@icculus.org>
parents: 9393
diff changeset
   435
    /* Post the event, if desired */
bb28e5281770 Bunch of reworking to how we manage audio devices.
Ryan C. Gordon <icculus@icculus.org>
parents: 9393
diff changeset
   436
    if (SDL_GetEventState(SDL_AUDIODEVICEREMOVED) == SDL_ENABLE) {
bb28e5281770 Bunch of reworking to how we manage audio devices.
Ryan C. Gordon <icculus@icculus.org>
parents: 9393
diff changeset
   437
        SDL_Event event;
bb28e5281770 Bunch of reworking to how we manage audio devices.
Ryan C. Gordon <icculus@icculus.org>
parents: 9393
diff changeset
   438
        event.adevice.type = SDL_AUDIODEVICEREMOVED;
bb28e5281770 Bunch of reworking to how we manage audio devices.
Ryan C. Gordon <icculus@icculus.org>
parents: 9393
diff changeset
   439
        event.adevice.which = device->id;
bb28e5281770 Bunch of reworking to how we manage audio devices.
Ryan C. Gordon <icculus@icculus.org>
parents: 9393
diff changeset
   440
        event.adevice.iscapture = device->iscapture ? 1 : 0;
bb28e5281770 Bunch of reworking to how we manage audio devices.
Ryan C. Gordon <icculus@icculus.org>
parents: 9393
diff changeset
   441
        SDL_PushEvent(&event);
bb28e5281770 Bunch of reworking to how we manage audio devices.
Ryan C. Gordon <icculus@icculus.org>
parents: 9393
diff changeset
   442
    }
bb28e5281770 Bunch of reworking to how we manage audio devices.
Ryan C. Gordon <icculus@icculus.org>
parents: 9393
diff changeset
   443
}
9393
ed79a66e57e5 Initial work on audio device hotplug support.
Ryan C. Gordon <icculus@icculus.org>
parents: 9392
diff changeset
   444
9394
bb28e5281770 Bunch of reworking to how we manage audio devices.
Ryan C. Gordon <icculus@icculus.org>
parents: 9393
diff changeset
   445
static void
bb28e5281770 Bunch of reworking to how we manage audio devices.
Ryan C. Gordon <icculus@icculus.org>
parents: 9393
diff changeset
   446
mark_device_removed(void *handle, SDL_AudioDeviceItem *devices, SDL_bool *removedFlag)
bb28e5281770 Bunch of reworking to how we manage audio devices.
Ryan C. Gordon <icculus@icculus.org>
parents: 9393
diff changeset
   447
{
bb28e5281770 Bunch of reworking to how we manage audio devices.
Ryan C. Gordon <icculus@icculus.org>
parents: 9393
diff changeset
   448
    SDL_AudioDeviceItem *item;
bb28e5281770 Bunch of reworking to how we manage audio devices.
Ryan C. Gordon <icculus@icculus.org>
parents: 9393
diff changeset
   449
    SDL_assert(handle != NULL);
bb28e5281770 Bunch of reworking to how we manage audio devices.
Ryan C. Gordon <icculus@icculus.org>
parents: 9393
diff changeset
   450
    for (item = devices; item != NULL; item = item->next) {
bb28e5281770 Bunch of reworking to how we manage audio devices.
Ryan C. Gordon <icculus@icculus.org>
parents: 9393
diff changeset
   451
        if (item->handle == handle) {
bb28e5281770 Bunch of reworking to how we manage audio devices.
Ryan C. Gordon <icculus@icculus.org>
parents: 9393
diff changeset
   452
            item->handle = NULL;
bb28e5281770 Bunch of reworking to how we manage audio devices.
Ryan C. Gordon <icculus@icculus.org>
parents: 9393
diff changeset
   453
            *removedFlag = SDL_TRUE;
bb28e5281770 Bunch of reworking to how we manage audio devices.
Ryan C. Gordon <icculus@icculus.org>
parents: 9393
diff changeset
   454
            return;
9393
ed79a66e57e5 Initial work on audio device hotplug support.
Ryan C. Gordon <icculus@icculus.org>
parents: 9392
diff changeset
   455
        }
ed79a66e57e5 Initial work on audio device hotplug support.
Ryan C. Gordon <icculus@icculus.org>
parents: 9392
diff changeset
   456
    }
9394
bb28e5281770 Bunch of reworking to how we manage audio devices.
Ryan C. Gordon <icculus@icculus.org>
parents: 9393
diff changeset
   457
}
9393
ed79a66e57e5 Initial work on audio device hotplug support.
Ryan C. Gordon <icculus@icculus.org>
parents: 9392
diff changeset
   458
9394
bb28e5281770 Bunch of reworking to how we manage audio devices.
Ryan C. Gordon <icculus@icculus.org>
parents: 9393
diff changeset
   459
/* The audio backends call this when a device is removed from the system. */
bb28e5281770 Bunch of reworking to how we manage audio devices.
Ryan C. Gordon <icculus@icculus.org>
parents: 9393
diff changeset
   460
void
bb28e5281770 Bunch of reworking to how we manage audio devices.
Ryan C. Gordon <icculus@icculus.org>
parents: 9393
diff changeset
   461
SDL_RemoveAudioDevice(void *handle)
bb28e5281770 Bunch of reworking to how we manage audio devices.
Ryan C. Gordon <icculus@icculus.org>
parents: 9393
diff changeset
   462
{
bb28e5281770 Bunch of reworking to how we manage audio devices.
Ryan C. Gordon <icculus@icculus.org>
parents: 9393
diff changeset
   463
    SDL_LockMutex(current_audio.detectionLock);
bb28e5281770 Bunch of reworking to how we manage audio devices.
Ryan C. Gordon <icculus@icculus.org>
parents: 9393
diff changeset
   464
    mark_device_removed(handle, current_audio.inputDevices, &current_audio.captureDevicesRemoved);
bb28e5281770 Bunch of reworking to how we manage audio devices.
Ryan C. Gordon <icculus@icculus.org>
parents: 9393
diff changeset
   465
    mark_device_removed(handle, current_audio.outputDevices, &current_audio.outputDevicesRemoved);
bb28e5281770 Bunch of reworking to how we manage audio devices.
Ryan C. Gordon <icculus@icculus.org>
parents: 9393
diff changeset
   466
    SDL_UnlockMutex(current_audio.detectionLock);
bb28e5281770 Bunch of reworking to how we manage audio devices.
Ryan C. Gordon <icculus@icculus.org>
parents: 9393
diff changeset
   467
    current_audio.impl.FreeDeviceHandle(handle);
9393
ed79a66e57e5 Initial work on audio device hotplug support.
Ryan C. Gordon <icculus@icculus.org>
parents: 9392
diff changeset
   468
}
ed79a66e57e5 Initial work on audio device hotplug support.
Ryan C. Gordon <icculus@icculus.org>
parents: 9392
diff changeset
   469
ed79a66e57e5 Initial work on audio device hotplug support.
Ryan C. Gordon <icculus@icculus.org>
parents: 9392
diff changeset
   470
9012
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   471
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   472
/* buffer queueing support... */
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   473
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   474
/* 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
   475
static void
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   476
free_audio_queue(SDL_AudioBufferQueue *buffer)
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   477
{
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   478
    while (buffer) {
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   479
        SDL_AudioBufferQueue *next = buffer->next;
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   480
        SDL_free(buffer);
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   481
        buffer = next;
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   482
    }
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   483
}
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   484
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   485
static void SDLCALL
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   486
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
   487
{
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   488
    /* 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
   489
    Uint32 len = (Uint32) _len;
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   490
    SDL_AudioDevice *device = (SDL_AudioDevice *) userdata;
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   491
    SDL_AudioBufferQueue *buffer;
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   492
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   493
    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
   494
    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
   495
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   496
    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
   497
        const Uint32 avail = buffer->datalen - buffer->startpos;
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   498
        const Uint32 cpy = SDL_min(len, avail);
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   499
        SDL_assert(device->queued_bytes >= avail);
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   500
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   501
        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
   502
        buffer->startpos += cpy;
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   503
        stream += cpy;
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   504
        device->queued_bytes -= cpy;
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   505
        len -= cpy;
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   506
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   507
        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
   508
            device->buffer_queue_head = buffer->next;
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   509
            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
   510
            buffer->next = device->buffer_queue_pool;
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   511
            device->buffer_queue_pool = buffer;
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   512
        }
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   513
    }
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   514
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   515
    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
   516
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   517
    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
   518
        SDL_assert(device->buffer_queue_head == NULL);
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   519
        SDL_memset(stream, device->spec.silence, len);
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   520
    }
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   521
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   522
    if (device->buffer_queue_head == NULL) {
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   523
        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
   524
    }
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   525
}
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   526
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   527
int
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   528
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
   529
{
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   530
    SDL_AudioDevice *device = get_audio_device(devid);
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   531
    const Uint8 *data = (const Uint8 *) _data;
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   532
    SDL_AudioBufferQueue *orighead;
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   533
    SDL_AudioBufferQueue *origtail;
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   534
    Uint32 origlen;
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   535
    Uint32 datalen;
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   536
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   537
    if (!device) {
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   538
        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
   539
    }
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   540
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   541
    if (device->spec.callback != SDL_BufferQueueDrainCallback) {
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   542
        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
   543
    }
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   544
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   545
    current_audio.impl.LockDevice(device);
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
    orighead = device->buffer_queue_head;
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   548
    origtail = device->buffer_queue_tail;
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   549
    origlen = origtail ? origtail->datalen : 0;
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   550
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   551
    while (len > 0) {
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   552
        SDL_AudioBufferQueue *packet = device->buffer_queue_tail;
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   553
        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
   554
        if (!packet || (packet->datalen >= SDL_AUDIOBUFFERQUEUE_PACKETLEN)) {
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   555
            /* 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
   556
            packet = device->buffer_queue_pool;
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   557
            if (packet != NULL) {
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   558
                /* we have one available in the pool. */
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   559
                device->buffer_queue_pool = packet->next;
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   560
            } else {
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   561
                /* Have to allocate a new one! */
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   562
                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
   563
                if (packet == NULL) {
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   564
                    /* 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
   565
                    if (!origtail) {
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   566
                        packet = device->buffer_queue_head;  /* whole queue. */
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   567
                    } else {
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   568
                        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
   569
                        origtail->next = NULL;
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   570
                        origtail->datalen = origlen;
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   571
                    }
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   572
                    device->buffer_queue_head = orighead;
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   573
                    device->buffer_queue_tail = origtail;
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   574
                    device->buffer_queue_pool = NULL;
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   575
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   576
                    current_audio.impl.UnlockDevice(device);
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   577
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   578
                    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
   579
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   580
                    return SDL_OutOfMemory();
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   581
                }
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
            packet->datalen = 0;
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   584
            packet->startpos = 0;
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   585
            packet->next = NULL;
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   586
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   587
            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
   588
            if (device->buffer_queue_tail == NULL) {
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   589
                device->buffer_queue_head = packet;
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   590
            } else {
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   591
                device->buffer_queue_tail->next = packet;
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   592
            }
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   593
            device->buffer_queue_tail = packet;
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   594
        }
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
        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
   597
        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
   598
        data += datalen;
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   599
        len -= datalen;
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   600
        packet->datalen += datalen;
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   601
        device->queued_bytes += datalen;
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   602
    }
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   603
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   604
    current_audio.impl.UnlockDevice(device);
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
    return 0;
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   607
}
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
Uint32
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   610
SDL_GetQueuedAudioSize(SDL_AudioDeviceID devid)
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 retval = 0;
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   613
    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
   614
36c472422d64 SDL_GetQueuedAudioSize() shouldn't grab lock when not set up for queueing.
Ryan C. Gordon <icculus@icculus.org>
parents: 9031
diff changeset
   615
    /* 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
   616
    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
   617
        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
   618
        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
   619
        current_audio.impl.UnlockDevice(device);
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   620
    }
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   621
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   622
    return retval;
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
void
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   626
SDL_ClearQueuedAudio(SDL_AudioDeviceID devid)
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
    SDL_AudioDevice *device = get_audio_device(devid);
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   629
    SDL_AudioBufferQueue *buffer = NULL;
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   630
    if (!device) {
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   631
        return;  /* nothing to do. */
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   632
    }
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   633
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   634
    /* 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
   635
    current_audio.impl.LockDevice(device);
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   636
    buffer = device->buffer_queue_head;
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   637
    device->buffer_queue_tail = NULL;
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   638
    device->buffer_queue_head = NULL;
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   639
    device->queued_bytes = 0;
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   640
    current_audio.impl.UnlockDevice(device);
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   641
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   642
    free_audio_queue(buffer);
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   643
}
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
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
   646
#if defined(__ANDROID__)
4722
faa228f7ce5b - Cleaned up a bunch of code
Paul Hunkin <paul@bieh.net>
parents: 4718
diff changeset
   647
#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
   648
#endif
4722
faa228f7ce5b - Cleaned up a bunch of code
Paul Hunkin <paul@bieh.net>
parents: 4718
diff changeset
   649
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   650
/* 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
   651
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
   652
SDL_RunAudio(void *devicep)
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   653
{
2049
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
   654
    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
   655
    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
   656
    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
   657
    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
   658
    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
   659
    Uint32 delay;
8660
6bd1f8bad873 Patched to compile on C89 compilers, removed more streamer code.
Ryan C. Gordon <icculus@icculus.org>
parents: 8658
diff changeset
   660
6bd1f8bad873 Patched to compile on C89 compilers, removed more streamer code.
Ryan C. Gordon <icculus@icculus.org>
parents: 8658
diff changeset
   661
#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
   662
    /* 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
   663
    Uint8 *istream;
5645b3a5dc03 Move variable declaration position to stick with C standart.
Airlangga Cahya Utama <airlangga.cahya@gmail.com>
parents: 5509
diff changeset
   664
    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
   665
#endif
2716
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   666
5509
5b1b4d820d10 The API sets the priority for the current thread, not an arbitrary thread.
Sam Lantinga <slouken@libsdl.org>
parents: 5506
diff changeset
   667
    /* 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
   668
    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
   669
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
   670
    /* 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
   671
    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
   672
    current_audio.impl.ThreadInit(device);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   673
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
   674
    /* 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
   675
    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
   676
    udata = device->spec.userdata;
21
75a95f82bc1f Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
   677
2716
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   678
    /* By default do not stream */
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   679
    device->use_streamer = 0;
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   680
2049
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
   681
    if (device->convert.needed) {
3040
Sam Lantinga <slouken@libsdl.org>
parents: 3032
diff changeset
   682
#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
   683
        /* 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
   684
        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
   685
            /* 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
   686
            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
   687
            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
   688
                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
   689
                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
   690
            }
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   691
            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
   692
                0)
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   693
                return -1;
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   694
            device->use_streamer = 1;
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   695
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   696
            /* 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
   697
               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
   698
             */
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   699
            istream_len =
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   700
                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
   701
                device->convert.len_mult;
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   702
        }
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2984
diff changeset
   703
#endif
7518
febc83bc2a43 Fixed crash and garbled output when converting from F32 to S16 audio.
Sam Lantinga <slouken@libsdl.org>
parents: 7447
diff changeset
   704
        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
   705
    } 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
   706
        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
   707
    }
1561
c724c4a99759 Try to fill the hardware audio buffer immediately.
Ryan C. Gordon <icculus@icculus.org>
parents: 1532
diff changeset
   708
3336
00fab0ebfe54 Fixed a bug where when the audio starts paused all the DirectSound buffers
Sam Lantinga <slouken@libsdl.org>
parents: 3283
diff changeset
   709
    /* 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
   710
    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
   711
2716
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   712
    /* 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
   713
#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
   714
    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
   715
        /* 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
   716
           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
   717
           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
   718
           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
   719
           - 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
   720
           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
   721
           - 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
   722
           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
   723
           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
   724
           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
   725
           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
   726
         */
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   727
        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
   728
00fab0ebfe54 Fixed a bug where when the audio starts paused all the DirectSound buffers
Sam Lantinga <slouken@libsdl.org>
parents: 3283
diff changeset
   729
            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
   730
                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
   731
                continue;
00fab0ebfe54 Fixed a bug where when the audio starts paused all the DirectSound buffers
Sam Lantinga <slouken@libsdl.org>
parents: 3283
diff changeset
   732
            }
00fab0ebfe54 Fixed a bug where when the audio starts paused all the DirectSound buffers
Sam Lantinga <slouken@libsdl.org>
parents: 3283
diff changeset
   733
2716
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   734
            /* 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
   735
            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
   736
                /* Set up istream */
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   737
                if (device->convert.needed) {
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   738
                    if (device->convert.buf) {
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   739
                        istream = device->convert.buf;
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   740
                    } else {
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   741
                        continue;
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   742
                    }
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   743
                } 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
   744
/* 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
   745
 * 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
   746
 */
2716
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   747
                    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
   748
                    if (istream == NULL) {
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   749
                        istream = device->fake_stream;
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   750
                    }
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   751
                }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   752
2716
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   753
                /* 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
   754
                // !!! FIXME: this should be LockDevice.
6977
b73d51026c68 Changed the name of SDL_mutexP() SDL_mutexV()
Sam Lantinga <slouken@libsdl.org>
parents: 6905
diff changeset
   755
                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
   756
                (*fill) (udata, istream, istream_len);
6977
b73d51026c68 Changed the name of SDL_mutexP() SDL_mutexV()
Sam Lantinga <slouken@libsdl.org>
parents: 6905
diff changeset
   757
                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
   758
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   759
                /* 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
   760
                if (device->convert.needed) {
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   761
                    SDL_ConvertAudio(&device->convert);
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   762
                    if (istream == NULL) {
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   763
                        istream = device->fake_stream;
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   764
                    }
7678
286c42d7c5ed OCD fixes: Adds a space after /* (glory to regular expressions!)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7518
diff changeset
   765
                    /* 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
   766
                    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
   767
                                    device->convert.len_cvt);
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   768
                } else {
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   769
                    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
   770
                }
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
   771
            }
2716
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   772
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   773
            /* 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
   774
            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
   775
                /* Set up the output stream */
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   776
                if (device->convert.needed) {
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   777
                    if (device->convert.buf) {
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   778
                        stream = device->convert.buf;
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   779
                    } else {
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   780
                        continue;
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   781
                    }
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
                    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
   784
                    if (stream == NULL) {
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   785
                        stream = device->fake_stream;
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   786
                    }
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   787
                }
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   788
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   789
                /* Now read from the streamer */
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   790
                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
   791
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   792
                /* 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
   793
                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
   794
                    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
   795
                    /* 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
   796
                    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
   797
                } 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
   798
                    SDL_Delay(delay);
2716
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   799
                }
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
   800
            }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   801
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
   802
        }
8660
6bd1f8bad873 Patched to compile on C89 compilers, removed more streamer code.
Ryan C. Gordon <icculus@icculus.org>
parents: 8658
diff changeset
   803
    } else
8658
7939f33e81ac #ifdef'd out the audio streamer code.
Ryan C. Gordon <icculus@icculus.org>
parents: 8149
diff changeset
   804
#endif
8660
6bd1f8bad873 Patched to compile on C89 compilers, removed more streamer code.
Ryan C. Gordon <icculus@icculus.org>
parents: 8658
diff changeset
   805
    {
2716
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   806
        /* 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
   807
        const int silence = (int) device->spec.silence;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   808
2716
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   809
        /* Loop, filling the audio buffers */
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   810
        while (device->enabled) {
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   811
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   812
            /* 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
   813
            if (device->convert.needed) {
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   814
                if (device->convert.buf) {
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   815
                    stream = device->convert.buf;
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   816
                } else {
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   817
                    continue;
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   818
                }
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
                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
   821
                if (stream == NULL) {
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   822
                    stream = device->fake_stream;
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   823
                }
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
   824
            }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   825
9391
3a54985e999e Tweaked a couple comments, added some FIXMEs.
Ryan C. Gordon <icculus@icculus.org>
parents: 9382
diff changeset
   826
            /* !!! 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
   827
            SDL_LockMutex(device->mixer_lock);
9393
ed79a66e57e5 Initial work on audio device hotplug support.
Ryan C. Gordon <icculus@icculus.org>
parents: 9392
diff changeset
   828
ed79a66e57e5 Initial work on audio device hotplug support.
Ryan C. Gordon <icculus@icculus.org>
parents: 9392
diff changeset
   829
            /* 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
   830
            if (!device->enabled) {
ed79a66e57e5 Initial work on audio device hotplug support.
Ryan C. Gordon <icculus@icculus.org>
parents: 9392
diff changeset
   831
                SDL_UnlockMutex(device->mixer_lock);
ed79a66e57e5 Initial work on audio device hotplug support.
Ryan C. Gordon <icculus@icculus.org>
parents: 9392
diff changeset
   832
                break;
ed79a66e57e5 Initial work on audio device hotplug support.
Ryan C. Gordon <icculus@icculus.org>
parents: 9392
diff changeset
   833
            }
ed79a66e57e5 Initial work on audio device hotplug support.
Ryan C. Gordon <icculus@icculus.org>
parents: 9392
diff changeset
   834
7406
fb02213c11d3 Explicitly write silence to the audio device while it is paused.
Ryan C. Gordon <icculus@icculus.org>
parents: 7367
diff changeset
   835
            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
   836
                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
   837
            } else {
fb02213c11d3 Explicitly write silence to the audio device while it is paused.
Ryan C. Gordon <icculus@icculus.org>
parents: 7367
diff changeset
   838
                (*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
   839
            }
7447
6860de5bcb8c Protect SDL_PauseAudio*() with the audio callback lock.
Ryan C. Gordon <icculus@icculus.org>
parents: 7446
diff changeset
   840
            SDL_UnlockMutex(device->mixer_lock);
1562
1d487a3fab41 Fixed bug #18
Sam Lantinga <slouken@libsdl.org>
parents: 1561
diff changeset
   841
2716
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   842
            /* Convert the audio if necessary */
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   843
            if (device->convert.needed) {
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   844
                SDL_ConvertAudio(&device->convert);
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   845
                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
   846
                if (stream == NULL) {
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   847
                    stream = device->fake_stream;
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   848
                }
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   849
                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
   850
                           device->convert.len_cvt);
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
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   853
            /* 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
   854
            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
   855
                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
   856
                /* 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
   857
                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
   858
            } 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
   859
                SDL_Delay(delay);
2716
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   860
            }
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
   861
        }
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
   862
    }
1562
1d487a3fab41 Fixed bug #18
Sam Lantinga <slouken@libsdl.org>
parents: 1561
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
    /* 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
   865
    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
   866
2716
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   867
    /* If necessary, deinit the streamer */
8658
7939f33e81ac #ifdef'd out the audio streamer code.
Ryan C. Gordon <icculus@icculus.org>
parents: 8149
diff changeset
   868
#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
   869
    if (device->use_streamer == 1)
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   870
        SDL_StreamDeinit(&device->streamer);
8658
7939f33e81ac #ifdef'd out the audio streamer code.
Ryan C. Gordon <icculus@icculus.org>
parents: 8149
diff changeset
   871
#endif
2716
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   872
9382
1c0f6952e65e Cleaning out a silly coding style I used to use.
Ryan C. Gordon <icculus@icculus.org>
parents: 9381
diff changeset
   873
    return 0;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   874
}
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   875
322
fd93a09655e3 The audio lock and unlock functions are now a part of the driver.
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
   876
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1978
diff changeset
   877
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
   878
SDL_ParseAudioFormat(const char *string)
1794
5605a9820134 Fixed bug #137
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
   879
{
2076
939420dee849 Use SDL_strcmp(), not strcmp().
Ryan C. Gordon <icculus@icculus.org>
parents: 2070
diff changeset
   880
#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
   881
    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
   882
    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
   883
    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
   884
    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
   885
    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
   886
    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
   887
    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
   888
    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
   889
    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
   890
    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
   891
    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
   892
    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
   893
    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
   894
    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
   895
    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
   896
    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
   897
    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
   898
    CHECK_FMT_STRING(F32);
2060
866052b01ee5 indent is evil
Sam Lantinga <slouken@libsdl.org>
parents: 2053
diff changeset
   899
#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
   900
    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
   901
}
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
   902
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
   903
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
   904
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
   905
{
9382
1c0f6952e65e Cleaning out a silly coding style I used to use.
Ryan C. Gordon <icculus@icculus.org>
parents: 9381
diff changeset
   906
    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
   907
}
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
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
   909
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
   910
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
   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
    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
   913
        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
   914
    }
9382
1c0f6952e65e Cleaning out a silly coding style I used to use.
Ryan C. Gordon <icculus@icculus.org>
parents: 9381
diff changeset
   915
    return NULL;
1794
5605a9820134 Fixed bug #137
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
   916
}
5605a9820134 Fixed bug #137
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
   917
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
   918
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
   919
SDL_AudioInit(const char *driver_name)
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   920
{
2049
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
   921
    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
   922
    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
   923
    int tried_to_init = 0;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   924
2049
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
   925
    if (SDL_WasInit(SDL_INIT_AUDIO)) {
2060
866052b01ee5 indent is evil
Sam Lantinga <slouken@libsdl.org>
parents: 2053
diff changeset
   926
        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
   927
    }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   928
9392
92e23eff9b89 Changed some SDL_memset() calls to SDL_zero().
Ryan C. Gordon <icculus@icculus.org>
parents: 9391
diff changeset
   929
    SDL_zero(current_audio);
92e23eff9b89 Changed some SDL_memset() calls to SDL_zero().
Ryan C. Gordon <icculus@icculus.org>
parents: 9391
diff changeset
   930
    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
   931
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
   932
    /* 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
   933
    if (driver_name == NULL) {
8f1ab2f7c722 Look at environment variables in SDL_VideoInit() and SDL_AudioInit()
Sam Lantinga <slouken@libsdl.org>
parents: 1903
diff changeset
   934
        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
   935
    }
2049
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
   936
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
   937
    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
   938
        /* 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
   939
        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
   940
        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
   941
            (!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
   942
            continue;
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
   943
        }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   944
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
        tried_to_init = 1;
9392
92e23eff9b89 Changed some SDL_memset() calls to SDL_zero().
Ryan C. Gordon <icculus@icculus.org>
parents: 9391
diff changeset
   946
        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
   947
        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
   948
        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
   949
        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
   950
    }
2049
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
   951
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
   952
    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
   953
        /* 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
   954
        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
   955
            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
   956
                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
   957
            } 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
   958
                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
   959
            }
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
        }
2049
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
   961
9392
92e23eff9b89 Changed some SDL_memset() calls to SDL_zero().
Ryan C. Gordon <icculus@icculus.org>
parents: 9391
diff changeset
   962
        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
   963
        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
   964
    }
2049
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
   965
9394
bb28e5281770 Bunch of reworking to how we manage audio devices.
Ryan C. Gordon <icculus@icculus.org>
parents: 9393
diff changeset
   966
    current_audio.detectionLock = SDL_CreateMutex();
9393
ed79a66e57e5 Initial work on audio device hotplug support.
Ryan C. Gordon <icculus@icculus.org>
parents: 9392
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
    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
   969
9393
ed79a66e57e5 Initial work on audio device hotplug support.
Ryan C. Gordon <icculus@icculus.org>
parents: 9392
diff changeset
   970
    /* Make sure we have a list of devices available at startup. */
9394
bb28e5281770 Bunch of reworking to how we manage audio devices.
Ryan C. Gordon <icculus@icculus.org>
parents: 9393
diff changeset
   971
    current_audio.impl.DetectDevices();
9393
ed79a66e57e5 Initial work on audio device hotplug support.
Ryan C. Gordon <icculus@icculus.org>
parents: 9392
diff changeset
   972
9382
1c0f6952e65e Cleaning out a silly coding style I used to use.
Ryan C. Gordon <icculus@icculus.org>
parents: 9381
diff changeset
   973
    return 0;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   974
}
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   975
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
   976
/*
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
   977
 * 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
   978
 */
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
   979
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
   980
SDL_GetCurrentAudioDriver()
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   981
{
2049
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
   982
    return current_audio.name;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   983
}
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   984
9394
bb28e5281770 Bunch of reworking to how we manage audio devices.
Ryan C. Gordon <icculus@icculus.org>
parents: 9393
diff changeset
   985
/* Clean out devices that we've removed but had to keep around for stability. */
bb28e5281770 Bunch of reworking to how we manage audio devices.
Ryan C. Gordon <icculus@icculus.org>
parents: 9393
diff changeset
   986
static void
bb28e5281770 Bunch of reworking to how we manage audio devices.
Ryan C. Gordon <icculus@icculus.org>
parents: 9393
diff changeset
   987
clean_out_device_list(SDL_AudioDeviceItem **devices, int *devCount, SDL_bool *removedFlag)
bb28e5281770 Bunch of reworking to how we manage audio devices.
Ryan C. Gordon <icculus@icculus.org>
parents: 9393
diff changeset
   988
{
bb28e5281770 Bunch of reworking to how we manage audio devices.
Ryan C. Gordon <icculus@icculus.org>
parents: 9393
diff changeset
   989
    SDL_AudioDeviceItem *item = *devices;
bb28e5281770 Bunch of reworking to how we manage audio devices.
Ryan C. Gordon <icculus@icculus.org>
parents: 9393
diff changeset
   990
    SDL_AudioDeviceItem *prev = NULL;
bb28e5281770 Bunch of reworking to how we manage audio devices.
Ryan C. Gordon <icculus@icculus.org>
parents: 9393
diff changeset
   991
    int total = 0;
bb28e5281770 Bunch of reworking to how we manage audio devices.
Ryan C. Gordon <icculus@icculus.org>
parents: 9393
diff changeset
   992
bb28e5281770 Bunch of reworking to how we manage audio devices.
Ryan C. Gordon <icculus@icculus.org>
parents: 9393
diff changeset
   993
    while (item) {
bb28e5281770 Bunch of reworking to how we manage audio devices.
Ryan C. Gordon <icculus@icculus.org>
parents: 9393
diff changeset
   994
        SDL_AudioDeviceItem *next = item->next;
bb28e5281770 Bunch of reworking to how we manage audio devices.
Ryan C. Gordon <icculus@icculus.org>
parents: 9393
diff changeset
   995
        if (item->handle != NULL) {
bb28e5281770 Bunch of reworking to how we manage audio devices.
Ryan C. Gordon <icculus@icculus.org>
parents: 9393
diff changeset
   996
            total++;
bb28e5281770 Bunch of reworking to how we manage audio devices.
Ryan C. Gordon <icculus@icculus.org>
parents: 9393
diff changeset
   997
            prev = item;
bb28e5281770 Bunch of reworking to how we manage audio devices.
Ryan C. Gordon <icculus@icculus.org>
parents: 9393
diff changeset
   998
        } else {
bb28e5281770 Bunch of reworking to how we manage audio devices.
Ryan C. Gordon <icculus@icculus.org>
parents: 9393
diff changeset
   999
            if (prev) {
bb28e5281770 Bunch of reworking to how we manage audio devices.
Ryan C. Gordon <icculus@icculus.org>
parents: 9393
diff changeset
  1000
                prev->next = next;
bb28e5281770 Bunch of reworking to how we manage audio devices.
Ryan C. Gordon <icculus@icculus.org>
parents: 9393
diff changeset
  1001
            } else {
bb28e5281770 Bunch of reworking to how we manage audio devices.
Ryan C. Gordon <icculus@icculus.org>
parents: 9393
diff changeset
  1002
                *devices = next;
bb28e5281770 Bunch of reworking to how we manage audio devices.
Ryan C. Gordon <icculus@icculus.org>
parents: 9393
diff changeset
  1003
            }
bb28e5281770 Bunch of reworking to how we manage audio devices.
Ryan C. Gordon <icculus@icculus.org>
parents: 9393
diff changeset
  1004
            SDL_free(item);
bb28e5281770 Bunch of reworking to how we manage audio devices.
Ryan C. Gordon <icculus@icculus.org>
parents: 9393
diff changeset
  1005
        }
bb28e5281770 Bunch of reworking to how we manage audio devices.
Ryan C. Gordon <icculus@icculus.org>
parents: 9393
diff changeset
  1006
        item = next;
bb28e5281770 Bunch of reworking to how we manage audio devices.
Ryan C. Gordon <icculus@icculus.org>
parents: 9393
diff changeset
  1007
    }
bb28e5281770 Bunch of reworking to how we manage audio devices.
Ryan C. Gordon <icculus@icculus.org>
parents: 9393
diff changeset
  1008
bb28e5281770 Bunch of reworking to how we manage audio devices.
Ryan C. Gordon <icculus@icculus.org>
parents: 9393
diff changeset
  1009
    *devCount = total;
bb28e5281770 Bunch of reworking to how we manage audio devices.
Ryan C. Gordon <icculus@icculus.org>
parents: 9393
diff changeset
  1010
    *removedFlag = SDL_FALSE;
bb28e5281770 Bunch of reworking to how we manage audio devices.
Ryan C. Gordon <icculus@icculus.org>
parents: 9393
diff changeset
  1011
}
bb28e5281770 Bunch of reworking to how we manage audio devices.
Ryan C. Gordon <icculus@icculus.org>
parents: 9393
diff changeset
  1012
bb28e5281770 Bunch of reworking to how we manage audio devices.
Ryan C. Gordon <icculus@icculus.org>
parents: 9393
diff changeset
  1013
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
  1014
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
  1015
SDL_GetNumAudioDevices(int iscapture)
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
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
    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
  1018
2049
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
  1019
    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
  1020
        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
  1021
    }
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
  1022
9394
bb28e5281770 Bunch of reworking to how we manage audio devices.
Ryan C. Gordon <icculus@icculus.org>
parents: 9393
diff changeset
  1023
    SDL_LockMutex(current_audio.detectionLock);
bb28e5281770 Bunch of reworking to how we manage audio devices.
Ryan C. Gordon <icculus@icculus.org>
parents: 9393
diff changeset
  1024
    if (iscapture && current_audio.captureDevicesRemoved) {
bb28e5281770 Bunch of reworking to how we manage audio devices.
Ryan C. Gordon <icculus@icculus.org>
parents: 9393
diff changeset
  1025
        clean_out_device_list(&current_audio.inputDevices, &current_audio.inputDeviceCount, &current_audio.captureDevicesRemoved);
2049
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
  1026
    }
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
  1027
9394
bb28e5281770 Bunch of reworking to how we manage audio devices.
Ryan C. Gordon <icculus@icculus.org>
parents: 9393
diff changeset
  1028
    if (!iscapture && current_audio.outputDevicesRemoved) {
bb28e5281770 Bunch of reworking to how we manage audio devices.
Ryan C. Gordon <icculus@icculus.org>
parents: 9393
diff changeset
  1029
        clean_out_device_list(&current_audio.outputDevices, &current_audio.outputDeviceCount, &current_audio.outputDevicesRemoved);
bb28e5281770 Bunch of reworking to how we manage audio devices.
Ryan C. Gordon <icculus@icculus.org>
parents: 9393
diff changeset
  1030
        current_audio.outputDevicesRemoved = SDL_FALSE;
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
  1031
    }
ab22ca13c47f Cleaned up audio device detection. Cleared out a lot of cut-and-paste.
Ryan C. Gordon <icculus@icculus.org>
parents: 5592
diff changeset
  1032
9393
ed79a66e57e5 Initial work on audio device hotplug support.
Ryan C. Gordon <icculus@icculus.org>
parents: 9392
diff changeset
  1033
    retval = iscapture ? current_audio.inputDeviceCount : current_audio.outputDeviceCount;
9394
bb28e5281770 Bunch of reworking to how we manage audio devices.
Ryan C. Gordon <icculus@icculus.org>
parents: 9393
diff changeset
  1034
    SDL_UnlockMutex(current_audio.detectionLock);
9393
ed79a66e57e5 Initial work on audio device hotplug support.
Ryan C. Gordon <icculus@icculus.org>
parents: 9392
diff changeset
  1035
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
  1036
    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
  1037
}
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
  1038
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1039
2049
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
  1040
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
  1041
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
  1042
{
9393
ed79a66e57e5 Initial work on audio device hotplug support.
Ryan C. Gordon <icculus@icculus.org>
parents: 9392
diff changeset
  1043
    const char *retval = NULL;
ed79a66e57e5 Initial work on audio device hotplug support.
Ryan C. Gordon <icculus@icculus.org>
parents: 9392
diff changeset
  1044
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
    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