00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include "Resample.h"
00020
00021 using namespace std;
00022 using namespace Marsyas;
00023
00033 Resample::Resample(mrs_string name):MarSystem("Resample", name)
00034 {
00035
00036
00037
00038
00039
00040
00041
00042
00043 interpolator_=new ResampleLinear("resa");
00044 addControls();
00045 }
00046
00047 Resample::Resample(const Resample& orig) : MarSystem(orig)
00048 {
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081 ctrl_offStart_ = getctrl("mrs_real/offStart");
00082 ctrl_offEnd_ = getctrl("mrs_real/offEnd");
00083 ctrl_option_ = getctrl("mrs_bool/option");
00084 ctrl_resamplingMode_ = getctrl("mrs_string/resamplingMode");
00085 ctrl_samplingRateAdjustmentMode_ = getctrl("mrs_bool/samplingRateAdjustmentMode");
00086 ctrl_newSamplingRate_ = getctrl("mrs_real/newSamplingRate");
00087
00088
00089
00090
00091
00092
00093 interpolator_=orig.interpolator_->clone();
00094 }
00095
00096 Resample::~Resample()
00097 {
00098
00099 delete interpolator_;
00100 }
00101
00102 MarSystem*
00103 Resample::clone() const
00104 {
00105 return new Resample(*this);
00106 }
00107
00108
00109 void
00110 Resample::addControls()
00111 {
00112
00113 addctrl("mrs_real/offStart", 0.0, ctrl_offStart_);
00114 addctrl("mrs_real/offEnd", 0.0, ctrl_offEnd_);
00115 addctrl("mrs_bool/samplingRateAdjustmentMode", (mrs_bool)true , ctrl_samplingRateAdjustmentMode_);
00116 addctrl("mrs_string/resamplingMode", "linear" , ctrl_resamplingMode_);
00117 addctrl("mrs_bool/option", (mrs_bool)false , ctrl_option_);
00118 addctrl("mrs_real/newSamplingRate", 22050.0 , ctrl_newSamplingRate_);
00119
00120
00121
00122 setctrlState("mrs_bool/samplingRateAdjustmentMode",(mrs_bool)true);
00123 setctrlState("mrs_real/newSamplingRate",(mrs_bool)true);
00124 setctrlState("mrs_string/resamplingMode",(mrs_bool)true);
00125 }
00126
00127 void
00128 Resample::myUpdate(MarControlPtr sender)
00129 {
00130 MarSystem::myUpdate(sender);
00131
00132
00133 mrs_real alpha = ctrl_newSamplingRate_->to<mrs_real>()/ctrl_israte_->to<mrs_real>();
00134
00135 ctrl_onSamples_->setValue((mrs_natural) (alpha * ctrl_inSamples_->to<mrs_natural>()), NOUPDATE);
00136 ctrl_onObservations_->setValue(ctrl_inObservations_->to<mrs_natural>());
00137 if (!(ctrl_samplingRateAdjustmentMode_->to<mrs_bool>()))
00138 {
00139 alpha=1.0;
00140 }
00141
00142 ctrl_osrate_->setValue(ctrl_israte_->to<mrs_real>()*alpha);
00143
00144 mrs_string inObsNames = ctrl_inObsNames_->to<mrs_string>();
00145
00146
00147
00148
00149 mrs_string resaMode=ctrl_resamplingMode_->to<mrs_string>();
00150
00151
00152
00153
00154
00155 delete interpolator_;
00156 if (resaMode==(mrs_string)"sincip")
00157 {
00158 interpolator_= new ResampleSinc("resa");
00159 interpolator_->updControl("mrs_bool/windowedMode", ctrl_option_->to<mrs_bool>());
00160 interpolator_->updControl("mrs_real/offStart", ctrl_offStart_->to<mrs_real>());
00161 interpolator_->updControl("mrs_real/offEnd", ctrl_offEnd_->to<mrs_real>());
00162 interpolator_->updControl("mrs_bool/samplingRateAdjustmentMode", ctrl_samplingRateAdjustmentMode_->to<mrs_bool>());
00163 interpolator_->updControl("mrs_real/stretch", ctrl_newSamplingRate_->to<mrs_real>()/ctrl_israte_->to<mrs_real>());
00164 }
00165 else if (resaMode==(mrs_string) "bezier")
00166 {
00167 interpolator_= new ResampleBezier("resa");
00168 interpolator_->updControl("mrs_bool/tangentMode", ctrl_option_);
00169 interpolator_->updControl("mrs_real/offStart", ctrl_offStart_->to<mrs_real>());
00170 interpolator_->updControl("mrs_real/offEnd", ctrl_offEnd_->to<mrs_real>());
00171 interpolator_->updControl("mrs_bool/samplingRateAdjustmentMode", ctrl_samplingRateAdjustmentMode_->to<mrs_bool>());
00172 interpolator_->updControl("mrs_real/stretch", ctrl_newSamplingRate_->to<mrs_real>()/ctrl_israte_->to<mrs_real>());
00173 }
00174 else if (resaMode==(mrs_string) "near")
00175 {
00176 interpolator_= new ResampleNearestNeighbour("resa");
00177
00178
00179 interpolator_->updControl("mrs_bool/samplingRateAdjustmentMode", ctrl_samplingRateAdjustmentMode_->to<mrs_bool>());
00180 interpolator_->updControl("mrs_real/stretch", ctrl_newSamplingRate_->to<mrs_real>()/ctrl_israte_->to<mrs_real>());
00181 }
00182 else
00183 {
00184 interpolator_= new ResampleLinear("resa");
00185
00186
00187 interpolator_->updControl("mrs_bool/samplingRateAdjustmentMode", ctrl_samplingRateAdjustmentMode_->to<mrs_bool>());
00188 interpolator_->updControl("mrs_real/stretch", ctrl_newSamplingRate_->to<mrs_real>()/ctrl_israte_->to<mrs_real>());
00189 }
00190
00191
00192
00193
00194 }
00195
00196
00197 void
00198 Resample::myProcess(realvec& in, realvec& out)
00199 {
00200 interpolator_->process(in,out);
00201 }