本文整理汇总了C++中Ports类的典型用法代码示例。如果您正苦于以下问题:C++ Ports类的具体用法?C++ Ports怎么用?C++ Ports使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Ports类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: process
bool Flux::process(Ports<InputBuffer*>& inp, Ports<OutputBuffer*>& outp)
{
assert(inp.size()==1);
InputBuffer* in = inp[0].data;
assert(outp.size()==1);
OutputBuffer* out = outp[0].data;
if ((out->tokenno()==0) && (in->tokenno()!=-1))
in->prependZeros(1);
if (!in->hasTokens(2))
return false;
const int N = in->info().size;
double lastNorm = 0.0;
double nextNorm = Map<VectorXd>(in->token(0),N).norm();
while (in->hasTokens(2))
{
Map<VectorXd> last(in->token(0),N);
lastNorm = nextNorm;
Map<VectorXd> next(in->token(1),N);
nextNorm = next.norm();
double* output = out->writeToken();
if (lastNorm*nextNorm==0)
*output = 0.0;
else if (m_onlyIncrease)
*output = (next-last).unaryExpr(filterNegativeOp<double>()).squaredNorm() / (lastNorm*nextNorm);
else
*output = (next - last).squaredNorm() / (lastNorm * nextNorm);
in->consumeToken();
}
return true;
}
示例2: process
bool Variation::process(Ports<InputBuffer*>& inp, Ports<OutputBuffer*>& outp)
{
assert(inp.size()==1);
InputBuffer* in = inp[0].data;
if (!in->hasTokens(2)) return false;
assert(outp.size()==1);
OutputBuffer* out = outp[0].data;
if ((out->tokenno()==0) && (in->tokenno()!=-1))
in->prependZeros(1);
const int N = in->info().size;
double lastNorm = 0.0;
double nextNorm = Map<VectorXd>(in->token(0),N).norm();
while (in->hasTokens(2))
{
Map<VectorXd> last(in->token(0),N);
lastNorm = nextNorm;
Map<VectorXd> next(in->token(1),N);
nextNorm = next.norm();
if (lastNorm*nextNorm !=0)
lastNorm = 1 - last.dot(next) / (lastNorm * nextNorm);
else
lastNorm = 0.0;
out->write(&lastNorm,1);
in->consumeToken();
}
return true;
}
示例3: process
bool ComplexDomainFlux::process(Ports<InputBuffer*>& inp, Ports<OutputBuffer*>& outp)
{
assert(inp.size()==1);
InputBuffer* in = inp[0].data;
assert(outp.size()==1);
OutputBuffer* out = outp[0].data;
if ((out->tokenno()==0) && (in->tokenno()!=-2))
in->prependZeros(2);
if (!in->hasTokens(3)) return false;
const int N = in->info().size/2;
ArrayXcd inPredPredRotator(N);
ArrayXcd inPredRotator(N);
rotatorOp<double> op;
{
Map<ArrayXcd> inPredPredData((complex<double>*) in->token(0),N);
inPredPredRotator = inPredPredData.unaryExpr(op);
}
while (in->hasTokens(3))
{
Map<ArrayXcd> inPredData((complex<double>*) in->token(1),N);
Map<ArrayXcd> inData((complex<double>*) in->token(2), N);
inPredRotator = inPredData.unaryExpr(op);
double* output = out->writeToken();
*output++ = (inData - (inPredData * (inPredRotator * inPredPredRotator.conjugate()))).abs().sum();
in->consumeToken();
inPredPredRotator.swap(inPredRotator);
}
return true;
}
示例4: process
bool SpectralCrestFactorPerBand::process(Ports<InputBuffer*>& inp, Ports<OutputBuffer*>& outp)
{
assert(inp.size()==1);
InputBuffer* in = inp[0].data;
if (in->empty()) return false;
assert(outp.size()==1);
OutputBuffer* out = outp[0].data;
int nbBands = m_band.size();
double* tmp = new double[in->info().size];
while (!in->empty())
{
double* inData = in->readToken();
double* output = out->writeToken();
for (int k=0;k<nbBands;++k)
{
bandinfo& bi = m_band[k];
double* data = &inData[bi.start];
int datalen = bi.length();
if (bi.group>1) // grpsize > 1
{
data = tmp;
datalen /= bi.group;
double* ptr = &inData[bi.start];
for (int d=0;d<datalen;d++) {
double s = 0;
for (int g=0;g<bi.group;g++)
s += *ptr++;
data[d] = s;
}
}
double am = 0;
double maxdata = data[0];
for (int i=0;i<datalen;i++)
{
am += data[i];
if (data[i]>maxdata) {
maxdata = data[i];
}
}
if (am!=0) {
output[k] = maxdata * datalen / am;
continue;
}
output[k] = maxdata / EPS;
}
in->consumeToken();
}
delete [] tmp;
return true;
}
示例5: log
bool Logger::unreportComponent( const std::string& component ) {
TaskContext* comp = this->getPeer(component);
if (!comp)
{
log(Error) << "no such component " << component << endlog();
return false;
}
Ports ports = comp->ports()->getPorts();
for (Ports::iterator it = ports.begin(); it != ports.end() ; ++it) {
this->unreportPort(component, (*it)->getName());
}
return true;
}
示例6: process
bool AudioFileReader::process(Ports<InputBuffer*>& inp, Ports<OutputBuffer*>& outp)
{
assert(inp.size()==0);
assert(outp.size()==1);
OutputBuffer* out = outp[0].data;
int nbRead = readFramesIntoBuffer();
if (nbRead==0)
return false;
if (m_rescale)
for (int i=0;i<nbRead;i++)
m_readBuffer[i] = (m_readBuffer[i] - m_mean) * m_factor;
out->write(m_readBuffer,nbRead);
return true;
}
示例7: init
bool FrameTokenizer::init(const ParameterMap& params, const Ports<StreamInfo>& inp)
{
assert(inp.size()==1);
const StreamInfo& in = inp[0].data;
if (in.size > 1)
{
cerr << "ERROR: input of FrameTokenizer should be of size 1" << endl;
return false;
}
m_blockSize = getIntParam("blockSize", params);
if (m_blockSize<=0) {
cerr << "ERROR: invalid blockSize parameter !" << endl;
}
m_stepSize = getIntParam("stepSize", params);
if (m_stepSize<=0) {
cerr << "ERROR: invalid stepSize parameter !" << endl;
return false;
}
outStreamInfo().add(StreamInfo());
StreamInfo& outInfo = outStreamInfo()[0].data;
outInfo.sampleRate = in.sampleRate;
outInfo.frameLength = m_blockSize * in.frameLength;
outInfo.sampleStep = m_stepSize * in.sampleStep;
outInfo.size = m_blockSize;
return true;
}
示例8: flush
void FrameTokenizer::flush(Ports<InputBuffer*>& inp, Ports<OutputBuffer*>& outp)
{
assert(inp.size()==1);
InputBuffer* in = inp[0].data;
in->appendZeros((m_blockSize-1)/2);
process(inp,outp);
}
示例9: init
bool Variation::init(const ParameterMap& params, const Ports<StreamInfo>& inp)
{
assert(inp.size()==1);
const StreamInfo& in = inp[0].data;
outStreamInfo().add(StreamInfo(in,1));
return true;
}
示例10: assert
bool AC2LPC::process(Ports<InputBuffer*>& inp, Ports<OutputBuffer*>& outp)
{
assert(inp.size()==1);
InputBuffer* in = inp[0].data;
assert(outp.size()==1);
OutputBuffer* out = outp[0].data;
assert(out->info().size==m_nbCoeffs);
assert(in->info().size>m_nbCoeffs);
while (!in->empty())
{
ac2lpc(in->readToken(),out->writeToken(),m_nbCoeffs);
in->consumeToken();
}
return true;
}
示例11: init
bool CSVWriter::init(const ParameterMap& params, const Ports<StreamInfo>& inp)
{
assert(inp.size()==1);
const StreamInfo& in = inp[0].data;
string outputFile = getStringParam("File", params);
m_precision = getIntParam("Precision",params);
if (m_precision > (BUFSIZE-10)) {
cerr << "WARNING: precision is too large ! use precision " << BUFSIZE - 10 << endl;
m_precision = BUFSIZE - 10;
}
int res = preparedirs(outputFile.c_str());
if (res!=0)
return false;
m_fout.open(outputFile.c_str(), ios_base::trunc);
if (!m_fout.is_open() || m_fout.bad())
return false;
if (getStringParam("Metadata",params)=="True") {
// write metadata at the beginnig of the file
string paramStr = getStringParam("Attrs",params);
map<string,string> params = decodeAttributeStr(paramStr);
ostringstream oss;
for (map<string,string>::const_iterator it=params.begin();it!=params.end();it++)
oss << "% " << it->first << "=" << it->second << endl;
m_fout.write(oss.str().c_str(),oss.str().size());
}
return true;
}
示例12: init
bool MelFilterBank::init(const ParameterMap& params, const Ports<StreamInfo>& inp)
{
assert(inp.size()==1);
const StreamInfo& in = inp[0].data;
// build mel filter bank
m_size = in.size;
int nbMelFilters = getIntParam("MelNbFilters",params);
double sampleRate = in.sampleRate;
double freqMin = getDoubleParam("MelMinFreq",params);
double freqMax = getDoubleParam("MelMaxFreq",params);
// set freqMax to Nyquist frequency if greater than nyquist frequency
freqMax = min(freqMax, sampleRate/2.0);
double melFreqMin = 1127 * log(1 + freqMin / 700);
double melFreqMax = 1127 * log(1 + freqMax / 700);
VectorXd melPeak(nbMelFilters+2);
VectorXd freqs(nbMelFilters+2);
melPeak = VectorXd::LinSpaced(nbMelFilters+2,melFreqMin,melFreqMax);
freqs = ((melPeak / 1127).array().exp() - 1.0) * 700.0;
VectorXd fftFreqs(m_size);
fftFreqs = VectorXd::LinSpaced(m_size,0,m_size-1) * sampleRate / ((m_size-1)*2);
for (int b=1;b<nbMelFilters+1;b++)
{
double norm = 2.0 / (freqs(b+1)-freqs(b-1));
VectorXd fullfilt(m_size);
// fullfilt.setZero(m_size);
// firstIndex i;
// fullfilt += where((fftFreqs(i)>freqs(b-1)) && (fftFreqs(i)<=freqs(b)),norm*(fftFreqs(i)-freqs(b-1))/(freqs(b)-freqs(b-1)),0.0);
// fullfilt += where((fftFreqs(i)>freqs(b)) && (fftFreqs(i)<freqs(b+1)),norm*(freqs(b+1)-fftFreqs(i))/(freqs(b+1)-freqs(b)),0.0);
double ffmin = freqs(b-1);
double ffmiddle = freqs(b);
double ffmax = freqs(b+1);
for (int i=0;i<m_size;i++) {
if ((fftFreqs(i)<ffmin) || (fftFreqs(i)>ffmax)) {
fullfilt(i) = 0;
continue;
}
if (fftFreqs(i)<ffmiddle)
fullfilt(i) = norm*(fftFreqs(i)-ffmin)/(ffmiddle-ffmin);
else
fullfilt(i) = norm*(ffmax-fftFreqs(i))/(ffmax-ffmiddle);
}
int fStart=0;
while (fullfilt(fStart)==0.0) fStart++;
int fEnd=fStart+1;
while ((fEnd<m_size) && (fullfilt(fEnd)!=0.0)) fEnd++;
m_filterStart.push_back(fStart);
m_filters.push_back(RowVectorXd());
m_filters.back() = fullfilt.segment(fStart,fEnd-fStart);
}
outStreamInfo().add(StreamInfo(in, m_filters.size()));
return true;
}
示例13: getIntParam
bool AC2LPC::init(const ParameterMap& params, const Ports<StreamInfo>& inp)
{
assert(inp.size()==1);
const StreamInfo& in = inp[0].data;
m_nbCoeffs = getIntParam("LPCNbCoeffs",params);
outStreamInfo().add(StreamInfo(in,m_nbCoeffs));
return true;
}
示例14: init
bool Flux::init(const ParameterMap& params, const Ports<StreamInfo>& inp)
{
assert(inp.size()==1);
const StreamInfo& in = inp[0].data;
m_onlyIncrease = (getStringParam("FluxSupport",params)=="Increase");
outStreamInfo().add(StreamInfo(in,1));
return true;
}
示例15: process
bool Difference::process(Ports<InputBuffer*>& inp, Ports<OutputBuffer*>& outp)
{
assert(inp.size()==1);
InputBuffer* in = inp[0].data;
if (in->empty()) return false;
assert(outp.size()==1);
OutputBuffer* out = outp[0].data;
const int N = in->info().size - 1;
while (!in->empty())
{
double* inData = in->readToken();
double* outData = out->writeToken();
for (int i=0;i<N;i++)
outData[i] = inData[i+1] - inData[i];
in->consumeToken();
}
return true;
}