I actually have some useful code for that purpose from my second generation CHIP-8 emulator (which is open sourced). It not only generates a 220hz square wave (using a simple implementation at the moment), but also comes equipped with a handcrafted envelope generator.
I recently made upgrades to it’s audio handling that should be almost latency free for real-time audio generation purposes: hyper_bandchip/audio.cpp at main · Bandock/hyper_bandchip · GitHub
I know I’m about five months late, but figured I could share some of my work for achieving this purpose in regards to game development.