00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031 #include "syn/Module/MixerModule.h"
00032 #include <syn/Stream/SampleBufferIStream.h>
00033
00034 namespace syn
00035 {
00036 MixerModule::MixerModule() : Module(), mIsOpen( false ), mWriteBuf( NULL )
00037 {
00038 this->createOutput( "output" );
00039
00040 bool result = this->getOutput( "output", mTerminal );
00041 assert( result && "this isn't right" );
00042 }
00043
00044 bool MixerModule::open()
00045 {
00046 mIsOpen = true;
00047 return mIsOpen;
00048 }
00049
00050 void MixerModule::close()
00051 {
00052 mIsOpen = false;
00053 }
00054
00056 bool MixerModule::areInputsDone()
00057 {
00058 std::map<std::string, TerminalPtr>::const_iterator input_itr;
00059 for (input_itr = this->inputs().begin(); input_itr != this->inputs().end(); ++input_itr)
00060 {
00061
00062 if (!(*input_itr).second->done())
00063 return false;
00064 }
00065
00066 return true;
00067 }
00068
00070 bool MixerModule::needToWait()
00071 {
00072 std::map<std::string, TerminalPtr>::const_iterator input_itr;
00073 for (input_itr = this->inputs().begin(); input_itr != this->inputs().end(); ++input_itr)
00074 {
00075 if ((*input_itr).second->empty() && !(*input_itr).second->done())
00076 return true;
00077 }
00078
00079 return false;
00080 }
00081
00082 void MixerModule::update()
00083 {
00084 mPutCount = 0;
00085
00087 if (this->needToWait())
00088 {
00089
00090 return;
00091 }
00092
00093
00094 if (mWriteBuf == NULL)
00095 {
00096
00097
00098 std::list<TerminalPtr> terms;
00099 {
00100 std::map<std::string, TerminalPtr>::iterator input_itr;
00101 for (input_itr = this->inputs().begin(); input_itr != this->inputs().end(); ++input_itr)
00102 {
00103 TerminalPtr input_term = (*input_itr).second;
00104 if (!input_term->empty())
00105 {
00106 terms.push_back( (*input_itr).second );
00107
00108 }
00109 }
00110 if (terms.size() == 0)
00111 return;
00112 }
00113
00114
00115 std::list<TerminalPtr>::iterator input_itr = terms.begin();
00116
00117
00118
00119 mWriteBuf = (*input_itr)->front();
00120 (*input_itr)->pop();
00121 ++input_itr;
00122
00123
00124 mPutCount = mWriteBuf->size();
00125
00126
00127
00128
00129 for (; input_itr != terms.end(); ++input_itr)
00130 {
00131 TerminalPtr input_term = (*input_itr);
00132 if (!input_term->empty())
00133 {
00134 SampleBuffer1f* read_buf = input_term->front();
00135
00136
00137 (*mWriteBuf) += (*read_buf);
00138
00139
00140 SampleBufferRepos::instance()->putback( read_buf );
00141 input_term->pop();
00142 }
00143 }
00144
00145
00146
00147 }
00148
00149 mTerminal->setDone( false );
00150
00151
00152 if (!mTerminal->high())
00153 {
00154 mTerminal->push( mWriteBuf );
00155 mWriteBuf = NULL;
00156 }
00157 }
00158 }