Пример #1
0
/* doBlock:
 * Set positions of block sn and its child blocks.
 */
static void doBlock(Agraph_t * g, block_t * sn, double min_dist)
{
    block_t *child;
    nodelist_t *longest_path;
    int childCount, length;
    double centerAngle = M_PI;

    /* layout child subtrees */
    childCount = 0;
    for (child = sn->children.first; child; child = child->next) {
	doBlock(g, child, min_dist);
	childCount++;
    }

    /* layout this block */
    longest_path = layout_block(g, sn, min_dist);
    sn->circle_list = longest_path;
    length = sizeNodelist(longest_path);	/* path contains everything in block */

    /* attach children */
    if (childCount > 0)
	centerAngle =
	    position(g, childCount, length, longest_path, sn, min_dist);

    if ((length == 1) && (BLK_PARENT(sn))) {
	sn->parent_pos = centerAngle;
	if (sn->parent_pos < 0)
	    sn->parent_pos += 2 * M_PI;
    }
}
void GoaliePen::decide()
{
	Vector Me;

	vector <int> opps = pWorldData->mr_found_opponents();

	Point ballPos = pWorldData->basedCenter(pWorldData->ball());
	Point closestOppToBalll;
	if(opps.size() != 0)
		pWorldData->basedCenter(pWorldData->opponent(pWorldData->getNearstOppToPoint(ballPos)));
	Point me;

	me.x = Me.getX();
	me.y = Me.getY();

	if(pBasicPlayer->can_kick())
		doClear();
	else
	{
		if(me.getDistance(closestOppToBalll) > ballPos.getDistance(closestOppToBalll) && opps.size() != 0)
			doBlock();
		else
			doGo();
	}


}
Пример #3
0
void DotBuilder::doElement(ASTElement* element)
{
  switch (element->getElementType())
  {
    case MELEMENT_BLOCK:
      doBlock(reinterpret_cast<ASTBlock*>(element));
      break;
    case MELEMENT_CONSTANT:
      doConstant(reinterpret_cast<ASTConstant*>(element));
      break;
    case MELEMENT_VARIABLE:
      doVariable(reinterpret_cast<ASTVariable*>(element));
      break;
    case MELEMENT_OPERATOR:
      doOperator(reinterpret_cast<ASTOperator*>(element));
      break;
    case MELEMENT_CALL:
      doCall(reinterpret_cast<ASTCall*>(element));
      break;
    case MELEMENT_TRANSFORM:
      doTransform(reinterpret_cast<ASTTransform*>(element));
      break;
    default:
      MP_ASSERT_NOT_REACHED();
  }
}
Пример #4
0
char dtmf(short *audio){

  //find number of frequencies
  numoffreq = sizeof(freq)/sizeof(int);

  //allocate DFT arrays
  float normfreq[numoffreq];
  float coef[numoffreq];
  float fmag[numoffreq];
  float sam0[numoffreq];
  float sam1[numoffreq];
  float sam2[numoffreq];

  //used in counters
  int i;

  //compute normalized frequencies
  for(i = 0; i != numoffreq; i++) {
    normfreq[i] = (float)freq[i]/((float)sampleRate*((float)interp+1));
  }

  //compute coefficents
  for(i = 0; i != numoffreq; i++) {
    coef[i] = 2*cos(2*pi*normfreq[i]);
  }

  //buffers
  short int readBuffer[windowmov];
  short int blockBuffer[blockln];
  float interpBuffer[(int)blockln*(interp + 1)];

  //clear buffers
  for(i=0; i != blockln; i++) {
    blockBuffer[i] = 0;
  } 

  for(i=0; i != windowmov; i++) {
    readBuffer[i] = 0;
  }

  for(i=0; i != (blockln*interp); i++){
    interpBuffer[i] = 0.0;
  }

  //instead of useing a file we need to have the function take an address of an array
  //and put the contence of the array into buffer b

  //keep analyzing if you haven't got to EOF
  //while(!feof(pfile)){
  int audioSize = sizeof(audio);  

  //for all of the data in our array that was passed, keep grabbing data.
  int k;
  for(k=0; (k*windowmov) < audioSize; k++) { 

    //read: windomov amount of, short int, once, and place in buffer b
    //fread(&readBuffer[0], sizeof(readBuffer), 1, pfile);

    for(i=0; i < windowmov && ( (k*windowmov)+i) < audioSize; i++) {
      readBuffer[i] = audio[(k*windowmov)+i];
    }

    //move samples in buffer windowmov ammount to the left
    for(i=windowmov; i != blockln; i++) {
      blockBuffer[(i-(int)windowmov)] = blockBuffer[i];
    }

    //put the windowmov amount of new samples at the end of the buffer
    for(i=windowmov; i != 0; i--) {
      blockBuffer[(int)(blockln-i)] = readBuffer[(int)windowmov-i];
    }

    //interpolate in-between the samples
    for(i=0; i != blockln; i++) {

      //find the step in-between samples
      float step = (blockBuffer[i+1] - blockBuffer[i])/(interp+1);

      //interpolate between the two given samples
      int j = 0;
      for(j=0; j != (interp+1); j++) {
        interpBuffer[(i*(interp+1))+j] = blockBuffer[i]+(j)*step;
      }
    }

    //do calculations on current block of samples
    //then find the magnitude of the tones
    doBlock(&interpBuffer[0], &sam0[0], &sam1[0], &sam2[0], &coef[0]);
    findMag(&fmag[0], &sam0[0], &sam1[0], &sam2[0], &coef[0]);
    
    //dtmf decision making


    for(i=0; i < numoffreq; i++){
      if (fmag[i] != fmag[i]) break;
      toneAvg += fmag[i]/(float)numoffreq;
    }

    printf("\navg: %f\n\n", toneAvg);
    //the two tones that are present for a single key will be above this average
    char col = 'e';
    char row = 'e';

    //if dtmf tones are not at the begining of the
    //freq array, these two for loops will need changed
    for(i=0; i < 4; i++){
      if(fmag[i] > toneAvg){
        row = i;
        printf("above%d", i);
      }
    }

    for(i=4; i < 8; i++){
      if(fmag[i]>toneAvg){
        col = i;
        printf("above%d", i);
      }
    }

    sum = 0;
    toneAvg = 0;

    printf("\n\n%c %d %d\n\n", keys[(int)row][(int)col], row, col);
    return keys[(int)row][(int)col];

  }

  // Should never get here?
  return -1;
}
Пример #5
0
void circPos(Agraph_t * g, block_t * sn, circ_state * state)
{
    doBlock(g, sn, state->min_dist);
}
Пример #6
0
static void convert_to_fft(SNDFILE * infile, FILE * outfile, int channels)
{
    float buf1 [channels * BLOCK_SIZE] ;
    float buf2 [channels * BLOCK_SIZE] ;
    float block [channels * BLOCK_SIZE] ;
    int k, m, readcount ;

    double edge, val, time = 0;
    int index = -1;
    int seconds = 0;
    int firstRun = 1;
    double mult;

    // Init peak hold
    for(int i = 0; i < BLOCK_SIZE; i++)
        for(int j = 0; j < g_channels; j++)
        {
            peakhold[j][i] = -100000;
            otherEnergy[j] = 0.0;
            peakEnergy[j] = 0.0;

        }
    /* Ignore first few blocks - hack to avoid 0's in start of wav */
    while(1)
    {
        if((readcount = sf_readf_float (infile, buf1, 1)) <= 0)
        {
            exit(1);
        }

        if(buf1[0] != 0.0)
            break;
    }

    if((readcount = sf_readf_float (infile, buf1, BLOCK_SIZE)) <= 0)
        exit(1);

    while (1)
    {
        readcount = sf_readf_float (infile, buf2, BLOCK_SIZE);
        if(readcount < 0)
        {
            break;
        }
        else if(readcount != BLOCK_SIZE)
        {
            fprintf(stderr, "Info: Dropped last block\n");
            break;
        }

        for(int i = 0; i < (BLOCK_SIZE); i++)
        {
            block[i] = buf1[i+(BLOCK_SIZE)];
        }
        for(int i = 0; i < (BLOCK_SIZE); i++)
        {
            block[i+(BLOCK_SIZE)] = buf2[i];
        }

        index = doBlock(block, readcount, index);
        index = doBlock(buf2, readcount, index);

        readcount = sf_readf_float(infile, buf1, BLOCK_SIZE);
        if(readcount < 0)
        {
            break;
        }
        else if(readcount != BLOCK_SIZE)
        {
            fprintf(stderr, "Info: Dropped last block\n");
            break;
        }

        for(int i = 0; i < (BLOCK_SIZE); i++)
        {
            block[i] = buf2[i+(BLOCK_SIZE)];
        }
        for(int i = 0; i < (BLOCK_SIZE); i++)
        {
            block[i+(BLOCK_SIZE)] = buf1[i];
        }

        index = doBlock(block, readcount, index);
        index = doBlock(buf1, readcount, index);

    } ;


    /* Print out the output */
    for(int i = 0; i < BLOCK_SIZE; i++)
    {
        fprintf(outfile, "%10d ", (int)(i*g_div));
        for(int c = 0; c<g_channels; c++)
        {
            fprintf(outfile, "%10g ", peakhold[c][i]);
        }
        fprintf(outfile, "\n");
    }

#define PEAK_RANGE 5
    for(int c = 0; c < g_channels; c++)
    {
        int othercount = 0;
        int peakIndex = g_peakIndex[c];

        for(int i = (-PEAK_RANGE); i< PEAK_RANGE; i++)
        {
            peakEnergy[c] += peakhold[c][g_peakIndex[c]+i];
        }

        for(int i = 0; i < BLOCK_SIZE; i++)
        {
            if((i < (peakIndex-PEAK_RANGE)) || (i > (peakIndex+PEAK_RANGE)))
            {
                if(peakhold[c][i] > -200)
                {
                    otherEnergy[c] -= peakhold[c][i];
                    othercount++;
                }
            }
        }

        peakEnergy[c] /= (PEAK_RANGE*2+1);
        otherEnergy[c] /= (othercount-(PEAK_RANGE*2+1));
        otherEnergy[c] *= -1;

        /* Convert to freq */
        g_peakIndex[c] = (int)((double)g_peakIndex[c]*g_div);

        fprintf(stderr, "Channel %d : Peak found at approx %d Hz, Peak avg: %10g, Other Freqs: %10g\n", c, g_peakIndex[c], (peakEnergy[c]), otherEnergy[c]);

        if(otherEnergy[c] > -85)
        {
            fprintf(stderr, "Suspect glitch on this channel!\n\n");
        }
        else
        {
            fprintf(stderr, "Looks okay - manual inspect to be sure!\n\n");
        }

    }

    return ;
} /* convert_to_fft */