AuroraOpenALSoft/Alc/winmm.c

799 lines
23 KiB
C
Raw Normal View History

2007-11-14 02:02:18 +00:00
/**
* OpenAL cross platform audio library
* Copyright (C) 1999-2007 by authors.
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* 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
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
* Or go to http://www.gnu.org/copyleft/lgpl.html
*/
2008-01-16 22:09:04 +00:00
#include "config.h"
#define _WIN32_WINNT 0x0500
2007-11-14 02:02:18 +00:00
#include <stdlib.h>
#include <stdio.h>
#include <memory.h>
#include <windows.h>
#include <mmsystem.h>
#include "alMain.h"
#include "AL/al.h"
#include "AL/alc.h"
typedef struct {
// MMSYSTEM Device
volatile ALboolean bWaveShutdown;
HANDLE hWaveHdrEvent;
HANDLE hWaveThreadEvent;
HANDLE hWaveThread;
DWORD ulWaveThreadID;
LONG lWaveBuffersCommitted;
WAVEHDR WaveBuffer[4];
union {
HWAVEIN In;
HWAVEOUT Out;
} hWaveHandle;
ALsizei Frequency;
RingBuffer *pRing;
2007-11-14 02:02:18 +00:00
} WinMMData;
static const ALCchar woDefault[] = "WaveOut Default";
static ALCchar **PlaybackDeviceList;
static ALuint NumPlaybackDevices;
static ALCchar **CaptureDeviceList;
static ALuint NumCaptureDevices;
2007-11-14 02:02:18 +00:00
static void ProbePlaybackDevices(void)
{
ALuint i;
for(i = 0;i < NumPlaybackDevices;i++)
free(PlaybackDeviceList[i]);
NumPlaybackDevices = waveOutGetNumDevs();
PlaybackDeviceList = realloc(PlaybackDeviceList, sizeof(ALCchar*) * NumPlaybackDevices);
for(i = 0;i < NumPlaybackDevices;i++)
{
WAVEOUTCAPS WaveCaps;
PlaybackDeviceList[i] = NULL;
if(waveOutGetDevCaps(i, &WaveCaps, sizeof(WaveCaps)) == MMSYSERR_NOERROR)
{
char name[1024];
ALuint count, j;
count = 0;
do {
if(count == 0)
snprintf(name, sizeof(name), "%s via WaveOut", WaveCaps.szPname);
else
snprintf(name, sizeof(name), "%s #%d via WaveOut", WaveCaps.szPname, count+1);
count++;
for(j = 0;j < i;j++)
{
if(strcmp(name, PlaybackDeviceList[j]) == 0)
break;
}
} while(j != i);
PlaybackDeviceList[i] = strdup(name);
}
}
}
static void ProbeCaptureDevices(void)
{
ALuint i;
for(i = 0;i < NumCaptureDevices;i++)
free(CaptureDeviceList[i]);
NumCaptureDevices = waveInGetNumDevs();
CaptureDeviceList = realloc(CaptureDeviceList, sizeof(ALCchar*) * NumCaptureDevices);
for(i = 0;i < NumCaptureDevices;i++)
{
WAVEINCAPS WaveInCaps;
CaptureDeviceList[i] = NULL;
if(waveInGetDevCaps(i, &WaveInCaps, sizeof(WAVEINCAPS)) == MMSYSERR_NOERROR)
{
char name[1024];
ALuint count, j;
count = 0;
do {
if(count == 0)
snprintf(name, sizeof(name), "%s via WaveIn", WaveInCaps.szPname);
else
snprintf(name, sizeof(name), "%s #%d via WaveIn", WaveInCaps.szPname, count+1);
count++;
for(j = 0;j < i;j++)
{
if(strcmp(name, CaptureDeviceList[j]) == 0)
break;
}
} while(j != i);
CaptureDeviceList[i] = strdup(name);
}
}
}
/*
WaveOutProc
Posts a message to 'PlaybackThreadProc' everytime a WaveOut Buffer is completed and
returns to the application (for more data)
*/
static void CALLBACK WaveOutProc(HWAVEOUT hDevice,UINT uMsg,DWORD_PTR dwInstance,DWORD_PTR dwParam1,DWORD_PTR dwParam2)
{
ALCdevice *pDevice = (ALCdevice*)dwInstance;
WinMMData *pData = pDevice->ExtraData;
(void)hDevice;
(void)dwParam2;
if(uMsg != WOM_DONE)
return;
// Decrement number of buffers in use
InterlockedDecrement(&pData->lWaveBuffersCommitted);
if(pData->bWaveShutdown == AL_FALSE)
{
// Notify Wave Processor Thread that a Wave Header has returned
PostThreadMessage(pData->ulWaveThreadID, uMsg, 0, dwParam1);
}
else
{
if(pData->lWaveBuffersCommitted == 0)
{
// Signal Wave Buffers Returned event
if(pData->hWaveHdrEvent)
SetEvent(pData->hWaveHdrEvent);
// Post 'Quit' Message to WaveOut Processor Thread
PostThreadMessage(pData->ulWaveThreadID, WM_QUIT, 0, 0);
}
}
}
/*
PlaybackThreadProc
Used by "MMSYSTEM" Device. Called when a WaveOut buffer has used up its
audio data.
*/
static DWORD WINAPI PlaybackThreadProc(LPVOID lpParameter)
{
ALCdevice *pDevice = (ALCdevice*)lpParameter;
WinMMData *pData = pDevice->ExtraData;
LPWAVEHDR pWaveHdr;
ALuint FrameSize;
MSG msg;
FrameSize = FrameSizeFromDevFmt(pDevice->FmtChans, pDevice->FmtType);
while(GetMessage(&msg, NULL, 0, 0))
{
if(msg.message != WOM_DONE || pData->bWaveShutdown)
continue;
pWaveHdr = ((LPWAVEHDR)msg.lParam);
aluMixData(pDevice, pWaveHdr->lpData, pWaveHdr->dwBufferLength/FrameSize);
// Send buffer back to play more data
waveOutWrite(pData->hWaveHandle.Out, pWaveHdr, sizeof(WAVEHDR));
InterlockedIncrement(&pData->lWaveBuffersCommitted);
}
// Signal Wave Thread completed event
if(pData->hWaveThreadEvent)
SetEvent(pData->hWaveThreadEvent);
ExitThread(0);
return 0;
}
2007-11-14 02:02:18 +00:00
/*
WaveInProc
Posts a message to 'CaptureThreadProc' everytime a WaveIn Buffer is completed and
returns to the application (with more data)
*/
static void CALLBACK WaveInProc(HWAVEIN hDevice,UINT uMsg,DWORD_PTR dwInstance,DWORD_PTR dwParam1,DWORD_PTR dwParam2)
{
ALCdevice *pDevice = (ALCdevice*)dwInstance;
2007-11-14 02:02:18 +00:00
WinMMData *pData = pDevice->ExtraData;
(void)hDevice;
(void)dwParam2;
if(uMsg != WIM_DATA)
return;
2007-11-14 02:02:18 +00:00
// Decrement number of buffers in use
InterlockedDecrement(&pData->lWaveBuffersCommitted);
if(pData->bWaveShutdown == AL_FALSE)
{
// Notify Wave Processor Thread that a Wave Header has returned
PostThreadMessage(pData->ulWaveThreadID,uMsg,0,dwParam1);
}
else
{
if(pData->lWaveBuffersCommitted == 0)
2007-11-14 02:02:18 +00:00
{
// Signal Wave Buffers Returned event
if(pData->hWaveHdrEvent)
SetEvent(pData->hWaveHdrEvent);
2007-11-14 02:02:18 +00:00
// Post 'Quit' Message to WaveIn Processor Thread
PostThreadMessage(pData->ulWaveThreadID,WM_QUIT,0,0);
2007-11-14 02:02:18 +00:00
}
}
}
/*
CaptureThreadProc
Used by "MMSYSTEM" Device. Called when a WaveIn buffer had been filled with new
audio data.
*/
static DWORD WINAPI CaptureThreadProc(LPVOID lpParameter)
2007-11-14 02:02:18 +00:00
{
ALCdevice *pDevice = (ALCdevice*)lpParameter;
WinMMData *pData = pDevice->ExtraData;
LPWAVEHDR pWaveHdr;
ALuint FrameSize;
2007-11-14 02:02:18 +00:00
MSG msg;
FrameSize = FrameSizeFromDevFmt(pDevice->FmtChans, pDevice->FmtType);
2007-11-14 02:02:18 +00:00
while(GetMessage(&msg, NULL, 0, 0))
{
if(msg.message != WIM_DATA || pData->bWaveShutdown)
continue;
2007-11-14 02:02:18 +00:00
pWaveHdr = ((LPWAVEHDR)msg.lParam);
2007-11-14 02:02:18 +00:00
WriteRingBuffer(pData->pRing, (ALubyte*)pWaveHdr->lpData,
pWaveHdr->dwBytesRecorded/FrameSize);
2007-11-14 02:02:18 +00:00
// Send buffer back to capture more data
waveInAddBuffer(pData->hWaveHandle.In,pWaveHdr,sizeof(WAVEHDR));
InterlockedIncrement(&pData->lWaveBuffersCommitted);
2007-11-14 02:02:18 +00:00
}
// Signal Wave Thread completed event
if(pData->hWaveThreadEvent)
SetEvent(pData->hWaveThreadEvent);
2007-11-14 02:02:18 +00:00
ExitThread(0);
return 0;
}
static ALCboolean WinMMOpenPlayback(ALCdevice *pDevice, const ALCchar *deviceName)
2007-11-14 02:02:18 +00:00
{
WAVEFORMATEX wfexFormat;
WinMMData *pData = NULL;
2011-02-08 18:33:18 +00:00
UINT lDeviceID = 0;
MMRESULT res;
ALuint i = 0;
// Find the Device ID matching the deviceName if valid
if(!deviceName || strcmp(deviceName, woDefault) == 0)
lDeviceID = WAVE_MAPPER;
else
{
if(!PlaybackDeviceList)
ProbePlaybackDevices();
for(i = 0;i < NumPlaybackDevices;i++)
{
if(PlaybackDeviceList[i] &&
strcmp(deviceName, PlaybackDeviceList[i]) == 0)
{
lDeviceID = i;
break;
}
}
if(i == NumPlaybackDevices)
return ALC_FALSE;
}
pData = calloc(1, sizeof(*pData));
if(!pData)
{
alcSetError(pDevice, ALC_OUT_OF_MEMORY);
return ALC_FALSE;
}
pDevice->ExtraData = pData;
if(pDevice->FmtChans != DevFmtMono)
{
if((pDevice->Flags&DEVICE_CHANNELS_REQUEST) &&
pDevice->FmtChans != DevFmtStereo)
{
AL_PRINT("Failed to set requested channel config %#x, got stereo instead\n", pDevice->FmtChans);
pDevice->Flags &= ~DEVICE_CHANNELS_REQUEST;
}
pDevice->FmtChans = DevFmtStereo;
}
switch(pDevice->FmtType)
{
case DevFmtByte:
pDevice->FmtType = DevFmtUByte;
break;
case DevFmtUShort:
case DevFmtFloat:
pDevice->FmtType = DevFmtShort;
break;
case DevFmtUByte:
case DevFmtShort:
break;
}
memset(&wfexFormat, 0, sizeof(WAVEFORMATEX));
wfexFormat.wFormatTag = WAVE_FORMAT_PCM;
wfexFormat.nChannels = ChannelsFromDevFmt(pDevice->FmtChans);
wfexFormat.wBitsPerSample = BytesFromDevFmt(pDevice->FmtType) * 8;
wfexFormat.nBlockAlign = wfexFormat.wBitsPerSample *
wfexFormat.nChannels / 8;
wfexFormat.nSamplesPerSec = pDevice->Frequency;
wfexFormat.nAvgBytesPerSec = wfexFormat.nSamplesPerSec *
wfexFormat.nBlockAlign;
wfexFormat.cbSize = 0;
if((res=waveOutOpen(&pData->hWaveHandle.Out, lDeviceID, &wfexFormat, (DWORD_PTR)&WaveOutProc, (DWORD_PTR)pDevice, CALLBACK_FUNCTION)) != MMSYSERR_NOERROR)
{
AL_PRINT("waveInOpen failed: %u\n", res);
goto failure;
}
pData->hWaveHdrEvent = CreateEvent(NULL, AL_TRUE, AL_FALSE, "WaveOutAllHeadersReturned");
pData->hWaveThreadEvent = CreateEvent(NULL, AL_TRUE, AL_FALSE, "WaveOutThreadDestroyed");
if(pData->hWaveHdrEvent == NULL || pData->hWaveThreadEvent == NULL)
{
AL_PRINT("CreateEvent failed: %lu\n", GetLastError());
goto failure;
}
pData->Frequency = pDevice->Frequency;
pDevice->szDeviceName = strdup((lDeviceID==WAVE_MAPPER) ? woDefault :
PlaybackDeviceList[lDeviceID]);
return ALC_TRUE;
failure:
if(pData->hWaveThreadEvent)
CloseHandle(pData->hWaveThreadEvent);
if(pData->hWaveHdrEvent)
CloseHandle(pData->hWaveHdrEvent);
if(pData->hWaveHandle.Out)
waveOutClose(pData->hWaveHandle.Out);
free(pData);
pDevice->ExtraData = NULL;
2007-11-14 02:02:18 +00:00
return ALC_FALSE;
}
static void WinMMClosePlayback(ALCdevice *device)
{
WinMMData *pData = (WinMMData*)device->ExtraData;
// Close the Wave device
CloseHandle(pData->hWaveThreadEvent);
pData->hWaveThreadEvent = 0;
CloseHandle(pData->hWaveHdrEvent);
pData->hWaveHdrEvent = 0;
waveInClose(pData->hWaveHandle.In);
pData->hWaveHandle.In = 0;
free(pData);
device->ExtraData = NULL;
2007-11-14 02:02:18 +00:00
}
static ALCboolean WinMMResetPlayback(ALCdevice *device)
{
WinMMData *pData = (WinMMData*)device->ExtraData;
ALbyte *BufferData;
ALint lBufferSize;
ALuint i;
pData->hWaveThread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)PlaybackThreadProc, (LPVOID)device, 0, &pData->ulWaveThreadID);
if(pData->hWaveThread == NULL)
return ALC_FALSE;
device->UpdateSize = (ALuint)((ALuint64)device->UpdateSize *
pData->Frequency / device->Frequency);
2011-05-03 09:29:26 +00:00
if(device->Frequency != streamInfo->sampleRate)
{
if((device->Flags&DEVICE_FREQUENCY_REQUEST))
AL_PRINT("WinMM does not support changing sample rates (wanted %dhz, got %dhz)\n", device->Frequency, pData->Frequency);
device->Flags &= ~DEVICE_FREQUENCY_REQUEST;
device->Frequency = pData->Frequency;
}
pData->lWaveBuffersCommitted = 0;
// Create 4 Buffers
lBufferSize = device->UpdateSize*device->NumUpdates / 4;
lBufferSize *= FrameSizeFromDevFmt(device->FmtChans, device->FmtType);
BufferData = calloc(4, lBufferSize);
for(i = 0;i < 4;i++)
{
memset(&pData->WaveBuffer[i], 0, sizeof(WAVEHDR));
pData->WaveBuffer[i].dwBufferLength = lBufferSize;
pData->WaveBuffer[i].lpData = ((i==0) ? (LPSTR)BufferData :
(pData->WaveBuffer[i-1].lpData +
pData->WaveBuffer[i-1].dwBufferLength));
waveOutPrepareHeader(pData->hWaveHandle.Out, &pData->WaveBuffer[i], sizeof(WAVEHDR));
waveOutWrite(pData->hWaveHandle.Out, &pData->WaveBuffer[i], sizeof(WAVEHDR));
InterlockedIncrement(&pData->lWaveBuffersCommitted);
}
return ALC_TRUE;
}
static void WinMMStopPlayback(ALCdevice *device)
{
WinMMData *pData = (WinMMData*)device->ExtraData;
int i;
if(pData->hWaveThread == NULL)
return;
// Set flag to stop processing headers
pData->bWaveShutdown = AL_TRUE;
// Wait for signal that all Wave Buffers have returned
WaitForSingleObjectEx(pData->hWaveHdrEvent, 5000, FALSE);
// Wait for signal that Wave Thread has been destroyed
WaitForSingleObjectEx(pData->hWaveThreadEvent, 5000, FALSE);
CloseHandle(pData->hWaveThread);
pData->hWaveThread = 0;
pData->bWaveShutdown = AL_FALSE;
// Release the wave buffers
for(i = 0;i < 4;i++)
{
waveOutUnprepareHeader(pData->hWaveHandle.Out, &pData->WaveBuffer[i], sizeof(WAVEHDR));
if(i == 0)
free(pData->WaveBuffer[i].lpData);
pData->WaveBuffer[i].lpData = NULL;
}
}
2009-08-14 02:36:14 +00:00
static ALCboolean WinMMOpenCapture(ALCdevice *pDevice, const ALCchar *deviceName)
2007-11-14 02:02:18 +00:00
{
WAVEFORMATEX wfexCaptureFormat;
DWORD ulCapturedDataSize;
2007-11-14 02:02:18 +00:00
WinMMData *pData = NULL;
2011-02-08 18:33:18 +00:00
UINT lDeviceID = 0;
ALbyte *BufferData;
2007-11-14 02:02:18 +00:00
ALint lBufferSize;
MMRESULT res;
ALuint i;
2007-11-14 02:02:18 +00:00
2010-03-09 14:09:29 +00:00
if(!CaptureDeviceList)
ProbeCaptureDevices();
2010-03-09 14:09:29 +00:00
2007-11-14 02:02:18 +00:00
// Find the Device ID matching the deviceName if valid
if(deviceName)
{
for(i = 0;i < NumCaptureDevices;i++)
{
if(CaptureDeviceList[i] &&
strcmp(deviceName, CaptureDeviceList[i]) == 0)
{
lDeviceID = i;
break;
}
}
}
else
2007-11-14 02:02:18 +00:00
{
for(i = 0;i < NumCaptureDevices;i++)
2007-11-14 02:02:18 +00:00
{
if(CaptureDeviceList[i])
2007-11-14 02:02:18 +00:00
{
lDeviceID = i;
break;
}
}
}
if(i == NumCaptureDevices)
return ALC_FALSE;
2007-11-14 02:02:18 +00:00
pData = calloc(1, sizeof(*pData));
if(!pData)
{
alcSetError(pDevice, ALC_OUT_OF_MEMORY);
2007-11-14 02:02:18 +00:00
return ALC_FALSE;
}
pDevice->ExtraData = pData;
2007-11-14 02:02:18 +00:00
if((pDevice->FmtChans != DevFmtMono && pDevice->FmtChans != DevFmtStereo) ||
(pDevice->FmtType != DevFmtUByte && pDevice->FmtType != DevFmtShort))
{
alcSetError(pDevice, ALC_INVALID_ENUM);
goto failure;
}
2007-11-14 02:02:18 +00:00
memset(&wfexCaptureFormat, 0, sizeof(WAVEFORMATEX));
wfexCaptureFormat.wFormatTag = WAVE_FORMAT_PCM;
wfexCaptureFormat.nChannels = ChannelsFromDevFmt(pDevice->FmtChans);
wfexCaptureFormat.wBitsPerSample = BytesFromDevFmt(pDevice->FmtType) * 8;
2008-02-15 06:05:56 +00:00
wfexCaptureFormat.nBlockAlign = wfexCaptureFormat.wBitsPerSample *
wfexCaptureFormat.nChannels / 8;
2009-08-14 02:36:14 +00:00
wfexCaptureFormat.nSamplesPerSec = pDevice->Frequency;
2007-11-14 02:02:18 +00:00
wfexCaptureFormat.nAvgBytesPerSec = wfexCaptureFormat.nSamplesPerSec *
2008-02-15 06:05:56 +00:00
wfexCaptureFormat.nBlockAlign;
2007-11-14 02:02:18 +00:00
wfexCaptureFormat.cbSize = 0;
if((res=waveInOpen(&pData->hWaveHandle.In, lDeviceID, &wfexCaptureFormat, (DWORD_PTR)&WaveInProc, (DWORD_PTR)pDevice, CALLBACK_FUNCTION)) != MMSYSERR_NOERROR)
{
AL_PRINT("waveInOpen failed: %u\n", res);
2007-11-14 02:02:18 +00:00
goto failure;
}
2007-11-14 02:02:18 +00:00
pData->hWaveHdrEvent = CreateEvent(NULL, AL_TRUE, AL_FALSE, "WaveInAllHeadersReturned");
pData->hWaveThreadEvent = CreateEvent(NULL, AL_TRUE, AL_FALSE, "WaveInThreadDestroyed");
if(pData->hWaveHdrEvent == NULL || pData->hWaveThreadEvent == NULL)
{
AL_PRINT("CreateEvent failed: %lu\n", GetLastError());
2007-11-14 02:02:18 +00:00
goto failure;
}
2007-11-14 02:02:18 +00:00
pData->Frequency = pDevice->Frequency;
2007-11-14 02:02:18 +00:00
// Allocate circular memory buffer for the captured audio
ulCapturedDataSize = pDevice->UpdateSize*pDevice->NumUpdates;
2007-11-14 02:02:18 +00:00
// Make sure circular buffer is at least 100ms in size
if(ulCapturedDataSize < (wfexCaptureFormat.nSamplesPerSec / 10))
ulCapturedDataSize = wfexCaptureFormat.nSamplesPerSec / 10;
pData->pRing = CreateRingBuffer(wfexCaptureFormat.nBlockAlign, ulCapturedDataSize);
if(!pData->pRing)
goto failure;
2007-11-14 02:02:18 +00:00
pData->lWaveBuffersCommitted = 0;
2007-11-14 02:02:18 +00:00
// Create 4 Buffers of 50ms each
lBufferSize = wfexCaptureFormat.nAvgBytesPerSec / 20;
lBufferSize -= (lBufferSize % wfexCaptureFormat.nBlockAlign);
BufferData = calloc(4, lBufferSize);
if(!BufferData)
goto failure;
2010-07-09 00:37:35 +00:00
for(i = 0;i < 4;i++)
2007-11-14 02:02:18 +00:00
{
memset(&pData->WaveBuffer[i], 0, sizeof(WAVEHDR));
pData->WaveBuffer[i].dwBufferLength = lBufferSize;
pData->WaveBuffer[i].lpData = ((i==0) ? (LPSTR)BufferData :
(pData->WaveBuffer[i-1].lpData +
pData->WaveBuffer[i-1].dwBufferLength));
pData->WaveBuffer[i].dwFlags = 0;
pData->WaveBuffer[i].dwLoops = 0;
waveInPrepareHeader(pData->hWaveHandle.In, &pData->WaveBuffer[i], sizeof(WAVEHDR));
waveInAddBuffer(pData->hWaveHandle.In, &pData->WaveBuffer[i], sizeof(WAVEHDR));
InterlockedIncrement(&pData->lWaveBuffersCommitted);
2007-11-14 02:02:18 +00:00
}
pData->hWaveThread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)CaptureThreadProc, (LPVOID)pDevice, 0, &pData->ulWaveThreadID);
if (pData->hWaveThread == NULL)
goto failure;
pDevice->szDeviceName = strdup(CaptureDeviceList[lDeviceID]);
2007-11-14 02:02:18 +00:00
return ALC_TRUE;
failure:
if(pData->hWaveThread)
CloseHandle(pData->hWaveThread);
2010-07-09 00:37:35 +00:00
for(i = 0;i < 4;i++)
{
if(pData->WaveBuffer[i].lpData)
{
waveInUnprepareHeader(pData->hWaveHandle.In, &pData->WaveBuffer[i], sizeof(WAVEHDR));
if(i == 0)
free(pData->WaveBuffer[i].lpData);
}
}
2010-07-09 00:37:35 +00:00
if(pData->pRing)
DestroyRingBuffer(pData->pRing);
if(pData->hWaveThreadEvent)
CloseHandle(pData->hWaveThreadEvent);
if(pData->hWaveHdrEvent)
CloseHandle(pData->hWaveHdrEvent);
2010-07-09 00:37:35 +00:00
if(pData->hWaveHandle.In)
waveInClose(pData->hWaveHandle.In);
2007-11-14 02:02:18 +00:00
free(pData);
pDevice->ExtraData = NULL;
2007-11-14 02:02:18 +00:00
return ALC_FALSE;
}
static void WinMMCloseCapture(ALCdevice *pDevice)
{
WinMMData *pData = (WinMMData*)pDevice->ExtraData;
int i;
// Call waveOutReset to shutdown wave device
pData->bWaveShutdown = AL_TRUE;
waveInReset(pData->hWaveHandle.In);
2007-11-14 02:02:18 +00:00
// Wait for signal that all Wave Buffers have returned
WaitForSingleObjectEx(pData->hWaveHdrEvent, 5000, FALSE);
2007-11-14 02:02:18 +00:00
// Wait for signal that Wave Thread has been destroyed
WaitForSingleObjectEx(pData->hWaveThreadEvent, 5000, FALSE);
2007-11-14 02:02:18 +00:00
CloseHandle(pData->hWaveThread);
pData->hWaveThread = 0;
2010-07-09 00:37:35 +00:00
2007-11-14 02:02:18 +00:00
// Release the wave buffers
2010-07-09 00:37:35 +00:00
for(i = 0;i < 4;i++)
2007-11-14 02:02:18 +00:00
{
waveInUnprepareHeader(pData->hWaveHandle.In, &pData->WaveBuffer[i], sizeof(WAVEHDR));
if(i == 0)
free(pData->WaveBuffer[i].lpData);
pData->WaveBuffer[i].lpData = NULL;
2007-11-14 02:02:18 +00:00
}
2010-07-09 00:37:35 +00:00
DestroyRingBuffer(pData->pRing);
pData->pRing = NULL;
2007-11-14 02:02:18 +00:00
2010-07-09 00:37:35 +00:00
// Close the Wave device
CloseHandle(pData->hWaveThreadEvent);
pData->hWaveThreadEvent = 0;
2007-11-14 02:02:18 +00:00
CloseHandle(pData->hWaveHdrEvent);
pData->hWaveHdrEvent = 0;
2007-11-14 02:02:18 +00:00
waveInClose(pData->hWaveHandle.In);
pData->hWaveHandle.In = 0;
2007-11-14 02:02:18 +00:00
free(pData);
pDevice->ExtraData = NULL;
}
static void WinMMStartCapture(ALCdevice *pDevice)
{
WinMMData *pData = (WinMMData*)pDevice->ExtraData;
waveInStart(pData->hWaveHandle.In);
2007-11-14 02:02:18 +00:00
}
static void WinMMStopCapture(ALCdevice *pDevice)
{
WinMMData *pData = (WinMMData*)pDevice->ExtraData;
waveInStop(pData->hWaveHandle.In);
2007-11-14 02:02:18 +00:00
}
static ALCuint WinMMAvailableSamples(ALCdevice *pDevice)
2007-11-14 02:02:18 +00:00
{
WinMMData *pData = (WinMMData*)pDevice->ExtraData;
return RingBufferSize(pData->pRing);
2007-11-14 02:02:18 +00:00
}
static void WinMMCaptureSamples(ALCdevice *pDevice, ALCvoid *pBuffer, ALCuint lSamples)
2007-11-14 02:02:18 +00:00
{
WinMMData *pData = (WinMMData*)pDevice->ExtraData;
if(WinMMAvailableSamples(pDevice) >= lSamples)
ReadRingBuffer(pData->pRing, pBuffer, lSamples);
else
alcSetError(pDevice, ALC_INVALID_VALUE);
2007-11-14 02:02:18 +00:00
}
static BackendFuncs WinMMFuncs = {
2007-11-14 02:02:18 +00:00
WinMMOpenPlayback,
WinMMClosePlayback,
WinMMResetPlayback,
WinMMStopPlayback,
2007-11-14 02:02:18 +00:00
WinMMOpenCapture,
WinMMCloseCapture,
WinMMStartCapture,
WinMMStopCapture,
WinMMCaptureSamples,
2010-11-21 14:32:59 +00:00
WinMMAvailableSamples
2007-11-14 02:02:18 +00:00
};
void alcWinMMInit(BackendFuncs *FuncList)
{
*FuncList = WinMMFuncs;
}
void alcWinMMDeinit()
2007-11-14 02:02:18 +00:00
{
ALuint lLoop;
2007-11-14 02:02:18 +00:00
for(lLoop = 0;lLoop < NumPlaybackDevices;lLoop++)
free(PlaybackDeviceList[lLoop]);
free(PlaybackDeviceList);
PlaybackDeviceList = NULL;
NumPlaybackDevices = 0;
for(lLoop = 0; lLoop < NumCaptureDevices; lLoop++)
free(CaptureDeviceList[lLoop]);
free(CaptureDeviceList);
CaptureDeviceList = NULL;
NumCaptureDevices = 0;
}
2009-08-28 13:33:59 +00:00
void alcWinMMProbe(int type)
{
ALuint i;
if(type == DEVICE_PROBE)
{
ProbePlaybackDevices();
if(NumPlaybackDevices > 0)
AppendDeviceList(woDefault);
}
else if(type == ALL_DEVICE_PROBE)
{
ProbePlaybackDevices();
if(NumPlaybackDevices > 0)
AppendAllDeviceList(woDefault);
for(i = 0;i < NumPlaybackDevices;i++)
{
if(PlaybackDeviceList[i])
AppendAllDeviceList(PlaybackDeviceList[i]);
}
}
else if(type == CAPTURE_DEVICE_PROBE)
2007-11-14 02:02:18 +00:00
{
ProbeCaptureDevices();
for(i = 0;i < NumCaptureDevices;i++)
{
if(CaptureDeviceList[i])
AppendCaptureDeviceList(CaptureDeviceList[i]);
}
2007-11-14 02:02:18 +00:00
}
}