Files
nt-lite/code/win32/winmm.c
T

129 lines
4.5 KiB
C

// winmm.c - Win32 multimedia: waveform audio, timer
// Stubs only; no audio hardware access at this stage.
#include <stdint.h>
#include <stddef.h>
// ---------------------------------------------------------------------------
// Types
// ---------------------------------------------------------------------------
typedef unsigned int MMRESULT;
typedef void* HWAVEOUT;
#define MMSYSERR_NOERROR 0
#define MMSYSERR_NOTSUPPORTED 8
#define WAVERR_STILLPLAYING 33
// WAVEFORMATEX - standard PCM audio format descriptor.
typedef struct {
unsigned short wFormatTag;
unsigned short nChannels;
unsigned int nSamplesPerSec;
unsigned int nAvgBytesPerSec;
unsigned short nBlockAlign;
unsigned short wBitsPerSample;
unsigned short cbSize;
} WAVEFORMATEX;
// WAVEHDR - buffer header submitted to waveOutWrite.
typedef struct _WAVEHDR {
char* lpData;
unsigned int dwBufferLength;
unsigned int dwBytesRecorded;
uintptr_t dwUser;
unsigned int dwFlags;
unsigned int dwLoops;
struct _WAVEHDR* lpNext;
uintptr_t reserved;
} WAVEHDR;
// MMTIME - used by waveOutGetPosition.
typedef struct {
unsigned int wType;
union {
unsigned int ms;
unsigned int sample;
unsigned int cb;
unsigned int ticks;
} u;
} MMTIME;
// ---------------------------------------------------------------------------
// Timer
// ---------------------------------------------------------------------------
// timeGetTime is the lightweight alternative to GetTickCount; both return
// milliseconds since system start. We forward to the kernel tick counter.
extern uint64_t SysGetTick(void);
__declspec(dllexport) unsigned long timeGetTime(void) {
return (unsigned long)SysGetTick();
}
// ---------------------------------------------------------------------------
// Waveform audio (stubs - no audio hardware at this stage)
// ---------------------------------------------------------------------------
__declspec(dllexport) MMRESULT waveOutOpen(HWAVEOUT* phwo, unsigned int deviceId,
const WAVEFORMATEX* fmt, uintptr_t callback,
uintptr_t callbackInstance, unsigned long flags) {
(void)deviceId; (void)fmt; (void)callback; (void)callbackInstance; (void)flags;
if (phwo) *phwo = (void*)0;
return MMSYSERR_NOTSUPPORTED;
}
__declspec(dllexport) MMRESULT waveOutClose(HWAVEOUT hwo) {
(void)hwo; return MMSYSERR_NOERROR;
}
__declspec(dllexport) MMRESULT waveOutPrepareHeader(HWAVEOUT hwo, WAVEHDR* hdr,
unsigned int size) {
(void)hwo; (void)hdr; (void)size; return MMSYSERR_NOERROR;
}
__declspec(dllexport) MMRESULT waveOutUnprepareHeader(HWAVEOUT hwo, WAVEHDR* hdr,
unsigned int size) {
(void)hwo; (void)hdr; (void)size; return MMSYSERR_NOERROR;
}
__declspec(dllexport) MMRESULT waveOutWrite(HWAVEOUT hwo, WAVEHDR* hdr, unsigned int size) {
(void)hwo; (void)hdr; (void)size; return MMSYSERR_NOTSUPPORTED;
}
__declspec(dllexport) MMRESULT waveOutPause(HWAVEOUT hwo) {
(void)hwo; return MMSYSERR_NOERROR;
}
__declspec(dllexport) MMRESULT waveOutRestart(HWAVEOUT hwo) {
(void)hwo; return MMSYSERR_NOERROR;
}
__declspec(dllexport) MMRESULT waveOutReset(HWAVEOUT hwo) {
(void)hwo; return MMSYSERR_NOERROR;
}
__declspec(dllexport) MMRESULT waveOutSetVolume(HWAVEOUT hwo, unsigned long volume) {
(void)hwo; (void)volume; return MMSYSERR_NOTSUPPORTED;
}
__declspec(dllexport) MMRESULT waveOutGetPosition(HWAVEOUT hwo, MMTIME* mmt,
unsigned int size) {
(void)hwo; (void)size;
if (mmt) { mmt->wType = 0; mmt->u.ms = 0; }
return MMSYSERR_NOERROR;
}
// ---------------------------------------------------------------------------
// Timer resolution control
// No hardware timer reprogramming at this stage; pretend success so callers
// that wrap their audio/game loop in timeBeginPeriod(1) don't bail out.
// ---------------------------------------------------------------------------
__declspec(dllexport) MMRESULT timeBeginPeriod(unsigned int uPeriod) {
(void)uPeriod;
return MMSYSERR_NOERROR;
}
__declspec(dllexport) MMRESULT timeEndPeriod(unsigned int uPeriod) {
(void)uPeriod;
return MMSYSERR_NOERROR;
}