2005-11-23 07:29:56 +00:00
|
|
|
/*
|
|
|
|
SDL - Simple DirectMedia Layer
|
2006-02-01 06:32:25 +00:00
|
|
|
Copyright (C) 1997-2006 Sam Lantinga
|
2005-11-23 07:29:56 +00:00
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or
|
2006-02-01 06:32:25 +00:00
|
|
|
modify it under the terms of the GNU Lesser General Public
|
2005-11-23 07:29:56 +00:00
|
|
|
License as published by the Free Software Foundation; either
|
2006-02-01 06:32:25 +00:00
|
|
|
version 2.1 of the License, or (at your option) any later version.
|
2005-11-23 07:29:56 +00:00
|
|
|
|
|
|
|
This library is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
2006-02-01 06:32:25 +00:00
|
|
|
Lesser General Public License for more details.
|
2005-11-23 07:29:56 +00:00
|
|
|
|
2006-02-01 06:32:25 +00:00
|
|
|
You should have received a copy of the GNU Lesser General Public
|
|
|
|
License along with this library; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
2005-11-23 07:29:56 +00:00
|
|
|
|
|
|
|
Sam Lantinga
|
|
|
|
slouken@libsdl.org
|
|
|
|
*/
|
2006-02-21 08:46:50 +00:00
|
|
|
#include "SDL_config.h"
|
2005-11-23 07:29:56 +00:00
|
|
|
|
|
|
|
/* Allow access to a raw mixing buffer */
|
|
|
|
|
|
|
|
#include "SDL_timer.h"
|
|
|
|
#include "SDL_audio.h"
|
2006-02-16 10:11:48 +00:00
|
|
|
#include "../SDL_audio_c.h"
|
2005-11-23 07:29:56 +00:00
|
|
|
#include "SDL_dart.h"
|
|
|
|
|
|
|
|
// Buffer states:
|
|
|
|
#define BUFFER_EMPTY 0
|
|
|
|
#define BUFFER_USED 1
|
|
|
|
|
2006-07-10 21:04:37 +00:00
|
|
|
typedef struct _tMixBufferDesc
|
|
|
|
{
|
|
|
|
int iBufferUsage; // BUFFER_EMPTY or BUFFER_USED
|
|
|
|
SDL_AudioDevice *pSDLAudioDevice;
|
2005-11-23 07:29:56 +00:00
|
|
|
} tMixBufferDesc, *pMixBufferDesc;
|
|
|
|
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------
|
|
|
|
// DARTEventFunc
|
|
|
|
//
|
2006-10-17 09:15:21 +00:00
|
|
|
// This function is called by DART, when an event occurs, like end of
|
2005-11-23 07:29:56 +00:00
|
|
|
// playback of a buffer, etc...
|
|
|
|
//---------------------------------------------------------------------
|
2006-10-17 09:15:21 +00:00
|
|
|
static LONG APIENTRY
|
2006-07-10 21:04:37 +00:00
|
|
|
DARTEventFunc(ULONG ulStatus, PMCI_MIX_BUFFER pBuffer, ULONG ulFlags)
|
2005-11-23 07:29:56 +00:00
|
|
|
{
|
2006-07-10 21:04:37 +00:00
|
|
|
if (ulFlags && MIX_WRITE_COMPLETE) { // Playback of buffer completed!
|
|
|
|
|
|
|
|
// Get pointer to buffer description
|
|
|
|
pMixBufferDesc pBufDesc;
|
|
|
|
|
|
|
|
if (pBuffer) {
|
|
|
|
pBufDesc = (pMixBufferDesc) (*pBuffer).ulUserParm;
|
|
|
|
|
|
|
|
if (pBufDesc) {
|
|
|
|
SDL_AudioDevice *pSDLAudioDevice = pBufDesc->pSDLAudioDevice;
|
|
|
|
// Set the buffer to be empty
|
|
|
|
pBufDesc->iBufferUsage = BUFFER_EMPTY;
|
|
|
|
// And notify DART feeder thread that it will have to work a bit.
|
|
|
|
if (pSDLAudioDevice)
|
|
|
|
DosPostEventSem(pSDLAudioDevice->hidden->
|
|
|
|
hevAudioBufferPlayed);
|
|
|
|
}
|
|
|
|
}
|
2005-11-23 07:29:56 +00:00
|
|
|
}
|
2006-07-10 21:04:37 +00:00
|
|
|
return TRUE;
|
2005-11-23 07:29:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-10-17 09:15:21 +00:00
|
|
|
static int
|
|
|
|
DART_OpenDevice(_THIS, const char *devname, int iscapture)
|
2005-11-23 07:29:56 +00:00
|
|
|
{
|
2006-10-17 09:15:21 +00:00
|
|
|
SDL_AudioFormat test_format = SDL_FirstAudioFormat(_this->spec.format);
|
2006-08-31 23:16:48 +00:00
|
|
|
int valid_datatype = 0;
|
2006-07-10 21:04:37 +00:00
|
|
|
MCI_AMP_OPEN_PARMS AmpOpenParms;
|
|
|
|
int iDeviceOrd = 0; // Default device to be used
|
|
|
|
int bOpenShared = 1; // Try opening it shared
|
|
|
|
int iBits = 16; // Default is 16 bits signed
|
|
|
|
int iFreq = 44100; // Default is 44KHz
|
|
|
|
int iChannels = 2; // Default is 2 channels (Stereo)
|
|
|
|
int iNumBufs = 2; // Number of audio buffers: 2
|
|
|
|
int iBufSize;
|
|
|
|
int iOpenMode;
|
|
|
|
int iSilence;
|
|
|
|
int rc;
|
|
|
|
|
2006-10-17 09:15:21 +00:00
|
|
|
/* Initialize all variables that we clean on shutdown */
|
|
|
|
_this->hidden = (struct SDL_PrivateAudioData *)
|
|
|
|
SDL_malloc((sizeof *_this->hidden));
|
|
|
|
if (_this->hidden == NULL) {
|
|
|
|
SDL_OutOfMemory();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
SDL_memset(_this->hidden, 0, (sizeof *_this->hidden));
|
|
|
|
|
2006-07-10 21:04:37 +00:00
|
|
|
// First thing is to try to open a given DART device!
|
|
|
|
SDL_memset(&AmpOpenParms, 0, sizeof(MCI_AMP_OPEN_PARMS));
|
|
|
|
// pszDeviceType should contain the device type in low word, and device ordinal in high word!
|
|
|
|
AmpOpenParms.pszDeviceType =
|
|
|
|
(PSZ) (MCI_DEVTYPE_AUDIO_AMPMIX | (iDeviceOrd << 16));
|
|
|
|
|
|
|
|
iOpenMode = MCI_WAIT | MCI_OPEN_TYPE_ID;
|
|
|
|
if (bOpenShared)
|
|
|
|
iOpenMode |= MCI_OPEN_SHAREABLE;
|
|
|
|
|
|
|
|
rc = mciSendCommand(0, MCI_OPEN, iOpenMode, (PVOID) & AmpOpenParms, 0);
|
2006-10-17 09:15:21 +00:00
|
|
|
if (rc != MCIERR_SUCCESS) { // No audio available??
|
|
|
|
DART_CloseDevice(_this);
|
|
|
|
SDL_SetError("DART: Couldn't open audio device.");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2006-07-10 21:04:37 +00:00
|
|
|
// Save the device ID we got from DART!
|
|
|
|
// We will use this in the next calls!
|
2006-10-17 09:15:21 +00:00
|
|
|
_this->hidden->iCurrDeviceOrd = iDeviceOrd = AmpOpenParms.usDeviceID;
|
2006-07-10 21:04:37 +00:00
|
|
|
|
|
|
|
// Determine the audio parameters from the AudioSpec
|
2006-10-17 09:15:21 +00:00
|
|
|
if (_this->spec.channels > 4)
|
|
|
|
_this->spec.channels = 4;
|
2006-08-31 22:40:53 +00:00
|
|
|
|
2006-08-31 23:16:48 +00:00
|
|
|
while ((!valid_datatype) && (test_format)) {
|
2006-10-17 09:15:21 +00:00
|
|
|
_this->spec.format = test_format;
|
2006-08-31 23:16:48 +00:00
|
|
|
valid_datatype = 1;
|
2006-08-31 22:40:53 +00:00
|
|
|
switch (test_format) {
|
2006-09-24 15:56:55 +00:00
|
|
|
case AUDIO_U8:
|
|
|
|
// Unsigned 8 bit audio data
|
|
|
|
iSilence = 0x80;
|
2006-10-17 09:15:21 +00:00
|
|
|
_this->hidden->iCurrBits = iBits = 8;
|
2006-09-24 15:56:55 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case AUDIO_S16LSB:
|
|
|
|
// Signed 16 bit audio data
|
|
|
|
iSilence = 0x00;
|
2006-10-17 09:15:21 +00:00
|
|
|
_this->hidden->iCurrBits = iBits = 16;
|
2006-09-24 15:56:55 +00:00
|
|
|
break;
|
2006-08-31 22:40:53 +00:00
|
|
|
|
|
|
|
// !!! FIXME: int32?
|
|
|
|
|
2006-09-24 15:56:55 +00:00
|
|
|
default:
|
|
|
|
valid_datatype = 0;
|
|
|
|
test_format = SDL_NextAudioFormat();
|
|
|
|
break;
|
2006-08-31 22:40:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-09-24 15:56:55 +00:00
|
|
|
if (!valid_datatype) { // shouldn't happen, but just in case...
|
2005-11-23 07:29:56 +00:00
|
|
|
// Close DART, and exit with error code!
|
2006-10-17 09:15:21 +00:00
|
|
|
DART_CloseDevice(_this);
|
2005-11-23 07:29:56 +00:00
|
|
|
SDL_SetError("Unsupported audio format");
|
2006-10-17 09:15:21 +00:00
|
|
|
return 0;
|
2006-07-10 21:04:37 +00:00
|
|
|
}
|
2006-08-31 22:40:53 +00:00
|
|
|
|
2006-10-17 09:15:21 +00:00
|
|
|
_this->hidden->iCurrFreq = iFreq = _this->spec.freq;
|
|
|
|
_this->hidden->iCurrChannels = iChannels = _this->spec.channels;
|
2006-07-10 21:04:37 +00:00
|
|
|
/* Update the fragment size as size in bytes */
|
2006-10-17 09:15:21 +00:00
|
|
|
SDL_CalculateAudioSpec(&_this->spec);
|
|
|
|
_this->hidden->iCurrBufSize = iBufSize = _this->spec.size;
|
2006-07-10 21:04:37 +00:00
|
|
|
|
|
|
|
// Now query this device if it supports the given freq/bits/channels!
|
|
|
|
SDL_memset(&(_this->hidden->MixSetupParms), 0,
|
|
|
|
sizeof(MCI_MIXSETUP_PARMS));
|
|
|
|
_this->hidden->MixSetupParms.ulBitsPerSample = iBits;
|
|
|
|
_this->hidden->MixSetupParms.ulFormatTag = MCI_WAVE_FORMAT_PCM;
|
|
|
|
_this->hidden->MixSetupParms.ulSamplesPerSec = iFreq;
|
|
|
|
_this->hidden->MixSetupParms.ulChannels = iChannels;
|
|
|
|
_this->hidden->MixSetupParms.ulFormatMode = MCI_PLAY;
|
|
|
|
_this->hidden->MixSetupParms.ulDeviceType = MCI_DEVTYPE_WAVEFORM_AUDIO;
|
|
|
|
_this->hidden->MixSetupParms.pmixEvent = DARTEventFunc;
|
|
|
|
rc = mciSendCommand(iDeviceOrd, MCI_MIXSETUP,
|
|
|
|
MCI_WAIT | MCI_MIXSETUP_QUERYMODE,
|
|
|
|
&(_this->hidden->MixSetupParms), 0);
|
|
|
|
if (rc != MCIERR_SUCCESS) { // The device cannot handle this format!
|
|
|
|
// Close DART, and exit with error code!
|
2006-10-17 09:15:21 +00:00
|
|
|
DART_CloseDevice(_this);
|
2006-07-10 21:04:37 +00:00
|
|
|
SDL_SetError("Audio device doesn't support requested audio format");
|
2006-10-17 09:15:21 +00:00
|
|
|
return 0;
|
2006-07-10 21:04:37 +00:00
|
|
|
}
|
|
|
|
// The device can handle this format, so initialize!
|
|
|
|
rc = mciSendCommand(iDeviceOrd, MCI_MIXSETUP,
|
|
|
|
MCI_WAIT | MCI_MIXSETUP_INIT,
|
|
|
|
&(_this->hidden->MixSetupParms), 0);
|
|
|
|
if (rc != MCIERR_SUCCESS) { // The device could not be opened!
|
2005-11-23 07:29:56 +00:00
|
|
|
// Close DART, and exit with error code!
|
2006-10-17 09:15:21 +00:00
|
|
|
DART_CloseDevice(_this);
|
2006-07-10 21:04:37 +00:00
|
|
|
SDL_SetError("Audio device could not be set up");
|
2006-10-17 09:15:21 +00:00
|
|
|
return 0;
|
2005-11-23 07:29:56 +00:00
|
|
|
}
|
2006-07-10 21:04:37 +00:00
|
|
|
// Ok, the device is initialized.
|
|
|
|
// Now we should allocate buffers. For this, we need a place where
|
|
|
|
// the buffer descriptors will be:
|
|
|
|
_this->hidden->pMixBuffers =
|
|
|
|
(MCI_MIX_BUFFER *) SDL_malloc(sizeof(MCI_MIX_BUFFER) * iNumBufs);
|
|
|
|
if (!(_this->hidden->pMixBuffers)) { // Not enough memory!
|
|
|
|
// Close DART, and exit with error code!
|
2006-10-17 09:15:21 +00:00
|
|
|
DART_CloseDevice(_this);
|
|
|
|
SDL_OutOfMemory();
|
|
|
|
return 0;
|
2006-07-10 21:04:37 +00:00
|
|
|
}
|
|
|
|
// Now that we have the place for buffer list, we can ask DART for the
|
|
|
|
// buffers!
|
|
|
|
_this->hidden->BufferParms.ulNumBuffers = iNumBufs; // Number of buffers
|
|
|
|
_this->hidden->BufferParms.ulBufferSize = iBufSize; // each with this size
|
|
|
|
_this->hidden->BufferParms.pBufList = _this->hidden->pMixBuffers; // getting descriptorts into this list
|
|
|
|
// Allocate buffers!
|
|
|
|
rc = mciSendCommand(iDeviceOrd, MCI_BUFFER,
|
|
|
|
MCI_WAIT | MCI_ALLOCATE_MEMORY,
|
|
|
|
&(_this->hidden->BufferParms), 0);
|
|
|
|
if ((rc != MCIERR_SUCCESS)
|
|
|
|
|| (iNumBufs != _this->hidden->BufferParms.ulNumBuffers)
|
|
|
|
|| (_this->hidden->BufferParms.ulBufferSize == 0)) { // Could not allocate memory!
|
|
|
|
// Close DART, and exit with error code!
|
2006-10-17 09:15:21 +00:00
|
|
|
DART_CloseDevice(_this);
|
2006-07-10 21:04:37 +00:00
|
|
|
SDL_SetError("DART could not allocate buffers");
|
2006-10-17 09:15:21 +00:00
|
|
|
return 0;
|
2006-07-10 21:04:37 +00:00
|
|
|
}
|
2006-10-17 09:15:21 +00:00
|
|
|
_this->hidden->iCurrNumBufs = iNumBufs;
|
|
|
|
|
2006-07-10 21:04:37 +00:00
|
|
|
// Ok, we have all the buffers allocated, let's mark them!
|
2005-11-23 07:29:56 +00:00
|
|
|
{
|
2006-07-10 21:04:37 +00:00
|
|
|
int i;
|
|
|
|
for (i = 0; i < iNumBufs; i++) {
|
|
|
|
pMixBufferDesc pBufferDesc =
|
|
|
|
(pMixBufferDesc) SDL_malloc(sizeof(tMixBufferDesc));;
|
|
|
|
// Check if this buffer was really allocated by DART
|
|
|
|
if ((!(_this->hidden->pMixBuffers[i].pBuffer))
|
|
|
|
|| (!pBufferDesc)) { // Wrong buffer!
|
2006-10-17 09:15:21 +00:00
|
|
|
DART_CloseDevice(_this);
|
2006-07-10 21:04:37 +00:00
|
|
|
SDL_SetError("Error at internal buffer check");
|
2006-10-17 09:15:21 +00:00
|
|
|
return 0;
|
2006-07-10 21:04:37 +00:00
|
|
|
}
|
|
|
|
pBufferDesc->iBufferUsage = BUFFER_EMPTY;
|
|
|
|
pBufferDesc->pSDLAudioDevice = _this;
|
|
|
|
|
|
|
|
_this->hidden->pMixBuffers[i].ulBufferLength =
|
|
|
|
_this->hidden->BufferParms.ulBufferSize;
|
|
|
|
_this->hidden->pMixBuffers[i].ulUserParm = (ULONG) pBufferDesc; // User parameter: Description of buffer
|
|
|
|
_this->hidden->pMixBuffers[i].ulFlags = 0; // Some stuff should be flagged here for DART, like end of
|
|
|
|
// audio data, but as we will continously send
|
|
|
|
// audio data, there will be no end.:)
|
|
|
|
SDL_memset(_this->hidden->pMixBuffers[i].pBuffer, iSilence,
|
|
|
|
iBufSize);
|
|
|
|
}
|
2005-11-23 07:29:56 +00:00
|
|
|
}
|
2006-07-10 21:04:37 +00:00
|
|
|
_this->hidden->iNextFreeBuffer = 0;
|
|
|
|
_this->hidden->iLastPlayedBuf = -1;
|
|
|
|
// Create event semaphore
|
|
|
|
if (DosCreateEventSem
|
|
|
|
(NULL, &(_this->hidden->hevAudioBufferPlayed), 0, FALSE) != NO_ERROR)
|
|
|
|
{
|
2006-10-17 09:15:21 +00:00
|
|
|
DART_CloseDevice(_this);
|
2006-07-10 21:04:37 +00:00
|
|
|
SDL_SetError("Could not create event semaphore");
|
2006-10-17 09:15:21 +00:00
|
|
|
return 0;
|
2006-07-10 21:04:37 +00:00
|
|
|
}
|
|
|
|
|
2006-10-17 09:15:21 +00:00
|
|
|
return 1;
|
2005-11-23 07:29:56 +00:00
|
|
|
}
|
|
|
|
|
2006-10-17 09:15:21 +00:00
|
|
|
static void
|
2006-07-10 21:04:37 +00:00
|
|
|
DART_ThreadInit(_THIS)
|
2005-11-23 07:29:56 +00:00
|
|
|
{
|
2006-10-17 09:15:21 +00:00
|
|
|
/* Increase the priority of this thread to make sure that
|
|
|
|
the audio will be continuous all the time! */
|
|
|
|
#ifdef USE_DOSSETPRIORITY
|
|
|
|
if (SDL_getenv("SDL_USE_TIMECRITICAL_AUDIO")) {
|
|
|
|
#ifdef DEBUG_BUILD
|
|
|
|
printf
|
|
|
|
("[DART_ThreadInit] : Setting priority to TimeCritical+0! (TID%d)\n",
|
|
|
|
SDL_ThreadID());
|
|
|
|
#endif
|
|
|
|
DosSetPriority(PRTYS_THREAD, PRTYC_TIMECRITICAL, 0, 0);
|
|
|
|
} else {
|
|
|
|
#ifdef DEBUG_BUILD
|
|
|
|
printf
|
|
|
|
("[DART_ThreadInit] : Setting priority to ForegroundServer+0! (TID%d)\n",
|
|
|
|
SDL_ThreadID());
|
|
|
|
#endif
|
|
|
|
DosSetPriority(PRTYS_THREAD, PRTYC_FOREGROUNDSERVER, 0, 0);
|
|
|
|
}
|
|
|
|
#endif
|
2005-11-23 07:29:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* This function waits until it is possible to write a full sound buffer */
|
2006-10-17 09:15:21 +00:00
|
|
|
static void
|
|
|
|
DART_WaitDevice(_THIS)
|
2005-11-23 07:29:56 +00:00
|
|
|
{
|
2006-07-10 21:04:37 +00:00
|
|
|
int i;
|
|
|
|
pMixBufferDesc pBufDesc;
|
|
|
|
ULONG ulPostCount;
|
|
|
|
|
|
|
|
DosResetEventSem(_this->hidden->hevAudioBufferPlayed, &ulPostCount);
|
|
|
|
// If there is already an empty buffer, then return now!
|
|
|
|
for (i = 0; i < _this->hidden->iCurrNumBufs; i++) {
|
|
|
|
pBufDesc = (pMixBufferDesc) _this->hidden->pMixBuffers[i].ulUserParm;
|
|
|
|
if (pBufDesc->iBufferUsage == BUFFER_EMPTY)
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// If there is no empty buffer, wait for one to be empty!
|
|
|
|
DosWaitEventSem(_this->hidden->hevAudioBufferPlayed, 1000); // Wait max 1 sec!!! Important!
|
|
|
|
return;
|
2005-11-23 07:29:56 +00:00
|
|
|
}
|
|
|
|
|
2006-10-17 09:15:21 +00:00
|
|
|
static void
|
|
|
|
DART_PlayDevice(_THIS)
|
2005-11-23 07:29:56 +00:00
|
|
|
{
|
2006-07-10 21:04:37 +00:00
|
|
|
int iFreeBuf = _this->hidden->iNextFreeBuffer;
|
|
|
|
pMixBufferDesc pBufDesc;
|
|
|
|
|
|
|
|
pBufDesc =
|
|
|
|
(pMixBufferDesc) _this->hidden->pMixBuffers[iFreeBuf].ulUserParm;
|
|
|
|
pBufDesc->iBufferUsage = BUFFER_USED;
|
|
|
|
// Send it to DART to be queued
|
|
|
|
_this->hidden->MixSetupParms.pmixWrite(_this->hidden->MixSetupParms.
|
|
|
|
ulMixHandle,
|
|
|
|
&(_this->hidden->
|
|
|
|
pMixBuffers[iFreeBuf]), 1);
|
|
|
|
|
|
|
|
_this->hidden->iLastPlayedBuf = iFreeBuf;
|
|
|
|
iFreeBuf = (iFreeBuf + 1) % _this->hidden->iCurrNumBufs;
|
|
|
|
_this->hidden->iNextFreeBuffer = iFreeBuf;
|
2005-11-23 07:29:56 +00:00
|
|
|
}
|
|
|
|
|
2006-10-17 09:15:21 +00:00
|
|
|
static Uint8 *
|
|
|
|
DART_GetDeviceBuf(_THIS)
|
2005-11-23 07:29:56 +00:00
|
|
|
{
|
2006-07-10 21:04:37 +00:00
|
|
|
int iFreeBuf;
|
|
|
|
Uint8 *pResult;
|
|
|
|
pMixBufferDesc pBufDesc;
|
2005-11-23 07:29:56 +00:00
|
|
|
|
2006-07-10 21:04:37 +00:00
|
|
|
if (_this) {
|
|
|
|
if (_this->hidden) {
|
|
|
|
iFreeBuf = _this->hidden->iNextFreeBuffer;
|
|
|
|
pBufDesc =
|
|
|
|
(pMixBufferDesc) _this->hidden->pMixBuffers[iFreeBuf].
|
|
|
|
ulUserParm;
|
|
|
|
|
|
|
|
if (pBufDesc) {
|
|
|
|
if (pBufDesc->iBufferUsage == BUFFER_EMPTY) {
|
|
|
|
pResult = _this->hidden->pMixBuffers[iFreeBuf].pBuffer;
|
|
|
|
return pResult;
|
|
|
|
}
|
|
|
|
} else
|
2006-10-17 09:15:21 +00:00
|
|
|
printf("[DART_GetDeviceBuf] : ERROR! pBufDesc = %p\n",
|
2006-07-10 21:04:37 +00:00
|
|
|
pBufDesc);
|
|
|
|
} else
|
2006-10-17 09:15:21 +00:00
|
|
|
printf("[DART_GetDeviceBuf] : ERROR! _this->hidden = %p\n",
|
2006-07-10 21:04:37 +00:00
|
|
|
_this->hidden);
|
2005-11-23 07:29:56 +00:00
|
|
|
} else
|
2006-10-17 09:15:21 +00:00
|
|
|
printf("[DART_GetDeviceBuf] : ERROR! _this = %p\n", _this);
|
2006-07-10 21:04:37 +00:00
|
|
|
return NULL;
|
2005-11-23 07:29:56 +00:00
|
|
|
}
|
|
|
|
|
2006-10-17 09:15:21 +00:00
|
|
|
static void
|
2006-07-10 21:04:37 +00:00
|
|
|
DART_WaitDone(_THIS)
|
2005-11-23 07:29:56 +00:00
|
|
|
{
|
2006-07-10 21:04:37 +00:00
|
|
|
pMixBufferDesc pBufDesc;
|
2006-10-17 09:15:21 +00:00
|
|
|
ULONG ulPostCount = 0;
|
|
|
|
APIRET rc = NO_ERROR;
|
|
|
|
|
|
|
|
pBufDesc = (pMixBufferDesc)
|
|
|
|
_this->hidden->pMixBuffers[_this->hidden->iLastPlayedBuf].ulUserParm;
|
2006-07-10 21:04:37 +00:00
|
|
|
|
|
|
|
while ((pBufDesc->iBufferUsage != BUFFER_EMPTY) && (rc == NO_ERROR)) {
|
|
|
|
DosResetEventSem(_this->hidden->hevAudioBufferPlayed, &ulPostCount);
|
|
|
|
rc = DosWaitEventSem(_this->hidden->hevAudioBufferPlayed, 1000); // 1 sec timeout! Important!
|
|
|
|
}
|
2005-11-23 07:29:56 +00:00
|
|
|
}
|
|
|
|
|
2006-10-17 09:15:21 +00:00
|
|
|
static void
|
|
|
|
DART_CloseDevice(_THIS)
|
2005-11-23 07:29:56 +00:00
|
|
|
{
|
2006-07-10 21:04:37 +00:00
|
|
|
MCI_GENERIC_PARMS GenericParms;
|
|
|
|
int rc;
|
2006-10-17 09:15:21 +00:00
|
|
|
int i;
|
2005-11-23 07:29:56 +00:00
|
|
|
|
2006-10-17 09:15:21 +00:00
|
|
|
if (_this->hidden != NULL) {
|
|
|
|
// Stop DART playback
|
|
|
|
if (_this->hidden->iCurrDeviceOrd) {
|
|
|
|
rc = mciSendCommand(_this->hidden->iCurrDeviceOrd, MCI_STOP,
|
|
|
|
MCI_WAIT, &GenericParms, 0);
|
2005-11-23 07:29:56 +00:00
|
|
|
#ifdef SFX_DEBUG_BUILD
|
2006-10-17 09:15:21 +00:00
|
|
|
if (rc != MCIERR_SUCCESS) {
|
|
|
|
printf("Could not stop DART playback!\n");
|
|
|
|
fflush(stdout);
|
|
|
|
}
|
2005-11-23 07:29:56 +00:00
|
|
|
#endif
|
2006-10-17 09:15:21 +00:00
|
|
|
}
|
2005-11-23 07:29:56 +00:00
|
|
|
|
2006-10-17 09:15:21 +00:00
|
|
|
// Close event semaphore
|
|
|
|
if (_this->hidden->hevAudioBufferPlayed) {
|
|
|
|
DosCloseEventSem(_this->hidden->hevAudioBufferPlayed);
|
|
|
|
_this->hidden->hevAudioBufferPlayed = 0;
|
|
|
|
}
|
2005-11-23 07:29:56 +00:00
|
|
|
|
2006-10-17 09:15:21 +00:00
|
|
|
// Free memory of buffer descriptions
|
|
|
|
for (i = 0; i < _this->hidden->iCurrNumBufs; i++) {
|
|
|
|
SDL_free((void *) (_this->hidden->pMixBuffers[i].ulUserParm));
|
|
|
|
_this->hidden->pMixBuffers[i].ulUserParm = 0;
|
|
|
|
}
|
|
|
|
_this->hidden->iCurrNumBufs = 0;
|
2005-11-23 07:29:56 +00:00
|
|
|
|
2006-10-17 09:15:21 +00:00
|
|
|
// Deallocate buffers
|
|
|
|
if (_this->hidden->iCurrDeviceOrd) {
|
|
|
|
rc = mciSendCommand(_this->hidden->iCurrDeviceOrd, MCI_BUFFER,
|
|
|
|
MCI_WAIT | MCI_DEALLOCATE_MEMORY,
|
|
|
|
&(_this->hidden->BufferParms), 0);
|
|
|
|
}
|
2005-11-23 07:29:56 +00:00
|
|
|
|
2006-10-17 09:15:21 +00:00
|
|
|
// Free bufferlist
|
|
|
|
if (_this->hidden->pMixBuffers != NULL) {
|
|
|
|
SDL_free(_this->hidden->pMixBuffers);
|
|
|
|
_this->hidden->pMixBuffers = NULL;
|
|
|
|
}
|
2005-11-23 07:29:56 +00:00
|
|
|
|
2006-10-17 09:15:21 +00:00
|
|
|
// Close dart
|
|
|
|
if (_this->hidden->iCurrDeviceOrd) {
|
|
|
|
rc = mciSendCommand(_this->hidden->iCurrDeviceOrd, MCI_CLOSE,
|
|
|
|
MCI_WAIT, &(GenericParms), 0);
|
|
|
|
}
|
|
|
|
_this->hidden->iCurrDeviceOrd = 0;
|
2005-11-23 07:29:56 +00:00
|
|
|
|
2006-10-17 09:15:21 +00:00
|
|
|
SDL_free(_this->hidden);
|
|
|
|
_this->hidden = NULL;
|
|
|
|
}
|
2005-11-23 07:29:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-10-17 09:15:21 +00:00
|
|
|
static int
|
|
|
|
DART_Init(SDL_AudioDriverImpl *impl)
|
2005-11-23 07:29:56 +00:00
|
|
|
{
|
2006-07-10 21:04:37 +00:00
|
|
|
/* Set the function pointers */
|
2006-10-17 09:15:21 +00:00
|
|
|
impl->OpenDevice = DART_OpenDevice;
|
|
|
|
impl->ThreadInit = DART_ThreadInit;
|
|
|
|
impl->WaitDevice = DART_WaitDevice;
|
|
|
|
impl->GetDeviceBuf = DART_GetDeviceBuf;
|
|
|
|
impl->PlayDevice = DART_PlayDevice;
|
|
|
|
impl->WaitDone = DART_WaitDone;
|
|
|
|
impl->CloseDevice = DART_CloseDevice;
|
|
|
|
impl->OnlyHasDefaultOutputDevice = 1; /* !!! FIXME: is this right? */
|
|
|
|
|
|
|
|
return 1;
|
2005-11-23 07:29:56 +00:00
|
|
|
}
|
|
|
|
|
2006-10-17 09:15:21 +00:00
|
|
|
|
2005-11-23 07:29:56 +00:00
|
|
|
AudioBootStrap DART_bootstrap = {
|
2006-10-17 09:15:21 +00:00
|
|
|
"dart", "OS/2 Direct Audio RouTines (DART)", DART_Init, 0
|
2005-11-23 07:29:56 +00:00
|
|
|
};
|
|
|
|
|
2006-07-10 21:04:37 +00:00
|
|
|
/* vi: set ts=4 sw=4 expandtab: */
|