Example #1
0
        public ValueOrder valueOrder = ValueOrder.SampleMajor;      // if SampleMajor, then the input is ordered by sample first (sample elements contiguously in memory) and channels second (i.e. <smpl0 - ch0> - <smpl0 - ch1> ...)
                                                                    // if ChannelMajor, then the input is ordered by channel first (channel elements contiguously in memory) and samples second (i.e. <smpl0 - ch0> - <smpl1 - ch0> ...)
        //private int[] types = null;                               //
        //private string[] channelNames;                            // Channel names in package description?

        public SamplePackageFormat(int channels, int samples, double rate, ValueOrder valueOrder)
        {
            this.numChannels = channels;
            this.numSamples  = samples;
            this.packageRate = rate;
            this.valueOrder  = valueOrder;
        }
Example #2
0
 public AgentOrder.E_OrderType GetOrder()
 {
     ValueOrder v = PropValue as ValueOrder; return(v != null ? v.Order : AgentOrder.E_OrderType.E_NONE);
 }
Example #3
0
 public OrderType GetOrder()
 {
     ValueOrder v = PropValue as ValueOrder; return(v != null ? v.Order : OrderType.NONE);
 }
Example #4
0
        public bool configure(out SamplePackageFormat output)
        {
            // retrieve the number of output channels
            outputChannels = parameters.getValue <int>("Channels");
            if (outputChannels <= 0)
            {
                logger.Error("Number of output channels cannot be 0");
                output = null;
                return(false);
            }

            // retrieve the sample-package rate
            samplePackageRate = parameters.getValue <double>("PackageRate");
            if (samplePackageRate <= 0)
            {
                logger.Error("The sample-package rate cannot be 0 or lower");
                output = null;
                return(false);
            }

            // retrieve the high precision setting
            highPrecision = parameters.getValue <bool>("HighPrecision");

            // retrieve the number of output channels
            samplesPerPackage = parameters.getValue <int>("SamplesPerPackage");
            if (samplesPerPackage <= 0)
            {
                logger.Error("Number of samples per package cannot be 0");
                output = null;
                return(false);
            }
            if (samplesPerPackage > 65535)
            {
                logger.Error("Number of samples per package cannot be higher than 65535");
                output = null;
                return(false);
            }

            // retrieve the sample value order
            //sampleValueOrder = (parameters.getValue<int>("ValueOrder") == 0 ? ValueOrder.ChannelMajor : ValueOrder.SampleMajor);
            sampleValueOrder = ValueOrder.SampleMajor;

            // create a sampleformat
            output = new SamplePackageFormat(outputChannels, samplesPerPackage, samplePackageRate, sampleValueOrder);

            // calculate the sample-package interval
            samplePackageIntervalMs = (int)Math.Floor(1000.0 / samplePackageRate);

            // check if the sample-package rate is above 1000hz
            if (samplePackageRate > 1000)
            {
                // enable the high precision timing
                highPrecision = true;

                // message
                logger.Warn("Because the sample-package rate is larger than 1000hz, the high precision timer will be used");
            }

            // check if high precision timing is enabled
            if (highPrecision)
            {
                // calculate the sample-package interval for the high precision timing
                samplePackageIntervalTicks = (long)Math.Round(Stopwatch.Frequency * (1.0 / samplePackageRate));

                // message
                logger.Warn("High precision timer enabled. The majority of the Palmtree OS-process will be claimed by the source-module, this might have consequences for the pipeline performance and/or your system performance");
            }

            // TODO: debug, log as sourceinput
            //for (int i = 0; i < outputChannels; i++)
            //    Data.registerSourceInputStream(("Ch" + i), samplesPerPackage, samplePackageRate);

            // flag as configured
            configured = true;

            // return success
            return(true);
        }
Example #5
0
        public bool configure(out SamplePackageFormat output)
        {
            // retrieve the number of output channels
            outputChannels = parameters.getValue <int>("Channels");
            if (outputChannels <= 0)
            {
                logger.Error("Number of output channels cannot be 0");
                output = null;
                return(false);
            }

            // retrieve the sample-package rate
            samplePackageRate = parameters.getValue <double>("SamplePackageRate");
            if (samplePackageRate <= 0)
            {
                logger.Error("The sample-package rate cannot be 0 or lower");
                output = null;
                return(false);
            }

            // retrieve the high precision setting
            highPrecision = parameters.getValue <bool>("HighPrecision");

            // retrieve the number of output channels
            samplesPerPackage = parameters.getValue <int>("SamplesPerPackage");
            if (samplesPerPackage <= 0)
            {
                logger.Error("Number of samples per package cannot be 0");
                output = null;
                return(false);
            }
            if (samplesPerPackage > 65535)
            {
                logger.Error("Number of samples per package cannot be higher than 65535");
                output = null;
                return(false);
            }

            // retrieve the sample value order
            //sampleValueOrder = (parameters.getValue<int>("ValueOrder") == 0 ? ValueOrder.ChannelMajor : ValueOrder.SampleMajor);
            sampleValueOrder = ValueOrder.SampleMajor;

            // create a sampleformat
            output = new SamplePackageFormat(outputChannels, samplesPerPackage, samplePackageRate, sampleValueOrder);

            // calculate the sample-package interval
            samplePackageIntervalMs = (int)Math.Floor(1000.0 / samplePackageRate);

            // check if the sample-package rate is above 1000hz
            if (samplePackageRate > 1000)
            {
                // enable the high precision timing
                highPrecision = true;

                // message
                logger.Warn("Because the sample-package rate is larger than 1000hz, the high precision timer will be used");
            }

            // check if high precision timing is enabled
            if (highPrecision)
            {
                // calculate the sample-package interval for the high precision timing
                samplePackageIntervalTicks = (long)Math.Round(Stopwatch.Frequency * (1.0 / samplePackageRate));

                // message
                logger.Warn("High precision timer enabled. The majority of the Palmtree OS-process will be claimed by the source-module, this might have consequences for the pipeline performance and/or your system performance");
            }

            // retrieve key settings
            string[][] keys = parameters.getValue <string[][]>("Keys");
            if (keys == null || keys.Length == 0)
            {
                // no keys specified

                mConfigKeys           = new Keys[0];
                mConfigOutputChannels = new int[0];
                mConfigPressed        = new double[0];
                mConfigNotPressed     = new double[0];
            }
            else
            {
                // keys present

                if (keys.Length != 4)
                {
                    logger.Error("Keys parameter must have 4 columns (Key, Output channel, Pressed, Not-pressed)");
                    return(false);
                }

                // resize the variables
                mConfigKeys           = new Keys[keys[0].Length];         // char converted to virtual key
                mConfigOutputChannels = new int[keys[0].Length];          // for the values stored in this array: value 0 = channel 1
                mConfigPressed        = new double[keys[0].Length];
                mConfigNotPressed     = new double[keys[0].Length];

                // loop through the rows
                for (int row = 0; row < keys[0].Length; ++row)
                {
                    // try to convert the key character to an int
                    string key = keys[0][row].ToUpper();
                    if (key.Length != 1 || !(new Regex(@"^[A-Z0-9]*$")).IsMatch(key))
                    {
                        logger.Error("The key value '" + key + "' is not a valid key (should be a single character, a-z or 0-9)");
                        return(false);
                    }
                    mConfigKeys[row] = (Keys)key[0];     // capital characters A-Z and numbers can be directly saved as int (directly used/emulated as virtual keys)

                    // try to parse the channel number
                    int channel = 0;
                    if (!int.TryParse(keys[1][row], out channel))
                    {
                        logger.Error("The value '" + keys[1][row] + "' is not a valid output channel value (should be a positive integer)");
                        return(false);
                    }
                    if (channel < 1)
                    {
                        logger.Error("Output channels must be positive integers");
                        return(false);
                    }
                    if (channel > outputChannels)
                    {
                        logger.Error("The output channel value '" + keys[1][row] + "' exceeds the number of channels coming out of the filter (#outputChannels: " + outputChannels + ")");
                        return(false);
                    }
                    mConfigOutputChannels[row] = channel - 1;   // -1 since the user input the channel 1-based and we use a 0-based array

                    // try to parse the pressed value
                    double doubleValue = 0;
                    if (!double.TryParse(keys[2][row], NumberStyles.AllowDecimalPoint | NumberStyles.AllowLeadingSign, Parameters.NumberCulture, out doubleValue))
                    {
                        logger.Error("The value '" + keys[2][row] + "' is not a valid double value");
                        return(false);
                    }
                    mConfigPressed[row] = doubleValue;

                    // try to parse the not-pressed value
                    doubleValue = 0;
                    if (!double.TryParse(keys[3][row], NumberStyles.AllowDecimalPoint | NumberStyles.AllowLeadingSign, Parameters.NumberCulture, out doubleValue))
                    {
                        logger.Error("The value '" + keys[3][row] + "' is not a valid double value");
                        return(false);
                    }
                    mConfigNotPressed[row] = doubleValue;
                }
            }

            // flag as configured
            configured = true;

            // return success
            return(true);
        }