How do you remove \"popping\" and \"clicking\" sounds in audio constructed by concatenating sound tonal sound clips together?
I have this PyAudio code for generating
My initial suspicion that the individual waveforms weren't aligning was correct, which I confirmed by inspecting in Audacity. My solution was to modify the code to start and stop each waveform on the peak of the sine wave.
def tone(self, frequency, length=1000, play=False, **kwargs):
number_of_frames = int(self.bitrate * length/1000.)
record = False
x = 0
y = 0
while 1:
x += 1
v = math.sin(x/((self.bitrate/float(frequency))/math.pi))
# Find where the sin tip starts.
if round(v, 3) == +1:
record = True
if record:
self._queue.append(chr(int(v*127+128)))
y += 1
if y > number_of_frames and round(v, 3) == +1:
# Always end on the high tip of the sin wave to clips align.
break