NOTE: visit https://www.github.com/kreivalabs for the current code versions.
Building on the method below, here is the same calculator in Python (hooray for cross-platform!).
Save the text below as a .py file to run in the Terminal of your choice.
Python 2:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
#!/usr/bin/env python # Version 1.4 / 08-November-2017 title="Acoustic Velocity and Loudspeaker Delay Calculator" print title print"=" * 80 # Prompt for user input temp_fahrenheit = float(input("Enter temperture in degrees Fahrenheit: ")) measured_distance = float(input("Enter measured distance between speakers in feet: ")) # Convert Fahrenheit to degrees Celsius temp_celsius = (temp_fahrenheit - 32) * 5/9 # Calculate acoustic velocity in meters/second meters_seconds = (temp_celsius * 0.606) + 331.3 # Convert meters/second to feet/millisecond feet_milliseconds = meters_seconds * 0.00328084 # Calculate time differential based on acoustic velocity and measured distance delay_time = measured_distance / feet_milliseconds # Round results to two decimal places - suitable for most loudspeaker processing hardware and software meters_seconds_round = str(round(meters_seconds, 4)) feet_milliseconds_round = str(round(feet_milliseconds, 4)) delay_time_round = str(round(delay_time, 4)) # Return results print"=" * 80 print"Approximate acoustic velocity is:" print meters_seconds_round, "m/s, or", feet_milliseconds_round, "ft/ms." print"" print"Approximate delay time is" , delay_time_round, "ms." print"" print"Press <Enter> to exit." raw_input() |
Python 3:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
#!/usr/bin/env python # Version 1.4 / 08-November-2017 title='Acoustic Velocity and Loudspeaker Delay Calculator' print(title) print('=' * 80) # Prompt for user input temp_fahrenheit = float(input("Enter temperture in degrees Fahrenheit: ")) measured_distance = float(input("Enter measured distance between speakers in feet: ")) # Convert Fahrenheit to degrees Celsius temp_celsius = (temp_fahrenheit - 32) * 5/9 # Calculate acoustic velocity in meters/second meters_seconds = (temp_celsius * 0.606) + 331.3 # Convert meters/second to feet/millisecond feet_milliseconds = meters_seconds * 0.00328084 # Calculate time differential based on acoustic velocity and measured distance delay_time = measured_distance / feet_milliseconds # Round results to two decimal places - suitable for most loudspeaker processing hardware and software meters_seconds_round = str(round(meters_seconds, 4)) feet_milliseconds_round = str(round(feet_milliseconds, 4)) delay_time_round = str(round(delay_time, 4)) # Return results print('=' * 80) print('Approximate acoustic velocity is:' print(meters_seconds_round, 'm/s, or', feet_milliseconds_round, 'ft/ms.') print() print('Approximate delay time is', delay_time_round, 'ms.') print() print('Press <Enter> key to exit.') input() |
And a version if you have Future installed, to avoid the version call:
Python w/Future:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
#!/usr/bin/env python # Version 1.4 / 08-November-2017 # Calculate acoustic velocity in air based on temperature. Calculate resulting delay time in milliseconds for a measured distance. Results rounded to two decimal places. # NOTE: there is no method for factoring in gas density in air. Returned values are suitable for indoor use where temperature and humidity swings are not extreme. # This script uses Future additions from http://www.python-future.org # Import Future additions from __future__ import absolute_import, division, print_function, unicode_literals from builtins import input title='Acoustic Velocity and Loudspeaker Delay Calculator' print(title) print('=' * 80) # Prompt for user input temp_fahrenheit = float(input("Enter temperture in degrees Fahrenheit: ")) measured_distance = float(input("Enter measured distance between speakers in feet: ")) # Convert Fahrenheit to degrees Celsius temp_celsius = (temp_fahrenheit - 32) * 5/9 # Calculate acoustic velocity in meters/second meters_seconds = (temp_celsius * 0.606) + 331.3 # Convert meters/second to feet/millisecond feet_milliseconds = meters_seconds * 0.00328084 # Calculate time differential based on acoustic velocity and measured distance delay_time = measured_distance / feet_milliseconds # Round returned values to two decimal places - suitable for most loudspeaker processing hardware and software. meters_seconds_round = str(round(meters_seconds, 4)) feet_milliseconds_round = str(round(feet_milliseconds, 4)) delay_time_round = str(round(delay_time, 4)) # Display results print('=' * 80) print('Approximate acoustic velocity is:') print(meters_seconds_round, 'm/s, or', feet_milliseconds, 'ft/ms.') print() print('Approximate delay time is', delay_time_round, 'ms.') print() print('Press <Enter> to exit.') input() |
Source available at https://github.com/kreivalabs/acousticVelocityAndDelay