Created
August 23, 2013 09:27
-
-
Save kbjorklu/6317308 to your computer and use it in GitHub Desktop.
Sample code for the waveOutWrite function.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <windows.h> | |
#include <mmsystem.h> | |
#pragma comment(lib, "winmm.lib") | |
int main() | |
{ | |
HWAVEOUT hWaveOut = 0; | |
WAVEFORMATEX wfx = { WAVE_FORMAT_PCM, 1, 8000, 8000, 1, 8, 0 }; | |
waveOutOpen(&hWaveOut, WAVE_MAPPER, &wfx, 0, 0, CALLBACK_NULL); | |
char buffer[8000 * 60] = {}; | |
// See http://goo.gl/hQdTi | |
for (DWORD t = 0; t < sizeof(buffer); ++t) | |
buffer[t] = static_cast<char>((((t * (t >> 8 | t >> 9) & 46 & t >> 8)) ^ (t & t >> 13 | t >> 6)) & 0xFF); | |
WAVEHDR header = { buffer, sizeof(buffer), 0, 0, 0, 0, 0, 0 }; | |
waveOutPrepareHeader(hWaveOut, &header, sizeof(WAVEHDR)); | |
waveOutWrite(hWaveOut, &header, sizeof(WAVEHDR)); | |
waveOutUnprepareHeader(hWaveOut, &header, sizeof(WAVEHDR)); | |
waveOutClose(hWaveOut); | |
Sleep(60 * 1000); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is an example that uses several buffers, without needing a huge buffer, and loops around them whilst dynamically calculating the samples: