Reworked Windows waveOut code.
Implemented multi-device support, changed name to "winmm". --HG-- rename : src/audio/windib/SDL_dibaudio.h => src/audio/winmm/SDL_winmm.h
This commit is contained in:
parent
ac93bd6e55
commit
6bd5c1b002
9 changed files with 210 additions and 71 deletions
|
@ -796,11 +796,11 @@
|
||||||
>
|
>
|
||||||
</File>
|
</File>
|
||||||
<File
|
<File
|
||||||
RelativePath="..\..\src\audio\windib\SDL_dibaudio.c"
|
RelativePath="..\..\src\audio\winmm\SDL_winmm.c"
|
||||||
>
|
>
|
||||||
</File>
|
</File>
|
||||||
<File
|
<File
|
||||||
RelativePath="..\..\src\audio\windib\SDL_dibaudio.h"
|
RelativePath="..\..\src\audio\winmm\SDL_winmm.h"
|
||||||
>
|
>
|
||||||
</File>
|
</File>
|
||||||
<File
|
<File
|
||||||
|
|
|
@ -785,11 +785,11 @@
|
||||||
>
|
>
|
||||||
</File>
|
</File>
|
||||||
<File
|
<File
|
||||||
RelativePath="..\..\src\audio\windib\SDL_dibaudio.c"
|
RelativePath="..\..\src\audio\winmm\SDL_winmm.c"
|
||||||
>
|
>
|
||||||
</File>
|
</File>
|
||||||
<File
|
<File
|
||||||
RelativePath="..\..\src\audio\windib\SDL_dibaudio.h"
|
RelativePath="..\..\src\audio\winmm\SDL_winmm.h"
|
||||||
>
|
>
|
||||||
</File>
|
</File>
|
||||||
<File
|
<File
|
||||||
|
|
|
@ -276,7 +276,7 @@
|
||||||
<ClInclude Include="..\..\src\video\SDL_blit_copy.h" />
|
<ClInclude Include="..\..\src\video\SDL_blit_copy.h" />
|
||||||
<ClInclude Include="..\..\src\video\SDL_blit_slow.h" />
|
<ClInclude Include="..\..\src\video\SDL_blit_slow.h" />
|
||||||
<ClInclude Include="..\..\src\video\SDL_shape_internals.h" />
|
<ClInclude Include="..\..\src\video\SDL_shape_internals.h" />
|
||||||
<ClInclude Include="..\..\src\audio\windib\SDL_dibaudio.h" />
|
<ClInclude Include="..\..\src\audio\winmm\SDL_winmm.h" />
|
||||||
<ClInclude Include="..\..\src\audio\disk\SDL_diskaudio.h" />
|
<ClInclude Include="..\..\src\audio\disk\SDL_diskaudio.h" />
|
||||||
<ClInclude Include="..\..\src\audio\dummy\SDL_dummyaudio.h" />
|
<ClInclude Include="..\..\src\audio\dummy\SDL_dummyaudio.h" />
|
||||||
<ClInclude Include="..\..\src\audio\directsound\SDL_directsound.h" />
|
<ClInclude Include="..\..\src\audio\directsound\SDL_directsound.h" />
|
||||||
|
@ -377,7 +377,7 @@
|
||||||
<ClCompile Include="..\..\src\cpuinfo\SDL_cpuinfo.c" />
|
<ClCompile Include="..\..\src\cpuinfo\SDL_cpuinfo.c" />
|
||||||
<ClCompile Include="..\..\src\video\SDL_clipboard.c" />
|
<ClCompile Include="..\..\src\video\SDL_clipboard.c" />
|
||||||
<ClCompile Include="..\..\src\video\SDL_shape.c" />
|
<ClCompile Include="..\..\src\video\SDL_shape.c" />
|
||||||
<ClCompile Include="..\..\src\audio\windib\SDL_dibaudio.c" />
|
<ClCompile Include="..\..\src\audio\winmm\SDL_winmm.c" />
|
||||||
<ClCompile Include="..\..\src\audio\disk\SDL_diskaudio.c" />
|
<ClCompile Include="..\..\src\audio\disk\SDL_diskaudio.c" />
|
||||||
<ClCompile Include="..\..\src\audio\dummy\SDL_dummyaudio.c" />
|
<ClCompile Include="..\..\src\audio\dummy\SDL_dummyaudio.c" />
|
||||||
<ClCompile Include="..\..\src\audio\directsound\SDL_directsound.c" />
|
<ClCompile Include="..\..\src\audio\directsound\SDL_directsound.c" />
|
||||||
|
|
|
@ -2057,8 +2057,8 @@ AC_HELP_STRING([--enable-render-d3d], [enable the Direct3D render driver [[defau
|
||||||
fi
|
fi
|
||||||
# Set up files for the audio library
|
# Set up files for the audio library
|
||||||
if test x$enable_audio = xyes; then
|
if test x$enable_audio = xyes; then
|
||||||
AC_DEFINE(SDL_AUDIO_DRIVER_WINWAVEOUT, 1, [ ])
|
AC_DEFINE(SDL_AUDIO_DRIVER_WINMM, 1, [ ])
|
||||||
SOURCES="$SOURCES $srcdir/src/audio/windib/*.c"
|
SOURCES="$SOURCES $srcdir/src/audio/winmm/*.c"
|
||||||
if test x$have_dsound = xyes; then
|
if test x$have_dsound = xyes; then
|
||||||
AC_DEFINE(SDL_AUDIO_DRIVER_DSOUND, 1, [ ])
|
AC_DEFINE(SDL_AUDIO_DRIVER_DSOUND, 1, [ ])
|
||||||
SOURCES="$SOURCES $srcdir/src/audio/directsound/*.c"
|
SOURCES="$SOURCES $srcdir/src/audio/directsound/*.c"
|
||||||
|
@ -2144,8 +2144,8 @@ AC_HELP_STRING([--enable-render-d3d], [enable the Direct3D render driver [[defau
|
||||||
fi
|
fi
|
||||||
# Set up files for the audio library
|
# Set up files for the audio library
|
||||||
if test x$enable_audio = xyes; then
|
if test x$enable_audio = xyes; then
|
||||||
AC_DEFINE(SDL_AUDIO_DRIVER_WINWAVEOUT, 1, [ ])
|
AC_DEFINE(SDL_AUDIO_DRIVER_WINMM, 1, [ ])
|
||||||
SOURCES="$SOURCES $srcdir/src/audio/windib/*.c"
|
SOURCES="$SOURCES $srcdir/src/audio/winmm/*.c"
|
||||||
if test x$have_dsound = xyes; then
|
if test x$have_dsound = xyes; then
|
||||||
AC_DEFINE(SDL_AUDIO_DRIVER_DSOUND, 1, [ ])
|
AC_DEFINE(SDL_AUDIO_DRIVER_DSOUND, 1, [ ])
|
||||||
SOURCES="$SOURCES $srcdir/src/audio/directsound/*.c"
|
SOURCES="$SOURCES $srcdir/src/audio/directsound/*.c"
|
||||||
|
|
|
@ -195,7 +195,7 @@
|
||||||
#undef SDL_AUDIO_DRIVER_PAUDIO
|
#undef SDL_AUDIO_DRIVER_PAUDIO
|
||||||
#undef SDL_AUDIO_DRIVER_QSA
|
#undef SDL_AUDIO_DRIVER_QSA
|
||||||
#undef SDL_AUDIO_DRIVER_SUNAUDIO
|
#undef SDL_AUDIO_DRIVER_SUNAUDIO
|
||||||
#undef SDL_AUDIO_DRIVER_WINWAVEOUT
|
#undef SDL_AUDIO_DRIVER_WINMM
|
||||||
#undef SDL_AUDIO_DRIVER_FUSIONSOUND
|
#undef SDL_AUDIO_DRIVER_FUSIONSOUND
|
||||||
#undef SDL_AUDIO_DRIVER_FUSIONSOUND_DYNAMIC
|
#undef SDL_AUDIO_DRIVER_FUSIONSOUND_DYNAMIC
|
||||||
|
|
||||||
|
|
|
@ -146,7 +146,7 @@ typedef unsigned int uintptr_t;
|
||||||
#ifndef _WIN32_WCE
|
#ifndef _WIN32_WCE
|
||||||
#define SDL_AUDIO_DRIVER_DSOUND 1
|
#define SDL_AUDIO_DRIVER_DSOUND 1
|
||||||
#endif
|
#endif
|
||||||
#define SDL_AUDIO_DRIVER_WINWAVEOUT 1
|
#define SDL_AUDIO_DRIVER_WINMM 1
|
||||||
#define SDL_AUDIO_DRIVER_DISK 1
|
#define SDL_AUDIO_DRIVER_DISK 1
|
||||||
#define SDL_AUDIO_DRIVER_DUMMY 1
|
#define SDL_AUDIO_DRIVER_DUMMY 1
|
||||||
|
|
||||||
|
|
|
@ -53,7 +53,7 @@ extern AudioBootStrap ARTS_bootstrap;
|
||||||
extern AudioBootStrap ESD_bootstrap;
|
extern AudioBootStrap ESD_bootstrap;
|
||||||
extern AudioBootStrap NAS_bootstrap;
|
extern AudioBootStrap NAS_bootstrap;
|
||||||
extern AudioBootStrap DSOUND_bootstrap;
|
extern AudioBootStrap DSOUND_bootstrap;
|
||||||
extern AudioBootStrap WINWAVEOUT_bootstrap;
|
extern AudioBootStrap WINMM_bootstrap;
|
||||||
extern AudioBootStrap PAUDIO_bootstrap;
|
extern AudioBootStrap PAUDIO_bootstrap;
|
||||||
extern AudioBootStrap BEOSAUDIO_bootstrap;
|
extern AudioBootStrap BEOSAUDIO_bootstrap;
|
||||||
extern AudioBootStrap COREAUDIO_bootstrap;
|
extern AudioBootStrap COREAUDIO_bootstrap;
|
||||||
|
@ -100,8 +100,8 @@ static const AudioBootStrap *const bootstrap[] = {
|
||||||
#if SDL_AUDIO_DRIVER_DSOUND
|
#if SDL_AUDIO_DRIVER_DSOUND
|
||||||
&DSOUND_bootstrap,
|
&DSOUND_bootstrap,
|
||||||
#endif
|
#endif
|
||||||
#if SDL_AUDIO_DRIVER_WINWAVEOUT
|
#if SDL_AUDIO_DRIVER_WINMM
|
||||||
&WINWAVEOUT_bootstrap,
|
&WINMM_bootstrap,
|
||||||
#endif
|
#endif
|
||||||
#if SDL_AUDIO_DRIVER_PAUDIO
|
#if SDL_AUDIO_DRIVER_PAUDIO
|
||||||
&PAUDIO_bootstrap,
|
&PAUDIO_bootstrap,
|
||||||
|
|
|
@ -28,23 +28,119 @@
|
||||||
#include "SDL_timer.h"
|
#include "SDL_timer.h"
|
||||||
#include "SDL_audio.h"
|
#include "SDL_audio.h"
|
||||||
#include "../SDL_audio_c.h"
|
#include "../SDL_audio_c.h"
|
||||||
#include "SDL_dibaudio.h"
|
#include "SDL_winmm.h"
|
||||||
#if defined(_WIN32_WCE) && (_WIN32_WCE < 300)
|
#if defined(_WIN32_WCE) && (_WIN32_WCE < 300)
|
||||||
#include "win_ce_semaphore.h"
|
#include "win_ce_semaphore.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(_WIN32_WCE)
|
|
||||||
#define WINDOWS_OS_NAME "Windows CE/PocketPC"
|
/* !!! FIXME: this is a cut and paste of SDL_FreeUnixAudioDevices(),
|
||||||
#elif defined(WIN64)
|
* !!! FIXME: which is more proof this needs to be managed in SDL_audio.c
|
||||||
#define WINDOWS_OS_NAME "Win64"
|
* !!! FIXME: and not in drivers.
|
||||||
|
*/
|
||||||
|
static void
|
||||||
|
FreeWaveOutAudioDevices(char ***devices, int *devCount)
|
||||||
|
{
|
||||||
|
int i = *devCount;
|
||||||
|
if ((i > 0) && (*devices != NULL)) {
|
||||||
|
while (i--) {
|
||||||
|
SDL_free((*devices)[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (*devices != NULL) {
|
||||||
|
SDL_free(*devices);
|
||||||
|
}
|
||||||
|
|
||||||
|
*devices = NULL;
|
||||||
|
*devCount = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static char **outputDevices = NULL;
|
||||||
|
static int outputDeviceCount = 0;
|
||||||
|
static char **inputDevices = NULL;
|
||||||
|
static int inputDeviceCount = 0;
|
||||||
|
|
||||||
|
static int
|
||||||
|
DetectWaveOutDevices(void)
|
||||||
|
{
|
||||||
|
UINT i;
|
||||||
|
const UINT devcount = waveOutGetNumDevs();
|
||||||
|
WAVEOUTCAPS caps;
|
||||||
|
FreeWaveOutAudioDevices(&outputDevices, &outputDeviceCount);
|
||||||
|
outputDevices = (const char **) SDL_malloc(sizeof (char *) * devcount);
|
||||||
|
for (i = 0; i < devcount; i++) {
|
||||||
|
if (waveOutGetDevCaps(i, &caps, sizeof (caps)) == MMSYSERR_NOERROR) {
|
||||||
|
outputDevices[outputDeviceCount] = WIN_StringToUTF8(caps.szPname);
|
||||||
|
if (outputDevices[outputDeviceCount] != NULL) {
|
||||||
|
outputDeviceCount++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return outputDeviceCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
DetectWaveInDevices(void)
|
||||||
|
{
|
||||||
|
UINT i;
|
||||||
|
const UINT devcount = waveInGetNumDevs();
|
||||||
|
WAVEINCAPS caps;
|
||||||
|
FreeWaveInAudioDevices(&inputDevices, &inputDeviceCount);
|
||||||
|
inputDevices = (const char **) SDL_malloc(sizeof (char *) * devcount);
|
||||||
|
for (i = 0; i < devcount; i++) {
|
||||||
|
if (waveInGetDevCaps(i, &caps, sizeof (caps)) == MMSYSERR_NOERROR) {
|
||||||
|
inputDevices[inputDeviceCount] = WIN_StringToUTF8(caps.szPname);
|
||||||
|
if (inputDevices[inputDeviceCount] != NULL) {
|
||||||
|
inputDeviceCount++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return inputDeviceCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
WINMM_DetectDevices(int iscapture)
|
||||||
|
{
|
||||||
|
return (iscapture) ? DetectWaveInDevices() : DetectWaveOutDevices();
|
||||||
|
}
|
||||||
|
|
||||||
|
static const char *
|
||||||
|
WINMM_GetDeviceName(int index, int iscapture)
|
||||||
|
{
|
||||||
|
if ((iscapture) && (index < inputDeviceCount)) {
|
||||||
|
return inputDevices[index];
|
||||||
|
} else if ((!iscapture) && (index < outputDeviceCount)) {
|
||||||
|
return outputDevices[index];
|
||||||
|
}
|
||||||
|
|
||||||
|
SDL_SetError("No such device");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void CALLBACK
|
||||||
|
CaptureSound(HWAVEIN hwi, UINT uMsg, DWORD_PTR dwInstance,
|
||||||
|
DWORD_PTR dwParam1, DWORD_PTR dwParam2)
|
||||||
|
{
|
||||||
|
SDL_AudioDevice *this = (SDL_AudioDevice *) dwInstance;
|
||||||
|
|
||||||
|
/* Only service "buffer is filled" messages */
|
||||||
|
if (uMsg != WIM_DATA)
|
||||||
|
return;
|
||||||
|
|
||||||
|
/* Signal that we have a new buffer of data */
|
||||||
|
#if defined(_WIN32_WCE) && (_WIN32_WCE < 300)
|
||||||
|
ReleaseSemaphoreCE(this->hidden->audio_sem, 1, NULL);
|
||||||
#else
|
#else
|
||||||
#define WINDOWS_OS_NAME "Win32"
|
ReleaseSemaphore(this->hidden->audio_sem, 1, NULL);
|
||||||
#endif
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/* The Win32 callback for filling the WAVE device */
|
/* The Win32 callback for filling the WAVE device */
|
||||||
static void CALLBACK
|
static void CALLBACK
|
||||||
FillSound(HWAVEOUT hwo, UINT uMsg, DWORD_PTR dwInstance,
|
FillSound(HWAVEOUT hwo, UINT uMsg, DWORD_PTR dwInstance,
|
||||||
DWORD dwParam1, DWORD dwParam2)
|
DWORD_PTR dwParam1, DWORD_PTR dwParam2)
|
||||||
{
|
{
|
||||||
SDL_AudioDevice *this = (SDL_AudioDevice *) dwInstance;
|
SDL_AudioDevice *this = (SDL_AudioDevice *) dwInstance;
|
||||||
|
|
||||||
|
@ -77,15 +173,8 @@ SetMMerror(char *function, MMRESULT code)
|
||||||
SDL_SetError("%s", errbuf);
|
SDL_SetError("%s", errbuf);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Set high priority for the audio thread */
|
|
||||||
static void
|
static void
|
||||||
WINWAVEOUT_ThreadInit(_THIS)
|
WINMM_WaitDevice(_THIS)
|
||||||
{
|
|
||||||
SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_HIGHEST);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
WINWAVEOUT_WaitDevice(_THIS)
|
|
||||||
{
|
{
|
||||||
/* Wait for an audio chunk to finish */
|
/* Wait for an audio chunk to finish */
|
||||||
#if defined(_WIN32_WCE) && (_WIN32_WCE < 300)
|
#if defined(_WIN32_WCE) && (_WIN32_WCE < 300)
|
||||||
|
@ -95,25 +184,25 @@ WINWAVEOUT_WaitDevice(_THIS)
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
Uint8 *
|
static Uint8 *
|
||||||
WINWAVEOUT_GetDeviceBuf(_THIS)
|
WINMM_GetDeviceBuf(_THIS)
|
||||||
{
|
{
|
||||||
return (Uint8 *) (this->hidden->
|
return (Uint8 *) (this->hidden->
|
||||||
wavebuf[this->hidden->next_buffer].lpData);
|
wavebuf[this->hidden->next_buffer].lpData);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
static void
|
||||||
WINWAVEOUT_PlayDevice(_THIS)
|
WINMM_PlayDevice(_THIS)
|
||||||
{
|
{
|
||||||
/* Queue it up */
|
/* Queue it up */
|
||||||
waveOutWrite(this->hidden->sound,
|
waveOutWrite(this->hidden->hout,
|
||||||
&this->hidden->wavebuf[this->hidden->next_buffer],
|
&this->hidden->wavebuf[this->hidden->next_buffer],
|
||||||
sizeof(this->hidden->wavebuf[0]));
|
sizeof(this->hidden->wavebuf[0]));
|
||||||
this->hidden->next_buffer = (this->hidden->next_buffer + 1) % NUM_BUFFERS;
|
this->hidden->next_buffer = (this->hidden->next_buffer + 1) % NUM_BUFFERS;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
static void
|
||||||
WINWAVEOUT_WaitDone(_THIS)
|
WINMM_WaitDone(_THIS)
|
||||||
{
|
{
|
||||||
int i, left;
|
int i, left;
|
||||||
|
|
||||||
|
@ -130,8 +219,8 @@ WINWAVEOUT_WaitDone(_THIS)
|
||||||
} while (left > 0);
|
} while (left > 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
static void
|
||||||
WINWAVEOUT_CloseDevice(_THIS)
|
WINMM_CloseDevice(_THIS)
|
||||||
{
|
{
|
||||||
/* Close up audio */
|
/* Close up audio */
|
||||||
if (this->hidden != NULL) {
|
if (this->hidden != NULL) {
|
||||||
|
@ -146,15 +235,20 @@ WINWAVEOUT_CloseDevice(_THIS)
|
||||||
this->hidden->audio_sem = 0;
|
this->hidden->audio_sem = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this->hidden->sound) {
|
if (this->hidden->hin) {
|
||||||
waveOutClose(this->hidden->sound);
|
waveInClose(this->hidden->hin);
|
||||||
this->hidden->sound = 0;
|
this->hidden->hin = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this->hidden->hout) {
|
||||||
|
waveOutClose(this->hidden->hout);
|
||||||
|
this->hidden->hout = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Clean up mixing buffers */
|
/* Clean up mixing buffers */
|
||||||
for (i = 0; i < NUM_BUFFERS; ++i) {
|
for (i = 0; i < NUM_BUFFERS; ++i) {
|
||||||
if (this->hidden->wavebuf[i].dwUser != 0xFFFF) {
|
if (this->hidden->wavebuf[i].dwUser != 0xFFFF) {
|
||||||
waveOutUnprepareHeader(this->hidden->sound,
|
waveOutUnprepareHeader(this->hidden->hout,
|
||||||
&this->hidden->wavebuf[i],
|
&this->hidden->wavebuf[i],
|
||||||
sizeof(this->hidden->wavebuf[i]));
|
sizeof(this->hidden->wavebuf[i]));
|
||||||
this->hidden->wavebuf[i].dwUser = 0xFFFF;
|
this->hidden->wavebuf[i].dwUser = 0xFFFF;
|
||||||
|
@ -172,15 +266,52 @@ WINWAVEOUT_CloseDevice(_THIS)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
static int
|
||||||
WINWAVEOUT_OpenDevice(_THIS, const char *devname, int iscapture)
|
WINMM_OpenDevice(_THIS, const char *devname, int iscapture)
|
||||||
{
|
{
|
||||||
SDL_AudioFormat test_format = SDL_FirstAudioFormat(this->spec.format);
|
SDL_AudioFormat test_format = SDL_FirstAudioFormat(this->spec.format);
|
||||||
int valid_datatype = 0;
|
int valid_datatype = 0;
|
||||||
MMRESULT result;
|
MMRESULT result;
|
||||||
WAVEFORMATEX waveformat;
|
WAVEFORMATEX waveformat;
|
||||||
|
UINT_PTR devId = WAVE_MAPPER; /* WAVE_MAPPER == choose system's default */
|
||||||
|
char *utf8 = NULL;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
|
if (devname != NULL) { /* specific device requested? */
|
||||||
|
if (iscapture) {
|
||||||
|
const int devcount = (int) waveInGetNumDevs();
|
||||||
|
WAVEINCAPS caps;
|
||||||
|
for (i = 0; (i < devcount) && (devId == WAVE_MAPPER); i++) {
|
||||||
|
result = waveInGetDevCaps(i, &caps, sizeof (caps));
|
||||||
|
if (result != MMSYSERR_NOERROR)
|
||||||
|
continue;
|
||||||
|
else if ((utf8 = WIN_StringToUTF8(caps.szPname)) == NULL)
|
||||||
|
continue;
|
||||||
|
else if (SDL_strcmp(devname, utf8) == 0)
|
||||||
|
devId = (UINT_PTR) i;
|
||||||
|
SDL_free(utf8);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
const int devcount = (int) waveOutGetNumDevs();
|
||||||
|
WAVEOUTCAPS caps;
|
||||||
|
for (i = 0; (i < devcount) && (devId == WAVE_MAPPER); i++) {
|
||||||
|
result = waveOutGetDevCaps(i, &caps, sizeof (caps));
|
||||||
|
if (result != MMSYSERR_NOERROR)
|
||||||
|
continue;
|
||||||
|
else if ((utf8 = WIN_StringToUTF8(caps.szPname)) == NULL)
|
||||||
|
continue;
|
||||||
|
else if (SDL_strcmp(devname, utf8) == 0)
|
||||||
|
devId = (UINT_PTR) i;
|
||||||
|
SDL_free(utf8);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (devId == WAVE_MAPPER) {
|
||||||
|
SDL_SetError("Requested device not found");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* Initialize all variables that we clean on shutdown */
|
/* Initialize all variables that we clean on shutdown */
|
||||||
this->hidden = (struct SDL_PrivateAudioData *)
|
this->hidden = (struct SDL_PrivateAudioData *)
|
||||||
SDL_malloc((sizeof *this->hidden));
|
SDL_malloc((sizeof *this->hidden));
|
||||||
|
@ -211,7 +342,7 @@ WINWAVEOUT_OpenDevice(_THIS, const char *devname, int iscapture)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!valid_datatype) {
|
if (!valid_datatype) {
|
||||||
WINWAVEOUT_CloseDevice(this);
|
WINMM_CloseDevice(this);
|
||||||
SDL_SetError("Unsupported audio format");
|
SDL_SetError("Unsupported audio format");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -239,11 +370,18 @@ WINWAVEOUT_OpenDevice(_THIS, const char *devname, int iscapture)
|
||||||
SDL_CalculateAudioSpec(&this->spec);
|
SDL_CalculateAudioSpec(&this->spec);
|
||||||
|
|
||||||
/* Open the audio device */
|
/* Open the audio device */
|
||||||
result = waveOutOpen(&this->hidden->sound, WAVE_MAPPER, &waveformat,
|
if (iscapture) {
|
||||||
|
result = waveInOpen(&this->hidden->hin, devId, &waveformat,
|
||||||
|
(DWORD_PTR) CaptureSound, (DWORD_PTR) this,
|
||||||
|
CALLBACK_FUNCTION);
|
||||||
|
} else {
|
||||||
|
result = waveOutOpen(&this->hidden->hout, devId, &waveformat,
|
||||||
(DWORD_PTR) FillSound, (DWORD_PTR) this,
|
(DWORD_PTR) FillSound, (DWORD_PTR) this,
|
||||||
CALLBACK_FUNCTION);
|
CALLBACK_FUNCTION);
|
||||||
|
}
|
||||||
|
|
||||||
if (result != MMSYSERR_NOERROR) {
|
if (result != MMSYSERR_NOERROR) {
|
||||||
WINWAVEOUT_CloseDevice(this);
|
WINMM_CloseDevice(this);
|
||||||
SetMMerror("waveOutOpen()", result);
|
SetMMerror("waveOutOpen()", result);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -252,10 +390,10 @@ WINWAVEOUT_OpenDevice(_THIS, const char *devname, int iscapture)
|
||||||
{
|
{
|
||||||
WAVEOUTCAPS caps;
|
WAVEOUTCAPS caps;
|
||||||
|
|
||||||
result = waveOutGetDevCaps((UINT) this->hidden->sound,
|
result = waveOutGetDevCaps((UINT) this->hidden->hout,
|
||||||
&caps, sizeof(caps));
|
&caps, sizeof(caps));
|
||||||
if (result != MMSYSERR_NOERROR) {
|
if (result != MMSYSERR_NOERROR) {
|
||||||
WINWAVEOUT_CloseDevice(this);
|
WINMM_CloseDevice(this);
|
||||||
SetMMerror("waveOutGetDevCaps()", result);
|
SetMMerror("waveOutGetDevCaps()", result);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -271,7 +409,7 @@ WINWAVEOUT_OpenDevice(_THIS, const char *devname, int iscapture)
|
||||||
CreateSemaphore(NULL, NUM_BUFFERS - 1, NUM_BUFFERS, NULL);
|
CreateSemaphore(NULL, NUM_BUFFERS - 1, NUM_BUFFERS, NULL);
|
||||||
#endif
|
#endif
|
||||||
if (this->hidden->audio_sem == NULL) {
|
if (this->hidden->audio_sem == NULL) {
|
||||||
WINWAVEOUT_CloseDevice(this);
|
WINMM_CloseDevice(this);
|
||||||
SDL_SetError("Couldn't create semaphore");
|
SDL_SetError("Couldn't create semaphore");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -280,7 +418,7 @@ WINWAVEOUT_OpenDevice(_THIS, const char *devname, int iscapture)
|
||||||
this->hidden->mixbuf =
|
this->hidden->mixbuf =
|
||||||
(Uint8 *) SDL_malloc(NUM_BUFFERS * this->spec.size);
|
(Uint8 *) SDL_malloc(NUM_BUFFERS * this->spec.size);
|
||||||
if (this->hidden->mixbuf == NULL) {
|
if (this->hidden->mixbuf == NULL) {
|
||||||
WINWAVEOUT_CloseDevice(this);
|
WINMM_CloseDevice(this);
|
||||||
SDL_OutOfMemory();
|
SDL_OutOfMemory();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -291,11 +429,11 @@ WINWAVEOUT_OpenDevice(_THIS, const char *devname, int iscapture)
|
||||||
this->hidden->wavebuf[i].dwFlags = WHDR_DONE;
|
this->hidden->wavebuf[i].dwFlags = WHDR_DONE;
|
||||||
this->hidden->wavebuf[i].lpData =
|
this->hidden->wavebuf[i].lpData =
|
||||||
(LPSTR) & this->hidden->mixbuf[i * this->spec.size];
|
(LPSTR) & this->hidden->mixbuf[i * this->spec.size];
|
||||||
result = waveOutPrepareHeader(this->hidden->sound,
|
result = waveOutPrepareHeader(this->hidden->hout,
|
||||||
&this->hidden->wavebuf[i],
|
&this->hidden->wavebuf[i],
|
||||||
sizeof(this->hidden->wavebuf[i]));
|
sizeof(this->hidden->wavebuf[i]));
|
||||||
if (result != MMSYSERR_NOERROR) {
|
if (result != MMSYSERR_NOERROR) {
|
||||||
WINWAVEOUT_CloseDevice(this);
|
WINMM_CloseDevice(this);
|
||||||
SetMMerror("waveOutPrepareHeader()", result);
|
SetMMerror("waveOutPrepareHeader()", result);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -306,23 +444,23 @@ WINWAVEOUT_OpenDevice(_THIS, const char *devname, int iscapture)
|
||||||
|
|
||||||
|
|
||||||
static int
|
static int
|
||||||
WINWAVEOUT_Init(SDL_AudioDriverImpl * impl)
|
WINMM_Init(SDL_AudioDriverImpl * impl)
|
||||||
{
|
{
|
||||||
/* Set the function pointers */
|
/* Set the function pointers */
|
||||||
impl->OpenDevice = WINWAVEOUT_OpenDevice;
|
impl->DetectDevices = WINMM_DetectDevices;
|
||||||
impl->ThreadInit = WINWAVEOUT_ThreadInit;
|
impl->GetDeviceName = WINMM_GetDeviceName;
|
||||||
impl->PlayDevice = WINWAVEOUT_PlayDevice;
|
impl->OpenDevice = WINMM_OpenDevice;
|
||||||
impl->WaitDevice = WINWAVEOUT_WaitDevice;
|
impl->PlayDevice = WINMM_PlayDevice;
|
||||||
impl->WaitDone = WINWAVEOUT_WaitDone;
|
impl->WaitDevice = WINMM_WaitDevice;
|
||||||
impl->GetDeviceBuf = WINWAVEOUT_GetDeviceBuf;
|
impl->WaitDone = WINMM_WaitDone;
|
||||||
impl->CloseDevice = WINWAVEOUT_CloseDevice;
|
impl->GetDeviceBuf = WINMM_GetDeviceBuf;
|
||||||
impl->OnlyHasDefaultOutputDevice = 1; /* !!! FIXME: Is this true? */
|
impl->CloseDevice = WINMM_CloseDevice;
|
||||||
|
|
||||||
return 1; /* this audio target is available. */
|
return 1; /* this audio target is available. */
|
||||||
}
|
}
|
||||||
|
|
||||||
AudioBootStrap WINWAVEOUT_bootstrap = {
|
AudioBootStrap WINMM_bootstrap = {
|
||||||
"waveout", WINDOWS_OS_NAME " WaveOut", WINWAVEOUT_Init, 0
|
"winmm", "Windows Waveform Audio", WINMM_Init, 0
|
||||||
};
|
};
|
||||||
|
|
||||||
/* vi: set ts=4 sw=4 expandtab: */
|
/* vi: set ts=4 sw=4 expandtab: */
|
|
@ -20,8 +20,8 @@
|
||||||
*/
|
*/
|
||||||
#include "SDL_config.h"
|
#include "SDL_config.h"
|
||||||
|
|
||||||
#ifndef _SDL_dibaudio_h
|
#ifndef _SDL_winmm_h
|
||||||
#define _SDL_dibaudio_h
|
#define _SDL_winmm_h
|
||||||
|
|
||||||
#include "../SDL_sysaudio.h"
|
#include "../SDL_sysaudio.h"
|
||||||
|
|
||||||
|
@ -32,13 +32,14 @@
|
||||||
|
|
||||||
struct SDL_PrivateAudioData
|
struct SDL_PrivateAudioData
|
||||||
{
|
{
|
||||||
HWAVEOUT sound;
|
HWAVEOUT hout;
|
||||||
|
HWAVEIN hin;
|
||||||
HANDLE audio_sem;
|
HANDLE audio_sem;
|
||||||
Uint8 *mixbuf; /* The raw allocated mixing buffer */
|
Uint8 *mixbuf; /* The raw allocated mixing buffer */
|
||||||
WAVEHDR wavebuf[NUM_BUFFERS]; /* Wave audio fragments */
|
WAVEHDR wavebuf[NUM_BUFFERS]; /* Wave audio fragments */
|
||||||
int next_buffer;
|
int next_buffer;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* _SDL_dibaudio_h */
|
#endif /* _SDL_winmm_h */
|
||||||
|
|
||||||
/* vi: set ts=4 sw=4 expandtab: */
|
/* vi: set ts=4 sw=4 expandtab: */
|
Loading…
Add table
Add a link
Reference in a new issue