This commit is contained in:
aprilnightk 2025-08-13 22:43:56 +03:00
parent 66615c10bc
commit 7a61540e78
4 changed files with 15 additions and 3 deletions

View file

@ -34,6 +34,7 @@ class Program:
self.volume = 0.1 self.volume = 0.1
self.actions = [] self.actions = []
def reset(self): def reset(self):
self.room = Room() self.room = Room()

View file

@ -28,6 +28,7 @@ class Room:
self.sine_multiplier = TAU / self.sample_rate self.sine_multiplier = TAU / self.sample_rate
self.dist_cache = dict() # {((x,y,z),(x,y,z)) : dist}
self.running_program = None self.running_program = None
def set_bit_depth(self, bit_depth): def set_bit_depth(self, bit_depth):

View file

@ -24,10 +24,19 @@ class SoundNode:
loc = self.location(t) loc = self.location(t)
other_loc = other_node.location(t) other_loc = other_node.location(t)
if (loc, other_loc) in self.room.dist_cache:
return self.room.dist_cache[(loc, other_loc)]
if (other_loc, loc) in self.room.dist_cache:
return self.room.dist_cache[(other_loc, loc)]
diff_x = loc[0]-other_loc[0] diff_x = loc[0]-other_loc[0]
diff_y = loc[1]-other_loc[1] diff_y = loc[1]-other_loc[1]
diff_z = loc[2]-other_loc[2] diff_z = loc[2]-other_loc[2]
return diff_x*diff_x + diff_y*diff_y + diff_z * diff_z
dist = diff_x*diff_x + diff_y*diff_y + diff_z * diff_z
self.room.dist_cache[(loc, other_loc)] = dist
return dist
return (loc[0]-other_loc[0])**2 + (loc[1]-other_loc[1])**2 + (loc[2]-other_loc[2])**2 return (loc[0]-other_loc[0])**2 + (loc[1]-other_loc[1])**2 + (loc[2]-other_loc[2])**2
def sample_r_amps_by_wire(self, source_node, current_t): def sample_r_amps_by_wire(self, source_node, current_t):
@ -40,7 +49,8 @@ class SoundNode:
def sample_r_amps_by_air(self, source_node, current_t): def sample_r_amps_by_air(self, source_node, current_t):
dist = self.distance_to_node(source_node, current_t) dist = self.distance_to_node(source_node, current_t)
sample_t = current_t - int(dist / self.room.speed_of_sound) #sample_t = current_t - int(dist / self.room.speed_of_sound)
sample_t = current_t - int(128.571428 * dist)
if sample_t in source_node.r_amps: if sample_t in source_node.r_amps:

View file

@ -37,7 +37,7 @@ class TestProgram(Program):
LinearPitchTransition('A4', 'E4', self.st(0), self.st(5), [sn], self) LinearPitchTransition('A4', 'E4', self.st(0), self.st(5), [sn], self)
LinearPitchTransition('E4', 'A4', self.st(0), self.st(5), [sn2], self) LinearPitchTransition('E4', 'A4', self.st(0), self.st(5), [sn2], self)
LinearSpatialTransition((-8,0,0),(8,0,0), self.st(0), self.st(5), [sn], self) #LinearSpatialTransition((-8,0,0),(8,0,0), self.st(0), self.st(5), [sn], self)
TP = TestProgram() TP = TestProgram()
TP.setup() TP.setup()