Esempio n. 1
0
/// Adds an instrument to the SoundFont.
void SoundFont::AddInstrument(std::shared_ptr<SFInstrument> instrument) {
  // Do nothing if nullptr specified.
  if (!instrument) {
    return;
  }

  // Check the parent file of the instrument.
  if (instrument->has_parent_file()) {
    if (&instrument->parent_file() == this) {
      // If the instrument is already be owned by this file, do nothing.
      return;
    }
    else {
      // Otherwise raise an error. An instrument cannot be shared by two files.
      throw std::invalid_argument("Instrument has already been owned by another file.");
    }
  }

  // Set this file to the parent file of the instrument.
  instrument->set_parent_file(*this);

  // Add the instrument to the list.
  instruments_.push_back(instrument);

  // If the instrument has orphan samples, add them to the file.
  for (auto && instrument_zone : instrument->zones()) {
    if (instrument_zone->has_sample()) {
      AddSample(instrument_zone->sample());
    }
  }
}
Esempio n. 2
0
void CHistorian::SetHistory(std::vector<double>& v)
{
    m_nMaxSamples = v.size();
    m_nSamplesStored = v.size();

    deqSamples.clear();
    for(int i=m_nSamplesStored-1; i>=0; --i)
        AddSample(v[i]);
}
Esempio n. 3
0
/* Add features to vec obtained from sampling the grad and ori images
   for a particular scale.  Location of key is (scale,row,col) with respect
   to images at this scale.  We examine each pixel within a circular
   region containing the keypoint, and distribute the gradient for that
   pixel into the appropriate bins of the index array.
*/
void KeySample(
	float index[IndexSize][IndexSize][OriSize], keypoint& key,
	const flimage& grad, float scale, float row, float col,siftPar &par)
{
	float rpos, cpos, rx, cx;

	int	irow = (int) (row + 0.5),
		icol = (int) (col + 0.5);
	float	sine   = (float) sin(key.angle),
		cosine = (float) cos(key.angle);

	/* The spacing of index samples in terms of pixels at this scale. */
	float	spacing = scale * par.MagFactor;

	/* Radius of index sample region must extend to diagonal corner of
	index patch plus half sample for interpolation. */
	float	radius = 1.414f * spacing * (IndexSize + 1) / 2.0f;
	int	iradius = (int) (radius + 0.5);

	/* Examine all points from the gradient image that could lie within the
	index square. */
	for (int i = -iradius; i <= iradius; i++) {
		for (int j = -iradius; j <= iradius; j++) {

			/* Rotate sample offset to make it relative to key orientation.
			 Uses (row,col) instead of (x,y) coords.  Also, make subpixel
			 correction as later image offset must be an integer.  Divide
			 by spacing to put in index units.
			*/

			 /* Guoshen Yu, inverse the rotation */
			 rpos = ((cosine * i - sine * j) - (row - irow)) / spacing;
			 cpos = ((sine * i + cosine * j) - (col - icol)) / spacing;

			 /*
			 rpos = ((cosine * i + sine * j) - (row - irow)) / spacing;
			 cpos = ((- sine * i + cosine * j) - (col - icol)) / spacing;*/

			 /* Compute location of sample in terms of real-valued index array
			 coordinates.  Subtract 0.5 so that rx of 1.0 means to put full
			 weight on index[1] (e.g., when rpos is 0 and IndexSize is 3. */
			 rx = rpos + IndexSize / 2.0f - 0.5f;
			 cx = cpos + IndexSize / 2.0f - 0.5f;
	
			/* Test whether this sample falls within boundary of index patch. */
			if (	rx > -1.0 && rx < (float) IndexSize  &&
				cx > -1.0 && cx < (float) IndexSize )
				AddSample(
					index, key, grad,
					irow + i, icol + j, rpos, cpos, rx, cx,par);
		}
	}
}
// Adds a character sample to this sample set.
// If the unichar is not already in the local unicharset, it is added.
// Returns the unichar_id of the added sample, from the local unicharset.
    int TrainingSampleSet::AddSample(const char *unichar, TrainingSample *sample) {
        if (!unicharset_.contains_unichar(unichar)) {
            unicharset_.unichar_insert(unichar);
            if (unicharset_.size() > MAX_NUM_CLASSES) {
                tprintf("Error: Size of unicharset in TrainingSampleSet::AddSample is "
                                "greater than MAX_NUM_CLASSES\n");
                return -1;
            }
        }
        UNICHAR_ID char_id = unicharset_.unichar_to_id(unichar);
        AddSample(char_id, sample);
        return char_id;
    }
Esempio n. 5
0
/* Add features to vec obtained from sampling the grad and ori images
   for a particular scale.  Location of key is (scale,row,col) with respect
   to images at this scale.  We examine each pixel within a circular
   region containing the keypoint, and distribute the gradient for that
   pixel into the appropriate bins of the index array.
*/
void KeySample(float index[IndexSize][IndexSize][OriSize], KKeypoint key,
	       Image grad, Image ori, float scale, float row, float col)
{
   int i, j, iradius, irow, icol;
   float spacing, radius, sine, cosine, rpos, cpos, rx, cx;

   irow = (int) (row + 0.5);
   icol = (int) (col + 0.5);
   sine = sin(key->ori);
   cosine = cos(key->ori);
          
   /* The spacing of index samples in terms of pixels at this scale. */
   spacing = scale * MagFactor;

   /* Radius of index sample region must extend to diagonal corner of
      index patch plus half sample for interpolation.
   */
   radius = 1.414 * spacing * (IndexSize + 1) / 2.0;
   iradius = (int) (radius + 0.5);
          
   /* Examine all points from the gradient image that could lie within the
      index square.
   */
   for (i = -iradius; i <= iradius; i++)
     for (j = -iradius; j <= iradius; j++) {
         
       /* Rotate sample offset to make it relative to key orientation.
	  Uses (row,col) instead of (x,y) coords.  Also, make subpixel
          correction as later image offset must be an integer.  Divide
          by spacing to put in index units.
       */
       rpos = ((cosine * i + sine * j) - (row - irow)) / spacing;
       cpos = ((- sine * i + cosine * j) - (col - icol)) / spacing;
         
       /* Compute location of sample in terms of real-valued index array
	  coordinates.  Subtract 0.5 so that rx of 1.0 means to put full
	  weight on index[1] (e.g., when rpos is 0 and IndexSize is 3.
       */
       rx = rpos + IndexSize / 2.0 - 0.5;
       cx = cpos + IndexSize / 2.0 - 0.5;

       /* Test whether this sample falls within boundary of index patch. */
       if (rx > -1.0 && rx < (float) IndexSize  &&
	   cx > -1.0 && cx < (float) IndexSize)
	 AddSample(index, key, grad, ori, irow + i, icol + j, rpos, cpos,
		   rx, cx);
     }
}
Esempio n. 6
0
  void
rttgraph_read(
    struct ip *pip,		/* the packet */
    tcp_pair *ptp,		/* info I have about this connection */
    void *plast,		/* past byte in the packet */
    void *mod_data)		/* module specific info for this connection */
{
  struct tcphdr *ptcp;
  struct rttgraph_info *prttg = mod_data;
  struct rtt_tcb *prtcb;
  tcb *ptcb;
  double rtt_us;
  u_long rtt_ms;

  /* find the start of the TCP header */
  ptcp = (struct tcphdr *) ((char *)pip + 4*IP_HL(pip));

  /* make sure there we could have a RTT sample */
  if (!ACK_SET(ptcp))
    return;  /* no RTT info */

  /* see which direction it is, if we don't know yet */
  ptcb = ptp2ptcb(ptp,pip,ptcp);
  if (ptcb == prttg->a2b.ptcb)
    prtcb = &prttg->a2b;
  else if (ptcb == prttg->b2a.ptcb)
    prtcb = &prttg->b2a;
  else {
    fprintf(stderr,
        "rttgraph_read: INTERNAL error (can't kind tcb)!!\n");
    exit(1);
  }

  /* grab the RTT */
  rtt_us = prtcb->ptcb->rtt_last;
  if (rtt_us == 0.0)
    return;  /* not a valid sample */

  /* convert to ms buckets */
  rtt_ms = (u_long) (rtt_us / 1000.0);

  if (debug && (rtt_ms == 0))
    printf("rtt_ms is 0, rtt_us was %f\n", rtt_us);

  /* add in the sample RTT */
  AddSample(&prtcb->samples, rtt_ms);
}
Esempio n. 7
0
void
StatisticalTimer::Stop( sTimerID id )
{
	unsigned long long n;

#if defined( _WIN32 )
	::QueryPerformanceCounter( reinterpret_cast<LARGE_INTEGER*>( &n ) );
#else
	struct timeval s;
	gettimeofday(&s, 0);
	n = (unsigned long long)s.tv_sec * 1000000 + (unsigned long long)s.tv_usec;
#endif

	n		-= clkStart.at( id );
	clkStart.at( id )	= 0;
	AddSample( id, n );
}
Esempio n. 8
0
void
statTimer::Stop( size_t id )
{
	statTimer::ulong n;

#if defined( _WIN32 )
	::QueryPerformanceCounter( reinterpret_cast<LARGE_INTEGER*>( &n ) );
#else
	struct timeval s;
	gettimeofday( &s, 0 );
	n = (cl_ulong)s.tv_sec * 1000000 + (cl_ulong)s.tv_usec;
#endif

	n		-= clkStart.at( id );
	clkStart.at( id )	= 0;
	AddSample( id, n );
}
Esempio n. 9
0
bool GPACommandList::BeginSample(ClientSampleId clientSampleIndex,
                                 GPASample* pSample)
{
    bool succeeded = false;

    if (CommandListState::SAMPLE_RECORDING_BEGIN != m_commandListState)
    {
        GPA_LogError("Command list must be in recording state to start/end a sample.");
    }
    else if (nullptr != GetSample(clientSampleIndex))
    {
        GPA_LogError("Sample Id already exists.");
    }
    else if (nullptr != m_pLastSample)
    {
        GPA_LogError("Previous sample must be ended before starting a new one.");
    }
    else
    {
        if (nullptr != pSample)
        {
            succeeded = BeginSampleRequest(clientSampleIndex, pSample);

            if (succeeded)
            {
                succeeded = pSample->Begin();

                if (succeeded)
                {
                    m_cmdListMutex.lock();
                    m_pLastSample = pSample;
                    m_cmdListMutex.unlock();
                    AddSample(clientSampleIndex, pSample);
                }
            }
            else
            {
                GPA_LogError("Failed to begin sample on command list.");
            }
        }
    }

    return succeeded;
}
Esempio n. 10
0
EncoderOutput EncodeTransform::EncodeData(char *pRGBAData, size_t numBytes)
{	
	VTUNE_TASK(g_pDomain, "EncodeData");

	const size_t numRGBAPixels = numBytes >> 2; // 4 bytes per pixel (TODO:Cleanup)
	
	EncoderOutput etn;

	etn.pEncodedData = NULL;
	etn.numBytes = 0;
	etn.returnCode = S_FALSE;

	size_t yuy2PixelIndex = 0;
	// The first step is to compress to YUV by taking in the current and next pixel (for averaging) n1 and n2, n2 and n3, n3 and n4,....

	DWORD *pRGBADataAsDWORD = reinterpret_cast<DWORD*> (pRGBAData);

	for (size_t rgbaIndex = 0; rgbaIndex < numRGBAPixels; rgbaIndex = rgbaIndex + 2)
	{
		//Here we convert RGB to YUY2 and add to the encode buffer (omiting intermediate step, go to function for more detail)
		mCompressedBuffer[yuy2PixelIndex++] = ColorConversion::RGBtoYUY2(pRGBADataAsDWORD[rgbaIndex], 
																		pRGBADataAsDWORD[rgbaIndex + 1], 
																		mbEncodeBackgroundPixels,
																		mEncodingThreshold);
	}

	SendStreamEndMessage();

	// Add a sample with the frame timestamp
	 HRESULT hr = AddSample(mTimeStamp);

	if (SUCCEEDED(hr))
	{
		etn.returnCode = ProcessOutput(etn);
	}

	mTimeStamp += VIDEO_FRAME_DURATION;

	return etn;
}
Esempio n. 11
0
 inline void AddSample(int val) {
   AddSample((double) val);
 }
Esempio n. 12
0
/////////////////////////////////////////////////////////////////////////////
// Shortcut to add sample and outcome at the same time
/////////////////////////////////////////////////////////////////////////////
void CResults::AddSample(const double *v, COutcome outcome)
{
 AddOutcome(AddSample(v), outcome);
}
Esempio n. 13
0
void Generate_Sample_Lookup(TMap &lookup){
        // 
        // Create Lookup table for each period
        // Vector contains 
        //   - path
        //   - pattern
        //   - MC/Data 
        //   - ESD/AOD
        //
        AddSample(lookup, "LHC13b.pass2", "/alice/data/2013/LHC13b", "pass2/*/AliESDs.root", "Data", "ESD");
        AddSample(lookup, "LHC13b.pass3", "/alice/data/2013/LHC13b", "pass3/*/AliESDs.root", "Data", "ESD");
        AddSample(lookup, "LHC13b.pass2.AOD", "/alice/data/2013/LHC13b", "pass2/AOD/*/AliAOD.root", "Data", "AOD"); 
        AddSample(lookup, "LHC13b.pass3.AOD", "/alice/data/2013/LHC13b", "pass3/AOD/*/AliAOD.root", "Data", "AOD"); 
        AddSample(lookup, "LHC13b.pass2.AOD126", "/alice/data/2013/LHC13b", "*/pass2/AOD126/*/AliAOD.root", "Data", "AOD"); 
        AddSample(lookup, "LHC13c.pass1", "/alice/data/2013/LHC13c/", "pass1/*/AliESDs.root", "Data", "ESD");
        AddSample(lookup, "LHC13c.pass2", "/alice/data/2013/LHC13c/", "pass2/*/AliESDs.root", "Data", "ESD");
        AddSample(lookup, "LHC13c.pass1.AOD", "/alice/data/2013/LHC13c/", "*/pass1/AOD/*/AliAOD.root", "Data", "AOD");
        AddSample(lookup, "LHC13c.pass2.AOD", "/alice/data/2013/LHC13c/", "*/pass2/AOD/*/AliAOD.root", "Data", "AOD");
        AddSample(lookup, "LHC13c.pass1.AOD126", "/alice/data/2013/LHC13c/", "*/pass1/AOD126/*/AliAOD.root", "Data", "AOD");
        AddSample(lookup, "LHC13b2", "/alice/sim/2013/LHC13b2", "*/*/AliESDs.root", "MC", "ESD");
        AddSample(lookup, "LHC13b2.AOD", "/alice/sim/2013/LHC13b2", "*/AliAOD.root", "MC", "AOD");
        AddSample(lookup, "LHC13b2plus", "/alice/sim/2013/LHC13b2_plus", "*/*/AliESDs.root", "MC", "ESD");
        AddSample(lookup, "LHC13b2plus.AOD", "/alice/sim/2013/LHC13b2_plus", "*/AliAOD.root", "MC", "AOD");
        AddSample(lookup, "LHC13b3", "/alice/sim/2013/LHC13b3", "*/*/AliESDs.root", "MC", "ESD");
	      AddSample(lookup, "LHC13b3.AOD", "/alice/sim/2013/LHC13b3", "*/AliAOD.root", "MC", "AOD");
	      AddSample(lookup, "LHC13d.pass1", "/alice/data/2013/LHC13d/", "pass1/*/AliESDs.root", "Data", "ESD");
	      AddSample(lookup, "LHC13e.pass1", "/alice/data/2013/LHC13e/", "pass1/*/AliESDs.root", "Data", "ESD");
	      AddSample(lookup, "LHC13f.pass1", "/alice/data/2013/LHC13f/", "pass1/*/AliESDs.root", "Data", "ESD");
        printf("Lookup table with sample information generated\n");
}
void FCrowdAvoidanceSamplingPattern::AddSampleWithMirror(float AngleInDegrees, float NormalizedRadius)
{
	AddSample(AngleInDegrees, NormalizedRadius);
	AddSample(-AngleInDegrees, NormalizedRadius);
}
Esempio n. 15
0
int ReadSearchDefine(const char *filepath, SearchDefine **sd)
{
    int res = 1, i, j;

    char * buf;
    cJSON * root = NULL, * item;

    printf("\n>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
    printf("\n>Reading %s...", filepath);

    if ((buf = get_file_content(filepath)) == NULL)
    {
        perror("\n>Cannot open SearchDefine json file!");
        return -1;
    }

    if ((root = cJSON_Parse(buf)) == NULL)
    {
        perror("\n>Cannot read SearchDefine json file!");
        return -1;
    }

    // check file format
    if ((item = cJSON_GetObjectItem(root, "Type")) == NULL)
    {
        perror("\n>Not SearchDefine json file!");
        return -1;
    }

    if (strcmp("SearchDefine", item->valuestring) != 0)
    {
        perror("\n>Not SearchDefine json file!");
        return -1;
    }

    // read department id
    if ((item = cJSON_GetObjectItem(root, "DepartmentID")) == NULL)
    {
        perror("\n>SearchDefine json file missing 'DepartmentID'!");
        return -1;
    }

    // TODO: 释放所有元素空间
    free(*sd);
    *sd = (SearchDefine *)malloc(sizeof(SearchDefine));
    (*sd)->DepartmentID = (char *)malloc(strlen(item->valuestring));
    strncpy((*sd)->DepartmentID, item->valuestring, strlen(item->valuestring));
    printf("\n>DepartmentID: %s", (*sd)->DepartmentID);

    // read switchgear id
    if ((item = cJSON_GetObjectItem(root, "SwitchgearID")) == NULL)
    {
        perror("\n>SearchDefine json file missing 'SwitchgearID'!");
        return -1;
    }

    (*sd)->SwitchgearID = (char *)malloc(strlen(item->valuestring));
    strncpy((*sd)->SwitchgearID, item->valuestring, strlen(item->valuestring));
    printf("\n>SwitchgearID: %s", (*sd)->SwitchgearID);

    // read meter array
    if ((item = cJSON_GetObjectItem(root, "Meters")) == NULL)
    {
        perror("\n>SearchDefine json file missing 'Meters'!");
        return -1;
    }

    if (item->type != cJSON_Array)
    {
        perror("\n>SearchDefine json file 'Meters' is not an array!");
        return -1;
    }

    int num = cJSON_GetArraySize(item);
    cJSON *meterItem, *meterItemTemp;

    for (i = 0; i < num; i++)
    {
        Meter *mt = (Meter *)malloc(sizeof(Meter));

        meterItem = cJSON_GetArrayItem(item, i);

        // read meter id
        if ((meterItemTemp = cJSON_GetObjectItem(meterItem, "ID")) == NULL)
        {
            printf("\n>  SearchDefine json file Meter NO: %d missing 'ID'!", i);
            continue;
        }

        mt->ID = (char *)malloc(strlen(meterItemTemp->valuestring));
        strncpy(mt->ID, meterItemTemp->valuestring, strlen(meterItemTemp->valuestring));
        printf("\n>  Meter NO: %d 'ID': %s", i, mt->ID);

        // read meter node address
        if ((meterItemTemp = cJSON_GetObjectItem(meterItem, "NodeAddress")) == NULL)
        {
            printf("\n>  SearchDefine json file Meter NO: %d missing 'NodeAddress'!", i);
            continue;
        }

        mt->NodeAddress = meterItemTemp->valueint;
        printf("\n>  Meter NO: %d 'NodeAddress': %d", i, mt->NodeAddress);

        // read meter command
        if ((meterItemTemp = cJSON_GetObjectItem(meterItem, "Command")) == NULL)
        {
            printf("\n>  SearchDefine json file Meter NO: %d missing 'Command'!", i);
            continue;
        }

        mt->Command = meterItemTemp->valueint;
        printf("\n>  Meter NO: %d 'Command': %d", i, mt->Command);

        // read meter start address
        if ((meterItemTemp = cJSON_GetObjectItem(meterItem, "StartAddress")) == NULL)
        {
            printf("\n>  SearchDefine json file Meter NO: %d missing 'StartAddress'!", i);
            continue;
        }

        mt->StartAddress = strtol(meterItemTemp->valuestring, NULL, 16);
        printf("\n>  Meter NO: %d 'StartAddress': 0x%04X", i, mt->StartAddress);

        // read meter register count
        if ((meterItemTemp = cJSON_GetObjectItem(meterItem, "RegisterCount")) == NULL)
        {
            printf("\n>  SearchDefine json file Meter NO: %d missing 'RegisterCount'!", i);
            continue;
        }

        mt->RegisterCount = meterItemTemp->valueint;
        printf("\n>  Meter NO: %d 'RegisterCount': %d", i, mt->RegisterCount);

        ///////////////////////////////////////////////////////////////////////////////////////////
        // read meter array
        if ((meterItemTemp = cJSON_GetObjectItem(meterItem, "Samples")) == NULL)
        {
            printf("\n>  SearchDefine json file Meter NO: %d missing 'Samples'!", i);
            continue;
        }

        if (meterItemTemp->type != cJSON_Array)
        {
            printf("\n>  SearchDefine json file Meter NO: %d 'Samples' is not an array!", i);
            continue;
        }

        int sampleNum = cJSON_GetArraySize(meterItemTemp);
        cJSON *sampleItem, *sampleItemTemp;

        for (j = 0; j < sampleNum; j++)
        {
            Sample *sm = (Sample *)malloc(sizeof(Sample));

            // read sample array
            sampleItem = cJSON_GetArrayItem(meterItemTemp, j);

            // read sample name
            if ((sampleItemTemp = cJSON_GetObjectItem(sampleItem, "Name")) == NULL)
            {
                printf("\n>    SearchDefine json file Meter NO: %d Sample NO: %d missing 'Name'!", i, j);
                continue;
            }

            sm->Name = (char *)malloc(strlen(sampleItemTemp->valuestring));
            strncpy(sm->Name, sampleItemTemp->valuestring, strlen(sampleItemTemp->valuestring));
            printf("\n>    Meter NO: %d Sample NO: %d 'Name': %s", i, j, sm->Name);

            // read sample value type
            if ((sampleItemTemp = cJSON_GetObjectItem(sampleItem, "ValueType")) == NULL)
            {
                printf("\n>    SearchDefine json file Meter NO: %d Sample NO: %d missing 'ValueType'!", i, j);
                continue;
            }

            if (strcmp("Float", sampleItemTemp->valuestring) == 0)
            {
                sm->ValueType = SampleValueType_Float;
            } else if (strcmp("Bit", sampleItemTemp->valuestring) == 0)
            {
                sm->ValueType = SampleValueType_Bit;
            } else
            {
                sm->ValueType = SampleValueType_Unknown;
            }
            printf("\n>    Meter NO: %d Sample NO: %d 'ValueType': %d", i, j, sm->ValueType);

            AddSample(mt, sm);
        }
        ///////////////////////////////////////////////////////////////////////////////////////////

        AddMeter((*sd), mt);
    }

    //ShowSearchDefine((*sd));

    free(buf);
    cJSON_Delete(root);

    printf("\n>Reading %s completed!", filepath);
    printf("\n>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
    fflush(stdout);

    return res;
}
Esempio n. 16
0
void CPerformanceStats::AddSample(const std::string &strStatName, double dTime)
{
  AddSample(strStatName, PerformanceCounter(dTime));
}
Esempio n. 17
0
void Stats::AddSample( int val )
{
   AddSample( (double)val );
}