2009-10-10 01:13:41 +04:00
|
|
|
/* public domain */
|
|
|
|
|
|
|
|
#include "qemu-common.h"
|
2009-10-10 16:57:52 +04:00
|
|
|
#include "sysemu.h"
|
2009-10-10 01:13:41 +04:00
|
|
|
#include "audio.h"
|
|
|
|
|
|
|
|
#define AUDIO_CAP "winwave"
|
|
|
|
#include "audio_int.h"
|
|
|
|
|
|
|
|
#include <windows.h>
|
|
|
|
#include <mmsystem.h>
|
|
|
|
|
|
|
|
#include "audio_win_int.h"
|
|
|
|
|
|
|
|
static struct {
|
|
|
|
int dac_headers;
|
|
|
|
int dac_samples;
|
2009-10-15 10:43:45 +04:00
|
|
|
int adc_headers;
|
|
|
|
int adc_samples;
|
2009-10-10 01:13:41 +04:00
|
|
|
} conf = {
|
|
|
|
.dac_headers = 4,
|
2009-10-15 10:43:45 +04:00
|
|
|
.dac_samples = 1024,
|
|
|
|
.adc_headers = 4,
|
|
|
|
.adc_samples = 1024
|
2009-10-10 01:13:41 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
HWVoiceOut hw;
|
|
|
|
HWAVEOUT hwo;
|
|
|
|
WAVEHDR *hdrs;
|
2009-10-10 16:57:52 +04:00
|
|
|
HANDLE event;
|
2009-10-10 01:13:41 +04:00
|
|
|
void *pcm_buf;
|
|
|
|
int avail;
|
|
|
|
int pending;
|
|
|
|
int curhdr;
|
2009-10-11 06:52:45 +04:00
|
|
|
int paused;
|
2009-10-10 01:13:41 +04:00
|
|
|
CRITICAL_SECTION crit_sect;
|
|
|
|
} WaveVoiceOut;
|
|
|
|
|
2009-10-15 10:43:45 +04:00
|
|
|
typedef struct {
|
|
|
|
HWVoiceIn hw;
|
|
|
|
HWAVEIN hwi;
|
|
|
|
WAVEHDR *hdrs;
|
|
|
|
HANDLE event;
|
|
|
|
void *pcm_buf;
|
|
|
|
int curhdr;
|
|
|
|
int paused;
|
|
|
|
int rpos;
|
|
|
|
int avail;
|
|
|
|
CRITICAL_SECTION crit_sect;
|
|
|
|
} WaveVoiceIn;
|
|
|
|
|
2009-10-10 01:13:41 +04:00
|
|
|
static void winwave_log_mmresult (MMRESULT mr)
|
|
|
|
{
|
|
|
|
const char *str = "BUG";
|
|
|
|
|
|
|
|
switch (mr) {
|
|
|
|
case MMSYSERR_NOERROR:
|
|
|
|
str = "Success";
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MMSYSERR_INVALHANDLE:
|
|
|
|
str = "Specified device handle is invalid";
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MMSYSERR_BADDEVICEID:
|
|
|
|
str = "Specified device id is out of range";
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MMSYSERR_NODRIVER:
|
|
|
|
str = "No device driver is present";
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MMSYSERR_NOMEM:
|
|
|
|
str = "Unable to allocate or locl memory";
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WAVERR_SYNC:
|
|
|
|
str = "Device is synchronous but waveOutOpen was called "
|
|
|
|
"without using the WINWAVE_ALLOWSYNC flag";
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WAVERR_UNPREPARED:
|
|
|
|
str = "The data block pointed to by the pwh parameter "
|
|
|
|
"hasn't been prepared";
|
|
|
|
break;
|
|
|
|
|
2009-10-15 02:11:25 +04:00
|
|
|
case WAVERR_STILLPLAYING:
|
|
|
|
str = "There are still buffers in the queue";
|
|
|
|
break;
|
|
|
|
|
2009-10-10 01:13:41 +04:00
|
|
|
default:
|
2009-10-15 10:43:45 +04:00
|
|
|
dolog ("Reason: Unknown (MMRESULT %#x)\n", mr);
|
2009-10-10 01:13:41 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-10-15 10:43:45 +04:00
|
|
|
dolog ("Reason: %s\n", str);
|
2009-10-10 01:13:41 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void GCC_FMT_ATTR (2, 3) winwave_logerr (
|
|
|
|
MMRESULT mr,
|
|
|
|
const char *fmt,
|
|
|
|
...
|
|
|
|
)
|
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
|
|
|
|
va_start (ap, fmt);
|
|
|
|
AUD_vlog (AUDIO_CAP, fmt, ap);
|
|
|
|
va_end (ap);
|
|
|
|
|
2009-10-15 02:15:42 +04:00
|
|
|
AUD_log (NULL, " failed\n");
|
2009-10-10 01:13:41 +04:00
|
|
|
winwave_log_mmresult (mr);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void winwave_anal_close_out (WaveVoiceOut *wave)
|
|
|
|
{
|
|
|
|
MMRESULT mr;
|
|
|
|
|
|
|
|
mr = waveOutClose (wave->hwo);
|
|
|
|
if (mr != MMSYSERR_NOERROR) {
|
2009-10-15 02:15:42 +04:00
|
|
|
winwave_logerr (mr, "waveOutClose");
|
2009-10-10 01:13:41 +04:00
|
|
|
}
|
|
|
|
wave->hwo = NULL;
|
|
|
|
}
|
|
|
|
|
2009-10-15 10:43:45 +04:00
|
|
|
static void CALLBACK winwave_callback_out (
|
2009-10-10 01:13:41 +04:00
|
|
|
HWAVEOUT hwo,
|
|
|
|
UINT msg,
|
|
|
|
DWORD_PTR dwInstance,
|
|
|
|
DWORD_PTR dwParam1,
|
|
|
|
DWORD_PTR dwParam2
|
|
|
|
)
|
|
|
|
{
|
|
|
|
WaveVoiceOut *wave = (WaveVoiceOut *) dwInstance;
|
|
|
|
|
|
|
|
switch (msg) {
|
|
|
|
case WOM_DONE:
|
|
|
|
{
|
|
|
|
WAVEHDR *h = (WAVEHDR *) dwParam1;
|
|
|
|
if (!h->dwUser) {
|
|
|
|
h->dwUser = 1;
|
|
|
|
EnterCriticalSection (&wave->crit_sect);
|
|
|
|
{
|
|
|
|
wave->avail += conf.dac_samples;
|
|
|
|
}
|
|
|
|
LeaveCriticalSection (&wave->crit_sect);
|
2009-10-10 16:57:52 +04:00
|
|
|
if (wave->hw.poll_mode) {
|
|
|
|
if (!SetEvent (wave->event)) {
|
2009-10-15 10:43:45 +04:00
|
|
|
dolog ("DAC SetEvent failed %lx\n", GetLastError ());
|
2009-10-10 16:57:52 +04:00
|
|
|
}
|
|
|
|
}
|
2009-10-10 01:13:41 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WOM_CLOSE:
|
|
|
|
case WOM_OPEN:
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2009-10-15 10:43:45 +04:00
|
|
|
dolog ("unknown wave out callback msg %x\n", msg);
|
2009-10-10 01:13:41 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int winwave_init_out (HWVoiceOut *hw, struct audsettings *as)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
int err;
|
|
|
|
MMRESULT mr;
|
|
|
|
WAVEFORMATEX wfx;
|
|
|
|
WaveVoiceOut *wave;
|
|
|
|
|
|
|
|
wave = (WaveVoiceOut *) hw;
|
|
|
|
|
|
|
|
InitializeCriticalSection (&wave->crit_sect);
|
|
|
|
|
2009-10-15 10:43:45 +04:00
|
|
|
err = waveformat_from_audio_settings (&wfx, as);
|
2009-10-10 01:13:41 +04:00
|
|
|
if (err) {
|
|
|
|
goto err0;
|
|
|
|
}
|
|
|
|
|
|
|
|
mr = waveOutOpen (&wave->hwo, WAVE_MAPPER, &wfx,
|
2009-10-15 10:43:45 +04:00
|
|
|
(DWORD_PTR) winwave_callback_out,
|
2009-10-10 01:13:41 +04:00
|
|
|
(DWORD_PTR) wave, CALLBACK_FUNCTION);
|
|
|
|
if (mr != MMSYSERR_NOERROR) {
|
2009-10-15 02:15:42 +04:00
|
|
|
winwave_logerr (mr, "waveOutOpen");
|
2009-10-10 01:13:41 +04:00
|
|
|
goto err1;
|
|
|
|
}
|
|
|
|
|
|
|
|
wave->hdrs = audio_calloc (AUDIO_FUNC, conf.dac_headers,
|
|
|
|
sizeof (*wave->hdrs));
|
|
|
|
if (!wave->hdrs) {
|
|
|
|
goto err2;
|
|
|
|
}
|
|
|
|
|
|
|
|
audio_pcm_init_info (&hw->info, as);
|
|
|
|
hw->samples = conf.dac_samples * conf.dac_headers;
|
|
|
|
wave->avail = hw->samples;
|
|
|
|
|
|
|
|
wave->pcm_buf = audio_calloc (AUDIO_FUNC, conf.dac_samples,
|
|
|
|
conf.dac_headers << hw->info.shift);
|
|
|
|
if (!wave->pcm_buf) {
|
|
|
|
goto err3;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < conf.dac_headers; ++i) {
|
|
|
|
WAVEHDR *h = &wave->hdrs[i];
|
|
|
|
|
|
|
|
h->dwUser = 0;
|
|
|
|
h->dwBufferLength = conf.dac_samples << hw->info.shift;
|
|
|
|
h->lpData = advance (wave->pcm_buf, i * h->dwBufferLength);
|
|
|
|
h->dwFlags = 0;
|
|
|
|
|
|
|
|
mr = waveOutPrepareHeader (wave->hwo, h, sizeof (*h));
|
|
|
|
if (mr != MMSYSERR_NOERROR) {
|
2009-10-15 10:43:45 +04:00
|
|
|
winwave_logerr (mr, "waveOutPrepareHeader(%d)", i);
|
2009-10-10 01:13:41 +04:00
|
|
|
goto err4;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
err4:
|
|
|
|
qemu_free (wave->pcm_buf);
|
|
|
|
err3:
|
|
|
|
qemu_free (wave->hdrs);
|
|
|
|
err2:
|
|
|
|
winwave_anal_close_out (wave);
|
|
|
|
err1:
|
|
|
|
err0:
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int winwave_write (SWVoiceOut *sw, void *buf, int len)
|
|
|
|
{
|
|
|
|
return audio_pcm_sw_write (sw, buf, len);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int winwave_run_out (HWVoiceOut *hw, int live)
|
|
|
|
{
|
|
|
|
WaveVoiceOut *wave = (WaveVoiceOut *) hw;
|
|
|
|
int decr;
|
2009-10-10 16:57:52 +04:00
|
|
|
int doreset;
|
2009-10-10 01:13:41 +04:00
|
|
|
|
|
|
|
EnterCriticalSection (&wave->crit_sect);
|
|
|
|
{
|
|
|
|
decr = audio_MIN (live, wave->avail);
|
|
|
|
decr = audio_pcm_hw_clip_out (hw, wave->pcm_buf, decr, wave->pending);
|
|
|
|
wave->pending += decr;
|
|
|
|
wave->avail -= decr;
|
|
|
|
}
|
|
|
|
LeaveCriticalSection (&wave->crit_sect);
|
|
|
|
|
2009-10-10 16:57:52 +04:00
|
|
|
doreset = hw->poll_mode && (wave->pending >= conf.dac_samples);
|
|
|
|
if (doreset && !ResetEvent (wave->event)) {
|
2009-10-15 10:43:45 +04:00
|
|
|
dolog ("DAC ResetEvent failed %lx\n", GetLastError ());
|
2009-10-10 16:57:52 +04:00
|
|
|
}
|
|
|
|
|
2009-10-10 01:13:41 +04:00
|
|
|
while (wave->pending >= conf.dac_samples) {
|
|
|
|
MMRESULT mr;
|
|
|
|
WAVEHDR *h = &wave->hdrs[wave->curhdr];
|
|
|
|
|
|
|
|
h->dwUser = 0;
|
|
|
|
mr = waveOutWrite (wave->hwo, h, sizeof (*h));
|
|
|
|
if (mr != MMSYSERR_NOERROR) {
|
2009-10-15 02:15:42 +04:00
|
|
|
winwave_logerr (mr, "waveOutWrite(%d)", wave->curhdr);
|
2009-10-10 01:13:41 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
wave->pending -= conf.dac_samples;
|
|
|
|
wave->curhdr = (wave->curhdr + 1) % conf.dac_headers;
|
|
|
|
}
|
2009-10-10 16:57:52 +04:00
|
|
|
|
2009-10-10 01:13:41 +04:00
|
|
|
return decr;
|
|
|
|
}
|
|
|
|
|
2009-10-15 10:43:45 +04:00
|
|
|
static void winwave_poll (void *opaque)
|
2009-10-11 05:39:09 +04:00
|
|
|
{
|
|
|
|
(void) opaque;
|
2009-10-15 10:43:45 +04:00
|
|
|
audio_run ("winwave_poll");
|
2009-10-11 05:39:09 +04:00
|
|
|
}
|
|
|
|
|
2009-10-10 01:13:41 +04:00
|
|
|
static void winwave_fini_out (HWVoiceOut *hw)
|
|
|
|
{
|
2009-10-15 02:11:25 +04:00
|
|
|
int i;
|
|
|
|
MMRESULT mr;
|
2009-10-10 01:13:41 +04:00
|
|
|
WaveVoiceOut *wave = (WaveVoiceOut *) hw;
|
|
|
|
|
2009-10-15 02:11:25 +04:00
|
|
|
mr = waveOutReset (wave->hwo);
|
|
|
|
if (mr != MMSYSERR_NOERROR) {
|
2009-10-15 02:15:42 +04:00
|
|
|
winwave_logerr (mr, "waveOutReset");
|
2009-10-15 02:11:25 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < conf.dac_headers; ++i) {
|
|
|
|
mr = waveOutUnprepareHeader (wave->hwo, &wave->hdrs[i],
|
|
|
|
sizeof (wave->hdrs[i]));
|
|
|
|
if (mr != MMSYSERR_NOERROR) {
|
2009-10-15 02:15:42 +04:00
|
|
|
winwave_logerr (mr, "waveOutUnprepareHeader(%d)", i);
|
2009-10-15 02:11:25 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-10-11 06:38:47 +04:00
|
|
|
winwave_anal_close_out (wave);
|
|
|
|
|
2009-10-10 16:57:52 +04:00
|
|
|
if (wave->event) {
|
2009-10-15 10:43:45 +04:00
|
|
|
qemu_del_wait_object (wave->event, winwave_poll, wave);
|
2009-10-10 16:57:52 +04:00
|
|
|
if (!CloseHandle (wave->event)) {
|
2009-10-15 10:43:45 +04:00
|
|
|
dolog ("DAC CloseHandle failed %lx\n", GetLastError ());
|
2009-10-10 16:57:52 +04:00
|
|
|
}
|
|
|
|
wave->event = NULL;
|
|
|
|
}
|
|
|
|
|
2009-10-11 05:39:09 +04:00
|
|
|
qemu_free (wave->pcm_buf);
|
|
|
|
wave->pcm_buf = NULL;
|
|
|
|
|
|
|
|
qemu_free (wave->hdrs);
|
|
|
|
wave->hdrs = NULL;
|
2009-10-10 01:13:41 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static int winwave_ctl_out (HWVoiceOut *hw, int cmd, ...)
|
|
|
|
{
|
2009-10-11 06:52:45 +04:00
|
|
|
MMRESULT mr;
|
2009-10-10 16:57:52 +04:00
|
|
|
WaveVoiceOut *wave = (WaveVoiceOut *) hw;
|
|
|
|
|
2009-10-10 01:13:41 +04:00
|
|
|
switch (cmd) {
|
|
|
|
case VOICE_ENABLE:
|
2009-10-10 16:57:52 +04:00
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
int poll_mode;
|
|
|
|
|
|
|
|
va_start (ap, cmd);
|
|
|
|
poll_mode = va_arg (ap, int);
|
|
|
|
va_end (ap);
|
|
|
|
|
|
|
|
if (poll_mode && !wave->event) {
|
|
|
|
wave->event = CreateEvent (NULL, TRUE, TRUE, NULL);
|
|
|
|
if (!wave->event) {
|
2009-10-15 10:43:45 +04:00
|
|
|
dolog ("DAC CreateEvent: %lx, poll mode will be disabled\n",
|
|
|
|
GetLastError ());
|
2009-10-10 16:57:52 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (wave->event) {
|
|
|
|
int ret;
|
|
|
|
|
2009-10-15 10:43:45 +04:00
|
|
|
ret = qemu_add_wait_object (wave->event, winwave_poll, wave);
|
2009-10-10 16:57:52 +04:00
|
|
|
hw->poll_mode = (ret == 0);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
hw->poll_mode = 0;
|
|
|
|
}
|
2009-10-11 06:52:45 +04:00
|
|
|
if (wave->paused) {
|
|
|
|
mr = waveOutRestart (wave->hwo);
|
|
|
|
if (mr != MMSYSERR_NOERROR) {
|
|
|
|
winwave_logerr (mr, "waveOutRestart");
|
|
|
|
}
|
|
|
|
wave->paused = 0;
|
|
|
|
}
|
2009-10-10 16:57:52 +04:00
|
|
|
}
|
2009-10-10 01:13:41 +04:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
case VOICE_DISABLE:
|
2009-10-11 06:52:45 +04:00
|
|
|
if (!wave->paused) {
|
|
|
|
mr = waveOutPause (wave->hwo);
|
|
|
|
if (mr != MMSYSERR_NOERROR) {
|
|
|
|
winwave_logerr (mr, "waveOutPause");
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
wave->paused = 1;
|
|
|
|
}
|
|
|
|
}
|
2009-10-10 16:57:52 +04:00
|
|
|
if (wave->event) {
|
2009-10-15 10:43:45 +04:00
|
|
|
qemu_del_wait_object (wave->event, winwave_poll, wave);
|
2009-10-10 16:57:52 +04:00
|
|
|
}
|
2009-10-10 01:13:41 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2009-10-15 10:43:45 +04:00
|
|
|
static void winwave_anal_close_in (WaveVoiceIn *wave)
|
|
|
|
{
|
|
|
|
MMRESULT mr;
|
|
|
|
|
|
|
|
mr = waveInClose (wave->hwi);
|
|
|
|
if (mr != MMSYSERR_NOERROR) {
|
|
|
|
winwave_logerr (mr, "waveInClose");
|
|
|
|
}
|
|
|
|
wave->hwi = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void CALLBACK winwave_callback_in (
|
|
|
|
HWAVEIN *hwi,
|
|
|
|
UINT msg,
|
|
|
|
DWORD_PTR dwInstance,
|
|
|
|
DWORD_PTR dwParam1,
|
|
|
|
DWORD_PTR dwParam2
|
|
|
|
)
|
|
|
|
{
|
|
|
|
WaveVoiceIn *wave = (WaveVoiceIn *) dwInstance;
|
|
|
|
|
|
|
|
switch (msg) {
|
|
|
|
case WIM_DATA:
|
|
|
|
{
|
|
|
|
WAVEHDR *h = (WAVEHDR *) dwParam1;
|
|
|
|
if (!h->dwUser) {
|
|
|
|
h->dwUser = 1;
|
|
|
|
EnterCriticalSection (&wave->crit_sect);
|
|
|
|
{
|
|
|
|
wave->avail += conf.adc_samples;
|
|
|
|
}
|
|
|
|
LeaveCriticalSection (&wave->crit_sect);
|
|
|
|
if (wave->hw.poll_mode) {
|
|
|
|
if (!SetEvent (wave->event)) {
|
|
|
|
dolog ("ADC SetEvent failed %lx\n", GetLastError ());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WIM_CLOSE:
|
|
|
|
case WIM_OPEN:
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
dolog ("unknown wave in callback msg %x\n", msg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void winwave_add_buffers (WaveVoiceIn *wave, int samples)
|
|
|
|
{
|
|
|
|
int doreset;
|
|
|
|
|
|
|
|
doreset = wave->hw.poll_mode && (samples >= conf.adc_samples);
|
|
|
|
if (doreset && !ResetEvent (wave->event)) {
|
|
|
|
dolog ("ADC ResetEvent failed %lx\n", GetLastError ());
|
|
|
|
}
|
|
|
|
|
|
|
|
while (samples >= conf.adc_samples) {
|
|
|
|
MMRESULT mr;
|
|
|
|
WAVEHDR *h = &wave->hdrs[wave->curhdr];
|
|
|
|
|
|
|
|
h->dwUser = 0;
|
|
|
|
mr = waveInAddBuffer (wave->hwi, h, sizeof (*h));
|
|
|
|
if (mr != MMSYSERR_NOERROR) {
|
|
|
|
winwave_logerr (mr, "waveInAddBuffer(%d)", wave->curhdr);
|
|
|
|
}
|
|
|
|
wave->curhdr = (wave->curhdr + 1) % conf.adc_headers;
|
|
|
|
samples -= conf.adc_samples;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int winwave_init_in (HWVoiceIn *hw, struct audsettings *as)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
int err;
|
|
|
|
MMRESULT mr;
|
|
|
|
WAVEFORMATEX wfx;
|
|
|
|
WaveVoiceIn *wave;
|
|
|
|
|
|
|
|
wave = (WaveVoiceIn *) hw;
|
|
|
|
|
|
|
|
InitializeCriticalSection (&wave->crit_sect);
|
|
|
|
|
|
|
|
err = waveformat_from_audio_settings (&wfx, as);
|
|
|
|
if (err) {
|
|
|
|
goto err0;
|
|
|
|
}
|
|
|
|
|
|
|
|
mr = waveInOpen (&wave->hwi, WAVE_MAPPER, &wfx,
|
|
|
|
(DWORD_PTR) winwave_callback_in,
|
|
|
|
(DWORD_PTR) wave, CALLBACK_FUNCTION);
|
|
|
|
if (mr != MMSYSERR_NOERROR) {
|
|
|
|
winwave_logerr (mr, "waveInOpen");
|
|
|
|
goto err1;
|
|
|
|
}
|
|
|
|
|
|
|
|
wave->hdrs = audio_calloc (AUDIO_FUNC, conf.dac_headers,
|
|
|
|
sizeof (*wave->hdrs));
|
|
|
|
if (!wave->hdrs) {
|
|
|
|
goto err2;
|
|
|
|
}
|
|
|
|
|
|
|
|
audio_pcm_init_info (&hw->info, as);
|
|
|
|
hw->samples = conf.adc_samples * conf.adc_headers;
|
|
|
|
wave->avail = 0;
|
|
|
|
|
|
|
|
wave->pcm_buf = audio_calloc (AUDIO_FUNC, conf.adc_samples,
|
|
|
|
conf.adc_headers << hw->info.shift);
|
|
|
|
if (!wave->pcm_buf) {
|
|
|
|
goto err3;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < conf.adc_headers; ++i) {
|
|
|
|
WAVEHDR *h = &wave->hdrs[i];
|
|
|
|
|
|
|
|
h->dwUser = 0;
|
|
|
|
h->dwBufferLength = conf.adc_samples << hw->info.shift;
|
|
|
|
h->lpData = advance (wave->pcm_buf, i * h->dwBufferLength);
|
|
|
|
h->dwFlags = 0;
|
|
|
|
|
|
|
|
mr = waveInPrepareHeader (wave->hwi, h, sizeof (*h));
|
|
|
|
if (mr != MMSYSERR_NOERROR) {
|
|
|
|
winwave_logerr (mr, "waveInPrepareHeader(%d)", i);
|
|
|
|
goto err4;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
wave->paused = 1;
|
|
|
|
winwave_add_buffers (wave, hw->samples);
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
err4:
|
|
|
|
qemu_free (wave->pcm_buf);
|
|
|
|
err3:
|
|
|
|
qemu_free (wave->hdrs);
|
|
|
|
err2:
|
|
|
|
winwave_anal_close_in (wave);
|
|
|
|
err1:
|
|
|
|
err0:
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void winwave_fini_in (HWVoiceIn *hw)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
MMRESULT mr;
|
|
|
|
WaveVoiceIn *wave = (WaveVoiceIn *) hw;
|
|
|
|
|
|
|
|
mr = waveInReset (wave->hwi);
|
|
|
|
if (mr != MMSYSERR_NOERROR) {
|
|
|
|
winwave_logerr (mr, "waveInReset");
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < conf.adc_headers; ++i) {
|
|
|
|
mr = waveInUnprepareHeader (wave->hwi, &wave->hdrs[i],
|
|
|
|
sizeof (wave->hdrs[i]));
|
|
|
|
if (mr != MMSYSERR_NOERROR) {
|
|
|
|
winwave_logerr (mr, "waveInUnprepareHeader(%d)", i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
winwave_anal_close_in (wave);
|
|
|
|
|
|
|
|
if (wave->event) {
|
|
|
|
qemu_del_wait_object (wave->event, winwave_poll, wave);
|
|
|
|
if (!CloseHandle (wave->event)) {
|
|
|
|
dolog ("ADC CloseHandle failed %lx\n", GetLastError ());
|
|
|
|
}
|
|
|
|
wave->event = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
qemu_free (wave->pcm_buf);
|
|
|
|
wave->pcm_buf = NULL;
|
|
|
|
|
|
|
|
qemu_free (wave->hdrs);
|
|
|
|
wave->hdrs = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int winwave_run_in (HWVoiceIn *hw)
|
|
|
|
{
|
|
|
|
WaveVoiceIn *wave = (WaveVoiceIn *) hw;
|
|
|
|
int live = audio_pcm_hw_get_live_in (hw);
|
|
|
|
int dead = hw->samples - live;
|
|
|
|
int decr, ret;
|
|
|
|
|
|
|
|
if (!dead) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
EnterCriticalSection (&wave->crit_sect);
|
|
|
|
{
|
|
|
|
decr = audio_MIN (dead, wave->avail);
|
|
|
|
wave->avail -= decr;
|
|
|
|
}
|
|
|
|
LeaveCriticalSection (&wave->crit_sect);
|
|
|
|
|
|
|
|
ret = decr;
|
|
|
|
while (decr) {
|
|
|
|
int left = hw->samples - hw->wpos;
|
|
|
|
int conv = audio_MIN (left, decr);
|
|
|
|
hw->conv (hw->conv_buf + hw->wpos,
|
|
|
|
advance (wave->pcm_buf, wave->rpos << hw->info.shift),
|
2011-01-05 03:05:47 +03:00
|
|
|
conv);
|
2009-10-15 10:43:45 +04:00
|
|
|
|
|
|
|
wave->rpos = (wave->rpos + conv) % hw->samples;
|
|
|
|
hw->wpos = (hw->wpos + conv) % hw->samples;
|
|
|
|
decr -= conv;
|
|
|
|
}
|
|
|
|
|
|
|
|
winwave_add_buffers (wave, ret);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int winwave_read (SWVoiceIn *sw, void *buf, int size)
|
|
|
|
{
|
|
|
|
return audio_pcm_sw_read (sw, buf, size);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int winwave_ctl_in (HWVoiceIn *hw, int cmd, ...)
|
|
|
|
{
|
|
|
|
MMRESULT mr;
|
|
|
|
WaveVoiceIn *wave = (WaveVoiceIn *) hw;
|
|
|
|
|
|
|
|
switch (cmd) {
|
|
|
|
case VOICE_ENABLE:
|
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
int poll_mode;
|
|
|
|
|
|
|
|
va_start (ap, cmd);
|
|
|
|
poll_mode = va_arg (ap, int);
|
|
|
|
va_end (ap);
|
|
|
|
|
|
|
|
if (poll_mode && !wave->event) {
|
|
|
|
wave->event = CreateEvent (NULL, TRUE, TRUE, NULL);
|
|
|
|
if (!wave->event) {
|
|
|
|
dolog ("ADC CreateEvent: %lx, poll mode will be disabled\n",
|
|
|
|
GetLastError ());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (wave->event) {
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = qemu_add_wait_object (wave->event, winwave_poll, wave);
|
|
|
|
hw->poll_mode = (ret == 0);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
hw->poll_mode = 0;
|
|
|
|
}
|
|
|
|
if (wave->paused) {
|
|
|
|
mr = waveInStart (wave->hwi);
|
|
|
|
if (mr != MMSYSERR_NOERROR) {
|
|
|
|
winwave_logerr (mr, "waveInStart");
|
|
|
|
}
|
|
|
|
wave->paused = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
case VOICE_DISABLE:
|
|
|
|
if (!wave->paused) {
|
|
|
|
mr = waveInStop (wave->hwi);
|
|
|
|
if (mr != MMSYSERR_NOERROR) {
|
|
|
|
winwave_logerr (mr, "waveInStop");
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
wave->paused = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (wave->event) {
|
|
|
|
qemu_del_wait_object (wave->event, winwave_poll, wave);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-10-10 01:13:41 +04:00
|
|
|
static void *winwave_audio_init (void)
|
|
|
|
{
|
|
|
|
return &conf;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void winwave_audio_fini (void *opaque)
|
|
|
|
{
|
|
|
|
(void) opaque;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct audio_option winwave_options[] = {
|
|
|
|
{
|
|
|
|
.name = "DAC_HEADERS",
|
|
|
|
.tag = AUD_OPT_INT,
|
|
|
|
.valp = &conf.dac_headers,
|
|
|
|
.descr = "DAC number of headers",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.name = "DAC_SAMPLES",
|
|
|
|
.tag = AUD_OPT_INT,
|
|
|
|
.valp = &conf.dac_samples,
|
|
|
|
.descr = "DAC number of samples per header",
|
|
|
|
},
|
2009-10-15 10:43:45 +04:00
|
|
|
{
|
|
|
|
.name = "ADC_HEADERS",
|
|
|
|
.tag = AUD_OPT_INT,
|
|
|
|
.valp = &conf.adc_headers,
|
|
|
|
.descr = "ADC number of headers",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.name = "ADC_SAMPLES",
|
|
|
|
.tag = AUD_OPT_INT,
|
|
|
|
.valp = &conf.adc_samples,
|
|
|
|
.descr = "ADC number of samples per header",
|
|
|
|
},
|
2009-10-10 01:13:41 +04:00
|
|
|
{ /* End of list */ }
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct audio_pcm_ops winwave_pcm_ops = {
|
|
|
|
.init_out = winwave_init_out,
|
|
|
|
.fini_out = winwave_fini_out,
|
|
|
|
.run_out = winwave_run_out,
|
|
|
|
.write = winwave_write,
|
2009-10-15 10:43:45 +04:00
|
|
|
.ctl_out = winwave_ctl_out,
|
|
|
|
.init_in = winwave_init_in,
|
|
|
|
.fini_in = winwave_fini_in,
|
|
|
|
.run_in = winwave_run_in,
|
|
|
|
.read = winwave_read,
|
|
|
|
.ctl_in = winwave_ctl_in
|
2009-10-10 01:13:41 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
struct audio_driver winwave_audio_driver = {
|
|
|
|
.name = "winwave",
|
|
|
|
.descr = "Windows Waveform Audio http://msdn.microsoft.com",
|
|
|
|
.options = winwave_options,
|
|
|
|
.init = winwave_audio_init,
|
|
|
|
.fini = winwave_audio_fini,
|
|
|
|
.pcm_ops = &winwave_pcm_ops,
|
|
|
|
.can_be_default = 1,
|
|
|
|
.max_voices_out = INT_MAX,
|
2009-10-15 10:43:45 +04:00
|
|
|
.max_voices_in = INT_MAX,
|
2009-10-10 01:13:41 +04:00
|
|
|
.voice_size_out = sizeof (WaveVoiceOut),
|
2009-10-15 10:43:45 +04:00
|
|
|
.voice_size_in = sizeof (WaveVoiceIn)
|
2009-10-10 01:13:41 +04:00
|
|
|
};
|