public int getValueInSamples() { // retrieve the value as integer int val = value; int intSamples = 0; // check if the unit is set in seconds if (unit == Parameters.Units.Seconds) { // flagged as seconds // convert, check rounding double samples = SampleConversion.timeToSamplesAsDouble(val); // conversion result as double, no rounding before intSamples = (int)Math.Round(samples); if (samples != intSamples) { // message logger.Warn("Value for parameter '" + this.Name + "' (parameter set: '" + this.getParentSetName() + "') was retrieved in number of samples (" + val + "s * " + SampleConversion.sampleRate() + "Hz), but has been rounded from " + samples + " samples to " + intSamples + " samples"); } // convert and return return(intSamples); } else { // not flagged as seconds // assume the value is in samples and return the value return(val); } }
public int[] getValueInSamples() { // create an array of values (in samples) to return int[] retValues = new int[values.Length]; // loop through the array for (int i = 0; i < retValues.Length; i++) { // retrieve the value double val = values[i]; int intSamples = 0; // check if the unit is set in seconds if (units[i] == Parameters.Units.Seconds) { // flagged as seconds // convert, check rounding double samples = SampleConversion.timeToSamplesAsDouble(val); // conversion result as double, no rounding before intSamples = (int)Math.Round(samples); if (samples != intSamples) { // message logger.Warn("Value in parameter '" + this.Name + "' (parameter set: '" + this.getParentSetName() + "') was retrieved in number of samples (" + val + "s * " + SampleConversion.sampleRate() + "Hz), but has been rounded from " + samples + " sample(s) to " + intSamples + " sample(s)"); } } else { // not flagged as seconds // convert double to int, check rounding intSamples = (int)Math.Round(val); if (val != intSamples) { // message logger.Warn("Value in parameter '" + this.Name + "' (parameter set: '" + this.getParentSetName() + "') was retrieved in number of samples, but has been rounded from " + val + " sample(s) to " + intSamples + " samples"); } } retValues[i] = intSamples; } // return number of samples return(retValues); }
public int[][] getValueInSamples(int[] ignoreColumns) { // create an matrix of values (in samples) to return int[][] retValues = new int[values.Length][]; // loop through the columns for (int c = 0; c < units.Length; c++) { // check if column should be ignored, if so skip if (ignoreColumns != null && ignoreColumns.Length > 0) { bool ignoreColumn = false; for (int j = 0; j < ignoreColumns.Length; j++) { if (c == ignoreColumns[j]) { ignoreColumn = true; break; } } if (ignoreColumn) { continue; } } // create array of values (in samples) for this column retValues[c] = new int[values[c].Length]; // loop through the rows for (int r = 0; r < values[c].Length; r++) { // retrieve the value int val = values[c][r]; int intSamples = 0; // check if the unit is set in seconds if (units[c][r] == Parameters.Units.Seconds) { // flagged as seconds // convert, check rounding double samples = SampleConversion.timeToSamplesAsDouble(val); // conversion result as double, no rounding before intSamples = (int)Math.Round(samples); if (samples != intSamples) { // message logger.Warn("Value in parameter '" + this.Name + "' (parameter set: '" + this.getParentSetName() + "') was retrieved in number of samples (" + val + "s * " + SampleConversion.sampleRate() + "Hz), but has been rounded from " + samples + " samples to " + intSamples + " samples"); } // set the rounded value retValues[c][r] = intSamples; } else { // not flagged as seconds // assume the value is in samples and set the value retValues[c][r] = val; } } } // return number of samples return(retValues); }