28 lines
No EOL
581 B
Python
28 lines
No EOL
581 B
Python
import math
|
|
|
|
from ..soundnode import SoundNode
|
|
|
|
class SineNode(SoundNode):
|
|
|
|
def __init__(self, freqs, room):
|
|
|
|
super().__init__("sine", room)
|
|
self.freqs = freqs
|
|
|
|
def calc_freqs_volumes(self, t):
|
|
# This function returns volumes of each relevant freq
|
|
# at tick t
|
|
|
|
res = dict()
|
|
for freq in self.freqs:
|
|
res[freq] = 1 / float(len(self.freqs))
|
|
return res
|
|
|
|
def fill_amp_cache(self, t):
|
|
|
|
tdct = dict()
|
|
for freq, vol in self.calc_freqs_volumes(t).items():
|
|
tdct[freq] = vol * math.sin(self.room.sine_multiplier * freq * t)
|
|
|
|
self.amp_cache[t] = tdct
|
|
|