annotate src/audio/dart/SDL_dart.c @ 3839:506fc6ca82cb SDL-ryan-multiple-audio-device

OS/2 audio code works in 1.3 now.
author Ryan C. Gordon <icculus@icculus.org>
date Sun, 08 Oct 2006 08:57:28 +0000
parents b225d9820ee3
children 66fb40445587
rev   line source
1190
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1 /*
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2 SDL - Simple DirectMedia Layer
1312
c9b51268668f Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents: 1190
diff changeset
3 Copyright (C) 1997-2006 Sam Lantinga
1190
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
4
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
5 This library is free software; you can redistribute it and/or
1312
c9b51268668f Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents: 1190
diff changeset
6 modify it under the terms of the GNU Lesser General Public
1190
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
7 License as published by the Free Software Foundation; either
1312
c9b51268668f Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents: 1190
diff changeset
8 version 2.1 of the License, or (at your option) any later version.
1190
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
9
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
10 This library is distributed in the hope that it will be useful,
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1312
c9b51268668f Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents: 1190
diff changeset
13 Lesser General Public License for more details.
1190
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
14
1312
c9b51268668f Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents: 1190
diff changeset
15 You should have received a copy of the GNU Lesser General Public
c9b51268668f Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents: 1190
diff changeset
16 License along with this library; if not, write to the Free Software
c9b51268668f Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents: 1190
diff changeset
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
1190
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
18
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
19 Sam Lantinga
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
20 slouken@libsdl.org
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
21 */
1402
d910939febfa Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents: 1361
diff changeset
22 #include "SDL_config.h"
1190
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
23
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
24 /* Allow access to a raw mixing buffer */
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
25
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
26 #include "SDL_timer.h"
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
27 #include "SDL_audio.h"
1361
19418e4422cb New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents: 1358
diff changeset
28 #include "../SDL_audio_c.h"
1190
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
29 #include "SDL_dart.h"
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
30
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
31 // Buffer states:
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
32 #define BUFFER_EMPTY 0
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
33 #define BUFFER_USED 1
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
34
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
35 typedef struct _tMixBufferDesc
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
36 {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
37 int iBufferUsage; // BUFFER_EMPTY or BUFFER_USED
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
38 SDL_AudioDevice *pSDLAudioDevice;
1190
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
39 } tMixBufferDesc, *pMixBufferDesc;
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
40
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
41
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
42 //---------------------------------------------------------------------
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
43 // DARTEventFunc
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
44 //
3819
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3807
diff changeset
45 // This function is called by DART, when an event occurs, like end of
1190
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
46 // playback of a buffer, etc...
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
47 //---------------------------------------------------------------------
3819
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3807
diff changeset
48 static LONG APIENTRY
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
49 DARTEventFunc(ULONG ulStatus, PMCI_MIX_BUFFER pBuffer, ULONG ulFlags)
1190
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
50 {
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
51 if (ulFlags && MIX_WRITE_COMPLETE) { // Playback of buffer completed!
1190
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
52
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
53 // Get pointer to buffer description
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
54 pMixBufferDesc pBufDesc;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
55
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
56 if (pBuffer) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
57 pBufDesc = (pMixBufferDesc) (*pBuffer).ulUserParm;
1190
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
58
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
59 if (pBufDesc) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
60 SDL_AudioDevice *pSDLAudioDevice = pBufDesc->pSDLAudioDevice;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
61 // Set the buffer to be empty
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
62 pBufDesc->iBufferUsage = BUFFER_EMPTY;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
63 // And notify DART feeder thread that it will have to work a bit.
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
64 if (pSDLAudioDevice)
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
65 DosPostEventSem(pSDLAudioDevice->hidden->
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
66 hevAudioBufferPlayed);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
67 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
68 }
1190
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
69 }
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
70 return TRUE;
1190
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
71 }
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
72
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
73
3819
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3807
diff changeset
74 static int
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3807
diff changeset
75 DART_OpenDevice(_THIS, const char *devname, int iscapture)
1190
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
76 {
3839
506fc6ca82cb OS/2 audio code works in 1.3 now.
Ryan C. Gordon <icculus@icculus.org>
parents: 3819
diff changeset
77 SDL_AudioFormat test_format = SDL_FirstAudioFormat(_this->spec.format);
2001
02108bfd6550 Actually, my silly logic bug was actually correct. :/
Ryan C. Gordon <icculus@icculus.org>
parents: 1999
diff changeset
78 int valid_datatype = 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: 1402
diff changeset
79 MCI_AMP_OPEN_PARMS AmpOpenParms;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
80 int iDeviceOrd = 0; // Default device to be used
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
81 int bOpenShared = 1; // Try opening it shared
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
82 int iBits = 16; // Default is 16 bits signed
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
83 int iFreq = 44100; // Default is 44KHz
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
84 int iChannels = 2; // Default is 2 channels (Stereo)
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
85 int iNumBufs = 2; // Number of audio buffers: 2
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
86 int iBufSize;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
87 int iOpenMode;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
88 int iSilence;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
89 int rc;
1190
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
90
3819
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3807
diff changeset
91 /* Initialize all variables that we clean on shutdown */
3839
506fc6ca82cb OS/2 audio code works in 1.3 now.
Ryan C. Gordon <icculus@icculus.org>
parents: 3819
diff changeset
92 _this->hidden = (struct SDL_PrivateAudioData *)
506fc6ca82cb OS/2 audio code works in 1.3 now.
Ryan C. Gordon <icculus@icculus.org>
parents: 3819
diff changeset
93 SDL_malloc((sizeof *_this->hidden));
506fc6ca82cb OS/2 audio code works in 1.3 now.
Ryan C. Gordon <icculus@icculus.org>
parents: 3819
diff changeset
94 if (_this->hidden == NULL) {
3819
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3807
diff changeset
95 SDL_OutOfMemory();
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3807
diff changeset
96 return 0;
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3807
diff changeset
97 }
3839
506fc6ca82cb OS/2 audio code works in 1.3 now.
Ryan C. Gordon <icculus@icculus.org>
parents: 3819
diff changeset
98 SDL_memset(_this->hidden, 0, (sizeof *_this->hidden));
3819
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3807
diff changeset
99
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
100 // First thing is to try to open a given DART device!
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
101 SDL_memset(&AmpOpenParms, 0, sizeof(MCI_AMP_OPEN_PARMS));
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
102 // pszDeviceType should contain the device type in low word, and device ordinal in high word!
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
103 AmpOpenParms.pszDeviceType =
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
104 (PSZ) (MCI_DEVTYPE_AUDIO_AMPMIX | (iDeviceOrd << 16));
1190
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
105
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
106 iOpenMode = MCI_WAIT | MCI_OPEN_TYPE_ID;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
107 if (bOpenShared)
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
108 iOpenMode |= MCI_OPEN_SHAREABLE;
1190
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
109
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
110 rc = mciSendCommand(0, MCI_OPEN, iOpenMode, (PVOID) & AmpOpenParms, 0);
3819
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3807
diff changeset
111 if (rc != MCIERR_SUCCESS) { // No audio available??
3839
506fc6ca82cb OS/2 audio code works in 1.3 now.
Ryan C. Gordon <icculus@icculus.org>
parents: 3819
diff changeset
112 DART_CloseDevice(_this);
506fc6ca82cb OS/2 audio code works in 1.3 now.
Ryan C. Gordon <icculus@icculus.org>
parents: 3819
diff changeset
113 SDL_SetError("DART: Couldn't open audio device.");
3819
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3807
diff changeset
114 return 0;
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3807
diff changeset
115 }
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3807
diff changeset
116
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
117 // Save the device ID we got from DART!
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
118 // We will use this in the next calls!
3819
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3807
diff changeset
119 _this->hidden->iCurrDeviceOrd = iDeviceOrd = AmpOpenParms.usDeviceID;
1190
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
120
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
121 // Determine the audio parameters from the AudioSpec
3839
506fc6ca82cb OS/2 audio code works in 1.3 now.
Ryan C. Gordon <icculus@icculus.org>
parents: 3819
diff changeset
122 if (_this->spec.channels > 4)
506fc6ca82cb OS/2 audio code works in 1.3 now.
Ryan C. Gordon <icculus@icculus.org>
parents: 3819
diff changeset
123 _this->spec.channels = 4;
1999
dd4b184b3050 Let OS/2 DART backend use SDL converters at a higher level (would fail if
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
124
2001
02108bfd6550 Actually, my silly logic bug was actually correct. :/
Ryan C. Gordon <icculus@icculus.org>
parents: 1999
diff changeset
125 while ((!valid_datatype) && (test_format)) {
3839
506fc6ca82cb OS/2 audio code works in 1.3 now.
Ryan C. Gordon <icculus@icculus.org>
parents: 3819
diff changeset
126 _this->spec.format = test_format;
2001
02108bfd6550 Actually, my silly logic bug was actually correct. :/
Ryan C. Gordon <icculus@icculus.org>
parents: 1999
diff changeset
127 valid_datatype = 1;
1999
dd4b184b3050 Let OS/2 DART backend use SDL converters at a higher level (would fail if
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
128 switch (test_format) {
2043
adf732f1f016 Formatting update
Sam Lantinga <slouken@libsdl.org>
parents: 2001
diff changeset
129 case AUDIO_U8:
adf732f1f016 Formatting update
Sam Lantinga <slouken@libsdl.org>
parents: 2001
diff changeset
130 // Unsigned 8 bit audio data
adf732f1f016 Formatting update
Sam Lantinga <slouken@libsdl.org>
parents: 2001
diff changeset
131 iSilence = 0x80;
3819
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3807
diff changeset
132 _this->hidden->iCurrBits = iBits = 8;
2043
adf732f1f016 Formatting update
Sam Lantinga <slouken@libsdl.org>
parents: 2001
diff changeset
133 break;
1999
dd4b184b3050 Let OS/2 DART backend use SDL converters at a higher level (would fail if
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
134
2043
adf732f1f016 Formatting update
Sam Lantinga <slouken@libsdl.org>
parents: 2001
diff changeset
135 case AUDIO_S16LSB:
adf732f1f016 Formatting update
Sam Lantinga <slouken@libsdl.org>
parents: 2001
diff changeset
136 // Signed 16 bit audio data
adf732f1f016 Formatting update
Sam Lantinga <slouken@libsdl.org>
parents: 2001
diff changeset
137 iSilence = 0x00;
3819
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3807
diff changeset
138 _this->hidden->iCurrBits = iBits = 16;
2043
adf732f1f016 Formatting update
Sam Lantinga <slouken@libsdl.org>
parents: 2001
diff changeset
139 break;
1999
dd4b184b3050 Let OS/2 DART backend use SDL converters at a higher level (would fail if
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
140
dd4b184b3050 Let OS/2 DART backend use SDL converters at a higher level (would fail if
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
141 // !!! FIXME: int32?
dd4b184b3050 Let OS/2 DART backend use SDL converters at a higher level (would fail if
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
142
2043
adf732f1f016 Formatting update
Sam Lantinga <slouken@libsdl.org>
parents: 2001
diff changeset
143 default:
adf732f1f016 Formatting update
Sam Lantinga <slouken@libsdl.org>
parents: 2001
diff changeset
144 valid_datatype = 0;
adf732f1f016 Formatting update
Sam Lantinga <slouken@libsdl.org>
parents: 2001
diff changeset
145 test_format = SDL_NextAudioFormat();
adf732f1f016 Formatting update
Sam Lantinga <slouken@libsdl.org>
parents: 2001
diff changeset
146 break;
1999
dd4b184b3050 Let OS/2 DART backend use SDL converters at a higher level (would fail if
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
147 }
dd4b184b3050 Let OS/2 DART backend use SDL converters at a higher level (would fail if
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
148 }
dd4b184b3050 Let OS/2 DART backend use SDL converters at a higher level (would fail if
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
149
2043
adf732f1f016 Formatting update
Sam Lantinga <slouken@libsdl.org>
parents: 2001
diff changeset
150 if (!valid_datatype) { // shouldn't happen, but just in case...
1190
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
151 // Close DART, and exit with error code!
3839
506fc6ca82cb OS/2 audio code works in 1.3 now.
Ryan C. Gordon <icculus@icculus.org>
parents: 3819
diff changeset
152 DART_CloseDevice(_this);
1190
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
153 SDL_SetError("Unsupported audio format");
3819
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3807
diff changeset
154 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: 1402
diff changeset
155 }
1999
dd4b184b3050 Let OS/2 DART backend use SDL converters at a higher level (would fail if
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
156
3839
506fc6ca82cb OS/2 audio code works in 1.3 now.
Ryan C. Gordon <icculus@icculus.org>
parents: 3819
diff changeset
157 _this->hidden->iCurrFreq = iFreq = _this->spec.freq;
506fc6ca82cb OS/2 audio code works in 1.3 now.
Ryan C. Gordon <icculus@icculus.org>
parents: 3819
diff changeset
158 _this->hidden->iCurrChannels = iChannels = _this->spec.channels;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
159 /* Update the fragment size as size in bytes */
3839
506fc6ca82cb OS/2 audio code works in 1.3 now.
Ryan C. Gordon <icculus@icculus.org>
parents: 3819
diff changeset
160 SDL_CalculateAudioSpec(&_this->spec);
506fc6ca82cb OS/2 audio code works in 1.3 now.
Ryan C. Gordon <icculus@icculus.org>
parents: 3819
diff changeset
161 _this->hidden->iCurrBufSize = iBufSize = _this->spec.size;
1190
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
162
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
163 // Now query this device if it supports the given freq/bits/channels!
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
164 SDL_memset(&(_this->hidden->MixSetupParms), 0,
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
165 sizeof(MCI_MIXSETUP_PARMS));
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
166 _this->hidden->MixSetupParms.ulBitsPerSample = iBits;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
167 _this->hidden->MixSetupParms.ulFormatTag = MCI_WAVE_FORMAT_PCM;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
168 _this->hidden->MixSetupParms.ulSamplesPerSec = iFreq;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
169 _this->hidden->MixSetupParms.ulChannels = iChannels;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
170 _this->hidden->MixSetupParms.ulFormatMode = MCI_PLAY;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
171 _this->hidden->MixSetupParms.ulDeviceType = MCI_DEVTYPE_WAVEFORM_AUDIO;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
172 _this->hidden->MixSetupParms.pmixEvent = DARTEventFunc;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
173 rc = mciSendCommand(iDeviceOrd, MCI_MIXSETUP,
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
174 MCI_WAIT | MCI_MIXSETUP_QUERYMODE,
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
175 &(_this->hidden->MixSetupParms), 0);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
176 if (rc != MCIERR_SUCCESS) { // The device cannot handle this format!
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
177 // Close DART, and exit with error code!
3839
506fc6ca82cb OS/2 audio code works in 1.3 now.
Ryan C. Gordon <icculus@icculus.org>
parents: 3819
diff changeset
178 DART_CloseDevice(_this);
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
179 SDL_SetError("Audio device doesn't support requested audio format");
3819
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3807
diff changeset
180 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: 1402
diff changeset
181 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
182 // The device can handle this format, so initialize!
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
183 rc = mciSendCommand(iDeviceOrd, MCI_MIXSETUP,
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
184 MCI_WAIT | MCI_MIXSETUP_INIT,
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
185 &(_this->hidden->MixSetupParms), 0);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
186 if (rc != MCIERR_SUCCESS) { // The device could not be opened!
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
187 // Close DART, and exit with error code!
3839
506fc6ca82cb OS/2 audio code works in 1.3 now.
Ryan C. Gordon <icculus@icculus.org>
parents: 3819
diff changeset
188 DART_CloseDevice(_this);
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
189 SDL_SetError("Audio device could not be set up");
3819
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3807
diff changeset
190 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: 1402
diff changeset
191 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
192 // Ok, the device is initialized.
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
193 // Now we should allocate buffers. For this, we need a place where
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
194 // the buffer descriptors will be:
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
195 _this->hidden->pMixBuffers =
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
196 (MCI_MIX_BUFFER *) SDL_malloc(sizeof(MCI_MIX_BUFFER) * iNumBufs);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
197 if (!(_this->hidden->pMixBuffers)) { // Not enough memory!
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
198 // Close DART, and exit with error code!
3839
506fc6ca82cb OS/2 audio code works in 1.3 now.
Ryan C. Gordon <icculus@icculus.org>
parents: 3819
diff changeset
199 DART_CloseDevice(_this);
3819
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3807
diff changeset
200 SDL_OutOfMemory();
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3807
diff changeset
201 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: 1402
diff changeset
202 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
203 // Now that we have the place for buffer list, we can ask DART for the
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
204 // buffers!
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
205 _this->hidden->BufferParms.ulNumBuffers = iNumBufs; // Number of buffers
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
206 _this->hidden->BufferParms.ulBufferSize = iBufSize; // each with this size
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
207 _this->hidden->BufferParms.pBufList = _this->hidden->pMixBuffers; // getting descriptorts into this list
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
208 // Allocate buffers!
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
209 rc = mciSendCommand(iDeviceOrd, MCI_BUFFER,
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
210 MCI_WAIT | MCI_ALLOCATE_MEMORY,
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
211 &(_this->hidden->BufferParms), 0);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
212 if ((rc != MCIERR_SUCCESS)
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
213 || (iNumBufs != _this->hidden->BufferParms.ulNumBuffers)
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
214 || (_this->hidden->BufferParms.ulBufferSize == 0)) { // Could not allocate memory!
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
215 // Close DART, and exit with error code!
3839
506fc6ca82cb OS/2 audio code works in 1.3 now.
Ryan C. Gordon <icculus@icculus.org>
parents: 3819
diff changeset
216 DART_CloseDevice(_this);
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
217 SDL_SetError("DART could not allocate buffers");
3819
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3807
diff changeset
218 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: 1402
diff changeset
219 }
3819
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3807
diff changeset
220 _this->hidden->iCurrNumBufs = iNumBufs;
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3807
diff changeset
221
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
222 // Ok, we have all the buffers allocated, let's mark them!
1190
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
223 {
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
224 int i;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
225 for (i = 0; i < iNumBufs; i++) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
226 pMixBufferDesc pBufferDesc =
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
227 (pMixBufferDesc) SDL_malloc(sizeof(tMixBufferDesc));;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
228 // Check if this buffer was really allocated by DART
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
229 if ((!(_this->hidden->pMixBuffers[i].pBuffer))
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
230 || (!pBufferDesc)) { // Wrong buffer!
3839
506fc6ca82cb OS/2 audio code works in 1.3 now.
Ryan C. Gordon <icculus@icculus.org>
parents: 3819
diff changeset
231 DART_CloseDevice(_this);
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
232 SDL_SetError("Error at internal buffer check");
3819
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3807
diff changeset
233 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: 1402
diff changeset
234 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
235 pBufferDesc->iBufferUsage = BUFFER_EMPTY;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
236 pBufferDesc->pSDLAudioDevice = _this;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
237
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
238 _this->hidden->pMixBuffers[i].ulBufferLength =
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
239 _this->hidden->BufferParms.ulBufferSize;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
240 _this->hidden->pMixBuffers[i].ulUserParm = (ULONG) pBufferDesc; // User parameter: Description of buffer
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
241 _this->hidden->pMixBuffers[i].ulFlags = 0; // Some stuff should be flagged here for DART, like end of
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
242 // audio data, but as we will continously send
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
243 // audio data, there will be no end.:)
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
244 SDL_memset(_this->hidden->pMixBuffers[i].pBuffer, iSilence,
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
245 iBufSize);
1190
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
246 }
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
247 }
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
248 _this->hidden->iNextFreeBuffer = 0;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
249 _this->hidden->iLastPlayedBuf = -1;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
250 // Create event semaphore
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
251 if (DosCreateEventSem
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
252 (NULL, &(_this->hidden->hevAudioBufferPlayed), 0, FALSE) != NO_ERROR)
1190
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
253 {
3839
506fc6ca82cb OS/2 audio code works in 1.3 now.
Ryan C. Gordon <icculus@icculus.org>
parents: 3819
diff changeset
254 DART_CloseDevice(_this);
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
255 SDL_SetError("Could not create event semaphore");
3819
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3807
diff changeset
256 return 0;
1190
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
257 }
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
258
3819
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3807
diff changeset
259 return 1;
1190
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
260 }
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
261
3819
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3807
diff changeset
262 static void
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
263 DART_ThreadInit(_THIS)
1190
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
264 {
3796
b19680c84cdf Bunch of 1.3 audio cleanups to remove FIXMEs, get driver specific crap out of
Ryan C. Gordon <icculus@icculus.org>
parents: 2043
diff changeset
265 /* Increase the priority of this thread to make sure that
b19680c84cdf Bunch of 1.3 audio cleanups to remove FIXMEs, get driver specific crap out of
Ryan C. Gordon <icculus@icculus.org>
parents: 2043
diff changeset
266 the audio will be continuous all the time! */
b19680c84cdf Bunch of 1.3 audio cleanups to remove FIXMEs, get driver specific crap out of
Ryan C. Gordon <icculus@icculus.org>
parents: 2043
diff changeset
267 #ifdef USE_DOSSETPRIORITY
b19680c84cdf Bunch of 1.3 audio cleanups to remove FIXMEs, get driver specific crap out of
Ryan C. Gordon <icculus@icculus.org>
parents: 2043
diff changeset
268 if (SDL_getenv("SDL_USE_TIMECRITICAL_AUDIO")) {
b19680c84cdf Bunch of 1.3 audio cleanups to remove FIXMEs, get driver specific crap out of
Ryan C. Gordon <icculus@icculus.org>
parents: 2043
diff changeset
269 #ifdef DEBUG_BUILD
b19680c84cdf Bunch of 1.3 audio cleanups to remove FIXMEs, get driver specific crap out of
Ryan C. Gordon <icculus@icculus.org>
parents: 2043
diff changeset
270 printf
3819
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3807
diff changeset
271 ("[DART_ThreadInit] : Setting priority to TimeCritical+0! (TID%d)\n",
3796
b19680c84cdf Bunch of 1.3 audio cleanups to remove FIXMEs, get driver specific crap out of
Ryan C. Gordon <icculus@icculus.org>
parents: 2043
diff changeset
272 SDL_ThreadID());
b19680c84cdf Bunch of 1.3 audio cleanups to remove FIXMEs, get driver specific crap out of
Ryan C. Gordon <icculus@icculus.org>
parents: 2043
diff changeset
273 #endif
b19680c84cdf Bunch of 1.3 audio cleanups to remove FIXMEs, get driver specific crap out of
Ryan C. Gordon <icculus@icculus.org>
parents: 2043
diff changeset
274 DosSetPriority(PRTYS_THREAD, PRTYC_TIMECRITICAL, 0, 0);
b19680c84cdf Bunch of 1.3 audio cleanups to remove FIXMEs, get driver specific crap out of
Ryan C. Gordon <icculus@icculus.org>
parents: 2043
diff changeset
275 } else {
b19680c84cdf Bunch of 1.3 audio cleanups to remove FIXMEs, get driver specific crap out of
Ryan C. Gordon <icculus@icculus.org>
parents: 2043
diff changeset
276 #ifdef DEBUG_BUILD
b19680c84cdf Bunch of 1.3 audio cleanups to remove FIXMEs, get driver specific crap out of
Ryan C. Gordon <icculus@icculus.org>
parents: 2043
diff changeset
277 printf
3819
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3807
diff changeset
278 ("[DART_ThreadInit] : Setting priority to ForegroundServer+0! (TID%d)\n",
3796
b19680c84cdf Bunch of 1.3 audio cleanups to remove FIXMEs, get driver specific crap out of
Ryan C. Gordon <icculus@icculus.org>
parents: 2043
diff changeset
279 SDL_ThreadID());
b19680c84cdf Bunch of 1.3 audio cleanups to remove FIXMEs, get driver specific crap out of
Ryan C. Gordon <icculus@icculus.org>
parents: 2043
diff changeset
280 #endif
b19680c84cdf Bunch of 1.3 audio cleanups to remove FIXMEs, get driver specific crap out of
Ryan C. Gordon <icculus@icculus.org>
parents: 2043
diff changeset
281 DosSetPriority(PRTYS_THREAD, PRTYC_FOREGROUNDSERVER, 0, 0);
b19680c84cdf Bunch of 1.3 audio cleanups to remove FIXMEs, get driver specific crap out of
Ryan C. Gordon <icculus@icculus.org>
parents: 2043
diff changeset
282 }
b19680c84cdf Bunch of 1.3 audio cleanups to remove FIXMEs, get driver specific crap out of
Ryan C. Gordon <icculus@icculus.org>
parents: 2043
diff changeset
283 #endif
1190
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
284 }
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
285
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
286 /* This function waits until it is possible to write a full sound buffer */
3819
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3807
diff changeset
287 static void
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3807
diff changeset
288 DART_WaitDevice(_THIS)
1190
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
289 {
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
290 int i;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
291 pMixBufferDesc pBufDesc;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
292 ULONG ulPostCount;
1190
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
293
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
294 DosResetEventSem(_this->hidden->hevAudioBufferPlayed, &ulPostCount);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
295 // If there is already an empty buffer, then return now!
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
296 for (i = 0; i < _this->hidden->iCurrNumBufs; i++) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
297 pBufDesc = (pMixBufferDesc) _this->hidden->pMixBuffers[i].ulUserParm;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
298 if (pBufDesc->iBufferUsage == BUFFER_EMPTY)
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
299 return;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
300 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
301 // If there is no empty buffer, wait for one to be empty!
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
302 DosWaitEventSem(_this->hidden->hevAudioBufferPlayed, 1000); // Wait max 1 sec!!! Important!
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
303 return;
1190
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
304 }
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
305
3819
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3807
diff changeset
306 static void
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3807
diff changeset
307 DART_PlayDevice(_THIS)
1190
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
308 {
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
309 int iFreeBuf = _this->hidden->iNextFreeBuffer;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
310 pMixBufferDesc pBufDesc;
1190
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
311
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
312 pBufDesc =
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
313 (pMixBufferDesc) _this->hidden->pMixBuffers[iFreeBuf].ulUserParm;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
314 pBufDesc->iBufferUsage = BUFFER_USED;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
315 // Send it to DART to be queued
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
316 _this->hidden->MixSetupParms.pmixWrite(_this->hidden->MixSetupParms.
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
317 ulMixHandle,
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
318 &(_this->hidden->
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
319 pMixBuffers[iFreeBuf]), 1);
1190
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
320
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
321 _this->hidden->iLastPlayedBuf = iFreeBuf;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
322 iFreeBuf = (iFreeBuf + 1) % _this->hidden->iCurrNumBufs;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
323 _this->hidden->iNextFreeBuffer = iFreeBuf;
1190
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
324 }
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
325
3819
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3807
diff changeset
326 static Uint8 *
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3807
diff changeset
327 DART_GetDeviceBuf(_THIS)
1190
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
328 {
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
329 int iFreeBuf;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
330 Uint8 *pResult;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
331 pMixBufferDesc pBufDesc;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
332
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
333 if (_this) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
334 if (_this->hidden) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
335 iFreeBuf = _this->hidden->iNextFreeBuffer;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
336 pBufDesc =
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
337 (pMixBufferDesc) _this->hidden->pMixBuffers[iFreeBuf].
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
338 ulUserParm;
1190
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
339
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
340 if (pBufDesc) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
341 if (pBufDesc->iBufferUsage == BUFFER_EMPTY) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
342 pResult = _this->hidden->pMixBuffers[iFreeBuf].pBuffer;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
343 return pResult;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
344 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
345 } else
3819
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3807
diff changeset
346 printf("[DART_GetDeviceBuf] : ERROR! pBufDesc = %p\n",
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
347 pBufDesc);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
348 } else
3819
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3807
diff changeset
349 printf("[DART_GetDeviceBuf] : ERROR! _this->hidden = %p\n",
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
350 _this->hidden);
1190
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
351 } else
3819
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3807
diff changeset
352 printf("[DART_GetDeviceBuf] : ERROR! _this = %p\n", _this);
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
353 return NULL;
1190
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
354 }
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
355
3819
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3807
diff changeset
356 static void
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
357 DART_WaitDone(_THIS)
1190
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
358 {
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
359 pMixBufferDesc pBufDesc;
3819
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3807
diff changeset
360 ULONG ulPostCount = 0;
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3807
diff changeset
361 APIRET rc = NO_ERROR;
1190
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
362
3819
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3807
diff changeset
363 pBufDesc = (pMixBufferDesc)
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3807
diff changeset
364 _this->hidden->pMixBuffers[_this->hidden->iLastPlayedBuf].ulUserParm;
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3807
diff changeset
365
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
366 while ((pBufDesc->iBufferUsage != BUFFER_EMPTY) && (rc == NO_ERROR)) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
367 DosResetEventSem(_this->hidden->hevAudioBufferPlayed, &ulPostCount);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
368 rc = DosWaitEventSem(_this->hidden->hevAudioBufferPlayed, 1000); // 1 sec timeout! Important!
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
369 }
1190
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
370 }
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
371
3819
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3807
diff changeset
372 static void
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3807
diff changeset
373 DART_CloseDevice(_THIS)
1190
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
374 {
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
375 MCI_GENERIC_PARMS GenericParms;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
376 int rc;
3819
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3807
diff changeset
377 int i;
1190
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
378
3819
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3807
diff changeset
379 if (_this->hidden != NULL) {
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3807
diff changeset
380 // Stop DART playback
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3807
diff changeset
381 if (_this->hidden->iCurrDeviceOrd) {
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3807
diff changeset
382 rc = mciSendCommand(_this->hidden->iCurrDeviceOrd, MCI_STOP,
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3807
diff changeset
383 MCI_WAIT, &GenericParms, 0);
1190
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
384 #ifdef SFX_DEBUG_BUILD
3819
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3807
diff changeset
385 if (rc != MCIERR_SUCCESS) {
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3807
diff changeset
386 printf("Could not stop DART playback!\n");
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3807
diff changeset
387 fflush(stdout);
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3807
diff changeset
388 }
1190
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
389 #endif
3819
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3807
diff changeset
390 }
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3807
diff changeset
391
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3807
diff changeset
392 // Close event semaphore
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3807
diff changeset
393 if (_this->hidden->hevAudioBufferPlayed) {
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3807
diff changeset
394 DosCloseEventSem(_this->hidden->hevAudioBufferPlayed);
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3807
diff changeset
395 _this->hidden->hevAudioBufferPlayed = 0;
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3807
diff changeset
396 }
1190
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
397
3819
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3807
diff changeset
398 // Free memory of buffer descriptions
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3807
diff changeset
399 for (i = 0; i < _this->hidden->iCurrNumBufs; i++) {
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
400 SDL_free((void *) (_this->hidden->pMixBuffers[i].ulUserParm));
3819
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3807
diff changeset
401 _this->hidden->pMixBuffers[i].ulUserParm = 0;
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3807
diff changeset
402 }
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3807
diff changeset
403 _this->hidden->iCurrNumBufs = 0;
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3807
diff changeset
404
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3807
diff changeset
405 // Deallocate buffers
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3807
diff changeset
406 if (_this->hidden->iCurrDeviceOrd) {
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3807
diff changeset
407 rc = mciSendCommand(_this->hidden->iCurrDeviceOrd, MCI_BUFFER,
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3807
diff changeset
408 MCI_WAIT | MCI_DEALLOCATE_MEMORY,
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3807
diff changeset
409 &(_this->hidden->BufferParms), 0);
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3807
diff changeset
410 }
1190
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
411
3819
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3807
diff changeset
412 // Free bufferlist
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3807
diff changeset
413 if (_this->hidden->pMixBuffers != NULL) {
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3807
diff changeset
414 SDL_free(_this->hidden->pMixBuffers);
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3807
diff changeset
415 _this->hidden->pMixBuffers = NULL;
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3807
diff changeset
416 }
1190
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
417
3819
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3807
diff changeset
418 // Close dart
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3807
diff changeset
419 if (_this->hidden->iCurrDeviceOrd) {
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3807
diff changeset
420 rc = mciSendCommand(_this->hidden->iCurrDeviceOrd, MCI_CLOSE,
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3807
diff changeset
421 MCI_WAIT, &(GenericParms), 0);
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3807
diff changeset
422 }
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3807
diff changeset
423 _this->hidden->iCurrDeviceOrd = 0;
1190
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
424
3819
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3807
diff changeset
425 SDL_free(_this->hidden);
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3807
diff changeset
426 _this->hidden = NULL;
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3807
diff changeset
427 }
1190
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
428 }
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
429
3819
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3807
diff changeset
430 static int
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3807
diff changeset
431 DART_Available(void)
1190
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
432 {
3819
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3807
diff changeset
433 return 1; /* Always available on OS/2 Warp */
1190
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
434 }
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
435
3819
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3807
diff changeset
436 static int
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3807
diff changeset
437 DART_Init(SDL_AudioDriverImpl *impl)
1190
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
438 {
3819
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3807
diff changeset
439 /* Set the function pointers */
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3807
diff changeset
440 impl->OpenDevice = DART_OpenDevice;
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3807
diff changeset
441 impl->ThreadInit = DART_ThreadInit;
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3807
diff changeset
442 impl->WaitDevice = DART_WaitDevice;
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3807
diff changeset
443 impl->GetDeviceBuf = DART_GetDeviceBuf;
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3807
diff changeset
444 impl->PlayDevice = DART_PlayDevice;
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3807
diff changeset
445 impl->WaitDone = DART_WaitDone;
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3807
diff changeset
446 impl->CloseDevice = DART_CloseDevice;
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3807
diff changeset
447 impl->OnlyHasDefaultOutputDevice = 1; /* !!! FIXME: is this right? */
1190
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
448
3819
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3807
diff changeset
449 return 1;
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3807
diff changeset
450 }
1190
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
451
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
452
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
453 AudioBootStrap DART_bootstrap = {
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
454 "dart", "OS/2 Direct Audio RouTines (DART)",
3819
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3807
diff changeset
455 DART_Available, DART_Init, 0
1190
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
456 };
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
457
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
458 /* vi: set ts=4 sw=4 expandtab: */