📄 speech.cs
字号:
}
/// <summary>
/// TODO
/// </summary>
/// <param name="i"></param>
/// <returns></returns>
public virtual double[] this[int i]
{
get
{
double[] returnValue = new double[2];
returnValue[0] = (double)f0[i];
returnValue[1] = (double)power[i];
return returnValue;
}
}
/// <summary>
/// TODO
/// </summary>
/// <param name="i"></param>
/// <returns></returns>
public PointF point(int i)
{
if (power != null && f0 != null)
{
double h = (double)f0[i];
PointF returnValue = new PointF();
returnValue.X = (float) h;
h = (double) power[i];
returnValue.Y = (float) h;
return returnValue;
}
else
return new PointF(0, 0);
}
/// <summary>
/// TODO
/// </summary>
/// <returns></returns>
public F0Data Clone()
{
F0Data returnValue = new F0Data();
returnValue.f0 = this.F0;
returnValue.Power = this.Power;
return returnValue;
}
}
/// <summary>
/// TODO
/// </summary>
public class VoiceField : UserControl
{
Matrix scaleMatrix;
private F0Data data;
/// <summary>
/// TODO
/// </summary>
public static readonly int RectWidth = 500;
/// <summary>
/// TODO
/// </summary>
public static readonly int RectHeight = 500;
//krajni hodnoty, ktere vykresluji
/// <summary>
/// TODO
/// </summary>
public static int _minYValue = 2;
/// <summary>
/// TODO
/// </summary>
public static int _maxYValue = 300;
/// <summary>
/// TODO
/// </summary>
public static int _minXValue = 50;
/// <summary>
/// TODO
/// </summary>
public static int _maxXValue = 1000;
/// <summary>
/// TODO
/// </summary>
public static int XMinAxisShift = 50;
/// <summary>
/// TODO
/// </summary>
public static int YMinAxisShift = 50;
/// <summary>
/// TODO
/// </summary>
public static int XMaxAxisShift = 50;
/// <summary>
/// TODO
/// </summary>
public static int YMaxAxisShift = 50;
//vyjadreno v kartezianskych souradnicich
/// <summary>
/// TODO
/// </summary>
public static Point _graphZeroLocation = new Point(XMinAxisShift, YMinAxisShift); //kde na grafu zacina nula
/// <summary>
/// TODO
/// </summary>
public static Point _graphMaxXLocation = new Point(RectWidth - XMaxAxisShift, _graphZeroLocation.Y);
/// <summary>
/// TODO
/// </summary>
public static Point _graphMaxYLocation = new Point(_graphZeroLocation.X, RectHeight - YMaxAxisShift);
/// <summary>
/// Sirka (v bodech) datove oblasti
/// </summary>
public int DataWidth
{ get { return -_graphZeroLocation.X + _graphMaxYLocation.X; } }
/// <summary>
/// Vyska (v bodech) datove oblasti
/// </summary>
public int DataHeight
{ get { return -_graphZeroLocation.Y + _graphMaxYLocation.Y; } }
/// <summary>
/// TODO
/// </summary>
public F0Data Data
{
set { data = value.Clone(); }
get { return data; }
}
/// <summary>
/// TODO
/// </summary>
public VoiceField()
{
ArrayList d = new ArrayList();
d.Add(10);
scaleMatrix = new Matrix();
scaleMatrix.Scale(1,1);
Size = new Size(100, 100);
data = new F0Data();
}
/// <summary>
///
/// </summary>
/// <param name="e"></param>
///<remarks>Vypocet nove transformacni matice</remarks>
protected override void OnResize(EventArgs e)
{
base.OnResize(e);
scaleMatrix.Reset();
float width = (float)Width/RectWidth;
float height = (float)Height / RectHeight;
scaleMatrix.Scale(width, height);
this.Invalidate();
}
/// <summary>
/// TODO
/// </summary>
/// <param name="e"></param>
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
Graphics g2 = e.Graphics;
Rectangle rect = new Rectangle(0, 0, RectWidth, RectHeight);
Region reg = new Region(rect);
g2.Transform = scaleMatrix;
g2.DrawRectangle(Pens.Blue, 1,1,RectWidth, RectHeight);
g2.Clip = reg;
_drawAxis(g2);
_drawData(g2);
g2.Dispose();
}
/// <summary>
/// Transformuje bod do kartezianskeho systemu. Nula je v levem dolnim rohu a osa
/// Y roste smerem nahoru k liste okna.
/// </summary>
/// <param name="point"></param>
/// <returns></returns>
protected void _pointTransform(ref Point point)
{
point.Y = RectHeight - point.Y;
}
/// <summary>
/// Stejne jako funkce _pointTransform, ale s respektovanim omezeni zobrazovane oblasti vzhledem k
/// _graphZeroLocation, _graphMaxXLocation, _graphMaxYLocation. Tedy nula nezacina uplne vlevo dole
/// ale na bode danem _graphZeroLocation
/// </summary>
/// <param name="point"></param>
protected void _pointValueTransform(ref Point point)
{
point.Y = RectHeight - _graphZeroLocation.Y - point.Y;
point.X += _graphZeroLocation.Y;
}
/// <summary>
/// TODO
/// </summary>
/// <param name="g"></param>
/// <param name="point"></param>
/// <param name="text"></param>
/// <param name="font"></param>
protected void _drawHorizontalAxisLine(Graphics g, Point point, String text, Font font)
{
g.DrawLine(Pens.Black, point.X+3, point.Y, point.X-3, point.Y);
SizeF fontSize = g.MeasureString(text, font);
g.DrawString(text, font, Brushes.Black, point.X - fontSize.Width - 10, point.Y-fontSize.Height/2);
}
/// <summary>
/// Vykresleni cary pri vykreslovani meritka grafu
/// </summary>
/// <param name="g"></param>
/// <param name="point"></param>
/// <param name="text"></param>
/// <param name="font"></param>
/// <todo>natoceni textu</todo>
protected void _drawVerticalAxisLine(Graphics g, Point point, String text, Font font)
{
g.DrawLine(Pens.Black, point.X, point.Y+3, point.X, point.Y-3);
SizeF fontSize = g.MeasureString(text, font);
g.DrawString(text, font, Brushes.Black, point.X - fontSize.Width - 10, point.Y - fontSize.Height / 2);
}
/// <summary>
/// Vykresleni souradneho systemu
/// </summary>
/// <param name="g">Graphics context</param>
/// <remarks>Tady je problem s presnosti vykreslovani polohy meritka na osach!</remarks>
protected void _drawAxis(Graphics g)
{
Point p1 = new Point();
Point p2 = new Point();
p1 = _graphZeroLocation; _pointTransform(ref p1);
p2 = _graphMaxXLocation; _pointTransform(ref p2);
g.DrawLine(Pens.Black, p1, p2);
p2 = _graphMaxYLocation; _pointTransform(ref p2);
g.DrawLine(Pens.Black, p1, p2);
//parametry popisku
String text = "";
Font font = new Font("Times New Roman", 10);
//vykresleni popisku osy Y --- meritka na ose Y
int numOfYLines = 5; //pocet carek na ose y
for (int i = 0; i <= numOfYLines; i++)
{
//vytvoreni textu, ktery bude u meritka vypsan jako popisek
double value = ((double) (_maxYValue - _minYValue)) / numOfYLines;
value *= i;
value += _minYValue;
text = value.ToString();
//vypocet bodu, kde dojde k zobrazeni linky
p1.X = YMinAxisShift;
value = ((double) (-_graphZeroLocation.Y + _graphMaxYLocation.Y)) / numOfYLines;
p1.Y = (int) (value * i) + YMinAxisShift;
_pointTransform(ref p1);
_drawHorizontalAxisLine(g, p1, text, font);
}
//vykresleni popisku osy X --- meritka na ose X
int numOfXLines = 7; //pocet carek na ose x
for (int i = 0; i <= numOfXLines; i++)
{
//vytvoreni textu, ktery bude u meritka vypsan jako popisek
double value = ((double)(_maxXValue - _minXValue)) / numOfXLines;
value *= i;
value += _minXValue;
text = value.ToString();
//vypocet bodu, kde dojde k zobrazeni linky
p1.Y = YMinAxisShift;
value = ((double)(-_graphZeroLocation.X + _graphMaxXLocation.X)) / numOfXLines;
p1.X = (int)(value * i) + XMinAxisShift;
_pointTransform(ref p1);
_drawVerticalAxisLine(g, p1, text, font);
}
}
/// <summary>
/// TODO
/// </summary>
/// <param name="g"></param>
/// <param name="pointF"></param>
protected void _drawCross(Graphics g, PointF pointF)
{
if (pointF.Y > _minYValue && pointF.Y < _maxYValue && pointF.X > _minXValue && pointF.X < _maxXValue)
{
float meritkoY = (float)_maxYValue / DataHeight; //-200dB je maximum a skaluji na nej
pointF.Y /= meritkoY;
Point point = new Point((int)pointF.X, (int)pointF.Y);
_pointValueTransform(ref point);
g.DrawLine(Pens.Red, point.X - 3, point.Y, point.X + 3, point.Y);
g.DrawLine(Pens.Red, point.X, point.Y - 3, point.X, point.Y + 3);
}
}
/// <summary>
/// TODO
/// </summary>
/// <param name="g"></param>
protected void _drawData(Graphics g)
{
if (data.Count > 0)
{
for (int i = 0; i < data.Count; i++)
_drawCross(g, data.point(i));
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -