#include <windows.h>
#ifndef False
# define False 0
#endif
#ifndef True
# define True 1
#endif
#ifndef Boolean
# define Boolean unsigned char
#endif
static Boolean bPlaying = False;
static WAVEHDR whdr;
static WAVEFORMATEX wfx = { 1 , 2 , 44100 , 44100 * 4 , 4 , 16 , 0 };
static HWAVEOUT hwo = NULL;
typedef struct {
void *buffer;
int buffer_length; /* In bytes (8 bits). */
} WSObject;
static void CALLBACK WaveOutCB(
HWAVEOUT hwo2,
UINT uMsg, DWORD dwInstance,
DWORD dwParam1,
DWORD dwParam2
);
void WSPlayDSP(WSObject *obj_ptr);
static void CALLBACK WaveOutCB(
HWAVEOUT hwo2,
UINT uMsg, DWORD dwInstance,
DWORD dwParam1,
DWORD dwParam2
)
{
if(uMsg == WOM_DONE)
{
waveOutUnprepareHeader(
hwo, &whdr, sizeof(whdr)
);
waveOutClose(hwo);
hwo = NULL;
bPlaying = True;
}
return;
}
void WSPlayDSP(WSObject *obj_ptr)
{
MMRESULT mmr;
if(bPlaying || (obj_ptr == NULL))
return;
whdr.lpData = (char *)obj_ptr->buffer;
whdr.dwBufferLength = (DWORD)obj_ptr->buffer_length;
whdr.dwBytesRecorded = 0;
whdr.dwUser = (int)NULL;
whdr.dwFlags = WAVE_ALLOWSYNC /*| WAVE_FORMAT_DIRECT*/;
whdr.dwLoops = 0;
whdr.lpNext = NULL;
whdr.reserved = 0;
wfx.wFormatTag = 1;
wfx.nChannels = 2;
wfx.wBitsPerSample = 8;
wfx.nSamplesPerSec = 11025;
wfx.nAvgBytesPerSec = wfx.nSamplesPerSec * wfx.nChannels;
wfx.nBlockAlign = wfx.nChannels * (wfx.wBitsPerSample / 8);
wfx.cbSize = 0; /* Extra bytes after cbSize. */
mmr = waveOutOpen(
&hwo, 0, &wfx,
(DWORD)WaveOutCB, 0, CALLBACK_FUNCTION
);
if(mmr != MMSYSERR_NOERROR)
{
MessageBox(
NULL,
"Error opening wave output device.",
"Error",
MB_OK
);
return;
}
else
{
MessageBox(
NULL,
"Beginning play...",
"Status",
MB_OK
);
}
waveOutReset(&hwo);
waveOutPrepareHeader(hwo, &whdr ,sizeof(whdr));
waveOutWrite(hwo, &whdr, sizeof(whdr));
bPlaying = True;
return;
}
int WINAPI WinMain(
HINSTANCE hInstance, // Instance
HINSTANCE hPrevInstance, // Previous Instance
LPSTR lpCmdLine, // Command Line Parameters
int nCmdShow // Window Show State
)
{
int i;
WSObject *obj_ptr = (WSObject *)malloc(sizeof(WSObject));
obj_ptr->buffer_length = 100000;
obj_ptr->buffer = malloc(obj_ptr->buffer_length);
WSPlayDSP(obj_ptr);
i = 0;
while(bPlaying)
i++;
free(obj_ptr->buffer);
free(obj_ptr);
obj_ptr = NULL;
MessageBox(
NULL,
"Done playing!",
"Status",
MB_OK
);
PostQuitMessage(0);
return(0);
}
Need help with Windows waveOut*() functions
I''ve been trying to write a wraparound of Windows''
waveOut*() sound API functions so that I can port a few
UNIX games to Windows. The problem is that the test
code dosen''t produce any sound output (note that this
is dirived partially on someone else''s code in a prior
thread).
Tara Milana - WP Entertainmenthttp://wolfpack.twu.net/Comp graphics artist and programmer.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement