Acoustic Velocity and Loudspeaker Delay with Temperature and Python

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:

#!/usr/bin/env python

#version 1.3 / 02-November-2017

# Calculate acoustic velocity in air based on temperature. Calculate resulting delay time
# in milliseconds for a measured distance. 
# 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.

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:

#!/usr/bin/env python

# version 1.3 / 02-November-2017

# Calculate acoustic velocity in air based on temperature. Calculate resulting delay time
# in milliseconds for a measured distance. 
# 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.

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:

#!/usr/bin/env python

#version 1.3 / 02-November-2017

# Calculate acoustic velocity in air based on temperature. Calculate resulting delay time
# in milliseconds for a measured distance. 
# 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:\n "))
measured_distance = float(input("Enter measured distance between speakers in feet:\n "))

# 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 or 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_round, '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