mirror of
https://github.com/firestar5683/StarPilot.git
synced 2026-07-21 17:22:24 +08:00
store mic audio with toggle (#35595)
* store/send mic audio with toggle * script to extract audio from logs * change description and add translation placeholders * microphone icon * apply toggle in loggerd * add legnth and counter * startFrameIdx counter * Revert "change description and add translation placeholders" This reverts commit 7baa1f6de99c6ebe9f9906193da7e83dad79511a. * send mic data first and then calc * restore changed description/icon after revert * adjust fft samples to keep old time window * remove extract_audio.py since audio is now stored in qcam isntead of rlog * qt microphone recording icon * Revert "remove extract_audio.py since audio is now stored in qcam isntead of rlog" This reverts commit 7a3a75bd8db5376d1e442a3ba931c67550b5f132. * move extract_audio script and output file by default * remove length field * recording indicator swaps sides based on lhd/rhd * use record icon from comma body * Update toggle description Co-authored-by: Adeeb Shihadeh <adeebshihadeh@gmail.com> * update raylib toggle desc cause I did earlier * microphone --> soundPressure, audioData --> rawAudioData * cleanup unused var * update README * sidebar mic indicator instead of annotated camera * improve logic readability * remove startFrameIdx and sequenceNum * use Q_PROPERTY/setProperty so that update() is actually called on value change * specify old id for SoundPressure * fix typo --------- Co-authored-by: Adeeb Shihadeh <adeebshihadeh@gmail.com>
This commit is contained in:
+14
-12
@@ -226,19 +226,21 @@ void loggerd_thread() {
|
||||
for (const auto& [_, it] : services) {
|
||||
const bool encoder = util::ends_with(it.name, "EncodeData");
|
||||
const bool livestream_encoder = util::starts_with(it.name, "livestream");
|
||||
if (!it.should_log && (!encoder || livestream_encoder)) continue;
|
||||
LOGD("logging %s", it.name.c_str());
|
||||
const bool record_audio = (it.name == "rawAudioData") && Params().getBool("RecordAudio");
|
||||
if (it.should_log || (encoder && !livestream_encoder) || record_audio) {
|
||||
LOGD("logging %s", it.name.c_str());
|
||||
|
||||
SubSocket * sock = SubSocket::create(ctx.get(), it.name);
|
||||
assert(sock != NULL);
|
||||
poller->registerSocket(sock);
|
||||
service_state[sock] = {
|
||||
.name = it.name,
|
||||
.counter = 0,
|
||||
.freq = it.decimation,
|
||||
.encoder = encoder,
|
||||
.user_flag = it.name == "userFlag",
|
||||
};
|
||||
SubSocket * sock = SubSocket::create(ctx.get(), it.name);
|
||||
assert(sock != NULL);
|
||||
poller->registerSocket(sock);
|
||||
service_state[sock] = {
|
||||
.name = it.name,
|
||||
.counter = 0,
|
||||
.freq = it.decimation,
|
||||
.encoder = encoder,
|
||||
.user_flag = it.name == "userFlag",
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
LoggerdState s;
|
||||
|
||||
+15
-9
@@ -9,10 +9,10 @@ from openpilot.common.retry import retry
|
||||
from openpilot.common.swaglog import cloudlog
|
||||
|
||||
RATE = 10
|
||||
FFT_SAMPLES = 4096
|
||||
FFT_SAMPLES = 1600 # 100ms
|
||||
REFERENCE_SPL = 2e-5 # newtons/m^2
|
||||
SAMPLE_RATE = 44100
|
||||
SAMPLE_BUFFER = 4096 # approx 100ms
|
||||
SAMPLE_RATE = 16000
|
||||
SAMPLE_BUFFER = 800 # 50ms
|
||||
|
||||
|
||||
@cache
|
||||
@@ -45,7 +45,7 @@ def apply_a_weighting(measurements: np.ndarray) -> np.ndarray:
|
||||
class Mic:
|
||||
def __init__(self):
|
||||
self.rk = Ratekeeper(RATE)
|
||||
self.pm = messaging.PubMaster(['microphone'])
|
||||
self.pm = messaging.PubMaster(['soundPressure', 'rawAudioData'])
|
||||
|
||||
self.measurements = np.empty(0)
|
||||
|
||||
@@ -61,12 +61,12 @@ class Mic:
|
||||
sound_pressure_weighted = self.sound_pressure_weighted
|
||||
sound_pressure_level_weighted = self.sound_pressure_level_weighted
|
||||
|
||||
msg = messaging.new_message('microphone', valid=True)
|
||||
msg.microphone.soundPressure = float(sound_pressure)
|
||||
msg.microphone.soundPressureWeighted = float(sound_pressure_weighted)
|
||||
msg.microphone.soundPressureWeightedDb = float(sound_pressure_level_weighted)
|
||||
msg = messaging.new_message('soundPressure', valid=True)
|
||||
msg.soundPressure.soundPressure = float(sound_pressure)
|
||||
msg.soundPressure.soundPressureWeighted = float(sound_pressure_weighted)
|
||||
msg.soundPressure.soundPressureWeightedDb = float(sound_pressure_level_weighted)
|
||||
|
||||
self.pm.send('microphone', msg)
|
||||
self.pm.send('soundPressure', msg)
|
||||
self.rk.keep_time()
|
||||
|
||||
def callback(self, indata, frames, time, status):
|
||||
@@ -76,6 +76,12 @@ class Mic:
|
||||
|
||||
Logged A-weighted equivalents are rough approximations of the human-perceived loudness.
|
||||
"""
|
||||
msg = messaging.new_message('rawAudioData', valid=True)
|
||||
audio_data_int_16 = (indata[:, 0] * 32767).astype(np.int16)
|
||||
msg.rawAudioData.data = audio_data_int_16.tobytes()
|
||||
msg.rawAudioData.sampleRate = SAMPLE_RATE
|
||||
self.pm.send('rawAudioData', msg)
|
||||
|
||||
with self.lock:
|
||||
self.measurements = np.concatenate((self.measurements, indata[:, 0]))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user