41 lines
No EOL
867 B
Python
41 lines
No EOL
867 B
Python
from core.room import Room
|
|
from core.soundnode import SoundNode
|
|
import math
|
|
|
|
R = Room()
|
|
R.left_sink.start_location = (-1, 0, 0)
|
|
R.right_sink.start_location = (2, 0, 0)
|
|
|
|
class SineNode(SoundNode):
|
|
|
|
def __init__(self, freq, room):
|
|
|
|
super().__init__("sine", room)
|
|
self.freq = freq
|
|
self.volume = 0.8
|
|
|
|
|
|
def calc_freqs_volumes(self, t):
|
|
# This function returns volumes of each relevant freq
|
|
# at tick t
|
|
|
|
res = dict()
|
|
for freq in range(self.freq-20, self.freq+20):
|
|
res[freq] = self.volume*0.05*math.sin(freq)
|
|
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
|
|
|
|
sn = SineNode(440, R)
|
|
|
|
sn.add_air_output(R.left_sink)
|
|
sn.add_air_output(R.right_sink)
|
|
|
|
|
|
R.record('test6.wav', 0, 2) |