Ok, here we go...

This is a (not cleaned up, yet!) patch, so you can change the mixer like
I did... I hope it doesn't break anything (so please carefully test it
before applying it to the git master...). I esp. did not wipe the old
code but only #if-ed it out...

cu (and have fun!)
Stefan

PS: If it crystalizes out that the patch will be accepted, I will be
very happy to submit a cleaner version... (or maybe getting write-access
to the repo? ... Well, due to strong restrictions in my spare-time you
should not expect to see too much noise from me anyways... ;-))...

diff --git a/include/FxMixer.h b/include/FxMixer.h
index 660d2ea..6b47d2c 100644
--- a/include/FxMixer.h
+++ b/include/FxMixer.h
@@ -63,7 +63,7 @@ class FxChannel : public ThreadableJob
 
 		virtual bool requiresProcessing() const { return true; }
 
-	private:
+//	private:
 		virtual void doProcessing( sampleFrame * _working_buffer );
 };
 
diff --git a/src/core/FxMixer.cpp b/src/core/FxMixer.cpp
index ce43d71..7544058 100644
--- a/src/core/FxMixer.cpp
+++ b/src/core/FxMixer.cpp
@@ -59,6 +59,7 @@ FxChannel::~FxChannel()
 }
 
 
+#include <iostream>
 
 void FxChannel::doProcessing( sampleFrame * _buf )
 {
@@ -74,6 +75,15 @@ void FxChannel::doProcessing( sampleFrame * _buf )
 	// <tobydox> this improves cache hit rate
 	_buf = m_buffer;
 
+  // SMF: OK, due to the fact, that the data from the audio-tracks has been 
+  //      written into our buffer already, all which needs to be done at this
+  //      stage is to process inter-channel sends. I really don't like the idea
+  //      of using threads for this -- it just doesn't make any sense and wastes
+  //      cpu-cylces... so I just go through every child of this channel and
+  //      call the acc. doProcessing() directly. 
+
+  // Take the old code out of business without erasing it, just for now...
+  #if 0
 	if( ! m_muteModel.value() )
 	{
 		// do mixer sends. loop through the channels that send to this one
@@ -82,6 +92,9 @@ void FxChannel::doProcessing( sampleFrame * _buf )
 			fx_ch_t senderIndex = m_receives[i];
 			FxChannel * sender = fxm->effectChannel(senderIndex);
 
+      std::cerr << "channel: " << m_name.toStdString();
+      std::cerr << " input:" << sender->m_name.toStdString() << "\n";
+
 			// mix it with this one
 			float amt = fxm->channelSendModel(senderIndex,
 											  m_channelIndex)->value();
@@ -126,7 +139,48 @@ void FxChannel::doProcessing( sampleFrame * _buf )
 			}
 		}
 	}
+#else
+  // the new code ... this does not click any more...
+
+	if( ! m_muteModel.value() )
+	{
+    // OK, we are not muted, so we go recursively through all the channels 
+    // which send to us (our "childs")...
+		for( int i = 0; i < m_receives.size(); ++i)
+		{
+      // we must assume that these are _not_ ready, already, so we trigger their
+      // doProcessing from here...
+
+			fx_ch_t senderIndex = m_receives[i];
+			FxChannel * sender = fxm->effectChannel(senderIndex);
 
+      // run that channels doProcessing() if it was not run before...
+      if( sender->m_state != ThreadableJob::Done )
+      {
+        sender->doProcessing( NULL );
+      }
+
+			// mix it's output with this one's output (this was segfaulting in the 
+      // first version -- I'm rather clueless why this happend...)
+      float amt = fxm->channelSendModel(senderIndex,
+											        m_channelIndex)->value();
+
+			CPU::bufMixCoeff( _buf, sender->m_buffer,
+								sender->m_volumeModel.value() * amt, fpp );
+    }
+  }
+
+	const float v = m_volumeModel.value();
+
+	m_fxChain.startRunning();
+	m_stillRunning = m_fxChain.processAudioBuffer( _buf, fpp );
+	m_peakLeft = engine::getMixer()->peakValueLeft( _buf, fpp ) * v;
+	m_peakRight = engine::getMixer()->peakValueRight( _buf, fpp ) * v;
+
+  // Ok, we do not really use threads here... but the flag is fine... ;-)
+  m_state = ThreadableJob::Done;
+
+#endif
 }
 
 
@@ -418,6 +472,15 @@ FloatModel * FxMixer::channelSendModel(fx_ch_t fromChannel, fx_ch_t toChannel)
 
 void FxMixer::mixToChannel( const sampleFrame * _buf, fx_ch_t _ch )
 {
+  // SMF: it seems like here the track-channels are mixed in... but from where
+  //      is this called and when and why...?!?
+  //
+  //      OK, found it (git grep is your friend...): This is the next part, 
+  //      where there is a mix between push and pull model inside the core, as
+  //      the audio-tracks *push* their data into the fx-channels hopefully just
+  //      before the Mixer-Channels are processed... Sorry to say this: but this
+  //      took me senseless hours to find out and is silly, too...
+
 	if( m_fxChannels[_ch]->m_muteModel.value() == false )
 	{
 		m_fxChannels[_ch]->m_lock.lock();
@@ -476,12 +539,18 @@ void FxMixer::masterMix( sampleFrame * _buf )
 	// and add all channels to job list that have no dependencies
 	// when the channel completes it will check its parent to see if it needs
 	// to be processed.
+
+  #if 0
 	MixerWorkerThread::resetJobQueue( MixerWorkerThread::JobQueue::Dynamic );
 	addChannelLeaf( 0, _buf );
 	while( m_fxChannels[0]->state() != ThreadableJob::Done )
 	{
 		MixerWorkerThread::startAndWaitForJobs();
 	}
+  #else
+  // SMF: unlike before just trigger the first channel (Master)...
+  m_fxChannels[0]->doProcessing( NULL );
+  #endif
 
 	memcpy( _buf, m_fxChannels[0]->m_buffer, sizeof( sampleFrame ) * fpp );
 
------------------------------------------------------------------------------
ThinkGeek and WIRED's GeekDad team up for the Ultimate 
GeekDad Father's Day Giveaway. ONE MASSIVE PRIZE to the 
lucky parental unit.  See the prize list and enter to win: 
http://p.sf.net/sfu/thinkgeek-promo
_______________________________________________
LMMS-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/lmms-devel

Reply via email to