gensound icon indicating copy to clipboard operation
gensound copied to clipboard

Crash when realising sequential Sines controlled by Lines

Open ali1234 opened this issue 2 years ago • 1 comments

Code:

if __name__ == '__main__':
    x = Sine(Line(220, 440, 1e3)) | Sine(Line(440, 220, 1e3))
    x.play()

Trace:

Traceback (most recent call last):
  File "test.py", line 15, in <module>
    x.play()
  File "python3.8/site-packages/gensound/signals.py", line 54, in play
    audio = self.realise(sample_rate)
  File "python3.8/site-packages/gensound/signals.py", line 41, in realise
    audio = self.generate(sample_rate)
  File "python3.8/site-packages/gensound/signals.py", line 382, in generate
    phase = (phase + signal.end_phase)%(2*np.pi) # phase inference
  File "python3.8/site-packages/gensound/signals.py", line 500, in end_phase
    return (phase + 2*np.pi * self.frequency * self.duration / 1000)%(2*np.pi)
TypeError: unsupported operand type(s) for *: 'float' and 'Line'

ali1234 avatar May 16 '22 09:05 ali1234

Thanks for finding this!

I found the problem, but I still need to decide on the most efficient way to prevent it.

In the meanwhile, here is a more natural way to accomplish this:

if __name__ == '__main__':
    x = Sine(Line(220, 440, 1e3) | Line(440, 220, 1e3))
    x.play()

Quefumas avatar May 17 '22 20:05 Quefumas