void QmitkFloatingPointSpanSlider::setMinimum(double min)
{
  //MITK_INFO << "QmitkFloatingPointSpanSlider new min: " << min;
  if (m_IntMode)
  {
    this->QxtSpanSlider::setMinimum(min);
    return;
  }

  if (min > m_Maximum)
  {
    m_Maximum = min;
  }
  m_Minimum = min;
  scaleSliderToInt();

  if (m_LowerValue < m_Minimum)
  {
    m_LowerValue = m_Minimum;
    this->QxtSpanSlider::setLowerValue(scaleValue(m_LowerValue));
  }
  if (m_UpperValue < m_Minimum)
  {
    m_UpperValue = m_Minimum;
    this->QxtSpanSlider::setUpperValue(scaleValue(m_UpperValue));
  }
}
Beispiel #2
0
void
Laber::UpdateTransform(bool updateChildren)
{
	float y, x = 0;

	if (center && base != nullptr) {
		float len = 0;
		for (unsigned int i = 0; i < controls.size(); i++)
			len += CharInfo[(unsigned char)text[i]].scale.x * fontSize;

		vec4 b = base->getBound(scaleValueType_absolute);
		x = (b.z - b.x) / 2 - len / 2;
	}

	for (auto i = controls.begin(); i != controls.end(); i++) {
		unsigned char c = (*i)->name[0];
		if (c == ' ')
			x += 20 * fontSize;
		else {
			vec2 s = CharInfo[c].scale * fontSize;
			y = CharInfo[c].offestY * fontSize;
			(*i)->Transform(scaleValue(scaleValueType_absolute, vec2(x, y)), scaleValue(scaleValueType_absolute, s));
			(*i)->colorMult = colorMult;

			x += s.x;
		}
	}
}
void QmitkFloatingPointSpanSlider::scaleSliderToInt()
{
  int tmpLower = unscaleValue(m_LowerValue);
  int tmpUpper = unscaleValue(m_UpperValue);

  double range = m_Maximum - m_Minimum;
  factor = range ? 1000.0 / range : 0;
  offset = -m_Minimum;

  //MITK_INFO << "New offset: " << offset << ", scale: " << factor;

  m_LowerValue = scaleValue(tmpLower);
  m_UpperValue = scaleValue(tmpUpper);
}
Beispiel #4
0
void decodepacket() {

	rx_fp_lowpassfilter(&global.rxvalues[ROLLINDEX],
			scaleValue(packet[5] + 256 * packet[6],0)
			/*((fixedpointnum) word_temp )*/, global.timesliver, 0L, 0);
	rx_fp_lowpassfilter(&global.rxvalues[PITCHINDEX],
			scaleValue(packet[7] + 256 * packet[8], 0)
			/*((fixedpointnum) word_temp )*/, global.timesliver, 0L, 0);
	rx_fp_lowpassfilter(&global.rxvalues[THROTTLEINDEX],
			scaleValue(packet[9] + 256 * packet[10], 0)
			/*((fixedpointnum) word_temp )*/, global.timesliver, 0L, 0);
	rx_fp_lowpassfilter(&global.rxvalues[YAWINDEX],
			scaleValue(packet[11] + 256 * packet[12], 1000)
			/*((fixedpointnum) word_temp )*/, global.timesliver, 0L, 0);
	rx_fp_lowpassfilter(&global.rxvalues[AUX1INDEX],
			scaleValue(packet[13] + 256 * packet[14], 0)
			/*((fixedpointnum) word_temp )*/, global.timesliver, 0L, 0);
	rx_fp_lowpassfilter(&global.rxvalues[AUX2INDEX],
			scaleValue(packet[15] + 256 * packet[16], 0)
			/*((fixedpointnum) word_temp )*/, global.timesliver, 0L, 0);
	rx_fp_lowpassfilter(&global.rxvalues[AUX3INDEX],
			scaleValue(packet[17] + 256 * packet[18], 0)
			/*((fixedpointnum) word_temp )*/, global.timesliver, 0L, 0);
	rx_fp_lowpassfilter(&global.rxvalues[AUX4INDEX],
			scaleValue(packet[19] + 256 * packet[20], 0)
			/*((fixedpointnum) word_temp )*/, global.timesliver, 0L, 0);
}
float DriveControl::adjustDeadband(float value) {
	if (isDead(value)) {
		return 0.0;
	} else {
		return scaleValue(value, DeadbandWidth);
	}
}
Beispiel #6
0
void PhyxCompoundUnit::compoundSimplify(int index)
{
    PhyxUnit *unit = m_compounds.at(index).unit;
    PhyxFloatDataType power = m_compounds.at(index).power;
    //qDebug() << static_cast<double>(power) << unit->symbol() << static_cast<double>(unit->scaleFactor()) << static_cast<double>(unit->offset()) << index;

    emit scaleValue(pow(unit->scaleFactor(), power));
    emit offsetValue(-unit->offset());

    if (power == PHYX_FLOAT_NULL)  //if unit is 1 remove it
    {
        m_compounds[index].power = PHYX_FLOAT_NULL;
    }
    else
    {

        PhyxUnit *tmpUnit = new PhyxUnit();
        copyUnit(unit,tmpUnit);
        tmpUnit->setOffset(PHYX_FLOAT_NULL);
        tmpUnit->setScaleFactor(PHYX_FLOAT_ONE);
        PhyxUnit *newUnit = m_unitSystem->verifyUnit(tmpUnit);
        if (newUnit != NULL)
        {
            compoundDivide(unit, power);    //remove old unit
            compoundMultiply(newUnit, PHYX_FLOAT_ONE); //add new unit
        }
        else
        {
            compoundStrip(index);             //strip compound
        }
        tmpUnit->deleteLater();
    }
}
void QmitkFloatingPointSpanSlider::setSpan(double lower, double upper)
{
  //MITK_INFO << "QmitkFloatingPointSpanSlider new span: " << lower << " - " << upper;
  m_LowerValue = lower;
  m_UpperValue = upper;
  if (m_IntMode)
  {
    this->QxtSpanSlider::setLowerValue(lower);
    this->QxtSpanSlider::setUpperValue(upper);
  }
  else
  {
    this->QxtSpanSlider::setLowerValue(scaleValue(lower));
    this->QxtSpanSlider::setUpperValue(scaleValue(upper));
    emit spanChanged(lower, upper);
  }
}
unsigned short qtractorMidiControlObserver::midiValue (void) const
{
	const unsigned short iScale = midiScale();
	unsigned short iValue = float(iScale) * scaleValue();
	if (iValue > iScale)
		iValue = iScale;
	return (m_bInvert ? iScale - iValue : iValue);
}
Beispiel #9
0
void Zoa_WS2801::initialize()
{
  scaled = true;
  for ( uint16_t i = 0; i < 256; ++i )
  {
    scaledValues[i] = scaleValue(i);
  }
}
Beispiel #10
0
void adc_main(void){
#else
void main(void){
#endif
   JOYSTICK_DIRECTION joystickDirection = CENTRED;
   INT8 adc_value;
   UINT8 potVoltage = 0;
   BOOL updateLCD = TRUE;

   initAdc();

   while( !stopApplication() ){
      ADC_ENABLE_CHANNEL(7);
      ADC_SINGLE_CONVERSION(ADC_REF_AVDD | ADC_8_BIT | ADC_AIN7);
      ADC_SAMPLE_SINGLE();

      while(!ADC_SAMPLE_READY());

      ADC_DISABLE_CHANNEL(7);

      adc_value = ADCH;

      if (potVoltage != scaleValue(adc_value)){
         //potVoltage changed since last sample
         potVoltage = scaleValue(adc_value);
         updateLCD = TRUE;
      }

      if (joystickDirection != getJoystickDirection()){
         //joystickDirection change since last sample
         joystickDirection = getJoystickDirection();
         updateLCD = TRUE;
      }

      if (updateLCD){
         updateVoltageLCD(potVoltage, adc_value);
         updateJoystickDirectionLCD(joystickDirection);
         updateLCD = FALSE;
      }
      updateCounter(adc_value);
   }

   LED1 = LED3 = LED_OFF;
   return;
}
void QmitkFloatingPointSpanSlider::setRange(double min, double max)
{
  if (m_IntMode)
  {
    this->QxtSpanSlider::setRange(min, max);
    m_Minimum = minimum();
    m_Maximum = maximum();
    m_LowerValue = lowerValue();
    m_UpperValue = upperValue();
    return;
  }

  if (min > max)
  {
    min = max;
  }
  m_Minimum = min;
  m_Maximum = max;

  if (m_LowerValue > m_Maximum)
  {
    m_LowerValue = m_Maximum;
    this->QxtSpanSlider::setLowerValue(scaleValue(m_LowerValue));
  }
  else if (m_LowerValue < m_Minimum)
  {
    m_LowerValue = m_Minimum;
    this->QxtSpanSlider::setLowerValue(scaleValue(m_LowerValue));
  }

  if (m_UpperValue > m_Maximum)
  {
    m_UpperValue = m_Maximum;
    this->QxtSpanSlider::setUpperValue(scaleValue(m_UpperValue));
  }
  else if (m_UpperValue < m_Minimum)
  {
    m_UpperValue = m_Minimum;
    this->QxtSpanSlider::setUpperValue(scaleValue(m_UpperValue));
  }

  scaleSliderToInt();
}
Beispiel #12
0
bool ProjectileData::setFadeDelay( void *obj, const char *index, const char *data )
{
	S32 value = dAtoi(data);
   value = scaleValue(value);

   ProjectileData *object = static_cast<ProjectileData*>(obj);
   object->fadeDelay = value;

   return false;
}
Beispiel #13
0
bool ProjectileData::setLifetime( void *obj, const char *data )
{
	S32 value = dAtoi(data);
   value = scaleValue(value);
   
   ProjectileData *object = static_cast<ProjectileData*>(obj);
   object->lifetime = value;

   return false;
}
Beispiel #14
0
const char *ProjectileData::getScaledValue( void *obj, const char *data)
{

	S32 value = dAtoi(data);
   value = scaleValue(value, false);

   String stringData = String::ToString(value);
   char *strBuffer = Con::getReturnBuffer(stringData.size());
   dMemcpy( strBuffer, stringData, stringData.size() );

   return strBuffer;
}
void QmitkFloatingPointSpanSlider::setLowerValue(double lower)
{
  m_LowerValue = lower;
  if (m_IntMode)
  {
    this->QxtSpanSlider::setLowerValue(lower);
  }
  else
  {
    this->QxtSpanSlider::setLowerValue(scaleValue(lower));
    emit lowerValueChanged(lower);
  }
}
void QmitkFloatingPointSpanSlider::setUpperValue(double upper)
{
  m_UpperValue = upper;
  if (m_IntMode)
  {
    this->QxtSpanSlider::setUpperValue(upper);
  }
  else
  {
    this->QxtSpanSlider::setUpperValue(scaleValue(upper));
    emit upperValueChanged(upper);
  }
}
Beispiel #17
0
void
dmz::QtCanvasView::set_scale (const qreal Value) {

   qreal scaleValue (Value ? Value : 1.0f);

   QMatrix transform (matrix ());

   transform.reset ();
   transform.scale (scaleValue, scaleValue);

   setMatrix (transform);

   emit scale_changed (scaleValue);
}
Beispiel #18
0
bool PhyxCompoundUnit::convertTo(PhyxCompoundUnit *unit)
{
    this->simplify();

    for (int i = 0; i < unit->compounds().size(); i++)
    {
        // make the inverse galilean transformation x = (y+b)/a
        offsetValue(unit->compounds().at(i).unit->offset());
        scaleValue(pow(unit->compounds().at(i).unit->scaleFactor(), -unit->compounds().at(i).power));
    }

    this->compoundsSetNull();
    this->compoundsMultiply(unit->compounds());

    return true;
}
Beispiel #19
0
/**
 * \brief Apply synthesis filter with zero input to x. The overall filter gain
 * is 1.0.
 * \param a LPC filter coefficients.
 * \param length length of the input/output data vector x.
 * \param x input/output vector, where the synthesis filter is applied in place.
 */
static void Syn_filt_zero(const FIXP_LPC a[], const INT a_exp, INT length,
                          FIXP_DBL x[]) {
  int i, j;
  FIXP_DBL L_tmp;

  for (i = 0; i < length; i++) {
    L_tmp = (FIXP_DBL)0;

    for (j = 0; j < fMin(i, M_LP_FILTER_ORDER); j++) {
      L_tmp -= fMultDiv2(a[j], x[i - (j + 1)]) >> (LP_FILTER_SCALE - 1);
    }

    L_tmp = scaleValue(L_tmp, a_exp + LP_FILTER_SCALE);
    x[i] = fAddSaturate(x[i], L_tmp);
  }
}
Beispiel #20
0
void Laber::setText(string text)
{
	this->text = text;
	for (int i = controls.size(); i > text.length(); i--)
		Detach(controls[i - 1], true);

	Control *c;
	for (int i = controls.size(); i < text.length(); i++) {
		c = new Control();
		c->texture = texture;
		c->Scale(scaleValue(scaleValueType_window, vec2(1, 1)));
		Attach(c);
	}

	for (int i = 0; i < text.length(); i++) {
		c = controls[i];
		c->name = string(" ");
		c->name[0] = text[i];
		c->uvbuffer = CharInfo[(unsigned char)text[i]].uv;
	}

	UpdateTransform(false);
}
Beispiel #21
0
Laber::Laber() : Control()
{
	texture = defaultTexture;
	Scale(scaleValue(scaleValueType_window, vec2(1, 1)));
	_rendable = false;
}
Beispiel #22
0
void Zoa_WS2801::scalingTest() {
  for ( byte i = 0; i < 256; ++i ) {
    Serial.println( "Original value: " + String(i) + ", scaled value: " + String( scaleValue(i) ) );
  }
}
Beispiel #23
0
void pvcDecodeTimeSlot(PVC_STATIC_DATA *pPvcStaticData,
                       PVC_DYNAMIC_DATA *pPvcDynamicData,
                       FIXP_DBL **qmfSlotReal, FIXP_DBL **qmfSlotImag,
                       const int qmfExponent, const int pvcBorder0,
                       const int timeSlotNumber, FIXP_DBL predictedEsgSlot[],
                       int *predictedEsg_exp) {
  int i, band, ksg, ksg_start = 0;
  int RATE = pPvcDynamicData->RATE;
  int Esg_index = pPvcStaticData->Esg_slot_index;
  const SCHAR *sg_borders = pPvcDynamicData->sg_offset_low;
  FIXP_DBL *pEsg = pPvcStaticData->Esg[Esg_index];
  FIXP_DBL E[PVC_NBLOW] = {0};

  /* Subband grouping in QMF subbands below SBR range */
  /* Within one timeslot ( i = [0...(RATE-1)] QMF subsamples) calculate energy
     E(ib,t) and group them to Esg(ksg,t). Then transfer values to logarithmical
     domain and store them for time domain smoothing. (7.5.6.3 Subband grouping
     in QMF subbands below SBR range)
  */
  for (ksg = 0; sg_borders[ksg] < 0; ksg++) {
    pEsg[ksg] = FL2FXCONST_DBL(-10.0 / (1 << PVC_ESG_EXP)); /* 10*log10(0.1) */
    ksg_start++;
  }

  for (i = 0; i < RATE; i++) {
    FIXP_DBL *qmfR, *qmfI;
    qmfR = qmfSlotReal[i];
    qmfI = qmfSlotImag[i];
    for (ksg = ksg_start; ksg < PVC_NBLOW; ksg++) {
      for (band = sg_borders[ksg]; band < sg_borders[ksg + 1]; band++) {
        /* The division by 8 == (RATE*lbw) is required algorithmically */
        E[ksg] += (fPow2Div2(qmfR[band]) + fPow2Div2(qmfI[band])) >> 2;
      }
    }
  }
  for (ksg = ksg_start; ksg < PVC_NBLOW; ksg++) {
    if (E[ksg] > (FIXP_DBL)0) {
      /* 10/log2(10) = 0.752574989159953 * 2^2 */
      int exp_log;
      FIXP_DBL nrg = CalcLog2(E[ksg], 2 * qmfExponent, &exp_log);
      nrg = fMult(nrg, FL2FXCONST_SGL(LOG10FAC));
      nrg = scaleValue(nrg, exp_log - PVC_ESG_EXP + 2);
      pEsg[ksg] = fMax(nrg, FL2FXCONST_DBL(-10.0 / (1 << PVC_ESG_EXP)));
    } else {
      pEsg[ksg] =
          FL2FXCONST_DBL(-10.0 / (1 << PVC_ESG_EXP)); /* 10*log10(0.1) */
    }
  }

  /* Time domain smoothing of subband-grouped energy */
  {
    int idx = pPvcStaticData->Esg_slot_index;
    FIXP_DBL *pEsg_filt;
    FIXP_SGL SCcoeff;

    E[0] = E[1] = E[2] = (FIXP_DBL)0;
    for (i = 0; i < pPvcDynamicData->ns; i++) {
      SCcoeff = pPvcDynamicData->pSCcoeffs[i];
      pEsg_filt = pPvcStaticData->Esg[idx];
      /* Div2 is compensated by scaling of coeff table */
      E[0] = fMultAddDiv2(E[0], pEsg_filt[0], SCcoeff);
      E[1] = fMultAddDiv2(E[1], pEsg_filt[1], SCcoeff);
      E[2] = fMultAddDiv2(E[2], pEsg_filt[2], SCcoeff);
      if (i >= pPvcDynamicData->pastEsgSlotsAvail) {
        /* if past Esg values are not available use the ones from the last valid
         * slot */
        continue;
      }
      if (idx > 0) {
        idx--;
      } else {
        idx += PVC_NS_MAX - 1;
      }
    }
  }

  /* SBR envelope scalefactor prediction */
  {
    int E_high_exp[PVC_NBHIGH_MAX];
    int E_high_exp_max = 0;
    int pvcTab1ID;
    int pvcTab2ID = (int)pPvcDynamicData->pPvcID[timeSlotNumber];
    const UCHAR *pTab1, *pTab2;
    if (pvcTab2ID < pPvcDynamicData->pPVCTab1_dp[0]) {
      pvcTab1ID = 0;
    } else if (pvcTab2ID < pPvcDynamicData->pPVCTab1_dp[1]) {
      pvcTab1ID = 1;
    } else {
      pvcTab1ID = 2;
    }
    pTab1 = &(pPvcDynamicData
                  ->pPVCTab1[pvcTab1ID * PVC_NBLOW * pPvcDynamicData->nbHigh]);
    pTab2 = &(pPvcDynamicData->pPVCTab2[pvcTab2ID * pPvcDynamicData->nbHigh]);
    for (ksg = 0; ksg < pPvcDynamicData->nbHigh; ksg++) {
      FIXP_SGL predCoeff;
      FIXP_DBL accu;
      int predCoeff_exp, kb;
      E_high_exp[ksg] = 0;

      /* residual part */
      accu = ((LONG)(SCHAR)*pTab2++) << (DFRACT_BITS - 8 - PVC_ESG_EXP +
                                         pPvcDynamicData->pScalingCoef[3]);

      /* linear combination of lower grouped energies part */
      for (kb = 0; kb < PVC_NBLOW; kb++) {
        predCoeff = (FIXP_SGL)(
            (SHORT)(SCHAR)pTab1[kb * pPvcDynamicData->nbHigh + ksg] << 8);
        predCoeff_exp = pPvcDynamicData->pScalingCoef[kb] +
                        1; /* +1 to compensate for Div2 */
        accu += fMultDiv2(E[kb], predCoeff) << predCoeff_exp;
      }
      /* convert back to linear domain */
      accu = fMult(accu, FL2FXCONST_SGL(LOG10FAC_INV));
      accu = f2Pow(
          accu, PVC_ESG_EXP - 1,
          &predCoeff_exp); /* -1 compensates for exponent of LOG10FAC_INV */
      predictedEsgSlot[ksg] = accu;
      E_high_exp[ksg] = predCoeff_exp;
      if (predCoeff_exp > E_high_exp_max) {
        E_high_exp_max = predCoeff_exp;
      }
    }

    /* rescale output vector according to largest exponent */
    for (ksg = 0; ksg < pPvcDynamicData->nbHigh; ksg++) {
      int scale = E_high_exp[ksg] - E_high_exp_max;
      predictedEsgSlot[ksg] = scaleValue(predictedEsgSlot[ksg], scale);
    }
    *predictedEsg_exp = E_high_exp_max;
  }

  pPvcStaticData->Esg_slot_index =
      (pPvcStaticData->Esg_slot_index + 1) & (PVC_NS_MAX - 1);
  pPvcDynamicData->pastEsgSlotsAvail =
      fMin(pPvcDynamicData->pastEsgSlotsAvail + 1, PVC_NS_MAX - 1);
  return;
}
Beispiel #24
0
void FDK_QmfDomain_GetSlot(const HANDLE_FDK_QMF_DOMAIN_IN qd_ch, const int ts,
                           const int start_band, const int stop_band,
                           FIXP_DBL *pQmfOutReal, FIXP_DBL *pQmfOutImag,
                           const int exp_out) {
  FDK_ASSERT(qd_ch != NULL);
  FDK_ASSERT(pQmfOutReal != NULL);
  HANDLE_FDK_QMF_DOMAIN_GC gc = qd_ch->pGlobalConf;
  const FIXP_DBL *real = qd_ch->hQmfSlotsReal[ts];
  const FIXP_DBL *imag = qd_ch->hQmfSlotsImag[ts];
  const int ovSlots = gc->nQmfOvTimeSlots;
  const int exp_lb = SCALE2EXP((ts < ovSlots) ? qd_ch->scaling.ov_lb_scale
                                              : qd_ch->scaling.lb_scale);
  const int exp_hb = SCALE2EXP(qd_ch->scaling.hb_scale);
  const int lsb = qd_ch->fb.lsb;
  const int usb = qd_ch->fb.usb;
  int b = start_band;
  int lb_sf, hb_sf;

  int target_exp =
      ALGORITHMIC_SCALING_IN_ANALYSIS_FILTERBANK + qd_ch->fb.filterScale;

  FDK_ASSERT(ts < (gc->nQmfTimeSlots + gc->nQmfOvTimeSlots));
  FDK_ASSERT(start_band >= 0);
  FDK_ASSERT(stop_band <= gc->nQmfProcBands);

  if (qd_ch->fb.no_channels == 24) {
    target_exp -= 1;
  }

  /* Limit scaling factors to maximum negative value to avoid faulty behaviour
     due to right-shifts. Corresponding asserts were observed during robustness
     testing.
   */
  lb_sf = fMax(exp_lb - target_exp - exp_out, -31);
  FDK_ASSERT(lb_sf < 32);
  hb_sf = fMax(exp_hb - target_exp - exp_out, -31);
  FDK_ASSERT(hb_sf < 32);

  if (pQmfOutImag == NULL) {
    for (; b < fMin(lsb, stop_band); b++) {
      pQmfOutReal[b] = scaleValue(real[b], lb_sf);
    }
    for (; b < fMin(usb, stop_band); b++) {
      pQmfOutReal[b] = scaleValue(real[b], hb_sf);
    }
    for (; b < stop_band; b++) {
      pQmfOutReal[b] = (FIXP_DBL)0;
    }
  } else {
    FDK_ASSERT(imag != NULL);
    for (; b < fMin(lsb, stop_band); b++) {
      pQmfOutReal[b] = scaleValue(real[b], lb_sf);
      pQmfOutImag[b] = scaleValue(imag[b], lb_sf);
    }
    for (; b < fMin(usb, stop_band); b++) {
      pQmfOutReal[b] = scaleValue(real[b], hb_sf);
      pQmfOutImag[b] = scaleValue(imag[b], hb_sf);
    }
    for (; b < stop_band; b++) {
      pQmfOutReal[b] = (FIXP_DBL)0;
      pQmfOutImag[b] = (FIXP_DBL)0;
    }
  }
}
Beispiel #25
0
void MSurface::drawSprite(const Common::Point &pt, SpriteInfo &info, const Common::Rect &clipRect) {

    enum {
        kStatusSkip,
        kStatusScale,
        kStatusDraw
    };

    // NOTE: The current clipping code assumes that the top left corner of the clip
    // rectangle is always 0, 0
    assert(clipRect.top == 0 && clipRect.left == 0);

    int errX = info.hotX * info.scaleX % 100;
    int errY = info.hotY * info.scaleY % 100;
    int scaledWidth = scaleValue(info.width, info.scaleX, errX);
    int scaledHeight = scaleValue(info.height, info.scaleY, errY);

    int x = pt.x, y = pt.y;
    int clipX = 0, clipY = 0;
    // Clip the sprite's width and height according to the clip rectangle's dimensions
    // This clips the sprite to the bottom and right
    if (x >= 0) {
        scaledWidth = MIN<int>(x + scaledWidth, clipRect.right) - x;
    } else {
        clipX = x;
        scaledWidth = x + scaledWidth;
    }
    if (y >= 0) {
        scaledHeight = MIN<int>(y + scaledHeight, clipRect.bottom) - y;
    } else {
        clipY = y;
        scaledHeight = y + scaledHeight;
    }

    // Check if sprite is inside the screen. If it's not, there's no need to draw it
    if (scaledWidth + x <= 0 || scaledHeight + y <= 0)	// check left and top (in case x,y are negative)
        return;
    if (scaledWidth <= 0 || scaledHeight <= 0)			// check right and bottom
        return;
    int heightAmt = scaledHeight;

    byte *src = info.sprite->getData();
    byte *dst = getBasePtr(x - info.hotX - clipX, y - info.hotY - clipY);

    int status = kStatusSkip;
    byte *scaledLineBuf = new byte[scaledWidth];

    while (heightAmt > 0) {

        if (status == kStatusSkip) {
            // Skip line
            errY -= info.scaleY;
            if (errY < 0)
                status = kStatusScale;
            else
                src += info.width;
        } else {

            if (status == kStatusScale) {
                // Scale current line
                byte *lineDst = scaledLineBuf;
                int curErrX = errX;
                int width = scaledWidth;
                byte *tempSrc = src;
                int startX = clipX;
                while (width > 0) {
                    byte pixel = *tempSrc++;
                    curErrX -= info.scaleX;
                    while (curErrX < 0) {
                        if (startX == 0) {
                            *lineDst++ = pixel;
                            width--;
                        } else {
                            startX++;
                        }
                        curErrX += 100;
                    }
                }
                src += info.width;
                status = kStatusDraw;
            }

            if (status == kStatusDraw && clipY == 0) {
                // Draw previously scaled line
                byte *tempDst = dst;
                for (int lineX = 0; lineX < scaledWidth; lineX++) {
                    byte pixel = scaledLineBuf[lineX];

                    if (info.encoding & 0x80) {

                        if (pixel == 0x80) {
                            pixel = 0;
                        } else {
                            byte destPixel = *tempDst;
                            byte r, g, b;
                            r = CLIP((info.palette[destPixel * 3] * pixel) >> 10, 0, 31);
                            g = CLIP((info.palette[destPixel * 3 + 1] * pixel) >> 10, 0, 31);
                            b = CLIP((info.palette[destPixel * 3 + 2] * pixel) >> 10, 0, 31);
                            pixel = info.inverseColorTable[(b << 10) | (g << 5) | r];
                        }
                    }

                    if (pixel)
                        *tempDst = pixel;

                    tempDst++;
                }
                dst += pitch;
                heightAmt--;

                errY += 100;
                if (errY >= 0)
                    status = kStatusSkip;
            } else if (status == kStatusDraw && clipY < 0) {
                clipY++;

                errY += 100;
                if (errY >= 0)
                    status = kStatusSkip;
            }

        }
Beispiel #26
0
static INT GetBandwidthEntry(
            const INT frameLength,
            const INT sampleRate,
            const INT chanBitRate,
            const INT entryNo)
{
  INT bandwidth = -1;
  const BANDWIDTH_TAB *pBwTab = NULL;
  INT bwTabSize = 0;

  switch (frameLength) {
    case 960:
    case 1024:
      pBwTab = bandWidthTable;
      bwTabSize = sizeof(bandWidthTable)/sizeof(BANDWIDTH_TAB);
      break;
    case 480:
    case 512:
      switch (sampleRate) {
        case 8000:
        case 11025:
        case 12000:
        case 16000:
        case 22050:
          pBwTab = bandWidthTable_LD_22050;
          bwTabSize = sizeof(bandWidthTable_LD_22050)/sizeof(BANDWIDTH_TAB);
          break;
        case 24000:
          pBwTab = bandWidthTable_LD_24000;
          bwTabSize = sizeof(bandWidthTable_LD_24000)/sizeof(BANDWIDTH_TAB);
          break;
        case 32000:
          pBwTab = bandWidthTable_LD_32000;
          bwTabSize = sizeof(bandWidthTable_LD_32000)/sizeof(BANDWIDTH_TAB);
          break;
        case (44100):
          pBwTab = bandWidthTable_LD_44100;
          bwTabSize = sizeof(bandWidthTable_LD_44100)/sizeof(BANDWIDTH_TAB);
          break;
        case 48000:
        case 64000:
        case 88200:
        case 96000:
          pBwTab = bandWidthTable_LD_48000;
          bwTabSize = sizeof(bandWidthTable_LD_48000)/sizeof(BANDWIDTH_TAB);
          break;
      }
      break;
    default:
      pBwTab = NULL;
      bwTabSize = 0;
  }

  if (pBwTab!=NULL) {
    int i;
    for (i=0; i<bwTabSize-1; i++) {
      if (chanBitRate >= pBwTab[i].chanBitRate &&
          chanBitRate < pBwTab[i+1].chanBitRate)
      {
        switch (frameLength) {
          case 960:
          case 1024:
            bandwidth = (entryNo==0)
              ? pBwTab[i].bandWidthMono
              : pBwTab[i].bandWidth2AndMoreChan;
            break;
          case 480:
          case 512:
            {
              INT q_res = 0;
              INT startBw = (entryNo==0) ?  pBwTab[i  ].bandWidthMono : pBwTab[i  ].bandWidth2AndMoreChan;
              INT endBw =   (entryNo==0) ?  pBwTab[i+1].bandWidthMono : pBwTab[i+1].bandWidth2AndMoreChan;
              INT startBr = pBwTab[i].chanBitRate;
              INT endBr = pBwTab[i+1].chanBitRate;

              FIXP_DBL bwFac_fix = fDivNorm(chanBitRate-startBr, endBr-startBr, &q_res);
              bandwidth = (INT)scaleValue(fMult(bwFac_fix, (FIXP_DBL)(endBw-startBw)),q_res) + startBw;
            }
            break;
          default:
            bandwidth = -1;
        }
        break;
      } /* within bitrate range */
    }
  } /* pBwTab!=NULL */

  return bandwidth;
}
/** Return a matrix containing appropriate representation of an area
of the board centred around the given move so it can be fed 
directly into a BPN network. The area size is determined by the
value of PATTERNWIDTH and PATTERNHEIGHT.
@param x The x coordinate to centre on.
@param y The y coordinate to centre on.
@param b The Board object from which to extract an area.
@param input A return parameter to store the converted, NN ready input matrix. 
@param colour The colour whose point of view we are creating this input pattern for. I.e. which colour
this move is being scored for. */
bool newBPN5GoAdapter::getInput(int x, int y, const BoardStruct& b, Matrix<float>& input, int colour) const
{
	const BoardStruct::contentsType& t = b.getContents();
	float act = 0;

	// board contents should be rotated so that nearest two board edges
	// are the top and left, this gets rid of all rotational symmetry
	int width = t.getWidth();
	int height = t.getHeight();
	int leftdist = x;
	int rightdist = width-x-1; 
	int topdist = y;
	int bottomdist = height-y-1;

	bool topcloser = true;
	bool leftcloser = true;

	// top left sides always preferred if equidistant from two edges
	if(topdist>bottomdist)
		topcloser = false;
	if(leftdist>rightdist)
		leftcloser = false;

	// copy board into a matrix so we can rotate later
	BoardStruct::contentsType temp2(t);
	BoardStruct::contentsType temp(temp2.width, temp2.height);

	// if bottom right edges closer
	if(!topcloser && !leftcloser)
	{
		// rotate temp 180 clw
		temp2.doTransform(temp, Matrix_ROTATE180);
		// translate x and y now to match newly rotated board
		x = rightdist;
		y = bottomdist;
	}
	// if top right edges closer
	else if(topcloser && !leftcloser)
	{
		// rotate temp 270 clw
		temp2.doTransform(temp, Matrix_ROTATE270);
		x = topdist;
		y = rightdist;
	}
	// if bottom left edges closer
	else if(!topcloser && leftcloser)
	{
		// rotate temp 90 clw
		temp2.doTransform(temp, Matrix_ROTATE90);
		x = bottomdist;
		y = leftdist;
	}
	// no rotation
	else
		temp = temp2;

	// 3 units per point + 18 units for distance to nearest board edges
	input.resize(1, getBPN().getWeights()[0].getHeight());
	// now extract contents of board around this point

	// values to work around area centred on x,y
	// extending as PATTERNWIDTHxPATTERNHEIGHT
	int pWidth = getPatternWidth();
	int pHeight = getPatternHeight();
	int topleftx = x-(pWidth/2);
	int toplefty = y-(pHeight/2);

	int offsetx = 0;
	int offsety = 0;

	int count = 0;
	vector<SpecialPoint> points;
	getInputFieldPoints(temp, points, x, y);
	vector<SpecialPoint>::const_iterator citer = points.begin();
	for(;citer!=points.end();citer++)
	{
		if(citer->type==OFFBOARD)
			setPoint(input, count++, ACT_OFFBOARD);
		else
			setPoint(input, count++, getActivationValue(citer->type, colour));
	}
	
/*	// find equivalent input values
	for(int i=0;i<pHeight;i++)
	{
		offsety = i+toplefty;
		for(int j=0;j<pWidth;j++)
		{
			offsetx = j+topleftx;
			// check bounds	to see if this point is off the board
			if(offsetx<0 || offsety<0 || offsetx>=width || offsety>=height)
				setPoint(input, count, ACT_OFFBOARD);
			else
				setPoint(input, count, getActivationValue(temp.getValue(offsetx, offsety), colour));
			count++;
		} // end for j
	} // end for i
*/
	// add distance to edge values for last 18 neurons
	// 9 neurons for top edge distance
	// 9 neurons for left edge distance
	// use binary type system
	// all off except the nth neuron indicating the distance

	// the distance to top and left edges (now the nearest after rotation)
	// should now be x, y

	// top distance
	for(int i=0;i<9;i++)
	{
		if((i+1)==x)
			input.setValue(0, (count*4)+i, 1);
		else
			input.setValue(0, (count*4)+i, 0);
	}

	// left distance
	for(i=0;i<9;i++)
	{
		if((i+1)==y)
			input.setValue(0, ((count*4)+9)+i, 1);
		else
			input.setValue(0, ((count*4)+9)+i, 0);
	}

	// 1 neuron indicating distance to last move
	int sqrx = b.getLastX()-x;
	sqrx*=sqrx;
	int sqry = b.getLastY()-y;
	sqry*=sqry;
	float dist = sqrt(sqrx+sqry);
	scaleValue(dist, 0.0, sqrt(b.getSize()*b.getSize()), 0.0, 1.0);
	input.setValue(0, ((count*4)+18), dist);

	//input.setValue(0, count*3, x);
	//input.setValue(0, (count*3)+1, y);
	return true;
}
/////////////////////////////////////////////////////////////////////////////
// Sound Engines Update Cycle
/////////////////////////////////////////////////////////////////////////////
bool MbCvEnvironment::tick(void)
{
    bool updateRequired = false;

    // Tempo Clock
    mbCvClock.tick();

    // Synchronized patch change request?
    if( mbCvClock.eventClock && mbCvPatch.reqChange ) {
        u32 tick = mbCvClock.clkTickCtr;
        u32 atStep = (u32)mbCvPatch.synchedChangeStep + 1;

#if 0
        if( (tick % 24) == 0 && ((tick/24) % atStep) == 0 )
            mbCvPatch.reqChangeAck = true;
#else
        // change 8 ticks before step change
        if( (tick % 24) == 16 && ((tick/24) % atStep) == (atStep-1) )
            mbCvPatch.reqChangeAck = true;        
#endif
    }

    // Engines
    for(MbCv *s = mbCv.first(); s != NULL ; s=mbCv.next(s)) {
        if( s->tick(updateSpeedFactor) )
            updateRequired = true;
    }

    // Transfer values to scope
    // we do this as a second step, so that it will be possible to map values
    {
        MbCvScope *scope = mbCvScope.first();
        for(int i=0; i < mbCvScope.size; ++i, ++scope) {
            u8 cvNumber = scope->getSource();
            if( cvNumber > 0 && cvNumber <= cvOut.size ) {
                u8 cv = cvNumber-1;
                scope->addValue(cvOut[cv] - 0x8000, mbCv[cv].mbCvVoice.voiceGateActive, mbCvClock.clkTickCtr);
            } else {
                scope->addValue(0, 0, 0);
            }
        }
    }

    if( updateRequired ) {
        // map engine parameters to CV outputs
        // we do this as a second step, so that it will be possible to map values
        // of a single engine to different channels in future
        cvGates = 0;
        MbCv *s = mbCv.first();
        u16 *out = cvOut.first();
        u16 *outMeter = cvOutMeter.first();
        for(int cv=0; cv < cvOut.size; ++cv, ++s, ++out, ++outMeter) {
            MbCvVoice *v = &s->mbCvVoice;
            MbCvMidiVoice *mv = (MbCvMidiVoice *)v->midiVoicePtr;

            if( v->voicePhysGateActive ^ v->voiceGateInverted )
                cvGates |= (1 << cv);

            if( v->voiceEventMode == MBCV_MIDI_EVENT_MODE_NOTE ) {
                *out = v->voiceFrq;
            } else {
                switch( v->voiceEventMode ) {
                case MBCV_MIDI_EVENT_MODE_VELOCITY: *out = v->transpose(v->voiceVelocity << 9); break;
                case MBCV_MIDI_EVENT_MODE_AFTERTOUCH: *out = v->transpose(mv->midivoiceAftertouch << 9); break;
                case MBCV_MIDI_EVENT_MODE_CC: *out = v->transpose(mv->midivoiceCCValue << 9); break;
                case MBCV_MIDI_EVENT_MODE_NRPN: *out = v->transpose(mv->midivoiceNRPNValue << 2); break;
                case MBCV_MIDI_EVENT_MODE_PITCHBENDER: *out = v->transpose((mv->midivoicePitchBender + 8192) << 2); break;
                case MBCV_MIDI_EVENT_MODE_CONST_MIN: *out = v->transpose(0x0000); break;
                case MBCV_MIDI_EVENT_MODE_CONST_MID: *out = v->transpose(0x8000); break;
                case MBCV_MIDI_EVENT_MODE_CONST_MAX: *out = v->transpose(0xffff); break;
                }
            }

            if( v->voiceForceToScale ) {
                *out = scaleValue(*out / 512) * 512;
            }

            if( *out > *outMeter ) {
                *outMeter = *out;
            }
        }
    }

    return updateRequired;
}