Search code examples
pythonnumpyscipysignalssine-wave

How to combine two sine waves without cracks


I'm using Python, pyaudio and scipy and I would like to combine two sine waves (two tones) in a way that one tone is played after another (create melody). Let's assume that I have two arrays: tone1 and tone2.

tone1 contains data of sine wave with frequency of 350 Hz. tone2 contains sine wave's data with frequency of 440 Hz.

My question is: how to combine these two arrays (tone1 and tone2) into one array that, after being played, will give me a melody without noticeable crack between these two sine waves (tone1 and tone2)?


Solution

  • Append them together and apply a Fourier Transform smoothing filter. In the regions with a single tone, the Fourier transform will have only one component, and the filter will do nothing; whereas in the transition region you will get both components (plus the crap coming from the jump), that the filter would hopefully smooth out.