public static mPoint[] createCurve(mPoint[] orip) { List <mPoint> curvePoint = new List <mPoint>(); int oripl = orip.Length; double scale = 0.16; mPoint[] ap = new mPoint[oripl]; mPoint[] bp = new mPoint[oripl]; ap[0] = new mPoint( orip[0].x + (orip[1].x - orip[0].x) * scale, orip[0].y + (orip[1].y - orip[0].y) * scale); bp[oripl - 2] = new mPoint( orip[oripl - 1].x - (orip[oripl - 1].x - orip[oripl - 2].x) * scale, orip[oripl - 1].y - (orip[oripl - 1].y - orip[oripl - 2].y) * scale); for (int i = 1; i < oripl - 1; i++) { ap[i] = new mPoint( orip[i].x + (orip[i + 1].x - orip[i - 1].x) * scale, orip[i].y + (orip[i + 1].y - orip[i - 1].y) * scale); } for (int i = 0; i < oripl - 2; i++) { bp[i] = new mPoint( orip[i + 1].x - (orip[i + 2].x - orip[i].x) * scale, orip[i + 1].y - (orip[i + 2].y - orip[i].y) * scale); } //生成4控制点,产生贝塞尔曲线 for (int i = 0; i < oripl - 1; i++) { mPoint[] points = new mPoint[4]; points[0] = orip[i]; points[1] = ap[i]; points[2] = bp[i]; points[3] = orip[i + 1]; double u = 1; double du = 1.0 / (points[3].x - points[0].x); for (int j = 0; j < points[3].x - points[0].x; j++) { int px = (int)bezier3funcX(u, points); int py = (int)bezier3funcY(u, points); //u的步长决定曲线的疏密 u -= du; mPoint tempP = new mPoint(px, py); //存入曲线点 curvePoint.Add(tempP); } } return(curvePoint.ToArray()); }
/// <summary> /// 获取与音量曲线一一对应的音量缩放比例 /// </summary> /// <param name="len"></param> /// <param name="zipdata"></param> /// <returns></returns> public static double[] getZipPoint(int len, double[] zipdata) { double[] res = new double[len]; if (zipdata.Length == 0) { for (int i = 0; i < len; i++) { res[i] = 1; } } else if (zipdata.Length == 1) { for (int i = 0; i < len; i++) { res[i] = zipdata[0]; } } else if (zipdata.Length == 2) { for (int i = 0; i < len; i++) { res[i] = zipdata[0] + ((zipdata[1] - zipdata[0]) * i / zipdata.Length); } } else { mPoint[] zippoints = new mPoint[zipdata.Length]; for (int i = 0; i < zipdata.Length; i++) { zippoints[i] = new mPoint(); } for (int i = 0; i < zipdata.Length; i++) { zippoints[i].x = len * i / (zipdata.Length - 1); zippoints[i].y = (int)(zipdata[i] * 10000); } mPoint[] zipres = BezierControl.createCurve(zippoints); for (int i = 0; i < len; i++) { res[i] = (double)zipres[i].y / 10000; } } return(res); }