50 lines
1.1 KiB
C++
50 lines
1.1 KiB
C++
|
#include <stdio.h>
|
||
|
#include <stdlib.h>
|
||
|
#include <malloc.h>
|
||
|
#include <Windows.h>
|
||
|
#include <MMSystem.h>
|
||
|
|
||
|
void fill(char *data)
|
||
|
{
|
||
|
for (int i = 0; i < 4096; i++)
|
||
|
{
|
||
|
data[i] = (i & (i & 512 ? 7 : 3)) << 3;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
static const WAVEFORMATEX fmt = {
|
||
|
WAVE_FORMAT_PCM, 1, 8000, 8000, 1, 8, 0
|
||
|
};
|
||
|
|
||
|
int main(int argc, char *argv[])
|
||
|
{
|
||
|
HWAVEOUT out;
|
||
|
HRESULT rc = waveOutOpen(&out, WAVE_MAPPER, &fmt, NULL, NULL, CALLBACK_NULL);
|
||
|
if (rc != MMSYSERR_NOERROR)
|
||
|
{
|
||
|
printf("error %d on open\n");
|
||
|
exit(1);
|
||
|
}
|
||
|
|
||
|
WAVEHDR bufs[2] = {
|
||
|
{ (char *)malloc(4096), 4096 },
|
||
|
{ (char *)malloc(4096), 4096 },
|
||
|
};
|
||
|
int i = 0;
|
||
|
|
||
|
fill(bufs[i].lpData);
|
||
|
bufs[i].dwFlags = WHDR_PREPARED;
|
||
|
waveOutPrepareHeader(out, bufs + i, sizeof(WAVEHDR));
|
||
|
waveOutWrite(out, bufs + i, sizeof(WAVEHDR));
|
||
|
i ^= 1;
|
||
|
|
||
|
while (!(GetAsyncKeyState(VK_ESCAPE) & 1))
|
||
|
{
|
||
|
fill(bufs[i].lpData);
|
||
|
bufs[i].dwFlags = WHDR_PREPARED;
|
||
|
waveOutPrepareHeader(out, bufs + i, sizeof(WAVEHDR));
|
||
|
waveOutWrite(out, bufs + i, sizeof(WAVEHDR));
|
||
|
i ^= 1;
|
||
|
while (waveOutUnprepareHeader(out, bufs + i, sizeof(WAVEHDR)) == WAVERR_STILLPLAYING);
|
||
|
}
|
||
|
}
|