-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLabel.cs
More file actions
35 lines (29 loc) · 1.16 KB
/
Label.cs
File metadata and controls
35 lines (29 loc) · 1.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
using System;
using System.Collections.Generic;
using System.IO;
using System.Runtime.CompilerServices;
namespace QuickLook.Plugin.WavLabelViewer;
public class LabelLine
{
public double Start { get; set; }
public double End { get; set; }
public string Text { get; set; }
public static LabelLine[] LoadFrom(string labelPath)
{
var labelLines = new List<LabelLine>();
var labelText = File.ReadAllText(labelPath);
string[] labLines = labelText.Split(['\n'], StringSplitOptions.RemoveEmptyEntries);
foreach (var labLine in labLines)
{
var lineSegs = labLine.Split([' '], 3);
var start = Convert100nSecondToSecond(double.Parse(lineSegs[0]));
var end = Convert100nSecondToSecond(double.Parse(lineSegs[1]));
var text = lineSegs[2].TrimEnd();
labelLines.Add(new LabelLine { Start = start, End = end, Text = text });
}
return labelLines.ToArray();
}
public const double LAB_100NS_OFFSET = 10_000_000.0;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static double Convert100nSecondToSecond(double ns) => ns / LAB_100NS_OFFSET;
}