|
|
@ -2,7 +2,6 @@ |
|
|
|
import numpy as np |
|
|
|
import numpy as np |
|
|
|
|
|
|
|
|
|
|
|
from cereal import messaging |
|
|
|
from cereal import messaging |
|
|
|
from openpilot.common.filter_simple import FirstOrderFilter |
|
|
|
|
|
|
|
from openpilot.common.realtime import Ratekeeper |
|
|
|
from openpilot.common.realtime import Ratekeeper |
|
|
|
from openpilot.system.swaglog import cloudlog |
|
|
|
from openpilot.system.swaglog import cloudlog |
|
|
|
|
|
|
|
|
|
|
@ -10,7 +9,6 @@ RATE = 10 |
|
|
|
FFT_SAMPLES = 4096 |
|
|
|
FFT_SAMPLES = 4096 |
|
|
|
REFERENCE_SPL = 2e-5 # newtons/m^2 |
|
|
|
REFERENCE_SPL = 2e-5 # newtons/m^2 |
|
|
|
SAMPLE_RATE = 44100 |
|
|
|
SAMPLE_RATE = 44100 |
|
|
|
FILTER_DT = 1. / (SAMPLE_RATE / FFT_SAMPLES) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def calculate_spl(measurements): |
|
|
|
def calculate_spl(measurements): |
|
|
@ -50,15 +48,12 @@ class Mic: |
|
|
|
self.sound_pressure_weighted = 0 |
|
|
|
self.sound_pressure_weighted = 0 |
|
|
|
self.sound_pressure_level_weighted = 0 |
|
|
|
self.sound_pressure_level_weighted = 0 |
|
|
|
|
|
|
|
|
|
|
|
self.spl_filter_weighted = FirstOrderFilter(0, 2.5, FILTER_DT, initialized=False) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def update(self): |
|
|
|
def update(self): |
|
|
|
msg = messaging.new_message('microphone', valid=True) |
|
|
|
msg = messaging.new_message('microphone', valid=True) |
|
|
|
msg.microphone.soundPressure = float(self.sound_pressure) |
|
|
|
msg.microphone.soundPressure = float(self.sound_pressure) |
|
|
|
msg.microphone.soundPressureWeighted = float(self.sound_pressure_weighted) |
|
|
|
msg.microphone.soundPressureWeighted = float(self.sound_pressure_weighted) |
|
|
|
|
|
|
|
|
|
|
|
msg.microphone.soundPressureWeightedDb = float(self.sound_pressure_level_weighted) |
|
|
|
msg.microphone.soundPressureWeightedDb = float(self.sound_pressure_level_weighted) |
|
|
|
msg.microphone.filteredSoundPressureWeightedDb = float(self.spl_filter_weighted.x) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
self.pm.send('microphone', msg) |
|
|
|
self.pm.send('microphone', msg) |
|
|
|
self.rk.keep_time() |
|
|
|
self.rk.keep_time() |
|
|
@ -79,7 +74,6 @@ class Mic: |
|
|
|
self.sound_pressure, _ = calculate_spl(measurements) |
|
|
|
self.sound_pressure, _ = calculate_spl(measurements) |
|
|
|
measurements_weighted = apply_a_weighting(measurements) |
|
|
|
measurements_weighted = apply_a_weighting(measurements) |
|
|
|
self.sound_pressure_weighted, self.sound_pressure_level_weighted = calculate_spl(measurements_weighted) |
|
|
|
self.sound_pressure_weighted, self.sound_pressure_level_weighted = calculate_spl(measurements_weighted) |
|
|
|
self.spl_filter_weighted.update(self.sound_pressure_level_weighted) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
self.measurements = self.measurements[FFT_SAMPLES:] |
|
|
|
self.measurements = self.measurements[FFT_SAMPLES:] |
|
|
|
|
|
|
|
|
|
|
|