Marsyas  0.6.0-alpha
/usr/src/RPM/BUILD/marsyas-0.6.0/src/marsyas/marsystems/Mono2Stereo.cpp
Go to the documentation of this file.
00001 /*
00002 ** Copyright (C) 1998-2007 George Tzanetakis <gtzan@cs.uvic.ca>
00003 **
00004 ** This program is free software; you can redistribute it and/or modify
00005 ** it under the terms of the GNU General Public License as published by
00006 ** the Free Software Foundation; either version 2 of the License, or
00007 ** (at your option) any later version.
00008 **
00009 ** This program is distributed in the hope that it will be useful,
00010 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012 ** GNU General Public License for more details.
00013 **
00014 ** You should have received a copy of the GNU General Public License
00015 ** along with this program; if not, write to the Free Software
00016 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00017 */
00018 
00019 
00020 #include "Mono2Stereo.h"
00021 
00022 using std::ostringstream;
00023 using namespace Marsyas;
00024 
00025 Mono2Stereo::Mono2Stereo(mrs_string name):MarSystem("Mono2Stereo", name)
00026 {
00027   //Add any specific controls needed by Mono2Stereo
00028   //(default controls all MarSystems should have
00029   //were already added by MarSystem::addControl(),
00030   //called by :MarSystem(name) constructor).
00031   //If no specific controls are needed by a MarSystem
00032   //there is no need to implement and call this addControl()
00033   //method (see for e.g. Rms.cpp)
00034   addControls();
00035 }
00036 
00037 Mono2Stereo::Mono2Stereo(const Mono2Stereo& a) : MarSystem(a)
00038 {
00039 }
00040 
00041 Mono2Stereo::~Mono2Stereo()
00042 {
00043 }
00044 
00045 MarSystem*
00046 Mono2Stereo::clone() const
00047 {
00048   return new Mono2Stereo(*this);
00049 }
00050 
00051 void
00052 Mono2Stereo::addControls()
00053 {
00054 }
00055 
00056 void
00057 Mono2Stereo::myUpdate(MarControlPtr sender)
00058 {
00059   (void) sender;  //suppress warning of unused parameter(s)
00060   setctrl("mrs_natural/onSamples", getctrl("mrs_natural/onSamples"));
00061 
00062   mrs_natural inObservations = getctrl("mrs_natural/inObservations")->to<mrs_natural>();
00063 
00064   if (inObservations == 1)
00065   {
00066     setctrl("mrs_natural/onObservations", 2);
00067     mrs_string inObsNames = getctrl("mrs_string/inObsNames")->to<mrs_string>();
00068     inObsNames += ",";
00069     inObsNames += inObsNames;
00070     setctrl("mrs_string/onObsNames", inObsNames);
00071   }
00072   else
00073   {
00074     setctrl("mrs_natural/onObservations", inObservations);
00075     setctrl("mrs_string/onObsNames", getctrl("mrs_string/inObsNames"));
00076   }
00077   setctrl("mrs_real/osrate", getctrl("mrs_real/israte"));
00078 
00079 
00080 
00081 
00082 }
00083 
00084 
00085 void
00086 Mono2Stereo::myProcess(realvec& in, realvec& out)
00087 {
00088   mrs_natural t,o;
00089   if (inObservations_ != 1)     // not mono - just pass through
00090   {
00091     for (o=0; o < inObservations_; o++)
00092     {
00093       for (t = 0; t < inSamples_; t++)
00094       {
00095         out(o,t) = in(o,t);
00096       }
00097     }
00098   }
00099 
00100   else // mono to stereo
00101   {
00102     for (o=0; o < onObservations_; o++)
00103       for (t = 0; t < inSamples_; t++)
00104       {
00105         out(o,t) = in(0,t);
00106       }
00107 
00108   }
00109 
00110 
00111 }
00112 
00113 
00114 
00115 
00116 
00117 
00118 
00119