sine wave glissando from one pitch to another in Numpy

后端 未结 2 2111
旧时难觅i
旧时难觅i 2021-02-10 18:22

I have been working on a program where I need to slowly and smoothly change the pitch of a sine wave from one pitch to another. I am able to get an array of the frequency the p

2条回答
  •  野趣味
    野趣味 (楼主)
    2021-02-10 18:44

    I like to think of frequency as the rate at which you are stepping through your sound sample - in this case a sine wave. Here's an attempt at some Python code to do what you want. We assume that the freq() method gives frequency as a function of time. For your purposes, it will be some kind of exponential. We are trying to fill a pre-allocated list called wave.

    index = 0
    t = 0
    while t < len(wave):
      wave[t] = math.sin(2*math.pi*index/sample_rate)
      t = t+1
      index = index + freq(t/sample_rate)
    

    Excuse my Python, I'm still learning the language.

提交回复
热议问题