add hanning back

pull/26673/head
Shane Smiskol 3 years ago
parent 178e3d2256
commit 72d6afb661
  1. 2
      selfdrive/ui/soundd/sound.cc
  2. 7
      system/micd.py

@ -48,7 +48,7 @@ void Sound::update() {
// scale volume with speed
if (sm.updated("microphone")) {
float volume = util::map_val(sm["microphone"].getMicrophone().getFilteredSoundPressureWeightedDb(), 34.f, 56.f, 0.f, 1.f);
float volume = util::map_val(sm["microphone"].getMicrophone().getFilteredSoundPressureWeightedDb(), 30.f, 52.f, 0.f, 1.f);
volume = QAudio::convertVolume(volume, QAudio::LogarithmicVolumeScale, QAudio::LinearVolumeScale);
Hardware::set_volume(volume);
}

@ -25,8 +25,11 @@ def calculate_spl(measurements):
def apply_a_weighting(measurements: np.ndarray) -> np.ndarray:
# Generate a Hanning window of the same length as the audio measurements
measurements_windowed = measurements * np.hanning(len(measurements))
# Calculate the frequency axis for the signal
freqs = np.fft.fftfreq(measurements.size, d=1 / SAMPLE_RATE)
freqs = np.fft.fftfreq(measurements_windowed.size, d=1 / SAMPLE_RATE)
# Calculate the A-weighting filter
# https://en.wikipedia.org/wiki/A-weighting
@ -34,7 +37,7 @@ def apply_a_weighting(measurements: np.ndarray) -> np.ndarray:
A /= np.max(A) # Normalize the filter
# Apply the A-weighting filter to the signal
return np.abs(np.fft.ifft(np.fft.fft(measurements) * A))
return np.abs(np.fft.ifft(np.fft.fft(measurements_windowed) * A))
class Mic:

Loading…
Cancel
Save