Skip to content

Commit 17d03b6

Browse files
committed
fix spatial tracks outputting non-spatialized audio when the listener is dropped
1 parent e1913bf commit 17d03b6

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

crates/kira/src/track/sub.rs

+18
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ impl Track {
138138
parent_spatial_track_info: Option<SpatialTrackInfo>,
139139
send_tracks: &mut ResourceStorage<SendTrack>,
140140
) {
141+
// get info
141142
let spatial_track_info = self
142143
.spatial_data
143144
.as_ref()
@@ -152,11 +153,14 @@ impl Track {
152153
&listeners.0.resources,
153154
spatial_track_info,
154155
);
156+
157+
// update volume parameters
155158
self.volume.update(dt * out.len() as f64, &info);
156159
for (_, route) in &mut self.sends {
157160
route.volume.update(dt * out.len() as f64, &info);
158161
}
159162

163+
// update playback state
160164
let changed_playback_state = self
161165
.playback_state_manager
162166
.update(dt * out.len() as f64, &info);
@@ -169,6 +173,8 @@ impl Track {
169173
}
170174

171175
let num_frames = out.len();
176+
177+
// process sub tracks
172178
for (_, sub_track) in &mut self.sub_tracks {
173179
sub_track.process(
174180
&mut self.temp_buffer[..out.len()],
@@ -184,16 +190,22 @@ impl Track {
184190
}
185191
self.temp_buffer.fill(Frame::ZERO);
186192
}
193+
194+
// process sounds
187195
for (_, sound) in &mut self.sounds {
188196
sound.process(&mut self.temp_buffer[..out.len()], dt, &info);
189197
for (summed_out, sound_out) in out.iter_mut().zip(self.temp_buffer.iter().copied()) {
190198
*summed_out += sound_out;
191199
}
192200
self.temp_buffer.fill(Frame::ZERO);
193201
}
202+
203+
// apply effects
194204
for effect in &mut self.effects {
195205
effect.process(out, dt, &info);
196206
}
207+
208+
// apply spatialization
197209
if let Some(spatial_data) = &mut self.spatial_data {
198210
spatial_data.position.update(dt * out.len() as f64, &info);
199211
spatial_data
@@ -212,9 +224,13 @@ impl Track {
212224
interpolated_orientation.into(),
213225
time_in_chunk,
214226
);
227+
} else {
228+
*frame = Frame::ZERO;
215229
}
216230
}
217231
}
232+
233+
// apply volume fade
218234
for (i, frame) in out.iter_mut().enumerate() {
219235
let time_in_chunk = (i + 1) as f64 / num_frames as f64;
220236
let volume = self.volume.interpolated_value(time_in_chunk).as_amplitude();
@@ -224,6 +240,8 @@ impl Track {
224240
.as_amplitude();
225241
*frame *= volume * fade_volume;
226242
}
243+
244+
// output to send tracks
227245
for (send_track_id, SendTrackRoute { volume, .. }) in &self.sends {
228246
let Some(send_track) = send_tracks.get_mut(send_track_id.0) else {
229247
continue;

0 commit comments

Comments
 (0)