ProcessBlobs::ProcessBlobs(Interpreter *interpreter)
{
    m_interpreter = interpreter;
    m_qq = new Qqueue();
#ifdef DEFER
    m_blobs = new Blobs(m_qq);
#endif
    m_qMem = new uint32_t[0x10000];

    connect(m_interpreter, SIGNAL(paramChange()), this, SLOT(handleParamChange()));
}
Пример #2
0
  void process(int numSamples, float* input, float* output){
    // process a block of more than 2 samples. Basic implementation without coeffs interpolation.
        
    if (paramChange()) {
      output[0] = (b[0]*input[0]+b[1]*x1+b[2]*x2-a[1]*y1-a[2]*y2)/a[0] ;
      output[1] = (b[0]*input[1]+b[1]*input[0]+b[2]*x1-a[1]*output[0]-a[2]*y1)/a[0] ;
      for (int i=2; i<numSamples; i++){
	output[i] = (b[0]*input[i]+b[1]*input[i-1]+b[2]*input[i-2]-a[1]*output[i-1]-a[2]*output[i-2])/a[0] ;
      }
      // store values for next block
      x1 = input[numSamples-1];
      x2 = input[numSamples-2];
      y1 = output[numSamples-1];
      y2 = output[numSamples-2];
    }
    else { // we then need to interpolate the coefficients
      int N=numSamples-1;
      output[0] = (pb[0]*input[0]+pb[1]*x1+pb[2]*x2-pa[1]*y1-pa[2]*y2)/pa[0] ;
      output[1] = (pb[0]*input[1]+pb[1]*input[0]+pb[2]*x1-pa[1]*output[0]-pa[2]*y1)/pa[0]*(N-1)/N ;
      output[1] += (b[0]*input[1]+b[1]*input[0]+b[2]*x1-a[1]*output[0]-a[2]*y1)/a[0] / N;
            
            
      float a1, a2, b0, b1, b2;
      for (int i=2; i<numSamples; i++){
	a1 = a[1]/a[0]*i+pa[1]/pa[0]*(N-i);
	a2 = a[2]/a[0]*i+pa[2]/pa[0]*(N-i);
	b0 = b[0]/a[0]*i+pb[0]/pa[0]*(N-i);
	b1 = b[1]/a[0]*i+pb[1]/pa[0]*(N-i);
	b2 = b[2]/a[0]*i+pb[2]/pa[0]*(N-i);
                
	output[i] = (b0*input[i]+b1*input[i-1]+b2*input[i-2]-a1*output[i-1]-a2*output[i-2])/N ;
      }
            
      // store values for next block
      x1 = input[numSamples-1];
      x2 = input[numSamples-2];
      y1 = output[numSamples-1];
      y2 = output[numSamples-2];
      pa[0]=a[0];
      pa[1]=a[1];
      pa[2]=a[2];
      pb[0]=b[0];
      pb[1]=b[1];
      pb[2]=b[2];
            
    }
  }
Пример #3
0
void Interpreter::handleSaveParams()
{
    int i;
    int res, response;
    bool dirty, running;

    // if we're running, stop so this doesn't take too long....
    // (ie it would proceed with 1 property to returned frame, which could take 1 second or 2)
    running = m_running;
    if (running==1) // only if we're running and not in forced state (running==2)
        sendStop();

    Parameters &parameters = m_pixyParameters.parameters();

    for (i=0, dirty=false; i<parameters.size(); i++)
    {
        uint8_t buf[0x100];

        if (parameters[i].dirty())
        {
            int len;
            QByteArray str = parameters[i].id().toUtf8();
            const char *id = str.constData();
            PType type = parameters[i].type();
            parameters[i].setDirty(false); // reset
            dirty = true; // keep track for sending signal

            qDebug() << id;

            if (type==PT_INT8 || type==PT_INT16 || type==PT_INT32)
            {
                int val = parameters[i].value().toInt();
                len = Chirp::serialize(NULL, buf, 0x100, type, val, END);
            }
            else if (type==PT_FLT32)
            {
                float val = parameters[i].value().toFloat();
                len = Chirp::serialize(NULL, buf, 0x100, type, val, END);
            }
            else if (type==PT_INTS8)
            {
                QByteArray a = parameters[i].value().toByteArray();
                len = a.size();
                memcpy(buf, a.constData(), len);
            }
            else
                continue; // don't know what to do!

            res = m_chirp->callSync(m_set_param, STRING(id), UINTS8(len, buf), END_OUT_ARGS, &response, END_IN_ARGS);
            if (res<0 || response<0)
            {
                emit error("There was a problem setting a parameter.");
                break;
            }
        }
    }

    // if we're running, we've stopped, now resume
    if (running==1)
    {
        sendRun();
        m_fastPoll = false; // turn off fast polling...
    }

    if (dirty)  // if we updated any parameters, output paramChange signal
        emit paramChange();

}
Пример #4
0
void Interpreter::handleLoadParams()
{
    qDebug("loading...");
    uint i;
    char *id, *desc;
    uint32_t len;
    uint32_t flags;
    int response, res;
    uint8_t *data, *argList;
    int running;

    // if we're running, stop so this doesn't take too long....
    // (ie it would proceed with 1 property to returned frame, which could take 1 second or 2)
    running = m_running;
    if (running==1) // only if we're running and not in forced state (running==2)
        sendStop();

    for (i=0; true; i++)
    {
        QString category;

        res = m_chirp->callSync(m_getAll_param, UINT16(i), END_OUT_ARGS, &response, &flags, &argList, &id, &desc, &len, &data, END_IN_ARGS);
        if (res<0)
            break;

        if (response<0)
            break;

        QString sdesc(desc);

        // deal with param category
        QStringList words = QString(desc).split(QRegExp("\\s+"));
        int i = words.indexOf("@c");
        if (i>=0 && words.size()>i+1)
        {
            category = words[i+1];
            sdesc = sdesc.remove("@c "); // remove form description
            sdesc = sdesc.remove(category + " "); // remove from description
            category = category.replace('_', ' '); // make it look prettier
        }
        else
            category = CD_GENERAL;

        Parameter parameter(id, (PType)argList[0], "("+printArgType(argList[0], flags)+") "+sdesc);
        parameter.setProperty(PP_CATEGORY, category);
        parameter.setProperty(PP_FLAGS, flags);
        if (strlen((char *)argList)>1)
        {
            QByteArray a((char *)data, len);
            parameter.set(a);
        }
        else
        {
            if (argList[0]==CRP_INT8 || argList[0]==CRP_INT16 || argList[0]==CRP_INT32)
            {
                int32_t val = 0;
                Chirp::deserialize(data, len, &val, END);
                parameter.set(val);
            }
            else if (argList[0]==CRP_FLT32)
            {
                float val;
                Chirp::deserialize(data, len, &val, END);
                parameter.set(val);
            }
            else // not sure what to do with it, so we'll save it as binary
            {
                QByteArray a((char *)data, len);
                parameter.set(a);
            }
        }
        m_pixyParameters.add(parameter);
    }

    // if we're running, we've stopped, now resume
    if (running==1)
    {
        sendRun();
        m_fastPoll = false; // turn off fast polling...
    }

    qDebug("loaded");
    emit paramLoaded();
    if (m_paramDirty) // emit first time to update any modules waiting to get paramter info
    {
        m_paramDirty = false;
        emit paramChange();
    }
}