Marsyas
0.6.0-alpha
|
00001 /* 00002 ** Copyright (C) 1998-2006 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 #include "LPCC.h" 00020 #include "../common_source.h" 00021 00022 using std::ostringstream; 00023 using namespace Marsyas; 00024 00025 LPCC::LPCC(mrs_string name):MarSystem("LPCC",name) 00026 { 00027 addControls(); 00028 } 00029 00030 LPCC::LPCC(const LPCC& a) : MarSystem(a) 00031 { 00032 ctrl_order_ = getctrl("mrs_natural/order"); 00033 } 00034 00035 LPCC::~LPCC() 00036 { 00037 } 00038 00039 MarSystem* 00040 LPCC::clone() const 00041 { 00042 return new LPCC(*this); 00043 } 00044 00045 void 00046 LPCC::addControls() 00047 { 00048 //read-only 00049 addctrl("mrs_natural/order", 1, ctrl_order_); 00050 } 00051 00052 void 00053 LPCC::myUpdate(MarControlPtr sender) 00054 { 00055 (void) sender; //suppress warning of unused parameter(s) 00056 MRSDIAG("LPCC.cpp - LPCC:myUpdate"); 00057 00058 ctrl_onSamples_->setValue(ctrl_inSamples_); 00059 ctrl_osrate_->setValue(ctrl_israte_, NOUPDATE); 00060 00061 // output nr of observations (i.e. LPCC coefficients) is equal 00062 // to the number of LPC coefs (LPC coeffs - 1 pitch coeff - 1 power) 00063 mrs_natural order = ctrl_inObservations_->to<mrs_natural>() - 2; 00064 ctrl_order_->setValue(order, NOUPDATE); 00065 ctrl_onObservations_->setValue(order, NOUPDATE); 00066 00067 //LPCC features names 00068 ostringstream oss; 00069 for (mrs_natural i = 0; i < ctrl_order_->to<mrs_natural>(); ++i) 00070 oss << "LPCC_" << i+1 << ","; 00071 ctrl_onObsNames_->setValue(oss.str(), NOUPDATE); 00072 00073 tmp_.create(ctrl_onObservations_->to<mrs_natural>()+1, ctrl_onSamples_->to<mrs_natural>()); 00074 } 00075 00076 void 00077 LPCC::myProcess(realvec& in, realvec& out) 00078 { 00079 mrs_real sum; 00080 mrs_natural order = ctrl_order_->to<mrs_natural>(); 00081 00082 //************************************************************************ 00083 // Based on: 00084 // http://www.mathworks.com/access/helpdesk/ 00085 // help/toolbox/dspblks/index.html?/access/helpdesk/help/toolbox/dspblks/ 00086 // lpctofromcepstralcoefficients.html 00087 //************************************************************************ 00088 tmp_.setval(0.0); 00089 tmp_(0) = -log(in(order+1)); //[!][?] 00090 for (mrs_natural m = 1; m <= order; m++) 00091 { 00092 sum = 0.0; 00093 for (mrs_natural k=1; k <= m-1; k++) 00094 sum = sum + (mrs_real)(m-k) * in(k-1) * tmp_(m-k); 00095 tmp_(m) = +in(m-1) + sum / (mrs_real)m; 00096 00097 out(m-1) = tmp_(m);//drop c0 => output only [c1 c2 c3 ... cp] 00098 } 00099 00100 //MATLAB_PUT(in, "LPCC_in"); 00101 //MATLAB_PUT(out, "LPCC_out"); 00102 //MATLAB_EVAL("LPCC_test"); 00103 }