@@ -75,10 +75,6 @@ def __init__(self):
7575
7676 self .spl_filter_weighted = FirstOrderFilter (0 , 2.5 , FILTER_DT , initialized = False )
7777
78- self ._webrtc_lock = threading .Lock ()
79- self ._webrtc_chunks : deque [np .ndarray ] = deque ()
80- self ._webrtc_size = 0
81-
8278 def load_sounds (self ):
8379 self .loaded_sounds : dict [int , np .ndarray ] = {}
8480
@@ -115,36 +111,10 @@ def get_sound_data(self, frames): # get "frames" worth of data from the current
115111
116112 return ret * self .current_volume
117113
118- def push_webrtc_audio (self , samples : np .ndarray ):
119- with self ._webrtc_lock :
120- if self ._webrtc_size > SAMPLE_RATE : # 1 second max buffer
121- self ._webrtc_chunks .clear ()
122- self ._webrtc_size = 0
123- self ._webrtc_chunks .append (samples )
124- self ._webrtc_size += samples .size
125-
126- def pop_webrtc_audio (self , frames : int ) -> np .ndarray :
127- out = np .zeros (frames , dtype = np .float32 )
128- written = 0
129- with self ._webrtc_lock :
130- while written < frames and self ._webrtc_chunks :
131- chunk = self ._webrtc_chunks [0 ]
132- take = min (frames - written , chunk .size )
133- out [written :written + take ] = chunk [:take ]
134- written += take
135- if take >= chunk .size :
136- self ._webrtc_chunks .popleft ()
137- else :
138- self ._webrtc_chunks [0 ] = chunk [take :]
139- self ._webrtc_size -= take
140- return out
141-
142114 def callback (self , data_out : np .ndarray , frames : int , time , status ) -> None :
143115 if status :
144116 cloudlog .warning (f"soundd stream over/underflow: { status } " )
145117 sound = self .get_sound_data (frames )
146- webrtc = self .pop_webrtc_audio (frames )
147- np .add (sound , webrtc , out = sound )
148118 np .clip (sound , - 1.0 , 1.0 , out = sound )
149119 data_out [:frames , 0 ] = sound
150120
@@ -181,27 +151,11 @@ def get_stream(self, sd):
181151 sd ._initialize ()
182152 return sd .OutputStream (channels = 1 , samplerate = SAMPLE_RATE , callback = self .callback , blocksize = SAMPLE_BUFFER )
183153
184- def _drain_webrtc_audio (self , webrtc_sock ):
185- """Drain all pending webrtcAudioData messages from the raw socket.
186- SubMaster only reads one message per socket per update(), which drops
187- ~60% of audio frames at the 20 Hz loop rate."""
188- while True :
189- raw = webrtc_sock .receive (non_blocking = True )
190- if raw is None :
191- break
192- evt = log .Event .from_bytes (raw )
193- raw_bytes = evt .webrtcAudioData .data
194- if len (raw_bytes ) > 0 :
195- pcm_float = np .frombuffer (raw_bytes , dtype = np .int16 ).astype (np .float32 )
196- pcm_float /= 32768.0
197- self .push_webrtc_audio (pcm_float )
198-
199154 def soundd_thread (self ):
200155 # sounddevice must be imported after forking processes
201156 import sounddevice as sd
202157
203158 sm = messaging .SubMaster (['selfdriveState' , 'soundPressure' , 'soundRequest' ])
204- webrtc_sock = messaging .sub_sock ('webrtcAudioData' )
205159
206160 with self .get_stream (sd ) as stream :
207161 rk = Ratekeeper (20 )
@@ -214,8 +168,6 @@ def soundd_thread(self):
214168 self .spl_filter_weighted .update (sm ["soundPressure" ].soundPressureWeightedDb )
215169 self .current_volume = self .calculate_volume (float (self .spl_filter_weighted .x ))
216170
217- self ._drain_webrtc_audio (webrtc_sock )
218-
219171 self .get_audible_alert (sm )
220172
221173 rk .keep_time ()
0 commit comments