-
Notifications
You must be signed in to change notification settings - Fork 151
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Crackling/clicking at the end of signal when using playback without callback #482
Comments
You should always check the return value of |
I updated the code to print out the return value "underflowed (bool)". It returns False. Yet the audio click is clearly audible. |
OK, that was an important first step. Now, listening to the output and looking at your code more closely, I have noticed that you don't do any fade in nor fade out, right? It is expected that you hear a click if you abruptly start or stop a sine wave, which creates a discontinuity in the signal. In signal processing terms, you are applying a "rectangular window" to the sine signal. You should hear the same click in the play_sine.py example (you may hear it more clearly at lower sine frequencies, as in your example). To avoid the click, you should create a fade in/out, see e.g. https://nbviewer.org/github/spatialaudio/communication-acoustics-exercises/blob/master/intro.ipynb#Listening-to-the-Signal A simple linear fade normally suffices. I guess this should solve the problem, but if not, there can be another reason for audible clicks when starting and stopping a stream, see #455. |
I do not do fade in/out but I was careful to make the sine wave end at a zero point. This does make a soft pop. But what I hear is a loud click, which seems to have another cause. To verify this I added 100 samples of zeros to the end of my signal (updated code above with "pad"). I'd expect that I hear the same click if it were about the sine wave's ending. Yet this fixed my problem and the loud click is gone. I also did the same experiment in Audacity. If I simply generate a sine wave that ends at a zero, I hear the exact same loud click. If I add silence at the end of it, the click is gone. This I believe points to the issue not being about python-sounddevice. |
Yeah, stopping at a zero crossing isn't enough to avoid audible artifacts, as you have witnessed:
With an appropriate fade, this should also go away.
OK, that's good to know. Did you look at #455 then? |
Yes I did. Similar conclusion there also, it seems to be an issue with host API. Suggestion is to separate playback endings from stream endings. So I'll add padding to my signals as in the example above. That is a good workaround. Thank you for the help. |
It seems like somehow the end of my signal is being clipped which causes an immediate jump to zero amplitude and a click sound.
What I have tested
My system
I do not have such issues in any other app- see updateThank you already for the help.
Edit: Addition to "What I have tested"
The text was updated successfully, but these errors were encountered: