#!/usr/bin/perl # A little utility to calculate room resonance modes. # (c) 1998 Paul M. Winkler, zarmzarm_AT_erols.com # Distributed under the terms of the GNU Public License. # Blah blah blah blah. # First we find our unit of measurement. print '[F]eet, [i]nches, or [m]eters? '; chomp ($units = ); if ($units =~ /^[Ii]/) { $speedosnd = 13536; } elsif ($units =~ /^[Mm]/) { $speedosnd = 344; } elsif ($units =~ /^[Ff]/) { $speedosnd = 1128; } else { print "Huh? I'll assume you are using feet.\n"; $speedosnd = 1128; } # Now we get three dimensions. print 'Length? '; chomp ($l = ); print 'Width? '; chomp ($w = ); print 'Height? '; chomp ($h = ); print "The total cubic volume is ", ($l * $w * $h ), "\n"; # Calculate and print the resonance modes ... print "How many modes do you want to see? "; chomp ($limit = ); $printlimit = $limit; for ($cnt = 0; $cnt < $limit; ++$cnt) { $l_modes[$cnt] = mode($cnt, $l); $w_modes[$cnt] = mode($cnt, $w); $h_modes[$cnt] = mode($cnt, $h); # write; } # Space the modes in a way that's easy to read. # This is a bad strategy and needs to be totally redone. for ($cnt = 0; $cnt < $limit; ++$cnt) { if ($l_modes[$cnt] < ($w_modes[$cnt] * 0.95 )) { shove_it (\@w_modes); } elsif ($l_modes[$cnt] > ($w_modes[$cnt] * 1.05)) { shove_it (\@l_modes); } } for ($cnt = 0; $cnt < $printlimit; ++$cnt) { write; } # print "\n\n Problem Zones:\n ==============\n"; # END ############# # A format for printing the modes. format STDOUT_TOP = Count Length: @<<< Width: @<<< Height: @<<< $l, $w, $h ===== ============ ============ ============ . format STDOUT = @<<<< @<<<<<<<<<<< @<<<<<<<<<<< @<<<<<<<<<<< $cnt, $l_modes[$cnt], $w_modes[$cnt], $h_modes[$cnt], . ############# # A subroutine to calculate one room mode. # This takes two arguments: the number of the mode (counting from # zero), and a dimension in some arbitrary unit of measure. # It returns a frequency in hz. # $speedosnd is the speed of sound in units per second. sub mode { return ($speedosnd * ($_[0] + 1) / ($_[1])); } sub shove_it { $aref = $_[0]; @movers = splice(@$aref, $cnt); $$aref[$cnt] = 0; push(@$aref, @movers); ++$printlimit; }