title: Remove/control clicking sound using PyAudio as an oscillator
body: <p>When this runs, there is a clicking sound between pitches. I don't mind the clicking sound too much - it's pleasantly rhythmic. That said... </p>
  
  <ul>
  <li>I'd like to be able to get rid of this clicking sound when I don't want it. </li>
  <li>Better yet, it would be nice to be able to control the clicking sound
  in some way - volume, etc. </li>
  </ul>
  
  <p>I have seen this thread, but haven't figured out how to apply it to my problem:
  <a href="https://stackoverflow.com/questions/36438850/how-to-remove-pops-from-concatented-sound-data-in-pyaudio">How to remove pops from concatented sound data in PyAudio</a></p>
  
  <p>Any ideas? Thanks for your time!</p>
  
  <pre><code>import numpy
  import pyaudio
  import math
  import random
  
  
  def sine(frequency, length, rate):
      length = int(length * rate)
      factor = float(frequency) * (math.pi * 2) / rate
      waveform = numpy.sin(numpy.arange(length) * factor)
      return waveform
  
  
  def play_tone(stream, frequency, length, rate=44100):
      chunks = []
      chunks.append(sine(frequency, length, rate))
  
      chunk = numpy.concatenate(chunks) * .25
  
      stream.write(chunk.astype(numpy.float32).tostring())
  
  
  def bassline():
          frequency = 300
          for i in range(1000000):
              play_tone(stream, frequency, .15)
              change = random.choice([-75, -75, -10, 10, 2, 3, 100, -125])
              print (frequency)
              if frequency &lt; 0:
                  frequency = random.choice([100, 200, 250, 300])
              else:
                  frequency = frequency + change 
  
  if __name__ == '__main__':
      p = pyaudio.PyAudio()
      stream = p.open(format=pyaudio.paFloat32,
                      channels=1, rate=44100, output=4)
  
  bassline()
  </code></pre>
  
  <p>/EDIT</p>
  
  <p>I've plotted the tones and it looks like the discontinuity is in the relationship between the starting and ending phase of each tone. </p>
  
  <p><a href="https://i.stack.imgur.com/pc07s.png" rel="noreferrer">First tone</a></p>
  
  <p><a href="https://i.stack.imgur.com/2xv0g.png" rel="noreferrer">Second tone</a></p>
  
  <p>Any ideas how to remedy this? </p>