cpal icon indicating copy to clipboard operation
cpal copied to clipboard

Unexpected frequency/sample rate modulations when playing simple tones

Open kyragit opened this issue 3 years ago • 4 comments

I'm trying to make a simple synthesizer using cpal, but I am getting strange artifacts/modulations when playing back a simple sine wave. It initially plays the correct tone, but after a few seconds other sounds start appearing until the pitch changes randomly, and then this keeps happening. I'm not sure if something is going wrong with the sample rate or what but it's very strange. I am on Windows 10 using WASAPI.

I can upload a recording of what it sounds like if need be.

Code: main_rs.txt

kyragit avatar Oct 06 '22 00:10 kyragit

Hmm there could be a couple of reasons ... are there other programs running that might request a different sample rate ? Your code doesn't seem dependent on a fixed blocksize, but if it was, WASAPI has a variable blocksize.

Also, what do you mean by other sounds ? Glitches, overtones ? Does it sound broken, or just a different pitch ?

the-drunk-coder avatar Oct 13 '22 18:10 the-drunk-coder

Glitches, strange overtones, it definitely sounds broken.

kyragit avatar Oct 13 '22 18:10 kyragit

Also, I tried switching to ASIO and the problem still occurred, so it probably isn't specific to WASAPI.

kyragit avatar Oct 13 '22 18:10 kyragit

Hello kyragit,

I test your code: 10 seconds with A4 frequency then change to low freq between G#4 and A4.

sbechet avatar Nov 20 '22 10:11 sbechet