sonnum/core/soundnode.py
2025-08-09 08:15:49 +03:00

45 lines
No EOL
1,017 B
Python

import math
TAU = 2 * math.pi
class SoundNode:
def __init__(self, name, room):
self.name = name
self.room = room
self.air_in = []
self.air_out = []
self.wire_in = []
self.wire_out = []
self.start_location = (0, 0, 0)
def location(self, t):
# Location of the soundnote (x,y,z) in meters
# at time t.
return self.start_location
def distance_to_node(self, other_node, t):
loc = self.location(t)
other_loc = other_node.location(t)
return (loc[0]-other_loc[0])**2 + (loc[1]-other_loc[1])**2 + (loc[2]-other_loc[2])**2
def frequency_max_rel_amp(self, f, t):
return 0
def amp_at_tick(self, f, t):
return self.room.max_amp * self.frequency_max_rel_amp(f, t) * math.sin(self.room.sine_multiplier * f * t)
def amp_at_tick_by_air(self, f, t, node):
dist = self.distance_to_node(node, t)
t = t - int(dist / self.room.speed_of_sound)
return self.room.max_amp * self.frequency_max_rel_amp(f, t) * math.sin(self.room.sine_multiplier * f * t)