src/audio/SDL_audio.c
author Ryan C. Gordon <icculus@icculus.org>
Tue, 22 Jul 2014 21:41:49 -0400
changeset 9012 aa058c87737b
parent 9010 6d059ed9b6ca
child 9031 e963a13a720c
permissions -rw-r--r--
Added audio device buffer queueing API.
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
#if SDL_AUDIO_DRIVER_NACL
ae720d61d14d Chrome's Native Client backend implementation
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8761
diff changeset
    55
extern AudioBootStrap NACLAUD_bootstrap;
ae720d61d14d Chrome's Native Client backend implementation
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8761
diff changeset
    56
#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
    57
extern AudioBootStrap NAS_bootstrap;
5592
2e88d0742f4d Implemented XAudio2 target for Windows (and Xbox360, theoretically!).
Ryan C. Gordon <icculus@icculus.org>
parents: 5588
diff changeset
    58
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
    59
extern AudioBootStrap DSOUND_bootstrap;
5588
57bfc2a2a452 Reworked Windows waveOut code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5586
diff changeset
    60
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
    61
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
    62
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
    63
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
    64
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
    65
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
    66
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
    67
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
    68
extern AudioBootStrap DART_bootstrap;
2735
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2728
diff changeset
    69
extern AudioBootStrap NDSAUD_bootstrap;
2947
fec0db6c44b7 Date: Thu, 01 Jan 2009 21:32:12 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2942
diff changeset
    70
extern AudioBootStrap FUSIONSOUND_bootstrap;
4718
79aa6c61f33b Added stub android sound system
Paul Hunkin <paul@bieh.net>
parents: 3699
diff changeset
    71
extern AudioBootStrap ANDROIDAUD_bootstrap;
7009
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents: 6977
diff changeset
    72
extern AudioBootStrap PSPAUD_bootstrap;
7367
d6eabafa8776 Added an SDL2 OpenBSD sndio(7) audio target.
Ryan C. Gordon <icculus@icculus.org>
parents: 7348
diff changeset
    73
extern AudioBootStrap SNDIO_bootstrap;
1190
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents: 955
diff changeset
    74
8833
ae720d61d14d Chrome's Native Client backend implementation
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8761
diff changeset
    75
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    76
/* Available audio drivers */
3162
dc1eb82ffdaa Von: Thomas Zimmermann
Sam Lantinga <slouken@libsdl.org>
parents: 3139
diff changeset
    77
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
    78
#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
    79
    &PULSEAUDIO_bootstrap,
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    80
#endif
1361
19418e4422cb New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents: 1358
diff changeset
    81
#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
    82
    &ALSA_bootstrap,
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    83
#endif
7367
d6eabafa8776 Added an SDL2 OpenBSD sndio(7) audio target.
Ryan C. Gordon <icculus@icculus.org>
parents: 7348
diff changeset
    84
#if SDL_AUDIO_DRIVER_SNDIO
d6eabafa8776 Added an SDL2 OpenBSD sndio(7) audio target.
Ryan C. Gordon <icculus@icculus.org>
parents: 7348
diff changeset
    85
    &SNDIO_bootstrap,
d6eabafa8776 Added an SDL2 OpenBSD sndio(7) audio target.
Ryan C. Gordon <icculus@icculus.org>
parents: 7348
diff changeset
    86
#endif
4548
b135d19f9764 RedHat patch: SDL-1.2.14-audiodriver.patch
Sam Lantinga <slouken@libsdl.org>
parents: 4507
diff changeset
    87
#if SDL_AUDIO_DRIVER_BSD
b135d19f9764 RedHat patch: SDL-1.2.14-audiodriver.patch
Sam Lantinga <slouken@libsdl.org>
parents: 4507
diff changeset
    88
    &BSD_AUDIO_bootstrap,
b135d19f9764 RedHat patch: SDL-1.2.14-audiodriver.patch
Sam Lantinga <slouken@libsdl.org>
parents: 4507
diff changeset
    89
#endif
2939
084e5b4fc5be Audio driver priority: favor PulseAudio and ALSA over OSS.
Ryan C. Gordon <icculus@icculus.org>
parents: 2938
diff changeset
    90
#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
    91
    &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
    92
#endif
3099
82e60908fab1 Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 3096
diff changeset
    93
#if SDL_AUDIO_DRIVER_QSA
82e60908fab1 Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 3096
diff changeset
    94
    &QSAAUDIO_bootstrap,
663
8bedd6d61642 Date: Sat, 2 Aug 2003 16:22:51 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 654
diff changeset
    95
#endif
1361
19418e4422cb New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents: 1358
diff changeset
    96
#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
    97
    &SUNAUDIO_bootstrap,
148
8758b8d42cd9 Audio subsystem no longer assumes sun audio API on UNIX systems
Sam Lantinga <slouken@libsdl.org>
parents: 121
diff changeset
    98
#endif
1361
19418e4422cb New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents: 1358
diff changeset
    99
#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
   100
    &ARTS_bootstrap,
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   101
#endif
1361
19418e4422cb New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents: 1358
diff changeset
   102
#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
   103
    &ESD_bootstrap,
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   104
#endif
8833
ae720d61d14d Chrome's Native Client backend implementation
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8761
diff changeset
   105
#if SDL_AUDIO_DRIVER_NACL
ae720d61d14d Chrome's Native Client backend implementation
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8761
diff changeset
   106
   &NACLAUD_bootstrap,
ae720d61d14d Chrome's Native Client backend implementation
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8761
diff changeset
   107
#endif
1361
19418e4422cb New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents: 1358
diff changeset
   108
#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
   109
    &NAS_bootstrap,
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   110
#endif
5592
2e88d0742f4d Implemented XAudio2 target for Windows (and Xbox360, theoretically!).
Ryan C. Gordon <icculus@icculus.org>
parents: 5588
diff changeset
   111
#if SDL_AUDIO_DRIVER_XAUDIO2
2e88d0742f4d Implemented XAudio2 target for Windows (and Xbox360, theoretically!).
Ryan C. Gordon <icculus@icculus.org>
parents: 5588
diff changeset
   112
    &XAUDIO2_bootstrap,
2e88d0742f4d Implemented XAudio2 target for Windows (and Xbox360, theoretically!).
Ryan C. Gordon <icculus@icculus.org>
parents: 5588
diff changeset
   113
#endif
1361
19418e4422cb New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents: 1358
diff changeset
   114
#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
   115
    &DSOUND_bootstrap,
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   116
#endif
5588
57bfc2a2a452 Reworked Windows waveOut code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5586
diff changeset
   117
#if SDL_AUDIO_DRIVER_WINMM
57bfc2a2a452 Reworked Windows waveOut code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5586
diff changeset
   118
    &WINMM_bootstrap,
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   119
#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
   120
#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
   121
    &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
   122
#endif
7981
6d538bc1b395 Renamed things named after BeOS to be named after Haiku instead.
Ryan C. Gordon <icculus@icculus.org>
parents: 7904
diff changeset
   123
#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
   124
    &HAIKUAUDIO_bootstrap,
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   125
#endif
1361
19418e4422cb New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents: 1358
diff changeset
   126
#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
   127
    &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
   128
#endif
1361
19418e4422cb New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents: 1358
diff changeset
   129
#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
   130
    &DISKAUD_bootstrap,
68
ac6645260d31 Added an audio driver that writes to disk (thanks Ryan!)
Sam Lantinga <slouken@lokigames.com>
parents: 38
diff changeset
   131
#endif
1532
30f189cdd82b Implemented dummy audio driver.
Ryan C. Gordon <icculus@icculus.org>
parents: 1487
diff changeset
   132
#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
   133
    &DUMMYAUD_bootstrap,
1532
30f189cdd82b Implemented dummy audio driver.
Ryan C. Gordon <icculus@icculus.org>
parents: 1487
diff changeset
   134
#endif
2947
fec0db6c44b7 Date: Thu, 01 Jan 2009 21:32:12 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2942
diff changeset
   135
#if SDL_AUDIO_DRIVER_FUSIONSOUND
fec0db6c44b7 Date: Thu, 01 Jan 2009 21:32:12 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2942
diff changeset
   136
    &FUSIONSOUND_bootstrap,
fec0db6c44b7 Date: Thu, 01 Jan 2009 21:32:12 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2942
diff changeset
   137
#endif
4718
79aa6c61f33b Added stub android sound system
Paul Hunkin <paul@bieh.net>
parents: 3699
diff changeset
   138
#if SDL_AUDIO_DRIVER_ANDROID
79aa6c61f33b Added stub android sound system
Paul Hunkin <paul@bieh.net>
parents: 3699
diff changeset
   139
    &ANDROIDAUD_bootstrap,
79aa6c61f33b Added stub android sound system
Paul Hunkin <paul@bieh.net>
parents: 3699
diff changeset
   140
#endif
7009
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents: 6977
diff changeset
   141
#if SDL_AUDIO_DRIVER_PSP
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents: 6977
diff changeset
   142
    &PSPAUD_bootstrap,
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents: 6977
diff changeset
   143
#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
   144
    NULL
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   145
};
2049
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
   146
2060
866052b01ee5 indent is evil
Sam Lantinga <slouken@libsdl.org>
parents: 2053
diff changeset
   147
static SDL_AudioDevice *
866052b01ee5 indent is evil
Sam Lantinga <slouken@libsdl.org>
parents: 2053
diff changeset
   148
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
   149
{
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
   150
    id--;
2060
866052b01ee5 indent is evil
Sam Lantinga <slouken@libsdl.org>
parents: 2053
diff changeset
   151
    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
   152
        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
   153
        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
   154
    }
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
   155
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
   156
    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
   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
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
/* 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
   161
static void
ab22ca13c47f Cleaned up audio device detection. Cleared out a lot of cut-and-paste.
Ryan C. Gordon <icculus@icculus.org>
parents: 5592
diff changeset
   162
SDL_AudioDetectDevices_Default(int iscapture, SDL_AddAudioDevice addfn)
ab22ca13c47f Cleaned up audio device detection. Cleared out a lot of cut-and-paste.
Ryan C. Gordon <icculus@icculus.org>
parents: 5592
diff changeset
   163
{                               /* no-op. */
2060
866052b01ee5 indent is evil
Sam Lantinga <slouken@libsdl.org>
parents: 2053
diff changeset
   164
}
2735
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2728
diff changeset
   165
2060
866052b01ee5 indent is evil
Sam Lantinga <slouken@libsdl.org>
parents: 2053
diff changeset
   166
static void
866052b01ee5 indent is evil
Sam Lantinga <slouken@libsdl.org>
parents: 2053
diff changeset
   167
SDL_AudioThreadInit_Default(_THIS)
866052b01ee5 indent is evil
Sam Lantinga <slouken@libsdl.org>
parents: 2053
diff changeset
   168
{                               /* no-op. */
866052b01ee5 indent is evil
Sam Lantinga <slouken@libsdl.org>
parents: 2053
diff changeset
   169
}
2735
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2728
diff changeset
   170
2060
866052b01ee5 indent is evil
Sam Lantinga <slouken@libsdl.org>
parents: 2053
diff changeset
   171
static void
866052b01ee5 indent is evil
Sam Lantinga <slouken@libsdl.org>
parents: 2053
diff changeset
   172
SDL_AudioWaitDevice_Default(_THIS)
866052b01ee5 indent is evil
Sam Lantinga <slouken@libsdl.org>
parents: 2053
diff changeset
   173
{                               /* no-op. */
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_AudioPlayDevice_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 Uint8 *
866052b01ee5 indent is evil
Sam Lantinga <slouken@libsdl.org>
parents: 2053
diff changeset
   182
SDL_AudioGetDeviceBuf_Default(_THIS)
866052b01ee5 indent is evil
Sam Lantinga <slouken@libsdl.org>
parents: 2053
diff changeset
   183
{
866052b01ee5 indent is evil
Sam Lantinga <slouken@libsdl.org>
parents: 2053
diff changeset
   184
    return NULL;
866052b01ee5 indent is evil
Sam Lantinga <slouken@libsdl.org>
parents: 2053
diff changeset
   185
}
2735
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2728
diff changeset
   186
2060
866052b01ee5 indent is evil
Sam Lantinga <slouken@libsdl.org>
parents: 2053
diff changeset
   187
static void
866052b01ee5 indent is evil
Sam Lantinga <slouken@libsdl.org>
parents: 2053
diff changeset
   188
SDL_AudioWaitDone_Default(_THIS)
866052b01ee5 indent is evil
Sam Lantinga <slouken@libsdl.org>
parents: 2053
diff changeset
   189
{                               /* no-op. */
866052b01ee5 indent is evil
Sam Lantinga <slouken@libsdl.org>
parents: 2053
diff changeset
   190
}
2735
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2728
diff changeset
   191
2060
866052b01ee5 indent is evil
Sam Lantinga <slouken@libsdl.org>
parents: 2053
diff changeset
   192
static void
866052b01ee5 indent is evil
Sam Lantinga <slouken@libsdl.org>
parents: 2053
diff changeset
   193
SDL_AudioCloseDevice_Default(_THIS)
866052b01ee5 indent is evil
Sam Lantinga <slouken@libsdl.org>
parents: 2053
diff changeset
   194
{                               /* no-op. */
866052b01ee5 indent is evil
Sam Lantinga <slouken@libsdl.org>
parents: 2053
diff changeset
   195
}
2735
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2728
diff changeset
   196
2060
866052b01ee5 indent is evil
Sam Lantinga <slouken@libsdl.org>
parents: 2053
diff changeset
   197
static void
866052b01ee5 indent is evil
Sam Lantinga <slouken@libsdl.org>
parents: 2053
diff changeset
   198
SDL_AudioDeinitialize_Default(void)
866052b01ee5 indent is evil
Sam Lantinga <slouken@libsdl.org>
parents: 2053
diff changeset
   199
{                               /* no-op. */
866052b01ee5 indent is evil
Sam Lantinga <slouken@libsdl.org>
parents: 2053
diff changeset
   200
}
2049
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
   201
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
   202
static int
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
   203
SDL_AudioOpenDevice_Default(_THIS, const char *devname, int iscapture)
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
   204
{
7038
7f22b9ba218f Changed audio subsystem's OpenDevice interface to return -1 on error.
Ryan C. Gordon <icculus@icculus.org>
parents: 7011
diff changeset
   205
    return -1;
2049
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
   206
}
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
   207
9010
6d059ed9b6ca Clarifying hard-to-understand piece of code.
Ryan C. Gordon <icculus@icculus.org>
parents: 8919
diff changeset
   208
static SDL_INLINE SDL_bool
6d059ed9b6ca Clarifying hard-to-understand piece of code.
Ryan C. Gordon <icculus@icculus.org>
parents: 8919
diff changeset
   209
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
   210
{
6d059ed9b6ca Clarifying hard-to-understand piece of code.
Ryan C. Gordon <icculus@icculus.org>
parents: 8919
diff changeset
   211
    /* 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
   212
       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
   213
       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
   214
       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
   215
    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
   216
        return SDL_TRUE;
6d059ed9b6ca Clarifying hard-to-understand piece of code.
Ryan C. Gordon <icculus@icculus.org>
parents: 8919
diff changeset
   217
    }
6d059ed9b6ca Clarifying hard-to-understand piece of code.
Ryan C. Gordon <icculus@icculus.org>
parents: 8919
diff changeset
   218
6d059ed9b6ca Clarifying hard-to-understand piece of code.
Ryan C. Gordon <icculus@icculus.org>
parents: 8919
diff changeset
   219
    return SDL_FALSE;
6d059ed9b6ca Clarifying hard-to-understand piece of code.
Ryan C. Gordon <icculus@icculus.org>
parents: 8919
diff changeset
   220
}
6d059ed9b6ca Clarifying hard-to-understand piece of code.
Ryan C. Gordon <icculus@icculus.org>
parents: 8919
diff changeset
   221
2049
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
   222
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
   223
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
   224
{
9010
6d059ed9b6ca Clarifying hard-to-understand piece of code.
Ryan C. Gordon <icculus@icculus.org>
parents: 8919
diff changeset
   225
    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
   226
        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
   227
    }
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
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
   230
static void
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
   231
SDL_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
   232
{
9010
6d059ed9b6ca Clarifying hard-to-understand piece of code.
Ryan C. Gordon <icculus@icculus.org>
parents: 8919
diff changeset
   233
    if (!is_in_audio_device_thread(device)) {
6d059ed9b6ca Clarifying hard-to-understand piece of code.
Ryan C. Gordon <icculus@icculus.org>
parents: 8919
diff changeset
   234
        SDL_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
   235
    }
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
   236
}
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
   237
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   238
2060
866052b01ee5 indent is evil
Sam Lantinga <slouken@libsdl.org>
parents: 2053
diff changeset
   239
static void
866052b01ee5 indent is evil
Sam Lantinga <slouken@libsdl.org>
parents: 2053
diff changeset
   240
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
   241
{
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
   242
    /*
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
   243
     * 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
   244
     *  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
   245
     */
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
   246
2060
866052b01ee5 indent is evil
Sam Lantinga <slouken@libsdl.org>
parents: 2053
diff changeset
   247
#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
   248
        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
   249
            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
   250
        }
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
   251
    FILL_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
   252
    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
   253
    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
   254
    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
   255
    FILL_STUB(PlayDevice);
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
   256
    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
   257
    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
   258
    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
   259
    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
   260
    FILL_STUB(UnlockDevice);
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
   261
    FILL_STUB(Deinitialize);
2060
866052b01ee5 indent is evil
Sam Lantinga <slouken@libsdl.org>
parents: 2053
diff changeset
   262
#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
   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
8660
6bd1f8bad873 Patched to compile on C89 compilers, removed more streamer code.
Ryan C. Gordon <icculus@icculus.org>
parents: 8658
diff changeset
   265
#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
   266
/* 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
   267
/* 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
   268
static void
2716
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   269
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
   270
{
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   271
    int i;
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   272
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   273
    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
   274
        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
   275
        ++stream->write_pos;
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   276
    }
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   277
}
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   278
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   279
/* 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
   280
static void
2716
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   281
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
   282
{
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   283
    int i;
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   284
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   285
    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
   286
        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
   287
        ++stream->read_pos;
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   288
    }
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   289
}
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   290
4472
791b3256fb22 Mostly cleaned up warnings with -Wmissing-prototypes
Sam Lantinga <slouken@libsdl.org>
parents: 3699
diff changeset
   291
static int
2716
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   292
SDL_StreamLength(SDL_AudioStreamer * stream)
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   293
{
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   294
    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
   295
}
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
/* 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
   298
#if 0
4472
791b3256fb22 Mostly cleaned up warnings with -Wmissing-prototypes
Sam Lantinga <slouken@libsdl.org>
parents: 3699
diff changeset
   299
static int
2716
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   300
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
   301
{
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   302
    /* First try to allocate the buffer */
2728
2768bd7281e0 Fixed Visual Studio compilation problems
Sam Lantinga <slouken@libsdl.org>
parents: 2716
diff changeset
   303
    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
   304
    if (stream->buffer == NULL) {
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   305
        return -1;
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
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   308
    stream->max_len = max_len;
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   309
    stream->read_pos = 0;
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   310
    stream->write_pos = 0;
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   311
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   312
    /* Zero out the buffer */
2728
2768bd7281e0 Fixed Visual Studio compilation problems
Sam Lantinga <slouken@libsdl.org>
parents: 2716
diff changeset
   313
    SDL_memset(stream->buffer, silence, max_len);
2768bd7281e0 Fixed Visual Studio compilation problems
Sam Lantinga <slouken@libsdl.org>
parents: 2716
diff changeset
   314
2768bd7281e0 Fixed Visual Studio compilation problems
Sam Lantinga <slouken@libsdl.org>
parents: 2716
diff changeset
   315
    return 0;
2716
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   316
}
4507
dbf3fa541096 Fixed compile warnings
Sam Lantinga <slouken@libsdl.org>
parents: 4472
diff changeset
   317
#endif
2716
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   318
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   319
/* 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
   320
static void
2716
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   321
SDL_StreamDeinit(SDL_AudioStreamer * stream)
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   322
{
7719
31b5f9ff36ca Christoph Mallon: Remove pointless if (x) before SDL_free(x)
Sam Lantinga <slouken@libsdl.org>
parents: 7678
diff changeset
   323
    SDL_free(stream->buffer);
2716
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   324
}
8660
6bd1f8bad873 Patched to compile on C89 compilers, removed more streamer code.
Ryan C. Gordon <icculus@icculus.org>
parents: 8658
diff changeset
   325
#endif
2716
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   326
9012
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   327
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   328
/* buffer queueing support... */
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   329
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   330
/* 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
   331
static void
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   332
free_audio_queue(SDL_AudioBufferQueue *buffer)
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   333
{
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   334
    while (buffer) {
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   335
        SDL_AudioBufferQueue *next = buffer->next;
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   336
        SDL_free(buffer);
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   337
        buffer = next;
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   338
    }
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   339
}
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   340
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   341
static void SDLCALL
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   342
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
   343
{
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   344
    /* 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
   345
    Uint32 len = (Uint32) _len;
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   346
    SDL_AudioDevice *device = (SDL_AudioDevice *) userdata;
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   347
    SDL_AudioBufferQueue *buffer;
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   348
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   349
    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
   350
    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
   351
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   352
    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
   353
        const Uint32 avail = buffer->datalen - buffer->startpos;
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   354
        const Uint32 cpy = SDL_min(len, avail);
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   355
        SDL_assert(device->queued_bytes >= avail);
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   356
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   357
        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
   358
        buffer->startpos += cpy;
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   359
        stream += cpy;
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   360
        device->queued_bytes -= cpy;
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   361
        len -= cpy;
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   362
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   363
        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
   364
            device->buffer_queue_head = buffer->next;
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   365
            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
   366
            buffer->next = device->buffer_queue_pool;
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   367
            device->buffer_queue_pool = buffer;
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   368
        }
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   369
    }
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   370
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   371
    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
   372
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   373
    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
   374
        SDL_assert(device->buffer_queue_head == NULL);
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   375
        SDL_memset(stream, device->spec.silence, len);
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   376
    }
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   377
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   378
    if (device->buffer_queue_head == NULL) {
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   379
        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
   380
    }
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   381
}
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   382
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   383
int
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   384
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
   385
{
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   386
    SDL_AudioDevice *device = get_audio_device(devid);
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   387
    const Uint8 *data = (const Uint8 *) _data;
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   388
    SDL_AudioBufferQueue *orighead;
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   389
    SDL_AudioBufferQueue *origtail;
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   390
    Uint32 origlen;
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   391
    Uint32 datalen;
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   392
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   393
    if (!device) {
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   394
        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
   395
    }
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   396
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   397
    if (device->spec.callback != SDL_BufferQueueDrainCallback) {
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   398
        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
   399
    }
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   400
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   401
    current_audio.impl.LockDevice(device);
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   402
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   403
    orighead = device->buffer_queue_head;
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   404
    origtail = device->buffer_queue_tail;
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   405
    origlen = origtail ? origtail->datalen : 0;
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   406
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   407
    while (len > 0) {
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   408
        SDL_AudioBufferQueue *packet = device->buffer_queue_tail;
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   409
        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
   410
        if (!packet || (packet->datalen >= SDL_AUDIOBUFFERQUEUE_PACKETLEN)) {
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   411
            /* 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
   412
            packet = device->buffer_queue_pool;
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   413
            if (packet != NULL) {
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   414
                /* we have one available in the pool. */
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   415
                device->buffer_queue_pool = packet->next;
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   416
            } else {
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   417
                /* Have to allocate a new one! */
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   418
                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
   419
                if (packet == NULL) {
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   420
                    /* 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
   421
                    if (!origtail) {
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   422
                        packet = device->buffer_queue_head;  /* whole queue. */
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   423
                    } else {
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   424
                        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
   425
                        origtail->next = NULL;
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   426
                        origtail->datalen = origlen;
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   427
                    }
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   428
                    device->buffer_queue_head = orighead;
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   429
                    device->buffer_queue_tail = origtail;
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   430
                    device->buffer_queue_pool = NULL;
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   431
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   432
                    current_audio.impl.UnlockDevice(device);
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   433
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   434
                    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
   435
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   436
                    return SDL_OutOfMemory();
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   437
                }
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   438
            }
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   439
            packet->datalen = 0;
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   440
            packet->startpos = 0;
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   441
            packet->next = NULL;
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   442
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   443
            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
   444
            if (device->buffer_queue_tail == NULL) {
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   445
                device->buffer_queue_head = packet;
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   446
            } else {
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   447
                device->buffer_queue_tail->next = packet;
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   448
            }
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   449
            device->buffer_queue_tail = packet;
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   450
        }
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   451
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   452
        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
   453
        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
   454
        data += datalen;
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   455
        len -= datalen;
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   456
        packet->datalen += datalen;
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   457
        device->queued_bytes += datalen;
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   458
    }
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   459
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   460
    current_audio.impl.UnlockDevice(device);
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   461
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   462
    return 0;
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   463
}
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   464
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   465
Uint32
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   466
SDL_GetQueuedAudioSize(SDL_AudioDeviceID devid)
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   467
{
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   468
    /* this happens to work for non-queueing devices, since we memset()
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   469
       the device to zero at init time, and these devices should return 0. */
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   470
    Uint32 retval = 0;
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   471
    SDL_AudioDevice *device = get_audio_device(devid);
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   472
    if (device) {
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   473
        current_audio.impl.LockDevice(device);
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   474
        retval = device->queued_bytes;
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   475
        current_audio.impl.UnlockDevice(device);
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   476
    }
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   477
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   478
    return retval;
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   479
}
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   480
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   481
void
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   482
SDL_ClearQueuedAudio(SDL_AudioDeviceID devid)
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
    SDL_AudioDevice *device = get_audio_device(devid);
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   485
    SDL_AudioBufferQueue *buffer = NULL;
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   486
    if (!device) {
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   487
        return;  /* nothing to do. */
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   488
    }
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   489
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   490
    /* 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
   491
    current_audio.impl.LockDevice(device);
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   492
    buffer = device->buffer_queue_head;
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   493
    device->buffer_queue_tail = NULL;
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   494
    device->buffer_queue_head = NULL;
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   495
    device->queued_bytes = 0;
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   496
    current_audio.impl.UnlockDevice(device);
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   497
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   498
    free_audio_queue(buffer);
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   499
}
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
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
   502
#if defined(__ANDROID__)
4722
faa228f7ce5b - Cleaned up a bunch of code
Paul Hunkin <paul@bieh.net>
parents: 4718
diff changeset
   503
#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
   504
#endif
4722
faa228f7ce5b - Cleaned up a bunch of code
Paul Hunkin <paul@bieh.net>
parents: 4718
diff changeset
   505
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   506
/* 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
   507
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
   508
SDL_RunAudio(void *devicep)
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   509
{
2049
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
   510
    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
   511
    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
   512
    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
   513
    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
   514
    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
   515
    Uint32 delay;
8660
6bd1f8bad873 Patched to compile on C89 compilers, removed more streamer code.
Ryan C. Gordon <icculus@icculus.org>
parents: 8658
diff changeset
   516
6bd1f8bad873 Patched to compile on C89 compilers, removed more streamer code.
Ryan C. Gordon <icculus@icculus.org>
parents: 8658
diff changeset
   517
#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
   518
    /* 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
   519
    Uint8 *istream;
5645b3a5dc03 Move variable declaration position to stick with C standart.
Airlangga Cahya Utama <airlangga.cahya@gmail.com>
parents: 5509
diff changeset
   520
    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
   521
#endif
2716
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   522
5509
5b1b4d820d10 The API sets the priority for the current thread, not an arbitrary thread.
Sam Lantinga <slouken@libsdl.org>
parents: 5506
diff changeset
   523
    /* 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
   524
    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
   525
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
   526
    /* 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
   527
    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
   528
    current_audio.impl.ThreadInit(device);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   529
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
   530
    /* 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
   531
    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
   532
    udata = device->spec.userdata;
21
75a95f82bc1f Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
   533
2716
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   534
    /* By default do not stream */
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   535
    device->use_streamer = 0;
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   536
2049
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
   537
    if (device->convert.needed) {
3040
Sam Lantinga <slouken@libsdl.org>
parents: 3032
diff changeset
   538
#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
   539
        /* 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
   540
        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
   541
            /* 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
   542
            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
   543
            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
   544
                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
   545
                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
   546
            }
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   547
            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
   548
                0)
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   549
                return -1;
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   550
            device->use_streamer = 1;
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   551
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   552
            /* 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
   553
               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
   554
             */
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   555
            istream_len =
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   556
                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
   557
                device->convert.len_mult;
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   558
        }
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2984
diff changeset
   559
#endif
7518
febc83bc2a43 Fixed crash and garbled output when converting from F32 to S16 audio.
Sam Lantinga <slouken@libsdl.org>
parents: 7447
diff changeset
   560
        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
   561
    } 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
   562
        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
   563
    }
1561
c724c4a99759 Try to fill the hardware audio buffer immediately.
Ryan C. Gordon <icculus@icculus.org>
parents: 1532
diff changeset
   564
3336
00fab0ebfe54 Fixed a bug where when the audio starts paused all the DirectSound buffers
Sam Lantinga <slouken@libsdl.org>
parents: 3283
diff changeset
   565
    /* 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
   566
    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
   567
2716
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   568
    /* 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
   569
#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
   570
    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
   571
        /* 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
   572
           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
   573
           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
   574
           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
   575
           - 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
   576
           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
   577
           - 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
   578
           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
   579
           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
   580
           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
   581
           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
   582
         */
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   583
        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
   584
00fab0ebfe54 Fixed a bug where when the audio starts paused all the DirectSound buffers
Sam Lantinga <slouken@libsdl.org>
parents: 3283
diff changeset
   585
            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
   586
                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
   587
                continue;
00fab0ebfe54 Fixed a bug where when the audio starts paused all the DirectSound buffers
Sam Lantinga <slouken@libsdl.org>
parents: 3283
diff changeset
   588
            }
00fab0ebfe54 Fixed a bug where when the audio starts paused all the DirectSound buffers
Sam Lantinga <slouken@libsdl.org>
parents: 3283
diff changeset
   589
2716
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   590
            /* 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
   591
            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
   592
                /* Set up istream */
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   593
                if (device->convert.needed) {
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   594
                    if (device->convert.buf) {
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   595
                        istream = device->convert.buf;
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   596
                    } else {
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   597
                        continue;
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   598
                    }
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   599
                } 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
   600
/* 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
   601
 * 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
   602
 */
2716
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   603
                    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
   604
                    if (istream == NULL) {
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   605
                        istream = device->fake_stream;
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   606
                    }
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   607
                }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   608
2716
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   609
                /* Read from the callback into the _input_ stream */
6977
b73d51026c68 Changed the name of SDL_mutexP() SDL_mutexV()
Sam Lantinga <slouken@libsdl.org>
parents: 6905
diff changeset
   610
                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
   611
                (*fill) (udata, istream, istream_len);
6977
b73d51026c68 Changed the name of SDL_mutexP() SDL_mutexV()
Sam Lantinga <slouken@libsdl.org>
parents: 6905
diff changeset
   612
                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
   613
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   614
                /* 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
   615
                if (device->convert.needed) {
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   616
                    SDL_ConvertAudio(&device->convert);
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   617
                    if (istream == NULL) {
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   618
                        istream = device->fake_stream;
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   619
                    }
7678
286c42d7c5ed OCD fixes: Adds a space after /* (glory to regular expressions!)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7518
diff changeset
   620
                    /* 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
   621
                    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
   622
                                    device->convert.len_cvt);
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   623
                } else {
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   624
                    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
   625
                }
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
   626
            }
2716
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   627
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   628
            /* 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
   629
            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
   630
                /* Set up the output stream */
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   631
                if (device->convert.needed) {
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   632
                    if (device->convert.buf) {
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   633
                        stream = device->convert.buf;
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   634
                    } else {
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   635
                        continue;
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   636
                    }
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   637
                } else {
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   638
                    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
   639
                    if (stream == NULL) {
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   640
                        stream = device->fake_stream;
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   641
                    }
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   642
                }
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   643
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   644
                /* Now read from the streamer */
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   645
                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
   646
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   647
                /* 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
   648
                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
   649
                    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
   650
                    /* 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
   651
                    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
   652
                } 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
   653
                    SDL_Delay(delay);
2716
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   654
                }
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
            }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   656
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
   657
        }
8660
6bd1f8bad873 Patched to compile on C89 compilers, removed more streamer code.
Ryan C. Gordon <icculus@icculus.org>
parents: 8658
diff changeset
   658
    } else
8658
7939f33e81ac #ifdef'd out the audio streamer code.
Ryan C. Gordon <icculus@icculus.org>
parents: 8149
diff changeset
   659
#endif
8660
6bd1f8bad873 Patched to compile on C89 compilers, removed more streamer code.
Ryan C. Gordon <icculus@icculus.org>
parents: 8658
diff changeset
   660
    {
2716
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   661
        /* 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
   662
        const int silence = (int) device->spec.silence;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   663
2716
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   664
        /* Loop, filling the audio buffers */
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   665
        while (device->enabled) {
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   666
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   667
            /* 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
   668
            if (device->convert.needed) {
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   669
                if (device->convert.buf) {
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   670
                    stream = device->convert.buf;
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   671
                } else {
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   672
                    continue;
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   673
                }
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   674
            } else {
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   675
                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
   676
                if (stream == NULL) {
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   677
                    stream = device->fake_stream;
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   678
                }
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
   679
            }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   680
7447
6860de5bcb8c Protect SDL_PauseAudio*() with the audio callback lock.
Ryan C. Gordon <icculus@icculus.org>
parents: 7446
diff changeset
   681
            SDL_LockMutex(device->mixer_lock);
7406
fb02213c11d3 Explicitly write silence to the audio device while it is paused.
Ryan C. Gordon <icculus@icculus.org>
parents: 7367
diff changeset
   682
            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
   683
                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
   684
            } else {
fb02213c11d3 Explicitly write silence to the audio device while it is paused.
Ryan C. Gordon <icculus@icculus.org>
parents: 7367
diff changeset
   685
                (*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
   686
            }
7447
6860de5bcb8c Protect SDL_PauseAudio*() with the audio callback lock.
Ryan C. Gordon <icculus@icculus.org>
parents: 7446
diff changeset
   687
            SDL_UnlockMutex(device->mixer_lock);
1562
1d487a3fab41 Fixed bug #18
Sam Lantinga <slouken@libsdl.org>
parents: 1561
diff changeset
   688
2716
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   689
            /* Convert the audio if necessary */
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   690
            if (device->convert.needed) {
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   691
                SDL_ConvertAudio(&device->convert);
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   692
                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
   693
                if (stream == NULL) {
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   694
                    stream = device->fake_stream;
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
                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
   697
                           device->convert.len_cvt);
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
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   700
            /* 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
   701
            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
   702
                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
   703
                /* 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
   704
                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
   705
            } 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
   706
                SDL_Delay(delay);
2716
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   707
            }
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1794
diff changeset
   708
        }
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
   709
    }
1562
1d487a3fab41 Fixed bug #18
Sam Lantinga <slouken@libsdl.org>
parents: 1561
diff changeset
   710
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
   711
    /* 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
   712
    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
   713
2716
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   714
    /* If necessary, deinit the streamer */
8658
7939f33e81ac #ifdef'd out the audio streamer code.
Ryan C. Gordon <icculus@icculus.org>
parents: 8149
diff changeset
   715
#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
   716
    if (device->use_streamer == 1)
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   717
        SDL_StreamDeinit(&device->streamer);
8658
7939f33e81ac #ifdef'd out the audio streamer code.
Ryan C. Gordon <icculus@icculus.org>
parents: 8149
diff changeset
   718
#endif
2716
f8f68f47285a Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
   719
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
   720
    return (0);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   721
}
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   722
322
fd93a09655e3 The audio lock and unlock functions are now a part of the driver.
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
   723
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1978
diff changeset
   724
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
   725
SDL_ParseAudioFormat(const char *string)
1794
5605a9820134 Fixed bug #137
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
   726
{
2076
939420dee849 Use SDL_strcmp(), not strcmp().
Ryan C. Gordon <icculus@icculus.org>
parents: 2070
diff changeset
   727
#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
   728
    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
   729
    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
   730
    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
   731
    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
   732
    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
   733
    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
   734
    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
   735
    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
   736
    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
   737
    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
   738
    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
   739
    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
   740
    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
   741
    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
   742
    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
   743
    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
   744
    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
   745
    CHECK_FMT_STRING(F32);
2060
866052b01ee5 indent is evil
Sam Lantinga <slouken@libsdl.org>
parents: 2053
diff changeset
   746
#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
   747
    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
   748
}
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
   749
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
   750
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
   751
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
   752
{
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
   753
    return (SDL_arraysize(bootstrap) - 1);
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
   754
}
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
   755
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
   756
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
   757
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
   758
{
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
   759
    if (index >= 0 && index < SDL_GetNumAudioDrivers()) {
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
   760
        return (bootstrap[index]->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
   761
    }
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
   762
    return (NULL);
1794
5605a9820134 Fixed bug #137
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
   763
}
5605a9820134 Fixed bug #137
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
   764
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
   765
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
   766
SDL_AudioInit(const char *driver_name)
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   767
{
2049
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
   768
    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
   769
    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
   770
    int tried_to_init = 0;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   771
2049
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
   772
    if (SDL_WasInit(SDL_INIT_AUDIO)) {
2060
866052b01ee5 indent is evil
Sam Lantinga <slouken@libsdl.org>
parents: 2053
diff changeset
   773
        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
   774
    }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   775
2060
866052b01ee5 indent is evil
Sam Lantinga <slouken@libsdl.org>
parents: 2053
diff changeset
   776
    SDL_memset(&current_audio, '\0', sizeof(current_audio));
866052b01ee5 indent is evil
Sam Lantinga <slouken@libsdl.org>
parents: 2053
diff changeset
   777
    SDL_memset(open_devices, '\0', sizeof(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
   778
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
   779
    /* 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
   780
    if (driver_name == NULL) {
8f1ab2f7c722 Look at environment variables in SDL_VideoInit() and SDL_AudioInit()
Sam Lantinga <slouken@libsdl.org>
parents: 1903
diff changeset
   781
        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
   782
    }
2049
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
   783
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
   784
    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
   785
        /* 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
   786
        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
   787
        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
   788
            (!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
   789
            continue;
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
   790
        }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   791
2049
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
   792
        tried_to_init = 1;
2060
866052b01ee5 indent is evil
Sam Lantinga <slouken@libsdl.org>
parents: 2053
diff changeset
   793
        SDL_memset(&current_audio, 0, sizeof(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
   794
        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
   795
        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
   796
        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
   797
    }
2049
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
   798
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
   799
    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
   800
        /* 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
   801
        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
   802
            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
   803
                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
   804
            } 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
   805
                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
   806
            }
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
   807
        }
2049
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
   808
2060
866052b01ee5 indent is evil
Sam Lantinga <slouken@libsdl.org>
parents: 2053
diff changeset
   809
        SDL_memset(&current_audio, 0, sizeof(current_audio));
866052b01ee5 indent is evil
Sam Lantinga <slouken@libsdl.org>
parents: 2053
diff changeset
   810
        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
   811
    }
2049
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
   812
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
   813
    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
   814
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
   815
    return (0);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   816
}
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   817
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
   818
/*
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
   819
 * 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
   820
 */
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
   821
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
   822
SDL_GetCurrentAudioDriver()
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   823
{
2049
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
   824
    return current_audio.name;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   825
}
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   826
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
   827
static void
ab22ca13c47f Cleaned up audio device detection. Cleared out a lot of cut-and-paste.
Ryan C. Gordon <icculus@icculus.org>
parents: 5592
diff changeset
   828
free_device_list(char ***devices, int *devCount)
ab22ca13c47f Cleaned up audio device detection. Cleared out a lot of cut-and-paste.
Ryan C. Gordon <icculus@icculus.org>
parents: 5592
diff changeset
   829
{
ab22ca13c47f Cleaned up audio device detection. Cleared out a lot of cut-and-paste.
Ryan C. Gordon <icculus@icculus.org>
parents: 5592
diff changeset
   830
    int i = *devCount;
ab22ca13c47f Cleaned up audio device detection. Cleared out a lot of cut-and-paste.
Ryan C. Gordon <icculus@icculus.org>
parents: 5592
diff changeset
   831
    if ((i > 0) && (*devices != NULL)) {
ab22ca13c47f Cleaned up audio device detection. Cleared out a lot of cut-and-paste.
Ryan C. Gordon <icculus@icculus.org>
parents: 5592
diff changeset
   832
        while (i--) {
ab22ca13c47f Cleaned up audio device detection. Cleared out a lot of cut-and-paste.
Ryan C. Gordon <icculus@icculus.org>
parents: 5592
diff changeset
   833
            SDL_free((*devices)[i]);
ab22ca13c47f Cleaned up audio device detection. Cleared out a lot of cut-and-paste.
Ryan C. Gordon <icculus@icculus.org>
parents: 5592
diff changeset
   834
        }
ab22ca13c47f Cleaned up audio device detection. Cleared out a lot of cut-and-paste.
Ryan C. Gordon <icculus@icculus.org>
parents: 5592
diff changeset
   835
    }
ab22ca13c47f Cleaned up audio device detection. Cleared out a lot of cut-and-paste.
Ryan C. Gordon <icculus@icculus.org>
parents: 5592
diff changeset
   836
7719
31b5f9ff36ca Christoph Mallon: Remove pointless if (x) before SDL_free(x)
Sam Lantinga <slouken@libsdl.org>
parents: 7678
diff changeset
   837
    SDL_free(*devices);
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
   838
ab22ca13c47f Cleaned up audio device detection. Cleared out a lot of cut-and-paste.
Ryan C. Gordon <icculus@icculus.org>
parents: 5592
diff changeset
   839
    *devices = NULL;
ab22ca13c47f Cleaned up audio device detection. Cleared out a lot of cut-and-paste.
Ryan C. Gordon <icculus@icculus.org>
parents: 5592
diff changeset
   840
    *devCount = 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
   841
}
ab22ca13c47f Cleaned up audio device detection. Cleared out a lot of cut-and-paste.
Ryan C. Gordon <icculus@icculus.org>
parents: 5592
diff changeset
   842
ab22ca13c47f Cleaned up audio device detection. Cleared out a lot of cut-and-paste.
Ryan C. Gordon <icculus@icculus.org>
parents: 5592
diff changeset
   843
static
ab22ca13c47f Cleaned up audio device detection. Cleared out a lot of cut-and-paste.
Ryan C. Gordon <icculus@icculus.org>
parents: 5592
diff changeset
   844
void SDL_AddCaptureAudioDevice(const char *_name)
ab22ca13c47f Cleaned up audio device detection. Cleared out a lot of cut-and-paste.
Ryan C. Gordon <icculus@icculus.org>
parents: 5592
diff changeset
   845
{
ab22ca13c47f Cleaned up audio device detection. Cleared out a lot of cut-and-paste.
Ryan C. Gordon <icculus@icculus.org>
parents: 5592
diff changeset
   846
    char *name = NULL;
ab22ca13c47f Cleaned up audio device detection. Cleared out a lot of cut-and-paste.
Ryan C. Gordon <icculus@icculus.org>
parents: 5592
diff changeset
   847
    void *ptr = SDL_realloc(current_audio.inputDevices,
ab22ca13c47f Cleaned up audio device detection. Cleared out a lot of cut-and-paste.
Ryan C. Gordon <icculus@icculus.org>
parents: 5592
diff changeset
   848
                          (current_audio.inputDeviceCount+1) * sizeof(char*));
ab22ca13c47f Cleaned up audio device detection. Cleared out a lot of cut-and-paste.
Ryan C. Gordon <icculus@icculus.org>
parents: 5592
diff changeset
   849
    if (ptr == NULL) {
ab22ca13c47f Cleaned up audio device detection. Cleared out a lot of cut-and-paste.
Ryan C. Gordon <icculus@icculus.org>
parents: 5592
diff changeset
   850
        return;  /* oh well. */
ab22ca13c47f Cleaned up audio device detection. Cleared out a lot of cut-and-paste.
Ryan C. Gordon <icculus@icculus.org>
parents: 5592
diff changeset
   851
    }
ab22ca13c47f Cleaned up audio device detection. Cleared out a lot of cut-and-paste.
Ryan C. Gordon <icculus@icculus.org>
parents: 5592
diff changeset
   852
ab22ca13c47f Cleaned up audio device detection. Cleared out a lot of cut-and-paste.
Ryan C. Gordon <icculus@icculus.org>
parents: 5592
diff changeset
   853
    current_audio.inputDevices = (char **) ptr;
ab22ca13c47f Cleaned up audio device detection. Cleared out a lot of cut-and-paste.
Ryan C. Gordon <icculus@icculus.org>
parents: 5592
diff changeset
   854
    name = SDL_strdup(_name);  /* if this returns NULL, that's okay. */
ab22ca13c47f Cleaned up audio device detection. Cleared out a lot of cut-and-paste.
Ryan C. Gordon <icculus@icculus.org>
parents: 5592
diff changeset
   855
    current_audio.inputDevices[current_audio.inputDeviceCount++] = name;
ab22ca13c47f Cleaned up audio device detection. Cleared out a lot of cut-and-paste.
Ryan C. Gordon <icculus@icculus.org>
parents: 5592
diff changeset
   856
}
ab22ca13c47f Cleaned up audio device detection. Cleared out a lot of cut-and-paste.
Ryan C. Gordon <icculus@icculus.org>
parents: 5592
diff changeset
   857
ab22ca13c47f Cleaned up audio device detection. Cleared out a lot of cut-and-paste.
Ryan C. Gordon <icculus@icculus.org>
parents: 5592
diff changeset
   858
static
ab22ca13c47f Cleaned up audio device detection. Cleared out a lot of cut-and-paste.
Ryan C. Gordon <icculus@icculus.org>
parents: 5592
diff changeset
   859
void SDL_AddOutputAudioDevice(const char *_name)
ab22ca13c47f Cleaned up audio device detection. Cleared out a lot of cut-and-paste.
Ryan C. Gordon <icculus@icculus.org>
parents: 5592
diff changeset
   860
{
ab22ca13c47f Cleaned up audio device detection. Cleared out a lot of cut-and-paste.
Ryan C. Gordon <icculus@icculus.org>
parents: 5592
diff changeset
   861
    char *name = NULL;
ab22ca13c47f Cleaned up audio device detection. Cleared out a lot of cut-and-paste.
Ryan C. Gordon <icculus@icculus.org>
parents: 5592
diff changeset
   862
    void *ptr = SDL_realloc(current_audio.outputDevices,
ab22ca13c47f Cleaned up audio device detection. Cleared out a lot of cut-and-paste.
Ryan C. Gordon <icculus@icculus.org>
parents: 5592
diff changeset
   863
                          (current_audio.outputDeviceCount+1) * sizeof(char*));
ab22ca13c47f Cleaned up audio device detection. Cleared out a lot of cut-and-paste.
Ryan C. Gordon <icculus@icculus.org>
parents: 5592
diff changeset
   864
    if (ptr == NULL) {
ab22ca13c47f Cleaned up audio device detection. Cleared out a lot of cut-and-paste.
Ryan C. Gordon <icculus@icculus.org>
parents: 5592
diff changeset
   865
        return;  /* oh well. */
ab22ca13c47f Cleaned up audio device detection. Cleared out a lot of cut-and-paste.
Ryan C. Gordon <icculus@icculus.org>
parents: 5592
diff changeset
   866
    }
ab22ca13c47f Cleaned up audio device detection. Cleared out a lot of cut-and-paste.
Ryan C. Gordon <icculus@icculus.org>
parents: 5592
diff changeset
   867
ab22ca13c47f Cleaned up audio device detection. Cleared out a lot of cut-and-paste.
Ryan C. Gordon <icculus@icculus.org>
parents: 5592
diff changeset
   868
    current_audio.outputDevices = (char **) ptr;
ab22ca13c47f Cleaned up audio device detection. Cleared out a lot of cut-and-paste.
Ryan C. Gordon <icculus@icculus.org>
parents: 5592
diff changeset
   869
    name = SDL_strdup(_name);  /* if this returns NULL, that's okay. */
ab22ca13c47f Cleaned up audio device detection. Cleared out a lot of cut-and-paste.
Ryan C. Gordon <icculus@icculus.org>
parents: 5592
diff changeset
   870
    current_audio.outputDevices[current_audio.outputDeviceCount++] = name;
ab22ca13c47f Cleaned up audio device detection. Cleared out a lot of cut-and-paste.
Ryan C. Gordon <icculus@icculus.org>
parents: 5592
diff changeset
   871
}
ab22ca13c47f Cleaned up audio device detection. Cleared out a lot of cut-and-paste.
Ryan C. Gordon <icculus@icculus.org>
parents: 5592
diff changeset
   872
2049
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
   873
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
   874
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
   875
SDL_GetNumAudioDevices(int iscapture)
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   876
{
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
   877
    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
   878
2049
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
   879
    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
   880
        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
   881
    }
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
   882
2049
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
   883
    if ((iscapture) && (!current_audio.impl.HasCaptureSupport)) {
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
   884
        return 0;
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
   885
    }
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
   886
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
   887
    if ((iscapture) && (current_audio.impl.OnlyHasDefaultInputDevice)) {
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
   888
        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
   889
    }
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
   890
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
   891
    if ((!iscapture) && (current_audio.impl.OnlyHasDefaultOutputDevice)) {
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
   892
        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
   893
    }
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
   894
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
   895
    if (iscapture) {
ab22ca13c47f Cleaned up audio device detection. Cleared out a lot of cut-and-paste.
Ryan C. Gordon <icculus@icculus.org>
parents: 5592
diff changeset
   896
        free_device_list(&current_audio.inputDevices,
ab22ca13c47f Cleaned up audio device detection. Cleared out a lot of cut-and-paste.
Ryan C. Gordon <icculus@icculus.org>
parents: 5592
diff changeset
   897
                         &current_audio.inputDeviceCount);
ab22ca13c47f Cleaned up audio device detection. Cleared out a lot of cut-and-paste.
Ryan C. Gordon <icculus@icculus.org>
parents: 5592
diff changeset
   898
        current_audio.impl.DetectDevices(iscapture, SDL_AddCaptureAudioDevice);
ab22ca13c47f Cleaned up audio device detection. Cleared out a lot of cut-and-paste.
Ryan C. Gordon <icculus@icculus.org>
parents: 5592
diff changeset
   899
        retval = current_audio.inputDeviceCount;
ab22ca13c47f Cleaned up audio device detection. Cleared out a lot of cut-and-paste.
Ryan C. Gordon <icculus@icculus.org>
parents: 5592
diff changeset
   900
    } else {
ab22ca13c47f Cleaned up audio device detection. Cleared out a lot of cut-and-paste.
Ryan C. Gordon <icculus@icculus.org>
parents: 5592
diff changeset
   901
        free_device_list(&current_audio.outputDevices,
ab22ca13c47f Cleaned up audio device detection. Cleared out a lot of cut-and-paste.
Ryan C. Gordon <icculus@icculus.org>
parents: 5592
diff changeset
   902
                         &current_audio.outputDeviceCount);
ab22ca13c47f Cleaned up audio device detection. Cleared out a lot of cut-and-paste.
Ryan C. Gordon <icculus@icculus.org>
parents: 5592
diff changeset
   903
        current_audio.impl.DetectDevices(iscapture, SDL_AddOutputAudioDevice);
ab22ca13c47f Cleaned up audio device detection. Cleared out a lot of cut-and-paste.
Ryan C. Gordon <icculus@icculus.org>
parents: 5592
diff changeset
   904
        retval = current_audio.outputDeviceCount;
ab22ca13c47f Cleaned up audio device detection. Cleared out a lot of cut-and-paste.
Ryan C. Gordon <icculus@icculus.org>
parents: 5592
diff changeset
   905
    }
ab22ca13c47f Cleaned up audio device detection. Cleared out a lot of cut-and-paste.
Ryan C. Gordon <icculus@icculus.org>
parents: 5592
diff changeset
   906
ab22ca13c47f Cleaned up audio device detection. Cleared out a lot of cut-and-paste.
Ryan C. Gordon <icculus@icculus.org>
parents: 5592
diff changeset
   907
    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
   908
}
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
   909
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   910
2049
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
   911
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
   912
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
   913
{
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
   914
    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
   915
        SDL_SetError("Audio subsystem is not initialized");
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
   916
        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
   917
    }
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
   918
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
   919
    if ((iscapture) && (!current_audio.impl.HasCaptureSupport)) {
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
   920
        SDL_SetError("No capture support");
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
   921
        return NULL;
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
   922
    }
2049
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
   923
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
   924
    if (index < 0) {
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
   925
        goto no_such_device;
2049
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
   926
    }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   927
2049
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
   928
    if ((iscapture) && (current_audio.impl.OnlyHasDefaultInputDevice)) {
7904
915b9b6c9fa0 Fixed bug 2205 - SDL_GetAudioDeviceName returns default-device name on invalid index for default-device only drivers
Sam Lantinga <slouken@libsdl.org>
parents: 7719
diff changeset
   929
        if (index > 0) {
915b9b6c9fa0 Fixed bug 2205 - SDL_GetAudioDeviceName returns default-device name on invalid index for default-device only drivers
Sam Lantinga <slouken@libsdl.org>
parents: 7719
diff changeset
   930
            goto no_such_device;
915b9b6c9fa0 Fixed bug 2205 - SDL_GetAudioDeviceName returns default-device name on invalid index for default-device only drivers
Sam Lantinga <slouken@libsdl.org>
parents: 7719
diff changeset
   931
        }
2049
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
   932
        return DEFAULT_INPUT_DEVNAME;
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
   933
    }
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
   934
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
   935
    if ((!iscapture) && (current_audio.impl.OnlyHasDefaultOutputDevice)) {
7904
915b9b6c9fa0 Fixed bug 2205 - SDL_GetAudioDeviceName returns default-device name on invalid index for default-device only drivers
Sam Lantinga <slouken@libsdl.org>
parents: 7719
diff changeset
   936
        if (index > 0) {
915b9b6c9fa0 Fixed bug 2205 - SDL_GetAudioDeviceName returns default-device name on invalid index for default-device only drivers
Sam Lantinga <slouken@libsdl.org>
parents: 7719
diff changeset
   937
            goto no_such_device;
915b9b6c9fa0 Fixed bug 2205 - SDL_GetAudioDeviceName returns default-device name on invalid index for default-device only drivers
Sam Lantinga <slouken@libsdl.org>
parents: 7719
diff changeset
   938
        }
2049
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
   939
        return DEFAULT_OUTPUT_DEVNAME;
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
   940
    }
262
ba5363e21df8 Don't allow multiple audio opens to succeed (until SDL 1.3)
Sam Lantinga <slouken@libsdl.org>
parents: 252
diff changeset
   941
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
   942
    if (iscapture) {
ab22ca13c47f Cleaned up audio device detection. Cleared out a lot of cut-and-paste.
Ryan C. Gordon <icculus@icculus.org>
parents: 5592
diff changeset
   943
        if (index >= current_audio.inputDeviceCount) {
ab22ca13c47f Cleaned up audio device detection. Cleared out a lot of cut-and-paste.
Ryan C. Gordon <icculus@icculus.org>
parents: 5592
diff changeset
   944
            goto no_such_device;
ab22ca13c47f Cleaned up audio device detection. Cleared out a lot of cut-and-paste.
Ryan C. Gordon <icculus@icculus.org>
parents: 5592
diff changeset
   945
        }
ab22ca13c47f Cleaned up audio device detection. Cleared out a lot of cut-and-paste.
Ryan C. Gordon <icculus@icculus.org>
parents: 5592
diff changeset
   946
        return current_audio.inputDevices[index];
ab22ca13c47f Cleaned up audio device detection. Cleared out a lot of cut-and-paste.
Ryan C. Gordon <icculus@icculus.org>
parents: 5592
diff changeset
   947
    } else {
ab22ca13c47f Cleaned up audio device detection. Cleared out a lot of cut-and-paste.
Ryan C. Gordon <icculus@icculus.org>
parents: 5592
diff changeset
   948
        if (index >= current_audio.outputDeviceCount) {
ab22ca13c47f Cleaned up audio device detection. Cleared out a lot of cut-and-paste.
Ryan C. Gordon <icculus@icculus.org>
parents: 5592
diff changeset
   949
            goto no_such_device;
ab22ca13c47f Cleaned up audio device detection. Cleared out a lot of cut-and-paste.
Ryan C. Gordon <icculus@icculus.org>
parents: 5592
diff changeset
   950
        }
ab22ca13c47f Cleaned up audio device detection. Cleared out a lot of cut-and-paste.
Ryan C. Gordon <icculus@icculus.org>
parents: 5592
diff changeset
   951
        return current_audio.outputDevices[index];
ab22ca13c47f Cleaned up audio device detection. Cleared out a lot of cut-and-paste.
Ryan C. Gordon <icculus@icculus.org>
parents: 5592
diff changeset
   952
    }
ab22ca13c47f Cleaned up audio device detection. Cleared out a lot of cut-and-paste.
Ryan C. Gordon <icculus@icculus.org>
parents: 5592
diff changeset
   953
ab22ca13c47f Cleaned up audio device detection. Cleared out a lot of cut-and-paste.
Ryan C. Gordon <icculus@icculus.org>
parents: 5592
diff changeset
   954
no_such_device:
ab22ca13c47f Cleaned up audio device detection. Cleared out a lot of cut-and-paste.
Ryan C. Gordon <icculus@icculus.org>
parents: 5592
diff changeset
   955
    SDL_SetError("No such device");
ab22ca13c47f Cleaned up audio device detection. Cleared out a lot of cut-and-paste.
Ryan C. Gordon <icculus@icculus.org>
parents: 5592
diff changeset
   956
    return 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
   957
}
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
   958
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
   959
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
   960
static void
2060
866052b01ee5 indent is evil
Sam Lantinga <slouken@libsdl.org>
parents: 2053
diff changeset
   961
close_audio_device(SDL_AudioDevice * device)
2049
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
   962
{
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
   963
    device->enabled = 0;
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
   964
    if (device->thread != NULL) {
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
   965
        SDL_WaitThread(device->thread, NULL);
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
   966
    }
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
   967
    if (device->mixer_lock != NULL) {
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
   968
        SDL_DestroyMutex(device->mixer_lock);
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
   969
    }
7719
31b5f9ff36ca Christoph Mallon: Remove pointless if (x) before SDL_free(x)
Sam Lantinga <slouken@libsdl.org>
parents: 7678
diff changeset
   970
    SDL_FreeAudioMem(device->fake_stream);
2049
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
   971
    if (device->convert.needed) {
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
   972
        SDL_FreeAudioMem(device->convert.buf);
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
   973
    }
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
   974
    if (device->opened) {
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
   975
        current_audio.impl.CloseDevice(device);
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
   976
        device->opened = 0;
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
   977
    }
9012
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   978
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   979
    free_audio_queue(device->buffer_queue_head);
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
diff changeset
   980
    free_audio_queue(device->buffer_queue_pool);
aa058c87737b Added audio device buffer queueing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9010
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
    SDL_FreeAudioMem(device);
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
   983
}
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
   984
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
   985
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
   986
/*
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
   987
 * Sanity check desired AudioSpec for SDL_OpenAudio() in (orig).
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
   988
 *  Fills in a sanitized copy in (prepared).
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
   989
 *  Returns non-zero if okay, zero on fatal parameters in (orig).
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
   990
 */
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
   991
static int
2060
866052b01ee5 indent is evil
Sam Lantinga <slouken@libsdl.org>
parents: 2053
diff changeset
   992
prepare_audiospec(const SDL_AudioSpec * orig, SDL_AudioSpec * prepared)
2049
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
   993
{
2060
866052b01ee5 indent is evil
Sam Lantinga <slouken@libsdl.org>
parents: 2053
diff changeset
   994
    SDL_memcpy(prepared, orig, sizeof(SDL_AudioSpec));
2049
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
   995
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
   996
    if (orig->freq == 0) {
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
   997
        const char *env = SDL_getenv("SDL_AUDIO_FREQUENCY");
2060
866052b01ee5 indent is evil
Sam Lantinga <slouken@libsdl.org>
parents: 2053
diff changeset
   998
        if ((!env) || ((prepared->freq = SDL_atoi(env)) == 0)) {
866052b01ee5 indent is evil
Sam Lantinga <slouken@libsdl.org>
parents: 2053
diff changeset
   999
            prepared->freq = 22050;     /* a reasonable default */
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1794
diff changeset
  1000
        }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1794
diff changeset
  1001
    }
2049
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
  1002
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
  1003
    if (orig->format == 0) {
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
  1004
        const char *env = SDL_getenv("SDL_AUDIO_FORMAT");
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
  1005
        if ((!env) || ((prepared->format = SDL_ParseAudioFormat(env)) == 0)) {
2060
866052b01ee5 indent is evil
Sam Lantinga <slouken@libsdl.org>
parents: 2053
diff changeset
  1006
            prepared->format = AUDIO_S16;       /* a reasonable default */
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
  1007
        }
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
  1008
    }
2049
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
  1009
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
  1010
    switch (orig->channels) {
2060
866052b01ee5 indent is evil
Sam Lantinga <slouken@libsdl.org>
parents: 2053
diff changeset
  1011
    case 0:{
866052b01ee5 indent is evil
Sam Lantinga <slouken@libsdl.org>
parents: 2053
diff changeset
  1012
            const char *env = SDL_getenv("SDL_AUDIO_CHANNELS");
2141
e1a70460c354 stupid indent
Sam Lantinga <slouken@libsdl.org>
parents: 2130
diff changeset
  1013
            if ((!env) || ((prepared->channels = (Uint8) SDL_atoi(env)) == 0)) {
2060
866052b01ee5 indent is evil
Sam Lantinga <slouken@libsdl.org>
parents: 2053
diff changeset
  1014
                prepared->channels = 2; /* a reasonable default */
866052b01ee5 indent is evil
Sam Lantinga <slouken@libsdl.org>
parents: 2053
diff changeset
  1015
            }
866052b01ee5 indent is evil
Sam Lantinga <slouken@libsdl.org>
parents: 2053
diff changeset
  1016
            break;
2049
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
  1017
        }
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
  1018
    case 1:                    /* Mono */
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
  1019
    case 2:                    /* Stereo */
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
  1020
    case 4:                    /* surround */
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
  1021
    case 6:                    /* surround with center and lfe */
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
  1022
        break;
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
  1023
    default:
2049
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
  1024
        SDL_SetError("Unsupported number of audio channels.");
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
  1025
        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
  1026
    }
2049
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
  1027
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
  1028
    if (orig->samples == 0) {
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
  1029
        const char *env = SDL_getenv("SDL_AUDIO_SAMPLES");
2060
866052b01ee5 indent is evil
Sam Lantinga <slouken@libsdl.org>
parents: 2053
diff changeset
  1030
        if ((!env) || ((prepared->samples = (Uint16) SDL_atoi(env)) == 0)) {
2049
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
  1031
            /* Pick a default of ~46 ms at desired frequency */
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
  1032
            /* !!! FIXME: remove this when the non-Po2 resampling is in. */
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
  1033
            const int samples = (prepared->freq / 1000) * 46;
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
  1034
            int power2 = 1;
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
  1035
            while (power2 < samples) {
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
  1036
                power2 *= 2;
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
            prepared->samples = power2;
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
  1039
        }
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
  1040
    }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1041
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
  1042
    /* Calculate the silence and size of the audio specification */
2049
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2045
diff changeset
  1043
    SDL_CalculateAudioSpec(prepared);
21
75a95f82bc1f Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents: 0
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
    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
  1046
}
1408
ceb5c2fec4f1 Fixed some preproc