lfocontrolsource: cleanups and fix triangle calculations

This commit is contained in:
Stefan Sauer 2012-01-01 18:43:23 +01:00
parent 35b817ad48
commit e87d563cac

View file

@ -78,12 +78,11 @@ _sine_get (GstLFOControlSource * self, gdouble amp, gdouble off,
GstClockTime timeshift, GstClockTime period, gdouble frequency, GstClockTime timeshift, GstClockTime period, gdouble frequency,
GstClockTime timestamp) GstClockTime timestamp)
{ {
GstClockTime pos = _calculate_pos (timestamp, timeshift, period); gdouble pos =
gst_guint64_to_gdouble (_calculate_pos (timestamp, timeshift, period));
gdouble ret; gdouble ret;
ret = ret = sin (2.0 * M_PI * (frequency / GST_SECOND) * pos);
sin (2.0 * M_PI * (frequency / GST_SECOND) *
gst_guint64_to_gdouble (pos));
ret *= amp; ret *= amp;
ret += off; ret += off;
@ -183,13 +182,12 @@ _saw_get (GstLFOControlSource * self, gdouble amp, gdouble off,
GstClockTime timeshift, GstClockTime period, gdouble frequency, GstClockTime timeshift, GstClockTime period, gdouble frequency,
GstClockTime timestamp) GstClockTime timestamp)
{ {
GstClockTime pos = _calculate_pos (timestamp, timeshift, period); gdouble pos =
gst_guint64_to_gdouble (_calculate_pos (timestamp, timeshift, period));
gdouble per = gst_guint64_to_gdouble (period);
gdouble ret; gdouble ret;
ret = ret = -((pos - per / 2.0) * ((2.0 * amp) / per));
-((gst_guint64_to_gdouble (pos) -
gst_guint64_to_gdouble (period) / 2.0) * ((2.0 * amp) /
gst_guint64_to_gdouble (period)));
ret += off; ret += off;
return ret; return ret;
@ -235,13 +233,12 @@ _rsaw_get (GstLFOControlSource * self, gdouble amp, gdouble off,
GstClockTime timeshift, GstClockTime period, gdouble frequency, GstClockTime timeshift, GstClockTime period, gdouble frequency,
GstClockTime timestamp) GstClockTime timestamp)
{ {
GstClockTime pos = _calculate_pos (timestamp, timeshift, period); gdouble pos =
gst_guint64_to_gdouble (_calculate_pos (timestamp, timeshift, period));
gdouble per = gst_guint64_to_gdouble (period);
gdouble ret; gdouble ret;
ret = ret = (pos - per / 2.0) * ((2.0 * amp) / per);
((gst_guint64_to_gdouble (pos) -
gst_guint64_to_gdouble (period) / 2.0) * ((2.0 * amp) /
gst_guint64_to_gdouble (period)));
ret += off; ret += off;
return ret; return ret;
@ -288,24 +285,20 @@ _triangle_get (GstLFOControlSource * self, gdouble amp, gdouble off,
GstClockTime timeshift, GstClockTime period, gdouble frequency, GstClockTime timeshift, GstClockTime period, gdouble frequency,
GstClockTime timestamp) GstClockTime timestamp)
{ {
GstClockTime pos = _calculate_pos (timestamp, timeshift, period); gdouble pos =
gst_guint64_to_gdouble (_calculate_pos (timestamp, timeshift, period));
gdouble per = gst_guint64_to_gdouble (period);
gdouble ret; gdouble ret;
if (gst_guint64_to_gdouble (pos) <= gst_guint64_to_gdouble (period) / 4.0) if (pos <= 0.25 * per)
ret = /* 1st quarter */
gst_guint64_to_gdouble (pos) * ((4.0 * amp) / ret = pos * ((4.0 * amp) / per);
gst_guint64_to_gdouble (period)); else if (pos <= 0.75 * per)
else if (gst_guint64_to_gdouble (pos) <= /* 2nd & 3rd quarter */
(3.0 * gst_guint64_to_gdouble (period)) / 4.0) ret = -(pos - per / 2.0) * ((4.0 * amp) / per);
ret =
-(gst_guint64_to_gdouble (pos) -
gst_guint64_to_gdouble (period) / 2.0) * ((4.0 * amp) /
gst_guint64_to_gdouble (period));
else else
ret = /* 4th quarter */
gst_guint64_to_gdouble (period) - ret = -(per - pos) * ((4.0 * amp) / per);
gst_guint64_to_gdouble (pos) * ((4.0 * amp) /
gst_guint64_to_gdouble (period));
ret += off; ret += off;