本文整理汇总了C++中OutputBuffer类的典型用法代码示例。如果您正苦于以下问题:C++ OutputBuffer类的具体用法?C++ OutputBuffer怎么用?C++ OutputBuffer使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了OutputBuffer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: assert
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;
}
示例2: test_accept
bool test_accept(LocalNode &node)
throw (EpiException)
{
node.publishPort();
std::auto_ptr<Connection> connection(node.accept());
std::auto_ptr<MailBox> mailbox(node.createMailBox(connection.get()));
connection->start();
std::auto_ptr<ErlangMessage> msg;
ErlTerm* received_term;
OutputBuffer *buffer = mailbox->newOutputBuffer();
bool loop = true;
while (loop) {
msg.reset(mailbox->receiveMsg());
if (!(msg->messageType() == ERL_MSG_SEND ||
msg->messageType() == ERL_MSG_REG_SEND)) {
std::cout << "Message is not SEND type\n";
return false;
}
received_term = msg->getMsg();
if (msg->messageType() == ERL_MSG_REG_SEND) {
std::cout << "Received to " << ((RegSendMessage *) msg.get())->getRecipientName() <<
": " << received_term->toString() << "\n";
} else {
std::cout << "Received to " << ((SendMessage *) msg.get())->getRecipientPid()->toString() <<
": " << received_term->toString() << "\n";
}
if (received_term->instanceOf(ERL_TUPLE)) {
ErlTuple *tuple = (ErlTuple *) received_term;
if (tuple->arity() == 2) {
ErlTerm* term1 = tuple->elementAt(0);
ErlTerm* term2 = tuple->elementAt(1);
if (term1->instanceOf(ERL_PID)) {
std::cout << "Sending " << term2->toString() <<
" to " << term1->toString() << "\n";
buffer->reset();
buffer->writeTerm(term2);
mailbox->sendBuf((ErlPid *) term1, buffer);
std::cout << "Sent.\n";
}
}
}
if (received_term->instanceOf(ERL_ATOM)) {
if (((ErlAtom *) received_term)->atomValue() == "exit") {
loop = false;
}
}
}
return true;
}
示例3: assert
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;
}
示例4: assert
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;
}
示例5: switch
void Webserver::HandleGCodeReply(const WebSource source, const char *reply)
{
switch (source)
{
case WebSource::HTTP:
if (numSessions > 0)
{
OutputBuffer *buffer = gcodeReply->GetLastItem();
if (buffer == nullptr || buffer->IsReferenced())
{
if (!OutputBuffer::Allocate(buffer))
{
// No more space available, stop here
return;
}
gcodeReply->Push(buffer);
}
buffer->cat(reply);
seq++;
}
break;
case WebSource::Telnet:
default:
break;
}
}
示例6: assert
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;
}
示例7: assert
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;
}
示例8: 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;
}
示例9: Add
/**
* Add text to the output storage.
* @param text Text to store.
* @param length Length of the text in bytes, \c 0 means 'length of the string'.
*/
void Add(const char *text, int length = 0)
{
if (length == 0) length = strlen(text);
if (length > 0 && this->BufferHasRoom()) {
int stored_size = this->output_buffer[this->output_buffer.Length() - 1].Add(text, length);
length -= stored_size;
text += stored_size;
}
while (length > 0) {
OutputBuffer *block = this->output_buffer.Append();
block->Clear(); // Initialize the new block.
int stored_size = block->Add(text, length);
length -= stored_size;
text += stored_size;
}
}
示例10: strlen
// Get the list of files in the specified directory in JSON format.
// If flagDirs is true then we prefix each directory with a * character.
OutputBuffer *RepRap::GetFilesResponse(const char *dir, bool flagsDirs)
{
// Need something to write to...
OutputBuffer *response;
if (!OutputBuffer::Allocate(response))
{
return nullptr;
}
response->copy("{\"dir\":");
response->EncodeString(dir, strlen(dir), false);
response->cat(",\"files\":[");
FileInfo fileInfo;
bool firstFile = true;
bool gotFile = platform->GetMassStorage()->FindFirst(dir, fileInfo);
size_t bytesLeft = OutputBuffer::GetBytesLeft(response); // don't write more bytes than we can
char filename[FILENAME_LENGTH];
filename[0] = '*';
const char *fname;
while (gotFile)
{
if (fileInfo.fileName[0] != '.') // ignore Mac resource files and Linux hidden files
{
// Get the long filename if possible
if (flagsDirs && fileInfo.isDirectory)
{
strncpy(filename + sizeof(char), fileInfo.fileName, FILENAME_LENGTH - 1);
filename[FILENAME_LENGTH - 1] = 0;
fname = filename;
}
else
{
fname = fileInfo.fileName;
}
// Make sure we can end this response properly
if (bytesLeft < strlen(fname) * 2 + 4)
{
// No more space available - stop here
break;
}
// Write separator and filename
if (!firstFile)
{
bytesLeft -= response->cat(',');
}
bytesLeft -= response->EncodeString(fname, FILENAME_LENGTH, false);
firstFile = false;
}
gotFile = platform->GetMassStorage()->FindNext(fileInfo);
}
response->cat("]}");
return response;
}
示例11: assert
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;
}
示例12: assert
bool Cepstrum::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;
safeLogOp<double> slop;
VectorXd outDct;
while (!in->empty())
{
Map<VectorXd> inData(in->readToken(),in->info().size);
outDct.noalias() = m_dctPlan * inData.unaryExpr(slop);
memcpy(out->writeToken(),outDct.data() + m_ignoreFirst, out->info().size*sizeof(double));
in->consumeToken();
}
return true;
}
示例13: assert
bool SpecificLoudness::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;
const int M = out->info().size;
while (!in->empty())
{
Map<VectorXd> inData(in->readToken(),N);
double* outData = out->writeToken();
for (int i=0;i<NB_BARK_BANDS;i++)
outData[i] = pow(inData.segment(m_bkBdLimits[i],m_bkBdLimits[i+1]-m_bkBdLimits[i]).sum(),0.23);
in->consumeToken();
}
return true;
}
示例14: assert
bool MelFilterBank::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;
while (!in->empty()) {
Map<VectorXd> inData(in->readToken(),in->info().size);
double* outData = out->writeToken();
for (int f=0;f<m_filters.size();f++)
{
RowVectorXd& filter = m_filters[f];
outData[f] = filter * inData.segment(m_filterStart[f],filter.size());
}
in->consumeToken();
}
return true;
}
示例15: assert
bool FrameTokenizer::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(in->size()==1);
if ((out->tokenno()==0) && (in->tokenno()!=-m_blockSize/2))
in->prependZeros(m_blockSize/2);
if (!in->hasTokens(m_blockSize))
return false;
while (in->hasTokens(m_blockSize)) {
in->read(out->writeToken(),m_blockSize);
in->consumeTokens(m_stepSize);
}
return true;
}