void
TranscriberExtract::getAllFromAudio(const std::string audioFilename, realvec&
                                    pitchList, realvec& ampList,
                                    realvec& boundaries)
{
	MarSystem* pitchSink = mng.create("RealvecSink", "pitchSink");
	MarSystem* ampSink = mng.create("RealvecSink", "ampSink");

	MarSystem* pnet = mng.create("Series", "pnet");
	mrs_real srate = addFileSource(pnet, audioFilename);
// TODO: double the number of observations?
//	pnet->updControl("SoundFileSource/src/mrs_natural/inSamples",256);
//	pnet->addMarSystem(mng.create("ShiftInput", "shift"));
//	pnet->updControl("ShiftInput/shift/mrs_natural/winSize",512);

	MarSystem* fanout = mng.create("Fanout", "fanout");
	fanout->addMarSystem(makePitchNet(srate, 100.0, pitchSink));
	fanout->addMarSystem(makeAmplitudeNet(ampSink));
	pnet->addMarSystem(fanout);

	while ( pnet->getctrl("mrs_bool/hasData")->to<mrs_bool>() )
		pnet->tick();

	pitchList = getPitchesFromRealvecSink(pitchSink, srate);
	ampList = getAmpsFromRealvecSink(ampSink);
	boundaries.create(2);
	boundaries(0) = 0;
	boundaries(1) = pitchList.getSize();
	delete pnet;
}
Esempio n. 2
0
void
HWPS::discretize(const realvec& peakSetWrapFreqs, const realvec& peakAmps,
                 const mrs_natural& histSize, realvec& resultHistogram)
{
  mrs_natural index;

  resultHistogram.create(histSize);

  for (mrs_natural i=0 ; i<peakSetWrapFreqs.getSize() ; ++i)
  {
    index = (mrs_natural) fmod(floor(peakSetWrapFreqs(i)*histSize+.5), histSize);
    resultHistogram(index) += peakAmps(i);
  }
}
Esempio n. 3
0
/**
 * Function: recvUDP
 * Description: Receive a vector from a peer on a UDP socket connection.
 */
int NetworkSocket::recvUDP ( realvec& out )  {

  int status = 0;

  // assume a size 512 vector
  mrs_natural inSamples = getctrl("mrs_natural/inSamples")->to<mrs_natural>();
  mrs_natural inObservations = getctrl("mrs_natural/inObservations")->to<mrs_natural>();


  mrs_real* buffer = new mrs_real[(inSamples*inObservations)+3];
  int cliLen = sizeof(cliAddr);
#ifndef MARSYAS_CYGWIN
  status = ::recvfrom(s_sock, buffer, sizeof(mrs_real) *
                      ((inSamples*inObservations)+3), MSG_WAITALL,
                      (struct sockaddr *) &cliAddr, (socklen_t *)&cliLen);
#else
  status = ::recvfrom(s_sock, buffer, sizeof(mrs_real) *
                      ((inSamples*inObservations)+3), MSG_NOSIGNAL,
                      (struct sockaddr *) &cliAddr, (socklen_t *)&cliLen);

#endif

  if ( status <= 0 ) {
    MRSERR("Could not receive UDP data...");
    return 0;
  } else {
    updctrl("mrs_natural/inSamples", (mrs_natural) buffer[0]);
    updctrl("mrs_natural/inObservations",(mrs_natural) buffer[1]);
    updctrl("mrs_real/israte", buffer[2]);
  }

  // process the data to an output vector...
  out.create( inObservations, inSamples );
  mrs_real* data = out.getData();

  int i;
  for ( i = 0; i < 512; i++ ) {
    // *( data + i ) = buffer[i+3];
  }

  // delete [] buffer;
  return status;
}
Esempio n. 4
0
/**
 * Function: recvTCP
 * Description: Receive a vector from a peer on a TCP socket connection.
 */
int NetworkSocket::recvTCP ( realvec& out )
{

  // create our slice with updated controls
  mrs_natural inSamples = getctrl("mrs_natural/inSamples")->to<mrs_natural>();
  mrs_natural inObservations = getctrl("mrs_natural/inObservations")->to<mrs_natural>();

  out.create(inObservations, inSamples);
  mrs_real* data = out.getData();


#ifndef MARSYAS_CYGWIN
  return ::recv ( client_d, data, sizeof(mrs_real)*(inObservations*inSamples),
                  MSG_WAITALL );
#else
  return ::recv ( client_d, data, sizeof(mrs_real)*(inObservations*inSamples),
                  MSG_NOSIGNAL);
#endif

}
Esempio n. 5
0
void
peakView::toTable(realvec& vecTable)
{
  //resize and initialize the table (assuming the largest possible number of peaks + the header for now...)
  vecTable.create(frameMaxNumPeaks_*numFrames_+1, nbPkParameters);


  //In Table format, the 1st row is a "header row"
  vecTable(0, 0) = -1;
  vecTable(0, 1) =  fs_;
  vecTable(0, 2) =  frameSize_;
  vecTable(0, 3) =  frameMaxNumPeaks_;
  vecTable(0, 4) =  numFrames_;
  vecTable(0, 5) = -1;
  vecTable(0, pkGroup) = -2;
  for (mrs_natural i = pkGroup+1 ; i < nbPkParameters ; ++i) //i = pkGroup or i = pkGroup+1 [?]
    vecTable(0, i)=0;


  //fill the table with peak data
  mrs_natural l = 1; //l = peak index for table format (i.e. row index)
  for (mrs_natural j=0 ; j < vec_.getCols(); ++j) //j = frame index
    for (mrs_natural i=0 ; i < frameMaxNumPeaks_; ++i) //i = peak index
    {
      //just output existing peaks at each frame (i.e. freq != 0)
      if(vec_(i, j) != 0.0)
      {
        for(mrs_natural k = 0; k < nbPkParameters; k++)// k = parameter index
          vecTable(l, k) = (*this)(i, pkParameter(k), j);
        l++;
      }
    }

  //resize the table to the correct (i.e. possibly smaller)
  //number of peaks (i.e. nr of rows)

  vecTable.stretch(l, nbPkParameters);
}
Esempio n. 6
0
int
MATLABengine::getVariable(std::string MATLABname, realvec& value)
{
  mxArray* mxVector = engGetVariable(engine_, MATLABname.c_str());

  if (mxVector == NULL)
  {
    MRSERR("MATLABengine::getVariable(\"" << MATLABname << "\", realvec&) error: variable does not exist in MATLAB!");
    return -1;
  }
  else {
    if (mxGetNumberOfDimensions(mxVector) > 2)
    {
      MRSERR("MATLABengine::getVariable(\"" << MATLABname << "\", realvecl&): MATLAB array with more than 2 dimensions!");
      return -1;
    }

    if(mxIsComplex(mxVector))
    {
      MRSWARN("MATLABengine::getVariable(\"" << MATLABname << "\", realvec&): MATLAB complex array => getting real part only!");
    }

    //number of rows and cols for the 2D MATLAB array
    //resize realvec accordingly
    value.create(mxGetDimensions(mxVector)[0],mxGetDimensions(mxVector)[1]);
    for(unsigned int i= 0; i < mxGetNumberOfElements(mxVector); ++i)
    {
      //both Marsyas realvec and MATLAB arrays are column-wise,
      //so they can be copied as linear vectors
      value(i) = (mrs_real)(*(mxGetPr(mxVector)+i));
    }

    mxDestroyArray(mxVector);
    return 0;
  }
}
Esempio n. 7
0
mrs_natural
realvec::invert(realvec& res)
{
  if (rows_ != cols_)
  {
    MRSERR("realvec::invert() - matrix should be square!");
    res.create(0);
    return -1;
  }
  if (this != &res)
  {
    mrs_natural rank;
    mrs_natural r,c,i;
    mrs_real temp;

    res.create(rows_, cols_);

    rank = 0;
    for (r = 0; r < rows_; ++r)
      for (c=0; c < cols_; ++c)
      {
        if (r == c)
          res(r,c) = 1.0;
        else
          res(r,c) = 0.0;
      }
    for (i = 0; i < rows_; ++i)
    {
      if ((*this)(i,i) == 0)
      {
        for (r = i; r < rows_; ++r)
          for (c = 0; c < cols_; ++c)
          {
            (*this)(i,c) += (*this)(r,c);
            res(i,c) += res(r,c);
          }
      }
      for (r = i; r < rows_; ++r)
      {
        temp = (*this)(r,i);
        if (temp != 0)
          for (c =0; c < cols_; ++c)
          {
            (*this)(r,c) /= temp;
            res(r,c) /= temp;
          }
      }
      if (i != rows_-1)
      {
        for (r = i+1; r < rows_; ++r)
        {
          temp = (*this)(r,i);
          if (temp != 0.0)
            for (c=0; c < cols_; ++c)
            {
              (*this)(r,c) -= (*this)(i,c);
              res(r,c) -= res(i,c);
            }
        }
      }
    }
    for (i=1; i < rows_; ++i)
      for (r=0; r < i; ++r)
      {
        temp = (*this)(r,i);
        for (c=0; c < cols_; ++c)
        {
          (*this)(r,c) -= (temp * (*this)(i,c));
          res(r,c) -= (temp * res(i,c));
        }
      }
    for (r =0; r < rows_; ++r)
      for (c=0; c < cols_; ++c)
        (*this)(r,c) = res(r,c);
    return rank;
  }
  else
  {
    res.create(0);
    MRSERR("realvec::invert() - inPlace operation not supported - returning empty result vector!");
    return -1;
  }
}