-
Notifications
You must be signed in to change notification settings - Fork 167
Description
I recently integrated the sample code for PortAudio/AudioEngine into a test app. Everything worked, but the audio quality for the metronome was poor; with annoying distortion of the sound on occasion.
The root cause of this problem is that the metronome calculates a simple sin/cos wave using the current time information. Inevitably from one audio frame to the next, the time value used in the sin() calculation will drift as tempo is synced across the network. This means that the waveform being filled into the audio buffers will have discontinuities of phase, and distortion is heard.
I'm sure many users who have integrated the metronome into their code will have heard this.
One simple solution would be to trigger a complete 'ping' for every beat and fill the buffer with the wave until the ping has timed out. In this way, discontinuities between audio frames are removed. I tried this and it makes a nice clean sound.
I know that using sin/cos won't be typical, and wavetables, etc. are more likely, but it's a shame that the sample source code generates poor audio!