/
acousticVelocityAndDelayUsingFuture.py
executable file
·49 lines (37 loc) · 1.79 KB
/
acousticVelocityAndDelayUsingFuture.py
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/usr/bin/env python
# Version 1.4.1 / 05-February-2018
# 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 any key to exit.')
input()