Esempio n. 1
0
int _gnutls_auth_cipher_decrypt2(auth_cipher_hd_st * handle,
				 const void *ciphertext, int ciphertextlen,
				 void *text, int textlen)
{
	int ret;

	if (unlikely(ciphertextlen > textlen))
		return gnutls_assert_val(GNUTLS_E_INTERNAL_ERROR);

	if (handle->is_mac && (handle->etm != 0 && handle->cipher.e->type == CIPHER_BLOCK)) {
		/* The MAC is not to be hashed */
		ciphertextlen -= handle->tag_size;

		MAC(handle, ciphertext, ciphertextlen);
	}

	if (handle->non_null != 0) {
		ret =
		    _gnutls_cipher_decrypt2(&handle->cipher, ciphertext,
					    ciphertextlen, text, textlen);
		if (ret < 0)
			return gnutls_assert_val(ret);
	} else if (handle->non_null == 0 && text != ciphertext)
		memcpy(text, ciphertext, ciphertextlen);

	if (handle->is_mac && (handle->etm == 0 || handle->cipher.e->type != CIPHER_BLOCK)) {
		/* The MAC is not to be hashed */
		ciphertextlen -= handle->tag_size;

		MAC(handle, text, ciphertextlen);
	}

	return 0;
}
Esempio n. 2
0
/*
  The function performs the post modulation in the inverse
  transformation.
*/
static void 
postModulation(float *x,              /*!< pointer to spectum */
               int m,                 /*!< number of lines in spectrum */
               const float *trigData, /*!< pointer to trigData */
               int step,              /*!< steps */
               int trigDataSize)      /*!< size of trigData */
{
  int i;
  float wre, wim, re1, re2, im1, im2;
  const float *sinPtr = trigData;
  const float *cosPtr = trigData+trigDataSize;

  COUNT_sub_start("postModulation");

  MOVE(2); /* previous initialization */

  MOVE(2);
  wim = *sinPtr;
  wre = *cosPtr;

  PTR_INIT(2);  /* pointers for x[2*i], x[m-2-2*i] */
  MULT(1); LOOP(1);
  for (i = 0; i < m/4; i++)
  {
    MOVE(4);
    re1=x[2*i];
    im1=x[2*i+1];
    re2=x[m-2-2*i];
    im2=x[m-1-2*i];

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

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

    ADD(2);
    sinPtr+=step;
    cosPtr-=step;

    MOVE(2);
    wim=*sinPtr;
    wre=*cosPtr;

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

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

  COUNT_sub_end();
}
// copy tempucum -> ucum so ucum only has updates where wanted for each pl.
// avoids NaN or out of bounds assignments into ucum (which shows up in, e.g., dump diagnostics)
// Also ensures that final unewglobal values are only updated within the well-defined computational box
// Note that inversion U->p is also within well-defined computational box.
// Note that ustag->pstag occurs in fluxctstag.c in well-defined computational box [with extra face for each B1,B2,B3 as required]
// So overall prim,pstag,unew are only updated where desired -- no leakage unlike fluxes, temp primitives, and other things.
void copy_tempucum_finalucum(int *loop, FTYPE (*tempucum)[NSTORE2][NSTORE3][NPR], FTYPE (*ucum)[NSTORE2][NSTORE3][NPR])
{


#pragma omp parallel  // just copying, only need PLOOP even for ucum_check()
  {
    int i,j,k;
    int pl,pliter;
    int is,ie,js,je,ks,ke;
    extern void ucum_check(int i, int j, int k, int loc, int pl, FTYPE *ucum);

    // loop range where final ucum is set from scratch ucum that may have been set outside desired region for simplicity of loop structures
    is=loop[FIS]-SHIFT1*(AVOIDADVANCESHIFTX1DN==0);
    ie=loop[FIE]+SHIFT1*(AVOIDADVANCESHIFTX1UP==0);
    js=loop[FJS]-SHIFT2*(AVOIDADVANCESHIFTX2DN==0);
    je=loop[FJE]+SHIFT2*(AVOIDADVANCESHIFTX2UP==0);
    ks=loop[FKS]-SHIFT3*(AVOIDADVANCESHIFTX3DN==0);
    ke=loop[FKE]+SHIFT3*(AVOIDADVANCESHIFTX3UP==0);


    if(FLUXB==FLUXCTSTAG){
      // do non-field quantities
      copy_3d_nofield_nowait(is, ie, js, je, ks, ke, tempucum,ucum);


#if(PRODUCTION==0)
#pragma omp barrier // force barrier since otherwise nowait will leak into here with undefined values in general
      COMPZSLOOP(is,ie,js,je,ks,ke){
        PLOOPNOB1(pl) ucum_check(i,j,k,CENT,pl, MAC(ucum,i,j,k));
        PLOOPNOB2(pl) ucum_check(i,j,k,CENT,pl, MAC(ucum,i,j,k));
      }
#endif



      // do pl==B1
      pl=B1;
      is=loop[FIS]-SHIFT1*(AVOIDADVANCESHIFTX1DN==0);
      ie=loop[FIE]+SHIFT1*(AVOIDADVANCESHIFTX1UP==0);
      js=loop[FJS]-SHIFT2*(AVOIDADVANCESHIFTX2DN==0);
      je=loop[FJE]+SHIFT2*(AVOIDADVANCESHIFTX2UP==0);
      ks=loop[FKS]-SHIFT3*(AVOIDADVANCESHIFTX3DN==0);
      ke=loop[FKE]+SHIFT3*(AVOIDADVANCESHIFTX3UP==0);

      ie=loop[FIE]+SHIFT1; // always shift - override
      copy_3d_onepl_nowait(is, ie, js, je, ks, ke, pl, tempucum, ucum );

#if(PRODUCTION==0)
#pragma omp barrier // force barrier since otherwise nowait will leak into here with undefined values in general
      COMPZSLOOP(is,ie,js,je,ks,ke){
        ucum_check(i,j,k,FACE1,pl, MAC(ucum,i,j,k));
      }
Esempio n. 4
0
static void ajust_pos(struct cli_t *pcli, struct timeval *ti, double *a, double *b)
{
	mac_debug(MAC(pcli->climac), "drift: %d cur: (%lf, %lf) last: (%lf, %lf)\n",
			argument.drift, *a, *b, pcli->pos.x, pcli->pos.y);

	if(pcli->pos.x == 0 && pcli->pos.y == 0)
		goto update;
	/* 
	if(ti->tv_sec - pcli->pos.timestamp.tv_sec > argument.agetime)
		goto update;
		*/

	double _x = *a - pcli->pos.x;
	double _y = *b - pcli->pos.y;
	if(abs(_x) > argument.drift)
		*a = _x > 0 ? pcli->pos.x + argument.drift : 
			pcli->pos.x - argument.drift;
	if(abs(_y) > argument.drift)
		*b = _y > 0 ? pcli->pos.y + argument.drift : 
			pcli->pos.y - argument.drift;
update:
	pcli->pos.x = *a;
	pcli->pos.y = *b;
	//pcli->pos.timestamp.tv_sec = ti->tv_sec;
	return;
}
Esempio n. 5
0
static void twoChannelFiltering( const float *pQmf,
                                 float *mHybrid )
{
  int n;
  float cum0, cum1;

  FLC_sub_start("twoChannelFiltering");

  LOOP(1); PTR_INIT(2);
  MULT(1);
  cum0 = 0.5f * pQmf[HYBRID_FILTER_DELAY];

  MOVE(1);
  cum1 = 0;

  LOOP(1); PTR_INIT(2);
  for(n = 0; n < 6; n++) {

    MAC(1); MULT(1);
    cum1 += p2_6[n] * pQmf[2*n+1];
  }

  ADD(1); STORE(1);
  mHybrid[0] = cum0 + cum1;
  ADD(1); STORE(1);
  mHybrid[1] = cum0 - cum1;

  FLC_sub_end();
}
Esempio n. 6
0
static void calcPeCorrection(float *correctionFac,
                             const float peAct,
                             const float peLast, 
                             const int bitsLast) 
{
  COUNT_sub_start("calcPeCorrection");

  ADD(4); FUNC(1); FUNC(1); MULT(4); LOGIC(4); BRANCH(1);
  if ((bitsLast > 0) && (peAct < (float)1.5f*peLast) && (peAct > (float)0.7f*peLast) &&
      ((float)1.2f*bits2pe((float)bitsLast) > peLast) && 
      ((float)0.65f*bits2pe((float)bitsLast) < peLast))
  {
    float newFac = peLast / bits2pe((float)bitsLast);

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

    /* dead zone */
    ADD(1); BRANCH(1);
    if (newFac < (float)1.0f) {

      MULT(1); ADD(1); BRANCH(1); MOVE(1);
      newFac = min((float)1.1f*newFac, (float)1.0f);

      ADD(1); BRANCH(1); MOVE(1);
      newFac = max(newFac, (float)0.85f);
    }
    else {
      MULT(1); ADD(1); BRANCH(1); MOVE(1);
      newFac = max((float)0.9f*newFac, (float)1.0f);

      ADD(1); BRANCH(1); MOVE(1);
      newFac = min(newFac, (float)1.15f);
    }
    ADD(4); LOGIC(3); BRANCH(1);
    if (((newFac > (float)1.0f) && (*correctionFac < (float)1.0f)) ||
        ((newFac < (float)1.0f) && (*correctionFac > (float)1.0f))) {

      MOVE(1);
      *correctionFac = (float)1.0f;
    }

    /* faster adaptation towards 1.0, slower in the other direction */
    ADD(3); LOGIC(3); BRANCH(1); /* if() */ MULT(1); MAC(1); STORE(1);
    if ((*correctionFac < (float)1.0f && newFac < *correctionFac) ||
        (*correctionFac > (float)1.0f && newFac > *correctionFac))
      *correctionFac = (float)0.85f * (*correctionFac) + (float)0.15f * newFac;
    else
      *correctionFac = (float)0.7f * (*correctionFac) + (float)0.3f * newFac;

    ADD(2); BRANCH(2); MOVE(2);
    *correctionFac = min(*correctionFac, (float)1.15f);
    *correctionFac = max(*correctionFac, (float)0.85f);
  }
  else {
    MOVE(1);
    *correctionFac = (float)1.0f;
  }

  COUNT_sub_end();
}
Esempio n. 7
0
static float
AdvanceMAFilter( IIR_FILTER *iirFilter
                 )
{
  float y;
  int j;
  int ptr = iirFilter->ptr;
  int i = ptr + (BUFFER_SIZE-1);

  COUNT_sub_start("AdvanceMAFilter");

  INDIRECT(1); /* MOVE(1); --> ptr isn't needed */ ADD(1); /* counting previous operations */

  INDIRECT(2); MULT(1);
  y = (iirFilter->coeffIIRa[0] * iirFilter->ring_buf_2[i & (BUFFER_SIZE-1)]);

  PTR_INIT(3); /* iirFilter->noOffCoeffs
                  iirFilter->coeffIIRa[]
                  iirFilter->ring_buf_2[]
               */
  LOOP(1);
  for (j=1; j<iirFilter->noOffCoeffs; j++) {
    i--;

    MAC(1);
    y += (iirFilter->coeffIIRa[j] * iirFilter->ring_buf_2[i & (BUFFER_SIZE-1)]);
  }

  COUNT_sub_end();

  return y;
}
Esempio n. 8
0
/*!
 
  \brief  calc attenuation parameters - this has to take place after
          the 'QCMain' call because PeSum of the merged l/r-m/s signal
          is relevant
 
  \return nothing
 
****************************************************************************/
void UpdateStereoPreProcess(PSY_OUT_CHANNEL psyOutChannel[MAX_CHANNELS],
                            QC_OUT_ELEMENT* qcOutElement,   /*! provides access to PE */
                            HANDLE_STEREO_PREPRO hStPrePro,
                            float weightPeFac               /*! ratio of ms PE vs. lr PE */
                            )
{
  COUNT_sub_start("UpdateStereoPreProcess");

  INDIRECT(1); BRANCH(1);
  if (hStPrePro->stereoAttenuationFlag)
  { 
    float DELTA = 0.1f;

    INDIRECT(4); MOVE(4);
    hStPrePro->avrgFreqEnergyL = psyOutChannel[0].sfbEnSumLR;
    hStPrePro->avrgFreqEnergyR = psyOutChannel[1].sfbEnSumLR;
    hStPrePro->avrgFreqEnergyM = psyOutChannel[0].sfbEnSumMS;
    hStPrePro->avrgFreqEnergyS = psyOutChannel[1].sfbEnSumMS;


    INDIRECT(3); MULT(1); MAC(1); STORE(1);
    hStPrePro->smoothedPeSumSum = 
      DELTA * qcOutElement->pe * weightPeFac + (1 - DELTA) * hStPrePro->smoothedPeSumSum;


  }

  COUNT_sub_end();
}
Esempio n. 9
0
	/**
	 * Derive the multicast group used for address resolution (ARP/NDP) for an IP
	 *
	 * @param ip IP address (port field is ignored)
	 * @return Multicat group for ARP/NDP
	 */
	static inline MulticastGroup deriveMulticastGroupForAddressResolution(const InetAddress &ip)
		throw()
	{
		if (ip.isV4()) {
			// IPv4 wants braodcast MACs, so we shove the V4 address itself into
			// the Multicast Group ADI field. Making V4 ARP work is basically why
			// ADI was added, as well as handling other things that want mindless
			// Ethernet broadcast to all.
			return MulticastGroup(MAC((unsigned char)0xff),Utils::ntoh(*((const uint32_t *)ip.rawIpData())));
		} else if (ip.isV6()) {
			// IPv6 is better designed in this respect. We can compute the IPv6
			// multicast address directly from the IP address, and it gives us
			// 24 bits of uniqueness. Collisions aren't likely to be common enough
			// to care about.
			const unsigned char *a = (const unsigned char *)ip.rawIpData();
			MAC m;
			m.data[0] = 0x33;
			m.data[1] = 0x33;
			m.data[2] = 0xff;
			m.data[3] = a[13];
			m.data[4] = a[14];
			m.data[5] = a[15];
			return MulticastGroup(m,0);
		}
		return MulticastGroup();
	}
Esempio n. 10
0
/*
  The function performs the pre modulation in the inverse
  transformation.
*/
static void 
preModulation(float *x,                /*!< pointer to spectrum */
              int m,                   /*!< number of lines in spectrum */
              const float *sineWindow) /*!< pointer to modulation coefficients */
{
  int i;
  float wre, wim, re1, re2, im1, im2;

  COUNT_sub_start("preModulation");

  PTR_INIT(4);  /* pointers for x[2*i], x[m-2-2*i],
                                sineWindow[i*2],
                                sineWindow[m-1-2*i] */
  MULT(1); LOOP(1);
  for (i = 0; i < m/4; i++)
  {
    MOVE(4);
    re1 = x[2*i];
    im2 = x[2*i+1];
    re2 = x[m-2-2*i];
    im1 = x[m-1-2*i];

    MOVE(2);
    wim = sineWindow[i*2];
    wre = sineWindow[m-1-2*i];

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

    MULT(3); ADD(1); STORE(1);
    x[2*i+1] = 0.5f * (im1*wre - re1*wim);

    MOVE(2);
    wim = sineWindow[m-2-2*i];
    wre = sineWindow[2*i+1];

    MULT(2); MAC(1); STORE(1);   
    x[m-2-2*i] = 0.5f * (im2*wim + re2*wre);

    MULT(3); ADD(1); STORE(1);
    x[m-1-2*i] = 0.5f * (im2*wre - re2*wim);
  }

  COUNT_sub_end();
}
Esempio n. 11
0
void CalcBandEnergyMS(const float *mdctSpectrumLeft,
                      const float *mdctSpectrumRight,
                      const int   *bandOffset,
                      const int    numBands,
                      float      *bandEnergyMid,
                      float       *bandEnergyMidSum,
                      float      *bandEnergySide,
                      float       *bandEnergySideSum) {

    int i, j;

    COUNT_sub_start("CalcBandEnergyMS");

    MOVE(3);
    j = 0;
    *bandEnergyMidSum = 0.0f;
    *bandEnergySideSum = 0.0f;

    PTR_INIT(5); /* pointers for bandEnergyMid[],
                               bandEnergySide[],
                               bandOffset[],
                               mdctSpectrumLeft[],
                               mdctSpectrumRight[]
               */
    LOOP(1);
    for(i=0; i<numBands; i++) {

        MOVE(2);
        bandEnergyMid[i] = 0.0f;
        bandEnergySide[i] = 0.0f;

        LOOP(1);
        while (j < bandOffset[i+1]) {
            float specm, specs;

            ADD(2);
            MULT(2);
            specm = 0.5f * (mdctSpectrumLeft[j] + mdctSpectrumRight[j]);
            specs = 0.5f * (mdctSpectrumLeft[j] - mdctSpectrumRight[j]);

            MAC(2);
            STORE(2);
            bandEnergyMid[i]  += specm * specm;
            bandEnergySide[i] += specs * specs;

            j++;
        }
        ADD(2);
        STORE(2);
        *bandEnergyMidSum += bandEnergyMid[i];
        *bandEnergySideSum += bandEnergySide[i];

    }

    COUNT_sub_end();
}
Esempio n. 12
0
/*
 *
 * \brief Perform inverse filtering level emphasis
 *
 */
static void
inverseFilteringLevelEmphasis(HANDLE_SBR_LPP_TRANS hLppTrans,
                              unsigned char nInvfBands,
                              INVF_MODE *sbr_invf_mode,
                              INVF_MODE *sbr_invf_mode_prev,
                              float * bwVector
                              )
{
  int i;
  float accu;
  float  w1, w2;

  COUNT_sub_start("inverseFilteringLevelEmphasis");

  PTR_INIT(1); /* pointer for hLppTrans->bwVectorOld[] */
  LOOP(1);
  for(i = 0; i < nInvfBands; i++) {

    INDIRECT(1); FUNC(2); MOVE(1);
    bwVector[i] = mapInvfMode (sbr_invf_mode[i],
                               sbr_invf_mode_prev[i]);

    ADD(1); BRANCH(1);
    if(bwVector[i] < hLppTrans->bwVectorOld[i]) {

      MOVE(2);
      w1 = 0.75f;
      w2 = 0.25f;
    }
    else {

      MOVE(2);
      w1 = 0.90625f;
      w2 = 0.09375f;
    }

    MULT(1); MAC(1);
    accu = w1*bwVector[i] + w2*hLppTrans->bwVectorOld[i];

    ADD(1); BRANCH(1);
    if (accu < 0.015625f) {

      MOVE(1);
      accu=0;
    }

    ADD(1); BRANCH(1); MOVE(1);
    accu = min(accu,0.99609375f);

    MOVE(1);
    bwVector[i] = accu;
  }


  COUNT_sub_end();
}
Esempio n. 13
0
int _gnutls_auth_cipher_add_auth(auth_cipher_hd_st * handle,
				 const void *text, int textlen)
{
	int ret;

	if (handle->is_mac) {
		MAC(handle, text, textlen);
	} else if (_gnutls_cipher_is_aead(&handle->cipher))
		return _gnutls_cipher_auth(&handle->cipher, text, textlen);
	return 0;
}
Esempio n. 14
0
signed char parse( etherPacket_t * pstr_reply, char tch_replySrcIp[], char tch_replySrcHwAddr[], char tch_replyHwAddr[], char tch_replyAddrIp[] )
{
    struct in_addr str_tmpIpAddr;

    /* Fill the string tch_srcIpAddr, that is the IP address of the reply sender with the address contained in received packet */
    memset( &str_tmpIpAddr, 0, sizeof( struct in_addr ) );
    memcpy( &str_tmpIpAddr, pstr_reply->str_packet.tuc_srcIpAddr, 4 );
    strncpy( tch_replySrcIp, inet_ntoa( str_tmpIpAddr ), IP_ADDR_SIZE );

    /* 
     * Fill the string tch_replyIpAddr, that is the IP address of the host which MAC address is the one we requested about
     * This is the "real" answer to the request sent
     */
    memset( &str_tmpIpAddr, 0, sizeof( struct in_addr ) );
    memcpy( &str_tmpIpAddr, pstr_reply->str_packet.tuc_targetIpAddr, 4 );
    strncpy( tch_replyAddrIp, inet_ntoa( str_tmpIpAddr ), IP_ADDR_SIZE ); /* this is the answer */

    /* 
     * Fill the string tch_replySrcHwAddr with formatted MAC address contained in received datas
     * This is the hardware address of the sender of the parsed reply
     */
#define MAC(i) pstr_reply->tuc_senderHwAddr[(i)]
    snprintf( tch_replySrcHwAddr, MAC_ADDR_SIZE+1, "%02x:%02x:%02x:%02x:%02x:%02x", 
            MAC(0), MAC(1), MAC(2), MAC(3), MAC(4), MAC(5) );

    /* The same way, but with Hardware Address of the host we requested about (this must be the same than the one specified by user)) */
#define _MAC(i) pstr_reply->str_packet.tuc_targetHwAddr[(i)]
    snprintf( tch_replyHwAddr, MAC_ADDR_SIZE+1, "%02x:%02x:%02x:%02x:%02x:%02x", 
            _MAC(0), _MAC(1), _MAC(2), _MAC(3), _MAC(4), _MAC(5) );
    /* --- -- --- -- --- */

    return 0;
}
Esempio n. 15
0
/*
 *
 * \brief Perform complex-valued forward modulation of the time domain
 *        data of timeIn and stores the real part of the subband
 *        samples in rSubband, and the imaginary part in iSubband
 *
 */
static void
sbrForwardModulation (const float *timeIn,
                      float *rSubband,
                      float *iSubband,
                      HANDLE_SBR_QMF_FILTER_BANK anaQmf
                      )
{
  int i, offset;

  float real, imag;

  COUNT_sub_start("sbrForwardModulation");

  MOVE(1);
  offset = 2 * NO_ANALYSIS_CHANNELS;

  PTR_INIT(1);  /* pointer for timeIn[offset - 1 - i] */
  LOOP(1);
  for (i = 0; i < NO_ANALYSIS_CHANNELS; i++) {
    ADD(2); STORE(2);
    rSubband[i] = timeIn[i] - timeIn[offset - 1 - i];
    iSubband[i] = timeIn[i] + timeIn[offset - 1 - i];
  }

  FUNC(2);
  cosMod (rSubband, anaQmf);
  FUNC(2);
  sinMod (iSubband, anaQmf);

  PTR_INIT(4);  /* pointers for rSubband[i],
                                iSubband[i],
                                anaQmf->t_cos[i],
                                anaQmf->t_sin[i]  */
  INDIRECT(1); LOOP(1);
  for (i = 0; i < anaQmf->lsb; i++) {

    MOVE(2);
    real = rSubband[i];
    imag = iSubband[i];

    MULT(1); MAC(1); STORE(1);
    rSubband[i] = real * anaQmf->t_cos[i] + imag * anaQmf->t_sin[i];
    MULT(2); ADD(1); STORE(1);
    iSubband[i] = imag * anaQmf->t_cos[i] - real * anaQmf->t_sin[i];
  }

  COUNT_sub_end();
}
Esempio n. 16
0
bool ProtocolDHCP::dissect(const FrameBuffer& buffer, size_t& offset, Protocol::Ptr& next)
{
    if (!enoughFor(buffer, offset, sizeof (DHCPHeader))) {
        return false;
    }
    struct DHCPHeader * dhcp = (struct DHCPHeader*) (buffer.begin() + offset);
    _type = dhcp->type;
    _clientMAC = MAC(dhcp->macAddress);
    Poco::UInt32 ipAddress = ntohl(dhcp->ipYour);
    _assignedIP = Poco::Net::IPAddress(&ipAddress, sizeof (Poco::UInt32));
    offset += sizeof (struct DHCPHeader);
    bool more = parseOption(buffer, offset);
    while (more) {
        more = parseOption(buffer, offset);
    };
    next = nullptr;
    return true;
}
Esempio n. 17
0
void doMAC(uint8_t *cc_nr_p, uint8_t *div_key_p, uint8_t mac[4])
{
	uint8_t cc_nr[13] = { 0 };
    uint8_t div_key[8];
	//cc_nr=(uint8_t*)malloc(length+1);

	memcpy(cc_nr,cc_nr_p,12);
    memcpy(div_key,div_key_p,8);

	reverse_arraybytes(cc_nr,12);
	BitstreamIn bitstream = {cc_nr,12 * 8,0};
    uint8_t dest []= {0,0,0,0,0,0,0,0};
    BitstreamOut out = { dest, sizeof(dest)*8, 0 };
    MAC(div_key,bitstream, out);
    //The output MAC must also be reversed
    reverse_arraybytes(dest, sizeof(dest));
    memcpy(mac, dest, 4);
	//free(cc_nr);
    return;
}
Esempio n. 18
0
static void
AdvanceARFilter( IIR_FILTER *iirFilter,
                 float input
                 )

{
  int j;
  float y;
  int ptr = iirFilter->ptr;
  int i = ptr + (BUFFER_SIZE-1);

  COUNT_sub_start("AdvanceARFilter");

  INDIRECT(1); MOVE(1); ADD(1); /* counting previous operations */

  INDIRECT(2); MULT(1); ADD(1);
  y = input + (iirFilter->coeffIIRb[1] * (-iirFilter->ring_buf_2[i & (BUFFER_SIZE-1)]));

  PTR_INIT(4); /* iirFilter->noOffCoeffs
                  iirFilter->coeffIIRb[]
                  iirFilter->ring_buf_2[i]
                  iirFilter->ring_buf_2[ptr]
               */

  LOOP(1);
  for (j=2; j<iirFilter->noOffCoeffs; j++) {
    i--;

    MULT(1); MAC(1);
    y += (iirFilter->coeffIIRb[j] * (-iirFilter->ring_buf_2[i & (BUFFER_SIZE-1)]));
  }

  MOVE(1);
  iirFilter->ring_buf_2[ptr] = y;

  /* pointer update */
  iirFilter->ptr = (ptr+1) & (BUFFER_SIZE-1);

  COUNT_sub_end();

}
Esempio n. 19
0
void CalcBandEnergy(const float *mdctSpectrum,
                    const int   *bandOffset,
                    const int    numBands,
                    float      *bandEnergy,
                    float       *bandEnergySum) {
    int i, j;

    COUNT_sub_start("CalcBandEnergy");

    MOVE(2);
    j = 0;
    *bandEnergySum = 0.0f;

    PTR_INIT(3); /* pointers for bandEnergy[],
                               bandOffset[],
                               mdctSpectrum[]
                */
    LOOP(1);
    for(i=0; i<numBands; i++) {

        MOVE(1);
        bandEnergy[i] = 0.0f;

        LOOP(1);
        while (j < bandOffset[i+1]) {

            MAC(1);
            STORE(1);
            bandEnergy[i] += mdctSpectrum[j] * mdctSpectrum[j];

            j++;
        }
        ADD(1);
        STORE(1);
        *bandEnergySum += bandEnergy[i];
    }

    COUNT_sub_end();
}
Esempio n. 20
0
void BSDEthernetTap::scanMulticastGroups(std::vector<MulticastGroup> &added,std::vector<MulticastGroup> &removed)
{
	std::vector<MulticastGroup> newGroups;

	struct ifmaddrs *ifmap = (struct ifmaddrs *)0;
	if (!getifmaddrs(&ifmap)) {
		struct ifmaddrs *p = ifmap;
		while (p) {
			if (p->ifma_addr->sa_family == AF_LINK) {
				struct sockaddr_dl *in = (struct sockaddr_dl *)p->ifma_name;
				struct sockaddr_dl *la = (struct sockaddr_dl *)p->ifma_addr;
				if ((la->sdl_alen == 6)&&(in->sdl_nlen <= _dev.length())&&(!memcmp(_dev.data(),in->sdl_data,in->sdl_nlen)))
					newGroups.push_back(MulticastGroup(MAC(la->sdl_data + la->sdl_nlen,6),0));
			}
			p = p->ifma_next;
		}
		freeifmaddrs(ifmap);
	}

	std::vector<InetAddress> allIps(ips());
	for(std::vector<InetAddress>::iterator ip(allIps.begin());ip!=allIps.end();++ip)
		newGroups.push_back(MulticastGroup::deriveMulticastGroupForAddressResolution(*ip));

	std::sort(newGroups.begin(),newGroups.end());
	std::unique(newGroups.begin(),newGroups.end());

	for(std::vector<MulticastGroup>::iterator m(newGroups.begin());m!=newGroups.end();++m) {
		if (!std::binary_search(_multicastGroups.begin(),_multicastGroups.end(),*m))
			added.push_back(*m);
	}
	for(std::vector<MulticastGroup>::iterator m(_multicastGroups.begin());m!=_multicastGroups.end();++m) {
		if (!std::binary_search(newGroups.begin(),newGroups.end(),*m))
			removed.push_back(*m);
	}

	_multicastGroups.swap(newGroups);
}
Esempio n. 21
0
/*
 * \brief Perform transposition by patching of subband samples.
 */
void lppTransposer (HANDLE_SBR_LPP_TRANS hLppTrans,
                    float **qmfBufferReal,
#ifndef LP_SBR_ONLY
                    float **qmfBufferImag,
#endif
                    float *degreeAlias,
                    int timeStep,
                    int firstSlotOffs,
                    int lastSlotOffs,
                    unsigned char nInvfBands,
                    INVF_MODE *sbr_invf_mode,
                    INVF_MODE *sbr_invf_mode_prev,
                    int   bUseLP
                    )
{
  int    bwIndex[MAX_NUM_PATCHES];
  float  bwVector[MAX_NUM_PATCHES];

  int    i,j;
  int    loBand, hiBand;

  PATCH_PARAM *patchParam;

  int    patch;

  float  alphar[LPC_ORDER], a0r, a1r;
  float  alphai[LPC_ORDER], a0i, a1i;

  float  bw;

  int    autoCorrLength;

  float k1, k1_below, k1_below2;

  ACORR_COEFS ac;
  int    startSample;
  int    stopSample;
  int    stopSampleClear;
  int    lb, hb;

  int targetStopBand;

  COUNT_sub_start("lppTransposer");

  INDIRECT(1); PTR_INIT(1);
  patchParam = hLppTrans->pSettings->patchParam;

  MOVE(1);
  bw = 0.0f;

  MOVE(2);
  k1_below=0, k1_below2=0;

  MULT(1);
  startSample = firstSlotOffs * timeStep;

  INDIRECT(1); MULT(1); ADD(1);
  stopSample  = hLppTrans->pSettings->nCols + lastSlotOffs * timeStep;

  FUNC(5);
  inverseFilteringLevelEmphasis(hLppTrans, nInvfBands, sbr_invf_mode, sbr_invf_mode_prev, bwVector);


  MOVE(1);
  stopSampleClear = stopSample;

  PTR_INIT(2); /* pointers for qmfBufferReal[],
                               qmfBufferImag[]  */
  INDIRECT(1); LOOP(1);
  for ( patch = 0; patch < hLppTrans->pSettings->noOfPatches; patch++ ) {
    LOOP(1);
    for (i = startSample; i < stopSampleClear; i++) {
      INDIRECT(1); ADD(1); LOOP(1);
      for(j=patchParam[patch].guardStartBand; j<patchParam[patch].guardStartBand+GUARDBANDS; j++){
        MOVE(1);
        qmfBufferReal[i][j] = 0.0;
#ifndef LP_SBR_ONLY
        BRANCH(1);
        if (!bUseLP) {
          MOVE(1);
          qmfBufferImag[i][j] = 0.0;
        }
#endif
      }
    }
  }

  INDIRECT(4); ADD(1);
  targetStopBand = patchParam[hLppTrans->pSettings->noOfPatches-1].targetStartBand +
    patchParam[hLppTrans->pSettings->noOfPatches-1].numBandsInPatch;

  PTR_INIT(2); /* pointers for qmfBufferReal[],
                               qmfBufferImag[]  */
  LOOP(1);
  for (i = startSample; i < stopSampleClear; i++) {
    LOOP(1);
    for (j=targetStopBand; j<NO_SYNTHESIS_CHANNELS; j++) {
      MOVE(1);
      qmfBufferReal[i][j] = 0.0;
#ifndef LP_SBR_ONLY
      BRANCH(1);
      if (!bUseLP) {
        MOVE(1);
        qmfBufferImag[i][j] = 0.0;
      }
#endif
    }
  }

  INDIRECT(1); ADD(1);
  autoCorrLength = hLppTrans->pSettings->nCols + 6;

  PTR_INIT(1); /* pointer for bwIndex[patch] */
  INDIRECT(1); LOOP(1);
  for ( patch=0; patch<hLppTrans->pSettings->noOfPatches; patch++ ) {
    MOVE(1);
    bwIndex[patch] = 0;
  }



  BRANCH(1);
  if (bUseLP) {

    INDIRECT(1); ADD(1); BRANCH(1); MOVE(1);
    lb = max(1, hLppTrans->pSettings->lbStartPatching - 2);

    INDIRECT(1);
    hb = patchParam[0].targetStartBand;
  }
#ifndef LP_SBR_ONLY
  else {

    INDIRECT(2); MOVE(2);
    lb = hLppTrans->pSettings->lbStartPatching;
    hb = hLppTrans->pSettings->lbStopPatching;
  }
#endif


  PTR_INIT(2); /* pointers for qmfBufferReal[],
                               qmfBufferImag[]  */
  INDIRECT(1); LOOP(1);
  for ( loBand = lb; loBand < hb; loBand++ ) {

    float  lowBandReal[MAX_ENV_COLS+LPC_ORDER];
#ifndef LP_SBR_ONLY
    float  lowBandImag[MAX_ENV_COLS+LPC_ORDER];
#endif
    int lowBandPtr =0;
    int resetLPCCoeffs=0;

    PTR_INIT(4); /* pointers for lowBandReal[],
                                 lowBandImag[],
                                 lpcFilterStatesReal,
                                 lpcFilterStatesImag  */
    LOOP(1);
    for(i=0;i<LPC_ORDER;i++){
      MOVE(1);
      lowBandReal[lowBandPtr] = hLppTrans->lpcFilterStatesReal[i][loBand];

#ifndef LP_SBR_ONLY
      if (!bUseLP) {
        MOVE(1);
        lowBandImag[lowBandPtr] = hLppTrans->lpcFilterStatesImag[i][loBand];
      }
#endif
      lowBandPtr++;
    }

    LOOP(1);
    for(i=0;i< 6;i++){

      MOVE(1);
      lowBandReal[lowBandPtr] = (float) qmfBufferReal[i][loBand];

#ifndef LP_SBR_ONLY
      BRANCH(1);
      if (!bUseLP) {
        MOVE(1);
        lowBandImag[lowBandPtr] = (float) qmfBufferImag[i][loBand];
      }
#endif
      lowBandPtr++;
    }


    INDIRECT(1); ADD(1); LOOP(1);
    for(i=6;i<hLppTrans->pSettings->nCols+6;i++){

        MOVE(1);
        lowBandReal[lowBandPtr] = (float) qmfBufferReal[i][loBand];

#ifndef LP_SBR_ONLY
        BRANCH(1);
        if (!bUseLP) {
          MOVE(1);
          lowBandImag[lowBandPtr] = (float) qmfBufferImag[i][loBand];
        }
#endif
        lowBandPtr++;
    }


    BRANCH(1);
    if (bUseLP) {
      PTR_INIT(1); ADD(1); FUNC(3);
      autoCorrelation2ndLP(&ac,
                           lowBandReal+LPC_ORDER,
                           autoCorrLength);
    }
#ifndef LP_SBR_ONLY
    else {
      PTR_INIT(1); ADD(2); FUNC(3);
      autoCorrelation2nd(&ac,
                         lowBandReal+LPC_ORDER,
                         lowBandImag+LPC_ORDER,
                         autoCorrLength);
    }
#endif

    MOVE(2);
    alphar[1] = 0;
    alphai[1] = 0;

    INDIRECT(1); BRANCH(1);
    if (ac.det != 0.0f) {
      float fac;

      DIV(1);
      fac = 1.0f / ac.det;

      MULT(4); ADD(2); STORE(1);
      alphar[1] = ( ac.r01r * ac.r12r - ac.r01i * ac.r12i - ac.r02r * ac.r11r ) * fac;

#ifndef LP_SBR_ONLY
      BRANCH(1);
      if (!bUseLP) {
        MULT(3); MAC(1); ADD(1); STORE(1);
        alphai[1] = ( ac.r01i * ac.r12r + ac.r01r * ac.r12i - ac.r02i * ac.r11r ) * fac;
      }
#endif
    }

    MOVE(2);
    alphar[0] = 0;
    alphai[0] = 0;


    INDIRECT(1); BRANCH(1);
    if ( ac.r11r != 0.0f ) {
      float fac;

      DIV(1);
      fac = 1.0f / ac.r11r;

      MULT(3); MAC(1); ADD(1); STORE(1);
      alphar[0] = - ( ac.r01r + alphar[1] * ac.r12r + alphai[1] * ac.r12i ) * fac;

#ifndef LP_SBR_ONLY
      BRANCH(1);
      if (!bUseLP) {
        MULT(4); ADD(2); STORE(1);
        alphai[0] = - ( ac.r01i + alphai[1] * ac.r12r - alphar[1] * ac.r12i ) * fac;
      }
#endif

    }
    
    MULT(1); MAC(1); ADD(1); BRANCH(1);
    if(alphar[0]*alphar[0] + alphai[0]*alphai[0] >= 16.0f) {
      MOVE(1);
      resetLPCCoeffs=1;
    }
    MULT(1); MAC(1); ADD(1); BRANCH(1);
    if(alphar[1]*alphar[1] + alphai[1]*alphai[1] >= 16.0f) {
      MOVE(1);
      resetLPCCoeffs=1;
    }

    BRANCH(1);
    if(resetLPCCoeffs){
      MOVE(4);
      alphar[0] = alphar[1] = 0;
      alphai[0] = alphai[1] = 0;
    }

    BRANCH(1);
    if (bUseLP) {

      INDIRECT(1); BRANCH(1);
      if(ac.r11r==0.0f) {
        MOVE(1);
        k1 = 0.0f;
      }
      else {
        INDIRECT(2); DIV(1); MULT(1);
        k1 = -(ac.r01r/ac.r11r);

        ADD(1); BRANCH(1); MOVE(1);
        k1 = min(k1, 1.0f);
        ADD(1); BRANCH(1); MOVE(1);
        k1 = max(k1,-1.0f);
      }

      ADD(1); BRANCH(1);
      if(loBand > 1){
        float deg;

        MULT(1); ADD(1);
        deg = 1.0f - (k1_below * k1_below);

        MOVE(1);
        degreeAlias[loBand] = 0;

        PTR_INIT(1); /* pointer for degreeAlias[] */

        LOGIC(2); BRANCH(1);
        if (((loBand & 1) == 0) && (k1 < 0)){

          BRANCH(1);
          if (k1_below < 0) {

            MOVE(1);
            degreeAlias[loBand] = 1.0f;

            BRANCH(1);
            if ( k1_below2 > 0 ) {

              MOVE(1);
              degreeAlias[loBand-1] = deg;
            }
          }
          else {
            BRANCH(1);
            if ( k1_below2 > 0 ) {
              MOVE(1);
              degreeAlias[loBand] = deg;
            }
          }
        }

        LOGIC(2); BRANCH(1);
        if (((loBand & 1) == 1) && (k1 > 0)){

          BRANCH(1);
          if (k1_below > 0) {

            MOVE(1);
            degreeAlias[loBand] = 1.0f;

            BRANCH(1);
            if ( k1_below2 < 0 ) {

              MOVE(1);
              degreeAlias[loBand-1] = deg;
            }
          }
          else {
            BRANCH(1);
            if ( k1_below2 < 0 ) {
              MOVE(1);
              degreeAlias[loBand] = deg;
            }
          }
        }
      }
      MOVE(2);
      k1_below2 = k1_below;
      k1_below = k1;
    }

    MOVE(1);
    patch = 0;

    PTR_INIT(1); /* pointer for patchParam[patch] */
    INDIRECT(1); LOOP(1);
    while ( patch < hLppTrans->pSettings->noOfPatches ) {

      ADD(1);
      hiBand = loBand + patchParam[patch].targetBandOffs;

      ADD(2); LOGIC(1); BRANCH(1);
      if ( loBand < patchParam[patch].sourceStartBand || loBand >= patchParam[patch].sourceStopBand ) {
        ADD(1);
        patch++;
        continue;
      }
      assert( hiBand < NO_SYNTHESIS_CHANNELS );

      LOOP(1);
      while (hiBand >= hLppTrans->pSettings->bwBorders[bwIndex[patch]]) {
        INDIRECT(1); /* while() condition */

        ADD(1); STORE(1);
        bwIndex[patch]++;
      }

      INDIRECT(1);
      bw = bwVector[bwIndex[patch]];

      INDIRECT(4); MULT(5);
      a0r = bw * alphar[0];
      a0i = bw * alphai[0];
      bw =  bw*bw;
      a1r = bw * alphar[1];
      a1i = bw * alphai[1];


      PTR_INIT(4); /* pointers for lowBandReal[],
                                   lowBandImag[],
                                   qmfBufferReal[],
                                   qmfBufferImag[]  */
      LOOP(1);
      for(i = startSample; i < stopSample; i++ ) {

        MOVE(1);
        qmfBufferReal[i][hiBand] = lowBandReal[LPC_ORDER+i];

        BRANCH(1);
        if (bUseLP) {

          BRANCH(1);
          if ( bw > 0 ) {

            MAC(2); STORE(1);
            qmfBufferReal[i][hiBand] = qmfBufferReal[i][hiBand] +
              a0r * lowBandReal[LPC_ORDER+i-1] +
              a1r * lowBandReal[LPC_ORDER+i-2];
          }
        }
#ifndef LP_SBR_ONLY
        else {

          MOVE(1);
          qmfBufferImag[i][hiBand] = lowBandImag[LPC_ORDER+i];

          BRANCH(1);
          if ( bw > 0 ) {
            float accu;

            MULT(4); ADD(3);
            accu = a0r * lowBandReal[LPC_ORDER+i-1] -  a0i * lowBandImag[LPC_ORDER+i-1]+
              a1r * lowBandReal[LPC_ORDER+i-2] -  a1i * lowBandImag[LPC_ORDER+i-2];

            ADD(1); STORE(1);
            qmfBufferReal[i][hiBand] = qmfBufferReal[i][hiBand] + accu;

            MAC(4);
            accu = a0i * lowBandReal[LPC_ORDER+i-1] +  a0r * lowBandImag[LPC_ORDER+i-1]+
              a1i * lowBandReal[LPC_ORDER+i-2] +  a1r * lowBandImag[LPC_ORDER+i-2];

            ADD(1); STORE(1);
            qmfBufferImag[i][hiBand] = qmfBufferImag[i][hiBand] + accu;
          }
        }
#endif

      }


      patch++;

    }  /* Patch */

  }  /* loBand (band) */


  PTR_INIT(4); /* pointers for lpcFilterStatesReal[][loBand],
                               lpcFilterStatesImag[][loBand],
                               qmfBufferReal[],
                               qmfBufferImag[]  */
  LOOP(1);
  for(i=0;i<LPC_ORDER;i++){
    INDIRECT(1); LOOP(1);
    for (loBand=0; loBand<patchParam[0].targetStartBand; loBand++) {
      MOVE(1);
      hLppTrans->lpcFilterStatesReal[i][loBand] = qmfBufferReal[hLppTrans->pSettings->nCols-LPC_ORDER+i][loBand];
#ifndef LP_SBR_ONLY
      BRANCH(1);
      if (!bUseLP) {
        MOVE(1);
        hLppTrans->lpcFilterStatesImag[i][loBand] = qmfBufferImag[hLppTrans->pSettings->nCols-LPC_ORDER+i][loBand];
      }
#endif
    }
  }

  BRANCH(1);
  if (bUseLP) {

    PTR_INIT(2); /* pointers for degreeAlias[loBand],
                                 degreeAlias[hiBand]  */
    INDIRECT(2); LOOP(1);
    for ( loBand = hLppTrans->pSettings->lbStartPatching; loBand <  hLppTrans->pSettings->lbStopPatching; loBand++ ) {

      MOVE(1);
      patch = 0;

      INDIRECT(1); LOOP(1);
      while ( patch < hLppTrans->pSettings->noOfPatches ) {

        INDIRECT(1); ADD(1);
        hiBand = loBand + patchParam[patch].targetBandOffs;

        LOGIC(2); ADD(3); BRANCH(1);
        if ( loBand < patchParam[patch].sourceStartBand
             || loBand >= patchParam[patch].sourceStopBand
             || hiBand >= NO_SYNTHESIS_CHANNELS
             ) {
          ADD(1);
          patch++;
          continue;
        }

        INDIRECT(1); ADD(1); BRANCH(1);
        if(hiBand != patchParam[patch].targetStartBand) {
          MOVE(1);
          degreeAlias[hiBand] = degreeAlias[loBand];
        }
        else {
          MOVE(1);
          degreeAlias[hiBand] = 0;
        }

        patch++;
      }
    }/* end  for loop */
  }

  PTR_INIT(2); /* pointers for bwVectorOld[],
                               bwVector[]     */
  LOOP(1);
  for (i = 0; i < nInvfBands; i++ ) {
    MOVE(1);
    hLppTrans->bwVectorOld[i] = bwVector[i];
  }

  COUNT_sub_end();
}
Esempio n. 22
0
/*
 *
 * \brief Calculate second order autocorrelation using 2 accumulators
 *
 */
static void
autoCorrelation2ndLP(ACORR_COEFS *ac,
                     float *realBuf,
                     int len
                     )
{
  int   j;
  float accu1, accu2;

  COUNT_sub_start("autoCorrelation2ndLP");


  MOVE(1);
  accu1 = 0.0;

  PTR_INIT(1); /* pointer for realBuf[]  */
  ADD(1); LOOP(1);
  for ( j = 0; j < len - 1; j++ ) {

    MAC(1);
    accu1 += realBuf[j-1] * realBuf[j-1];
  }

  MULT(1);
  accu2 = realBuf[-2] * realBuf[-2];

  ADD(1);
  accu2 += accu1;

  MAC(1);
  accu1 += realBuf[j-1] * realBuf[j-1];

  MOVE(2);
  ac->r11r = accu1;
  ac->r22r = accu2;


  MOVE(1);
  accu1 = 0.0;

  PTR_INIT(1); /* pointer for realBuf[] */
  LOOP(1);
  for ( j = 0; j < len - 1; j++ ) {

    MAC(1);
    accu1 += realBuf[j] * realBuf[j-1];
  }

  MULT(1);
  accu2 = realBuf[-1] * realBuf[-2];

  ADD(1);
  accu2 += accu1;

  MAC(1);
  accu1 += realBuf[j] * realBuf[j-1];

  MOVE(2);
  ac->r01r = accu1;
  ac->r12r = accu2;


  MOVE(1);
  accu1=0.0;

  PTR_INIT(1); /* pointer for realBuf[] */
  LOOP(1);
  for ( j = 0; j < len; j++ ) {

    MAC(1);
    accu1 += realBuf[j] * realBuf[j-2];
  }

  MOVE(1);
  ac->r02r = accu1;

  MULT(2); ADD(1); STORE(1);
  ac->det = ac->r11r * ac->r22r - ac->r12r * ac->r12r;

  MOVE(3);
  ac->r01i = ac->r02i = ac->r12i = 0.0f;

  INDIRECT(10); MOVE(10); /* move all register variables to the structure ac->... */

  COUNT_sub_end();
}
Esempio n. 23
0
/* The caller must make sure that textlen+pad_size+tag_size is divided by the block size of the cipher */
int _gnutls_auth_cipher_encrypt2_tag(auth_cipher_hd_st * handle,
				     const uint8_t * text, int textlen,
				     void *_ciphertext, int ciphertextlen,
				     int pad_size)
{
	int ret;
	uint8_t *ciphertext = _ciphertext;
	unsigned blocksize =
	    _gnutls_cipher_get_block_size(handle->cipher.e);
	unsigned l;

	if (handle->is_mac) { /* cipher + mac */
		if (handle->non_null == 0) { /* NULL cipher + MAC */
			MAC(handle, text, textlen);

			if (unlikely(textlen + pad_size + handle->tag_size) >
			    ciphertextlen)
				return gnutls_assert_val(GNUTLS_E_INTERNAL_ERROR);

			if (text != ciphertext)
				memcpy(ciphertext, text, textlen);
			ret =
			    _gnutls_auth_cipher_tag(handle,
						    ciphertext + textlen,
						    handle->tag_size);
			if (ret < 0)
				return gnutls_assert_val(ret);

		} else {
			uint8_t *orig_ciphertext = ciphertext;

			if (handle->etm == 0 || handle->cipher.e->type != CIPHER_BLOCK) {
				MAC(handle, text, textlen);
			}

			if (unlikely(textlen + pad_size + handle->tag_size) >
			    ciphertextlen)
				return gnutls_assert_val(GNUTLS_E_INTERNAL_ERROR);

			l = (textlen / blocksize) * blocksize;
			if (l > 0) {
				ret =
			    	_gnutls_cipher_encrypt2(&handle->cipher, text,
						    l, ciphertext,
						    ciphertextlen);
				if (ret < 0)
					return gnutls_assert_val(ret);

				textlen -= l;
				text += l;
				ciphertext += l;
				ciphertextlen -= l;
			}

			if (ciphertext != text && textlen > 0)
				memcpy(ciphertext, text, textlen);

			if (handle->etm == 0 || handle->cipher.e->type != CIPHER_BLOCK) {
				ret =
				    _gnutls_auth_cipher_tag(handle,
							    ciphertext + textlen,
							    handle->tag_size);
				if (ret < 0)
					return gnutls_assert_val(ret);
				textlen += handle->tag_size;
			}

			/* TLS 1.0 style padding */
			if (pad_size > 0) {
				memset(ciphertext + textlen, pad_size - 1,
				       pad_size);
				textlen += pad_size;
			}

			ret =
			    _gnutls_cipher_encrypt2(&handle->cipher,
						    ciphertext, textlen,
						    ciphertext,
						    ciphertextlen);
			if (ret < 0)
				return gnutls_assert_val(ret);

			if (handle->etm != 0 && handle->cipher.e->type == CIPHER_BLOCK) {
				MAC(handle, orig_ciphertext, l);
				MAC(handle, ciphertext, textlen);

				ret =
				    _gnutls_auth_cipher_tag(handle,
						    	    ciphertext + textlen,
						    	    handle->tag_size);
				if (ret < 0)
					return gnutls_assert_val(ret);
			}
		}
	} else if (_gnutls_cipher_is_aead(&handle->cipher)) {
		ret =
		    _gnutls_cipher_encrypt2(&handle->cipher, text, textlen,
					    ciphertext, ciphertextlen);
		if (unlikely(ret < 0))
			return gnutls_assert_val(ret);

		ret =
		    _gnutls_auth_cipher_tag(handle, ciphertext + textlen,
					    handle->tag_size);
		if (unlikely(ret < 0))
			return gnutls_assert_val(ret);
	} else if (handle->non_null == 0 && text != ciphertext) /* NULL cipher - no MAC */
		memcpy(ciphertext, text, textlen);

	return 0;
}
Esempio n. 24
0
/*!
 
  \brief  do an appropriate attenuation on the side channel of a stereo
          signal
 
  \return nothing
 
****************************************************************************/
void ApplyStereoPreProcess(HANDLE_STEREO_PREPRO hStPrePro, /*!st.-preproc handle */
                           int                 nChannels, /*! total number of channels */              
                           ELEMENT_INFO        *elemInfo,
                           float *timeData,     /*! lr time data (modified) */
                           int granuleLen) /*! num. samples to be processed */
{
  /* inplace operation on inData ! */

  float SMRatio, StoM;
  float LRRatio, LtoR, deltaLtoR, deltaNrg;
  float EnImpact, PeImpact, PeNorm;
  float Att, AttAimed;
  float maxInc, maxDec, swiftfactor;
  float DELTA=0.1f;
  
  float fac = hStPrePro->stereoAttFac;
  float mPart, upper, div;
  float lFac,rFac;

  int i;

  COUNT_sub_start("ApplyStereoPreProcess");

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

  INDIRECT(1); BRANCH(1);
  if (!hStPrePro->stereoAttenuationFlag) {
    COUNT_sub_end();
    return;
  }

  
  /* calc L/R ratio */
  INDIRECT(1); MULT(3); ADD(1);
  mPart = 2.0f * hStPrePro->avrgFreqEnergyM * (1.0f - fac*fac);

  INDIRECT(2); ADD(4); MULT(2); MAC(2);
  upper = hStPrePro->avrgFreqEnergyL * (1.0f+fac) + hStPrePro->avrgFreqEnergyR * (1.0f-fac) - mPart;
  div   = hStPrePro->avrgFreqEnergyR * (1.0f+fac) + hStPrePro->avrgFreqEnergyL * (1.0f-fac) - mPart;
  
  LOGIC(1); BRANCH(1);
  if (div == 0.0f || upper == 0.0f) {

    INDIRECT(1); MOVE(1);
    LtoR = hStPrePro->LRMax;
  }
  else {

    DIV(1); MISC(1);
    LRRatio = (float) fabs ( upper / div ) ;

    TRANS(1); MULT(1); MISC(1);
    LtoR = (float) fabs(10.0 * log10(LRRatio));
  }
  

  /* calc delta energy to previous frame */
  INDIRECT(3); ADD(3); DIV(1);
  deltaNrg = ( hStPrePro->avrgFreqEnergyL + hStPrePro->avrgFreqEnergyR + 1.0f) / 
             ( hStPrePro->lastNrgLR + 1.0f );

  TRANS(1); MULT(1); MISC(1);
  deltaNrg = (float) (fabs(10.0 * log10(deltaNrg)));
  
  

  /* Smooth S/M over time */
  INDIRECT(2); ADD(2); DIV(1);
  SMRatio = (hStPrePro->avrgFreqEnergyS + 1.0f) / (hStPrePro->avrgFreqEnergyM + 1.0f);

  TRANS(1); MULT(1);
  StoM = (float) (10.0 * log10(SMRatio));

  INDIRECT(2); MULT(1); MAC(1); STORE(1);
  hStPrePro->avgStoM = DELTA * StoM + (1-DELTA) * hStPrePro->avgStoM;
  
  

  MOVE(1);
  EnImpact = 1.0f;
  
  INDIRECT(2); ADD(1); BRANCH(1);
  if (hStPrePro->avgStoM > hStPrePro->SMMin) {

    INDIRECT(1); ADD(1); BRANCH(1);
    if (hStPrePro->avgStoM > hStPrePro->SMMax) {

      MOVE(1);
      EnImpact = 0.0f;
    }
    else {

      ADD(2); DIV(1);
      EnImpact = (hStPrePro->SMMax - hStPrePro->avgStoM) / (hStPrePro->SMMax - hStPrePro->SMMin);
    }
  }
  
  INDIRECT(1); ADD(1); BRANCH(1);
  if (LtoR > hStPrePro->LRMin) {

    INDIRECT(1); ADD(1); BRANCH(1);
    if ( LtoR > hStPrePro->LRMax) {

      MOVE(1);
      EnImpact = 0.0f;
    }
    else {

      ADD(2); DIV(1); MULT(1);
      EnImpact *= (hStPrePro->LRMax - LtoR) / (hStPrePro->LRMax - hStPrePro->LRMin);
    }
  }
  
  
  MOVE(1);
  PeImpact = 0.0f;
  
  INDIRECT(2); MULT(1);
  PeNorm = hStPrePro->smoothedPeSumSum * hStPrePro->normPeFac;
  
  INDIRECT(1); ADD(1); BRANCH(1);
  if ( PeNorm > hStPrePro->PeMin )  {

    INDIRECT(1); ADD(2); DIV(1);
    PeImpact= ((PeNorm - hStPrePro->PeMin) / (hStPrePro->PeCrit - hStPrePro->PeMin));
  }
  
  INDIRECT(1); ADD(1); BRANCH(1);
  if (PeImpact > hStPrePro->PeImpactMax) {

    MOVE(1);
    PeImpact = hStPrePro->PeImpactMax;
  }
  
  
  INDIRECT(1); MULT(2);
  AttAimed = EnImpact * PeImpact * hStPrePro->ImpactFactor;
  
  
  INDIRECT(1); ADD(1); BRANCH(1);
  if (AttAimed > hStPrePro->stereoAttMax) {

    MOVE(1);
    AttAimed = hStPrePro->stereoAttMax;
  }
  
  /* only accept changes if they are large enough */

  INDIRECT(1); ADD(2); MISC(1); LOGIC(1); BRANCH(1);
  if ( fabs(AttAimed - hStPrePro->stereoAttenuation) < 1.0f && AttAimed != 0.0f) {

    MOVE(1);
    AttAimed = hStPrePro->stereoAttenuation;
  }
  
  MOVE(1);
  Att = AttAimed;


  INDIRECT(1); ADD(1); MULT(1); BRANCH(1); /* max() */ ADD(2); DIV(1); MULT(1);
  swiftfactor = (6.0f + hStPrePro->stereoAttenuation) / (10.0f + LtoR) * max(1.0f, 0.2f * deltaNrg );
  
  INDIRECT(1); ADD(2); BRANCH(1); MOVE(1);
  deltaLtoR = max(3.0f, LtoR - hStPrePro->lastLtoR );
  
  MULT(2); DIV(1);
  maxDec = deltaLtoR * deltaLtoR / 9.0f * swiftfactor;
  
  ADD(1); BRANCH(1); MOVE(1);
  maxDec = min( maxDec, 5.0f );
  
  INDIRECT(1); MULT(1);
  maxDec *= hStPrePro->stereoAttenuationDec;
  
  
  INDIRECT(1); MULT(1); ADD(1); BRANCH(1);
  if (maxDec > hStPrePro->stereoAttenuation * 0.8f) {
    
    MOVE(1);
    maxDec = hStPrePro->stereoAttenuation * 0.8f;
  }
  
  INDIRECT(1); ADD(2); BRANCH(1); MOVE(1);
  deltaLtoR = max(3.0f, hStPrePro->lastLtoR - LtoR );
  
  MULT(2); DIV(1);
  maxInc = deltaLtoR * deltaLtoR / 9.0f * swiftfactor;
  
  ADD(1); BRANCH(1); MOVE(1);
  maxInc = min( maxInc, 5.0f );
  
  INDIRECT(1); MULT(1);
  maxInc *= hStPrePro->stereoAttenuationInc;
  
  
  INDIRECT(1); MULT(1); ADD(1); BRANCH(1);
  if (maxDec > hStPrePro->stereoAttenuation * 0.8f) {
    
    MOVE(1);
    maxDec = hStPrePro->stereoAttenuation * 0.8f;
  }
  
  INDIRECT(1); ADD(2); BRANCH(1); MOVE(1);
  deltaLtoR = max(3.0f, hStPrePro->lastLtoR - LtoR );
  
  MULT(2); DIV(1);
  maxInc = deltaLtoR * deltaLtoR / 9.0f * swiftfactor;
  
  ADD(1); BRANCH(1); MOVE(1);
  maxInc = min( maxInc, 5.0f );
  
  INDIRECT(1); MULT(1);
  maxInc *= hStPrePro->stereoAttenuationInc;
  
  
  INDIRECT(1); ADD(2); BRANCH(1);
  if (Att > hStPrePro->stereoAttenuation + maxInc) {

    MOVE(1);
    Att = hStPrePro->stereoAttenuation + maxInc;
  }

  INDIRECT(1); ADD(2); BRANCH(1);
  if (Att < hStPrePro->stereoAttenuation - maxDec) {

    MOVE(1);
    Att = hStPrePro->stereoAttenuation - maxDec;
  }
  
  INDIRECT(2); BRANCH(1); MOVE(1);
  if (hStPrePro->ConstAtt == 0) hStPrePro->stereoAttenuation = Att;
  else                          hStPrePro->stereoAttenuation = hStPrePro->ConstAtt;
  

  /* perform attenuation of Side Channel */
  
  INDIRECT(2); MULT(1); TRANS(1); STORE(1);
  hStPrePro->stereoAttFac = (float) pow(10.0f, 0.05f*(-hStPrePro->stereoAttenuation ));
  
  INDIRECT(1); ADD(2); MULT(2);
  lFac = 0.5f * (1.0f + hStPrePro->stereoAttFac);
  rFac = 0.5f * (1.0f - hStPrePro->stereoAttFac);
  
  PTR_INIT(2); /* pointer for timeData[nChannels * i + elemInfo->ChannelIndex[0]], 
                              timeData[nChannels * i + elemInfo->ChannelIndex[1]]
               */
  LOOP(1);
  for (i = 0; i < granuleLen; i++){
    float L = lFac * timeData[nChannels * i+elemInfo->ChannelIndex[0]] + rFac * timeData[nChannels * i + elemInfo->ChannelIndex[1]];
    float R = rFac * timeData[nChannels * i+elemInfo->ChannelIndex[0]] + lFac * timeData[nChannels * i + elemInfo->ChannelIndex[1]];

    MULT(2); MAC(2); /* counting operations above */
    
    MOVE(2);
    timeData[nChannels * i + elemInfo->ChannelIndex[0]]= L;
    timeData[nChannels * i + elemInfo->ChannelIndex[1]]= R;
  }
  
  INDIRECT(1); MOVE(1);
  hStPrePro->lastLtoR = LtoR;

  INDIRECT(3); ADD(1); STORE(1);
  hStPrePro->lastNrgLR = hStPrePro->avrgFreqEnergyL + hStPrePro->avrgFreqEnergyR;
  
  COUNT_sub_end();
}
Esempio n. 25
0
File: cmac.c Progetto: bk2204/drew
int cmack_init(drew_kdf_t *ctx, int flags, DrewLoader *ldr,
		const drew_param_t *param)
{
	return cmac_init(MAC(ctx), flags, ldr, param);
}
Esempio n. 26
0
static void adjustPeMinMax(const float currPe,
                           float      *peMin,
                           float      *peMax)
{
  float minFacHi = 0.3f, maxFacHi = 1.0f, minFacLo = 0.14f, maxFacLo = 0.07f;
  float diff;
  float minDiff = currPe * (float)0.1666666667f;

  COUNT_sub_start("adjustPeMinMax");

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

  ADD(1); BRANCH(1);
  if (currPe > *peMax) {

     ADD(1);
     diff = (currPe-*peMax) ;

     MAC(2); STORE(2);
     *peMin += diff * minFacHi;
     *peMax += diff * maxFacHi;

  } else {

    ADD(1); BRANCH(1);
    if (currPe < *peMin) {

     ADD(1);
     diff = (*peMin-currPe) ;

     MAC(2); STORE(2);
     *peMin -= diff * minFacLo;
     *peMax -= diff * maxFacLo;
  } else {

     ADD(1); MAC(1); STORE(1);
     *peMin += (currPe - *peMin) * minFacHi;

     ADD(2); MULT(1); STORE(1);
     *peMax -= (*peMax - currPe) * maxFacLo;
  }
  }

  ADD(2); BRANCH(1);
  if ((*peMax - *peMin) < minDiff) {
     float partLo, partHi;

     ADD(2); BRANCH(1); MOVE(1);
     partLo = max((float)0.0f, currPe - *peMin);

     ADD(2); BRANCH(1); MOVE(1);
     partHi = max((float)0.0f, *peMax - currPe);

     ADD(2 * 2); DIV(2); MULT(2); STORE(2);
     *peMax = currPe + partHi/(partLo+partHi) * minDiff;
     *peMin = currPe - partLo/(partLo+partHi) * minDiff;

     ADD(1); BRANCH(1); MOVE(1);
     *peMin = max((float)0.0f, *peMin);
  }

  COUNT_sub_end();
}
Esempio n. 27
0
void *get_pos(void *arg)
{
	struct timeval ti;

	int ret;
	struct ap_t *ap;
	int i, j, k, num = 0;
	long interval;
	struct point_t *pi = NULL;
	double a,b;

replay:
	for(i = 0; i < MAX_CLI; i++) {
		if(clihead[i].key == IDLE_CLI)
			continue;

		now(&ti);
		if((ti.tv_sec - clihead[i].timestamp.tv_sec) > 
			argument.losttime) {
			cli_del(&clihead[i]);
			continue;
		}

		pthread_mutex_lock(&clihead[i].lock);
		if(clihead[i].key == IDLE_CLI)
			goto unlock;

		clr_bit(&clihead[i].bitmap);
		num = 0;

		for(j = 0; j < MAX_AP; j++) {
			ap = &clihead[i].ap[j];
			interval = ti.tv_sec - ap->timestamp.tv_sec;

			if((ap->valid) && (interval < argument.agetime)) {
				num++;
				set_bit(&clihead[i].bitmap, j);
			}
		}

		if(num < 3) goto unlock;

		pi = malloc(sizeof(struct point_t) * num);
		if(pi == NULL) {
			sys_warn("Malloc memory failed: %s\n",
				strerror(errno));
			continue;
		}

		for(j = 0, k = 0; j < MAX_AP && k < num; j++) {
			if(isset(&clihead[i].bitmap, j)) {
				ret = getap_pos(clihead[i].ap[j].apmac, pi + k);
				if(ret < 0) goto free;
				pi[k].d = distance(clihead[i].ap[j].signal);
				mac_debug(MAC(clihead[i].climac), 
					"(%lf, %lf, %lf) sig: %d dist: %lf\n", 
					pi[k].x, pi[k].y, pi[k].z,
					clihead[i].ap[j].signal, pi[k].d);
				k++;
			}
		}

		ret = get_point(pi, num, &a, &b);
		if(ret < 0 || a < 0 || b < 0) goto free;
		ajust_pos(&clihead[i], &ti, &a, &b);
		mac_debug(MAC(clihead[i].climac), "%lf %lf %lf\n", a, b, pi->z);
#ifndef DISABLE_MYSQL
		sql_insert(&sql, clihead[i].climac, a, b, pi->z);
#endif
free:
		free(pi);
unlock:
		pthread_mutex_unlock(&clihead[i].lock);
	}
	sleep(2);
	goto replay;
	return NULL;
}
Esempio n. 28
0
void
groupShortData(float         *mdctSpectrum,
               float         *tmpSpectrum,
               SFB_THRESHOLD *sfbThreshold,
               SFB_ENERGY    *sfbEnergy,
               SFB_ENERGY    *sfbEnergyMS,
               SFB_ENERGY    *sfbSpreadedEnergy,
               const int      sfbCnt,
               const int     *sfbOffset,
               const float *sfbMinSnr,
               int           *groupedSfbOffset,
               int           *maxSfbPerGroup,
               float       *groupedSfbMinSnr,
               const int     noOfGroups,
               const int     *groupLen)
{
  int i,j;
  int line;
  int sfb;
  int grp;
  int wnd;
  int offset;
  int highestSfb;

  FLC_sub_start("groupShortData");



  /* for short: regroup and  */
  /* cumulate energies und thresholds group-wise . */
 
  
    /* calculate sfbCnt */
    MOVE(1);
    highestSfb = 0;

    LOOP(1);
    for (wnd = 0; wnd < TRANS_FAC; wnd++)
    {
      PTR_INIT(1); /* sfbOffset[] */
      LOOP(1);
      for (sfb = sfbCnt-1; sfb >= highestSfb; sfb--)
      {
        PTR_INIT(1); /* mdctSpectrum[] */
        LOOP(1);
        for (line = sfbOffset[sfb+1]-1; line >= sfbOffset[sfb]; line--)
        {
          BRANCH(1);
          if (mdctSpectrum[wnd*FRAME_LEN_SHORT+line] != 0.0) break;  // this band is not completely zero
        }
        ADD(1); BRANCH(1);
        if (line >= sfbOffset[sfb]) break; // this band was not completely zero
      }
      ADD(1); BRANCH(1); MOVE(1);
      highestSfb = max(highestSfb, sfb);
    }
    BRANCH(1); MOVE(1);
    highestSfb = highestSfb > 0 ? highestSfb : 0;

    ADD(1); STORE(1);
    *maxSfbPerGroup = highestSfb+1;

  /* calculate sfbOffset */
  MOVE(2);
  i = 0;
  offset = 0;

  PTR_INIT(2); /* groupedSfbOffset[]
                  groupLen[]
               */
  LOOP(1);
  for (grp = 0; grp < noOfGroups; grp++)
  {
    PTR_INIT(1); /* sfbOffset[] */
    LOOP(1);
    for (sfb = 0; sfb < sfbCnt; sfb++)
    {
      MULT(1); ADD(1); STORE(1);
      groupedSfbOffset[i++] = offset + sfbOffset[sfb] * groupLen[grp];
    }

    MAC(1);
    offset += groupLen[grp] * FRAME_LEN_SHORT;
  }
  MOVE(1);
  groupedSfbOffset[i++] = FRAME_LEN_LONG;

   /* calculate minSnr */

  MOVE(2);
  i = 0;
  offset = 0;

  PTR_INIT(1); /* groupedSfbMinSnr[] */
  for (grp = 0; grp < noOfGroups; grp++)
  {
    PTR_INIT(1); /* sfbMinSnr[] */
    LOOP(1);
    for (sfb = 0; sfb < sfbCnt; sfb++)
    {
      MOVE(1);
      groupedSfbMinSnr[i++] = sfbMinSnr[sfb];
    }

    MAC(1);
    offset += groupLen[grp] * FRAME_LEN_SHORT;
  }



  /* sum up sfbThresholds */
  MOVE(2);
  wnd = 0;
  i = 0;

  PTR_INIT(2); /* groupLen[]
                  sfbThreshold->Long[]
               */
  LOOP(1);
  for (grp = 0; grp < noOfGroups; grp++)
  {
    PTR_INIT(1); /* sfbThreshold->Short[][] */
    LOOP(1);
    for (sfb = 0; sfb < sfbCnt; sfb++)
    {
      float thresh = sfbThreshold->Short[wnd][sfb];

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

      LOOP(1);
      for (j=1; j<groupLen[grp]; j++)
      {
        ADD(1);
        thresh += sfbThreshold->Short[wnd+j][sfb];
      }

      MOVE(1);
      sfbThreshold->Long[i++] = thresh;
    }
    wnd += groupLen[grp];
  }

  /* sum up sfbEnergies left/right */
  MOVE(2);
  wnd = 0;
  i = 0;

  PTR_INIT(2); /* groupLen[]
                  sfbEnergy->Long[]
               */
  LOOP(1);
  for (grp = 0; grp < noOfGroups; grp++)
  {
    PTR_INIT(1); /* sfbEnergy->Short[][] */
    LOOP(1);
    for (sfb = 0; sfb < sfbCnt; sfb++)
    {
      float energy = sfbEnergy->Short[wnd][sfb];

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

      LOOP(1);
      for (j=1; j<groupLen[grp]; j++)
      {
        ADD(1);
        energy += sfbEnergy->Short[wnd+j][sfb];
      }
      MOVE(1);
      sfbEnergy->Long[i++] = energy;
    }
    wnd += groupLen[grp];
  }

  /* sum up sfbEnergies mid/side */
  MOVE(1);
  wnd = 0;
  i = 0;

  PTR_INIT(2); /* groupLen[]
                  sfbEnergy->Long[]
               */
  LOOP(1);
  for (grp = 0; grp < noOfGroups; grp++)
  {
    PTR_INIT(1); /* sfbEnergy->Short[][] */
    LOOP(1);
    for (sfb = 0; sfb < sfbCnt; sfb++)
    {
      float energy = sfbEnergyMS->Short[wnd][sfb];

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

      LOOP(1);
      for (j=1; j<groupLen[grp]; j++)
      {
        ADD(1);
        energy += sfbEnergyMS->Short[wnd+j][sfb];
      }
      MOVE(1);
      sfbEnergyMS->Long[i++] = energy;
    }
    wnd += groupLen[grp];
  }

  /* sum up sfbSpreadedEnergies */
  MOVE(2);
  wnd = 0;
  i = 0;

  PTR_INIT(2); /* groupLen[]
                  sfbEnergy->Long[]
               */
  LOOP(1);
  for (grp = 0; grp < noOfGroups; grp++)
  {
     PTR_INIT(1); /* sfbEnergy->Short[][] */
     LOOP(1);
     for (sfb = 0; sfb < sfbCnt; sfb++)
     {
        float energy = sfbSpreadedEnergy->Short[wnd][sfb];

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

        LOOP(1);
        for (j=1; j<groupLen[grp]; j++)
        {
           ADD(1);
           energy += sfbSpreadedEnergy->Short[wnd+j][sfb];
        }
        MOVE(1);
        sfbSpreadedEnergy->Long[i++] = energy;
     }
     wnd += groupLen[grp];
  }

  /* re-group spectrum */
    MOVE(2);
    wnd = 0;
    i = 0;

    PTR_INIT(2); /* groupLen[]
                    tmpSpectrum[]
                 */
    LOOP(1);
    for (grp = 0; grp < noOfGroups; grp++)
    {
      PTR_INIT(1); /* sfbOffset[] */
      LOOP(1);
      for (sfb = 0; sfb < sfbCnt; sfb++)
      {
        LOOP(1);
        for (j = 0; j < groupLen[grp]; j++)
        {
          PTR_INIT(1); /* mdctSpectrum[] */
          LOOP(1);
          for (line = sfbOffset[sfb]; line < sfbOffset[sfb+1]; line++)
          {
            MOVE(1);
            tmpSpectrum[i++] = mdctSpectrum[(wnd+j)*FRAME_LEN_SHORT+line];
          }
        }
      }
     wnd += groupLen[grp];
  }

  PTR_INIT(2); /* mdctSpectrum[]
                  tmpSpectrum[]
               */
  LOOP(1);
  for(i=0;i<FRAME_LEN_LONG;i++)
  {
    MOVE(1);
    mdctSpectrum[i]=tmpSpectrum[i];
  }

  FLC_sub_end();
}
Esempio n. 29
0
int
IIR32Resample( float *inbuf,
               float *outbuf,
               int    inSamples,
               int    outSamples,
               int    stride)
{
  int i, k, s, ch, r;
  double accu;
  float  scratch[IIR_INTERNAL_BUFSIZE];
  int nProcessRuns  = outSamples  >> 1;

  COUNT_sub_start("IIR32Resample");

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

  assert( stride <= IIR_CHANNELS);

  LOOP(1);
  for (ch=0; ch<stride; ch++) {
    int idxIn  = ch;
    int idxOut = ch;

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

    PTR_INIT(2); /* scratch[s]
                    statesIIR[s*stride+ch]
                 */
    LOOP(1);
    for (s=0; s<IIR_32_ORDER; s++) {

      MOVE(1);
      scratch[s] = statesIIR[s*stride+ch];
    }

    LOOP(1);
    for (r=0; r<nProcessRuns; r++) {

      PTR_INIT(1); /* scratch[s] */
      MOVE(1);
      s=IIR_32_ORDER;

      PTR_INIT(2); /* inbuf[idxIn] 
                      outbuf[idxOut]
                   */
      LOOP(1);
      for (i=0; i<IIR_DOWNSAMPLE_FAC; i++) {

        MOVE(1);
        accu = inbuf[idxIn];

        PTR_INIT(2); /* coeffDen[k]
                        scratch[s-k]
                     */
        LOOP(1);
        for (k=1; k<IIR_32_ORDER; k++) {
          MAC(1);
          accu += coeffDen[k] * scratch[s-k];
        }

        MOVE(1);
        scratch[s] = (float) accu;

        s++;

        assert( s<=IIR_INTERNAL_BUFSIZE);

        MOVE(1);
        accu = 0.0;

        PTR_INIT(2); /* coeffDen[k]
                        scratch[s-k]
                     */
        LOOP(1);
        for (k=1; k<IIR_32_ORDER; k++) {

          MAC(1);
          accu += coeffDen[k] * scratch[s-k];
        }

        MOVE(1);
        scratch[s] = (float) accu;

        s++;

        idxIn += stride;

      }

      PTR_INIT(1); /* scratch[s] */
      MOVE(1);
      s = IIR_32_ORDER;

      LOOP(1);
      for (i=0; i<IIR_UPSAMPLE_FAC; i++) {

        MULT(1);
        accu = coeffNum[0] * scratch[s];

        PTR_INIT(2); /* coeffNum[k]
                        scratch[s-k]
                     */
        LOOP(1);
        for (k=1; k<IIR_32_ORDER; k++) {

          MAC(1);
          accu += coeffNum[k] * scratch[s-k];
        }

        MOVE(1);
        outbuf[idxOut] = (float) accu;

        assert( s<=IIR_INTERNAL_BUFSIZE);

        s += IIR_DOWNSAMPLE_FAC;

        idxOut += stride;

      }

      FUNC(2); LOOP(1); PTR_INIT(2); MOVE(1); STORE(IIR_32_ORDER);
      memmove( &scratch[0], &scratch[IIR_UPSAMPLE_FAC*IIR_DOWNSAMPLE_FAC], IIR_32_ORDER*sizeof(float));

    }

    PTR_INIT(2); /* statesIIR[s*stride+ch]
                    scratch[s]
                 */
    LOOP(1);
    for (s=0; s<IIR_32_ORDER; s++) {

      MOVE(1);
      statesIIR[s*stride+ch] = scratch[s];
    }

    assert(idxIn/stride <= inSamples);

  } /* ch */

  MULT(1); /* counting post-operation */

  COUNT_sub_end();
  
  return outSamples * stride;
}
Esempio n. 30
0
int user1_init_primitives(FTYPE (*prim)[NSTORE2][NSTORE3][NPR], FTYPE (*pstag)[NSTORE2][NSTORE3][NPR], FTYPE (*ucons)[NSTORE2][NSTORE3][NPR], FTYPE (*vpot)[NSTORE1+SHIFTSTORE1][NSTORE2+SHIFTSTORE2][NSTORE3+SHIFTSTORE3], FTYPE (*Bhat)[NSTORE2][NSTORE3][NPR], FTYPE (*panalytic)[NSTORE2][NSTORE3][NPR], FTYPE (*pstaganalytic)[NSTORE2][NSTORE3][NPR], FTYPE (*vpotanalytic)[NSTORE1+SHIFTSTORE1][NSTORE2+SHIFTSTORE2][NSTORE3+SHIFTSTORE3], FTYPE (*Bhatanalytic)[NSTORE2][NSTORE3][NPR],
			  FTYPE (*F1)[NSTORE2][NSTORE3][NPR],FTYPE (*F2)[NSTORE2][NSTORE3][NPR],FTYPE (*F3)[NSTORE2][NSTORE3][NPR], FTYPE (*Atemp)[NSTORE1+SHIFTSTORE1][NSTORE2+SHIFTSTORE2][NSTORE3+SHIFTSTORE3])
{
  int whichvel, whichcoord;
  int initreturn;
  int i = 0, j = 0, k = 0, l;
  FTYPE r,th,X[NDIM],V[NDIM];
  int normalize_densities(FTYPE (*prim)[NSTORE2][NSTORE3][NPR]);
  int normalize_field(FTYPE (*prim)[NSTORE2][NSTORE3][NPR], FTYPE (*pstag)[NSTORE2][NSTORE3][NPR], FTYPE (*ucons)[NSTORE2][NSTORE3][NPR], FTYPE (*vpot)[NSTORE1+SHIFTSTORE1][NSTORE2+SHIFTSTORE2][NSTORE3+SHIFTSTORE3], FTYPE (*Bhat)[NSTORE2][NSTORE3][NPR]);
  int init_dsandvels(int *whichvel, int *whichcoord, int i, int j, int k, FTYPE *p, FTYPE *pstag);
  int init_atmosphere(int *whichvel, int *whichcoord, int i, int j, int k, FTYPE *pr);
  int pl,pliter;


  ///////////////////////////////////
  //
  // Assign primitive variables
  //
  ///////////////////////////////////
  trifprintf("Assign primitives\n");

  // assume we start in bl coords and convert to KSprim
  // so field defined when get to floor model (fixup)
  init_3dnpr_fullloop(0.0,prim);



  //////////////////////
  //
  // assume we start in bl coords and convert to KSprim
  //
  //////////////////////
#pragma omp parallel private(i,j,k,initreturn,whichvel,whichcoord) OPENMPGLOBALPRIVATEFULL
  {
    OPENMP3DLOOPVARSDEFINE;
  ////////  COMPFULLLOOP{
    OPENMP3DLOOPSETUPFULL;
#pragma omp for schedule(OPENMPSCHEDULE(),OPENMPCHUNKSIZE(blocksize))
    OPENMP3DLOOPBLOCK{
      OPENMP3DLOOPBLOCK2IJK(i,j,k);

      initreturn=init_dsandvels(&whichvel, &whichcoord,i,j,k,MAC(prim,i,j,k),MAC(pstag,i,j,k)); // request densities for all computational centers
      if(initreturn>0){
	FAILSTATEMENT("init.c:init_primitives()", "init_dsandvels()", 1);
      }
      else MYFUN(transform_primitive_vB(whichvel, whichcoord, i,j,k, prim, pstag),"init.c:init_primitives","transform_primitive_vB()",0);
    }
  }// end parallel region


  /////////////////////////////
  //
  // normalize density if wanted
  //
  /////////////////////////////// 
  // at this point densities are still standard, so just send "prim"
  trifprintf("Normalize densities\n");
  normalize_densities(prim);




  /////////////////////////////
  //
  // Define an atmosphere if wanted
  //
  /////////////////////////////// 

  if(DOEVOLVERHO||DOEVOLVEUU){
    // normalized atmosphere
    trifprintf("Add atmosphere\n");

#pragma omp parallel private(i,j,k,initreturn,whichvel,whichcoord) OPENMPGLOBALPRIVATEFULL
    {
      OPENMP3DLOOPVARSDEFINE;
      ///////  COMPZLOOP {
      OPENMP3DLOOPSETUPZLOOP;
#pragma omp for schedule(OPENMPSCHEDULE(),OPENMPCHUNKSIZE(blocksize))
      OPENMP3DLOOPBLOCK{
	OPENMP3DLOOPBLOCK2IJK(i,j,k);

	initreturn=init_atmosphere(&whichvel, &whichcoord,i,j,k,MAC(prim,i,j,k));
	if(initreturn>0){
	  FAILSTATEMENT("init.c:init_primitives()", "init_atmosphere()", 1);
	}
	else{
	  // transform from whichcoord to MCOORD
	  if (bl2met2metp2v(whichvel, whichcoord,MAC(prim,i,j,k), i,j,k) >= 1){
	    FAILSTATEMENT("init.c:init()", "bl2ks2ksp2v()", 1);
	  }
	}
      }// end 3D LOOP
    }// end parallel region
  }