From 7a61540e78225b28d9c66479b4606ef0839ae94e Mon Sep 17 00:00:00 2001 From: aprilnightk Date: Wed, 13 Aug 2025 22:43:56 +0300 Subject: [PATCH] tests --- core/program.py | 1 + core/room.py | 1 + core/soundnode.py | 14 ++++++++++++-- test.py | 2 +- 4 files changed, 15 insertions(+), 3 deletions(-) diff --git a/core/program.py b/core/program.py index b9f46ed..c4947c0 100644 --- a/core/program.py +++ b/core/program.py @@ -34,6 +34,7 @@ class Program: self.volume = 0.1 self.actions = [] + def reset(self): self.room = Room() diff --git a/core/room.py b/core/room.py index 80f235f..26ce75a 100644 --- a/core/room.py +++ b/core/room.py @@ -28,6 +28,7 @@ class Room: self.sine_multiplier = TAU / self.sample_rate + self.dist_cache = dict() # {((x,y,z),(x,y,z)) : dist} self.running_program = None def set_bit_depth(self, bit_depth): diff --git a/core/soundnode.py b/core/soundnode.py index 8f3986a..7a453cf 100644 --- a/core/soundnode.py +++ b/core/soundnode.py @@ -24,10 +24,19 @@ class SoundNode: loc = self.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_y = loc[1]-other_loc[1] 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 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): 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: diff --git a/test.py b/test.py index 1f29b34..7c2d1c6 100644 --- a/test.py +++ b/test.py @@ -37,7 +37,7 @@ class TestProgram(Program): LinearPitchTransition('A4', 'E4', self.st(0), self.st(5), [sn], 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.setup()