Help with Day 008 - DirectSound crackling issues

Hello there. I'm just following the series as usual, but at the point of writing a square wave to DirectSound, I'm not sure what happened. The sound is all crackled and distorted: See here

The first window is my code, the second is literally the day 8 source code extracted and compiled. There is a difference but both are horribly distorted. The second window's square wave sounds fine when I resize it for some reason but even then it still has weird cuts. Since Casey's code which sounds fine in the stream sounds horrible in my computer, I can only assume this is a DirectSound problem?

Any clues what should I do? Maybe try another API?

Edited by ScarletKrath on Reason: Initial post
I by "DirectSound" problem you mean that DirectSound is broken, I doubt it. It's more likely you don't feel the buffer properly for some reason.

An easy way to know if DirectSound is working is to just fill a several second long buffer with a sine wave (or square) and to play it without trying to modify it after it has been initialized. If the sound is correct than you probably have a timing bug or you're not properly filling the buffer.

My guess would be that you need to write more samples in each iteration of your main loop. Also note that Casey's square wave doesn't sound right at the end of the video so there's probably already a bug in there and it may sound worst on your machine.