From 742358134db3c967a5207e8b437ddb656ea0e98f Mon Sep 17 00:00:00 2001
From: Nicolas Pope <nwpope@utu.fi>
Date: Wed, 29 Jul 2020 13:02:39 +0300
Subject: [PATCH] Fix incorrect track mapping in audio mix

---
 components/streams/src/renderers/screen_render.cpp | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/components/streams/src/renderers/screen_render.cpp b/components/streams/src/renderers/screen_render.cpp
index b9b5bb737..37c46a717 100644
--- a/components/streams/src/renderers/screen_render.cpp
+++ b/components/streams/src/renderers/screen_render.cpp
@@ -155,18 +155,19 @@ bool ScreenRender::retrieve(ftl::data::Frame &frame_out) {
 			for (auto &s : sets) {
 				if (s->frameset() == my_id_) continue;  // Skip self
 
-				auto &mixmap = mixmap_[s->id().id];
-				if (mixmap.track == -1) mixmap.track = tracks_++;
-
 				// TODO: Render audio also...
 				// Use another thread to merge all audio channels along with
 				// some degree of volume adjustment. Later, do 3D audio.
-				mixer_.resize(tracks_);
+				//mixer_.resize(tracks_);
 
 				// Inject and copy data items
 				for (size_t i=0; i<s->frames.size(); ++i) {
 					auto &f = s->frames[i];
 
+					auto &mixmap = mixmap_[f.id().id];
+					if (mixmap.track == -1) mixmap.track = tracks_++;
+					mixer_.resize(tracks_);
+
 					if (mixmap.last_timestamp != f.timestamp() && f.hasChannel(Channel::AudioStereo)) {
 						const auto &audio = f.get<std::list<ftl::audio::Audio>>(Channel::AudioStereo).front();
 						mixer_.write(mixmap.track, audio.data());
-- 
GitLab