Exemple #1
0
TMove CMyAI::ourNewTurn()
{
	assert(!inEnemyTurn);
	TMove result;
	static CMyTimer *timer = CMyTimer::getInstance();

	if (activeIsolatedMode || isIsolated(this->boardData, this->p1, this->p2)){
		activeIsolatedMode = true;
		cout << "Isolated mode!" << endl;
		TPos p1, p2;
		p1 = CC(p_ai->GetMyPosition().x, p_ai->GetMyPosition().y);
		p2 = CC(p_ai->GetEnemyPosition().x, p_ai->GetEnemyPosition().y);

		static CBCO o1, o2;
		CBC::calculateBCs(this->boardData, &o1, p1);
		CBC::calculateBCs(this->boardData, &o2, p2);
		int n1, n2;
		n1 = o1.findLengthOfLongestPath(EXACT_AREA_BELOW_10);
		n2 = o2.findLengthOfLongestPath(EXACT_AREA_BELOW_10);
		if (abs(n1 - n2) < 4)
		{
			int _n1 = o1.findLengthOfLongestPath(EXACT);
			if (_n1 != TIMEOUT_POINTS)
			{
				n1 = _n1;
				int _n2 = o2.findLengthOfLongestPath(EXACT);
				if (_n2 != TIMEOUT_POINTS)
					n2 = _n2;
			}
		}

		cout << "\tEstimated length of our path	   " << n1 << endl;
		cout << "\tEstimated length of enemy path  " << n2 << endl;
		if (n1 > n2)
			cout << "\t => It seems that we will f*****g WIN  ";
		else
			cout << "\t => It seems that we will f*****g LOSE ";
		if (first == we)
			cout << "this easy game " << n1 - n2 << endl;
		else
			cout << "this hard game " << n1 - n2 << endl;
		p1 = CC(p_ai->GetMyPosition().x, p_ai->GetMyPosition().y);
		TMove estimateMove = CHeuristicBase::getFirstMove(boardData, p1, EXACT_AREA_BELOW_25, n1);
		TMove exactMove = CHeuristicBase::getFirstMove(boardData, p1, EXACT, n1);
		if (exactMove < 1 || exactMove > 4)
			result = estimateMove;
		else
			result = exactMove;

		result = estimateMove;
	}
	else
	{
		static bool followingMode = TRY_FOLLOWING && we != first;
		if (followingMode){
			TPos u = MOVE(we == PLAYER_1 ? p1 : p2, getOpositeDirection(history.back())) != BLOCK_EMPTY;
			if (GET_BLOCK(boardData, u))
				followingMode = false;
		}

		if (followingMode) {
			assert(history.size() % 2 == 1);
			for (unsigned int i = 0; i < history.size() - 1; i = i + 2){
				if (history[i] != getOpositeDirection(history[i + 1]))
				{
					followingMode = false;
					break;
				}
			}

		}
		else{
			followingMode = false;
		}

		pair<TMove, int> re = searcher.optimalMove(boardData, p1, p2, next, history);
		if (we == PLAYER_2)
			re.second = -re.second;

		if (!followingMode || re.first == getOpositeDirection(history.back()))
		{
			result = re.first;
		}
		else {
			if (re.second >= 0)
				result = re.first;
			else
			{
				result = getOpositeDirection(history.back());
				cout << "\t===FOLLOWING ENEMY===\n";
			}
		}
	}
	cout << "We take " << timer->getTimeInMs() << " ms\n";
	return result;
}
Exemple #2
0
void GenerateAllCaps(const S_BOARD *pos, S_MOVELIST *list) {
	int pce = EMPTY;
	int side = pos->side;
	int sq = 0, t_sq = 0;
	int pceNum = 0;

	int dir = 0;
	int index = 0;
	int pceIndex = 0;

	ASSERT(CheckBoard(pos));
	list->count = 0;

	if(side == WHITE) {
		for(pceNum = 0; pceNum < pos->pceNum[wP]; ++pceNum) {
			sq = pos->pList[wP][pceNum];
			ASSERT(SqOnBoard(sq));

			if(!SQOFFBOARD(sq + 9) && PieceCol[pos->pieces[sq + 9]] == BLACK) {
				AddWhitePawnCapMove(pos, sq, sq + 9, pos->pieces[sq + 9], list);
			}
			if(!SQOFFBOARD(sq + 11) && PieceCol[pos->pieces[sq + 11]] == BLACK) {
				AddWhitePawnCapMove(pos, sq, sq + 11, pos->pieces[sq + 11], list);
			}

			if(pos->enPas != NO_SQ) {
				if(sq + 9 == pos->enPas) {
					AddEnPassantMove(pos, MOVE(sq, sq + 9, EMPTY, EMPTY, MFLAGEP), list);
				}
				if(sq + 11 == pos->enPas) {
					AddEnPassantMove(pos, MOVE(sq, sq + 11, EMPTY, EMPTY, MFLAGEP), list);
				}
			}
		}

	} else {
		for(pceNum = 0; pceNum < pos->pceNum[bP]; ++pceNum) {
			sq = pos->pList[bP][pceNum];
			ASSERT(SqOnBoard(sq));

			if(!SQOFFBOARD(sq - 9) && PieceCol[pos->pieces[sq - 9]] == WHITE) {
				AddBlackPawnCapMove(pos, sq, sq - 9, pos->pieces[sq - 9], list);
			}
			if(!SQOFFBOARD(sq - 11) && PieceCol[pos->pieces[sq - 11]] == WHITE) {
				AddBlackPawnCapMove(pos, sq, sq - 11, pos->pieces[sq - 11], list);
			}

			if(pos->enPas != NO_SQ) {
				if(sq - 9 == pos->enPas) {
					AddEnPassantMove(pos, MOVE(sq, sq - 9, EMPTY, EMPTY, MFLAGEP), list);
				}
				if(sq - 11 == pos->enPas) {
					AddEnPassantMove(pos, MOVE(sq, sq - 11, EMPTY, EMPTY, MFLAGEP), list);
				}
			}
		}	

	}

	pceIndex = LoopSlideIndex[side];
	pce = LoopSlidePce[pceIndex++];
	while(pce != 0) {
		ASSERT(PieceValid(pce));

		for(pceNum = 0; pceNum < pos->pceNum[pce]; ++pceNum) {
			sq = pos->pList[pce][pceNum];
			ASSERT(SqOnBoard(sq));

			for(index = 0; index < NumDir[pce]; ++index) {
				dir = PceDir[pce][index];
				t_sq = sq + dir;

				while(!SQOFFBOARD(t_sq)) {

					if(pos->pieces[t_sq] != EMPTY) {
						if(PieceCol[pos->pieces[t_sq]] == (side ^ 1)) {
							AddCaptureMove(pos, MOVE(sq, t_sq, pos->pieces[t_sq], EMPTY, 0), list);
						}
						break;
					}
					t_sq += dir;
				}
			}
		}
		pce = LoopSlidePce[pceIndex++];
	}

	pceIndex = LoopNonSlideIndex[side];
	pce = LoopNonSlidePce[pceIndex++];
	while(pce != 0) {
		ASSERT(PieceValid(pce));

		for(pceNum = 0; pceNum < pos->pceNum[pce]; ++pceNum) {
			sq = pos->pList[pce][pceNum];
			ASSERT(SqOnBoard(sq));

			for(index = 0; index < NumDir[pce]; ++index) {
				dir = PceDir[pce][index];
				t_sq = sq + dir;

				if(SQOFFBOARD(t_sq))
					continue;

				if(pos->pieces[t_sq] != EMPTY) {
					if(PieceCol[pos->pieces[t_sq]] == (side ^ 1)) {
						AddCaptureMove(pos, MOVE(sq, t_sq, pos->pieces[t_sq], EMPTY, 0), list);
					}
					continue;
				}
			}
		}
		pce = LoopNonSlidePce[pceIndex++];
	}
}
Exemple #3
0
void DisassembleToken(DacpObjectData& tokenArray,
                      DWORD token)
{    
    switch (TypeFromToken(token))
    {
    default:
        printf("<unknown token type (token=%08x)>", token);
        break;

    case mdtTypeDef:
        {
            DWORD_PTR runtimeTypeHandle = GetObj(tokenArray, RidFromToken(token));

            DWORD_PTR runtimeType = NULL;
            MOVE(runtimeType, runtimeTypeHandle + sizeof(DWORD_PTR));

            int offset = GetObjFieldOffset(runtimeType, W("m_handle"));

            DWORD_PTR methodTable = NULL;
            MOVE(methodTable, runtimeType + offset);

            if (NameForMT_s(methodTable, g_mdName,mdNameLen))
            {
                printf("%x \"%S\"", token, g_mdName);
            }
            else
            {
                printf("<invalid MethodTable>");
            }
        }
        break;

    case mdtSignature:
    case mdtTypeRef:
        {
            printf ("%x (%p)", token, SOS_PTR(GetObj(tokenArray, RidFromToken(token))));
        }
        break;

    case mdtFieldDef:
        {
            printf ("%x (%p)", token, SOS_PTR(GetObj(tokenArray, RidFromToken(token))));
        }
        break;

    case mdtMethodDef:
        {
            CLRDATA_ADDRESS runtimeMethodHandle = GetObj(tokenArray, RidFromToken(token));            
            int offset = GetObjFieldOffset(runtimeMethodHandle, W("m_value"));

            TADDR runtimeMethodInfo = NULL;
            MOVE(runtimeMethodInfo, runtimeMethodHandle+offset);

            offset = GetObjFieldOffset(runtimeMethodInfo, W("m_handle"));

            TADDR methodDesc = NULL;
            MOVE(methodDesc, runtimeMethodInfo+offset);

            NameForMD_s((DWORD_PTR)methodDesc, g_mdName, mdNameLen);
            printf ("%x %S", token, g_mdName);
        }
        break;

    case mdtMemberRef:
        {
            printf ("%x (%p)", token, SOS_PTR(GetObj(tokenArray, RidFromToken(token))));
        }
        break;
    case mdtString:
        {
            DWORD_PTR strObj = GetObj(tokenArray, RidFromToken(token));
            printf ("%x \"", token);
            StringObjectContent (strObj, FALSE, 40);
            printf ("\"");
        }
        break;
    }
}
Exemple #4
0
static inline
unsigned char *advance(unsigned char *pc)
{
  if (SEND(pc)) {
    int count = 3;
		
    if (VAL_IS_FLOAT(SEND_ARG1(pc)))
      count += sizeof(meld_float);
    else if (VAL_IS_INT(SEND_ARG1(pc)))
      count += sizeof(meld_int);
    else if (VAL_IS_FIELD(SEND_ARG1(pc)))
      count += 2;
    else if (VAL_IS_REVERSE(SEND_ARG1(pc)))
      count += 2;
    else {
      assert(0);
      exit(1);
    }

    return pc+count;
  }
  else if(OP(pc)) {
    int count = 3;

    /* check v1 */
    if (VAL_IS_FLOAT(OP_ARG1(pc)))
      count += sizeof(meld_float);
    else if (VAL_IS_INT(OP_ARG1(pc)))
      count += sizeof(meld_int);
    else if (VAL_IS_FIELD(OP_ARG1(pc)))
      count += 2;
    else if (VAL_IS_REVERSE(OP_ARG1(pc)))
      count += 2;
    else if (VAL_IS_REG(OP_ARG1(pc)))
      {} /* do nothing */
    else {
      assert(0);
      exit(1);
    }
			
    /* check v2 */
    if (VAL_IS_FLOAT(OP_ARG2(pc)))
      count += sizeof(meld_float);
    else if (VAL_IS_INT(OP_ARG2(pc)))
      count += sizeof(meld_int);
    else if (VAL_IS_FIELD(OP_ARG2(pc)))
      count += 2;
    else if (VAL_IS_REVERSE(OP_ARG2(pc)))
      count += 2;
    else if (VAL_IS_REG(OP_ARG2(pc)))
      {} /* do nothing */
    else {
      printf("got value %c\n", OP_ARG2(pc));
      assert(0);
      exit(1);
    }

    return pc+count;
  }
  else if(MOVE(pc)) {
    int count = 2;
		
    /* move src */
    if (VAL_IS_FLOAT(MOVE_SRC(pc)))
      count += sizeof(meld_float);
    else if (VAL_IS_INT(MOVE_SRC(pc)))
      count += sizeof(meld_int);
    else if (VAL_IS_FIELD(MOVE_SRC(pc)))
      count += 2;
    else if (VAL_IS_REVERSE(MOVE_SRC(pc)))
      count += 2;
    else if (VAL_IS_TUPLE(MOVE_SRC(pc)))
      {} /* nothing */
    else if(VAL_IS_REG(MOVE_SRC(pc)))
      {} /* nothing */
    else if(VAL_IS_HOST(MOVE_SRC(pc)))
      {} /* nothing */
    else {
      assert(0);
      exit(1);
    }
  		
    /* move dst */
    if (VAL_IS_FLOAT(MOVE_DST(pc)))
      count += sizeof(meld_float);
    else if (VAL_IS_INT(MOVE_DST(pc)))
      count += sizeof(meld_int);
    else if (VAL_IS_FIELD(MOVE_DST(pc)))
      count += 2;
    else if (VAL_IS_REVERSE(MOVE_DST(pc)))
      count += 2;
    else if (VAL_IS_REG(MOVE_DST(pc)))
      {} /* nothing */
    else {
      assert(0);
      exit(1);
    }

    return pc+count;
  }
  else if(ITER(pc)) {
    
    pc += ITER_BASE;
    
    if(ITER_MATCH_NONE(pc))
      pc += 2;
    else {
      unsigned char *old;
      while(1) {
        old = pc;

	if (VAL_IS_FLOAT(ITER_MATCH_VAL(pc)))
	  pc += sizeof(meld_float);
	else if (VAL_IS_INT(ITER_MATCH_VAL(pc)))
	  pc += sizeof(meld_int);
	else if (VAL_IS_FIELD(ITER_MATCH_VAL(pc)))
	  pc += 2;
	else if (VAL_IS_REVERSE(ITER_MATCH_VAL(pc)))
	  pc += 2;
	else {
	  assert(0);
	  exit(1);
	}

        pc += 2;

        if(ITER_MATCH_END(old))
          break;
      }
    }

    return pc;
  } else if (ALLOC(pc)) {
    int count = 2;

    if (VAL_IS_INT(ALLOC_DST(pc)))
      count += sizeof(meld_int);
    else if	(VAL_IS_FLOAT(ALLOC_DST(pc)))
      count += sizeof(meld_float);
    else if (VAL_IS_FIELD(ALLOC_DST(pc)))
      count += 2;
    else if (VAL_IS_REG(ALLOC_DST(pc)))
      {} /* nothing */
    else if (VAL_IS_REVERSE(ALLOC_DST(pc))) {
      count += 2;
      assert(0);
      exit(1);
    } else {
      assert(0);
      exit(1);
    }

    return pc+count;
  }
  else if (CALL(pc)) {
    int numArgs = CALL_ARGS(pc);
    int i;
		
    for (i = 0, pc+=2; i < numArgs; i++, pc++) {
      if (VAL_IS_FLOAT(CALL_VAL(pc)))
        pc += sizeof(meld_float);
      else if (VAL_IS_INT(CALL_VAL(pc)))
	pc += sizeof(meld_int);
      else if (VAL_IS_FIELD(CALL_VAL(pc)))
	pc += 2;
      else if (VAL_IS_REVERSE(CALL_VAL(pc))) {
	pc += 2;
	assert(0);
	exit(1);
      }
    }
    return pc;
  }
  else if (IF(pc)) {
    return pc+IF_BASE;
  }
  else {
    return pc+1;
  }
}
Exemple #5
0
/*
 *
 * \brief Sine modulation of the time domain data of a subband. Performed in-place
 *
 */
static void
sinMod (float *subband,
        HANDLE_SBR_QMF_FILTER_BANK qmfBank
        )
{
  int i, M;
  float wre, wim;
  float re1, im1, re2, im2;
  float accu1,accu2;

  COUNT_sub_start("sinMod");

  INDIRECT(1); SHIFT(1);
  M = qmfBank->no_channels >> 1;

  PTR_INIT(6);  /* pointers for subband[2 * i],
                                subband[2 * M - 2 * i],
                                qmfBank->sin_twiddle[i],
                                qmfBank->cos_twiddle[i],
                                qmfBank->sin_twiddle[M - 1 - i],
                                qmfBank->cos_twiddle[M - 1 - i]  */

  MULT(1); /* M/2 */ LOOP(1);
  for (i = 0; i < M / 2; i++) {

    MOVE(4);
    re1 = subband[2 * i];
    im2 = subband[2 * i + 1];
    re2 = subband[2 * M - 2 - 2 * i];
    im1 = subband[2 * M - 1 - 2 * i];

    MOVE(2);
    wre = qmfBank->sin_twiddle[i];
    wim = qmfBank->cos_twiddle[i];

    MULT(1); MAC(1);
    accu1 = im1 * wim + re1 * wre;
    MULT(2); ADD(1);
    accu2 = im1 * wre - re1 * wim;

    MOVE(2);
    subband[2 * i + 1] = accu1;
    subband[2 * i] = accu2;

    MOVE(2);
    wre = qmfBank->sin_twiddle[M - 1 - i];
    wim = qmfBank->cos_twiddle[M - 1 - i];

    MULT(1); MAC(1);
    accu1 = im2 * wim + re2 * wre;
    MULT(2); ADD(1);
    accu2 = im2 * wre - re2 * wim;

    MOVE(2);
    subband[2 * M - 1 - 2 * i] = accu1;
    subband[2 * M - 2 - 2 * i] = accu2;
  }

  FUNC(2);
  sbrfft(subband, M);

  PTR_INIT(4);  /* pointers for  subband[2 * i],
                                 subband[2 * M - 2 * i],
                                 qmfBank->alt_sin_twiddle[i],
                                 qmfBank->sin_twiddle[M - 1 - i] */
  MOVE(2);
  wim = qmfBank->alt_sin_twiddle[0];
  wre = qmfBank->alt_sin_twiddle[M];

  for (i = 0; i < M / 2; i++) {

    MOVE(4);
    re1 = subband[2 * i];
    im1 = subband[2 * i + 1];
    re2 = subband[2 * M - 2 - 2 * i];
    im2 = subband[2 * M - 1 - 2 * i];

    MULT(2); MAC(1);
    accu1 = -(re1 * wre + im1 * wim);
    MULT(2); ADD(1);
    accu2 = -(re1 * wim - im1 * wre);

    MOVE(2);
    subband[2 * M - 1 - 2 * i] = accu1;
    subband[2 * i] = accu2;

    MOVE(2);
    wim = qmfBank->alt_sin_twiddle[i + 1];
    wre = qmfBank->alt_sin_twiddle[M - 1 - i];

    MULT(2); MAC(1);
    accu1 = -(re2 * wim + im2 * wre);
    MULT(2); ADD(1);
    accu2 = -(re2 * wre - im2 * wim);

    MOVE(2);
    subband[2 * i + 1] = accu1;
    subband[2 * M - 2 - 2 * i] = accu2;

  }

  COUNT_sub_end();
}
Exemple #6
0
static void
inverseModulationLP (float *qmfReal,
                     float *qmfReal2,
                     HANDLE_SBR_QMF_FILTER_BANK synQmf
                     )
{
  int i, L, M;
  float timeOut[2*NO_ACTUAL_SYNTHESIS_CHANNELS];

  COUNT_sub_start("inverseModulationLP");

  INDIRECT(1);
  L = synQmf->no_channels;

  MULT(1); STORE(1);
  M = L / 2;

  PTR_INIT(2);  /* pointers for timeOut[],
                                qmfReal[]  */
  INDIRECT(1); LOOP(1);
  for (i = 0; i < synQmf->usb; i++) {

    MOVE(1);
    timeOut[i + M] = qmfReal[i];
  }

  INDIRECT(1); LOOP(1);
  for (i = synQmf->usb; i < L; i++) {

    MOVE(1);
    timeOut[i + M] = 0;
  }

  FUNC(3);
  dct2(timeOut+M, L, synQmf);

  MOVE(1);
  timeOut[3 * M] = 0;

  PTR_INIT(2);  /* pointers for timeOut[i]
                                timeOut[-i] */
  LOOP(1);
  for (i = 1; i < M; i++) {

    MULT(1); STORE(1);
    timeOut[i + 3 * M] = - timeOut[3 * M - i];
  }

  PTR_INIT(2);  /* pointer for timeOut[i],
                               timeOut[L-i] */
  LOOP(1);
  for (i = 0; i < M; i++) {

    MOVE(1);
    timeOut[i] = timeOut[L - i];
  }

  PTR_INIT(2);  /* pointer for timeOut[],
                               qmfReal[]  */
  LOOP(1);
  for (i = 0; i < L; i++) {

    MOVE(1);
    qmfReal[i] = timeOut[i];
  }

  PTR_INIT(2);  /* pointer for timeOut[],
                               qmfReal2[]  */
  LOOP(1);
  for (i = 0; i < L; i++) {

    MOVE(1);
    qmfReal2[i] = timeOut[L+i];
  }

  COUNT_sub_end();
}
Exemple #7
0
void calcSfbPe(PE_CHANNEL_DATA *peChanData,
               const float *sfbEnergy,
               const float *sfbThreshold,
               const int    sfbCnt,
               const int    sfbPerGroup,
               const int    maxSfbPerGroup)
{
   int sfbGrp,sfb;
   float nLines;
   float ldThr, ldRatio;

   COUNT_sub_start("calcSfbPe");

   INDIRECT(3); MOVE(3);
   peChanData->pe = 0.0f;
   peChanData->constPart = 0.0f;
   peChanData->nActiveLines = 0.0f;

   LOOP(1);
   for(sfbGrp = 0;sfbGrp < sfbCnt;sfbGrp+=sfbPerGroup){

    PTR_INIT(8); /* pointers for sfbEnergy[]
                                 sfbThreshold[]
                                 peChanData->sfbLdEnergy[]
                                 peChanData->sfbNLines[]
                                 peChanData->sfbPe[]
                                 peChanData->sfbConstPart[]
                                 peChanData->sfbLdEnergy[]
                                 peChanData->sfbNActiveLines[]
                 */
    LOOP(1);
    for (sfb=0; sfb<maxSfbPerGroup; sfb++) {

      ADD(1); BRANCH(1);
      if (sfbEnergy[sfbGrp+sfb] > sfbThreshold[sfbGrp+sfb]) {

         TRANS(1); MULT(1);
         ldThr = (float)log(sfbThreshold[sfbGrp+sfb]) * LOG2_1;

         ADD(1);
         ldRatio = peChanData->sfbLdEnergy[sfbGrp+sfb] - ldThr;

         MOVE(1);
         nLines = peChanData->sfbNLines[sfbGrp+sfb];

         ADD(1); BRANCH(1);
         if (ldRatio >= C1) {

            MULT(1); STORE(1);
            peChanData->sfbPe[sfbGrp+sfb] = nLines * ldRatio;

            MULT(1); STORE(1);
            peChanData->sfbConstPart[sfbGrp+sfb] = nLines*peChanData->sfbLdEnergy[sfbGrp+sfb];
         }
         else {

            MULT(2); ADD(1); STORE(1);
            peChanData->sfbPe[sfbGrp+sfb] = nLines * (C2 + C3 * ldRatio);

            MULT(2); ADD(1); STORE(1);
            peChanData->sfbConstPart[sfbGrp+sfb] = nLines *
               (C2 + C3 * peChanData->sfbLdEnergy[sfbGrp+sfb]);

            MULT(1);
            nLines = nLines * C3;
         }

         MOVE(1);
         peChanData->sfbNActiveLines[sfbGrp+sfb] = nLines;
      }
      else {

         MOVE(3);
         peChanData->sfbPe[sfbGrp+sfb] = 0.0f;
         peChanData->sfbConstPart[sfbGrp+sfb] = 0.0f;
         peChanData->sfbNActiveLines[sfbGrp+sfb] = 0.0;
      }

      INDIRECT(3); ADD(3); STORE(3);
      peChanData->pe += peChanData->sfbPe[sfbGrp+sfb];
      peChanData->constPart += peChanData->sfbConstPart[sfbGrp+sfb];
      peChanData->nActiveLines += peChanData->sfbNActiveLines[sfbGrp+sfb];
    }
   }

   COUNT_sub_end();
}
Exemple #8
0
/*
    Perform dct type 4
 */
static void
dct4 (float *data,
      int L,
      HANDLE_SBR_QMF_FILTER_BANK qmfBank
      )
{
  int i, M, ld;
  float wim, wre;
  float re1, im1, re2, im2;
  struct dct4Twiddle *pTwiddle;

  const float cosPiBy8  = 0.92387953251129f;
  const float cosPi3By8 = 0.38268343236509f;
  MOVE(2);

  MOVE(1);
  i = 1;

  MULT(1);
  M = L / 2;

  MOVE(1);
  ld = -2;


  ADD(1); BRANCH(1);
  if (L > 2) {

    LOOP(1);
    while(i < L) {
      SHIFT(1);
      i <<= 1;

      ADD(1);
      ld++;
    }

    INDIRECT(1); PTR_INIT(1);
    pTwiddle = &qmfBank->pDct4Twiddle[ld];

    MULT(1); /* M / 2 */
    LOOP(1); PTR_INIT(6); /* pointers for data[2 * i],
                                          data[2 * M - 2 * i],
                                          pTwiddle->sin_twiddle[],
                                          pTwiddle->cos_twiddle[],
                                          pTwiddle->sin_twiddle[M - 1 - i],
                                          pTwiddle->cos_twiddle[M - 1 - i] */
    for (i = 0; i < M / 2; i++) {

      MOVE(4);
      re1 = data[2 * i];
      im2 = data[2 * i + 1];
      re2 = data[2 * M - 2 - 2 * i];
      im1 = data[2 * M - 1 - 2 * i];

      MOVE(2);
      wim = pTwiddle->sin_twiddle[i];
      wre = pTwiddle->cos_twiddle[i];

      MULT(1); MAC(1); STORE(1);
      data[2 * i]     = im1 * wim + re1 * wre;

      MULT(2); ADD(1); STORE(1);
      data[2 * i + 1] = im1 * wre - re1 * wim;

      MOVE(2);
      wim = pTwiddle->sin_twiddle[M - 1 - i];
      wre = pTwiddle->cos_twiddle[M - 1 - i];

      MULT(1); MAC(1); STORE(1);
      data[2 * M - 2 - 2 * i] = im2 * wim + re2 * wre;

      MULT(2); ADD(1); STORE(1);
      data[2 * M - 1 - 2 * i] = im2 * wre - re2 * wim;
    }

    ADD(1); BRANCH(1);
    if (M == 2) {

      MOVE(2);
      re1 = data[0];
      im1 = data[1];

      ADD(4); STORE(4);
      data[0] = re1 + data[2];
      data[1] = im1 + data[3];
      data[2] = re1 - data[2];
      data[3] = im1 - data[3];
    }
    else {
      FUNC(2);
      sbrfft(data,M);
    }

    INDIRECT(2); MOVE(2);
    wim = pTwiddle->alt_sin_twiddle[0];
    wre = pTwiddle->alt_sin_twiddle[M];

    PTR_INIT(4);  /* pointers for data[2 * i],
                                  data[2 * M - 2 * i],
                                  pTwiddle->alt_sin_twiddle[i],
                                  pTwiddle->alt_sin_twiddle[M - 1 - i] */
    LOOP(1);
    for (i = 0; i < M / 2; i++) {

      MOVE(4);
      re1 = data[2 * i];
      im1 = data[2 * i + 1];
      re2 = data[2 * M - 2 - 2 * i];
      im2 = data[2 * M - 1 - 2 * i];

      MULT(1); MAC(1); STORE(1);
      data[2 * i]             = re1 * wre + im1 * wim;

      MULT(2); ADD(1); STORE(1);
      data[2 * M - 1 - 2 * i] = re1 * wim - im1 * wre;

      MOVE(2);
      wim = pTwiddle->alt_sin_twiddle[i + 1];
      wre = pTwiddle->alt_sin_twiddle[M - 1 - i];

      MULT(1); MAC(1); STORE(1);
      data[2 * M - 2 - 2 * i] = re2 * wim + im2 * wre;
      MULT(2); ADD(1); STORE(1);
      data[2 * i + 1]         = re2 * wre - im2 * wim;
    }
  }
  else { /* 2-point transform */

    MOVE(2);
    re1 = data[0];
    re2 = data[1];

    MULT(1); MAC(1); STORE(1);
    data[0] = re1 * cosPiBy8  + re2 * cosPi3By8;

    MULT(2); ADD(1); STORE(1);
    data[1] = re1 * cosPi3By8 - re2 * cosPiBy8;
  }

}
Exemple #9
0
void CShortBlock_FrequencyToTime(CAacDecoderStaticChannelInfo *pAacDecoderStaticChannelInfo,
                                 CAacDecoderChannelInfo *pAacDecoderChannelInfo,
                                 float outSamples[],
                                 const int stride)
{
  int i;
  COverlapAddData *pOverlapAddData = &pAacDecoderStaticChannelInfo->OverlapAddData;
  const float *shortWindow = pAacDecoderStaticChannelInfo->pShortWindow[GetWindowShape(&pAacDecoderChannelInfo->IcsInfo)];
  const float *shortWindowPrev = pAacDecoderStaticChannelInfo->pShortWindow[pOverlapAddData->WindowShape];
  const float *longWindowPrev = pAacDecoderStaticChannelInfo->pLongWindow[pOverlapAddData->WindowShape];
  float *pSpectralCoefficient = pAacDecoderChannelInfo->pSpectralCoefficient;

  FLC_sub_start("CShortBlock_FrequencyToTime");

  INDIRECT(5); PTR_INIT(5); /* counting previous operations */

  /* Inverse MDCT */
  PTR_INIT(1); /* pSpectralCoefficient[i*Size02] */
  LOOP(1);
  for (i=0; i<MaximumWindows; i++) {
    FUNC(1);
    CShortBlock_InverseTransform(&pSpectralCoefficient[i*Size02]);
  }

  /* Overlap & Add */
  INDIRECT(1); BRANCH(2);
  switch(pOverlapAddData->WindowSequence)
  {
    case EightShortSequence:
    case LongStartSequence:

      PTR_INIT(2); /* outSamples[stride*i]
                      pOverlapAddData->pOverlapBuffer[i]
                   */
      LOOP(1);
      for (i=0; i<Size07; i++)
      {
        MOVE(1);
        outSamples[stride*i] = pOverlapAddData->pOverlapBuffer[i];
      }

      INDIRECT(2); PTR_INIT(3); FUNC(6);
      Lap1(&pSpectralCoefficient[0],&pOverlapAddData->pOverlapBuffer[Size07],
           &outSamples[stride*Size07],shortWindowPrev,Size01,stride);

      INDIRECT(1); PTR_INIT(3); FUNC(6);
      Lap1(&pSpectralCoefficient[Size02],&pSpectralCoefficient[0],
           &outSamples[stride*Size09],shortWindow,Size01,stride);

      INDIRECT(1); PTR_INIT(3); FUNC(6);
      Lap1(&pSpectralCoefficient[Size04],&pSpectralCoefficient[Size02],
           &outSamples[stride*Size11],shortWindow,Size01,stride);

      INDIRECT(1); PTR_INIT(3); FUNC(6);
      Lap1(&pSpectralCoefficient[Size06],&pSpectralCoefficient[Size04],
           &outSamples[stride*Size13],shortWindow,Size01,stride);

      PTR_INIT(3); FUNC(6);
      Lap2(&pSpectralCoefficient[Size08],&pSpectralCoefficient[Size06],
           pOverlapAddData->pOverlapBuffer,shortWindow,Size01,1);

      PTR_INIT(3); /* outSamples[stride*(Size15+i)]
                      pOverlapAddData->pOverlapBuffer[i]
                      pOverlapAddData->pOverlapBuffer[i+Size01]
                   */
      LOOP(1);
      for (i=0; i<Size01; i++)
      {
        MOVE(2);
        outSamples[stride*(Size15+i)] = pOverlapAddData->pOverlapBuffer[i];
        pOverlapAddData->pOverlapBuffer[i] = pOverlapAddData->pOverlapBuffer[i+Size01];
      }
    break;

    case OnlyLongSequence:
    case LongStopSequence:
      INDIRECT(1); FUNC(6);
      LongShortLapIllegal(pSpectralCoefficient,pOverlapAddData->pOverlapBuffer,outSamples,
                          shortWindow,shortWindowPrev,longWindowPrev,stride);
    break;
  }

  PTR_INIT(3); FUNC(6);
  Lap2(&pSpectralCoefficient[Size10],&pSpectralCoefficient[Size08],
       &pOverlapAddData->pOverlapBuffer[Size01],shortWindow,Size01,1);

  PTR_INIT(3); FUNC(6);
  Lap2(&pSpectralCoefficient[Size12],&pSpectralCoefficient[Size10],
       &pOverlapAddData->pOverlapBuffer[Size03],shortWindow,Size01,1);

  PTR_INIT(3); FUNC(6);
  Lap2(&pSpectralCoefficient[Size14],&pSpectralCoefficient[Size12],
       &pOverlapAddData->pOverlapBuffer[Size05],shortWindow,Size01,1);

  PTR_INIT(2); /* pOverlapAddData->pOverlapBuffer[i+Size07]
                  pSpectralCoefficient[Size14+i]
               */
  LOOP(1);
  for (i=0; i<Size01; i++)
  {
    MOVE(1);
    pOverlapAddData->pOverlapBuffer[i+Size07] = pSpectralCoefficient[Size14+i];
  }

  INDIRECT(1); PTR_INIT(1); FUNC(1); FUNC(1); STORE(2);
  pOverlapAddData->WindowShape = GetWindowShape(&pAacDecoderChannelInfo->IcsInfo);
  pOverlapAddData->WindowSequence = GetWindowSequence(&pAacDecoderChannelInfo->IcsInfo);


  FLC_sub_end();
}
Exemple #10
0
int CShortBlock_ReadSectionData(HANDLE_BIT_BUF bs,
                                CAacDecoderChannelInfo *pAacDecoderChannelInfo)
{
  int top;
  int band;
  int group;
  char sect_cb;
  int sect_len;
  int sect_len_incr;
  int sect_esc_val = (1 << 3) - 1 ;
  char *pCodeBook = pAacDecoderChannelInfo->pCodeBook;
  int ErrorStatus = AAC_DEC_OK;

  FLC_sub_start("CShortBlock_ReadSectionData");
  
  INDIRECT(1); PTR_INIT(1); MOVE(2); /* counting previous operation */

  INDIRECT(1); PTR_INIT(1); FUNC(1); LOOP(1);
  for (group=0; group<GetWindowGroups(&pAacDecoderChannelInfo->IcsInfo); group++)
  {
    PTR_INIT(1); /* pCodeBook[] */
    FUNC(1); LOOP(1);
    for (band=0; band<GetScaleFactorBandsTransmitted(&pAacDecoderChannelInfo->IcsInfo); )
    {
      MOVE(1);
      sect_len = 0 ;

      FUNC(2);
      sect_cb = (char) GetBits(bs,4) ;

      FUNC(2);
      sect_len_incr = GetBits(bs,3);

      LOOP(1);
      while (sect_len_incr == sect_esc_val)
      {
        ADD(1);
        sect_len += sect_esc_val;

        FUNC(2);
        sect_len_incr = GetBits(bs,3);
      }

      ADD(1);
      sect_len += sect_len_incr;


      ADD(1);
      top = band + sect_len;

      MULT(1); ADD(2); BRANCH(1);
      if (top + group*MaximumScaleFactorBandsShort > (MAX_WINDOWS * MAX_SFB_SHORT)) {
        FLC_sub_end();
        return (AAC_DEC_DECODE_FRAME_ERROR);
      }

      LOOP(1);
      for (; band < top; band++)
      {
        MOVE(1);
        pCodeBook[group*MaximumScaleFactorBandsShort+band] = sect_cb;

        ADD(1); BRANCH(1);
        if (pCodeBook[group*MaximumScaleFactorBandsShort+band] == BOOKSCL)
        {
          FLC_sub_end();
          return (AAC_DEC_INVALID_CODE_BOOK);
        }
      }
    }

    PTR_INIT(1); /* pCodeBook[] */
    FUNC(1); LOOP(1);
    for ( ; band < GetScaleFactorBandsTotal(&pAacDecoderChannelInfo->IcsInfo); band++)
    {
      MOVE(1);
      pCodeBook[group*MaximumScaleFactorBandsShort+band] = ZERO_HCB;
    }
  }


  FLC_sub_end();

  return (ErrorStatus);
}
Exemple #11
0
int  CShortBlock_ReadSpectralData(HANDLE_BIT_BUF bs,
                                  CAacDecoderChannelInfo *pAacDecoderChannelInfo)
{
  int i,index,step;
  int window,group,groupwin,groupoffset,band;
  int scfExp,scfMod;
  int *QuantizedCoef;
  char *pCodeBook = pAacDecoderChannelInfo->pCodeBook;
  short *pScaleFactor = pAacDecoderChannelInfo->pScaleFactor;
  float *pSpectralCoefficient = pAacDecoderChannelInfo->pSpectralCoefficient;
  const short *BandOffsets = GetScaleFactorBandOffsets(&pAacDecoderChannelInfo->IcsInfo);
  const CodeBookDescription *hcb;

  FLC_sub_start("CShortBlock_ReadSpectralData");

  QuantizedCoef = (int*)pSpectralCoefficient;
  PTR_INIT(5); INDIRECT(4); FUNC(1); /* counting previous operations */

  LOOP(1);
  for (window=0; window < MaximumWindows; window++)
  {
    PTR_INIT(1); /* pointer for QuantizedCoef[] */
    LOOP(1);
    for (index=0; index < MaximumBinsShort; index++) {
      MOVE(1);
      QuantizedCoef[window*MaximumBinsShort+index] = 0;
    }
  }


  MOVE(1);
  groupoffset = 0;

  INDIRECT(1); FUNC(1); LOOP(1);
  for (group=0; group < GetWindowGroups(&pAacDecoderChannelInfo->IcsInfo); group++)
  {
    PTR_INIT(1); /* pointer for pCodeBook[] */
    INDIRECT(1); FUNC(1); LOOP(1);
    for (band=0; band < GetScaleFactorBandsTransmitted(&pAacDecoderChannelInfo->IcsInfo); band++)
    {
      PTR_INIT(1);
      hcb = &HuffmanCodeBooks[pCodeBook[group*MaximumScaleFactorBandsShort+band]];

      INDIRECT(1); FUNC(1); LOOP(1);
      for (groupwin=0; groupwin < GetWindowGroupLength(&pAacDecoderChannelInfo->IcsInfo,group); groupwin++)
      {
        ADD(1);
        window = groupoffset + groupwin;

        ADD(4); LOGIC(3); BRANCH(1);
        if (  (pCodeBook[group*MaximumScaleFactorBandsShort+band] == ZERO_HCB)
            ||(pCodeBook[group*MaximumScaleFactorBandsShort+band] == INTENSITY_HCB)
            ||(pCodeBook[group*MaximumScaleFactorBandsShort+band] == INTENSITY_HCB2)
            ||(pCodeBook[group*MaximumScaleFactorBandsShort+band] == NOISE_HCB))
          continue;

        MOVE(1);
        step = 0 ;

        PTR_INIT(2); /* pointer for BandOffsets[],
                                    QuantizedCoef[] */
        LOOP(1);
        for (index=BandOffsets[band]; index < BandOffsets[band+1]; index+=step)
        {
          INDIRECT(1); FUNC(2); PTR_INIT(1); FUNC(3);
          step = CBlock_UnpackIndex(CBlock_DecodeHuffmanWord(bs,hcb->CodeBook),&QuantizedCoef[window*MaximumBinsShort+index],hcb);

          INDIRECT(1); BRANCH(1);
          if (hcb->Offset == 0)
          {
            PTR_INIT(1); /* pointer for QuantizedCoef[] */
            LOOP(1);
            for (i=0; i < step; i++)
            {
              BRANCH(1);
              if (QuantizedCoef[window*MaximumBinsShort+index+i])
              {
                FUNC(2);
                if (GetBits(bs,1)) /* sign bit */
                {
                  MULT(1); STORE(1);
                  QuantizedCoef [window*MaximumBinsShort+index+i] = -QuantizedCoef [window*MaximumBinsShort+index+i];
                }
              }
            }
          }

          ADD(1); BRANCH(1);
          if (pCodeBook[group*MaximumScaleFactorBandsShort+band] == ESCBOOK)
          {
            FUNC(2); STORE(1);
            QuantizedCoef[window*MaximumBinsShort+index] = CBlock_GetEscape(bs,QuantizedCoef[window*MaximumBinsShort+index]);

            FUNC(2); STORE(1);
            QuantizedCoef[window*MaximumBinsShort+index+1] = CBlock_GetEscape(bs,QuantizedCoef[window*MaximumBinsShort+index+1]);
  
            FUNC(1); FUNC(1); ADD(2); LOGIC(1); BRANCH(1);
            if (abs(QuantizedCoef[window*MaximumBinsShort+index]) > MAX_QUANTIZED_VALUE || abs(QuantizedCoef[window*MaximumBinsShort+index+1]) > MAX_QUANTIZED_VALUE) {
              FLC_sub_end();
              return (AAC_DEC_DECODE_FRAME_ERROR);
            }
          }
        }
      }
    }

    INDIRECT(1); ADD(1);
    groupoffset += GetWindowGroupLength(&pAacDecoderChannelInfo->IcsInfo,group);
  }



  INDIRECT(1); FUNC(1); LOOP(1);
  for (window=0, group=0; group < GetWindowGroups(&pAacDecoderChannelInfo->IcsInfo); group++)
  {
    INDIRECT(1); FUNC(1); LOOP(1);
    for (groupwin=0; groupwin < GetWindowGroupLength(&pAacDecoderChannelInfo->IcsInfo,group); groupwin++, window++)
    {
      MOVE(1);
      index = 0;

      PTR_INIT(2); /* pointer for BandOffsets[],
                                  pScaleFactor     */
      INDIRECT(1); FUNC(1); LOOP(1) ;
      /* quantize & apply scalefactors */
      for (band=0; band < GetScaleFactorBandsTransmitted(&pAacDecoderChannelInfo->IcsInfo); band++)
      {
        /* scalefactor exponents and scalefactor mantissa for current band */
        SHIFT(1);
        scfExp = pScaleFactor[group*MaximumScaleFactorBandsShort+band] >> 2;

        LOGIC(1);
        scfMod = pScaleFactor[group*MaximumScaleFactorBandsShort+band] & 3;

        PTR_INIT(2); /* pointer for QuantizedCoef[], 
                                    pSpectralCoefficient */
        LOOP(1);
        for (index=BandOffsets[band]; index < BandOffsets[band+1] ;index++)
        {
          ADD(1); FUNC(3); STORE(1);
          pSpectralCoefficient[window*MaximumBinsShort+index] = CBlock_Quantize(QuantizedCoef[window*MaximumBinsShort+index],scfMod,scfExp-6);
        }
      }

      PTR_INIT(1); /* pointer for pSpectralCoefficient */
      LOOP(1);
      for (; index < MaximumBinsShort; index++) {
        MOVE(1);
        pSpectralCoefficient[window*MaximumBinsShort+index] = 0.0;
      }
    }
  }


  FLC_sub_end();
  return (AAC_DEC_OK);
}
Exemple #12
0
void CShortBlock_ReadScaleFactorData(HANDLE_BIT_BUF bs,
                                     CAacDecoderChannelInfo *pAacDecoderChannelInfo,
                                     unsigned char global_gain)
{
  int temp;
  int band;
  int group;
  int position = 0;
  int factor = global_gain;
  char *pCodeBook = pAacDecoderChannelInfo->pCodeBook;
  short *pScaleFactor = pAacDecoderChannelInfo->pScaleFactor;
  const CodeBookDescription *hcb = &HuffmanCodeBooks[BOOKSCL];

  FLC_sub_start("CShortBlock_ReadScaleFactorData");

  INDIRECT(3); PTR_INIT(3); MOVE(2); /* counting previous operations */

  INDIRECT(1); PTR_INIT(1); FUNC(1); LOOP(1);
  for (group=0; group < GetWindowGroups(&pAacDecoderChannelInfo->IcsInfo); group++)
  {
    PTR_INIT(2); /* pCodeBook[] 
                    pScaleFactor[]
                 */
    for (band=0; band < GetScaleFactorBandsTransmitted(&pAacDecoderChannelInfo->IcsInfo); band++)
    {
      BRANCH(2);
      switch (pCodeBook[group*MaximumScaleFactorBandsShort+band])
      {
        case ZERO_HCB: /* zero book */
          MOVE(1);
          pScaleFactor[group*MaximumScaleFactorBandsShort+band] = 0;
          break;

        default: /* decode scale factor */

          INDIRECT(1); FUNC(2);
          temp = CBlock_DecodeHuffmanWord(bs,hcb->CodeBook);

          ADD(2);
          factor += temp - 60; /* MIDFAC 1.5 dB */

          ADD(1); STORE(1);
          pScaleFactor[group*MaximumScaleFactorBandsShort+band] = factor - 100;
          break;

        case INTENSITY_HCB: /* intensity steering */
        case INTENSITY_HCB2:

          INDIRECT(1); FUNC(2);
          temp = CBlock_DecodeHuffmanWord(bs,hcb->CodeBook);

          ADD(2);
          position += temp - 60;

          ADD(1); STORE(1);
          pScaleFactor[group*MaximumScaleFactorBandsShort+band] = position - 100;
          break;

        case NOISE_HCB: /* PNS */

          FUNC(5);
          CPns_Read(pAacDecoderChannelInfo, bs, hcb, global_gain, band, group);
          break;
      }
    }
  }


  FLC_sub_end();
}
Exemple #13
0
TMove CMyAI::newTurn()
{
	// update board first

	if (p_ai->GetBlock(p_ai->GetMyPosition()) == BLOCK_PLAYER_1){
		we = PLAYER_1;
		p1 = p_ai->GetMyPosition().x + p_ai->GetMyPosition().y*MAP_SIZE;
		p2 = p_ai->GetEnemyPosition().x + p_ai->GetEnemyPosition().y*MAP_SIZE;
		next = p_ai->IsMyTurn() ? PLAYER_1 : PLAYER_2;
	}
	else {
		we = PLAYER_2;
		p2 = p_ai->GetMyPosition().x + p_ai->GetMyPosition().y*MAP_SIZE;
		p1 = p_ai->GetEnemyPosition().x + p_ai->GetEnemyPosition().y*MAP_SIZE;
		next = p_ai->IsMyTurn() ? PLAYER_2 : PLAYER_1;
	}

	auto newBoard = p_ai->GetBoard();

	// update newBoard to boardData and players' positions
	for (int i = 0; i < BOARD_SIZE; i++){
		boardData[i] = newBoard[i];
	}

	if (!firstMoveIsOver) // assume this only run 1
	{
		assert(boardData[0] == BLOCK_PLAYER_1 || boardData[120] == BLOCK_PLAYER_2);
		newGame();
	}
	else{
		// calculate history
		if (next == PLAYER_1)
		{
			for (int i = 1; i <= 4; i++){
				if (MOVE(oP2, i) == p2)
				{
					history.push_back(i);
					break;
				}
			}
		}
		else {
			for (int i = 1; i <= 4; i++){
				if (MOVE(oP1, i) == p1)
				{
					history.push_back(i);
					break;
				}
			}
		}
	}
	oP1 = p1; oP2 = p2;

	TMove m;
	if (we == next)
	{
		m = ourNewTurn();
		if (m < 1 || m>4){
			cout << "calculated move: " << (int)m << endl;
			system("pause");
		}
	}
	else
		m = enemyNewTurn();

	return m;
}
void MoveGenerator::GenerateAllPawnMoves(Board *gameboard, MOVELIST *move_list) {

	side = gameboard->side_to_move;

	/* WHITE PAWN MOVES */
	if (side == WHITE) {

		for (piece_number = 0; piece_number < gameboard->piece_number[WHITE_PAWN]; ++piece_number) {
			square = gameboard->piece_list[WHITE_PAWN][piece_number];

			if (gameboard->pieces[square+10] == EMPTY) {
				AddWhitePawnMove(gameboard, square, square+10, move_list);
				if (rank_of[square] == RANK_2 && gameboard->pieces[square+20] == EMPTY) {
					AddQuietMove(gameboard, MOVE(square, (square+20), EMPTY, EMPTY, MOVEFLAGPAWNSTART), move_list);
				}
			}

			if(!SQUAREOFFBOARD(square + 9) && PieceColor[gameboard->pieces[square + 9]] == BLACK) {
				AddWhitePawnCapture(gameboard, square, square+9, gameboard->pieces[square + 9], move_list);
			}
			if(!SQUAREOFFBOARD(square + 11) && PieceColor[gameboard->pieces[square + 11]] == BLACK) {
				AddWhitePawnCapture(gameboard, square, square+11, gameboard->pieces[square + 11], move_list);
			}

			if(gameboard->en_passant_square != NO_SQUARE) {
				if(square + 9 == gameboard->en_passant_square) {
					AddEnPassantMove(gameboard, MOVE(square,square + 9,EMPTY,EMPTY,MOVEFLAGENPASSANT), move_list);
				}
				if(square + 11 == gameboard->en_passant_square) {
					AddEnPassantMove(gameboard, MOVE(square,square + 11,EMPTY,EMPTY,MOVEFLAGENPASSANT), move_list);
				}
			}
		}

		/* WHITE SIDE CASTLING */
		if(gameboard->castle_permission & WHITE_KING_CASTLE) {
			if(gameboard->pieces[F1] == EMPTY && gameboard->pieces[G1] == EMPTY) {
				if(!IsSquareAttacked(E1,BLACK,gameboard) && !IsSquareAttacked(F1,BLACK,gameboard) ) {
					AddQuietMove(gameboard, MOVE(E1, G1, EMPTY, EMPTY, MOVEFLAGCASTLE), move_list);
				}
			}
		}

		if(gameboard->castle_permission & WHITE_QUEEN_CASTLE) {
			if(gameboard->pieces[D1] == EMPTY && gameboard->pieces[C1] == EMPTY && gameboard->pieces[B1] == EMPTY) {
				if(!IsSquareAttacked(E1,BLACK,gameboard) && !IsSquareAttacked(D1,BLACK,gameboard) ) {
					AddQuietMove(gameboard, MOVE(E1, C1, EMPTY, EMPTY, MOVEFLAGCASTLE), move_list);
				}
			}
		}
	} 

	/* BLACK PAWN MOVES */
	else {

		for(piece_number = 0; piece_number < gameboard->piece_number[BLACK_PAWN]; ++piece_number) {
			square = gameboard->piece_list[BLACK_PAWN][piece_number];

			if(gameboard->pieces[square - 10] == EMPTY) {
				AddBlackPawnMove(gameboard, square, square-10, move_list);
				if(rank_of[square] == RANK_7 && gameboard->pieces[square - 20] == EMPTY) {
					AddQuietMove(gameboard, MOVE(square,(square-20),EMPTY,EMPTY,MOVEFLAGPAWNSTART),move_list);
				}
			}

			if(!SQUAREOFFBOARD(square - 9) && PieceColor[gameboard->pieces[square - 9]] == WHITE) {
				AddBlackPawnCapture(gameboard, square, square-9, gameboard->pieces[square - 9], move_list);
			}

			if(!SQUAREOFFBOARD(square - 11) && PieceColor[gameboard->pieces[square - 11]] == WHITE) {
				AddBlackPawnCapture(gameboard, square, square-11, gameboard->pieces[square - 11], move_list);
			}
			if(gameboard->en_passant_square != NO_SQUARE) {
				if(square - 9 == gameboard->en_passant_square) {
					AddEnPassantMove(gameboard, MOVE(square,square - 9,EMPTY,EMPTY,MOVEFLAGENPASSANT), move_list);
				}
				if(square - 11 == gameboard->en_passant_square) {
					AddEnPassantMove(gameboard, MOVE(square,square - 11,EMPTY,EMPTY,MOVEFLAGENPASSANT), move_list);
				}
			}
		}
		/* BLACK SIDE CASTLING */
		if(gameboard->castle_permission & BLACK_KING_CASTLE) {
			if(gameboard->pieces[F8] == EMPTY && gameboard->pieces[G1] == EMPTY) {
				if(!IsSquareAttacked(E8,WHITE,gameboard) && !IsSquareAttacked(F8,WHITE,gameboard) ) {
					AddQuietMove(gameboard, MOVE(E8, G8, EMPTY, EMPTY, MOVEFLAGCASTLE), move_list);
				}
			}
		}

		if(gameboard->castle_permission & BLACK_QUEEN_CASTLE) {
			if(gameboard->pieces[D8] == EMPTY && gameboard->pieces[C1] == EMPTY && gameboard->pieces[B1] == EMPTY) {
				if(!IsSquareAttacked(E8,WHITE,gameboard) && !IsSquareAttacked(D8,WHITE,gameboard) ) {
					AddQuietMove(gameboard, MOVE(E8, C8, EMPTY, EMPTY, MOVEFLAGCASTLE), move_list);
				}
			}
		}
	}
}
Exemple #15
0
int InitElementBits(ELEMENT_BITS*   elementBits,
                    ELEMENT_INFO    elInfo,
                    int bitrateTot,
                    int averageBitsTot,
                    int staticBitsTot)
{
  int error=0;

  COUNT_sub_start("InitElementBits");

  MOVE(1); /* counting previous operation */

  INDIRECT(1); BRANCH(2);
  switch(elInfo.nChannelsInEl) {

  case 1:
    MOVE(1); PTR_INIT(1);
    elementBits->chBitrate = bitrateTot;

    ADD(1); STORE(1);
    elementBits->averageBits = (averageBitsTot - staticBitsTot);

    MOVE(1);
    elementBits->maxBits = MAX_CHANNEL_BITS;

    ADD(1); STORE(1);
    elementBits->maxBitResBits = MAX_CHANNEL_BITS - averageBitsTot;

    LOGIC(1); ADD(1); STORE(1);
    elementBits->maxBitResBits -= (elementBits[0].maxBitResBits%8);

    MOVE(2);
    elementBits->bitResLevel = elementBits[0].maxBitResBits;
    elementBits->relativeBits  = 1.0f;
    break;

  case 2:
    MULT(1); STORE(1);
    elementBits->chBitrate   = (int)(bitrateTot*0.5f);

    ADD(1); STORE(1);
    elementBits->averageBits = (averageBitsTot - staticBitsTot);

    MULT(1); STORE(1);
    elementBits->maxBits     = 2*MAX_CHANNEL_BITS;

    MULT(1); ADD(1); STORE(1);
    elementBits->maxBitResBits = 2*MAX_CHANNEL_BITS - averageBitsTot;

    LOGIC(1); ADD(1); STORE(1);
    elementBits->maxBitResBits -= (elementBits[0].maxBitResBits%8);

    MOVE(2);
    elementBits->bitResLevel = elementBits[0].maxBitResBits;
    elementBits->relativeBits = 1.0f;
    break;

  default:
    MOVE(2);
    error=1;
  }

  COUNT_sub_end();

  return error;
}
Exemple #16
0
/*
 *
 * \brief Create QMF filter bank instance
 *
 * \return 0 if successful
 *
 */
int
createCplxSynthesisQmfBank (HANDLE_SBR_QMF_FILTER_BANK h_sbrQmf,
                            int noCols,
                            int lsb,
                            int usb,
                            int chan,
                            int bDownSample)
{
  int L, qmfFilterStateSize;

  COUNT_sub_start("createCplxSynthesisQmfBank");

  FUNC(2); LOOP(1); PTR_INIT(1); MOVE(1); STORE(sizeof(SBR_QMF_FILTER_BANK));
  memset(h_sbrQmf,0,sizeof(SBR_QMF_FILTER_BANK));

  BRANCH(1);
  if(bDownSample){

    MOVE(2);
    L = NO_SYNTHESIS_CHANNELS_DOWN_SAMPLED;
    qmfFilterStateSize = QMF_FILTER_STATE_SYN_SIZE_DOWN_SAMPLED;
  }
  else{

    MOVE(2);
    L = NO_SYNTHESIS_CHANNELS;
    qmfFilterStateSize = QMF_FILTER_STATE_SYN_SIZE;
  }

  PTR_INIT(1);
  h_sbrQmf->p_filter = sbr_qmf_64_640;

  MOVE(3);
  h_sbrQmf->no_channels = L;
  h_sbrQmf->qmf_filter_state_size = qmfFilterStateSize;
  h_sbrQmf->no_col = noCols;

  MOVE(1);
  h_sbrQmf->lsb = lsb;

  BRANCH(1);
  if(bDownSample){
    MOVE(1);
    h_sbrQmf->usb = 32;
  }
  else{
    MOVE(1);
    h_sbrQmf->usb = usb;
  }

  PTR_INIT(1);
  h_sbrQmf->pDct4Twiddle = dct4TwiddleTable;

#ifndef LP_SBR_ONLY

  ADD(1); BRANCH(1);
  if(L == 32){

    PTR_INIT(5);
    h_sbrQmf->cos_twiddle = sbr_cos_twiddle_L32;
    h_sbrQmf->sin_twiddle = sbr_sin_twiddle_L32;
    h_sbrQmf->alt_sin_twiddle = sbr_alt_sin_twiddle_L32;
    h_sbrQmf->t_cos = sbr_cos_twiddle_ds_L32;
    h_sbrQmf->t_sin = sbr_sin_twiddle_ds_L32;
  }
  else{

    PTR_INIT(3);
    h_sbrQmf->cos_twiddle = sbr_cos_twiddle_L64;
    h_sbrQmf->sin_twiddle = sbr_sin_twiddle_L64;
    h_sbrQmf->alt_sin_twiddle = sbr_alt_sin_twiddle_L64;
  }
#endif

  PTR_INIT(1);
  h_sbrQmf->FilterStatesSyn = &sbr_QmfStatesSynthesis[chan*qmfFilterStateSize];

  FUNC(2); LOOP(1); PTR_INIT(1); MOVE(1); STORE(qmfFilterStateSize);
  memset(h_sbrQmf->FilterStatesSyn,0,qmfFilterStateSize*sizeof(float));

  COUNT_sub_end();

  return 0;

}
Exemple #17
0
void SplineResample(HANDLE_SPLINE_RESAMPLER hr,
                    float* ioBuffer,
                    int inSamples, 
                    int* outSamples,
                    int ch)
{
  int i, k, samplesOut, outIndex = 0;
  float alpha, alpha_2, alpha_3, coeff, accu;
  float *pos;
  int inIndex=0;
  float tmpOutSamples[MAX_ORDER+1];
  int numTmpOutSamples = 0;
  
  COUNT_sub_start("Resample");

  MOVE(3); /* counting previous operations */

  PTR_INIT(10); /* hr->position[ch]
                   hr->distance[ch]
                   hr->quotient
                   hr->remainder
                   hr->L
                   hr->invL
                   hr->iirFilterCoeff_a
                   hr->iirFilterCoeff_b
                   tmpOutSamples[]
                   ioBuffer[]
                */

  /* special treatment for the first output samples: may need oldSamples */
  LOOP(1);
  while (hr->position[ch] < 3){ 

    MULT(3);
    alpha   = hr->invL * hr->distance[ch];
    alpha_2 = alpha * alpha;
    alpha_3 = alpha * alpha_2;
    
    
    ADD(2); MULT(1); MAC(1);
    coeff = (__1_6 * (1.0f - alpha_3) + 0.5f * (alpha_2 - alpha));

    ADD(1); BRANCH(1);
    if (hr->position[ch] >= 3) {

      INDIRECT(1); MULT(1);
      accu  = ioBuffer[hr->position[ch]-3] * coeff;
    }
    else {

      INDIRECT(1); MULT(1);
      accu  = hr->oldSamples[hr->position[ch]][ch] * coeff;
    }
    

    MULT(1); ADD(2);
    coeff = (0.5f * alpha_3 - alpha_2 + __2_3);

    ADD(1); BRANCH(1);
    if (hr->position[ch] >= 2) {

      INDIRECT(1); MAC(1);
      accu += ioBuffer[hr->position[ch]-2] * coeff;
    }
    else {

      INDIRECT(1); MAC(1);
      accu += hr->oldSamples[hr->position[ch]+1][ch] * coeff;
    }
    
    ADD(3); MULT(1);
    coeff = (0.5f * (-alpha_3 + alpha_2 + alpha) + __1_6);

    ADD(1); BRANCH(1);
    if (hr->position[ch] >= 1) {

      INDIRECT(1); MAC(1);
      accu += ioBuffer[hr->position[ch]-1] * coeff;
    }
    else {

      INDIRECT(1); MAC(1);
      accu += hr->oldSamples[hr->position[ch]+2][ch] * coeff;
    }
    
    MULT(1);
    coeff = (__1_6 * alpha_3);

    MAC(1);
    accu += ioBuffer[hr->position[ch]] * coeff;
    
    MOVE(1);
    tmpOutSamples[numTmpOutSamples++] = accu;

    /* Update variables */
    ADD(2);
    hr->position[ch] += hr->quotient;
    hr->distance[ch] += hr->remainder;

    ADD(1); BRANCH(1);
    if(hr->distance[ch] >= hr->L) {

      ADD(2);
      hr->distance[ch] -= hr->L;
      hr->position[ch] += 1;
    }

  }
  
  ADD(1);
  inIndex =  hr->position[ch] - 3;

  assert (inIndex >=0);

  
  /* now we have to work up input buffer samples such long that we can start writing the output samples ... */

  LOOP(1);
  while(numTmpOutSamples) 
  {
    MULT(3);
    alpha   = hr->invL * hr->distance[ch];
    alpha_2 = alpha * alpha;
    alpha_3 = alpha * alpha_2;

    PTR_INIT(1);
    pos = &ioBuffer[inIndex];
        
    ADD(2); MULT(1); MAC(1);
    coeff = (__1_6 * (1.0f - alpha_3) + 0.5f * (alpha_2 - alpha));

    MULT(1);
    accu  = *pos++ * coeff;
    
    ADD(2); MULT(1);
    coeff = (0.5f * alpha_3 - alpha_2 + __2_3);

    MAC(1);
    accu += *pos++ * coeff;
    
    ADD(3); MULT(1);
    coeff = (0.5f * (-alpha_3 + alpha_2 + alpha) + __1_6);

    MAC(1);
    accu += *pos++ * coeff;
    
    MULT(1);
    coeff = (__1_6 * alpha_3);

    MAC(1);
    accu += *pos++ * coeff;

    MOVE(1);
    tmpOutSamples[numTmpOutSamples++] =  accu;

    assert (numTmpOutSamples <= MAX_ORDER+1);


    /* Update variables */
    ADD(2);
    inIndex          += hr->quotient;
    hr->distance[ch] += hr->remainder;

    ADD(1); BRANCH(1);
    if(hr->distance[ch] >= hr->L) {

      ADD(2);
      hr->distance[ch] -= hr->L;
      inIndex          += 1;
    }

    /* write as many output samples as possible */
    ADD(2); BRANCH(1); MOVE(1);
    samplesOut = min( (inIndex-outIndex), numTmpOutSamples );

    PTR_INIT(1); /* tmpOutSamples[] */
    LOOP(1);
    for ( i=0; i<samplesOut; i++ ) {
      MOVE(1);
      ioBuffer[outIndex++] = tmpOutSamples[i];
    }

    PTR_INIT(1); /* tmpOutSamples[] */
    ADD(1); LOOP(1);
    for ( k=0; k<numTmpOutSamples-samplesOut; k++) {
      MOVE(1);
      tmpOutSamples[k] = tmpOutSamples[samplesOut+k];
    }

    ADD(1);
    numTmpOutSamples -= samplesOut;

  }


  /* now we can work directly on the i/o buffer */
  ADD(1); LOOP(1);
  while(inIndex < inSamples - 3) 
  {
    MULT(3);
    alpha   = hr->invL * hr->distance[ch];
    alpha_2 = alpha * alpha;
    alpha_3 = alpha * alpha_2;

    PTR_INIT(1);
    pos = &ioBuffer[inIndex];
        
    ADD(2); MULT(1); MAC(1);
    coeff = (__1_6 * (1.0f - alpha_3) + 0.5f * (alpha_2 - alpha));

    MULT(1);
    accu  = *pos++ * coeff;
    
    MULT(1); ADD(2);
    coeff = (0.5f * alpha_3 - alpha_2 + __2_3);

    MAC(1);
    accu += *pos++ * coeff;
    
    MULT(1); ADD(3);
    coeff = (0.5f * (-alpha_3 + alpha_2 + alpha) + __1_6);

    MAC(1);
    accu += *pos++ * coeff;
    
    MULT(1);
    coeff = (__1_6 * alpha_3);

    MAC(1);
    accu += *pos++ * coeff;


    /* Update variables */
    ADD(2);
    inIndex          += hr->quotient;
    hr->distance[ch] += hr->remainder;


    ADD(1); BRANCH(1);
    if(hr->distance[ch] >= hr->L) {

      ADD(2);
      hr->distance[ch] -= hr->L;
      inIndex      += 1;
    }

    assert(outIndex < inIndex); /* make sure that we can work inplace */

    MOVE(1);
    ioBuffer[outIndex++] =  accu;

    assert(outIndex <= inSamples);
  }

  MOVE(1);
  *outSamples = outIndex;

  ADD(2); STORE(1);
  hr->position[ch] = inIndex - (inSamples-3);

  if (hr->position[ch] < 0) {
    assert (hr->position[ch] >= 0);
  }

  
  /* update buffers */
  ADD(1); BRANCH(1);
  if (inSamples > 3) {

    PTR_INIT(2); /* hr->oldSamples[][]
                    ioBuffer[]
                 */
    LOOP(1);
    for (i=0; i<3; i++) {
      MOVE(1);
      hr->oldSamples[i][ch] = ioBuffer[inSamples-3+i];
    }
  }


  /* Do the IIR filtering*/

  PTR_INIT(1); /* ioBuffer[] */

  MULT(2); ADD(1); STORE(1);
  ioBuffer[0] = hr->iirFilterCoeff_b*ioBuffer[0] - hr->oldSampleFilter[ch]*hr->iirFilterCoeff_a;

  LOOP(1);
  for(i=1; i < outIndex; i++){
    MULT(2); ADD(1); STORE(1);
    ioBuffer[i] = hr->iirFilterCoeff_b*ioBuffer[i] - ioBuffer[i-1]*hr->iirFilterCoeff_a;
  }

  MOVE(1);
  hr->oldSampleFilter[ch] = ioBuffer[outIndex - 1];


  COUNT_sub_end();
}
Exemple #18
0
/*
   Perform dct type 2
 */
static void
dct2 (float *data,
      int L,
      HANDLE_SBR_QMF_FILTER_BANK qmfBank
      )
{
  int i, M, N;
  float s1, s2, s3, s4;
  float temp[16];

  const float sqrtHalf  = 0.70710678118655f;
  MOVE(1);

  MULT(1);
  M = L / 2;

  MULT(1);
  N = L / 4;

  ADD(1); BRANCH(1);
  if (L > 2) {

    PTR_INIT(4);  /* pointers for data[i],
                                  data[i + M],
                                  data[M-1 - i],
                                  data[L-1 - i] */
    LOOP(1);
    for(i = 0; i < N; i++) {

      MOVE(4);
      s1 = data[i];
      s2 = data[i + M];
      s3 = data[M-1 - i];
      s4 = data[L-1 - i];

      ADD(4); STORE(4);
      data[i]       = (s1 + s4);
      data[i + M]   = (s1 - s4);
      data[M-1 - i] = (s3 + s2);
      data[L-1 - i] = (s3 - s2);
    }

    FUNC(3);
    dct2(data,     M, qmfBank);

    FUNC(3);
    dct4(data + M, M, qmfBank);

    PTR_INIT(2);  /* pointers for data[2*i + M],
                                  temp[i]        */
    LOOP(1);
    for(i = 0; i < N; i++) {
      MOVE(1);
      temp[i] = data[2*i + M];
    }

    PTR_INIT(2);  /* pointers for data[L - 2*i],
                                  data[M - i]    */
    LOOP(1);
    for(i = 1; i < M; i++) {
      MOVE(1);
      data[L - 2*i] = data[M - i];
    }

    PTR_INIT(2);  /* pointers for data[4*i - 1],
                                  data[M-1 + 2*i] */
    LOOP(1);
    for(i = 1; i < N; i++) {
      MOVE(1);
      data[4*i - 1] = data[M-1 + 2*i];
    }

    PTR_INIT(2);  /* pointers for data[4*i + 1],
                                  temp[i]        */
    LOOP(1);
    for(i = 0; i < N; i++) {
      MOVE(1);
      data[4*i + 1] = temp[i];
    }
  }
  else { /* 2-point transform */
    MOVE(1);
    s1 = data[0];

    ADD(1); STORE(1);
    data[0] =   (s1 + data[1]);

    ADD(1); MAC(1); STORE(1);
    data[1] =  ((s1 - data[1]) * sqrtHalf);
  }
}
Exemple #19
0
void
CreateSplineResampler(HANDLE_SPLINE_RESAMPLER* hr,
                      int Fin, int Fout)
{
  int i;

  COUNT_sub_start("CreateResampler");

  PTR_INIT(1); STORE(1);
  *hr = &splineResamplerInstance;

  INDIRECT(2); MOVE(2);
  (*hr)->L = Fout;
  (*hr)->M = Fin;

  INDIRECT(1); DIV(1); STORE(1);
  (*hr)->invL         = 1.0f/Fout;

  INDIRECT(2); MOVE(2);
  (*hr)->distance[0]  = 0;
  (*hr)->distance[1]  = 0;

  INDIRECT(2); DIV(2); STORE(2);
  (*hr)->remainder = Fin % Fout;
  (*hr)->quotient  = Fin / Fout;

  INDIRECT(2); MOVE(2);
  (*hr)->position[0]  = 0;
  (*hr)->position[1]  = 0;

  PTR_INIT(2); /* (*hr)->oldSamples[i][0]
                  (*hr)->oldSamples[i][1]
               */
  LOOP(1);
  for (i=0; i<MAX_ORDER; i++) {

    MOVE(2);
    (*hr)->oldSamples[i][0] = 0;
    (*hr)->oldSamples[i][1] = 0;
  }

  BRANCH(2);
  switch(Fin){

  case 22050:
    BRANCH(2);
    switch(Fout){
    case 16000:
      INDIRECT(2); PTR_INIT(2);
      (*hr)->iirFilterCoeff_a = a_22_16;
      (*hr)->iirFilterCoeff_b = b_22_16;
      break;
    case 8000:
      INDIRECT(2); PTR_INIT(2);
      (*hr)->iirFilterCoeff_a = a_22_8;
      (*hr)->iirFilterCoeff_b = b_22_8;
      break;
    };
    break;

  case 24000:
    BRANCH(2);
    switch(Fout){
    case 16000:
      INDIRECT(2); PTR_INIT(2);
      (*hr)->iirFilterCoeff_a = a_24_16;
      (*hr)->iirFilterCoeff_b = b_24_16;
      break;
    case 8000:
      INDIRECT(2); PTR_INIT(2);
      (*hr)->iirFilterCoeff_a = a_24_8;
      (*hr)->iirFilterCoeff_b = b_24_8;
      break;
    };
    break;
  default:
    INDIRECT(2); PTR_INIT(2);
    (*hr)->iirFilterCoeff_a = 0;
    (*hr)->iirFilterCoeff_b = 1;
    break;
  };

  INDIRECT(2); MOVE(2);
  (*hr)->iirFilterCoeff_a = 0;
  (*hr)->iirFilterCoeff_b = 1;

  COUNT_sub_end();
}
Exemple #20
0
/*
 *
 * \brief Perform complex-valued subband filtering of the time domain
 *        data of timeIn and stores the real part of the subband
 *        samples in rAnalysis, and the imaginary part in iAnalysis
 *
 */
void
cplxAnalysisQmfFiltering (
                          const float *timeIn,
                          float **qmfReal,
#ifndef LP_SBR_ONLY
                          float **qmfImag,
#endif
                          HANDLE_SBR_QMF_FILTER_BANK anaQmf,
                          int   bUseLP
                          )
{
  int i, k;
  float analysisBuffer[NO_ANALYSIS_CHANNELS*2];
  const float *ptr_pf;
  const float *ptr_states;
  const float *ptr_timeIn;
  int p;
  float accu;

  COUNT_sub_start("cplxAnalysisQmfFiltering");

  PTR_INIT(1);
  ptr_timeIn = timeIn;

  INDIRECT(1); LOOP(1);
  for (i = 0; i < anaQmf->no_col; i++) {

    FUNC(2); LOOP(1); PTR_INIT(1); MOVE(1); STORE(2*NO_ANALYSIS_CHANNELS);
    memset (analysisBuffer, 0, 2*NO_ANALYSIS_CHANNELS * sizeof (float));

    INDIRECT(2); PTR_INIT(2);
    ptr_pf     = anaQmf->p_filter;
    ptr_states = anaQmf->FilterStatesAna;


    FUNC(2); LOOP(1); PTR_INIT(2); MOVE(1); STORE(NO_ANALYSIS_CHANNELS);
    memcpy(anaQmf->FilterStatesAna+(QMF_FILTER_STATE_ANA_SIZE-NO_ANALYSIS_CHANNELS),ptr_timeIn,NO_ANALYSIS_CHANNELS*sizeof(float));

                                                                       COUNT_sub_start("AnalysisPolyphaseFiltering");

                                                                       LOOP(1); PTR_INIT(1);
    for (k = 0; k < NO_ANALYSIS_CHANNELS; k++) {
      ptr_pf += NO_POLY * (QMF_ANA_FILTER_STRIDE - 1);                 MAC(1);
      accu=0;                                                          MOVE(1);

      for (p = 0; p < NO_POLY; p++) {
        accu +=  *ptr_pf++ * ptr_states[2*NO_ANALYSIS_CHANNELS * p];   MAC(1);
      }
      analysisBuffer[2*NO_ANALYSIS_CHANNELS - 1 - k] = accu;           STORE(1);
      ptr_states++;
    }

    accu=0;                                                            MOVE(1); LOOP(1); PTR_INIT(1);
    for (p = 0; p < NO_POLY; p++) {
      accu +=  *ptr_pf++ * anaQmf->FilterStatesAna[2*NO_ANALYSIS_CHANNELS * p + 2*NO_ANALYSIS_CHANNELS-1]; MAC(1);
    }
    analysisBuffer[0] = accu;                                          MOVE(1);
    ptr_pf -= NO_POLY * 2;                                             PTR_INIT(1);

                                                                       LOOP(1); PTR_INIT(1);
    for (k = 0; k < NO_ANALYSIS_CHANNELS-1; k++){
      ptr_pf -= NO_POLY * (QMF_ANA_FILTER_STRIDE - 1);                 PTR_INIT(1);
      accu=0;                                                          MOVE(1);

      for (p = 0; p < NO_POLY; p++) {
        accu +=  *--ptr_pf * ptr_states[2*NO_ANALYSIS_CHANNELS * p];   MAC(1);
      }
      analysisBuffer[NO_ANALYSIS_CHANNELS - 1 - k] = accu;             STORE(1);
      ptr_states++;
    }

                                                                       COUNT_sub_end();



    BRANCH(1);
    if (bUseLP) {
      FUNC(3);
      sbrForwardModulationLP (analysisBuffer,
                              qmfReal[i],
                              anaQmf);
    }
#ifndef LP_SBR_ONLY
    else {
      FUNC(4);
      sbrForwardModulation (analysisBuffer,
                            qmfReal[i],
                            qmfImag[i],
                            anaQmf);
    }
#endif

    /*
      Shift filter states
      Should be realized with modulo adressing on a DSP instead of a true buffer shift
    */
    /* FUNC(2); LOOP(1); PTR_INIT(2); MOVE(1); STORE(NO_ANALYSIS_CHANNELS); */
    memmove(anaQmf->FilterStatesAna,anaQmf->FilterStatesAna+NO_ANALYSIS_CHANNELS,(QMF_FILTER_STATE_ANA_SIZE-NO_ANALYSIS_CHANNELS)*sizeof(float));

    ptr_timeIn += NO_ANALYSIS_CHANNELS;
  }

  COUNT_sub_end();
}
Exemple #21
0
int
AacEncOpen ( struct AAC_ENCODER**     phAacEnc,       /* pointer to an encoder handle, initialized on return */
             const  AACENC_CONFIG     config          /* pre-initialized config struct */
             )
{
  int error = 0;
  int profile = 1;
  ELEMENT_INFO* elInfo = NULL;
  struct AAC_ENCODER  *hAacEnc ;

  COUNT_sub_start("AacEncOpen");

  MOVE(2); /* counting previous operations */

  PTR_INIT(1);
  hAacEnc = &aacEncoder;

  BRANCH(1);
  if (phAacEnc==0)  {
    MOVE(1);
    error=1;
  }

  BRANCH(1);
  if (!error) {
    /* sanity checks on config structure */
    PTR_INIT(1); ADD(7); LOGIC(9); DIV(1);
    error = (/* &config == 0            || */
             phAacEnc == 0             ||
             config.nChannelsIn  < 1 || config.nChannelsIn  > MAX_CHANNELS ||
             config.nChannelsOut < 1 || config.nChannelsOut > MAX_CHANNELS ||
             config.nChannelsIn  < config.nChannelsOut            ||
             (config.bitRate!=0 && (config.bitRate / config.nChannelsOut < 8000      ||
                                    config.bitRate / config.nChannelsOut > 160000)));
  }

  /* check sample rate */
  BRANCH(1);
  if (!error)  {

    BRANCH(2);
    switch (config.sampleRate) {
    case  8000: case 11025: case 12000:
    case 16000: case 22050: case 24000:
    case 32000: case 44100: case 48000:
      break;

    default:
      MOVE(1);
      error = 1; break;
    }
  }


  /* check if bit rate is not too high for sample rate */
  BRANCH(1);
  if (!error) {

    MULT(2); ADD(1); BRANCH(1);
    if (config.bitRate > ((float)(MAX_CHANNEL_BITS-744)/FRAME_LEN_LONG*
                          config.sampleRate*config.nChannelsOut))
      {
        MOVE(1);
        error=1;
      }
  }


  BRANCH(1);
  if (!error) {
    INDIRECT(1); MOVE(1);
    hAacEnc->config = config;
  }


  BRANCH(1);
  if (!error) {
    INDIRECT(2); PTR_INIT(1); FUNC(2);
    error = InitElementInfo (config.nChannelsOut,
                             &hAacEnc->elInfo);
  }

  BRANCH(1);
  if (!error) {
    INDIRECT(1); PTR_INIT(1);
    elInfo = &hAacEnc->elInfo;
  }

  /* allocate the Psy aud Psy Out structure */
  BRANCH(1);
  if (!error) {

    INDIRECT(3); PTR_INIT(2); FUNC(2); FUNC(1); LOGIC(1);
    error = (PsyNew(&hAacEnc->psyKernel, elInfo->nChannelsInEl) ||
             PsyOutNew(&hAacEnc->psyOut));
  }

  BRANCH(1);
  if (!error) {
    int tnsMask=3;

    MOVE(1); /* counting previous operation */

    INDIRECT(2); MOVE(1);
    hAacEnc->bandwidth90dB = (int)hAacEnc->config.bandWidth;

    INDIRECT(4); PTR_INIT(1); FUNC(6);
    error = psyMainInit(&hAacEnc->psyKernel,
                        config.sampleRate,
                        config.bitRate,
                        elInfo->nChannelsInEl,
                        tnsMask,
                        hAacEnc->bandwidth90dB);
  }


  /* allocate the Q&C Out structure */
  BRANCH(1);
  if (!error) {
    INDIRECT(2); PTR_INIT(1); FUNC(2);
    error = QCOutNew(&hAacEnc->qcOut,
                     elInfo->nChannelsInEl);
  }

  /* allocate the Q&C kernel */
  BRANCH(1);
  if (!error) {
    INDIRECT(1); PTR_INIT(1); FUNC(1);
    error = QCNew(&hAacEnc->qcKernel);
  }

  BRANCH(1);
  if (!error) {
    struct QC_INIT qcInit;

    INDIRECT(1); PTR_INIT(1); MOVE(1);
    qcInit.elInfo = &hAacEnc->elInfo;

    INDIRECT(1); MULT(1); STORE(1);
    qcInit.maxBits = MAX_CHANNEL_BITS * elInfo->nChannelsInEl;

    MOVE(1);
    qcInit.bitRes = qcInit.maxBits;

    MULT(1); DIV(1); STORE(1);
    qcInit.averageBits = (config.bitRate * FRAME_LEN_LONG) / config.sampleRate;

    MOVE(1);
    qcInit.padding.paddingRest = config.sampleRate;

    INDIRECT(1); MULT(2); DIV(1);
    qcInit.meanPe = 10.0f * FRAME_LEN_LONG * hAacEnc->bandwidth90dB/(config.sampleRate/2.0f);

    MULT(1); DIV(1); BRANCH(1); STORE(1);
    qcInit.maxBitFac = (float)((MAX_CHANNEL_BITS-744)*elInfo->nChannelsInEl) /
      (float)(qcInit.averageBits?qcInit.averageBits:1);

    MOVE(1);
    qcInit.bitrate = config.bitRate;

    INDIRECT(1); PTR_INIT(2); FUNC(2);
    error = QCInit(&hAacEnc->qcKernel, &qcInit);
  }

  /* init bitstream encoder */
  BRANCH(1);
  if (!error) {

    INDIRECT(5); MOVE(4);
      hAacEnc->bseInit.nChannels   = elInfo->nChannelsInEl;
      hAacEnc->bseInit.bitrate     = config.bitRate;
      hAacEnc->bseInit.sampleRate  = config.sampleRate;
      hAacEnc->bseInit.profile     = profile;
  }


  /* common things */
  BRANCH(1);
  if (!error) {

    INDIRECT(1); ADD(2); LOGIC(1); STORE(1);
    hAacEnc->downmix = (config.nChannelsIn==2 && config.nChannelsOut==1);

    INDIRECT(1); BRANCH(1); MOVE(1);
    hAacEnc->downmixFac = (hAacEnc->downmix) ? config.nChannelsIn : 1;
  }



  BRANCH(1);
  if(!error) {

    /*
      decide if stereo preprocessing should be activated
    */

    ADD(3); DIV(1); MULT(1); LOGIC(2); BRANCH(1);
    if ( elInfo->elType == ID_CPE &&
         (config.sampleRate <= 24000 && (config.bitRate/elInfo->nChannelsInEl*2) < 60000) ) {

      float scfUsedRatio = (float) hAacEnc->psyKernel.psyConfLong.sfbActive / hAacEnc->psyKernel.psyConfLong.sfbCnt ;

      DIV(1); /* counting previous operation */

      FUNC(5);
      error = InitStereoPreProcessing(&(hAacEnc->stereoPrePro),
                                      elInfo->nChannelsInEl,
                                      config.bitRate,
                                      config.sampleRate,
                                      scfUsedRatio);
    }
  }

  BRANCH(1);
  if (error) {

    FUNC(1);
    AacEncClose(hAacEnc);

    MOVE(1);
    hAacEnc=0;
  }

  MOVE(1);
  *phAacEnc = hAacEnc;

  COUNT_sub_end();

  return error;
}
Exemple #22
0
/*
 *
 *
 * \brief Perform complex-valued subband synthesis of the
 *        low band and the high band and store the
 *        time domain data in timeOut
 *
*/
void
cplxSynthesisQmfFiltering( float **qmfReal,
#ifndef LP_SBR_ONLY
                           float **qmfImag,
#endif
                           float *timeOut,
                           HANDLE_SBR_QMF_FILTER_BANK synQmf,
                           int   bUseLP,
                           HANDLE_PS_DEC h_ps_dec,
                           int   active
                           )
{
  int i, j;
  float *ptr_time_out;

  float *filterStates;

  float accu;
  int p;
  float qmfReal2[NO_ACTUAL_SYNTHESIS_CHANNELS];

  float *imagSlot;

  int no_synthesis_channels;
  int qmf_filter_state_syn_size;

  float qmfRealTmp[NO_ACTUAL_SYNTHESIS_CHANNELS];
  float qmfImagTmp[NO_ACTUAL_SYNTHESIS_CHANNELS];

  int env;

  COUNT_sub_start("cplxSynthesisQmfFiltering");

  MOVE(1);
  env = 0;

  FUNC(3); LOOP(1); PTR_INIT(1); MOVE(1); STORE(NO_ACTUAL_SYNTHESIS_CHANNELS);
  memset(qmfRealTmp,0,NO_ACTUAL_SYNTHESIS_CHANNELS*sizeof(float));

  FUNC(3); LOOP(1); PTR_INIT(1); MOVE(1); STORE(NO_ACTUAL_SYNTHESIS_CHANNELS);
  memset(qmfImagTmp,0,NO_ACTUAL_SYNTHESIS_CHANNELS*sizeof(float));

  INDIRECT(1); MOVE(1);
  no_synthesis_channels = synQmf->no_channels;

  INDIRECT(1); MOVE(1);
  qmf_filter_state_syn_size = synQmf->qmf_filter_state_size;

  INDIRECT(1); PTR_INIT(1);
  filterStates = synQmf->FilterStatesSyn;

  PTR_INIT(1);
  ptr_time_out = timeOut;

  INDIRECT(1); LOOP(1);
  for (i = 0; i < synQmf->no_col; i++) {

    const float *p_filter = synQmf->p_filter;
    INDIRECT(1); PTR_INIT(1);

    BRANCH(1);
    if (bUseLP) {

      PTR_INIT(1);
      imagSlot = qmfReal2;
    }
#ifndef LP_SBR_ONLY
    else {

      PTR_INIT(1);
      imagSlot = *(qmfImag + i);
    }
#endif


#ifndef MONO_ONLY
    BRANCH(1);
    if(active){

      ADD(1); INDIRECT(1); BRANCH(1);
      if(i == h_ps_dec-> aEnvStartStop[env]){

        FUNC(3); INDIRECT(1);
        InitRotationEnvelope(h_ps_dec,env,synQmf->usb);
        env++;
      }

      FUNC(5);
      ApplyPsSlot(h_ps_dec,
                  &qmfReal[i],
                  &qmfImag[i],
                  qmfRealTmp,
                  qmfImagTmp);
    }
#endif



#ifndef  LP_SBR_ONLY
    BRANCH(1);
    if(!bUseLP) {

      BRANCH(1);
      if(no_synthesis_channels == NO_SYNTHESIS_CHANNELS_DOWN_SAMPLED){

        PTR_INIT(4);  /* pointers for qmfReal[i][j],
                                      imagSlot[j],
                                      synQmf->cos_twiddle_ds[j],
                                      synQmf->sin_twiddle_ds[j]  */
        LOOP(1);
        for (j = 0; j < no_synthesis_channels; j++){
          float temp;

          MOVE(1);
          temp = qmfReal[i][j];

          MULT(1); MAC(1); STORE(1);
          qmfReal[i][j] = synQmf->t_cos[j] * qmfReal[i][j] + synQmf->t_sin[j] * imagSlot[j];

          MULT(2); ADD(1); STORE(1);
          imagSlot[j]   = synQmf->t_cos[j] * imagSlot[j]   - synQmf->t_sin[j] * temp;
        }
      }

      PTR_INIT(2);  /* pointers for qmfReal[i][j],
                                    imagSlot[j],   */
      INDIRECT(1); LOOP(1);
      for (j = 0; j < synQmf->usb; j++) {

        MULT(2); STORE(2);
        qmfReal[i][j] *= -1.0;
        imagSlot[j]   *= -1.0;
      }
    }
#endif

    BRANCH(1);
    if (bUseLP) {

      FUNC(3);
      inverseModulationLP (qmfReal[i], imagSlot, synQmf);
    }
#ifndef  LP_SBR_ONLY
    else {

      FUNC(3);
      inverseModulation (qmfReal[i], imagSlot, synQmf);
    }
#endif

    BRANCH(1);
    if (bUseLP) {

      PTR_INIT(2);  /* pointers for qmfReal[i][j],
                                    imagSlot[j],   */
      LOOP(1);
      for (j = 0; j < no_synthesis_channels; j++) {

        MULT(2); STORE(2);
        qmfReal[i][j] =  qmfReal[i][j] * 0.0625f;
        imagSlot[j]   =  imagSlot[j]   * 0.0625f;
      }
    }
#ifndef  LP_SBR_ONLY
    else {

      PTR_INIT(2);  /* pointers for qmfReal[i][j],
                                    imagSlot[j],   */
      LOOP(1);
      for (j = 0; j < no_synthesis_channels; j++) {

        MULT(2); STORE(2);
        qmfReal[i][j] =  qmfReal[i][j] * 0.03125f;
        imagSlot[j]   =  imagSlot[j]   * 0.03125f;
      }
    }
#endif

    COUNT_sub_start("SynthesisPolyphaseFiltering");

    MULT(1); PTR_INIT(2);  /* pointers for filterStates[p * 2*no_synthesis_channels + j],
                                           imagSlot[no_synthesis_channels -1 - j]         */
    LOOP(1);
    for (j = 0; j < no_synthesis_channels; j++){
      float newSample;
      MOVE(1);
      newSample = imagSlot[no_synthesis_channels -1 - j];

      if(no_synthesis_channels == 32){
        p_filter += NO_POLY;
      }

      LOOP(1);
      for (p = 0; p < NO_POLY; p++) {

        MAC(1); STORE(1);
        accu = filterStates[p * 2*no_synthesis_channels + j] + (*p_filter++) * newSample;
        filterStates[p * 2*no_synthesis_channels + j] = accu;

      }

    }


    MULT(2); PTR_INIT(1);  /* pointer for filterStates[p * 2*no_synthesis_channels + no_synthesis_channels + (no_synthesis_channels-1)] */
    LOOP(1);
    for (p = 0; p < NO_POLY; p++) {

      MAC(1); STORE(1);
      accu =  filterStates[p * 2*no_synthesis_channels + no_synthesis_channels + (no_synthesis_channels-1) ] +  (*p_filter++) * qmfReal[i][0];
      filterStates[p * 2*no_synthesis_channels + no_synthesis_channels + (no_synthesis_channels-1)] = accu;

    }
    MOVE(1);
    ptr_time_out[0] = accu;

    p_filter -= NO_POLY*2;

    MULT(2); PTR_INIT(2);  /* pointers for filterStates[p * 2*no_synthesis_channels + no_synthesis_channels + j],
                                           qmfReal[no_synthesis_channels -1 - j]                                  */
    ADD(1); LOOP(1);
    for (j = 0; j < no_synthesis_channels-1; j++){
      float newSample;

      MOVE(1);
      newSample = qmfReal[i][no_synthesis_channels -1 - j];

      if(no_synthesis_channels == 32){

        p_filter -= NO_POLY;
      }

      LOOP(1);
      for (p = 0; p < NO_POLY; p++) {

        MAC(1); STORE(1);
        accu =  filterStates[p * 2*no_synthesis_channels + no_synthesis_channels + j] + (*--p_filter) * newSample;
        filterStates[p * 2*no_synthesis_channels + no_synthesis_channels + j] = accu;

      }

      MOVE(1);
      ptr_time_out[no_synthesis_channels - 1 - j] = accu;
    }


    ptr_time_out += no_synthesis_channels;

    /*
      Shift filter states
      Should be replaces by modulo operation if available
    */
    /* FUNC(2); LOOP(1); PTR_INIT(2); MOVE(1); STORE((qmf_filter_state_syn_size - no_synthesis_channels)); */
    memmove (filterStates + no_synthesis_channels, filterStates,
             (qmf_filter_state_syn_size - no_synthesis_channels) * sizeof (float));

    /* FUNC(2); LOOP(1); PTR_INIT(1); MOVE(1); STORE(no_synthesis_channels); */
    memset (filterStates, 0, no_synthesis_channels * sizeof (float));

    BRANCH(1);
    if(active){
      FUNC(2); LOOP(1); PTR_INIT(2); MOVE(1); STORE(no_synthesis_channels);
      memcpy(qmfReal[i],qmfRealTmp,sizeof(float)*no_synthesis_channels);

#ifndef  LP_SBR_ONLY
      FUNC(2); LOOP(1); PTR_INIT(2); MOVE(1); STORE(no_synthesis_channels);
      memcpy(qmfImag[i],qmfImagTmp,sizeof(float)*no_synthesis_channels);
#endif
    }

    COUNT_sub_end();

  }

  COUNT_sub_end();
}
Exemple #23
0
int AacEncEncode(struct AAC_ENCODER *aacEnc,          /*!< an encoder handle */
                 float  *timeSignal,                  /*!< BLOCKSIZE*nChannels audio samples */
                 unsigned int timeInStride,
                 const unsigned char *ancBytes,       /*!< pointer to ancillary data bytes */
                 unsigned int        *numAncBytes,    /*!< number of ancillary Data Bytes */
                 unsigned int        *outBytes,       /*!< pointer to output buffer            */
                 int                 *numOutBytes     /*!< number of bytes in output buffer */
                 )
{
  ELEMENT_INFO* elInfo = &aacEnc->elInfo;
  int globUsedBits;
  int ancDataBytes, ancDataBytesLeft;

  COUNT_sub_start("AacEncEncode");

  INDIRECT(2); PTR_INIT(1); FUNC(3);
  aacEnc->hBitStream = CreateBitBuffer(&aacEnc->bitStream,
                                       (unsigned char*) outBytes,
                                       (MAX_CHANNEL_BITS/8)*MAX_CHANNELS);

  INDIRECT(1); PTR_INIT(1); /* counting previous operation */

  MOVE(2);
  ancDataBytes = ancDataBytesLeft =  *numAncBytes;


  /* advance psychoacoustic */

  LOGIC(1); BRANCH(1);
  if (elInfo->elType == ID_CPE) {

    PTR_INIT(1); FUNC(5);
    ApplyStereoPreProcess(&aacEnc->stereoPrePro,
                          timeInStride,
                          elInfo,
                          timeSignal,
                          FRAME_LEN_LONG);
  }

  INDIRECT(5); PTR_INIT(4); FUNC(9);
  psyMain(timeInStride,
          elInfo,
          timeSignal,
          &aacEnc->psyKernel.psyData[elInfo->ChannelIndex[0]],
          &aacEnc->psyKernel.tnsData[elInfo->ChannelIndex[0]],
          &aacEnc->psyKernel.psyConfLong,
          &aacEnc->psyKernel.psyConfShort,
          &aacEnc->psyOut.psyOutChannel[elInfo->ChannelIndex[0]],
          &aacEnc->psyOut.psyOutElement,
          aacEnc->psyKernel.pScratchTns);


  INDIRECT(3); PTR_INIT(1); FUNC(3);
  AdjustBitrate(&aacEnc->qcKernel,
                aacEnc->config.bitRate,
                aacEnc->config.sampleRate);

  PTR_INIT(4); /*
                  aacEnc->qcKernel.elementBits
                  aacEnc->qcKernel.adjThr.adjThrStateElem,
                  aacEnc->psyOut.psyOutElement,
                  aacEnc->qcOut.qcElement
               */

  ADD(1); BRANCH(1); MOVE(1); /* min() */ INDIRECT(2); PTR_INIT(3); FUNC(9);
  QCMain( &aacEnc->qcKernel,
          elInfo->nChannelsInEl,
          &aacEnc->qcKernel.elementBits,
          &aacEnc->qcKernel.adjThr.adjThrStateElem,
          &aacEnc->psyOut.psyOutChannel[elInfo->ChannelIndex[0]],
          &aacEnc->psyOut.psyOutElement,
          &aacEnc->qcOut.qcChannel[elInfo->ChannelIndex[0]],
          &aacEnc->qcOut.qcElement,
          min(ancDataBytesLeft,ancDataBytes));


  LOGIC(1); BRANCH(1);
  if ( elInfo->elType == ID_CPE ) {

    INDIRECT(1); PTR_INIT(2); FUNC(4);
    UpdateStereoPreProcess(&aacEnc->psyOut.psyOutChannel[elInfo->ChannelIndex[0]],
                           &aacEnc->qcOut.qcElement,
                           &aacEnc->stereoPrePro,
                           aacEnc->psyOut.psyOutElement.weightMsLrPeRatio);
  }

  ADD(1);
  ancDataBytesLeft-=ancDataBytes;


  INDIRECT(2); PTR_INIT(2); FUNC(2);
  FinalizeBitConsumption( &aacEnc->qcKernel,
                          &aacEnc->qcOut);

  INDIRECT(3); PTR_INIT(3); FUNC(7);
  WriteBitstream( aacEnc->hBitStream,
                  *elInfo,
                  &aacEnc->qcOut,
                  &aacEnc->psyOut,
                  &globUsedBits,
                  ancBytes);

  INDIRECT(2); PTR_INIT(2); FUNC(2);
  UpdateBitres(&aacEnc->qcKernel,
               &aacEnc->qcOut);

  /* write out the bitstream */
  INDIRECT(1); FUNC(1); DIV(1); STORE(1);
  *numOutBytes = GetBitsAvail(aacEnc->hBitStream)/8;

  /* assert this frame is not too large */
  assert(*numOutBytes*8 <= MAX_CHANNEL_BITS * elInfo->nChannelsInEl);

  COUNT_sub_end();

  return 0;
}
Exemple #24
0
void MsStereoProcessing(float       *sfbEnergyLeft,
                        float       *sfbEnergyRight,
                        const float *sfbEnergyMid,
                        const float *sfbEnergySide,
                        float       *mdctSpectrumLeft,
                        float       *mdctSpectrumRight,
                        float       *sfbThresholdLeft,
                        float       *sfbThresholdRight,
                        float       *sfbSpreadedEnLeft,
                        float       *sfbSpreadedEnRight,
                        int         *msDigest,
                        int         *msMask,
                        const int   sfbCnt,
                        const int   sfbPerGroup,
                        const int   maxSfbPerGroup,
                        const int   *sfbOffset,
                        float       *weightMsLrPeRatio) 
{
  int sfb,sfboffs, j, cnt = 0;
  int msMaskTrueSomewhere = 0;
  int msMaskFalseSomewhere = 0;
  float sumMsLrPeRatio = 0;

  COUNT_sub_start("MsStereoProcessing");

  MOVE(4); /* counting previous operations */

  PTR_INIT(10); /* pointers for sfbThresholdLeft[sfb+sfboffs]
                                sfbThresholdRight[sfb+sfboffs]
                                sfbEnergyLeft[sfb+sfboffs]
                                sfbEnergyRight[sfb+sfboffs]
                                sfbEnergyMid[sfb+sfboffs]
                                sfbEnergySide[sfb+sfboffs]
                                sfbSpreadedEnLeft[sfb+sfboffs]
                                sfbSpreadedEnRight[sfb+sfboffs]
                                sfbOffset[sfb+sfboffs]
                                msMask[sfb+sfboffs]
               */
  LOOP(1);
  for(sfb=0; sfb<sfbCnt; sfb+=sfbPerGroup) {

    LOOP(1);
    for(sfboffs=0;sfboffs<maxSfbPerGroup;sfboffs++) {
      float pnlr,pnms,minThreshold;
      int useMS;
      
      ADD(1); BRANCH(1); MOVE(1);
      minThreshold=min(sfbThresholdLeft[sfb+sfboffs], sfbThresholdRight[sfb+sfboffs]);
      
      ADD(2); BRANCH(2); MOVE(2); /* max() */ DIV(2); MULT(1);
      pnlr = (sfbThresholdLeft[sfb+sfboffs]/
              max(sfbEnergyLeft[sfb+sfboffs],sfbThresholdLeft[sfb+sfboffs]))*
             (sfbThresholdRight[sfb+sfboffs]/
              max(sfbEnergyRight[sfb+sfboffs],sfbThresholdRight[sfb+sfboffs]));
      
      ADD(2); BRANCH(2); MOVE(2); /* max() */ DIV(2); MULT(1);
      pnms=  (minThreshold/max(sfbEnergyMid[sfb+sfboffs],minThreshold))*
             (minThreshold/max(sfbEnergySide[sfb+sfboffs],minThreshold));
      
      ADD(3); DIV(1);
      sumMsLrPeRatio += (pnlr + 1.0e-9f) / (pnms + 1.0e-9f) ;

      ADD(1);
      cnt++;

      ADD(1);
      useMS = (pnms >= pnlr);
      
      BRANCH(1);
      if(useMS){

        MOVE(2);
        msMask[sfb+sfboffs] = 1;
        msMaskTrueSomewhere = 1;

        PTR_INIT(2); /* pointers for mdctSpectrumLeft[],
                                     mdctSpectrumRight[]
                     */
        LOOP(1);
        for(j=sfbOffset[sfb+sfboffs]; j<sfbOffset[sfb+sfboffs+1]; j++) {
          float tmp = mdctSpectrumLeft[j];

          MOVE(1); /* counting operation above */

          ADD(1); MULT(1); STORE(1);
          mdctSpectrumLeft[j]  = 0.5f * (mdctSpectrumLeft[j] + mdctSpectrumRight[j]) ;

          ADD(1); MULT(1); STORE(1);
          mdctSpectrumRight[j] = 0.5f * (tmp - mdctSpectrumRight[j]) ;
        }

        MOVE(2);
        sfbThresholdLeft[sfb+sfboffs] = sfbThresholdRight[sfb+sfboffs] = minThreshold;

        MOVE(2);
        sfbEnergyLeft[sfb+sfboffs] = sfbEnergyMid[sfb+sfboffs];
        sfbEnergyRight[sfb+sfboffs] = sfbEnergySide[sfb+sfboffs];

        ADD(1); BRANCH(1); MOVE(1); /* min() */ MULT(1); STORE(2);
        sfbSpreadedEnLeft[sfb+sfboffs] = sfbSpreadedEnRight[sfb+sfboffs] =
          min(sfbSpreadedEnLeft[sfb+sfboffs], sfbSpreadedEnRight[sfb+sfboffs]) * 0.5f;

      }else {
        
        MOVE(2);
        msMask[sfb+sfboffs] = 0;
        msMaskFalseSomewhere = 1;
      }
    }
  }

  ADD(1); BRANCH(1);
  if(msMaskTrueSomewhere == 1) {

    ADD(1); BRANCH(1);
    if(msMaskFalseSomewhere == 1) {

      MOVE(1);
      *msDigest = SI_MS_MASK_SOME;
    } else {

      MOVE(1);
      *msDigest = SI_MS_MASK_ALL;
    }
  } else {

    MOVE(1);
    *msDigest = SI_MS_MASK_NONE;
  }
  
  ADD(1); BRANCH(1); MOVE(1);
  cnt = max (1,cnt);

  DIV(1); ADD(2); MULT(2); TRANS(1); STORE(1);
  *weightMsLrPeRatio = (float) (0.28 * atan( 0.37*(sumMsLrPeRatio/cnt-6.5) ) + 1.25);
  
  COUNT_sub_end();
}
Exemple #25
0
void GenerateAllMoves(const S_BOARD *pos, S_MOVELIST *list) {
	int pce = EMPTY;
	int side = pos->side;
	int sq = 0, t_sq = 0;
	int pceNum = 0;

	int dir = 0;
	int index = 0;
	int pceIndex = 0;

	ASSERT(CheckBoard(pos));
	list->count = 0;

	if(side == WHITE) {
		for(pceNum = 0; pceNum < pos->pceNum[wP]; ++pceNum) {
			sq = pos->pList[wP][pceNum];
			ASSERT(SqOnBoard(sq));

			if(pos->pieces[sq + 10] == EMPTY) {
				AddWhitePawnMove(pos, sq, sq + 10, list);
				if(RanksBrd[sq] == RANK_2 && pos->pieces[sq + 20] == EMPTY) {
					AddQuietMove(pos, MOVE(sq, (sq + 20), EMPTY, EMPTY, MFLAGPS), list);
				}
			}

			if(!SQOFFBOARD(sq + 9) && PieceCol[pos->pieces[sq + 9]] == BLACK) {
				AddWhitePawnCapMove(pos, sq, sq + 9, pos->pieces[sq + 9], list);
			}
			if(!SQOFFBOARD(sq + 11) && PieceCol[pos->pieces[sq + 11]] == BLACK) {
				AddWhitePawnCapMove(pos, sq, sq + 11, pos->pieces[sq + 11], list);
			}

			if(pos->enPas != NO_SQ) {
				if(sq + 9 == pos->enPas) {
					AddEnPassantMove(pos, MOVE(sq, sq + 9, EMPTY, EMPTY, MFLAGEP), list);
				}
				if(sq + 11 == pos->enPas) {
					AddEnPassantMove(pos, MOVE(sq, sq + 11, EMPTY, EMPTY, MFLAGEP), list);
				}
			}
		}

		if(pos->castlePerm & WKCA) {
			if(pos->pieces[F1] == EMPTY && pos->pieces[G1] == EMPTY) {
				if(!SqAttacked(E1, BLACK, pos) && !SqAttacked(F1, BLACK, pos)) {
					AddQuietMove(pos, MOVE(E1, G1, EMPTY, EMPTY, MFLAGCA), list);
				}
			}
		}		

		if(pos->castlePerm & WQCA) {
			if(pos->pieces[D1] == EMPTY && pos->pieces[C1] == EMPTY && pos->pieces[B1] == EMPTY) {
				if(!SqAttacked(E1, BLACK, pos) && !SqAttacked(D1, BLACK, pos)) {
					AddQuietMove(pos, MOVE(E1, C1, EMPTY, EMPTY, MFLAGCA), list);
				}
			}
		}
	} else {
		for(pceNum = 0; pceNum < pos->pceNum[bP]; ++pceNum) {
			sq = pos->pList[bP][pceNum];
			ASSERT(SqOnBoard(sq));

			if(pos->pieces[sq - 10] == EMPTY) {
				AddBlackPawnMove(pos, sq, sq - 10, list);
				if(RanksBrd[sq] == RANK_7 && pos->pieces[sq - 20] == EMPTY) {
					AddQuietMove(pos, MOVE(sq, (sq - 20), EMPTY, EMPTY, MFLAGPS), list);
				}
			}

			if(!SQOFFBOARD(sq - 9) && PieceCol[pos->pieces[sq - 9]] == WHITE) {
				AddBlackPawnCapMove(pos, sq, sq - 9, pos->pieces[sq - 9], list);
			}
			if(!SQOFFBOARD(sq - 11) && PieceCol[pos->pieces[sq - 11]] == WHITE) {
				AddBlackPawnCapMove(pos, sq, sq - 11, pos->pieces[sq - 11], list);
			}

			if(pos->enPas != NO_SQ) {
				if(sq - 9 == pos->enPas) {
					AddEnPassantMove(pos, MOVE(sq, sq - 9, EMPTY, EMPTY, MFLAGEP), list);
				}
				if(sq - 11 == pos->enPas) {
					AddEnPassantMove(pos, MOVE(sq, sq - 11, EMPTY, EMPTY, MFLAGEP), list);
				}
			}
		}	

		if(pos->castlePerm & BKCA) {
			if(pos->pieces[F8] == EMPTY && pos->pieces[G8] == EMPTY) {
				if(!SqAttacked(E8, WHITE, pos) && !SqAttacked(F8, WHITE, pos)) {
					AddQuietMove(pos, MOVE(E8, G8, EMPTY, EMPTY, MFLAGCA), list);
				}
			}
		}

		if(pos->castlePerm & BQCA) {
			if(pos->pieces[D8] == EMPTY && pos->pieces[C8] == EMPTY && pos->pieces[B8] == EMPTY) {
				if((!SqAttacked(E8, WHITE, pos)) && (!SqAttacked(D8, WHITE, pos))) {
					AddQuietMove(pos, MOVE(E8, C8, EMPTY, EMPTY, MFLAGCA), list);
				}
			}
		}
	}

	pceIndex = LoopSlideIndex[side];
	pce = LoopSlidePce[pceIndex++];
	while(pce != 0) {
		ASSERT(PieceValid(pce));

		for(pceNum = 0; pceNum < pos->pceNum[pce]; ++pceNum) {
			sq = pos->pList[pce][pceNum];
			ASSERT(SqOnBoard(sq));

			for(index = 0; index < NumDir[pce]; ++index) {
				dir = PceDir[pce][index];
				t_sq = sq + dir;

				while(!SQOFFBOARD(t_sq)) {

					if(pos->pieces[t_sq] != EMPTY) {
						if(PieceCol[pos->pieces[t_sq]] == (side ^ 1)) {
							AddCaptureMove(pos, MOVE(sq, t_sq, pos->pieces[t_sq], EMPTY, 0), list);
						}
						break;
					}
					AddQuietMove(pos, MOVE(sq, t_sq, EMPTY, EMPTY, 0), list);
					t_sq += dir;
				}
			}
		}
		pce = LoopSlidePce[pceIndex++];
	}

	pceIndex = LoopNonSlideIndex[side];
	pce = LoopNonSlidePce[pceIndex++];
	while(pce != 0) {
		ASSERT(PieceValid(pce));

		for(pceNum = 0; pceNum < pos->pceNum[pce]; ++pceNum) {
			sq = pos->pList[pce][pceNum];
			ASSERT(SqOnBoard(sq));

			for(index = 0; index < NumDir[pce]; ++index) {
				dir = PceDir[pce][index];
				t_sq = sq + dir;

				if(SQOFFBOARD(t_sq))
					continue;

				if(pos->pieces[t_sq] != EMPTY) {
					if(PieceCol[pos->pieces[t_sq]] == (side ^ 1)) {
						AddCaptureMove(pos, MOVE(sq, t_sq, pos->pieces[t_sq], EMPTY, 0), list);
					}
					continue;
				}
				AddQuietMove(pos, MOVE(sq, t_sq, EMPTY, EMPTY, 0), list);
			}
		}
		pce = LoopNonSlidePce[pceIndex++];
	}
}
Exemple #26
0
static const char *
aeabi_parse_arm_attributes(void *data, size_t length) 
{
	uint32_t sect_len;
	uint8_t *section = data;

#define	MOVE(len) do {            \
	assert(length >= (len));  \
	section += (len);         \
	length -= (len);          \
} while (0)

	if (length == 0 || *section != 'A')
		return (NULL);

	MOVE(1);

	/* Read the section length */
	if (length < sizeof(sect_len))
		return (NULL);

	memcpy(&sect_len, section, sizeof(sect_len));

	/*
	 * The section length should be no longer than the section it is within
	 */
	if (sect_len > length)
		return (NULL);

	MOVE(sizeof(sect_len));

	/* Skip the vendor name */
	while (length != 0) {
		if (*section == '\0')
			break;
		MOVE(1);
	}
	if (length == 0)
		return (NULL);
	MOVE(1);

	while (length != 0) {
		uint32_t tag_length;

	switch(*section) {
	case 1: /* Tag_File */
		MOVE(1);
		if (length < sizeof(tag_length))
			return (NULL);
		memcpy(&tag_length, section, sizeof(tag_length));
		break;
	case 2: /* Tag_Section */
	case 3: /* Tag_Symbol */
	default:
		return (NULL);
	}
	/* At least space for the tag and size */
	if (tag_length <= 5)
		return (NULL);
	tag_length--;
	/* Check the tag fits */
	if (tag_length > length)
		return (NULL);

#define  MOVE_TAG(len) do {           \
	assert(tag_length >= (len));  \
	MOVE(len);                    \
	tag_length -= (len);          \
} while(0)

		MOVE(sizeof(tag_length));
		tag_length -= sizeof(tag_length);

		while (tag_length != 0) {
			uint8_t tag;

			assert(tag_length >= length);

			tag = *section;
			MOVE_TAG(1);

			/*
			 * These tag values come from:
			 * 
			 * Addenda to, and Errata in, the ABI for the
			 * ARM Architecture. Release 2.08, section 2.3.
			 */
			if (tag == 6) { /* == Tag_CPU_arch */
				uint8_t val;

				val = *section;
				/*
				 * We don't support values that require
				 * more than one byte.
				 */
				if (val & (1 << 7))
					return (NULL);

				/* We have an ARMv4 or ARMv5 */
				if (val <= 5)
					return ("arm");
				else /* We have an ARMv6+ */
					return ("armv6");
			} else if (tag == 4 || tag == 5 || tag == 32 ||
			    tag == 65 || tag == 67) {
				while (*section != '\0' && length != 0)
					MOVE_TAG(1);
				if (tag_length == 0)
					return (NULL);
				/* Skip the last byte */
				MOVE_TAG(1);
			} else if ((tag >= 7 && tag <= 31) || tag == 34 ||
			    tag == 36 || tag == 38 || tag == 42 || tag == 44 ||
			    tag == 64 || tag == 66 || tag == 68 || tag == 70) {
				/* Skip the uleb128 data */
				while (*section & (1 << 7) && length != 0)
					MOVE_TAG(1);
				if (tag_length == 0)
					return (NULL);
				/* Skip the last byte */
				MOVE_TAG(1);
			} else
				return (NULL);
#undef MOVE_TAG
		}

		break;
	}
	return (NULL);
#undef MOVE
}
Exemple #27
0
/* ---------------------------------------------------------------------------
 * moves a element by +-X and +-Y
 */
void
MoveElementLowLevel (DataType *Data, ElementType *Element,
		     Coord DX, Coord DY)
{
  if (Data)
    r_delete_entry (Data->element_tree, (BoxType *)Element);
  ELEMENTLINE_LOOP (Element);
  {
    MOVE_LINE_LOWLEVEL (line, DX, DY);
  }
  END_LOOP;
  PIN_LOOP (Element);
  {
    if (Data)
      {
	r_delete_entry (Data->pin_tree, (BoxType *)pin);
	RestoreToPolygon (Data, PIN_TYPE, Element, pin);
      }
    MOVE_PIN_LOWLEVEL (pin, DX, DY);
    if (Data)
      {
	r_insert_entry (Data->pin_tree, (BoxType *)pin, 0);
	ClearFromPolygon (Data, PIN_TYPE, Element, pin);
      }
  }
  END_LOOP;
  PAD_LOOP (Element);
  {
    if (Data)
      {
	r_delete_entry (Data->pad_tree, (BoxType *)pad);
	RestoreToPolygon (Data, PAD_TYPE, Element, pad);
      }
    MOVE_PAD_LOWLEVEL (pad, DX, DY);
    if (Data)
      {
	r_insert_entry (Data->pad_tree, (BoxType *)pad, 0);
	ClearFromPolygon (Data, PAD_TYPE, Element, pad);
      }
  }
  END_LOOP;
  ARC_LOOP (Element);
  {
    MOVE_ARC_LOWLEVEL (arc, DX, DY);
  }
  END_LOOP;
  ELEMENTTEXT_LOOP (Element);
  {
    if (Data && Data->name_tree[n])
      r_delete_entry (PCB->Data->name_tree[n], (BoxType *)text);
    MOVE_TEXT_LOWLEVEL (text, DX, DY);
    if (Data && Data->name_tree[n])
      r_insert_entry (PCB->Data->name_tree[n], (BoxType *)text, 0);
  }
  END_LOOP;
  MOVE_BOX_LOWLEVEL (&Element->BoundingBox, DX, DY);
  MOVE_BOX_LOWLEVEL (&Element->VBox, DX, DY);
  MOVE (Element->MarkX, Element->MarkY, DX, DY);
  if (Data)
    r_insert_entry (Data->element_tree, (BoxType *)Element, 0);
}