void AudioPlayerGnu::setBalance(int b)
{
    b = Clamp(b, kMinBalance, kMaxBalance);
    gfloat gst_balance =
            (gfloat(b*100 - kMinBalance*100) / (kMaxBalance*100 - kMinBalance*100)) * 2 - 1;
    g_object_set(G_OBJECT(balance), "panorama", gst_balance, NULL);
}
    Circle::Circle(gsize n_circle_vertices, gsize n_triangles)
    {
      g_assert(abs(PI2-6.2831) < 0.001);
      g_assert(n_circle_vertices>=12);

      //-- Allocate enough memory for the meshdata
      i_triangle = 0;
      this->n_triangles  = n_triangles;
      triangles  = new Polygon[n_triangles];
      uv_rectangle  = new UV[n_triangles*3];
      uv_warped  = new UV[n_triangles*3];

      //-- Generates the Circle
      _n_circle_vertices = n_circle_vertices;
      _circle_vertices = new Vector3[_n_circle_vertices];

      gfloat ia  = PI2/gfloat(_n_circle_vertices);
      gfloat a  = 0.f;

      for(gsize i=0; i<_n_circle_vertices; ++i)
      {
        _circle_vertices[i].x  = cos(a);
        _circle_vertices[i].y  = sin(a);
        _circle_vertices[i].z  = 0.f;

        a += ia;
      }
    }
Exemple #3
0
/*
* Update the  congestion window
*/
void ScreamTx::updateCwnd(guint64 time_us) {
    /*
    * Compute the OWD 
    */
    guint64 tmp = estimateOwd(time_us) - getBaseOwd();
    /*
    * Convert from [jiffy] OWD to an OWD in [s]
    */ 
    owd = tmp/kTimestampRate;


    if (owd > MAX(0.2f,2*getSRtt()) && time_us - baseOwdResetT_us > 10000000) {
        /*
        * The base OWD is likely wrong, for instance due to 
        * a channel change, reset base OWD history
        */
        for (int n=0; n < kBaseOwdHistSize; n++)
            baseOwdHist[n] = G_MAXINT32;
        baseOwd = G_MAXINT32;
        baseOwdResetT_us = time_us;
    }
    /*
    * An averaged version of the OWD fraction
    * neceassary in order to make video rate control robust 
    * against jitter 
    */
    owdFractionAvg = 0.9f*owdFractionAvg + 0.1f*getOwdFraction(); 

    /*
    * Save to OWD fraction history
    * used in computeOwdTrend()
    */
    if ((time_us - lastAddToOwdFractionHistT_us) >
        kOwdFractionHistInterval_us) {
            owdFractionHist[owdFractionHistPtr] = getOwdFraction();
            owdFractionHistPtr = (owdFractionHistPtr+1) % kOwdFractionHistSize;
            computeOwdTrend();

            owdTrendMem = MAX(owdTrendMem*0.99,owdTrend);

            if (kEnableSbd) {
                /*
                * Shared bottleneck detection, 
                */
                gfloat owdNorm = owd/kOwdTargetMin;
                owdNormHist[owdNormHistPtr] = owdNorm;
                owdNormHistPtr = (owdNormHistPtr+1) % kOwdNormHistSize;
                /*
                * Compute shared bottleneck detection and update OWD target
                * if OWD variance is sufficienctly low
                */    
                computeSbd(); 
                /* 
                * This function avoids the adjustment of owdTarget when 
                * congestion occurs (indicated by high owdSbdVar and owdSbdSkew)
                */
                
                /*
                cerr << "owdSbdVar=" << owdSbdVar << " owdSbdSkew=" << owdSbdSkew
                     << " owdSbdMeanSh=" << owdSbdMeanSh << " owdTarget=" << owdTarget
                     << endl;
                */

                /* Need to change parameters in order to adapt 
                   delay target to competing flows */
                if (owdSbdVar < 1 && owdSbdSkew < 2) {
                // if (owdSbdVar < 0.2 && owdSbdSkew < 0.05) { 
                    owdTarget = MAX(kOwdTargetMin,
                        MIN(kOwdTargetMax,owdSbdMeanSh*kOwdTargetMin*1.1f));
                } else if (owdSbdMeanSh*kOwdTargetMin < owdTarget) {
                    owdTarget = MAX(kOwdTargetMin,owdSbdMeanSh*kOwdTargetMin);
                }
            }
            lastAddToOwdFractionHistT_us = time_us;
    }
    /*
    * off_target is a normalized deviation from the owdTarget
    */
    gfloat offTarget = (owdTarget - owd) / gfloat(owdTarget);


    if (lossEvent) {
        /*
        * loss event detected, decrease congestion window
        */
        cwndI = cwnd;
        cwnd = MAX(cwndMin, (int) (kLossBeta*cwnd));
        lossEvent = FALSE;
        lastCongestionDetectedT_us = time_us;

        inFastStart = FALSE;
    }
    else {
			/*
			* Compute a scaling dependent on the relation between CWND and the inflection point
			* i.e the last known max value. This helps to reduce the CWND growth close to
			* the last known congestion point
			*/
			gfloat sclI = (cwnd - cwndI) / ((gfloat)(cwndI));
			sclI *= 4.0f;
			sclI = MAX(0.1f, MIN(1.0f, sclI*sclI));

			if (inFastStart) {
				/*
				* In fast start, variable exit condition depending of
				* if it is the first fast start or a later
				* In addition, the threshhold is more relaxed if
				* competing flows are detected
				*/
				gfloat th = 0.2f;
				if (isCompetingFlows())
					th = 0.5f;
				else if (nFastStart > 1)
					th = 0.1f;
				if (owdTrend < th) {
					/*
					* CWND is in principle increased by the number of ACKed bytes
					* save for a restriction to 10*MSS. In addition the increase
					* is limited if CWND is close to the last known max value
					* cwnd is not increased if less than half is used
					*/
					if (bytesInFlight() > cwnd / 2)
						cwnd += MIN(10 * mss, (int)(bytesNewlyAcked*sclI));
				}
				else {
					inFastStart = FALSE;
					lastCongestionDetectedT_us = time_us;
					cwndI = cwnd;
					wasCwndIncrease = TRUE;
				}
			}
			else {
				if (offTarget > 0.0f) {
					/*
					* OWD below target
					*/
					wasCwndIncrease = TRUE;
					/*
					* Limit growth if OWD shows an increasing trend
					*/
					gfloat gain = kGainUp*(1.0f + MAX(0.0f, 1.0f - owdTrend / 0.2f));
					gain *= sclI;

					cwnd += (int)(gain * offTarget * bytesNewlyAcked * mss / cwnd + 0.5f);
				}
				else {
					/*
					* OWD above target
					*/
					if (wasCwndIncrease) {
						wasCwndIncrease = FALSE;
						cwndI = cwnd;
					}
					cwnd += (int)(kGainDown * offTarget * bytesNewlyAcked * mss / cwnd);
					lastCongestionDetectedT_us = time_us;
				}
		}
    }
    /*
    * Congestion window validation, checks that the congestion window is
    * not considerably higher than the actual number of bytes in flight
    */ 
    gint maxBytesInFlightHi = (int)(MAX(bytesInFlightMaxHi, getMaxBytesInFlightHi()));
    gint maxBytesInFlightLo = (int)(MAX(bytesInFlight(), getMaxBytesInFlightLo()));
    gfloat maxBytesInFlight = (maxBytesInFlightHi*(1.0-owdTrendMem)+maxBytesInFlightLo*owdTrendMem)*
        kMaxBytesInFlightHeadRoom;
    if (maxBytesInFlight > 5000) {
        cwnd = MIN(cwnd, maxBytesInFlight);
    }

    if (getSRtt() < 0.01f && owdTrend < 0.1) {
        /* fix -Werror=sign-compare
        guint tmp = rateTransmitted*0.01f/8;
        */
        gint tmp = rateTransmitted*0.01f/8;

        tmp = MAX(tmp,maxBytesInFlight*1.5);
        cwnd = MAX(cwnd,tmp);
    }
    cwnd = MAX(cwndMin, cwnd);

    if (kOpenCwnd) {
        /*
        *
        */
        cwnd = 1000000;
    }
    /*
    * Make possible to enter fast start if OWD has been low for a while
    * The detection threshold is a bit less strick when competing flows are detected
    */
    gfloat th = 0.2f;
    if (isCompetingFlows())
        th = 0.5f;
    if (owdTrend > th) {
        lastCongestionDetectedT_us = time_us;
    } else if (time_us - lastCongestionDetectedT_us > 1000000 && 
        !inFastStart && kEnableConsecutiveFastStart ) {
            /*
            * The OWD trend has been low for more than 1.0s, resume fast start
            */
            inFastStart = TRUE;
            lastCongestionDetectedT_us = time_us;
            nFastStart++;
    }
    bytesNewlyAcked = 0;
}
Exemple #4
0
static gboolean
process (GeglOperation       *operation,
         void                *in_buf,
         void                *out_buf,
         glong                n_pixels,
         const GeglRectangle *roi,
         gint                 level)
{
  GeglProperties *o  = GEGL_PROPERTIES (operation);

  gdouble  noise_coeff = 0.0;
  gint     b, i;
  gint     x, y;
  gdouble  noise[4];
  gfloat   tmp;
  gfloat   * GEGL_ALIGNED in_pixel;
  gfloat   * GEGL_ALIGNED out_pixel;
  gfloat   (*noise_fun) (GeglRandom *rand, gint xx, gint yy, gint *n) = noise_gauss;

  in_pixel   = in_buf;
  out_pixel  = out_buf;

  noise[0] = o->red;
  noise[1] = o->green;
  noise[2] = o->blue;
  noise[3] = o->alpha;

  if (o->gaussian == FALSE)
    noise_fun = noise_linear;

  x = roi->x;
  y = roi->y;

  for (i=0; i<n_pixels; i++)
  {
    gint n = 0;

    for (b = 0; b < 4; b++)
    {
      if (b == 0 || o->independent || b == 3 )
         noise_coeff = noise[b] * noise_fun (o->rand, x, y, &n) * 0.5;

      if (noise[b] > 0.0)
      {
        if (o->correlated)
        {
          tmp = (in_pixel[b] + (in_pixel[b] * (noise_coeff / 0.5)) );
        }
        else
        {
          tmp = (in_pixel[b] + noise_coeff );
        }

        out_pixel[b] = CLAMP(tmp, 0.0, 1.0);
      }
      else
      {
        out_pixel[b] = in_pixel[b];
      }
    }

    in_pixel  += 4;
    out_pixel += 4;

    x++;
    if (x >= roi->x + roi->width)
      {
        x = roi->x;
        y++;
      }
  }

  return TRUE;
}
static void
binary_dt_2nd_pass (GeglOperation *operation,
                    gint           width,
                    gint           height,
                    gfloat         thres_lo,
                    GeglDTMetric   metric,
                    gfloat        *src,
                    gfloat        *dest)
{
  gint u, y;
  gint q, w, *t, *s;
  gfloat *g, *row_copy;

  gfloat (*dt_f)   (gfloat, gfloat, gfloat);
  gint   (*dt_sep) (gint, gint, gfloat, gfloat);

  switch (metric)
    {
      case GEGL_DT_METRIC_CHESSBOARD:
        dt_f   = cdt_f;
        dt_sep = cdt_sep;
        break;
      case GEGL_DT_METRIC_MANHATTAN:
        dt_f   = mdt_f;
        dt_sep = mdt_sep;
        break;
      default: /* GEGL_DT_METRIC_EUCLIDEAN */
        dt_f   = edt_f;
        dt_sep = edt_sep;
        break;
    }

  /* sorry for the variable naming, they are taken from the paper */

  s = gegl_calloc (sizeof (gint), width);
  t = gegl_calloc (sizeof (gint), width);
  row_copy = gegl_calloc (sizeof (gfloat), width);

  /* this could be parallelized */
  for (y = 0; y < height; y++)
    {
      q = 0;
      s[0] = 0;
      t[0] = 0;
      g = dest + y * width;

      dest[0 + y * width] = MIN (dest[0 + y * width], 1.0);
      dest[width - 1 + y * width] = MIN (dest[width - 1 + y * width], 1.0);

      for (u = 1; u < width; u++)
        {
          while (q >= 0 &&
                 dt_f (t[q], s[q], g[s[q]]) >= dt_f (t[q], u, g[u]) + EPSILON)
            {
              q --;
            }

          if (q < 0)
            {
              q = 0;
              s[0] = u;
            }
          else
            {
              /* function Sep from paper */
              w = dt_sep (s[q], u, g[s[q]], g[u]);
              w += 1;

              if (w < width)
                {
                  q ++;
                  s[q] = u;
                  t[q] = w;
                }
            }
        }

      memcpy (row_copy, g, width * sizeof (gfloat));

      for (u = width - 1; u >= 0; u--)
        {
          if (u == s[q])
            g[u] = row_copy[u];
          else
            g[u] = dt_f (u, s[q], row_copy[s[q]]);

          if (q > 0 && u == t[q])
            {
              q--;
            }
        }

      gegl_operation_progress (operation,
                               (gdouble) y / (gdouble) height / 2.0 + 0.5, "");
    }

  gegl_free (t);
  gegl_free (s);
  gegl_free (row_copy);
}