示例#1
0
        /// <summary>
        /// Gets the length of the signal.
        /// </summary>
        /// <param name="unisensxml">The unisensxml.</param>
        /// <param name="selectedsignals">The selectedsignals.</param>
        /// <returns>length of the signal</returns>
        private static double GetSignalLength(XDocument unisensxml, IEnumerable <XElement> selectedsignals)
        {
            double length = -1;

            try
            {
                XElement unisens = unisensxml.Root;
                if (unisens != null)
                {
                    XAttribute duration = unisens.Attribute("duration");
                    length = double.Parse(duration.Value, System.Globalization.CultureInfo.InvariantCulture);
                }
            }
            catch (Exception)
            {
                foreach (XElement xe in selectedsignals)
                {
                    // no DURATION attribut existent -> calculate duration (in seconds) with length of signal entry
                    switch (xe.Name.LocalName)
                    {
                    case "signalEntry":
                    case "valuesEntry":
                    case "customEntry":
                        // length = length_of_file / (bytes_per_sample * number_of_channels * sample_rate)
                        if (SignalEntry.GetFileFormat(xe) == FileFormat.Bin)
                        {
                            length = new FileInfo(SignalEntry.GetId(xe)).Length /
                                     (SignalEntry.GetDataTypeBytes(SignalEntry.GetBinDataType(xe)) *
                                      MeasurementEntry.GetNumChannels(xe) *
                                      MeasurementEntry.GetSampleRate(xe));
                        }

                        break;
                    }

                    // Exit the foreach loop when length is calculated
                    if (length > 0)
                    {
                        break;
                    }
                }
            }

            if (length < 0)
            {
                throw new Exception("Cannot cut a file without duration information");
            }

            return(length);
        }
示例#2
0
        public static double GetSignalLength(XDocument unisensxml, IEnumerable <XElement> selectedsignals)
        {
            double length = 0;

            try
            {
                XElement xUnisens = unisensxml.Root;
                if (xUnisens != null)
                {
                    length = double.Parse(xUnisens.Attribute("duration").Value);
                }
            }
            catch (Exception e)
            {
                foreach (XElement xe in selectedsignals)
                {
                    // no DURATION attribut existent -> calculate duration (in seconds) with length of signal entry
                    switch (xe.Name.LocalName)
                    {
                    case "signalEntry":
                        // length = length_of_file / (bytes_per_sample * number_of_channels * sample_rate)
                        length = new FileInfo(SignalEntry.GetId(xe)).Length /
                                 (SignalEntry.GetDataTypeBytes(SignalEntry.GetBinDataType(xe)) *
                                  MeasurementEntry.GetNumChannels(xe) *
                                  MeasurementEntry.GetSampleRate(xe));
                        break;
                    }

                    // Exit the foreach loop when length is calculated
                    if (length > 0)
                    {
                        break;
                    }
                }
            }

            return(length);
        }