Skip to content

Instantly share code, notes, and snippets.

@MysteriousJ
MysteriousJ / minimal_wasapi.cpp
Created January 31, 2023 04:30
Minimal WASAPI implementation that plays a sine wave
// Compile: cl minimal_wasapi.cpp /link ole32.lib
#include <windows.h>
#include <inttypes.h>
#include <math.h>
#include <mmdeviceapi.h>
#include <audioclient.h>
#define BYTES_PER_CHANNEL sizeof(float)
#define CHANNELS_PER_SAMPLE 1
#define SAMPLES_PER_SECOND 44100
@MysteriousJ
MysteriousJ / music_box.cpp
Last active January 31, 2023 14:38
Sturdy WASAPI example
// Compile: cl music_box.cpp /link ole32.lib
// Usage: music_box.exe "Hello World"
#include <windows.h>
#include <inttypes.h>
#include <math.h>
#include <mmdeviceapi.h>
#include <audioclient.h>
#define BYTES_PER_CHANNEL sizeof(float)
#define CHANNELS_PER_SAMPLE 1
@MysteriousJ
MysteriousJ / DirectoryWatch.cpp
Last active January 6, 2023 08:18
File change notifications on Windows
#include <windows.h>
#include <stdio.h>
struct DirectoryWatch
{
char filePath[1024];
char changeBuffer[65536];
HANDLE directoryHandle;
FILE_NOTIFY_INFORMATION* nextChange;
};