0
$\begingroup$

I am trying to produce some simple audio waves using WASAPI (Windows Audio Session API). If I skip all the abstractions, my program basically receives a buffer from the API, then writes results of a sine function (or some other simple function) of a selected frequency to the buffer sample by sample, while counting the samples to keep track of time. When it goes to the next buffer it continues with an offset of the samples passed. So in theory, it should be a simple quantization of the sine wave.

The problem is, that some frequencies work and some don't. In particular, multiples of 50 work perfectly fine, while all the other frequencies sound glitchy.

Any ideas on what problem this could be related to? Is it some quantization error maybe? Should I look into some concepts like signal-to-noise ratio? Or are these problems a matter of the DAC and not my concern.

Edit:

I agree with the comments bellow, that my code being wrong is more probable, but after trying to inspect every detail of the code and also noticing this strange behavior I just thought I might ask some more experienced people, and hope that this behavior might be suspicious of some more general problem. If it sounds like a problem specific to my implementation, then I'll try to post a simplified example of my code. (Only if this community is a right place to post such questions of course.)

$\endgroup$
  • 1
    $\begingroup$ Hard to tell. Probably something is broken about your signal generation. $\endgroup$ – Marcus Müller Sep 6 '18 at 10:57
  • 1
    $\begingroup$ @MarcusMüller is correct, you need to show more than you have in order to get any helpful answers. To address your last question, I seriously doubt that there is an issue with the DAC in your system, especially if other audio on the machine works properly. When you encounter a bug while writing software, always suspect your own code first. $\endgroup$ – Jason R Sep 6 '18 at 11:22
  • $\begingroup$ I'm not saying there should be a problem with the DAC. I meant to ask whether there are some techniques I need to use to reduce quantization problems, or do I just feed the API with the discrete values of the wave function and the OS's sound engine or the audio drivers then handle those issues instead when converting back to the analogue representation. $\endgroup$ – egst Sep 6 '18 at 11:47
  • $\begingroup$ Make sure you're using numbers (sine amplitudes) in the range that the API expects. If the signal clips, it will sound glitchy. $\endgroup$ – MBaz Sep 6 '18 at 12:44
  • $\begingroup$ You could simply save your samples away simultaneously to pushing them through the sound system and plotting them. Again, it's extremely likely the bug is in your code, and with the info you give us ("sounds glitchy", whatever that means) we can't help you figure out what#s wrong. $\endgroup$ – Marcus Müller Sep 7 '18 at 6:55
0
$\begingroup$

I resolved my issue. The problem was with timing. My samples were rendered correctly, but the problem was with waiting for the buffer. I switched to event driven approach instead of manually calculating the buffer length and waiting, and the problem was resolved.

I don't know whether this question might be useful for someone. If not or if the source of the problem is not related to DSP, I will delete it. But for now I'm keeping it here with my answer.

| improve this answer | |
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.