From 9560346cdd1429ff5c9d22e80963d9c6b30358ec Mon Sep 17 00:00:00 2001 From: aprilnightk Date: Sat, 9 Aug 2025 08:15:49 +0300 Subject: [PATCH] speed of sound fix --- core/room.py | 2 +- core/soundnode.py | 2 +- test.py | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/core/room.py b/core/room.py index 8311ef8..68b4dfb 100644 --- a/core/room.py +++ b/core/room.py @@ -12,9 +12,9 @@ class Room: def __init__(self): - self.speed_of_sound = 330 #m/s self.dissipation_quotient = 0.9993 self.sample_rate = 44100 + self.speed_of_sound = 343 / float(self.sample_rate) #m/tick self.set_bit_depth(24) self.lowest_freq = 430 diff --git a/core/soundnode.py b/core/soundnode.py index 5056e69..d80326a 100644 --- a/core/soundnode.py +++ b/core/soundnode.py @@ -39,7 +39,7 @@ class SoundNode: def amp_at_tick_by_air(self, f, t, node): dist = self.distance_to_node(node, t) - t = t - ((self.room.speed_of_sound*dist)/float(self.room.sample_rate)) + 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) \ No newline at end of file diff --git a/test.py b/test.py index 8c98213..b653244 100644 --- a/test.py +++ b/test.py @@ -4,7 +4,7 @@ import math R = Room() R.left_sink.start_location = (-1, 0, 0) -R.right_sink.start_location = (1, 0, 0) +R.right_sink.start_location = (2, 0, 0) class SineNode(SoundNode): @@ -23,7 +23,7 @@ class SineNode(SoundNode): sn = SineNode(440, R) -R.link_wire(sn, R.left_sink) -R.link_wire(sn, R.right_sink) +R.link_air(sn, R.left_sink) +R.link_air(sn, R.right_sink) R.record('test5.wav', 0, 6) \ No newline at end of file