示例#1
0
 public void ParseData()
 {
     Sanity.Requires(DeepFlag, "Parse data requires deep parse.");
     ParseDataFlag = true;
     AudioBits     = BlockAlign / NumChannels * 8;
     DataValues    = CalcValues().ToArray();
     RMS           = CalculateRms();
 }
示例#2
0
 public static byte[] ReadBytes(string path, int n)
 {
     Sanity.Requires(File.Exists(path), "The file doesn't exist.");
     Sanity.Requires(n >= 0, "The bytes required cannot be negative.");
     using (FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read))
     {
         using (BinaryReader br = new BinaryReader(fs))
         {
             return(br.ReadBytes(n));
         }
     }
 }
示例#3
0
 /// <summary>
 /// Calculate the root mean square of the audio.
 /// </summary>
 /// <returns>The RMS value</returns>
 private double CalculateRms()
 {
     Sanity.Requires(ParseDataFlag, "The wave data has to be parsed in order to get RMS.");
     return(Math.Sqrt(DataValues.Sum(x => x * x) / DataValues.Length));
 }
示例#4
0
 public static int ToInt24(byte[] bytes, int offset)
 {
     Sanity.Requires(offset + 3 <= bytes.Length, "Offset exceeds array length.");
     return(ToInt24(bytes[offset], bytes[offset + 1], bytes[offset + 2]));
 }