/// <summary> /// Generates a signal. /// </summary> /// <returns>The signal.</returns> public override float Generate() { switch (WindowType) { case WindowType.None: this.windowMethod = null; break; case WindowType.Hann: this.windowMethod = Hann; break; case WindowType.Cosine: this.windowMethod = Cosine; break; case WindowType.Rectangular: this.windowMethod = Rectangular; break; case WindowType.Triangular: this.windowMethod = Triangular; break; case WindowType.BlackmanHarris: this.windowMethod = BlackmanHarris; break; case WindowType.BlackmanNutall: this.windowMethod = BlackmanNutall; break; case WindowType.Gauss: this.windowMethod = Gauss; break; default: this.windowMethod = null; break; } this.CurrentSample = this.windowMethod != null ? (float)this.windowMethod(this.Phase) : 0f; this.Phase += this.increment; if (this.Phase >= 1.0) { this.Phase -= 1.0; } return(this.CurrentSample); }
public static double GetWindow(int i, int signalLength, double windowLen, WindowMethod windowType) { var pos = i / (double)signalLength; if (pos < 1 - windowLen) { return(1.0); } if (i >= signalLength) { return(0.0); } if (windowLen < 0.002) // no effect of tiny window { return(1.0); } var posInWindow = (pos - (1 - windowLen)) / windowLen; if (windowType == WindowMethod.Truncate) { return(0.0); } if (windowType == WindowMethod.Linear) { return(1 - posInWindow); } if (windowType == WindowMethod.Logarithmic) { return(AudioLib.Utils.DB2gain(-posInWindow * 60)); } if (windowType == WindowMethod.Cosine) { return((Math.Cos(posInWindow * Math.PI) + 1) * 0.5); } return(1.0); }
public void Validate() { if (this.GetEncoderModeIndex() < 0) { throw new Exception("unsupported encoder mode"); } this.SetDefaultValuesForMode(); if (Padding < 0) { throw new Exception("unsupported padding value " + Padding.ToString()); } if (BlockSize != 0 && (BlockSize < 256 || BlockSize >= FlakeConstants.MAX_BLOCKSIZE)) { throw new Exception("unsupported block size " + BlockSize.ToString()); } if (MinLPCOrder > MaxLPCOrder || MaxLPCOrder > lpc.MAX_LPC_ORDER) { throw new Exception("invalid MaxLPCOrder " + MaxLPCOrder.ToString()); } if (MinFixedOrder < 0 || MinFixedOrder > 4) { throw new Exception("invalid MinFixedOrder " + MinFixedOrder.ToString()); } if (MaxFixedOrder < 0 || MaxFixedOrder > 4) { throw new Exception("invalid MaxFixedOrder " + MaxFixedOrder.ToString()); } if (MinPartitionOrder < 0) { throw new Exception("invalid MinPartitionOrder " + MinPartitionOrder.ToString()); } if (MinPartitionOrder > MaxPartitionOrder || MaxPartitionOrder > 8) { throw new Exception("invalid MaxPartitionOrder " + MaxPartitionOrder.ToString()); } if (PredictionType == PredictionType.None) { throw new Exception("invalid PredictionType " + PredictionType.ToString()); } if (PredictionType != PredictionType.Fixed) { if (WindowMethod == WindowMethod.Invalid) { throw new InvalidOperationException("invalid WindowMethod " + WindowMethod.ToString()); } if (WindowFunctions == WindowFunction.None) { throw new InvalidOperationException("invalid WindowFunctions " + WindowFunctions.ToString()); } if (EstimationDepth > 32 || EstimationDepth < 1) { throw new InvalidOperationException("invalid EstimationDepth " + EstimationDepth.ToString()); } if (MinPrecisionSearch < 0 || MinPrecisionSearch >= lpc.MAX_LPC_PRECISIONS) { throw new Exception("unsupported MinPrecisionSearch value"); } if (MaxPrecisionSearch < 0 || MaxPrecisionSearch >= lpc.MAX_LPC_PRECISIONS) { throw new Exception("unsupported MaxPrecisionSearch value"); } if (MaxPrecisionSearch < MinPrecisionSearch) { throw new Exception("unsupported MaxPrecisionSearch value"); } } if (!AllowNonSubset && !IsSubset()) { throw new Exception("the encoding parameters specified do not conform to the FLAC Subset"); } }
public int flake_set_defaults(int lvl) { compression = lvl; if ((lvl < 0 || lvl > 12) && (lvl != 99)) { return -1; } // default to level 5 params window_function = WindowFunction.Flattop | WindowFunction.Tukey; order_method = OrderMethod.Akaike; stereo_method = StereoMethod.Evaluate; window_method = WindowMethod.Evaluate; block_size = 0; block_time_ms = 105; prediction_type = PredictionType.Search; min_prediction_order = 1; max_prediction_order = 12; estimation_depth = 1; min_fixed_order = 2; max_fixed_order = 2; min_partition_order = 0; max_partition_order = 8; variable_block_size = 0; lpc_min_precision_search = 1; lpc_max_precision_search = 1; do_seektable = true; // differences from level 7 switch (lvl) { case 0: block_time_ms = 53; prediction_type = PredictionType.Fixed; stereo_method = StereoMethod.Independent; max_partition_order = 6; break; case 1: prediction_type = PredictionType.Levinson; stereo_method = StereoMethod.Independent; window_function = WindowFunction.Bartlett; max_prediction_order = 8; max_partition_order = 6; break; case 2: stereo_method = StereoMethod.Independent; window_function = WindowFunction.Bartlett; max_partition_order = 6; break; case 3: stereo_method = StereoMethod.Estimate; window_function = WindowFunction.Bartlett; max_prediction_order = 8; break; case 4: stereo_method = StereoMethod.Estimate; window_function = WindowFunction.Bartlett; break; case 5: stereo_method = StereoMethod.Estimate; window_method = WindowMethod.Estimate; break; case 6: stereo_method = StereoMethod.Estimate; break; case 7: break; case 8: estimation_depth = 2; min_fixed_order = 0; lpc_min_precision_search = 0; break; case 9: window_function = WindowFunction.Bartlett; max_prediction_order = 32; break; case 10: min_fixed_order = 0; max_fixed_order = 4; max_prediction_order = 32; //lpc_max_precision_search = 2; break; case 11: min_fixed_order = 0; max_fixed_order = 4; max_prediction_order = 32; estimation_depth = 5; //lpc_max_precision_search = 2; variable_block_size = 4; break; } return 0; }
public int flake_set_defaults(FlakeWriterSettings settings) { // default to level 7 params window_function = WindowFunction.Flattop | WindowFunction.Tukey; order_method = OrderMethod.Akaike; stereo_method = StereoMethod.Evaluate; window_method = WindowMethod.Evaluate; block_time_ms = 105; prediction_type = PredictionType.Search; estimation_depth = 1; variable_block_size = 0; lpc_min_precision_search = 1; lpc_max_precision_search = 1; do_seektable = true; development_mode = -1; // differences from level 7 switch (settings.EncoderModeIndex) { case 0: block_time_ms = 53; prediction_type = PredictionType.Fixed; stereo_method = StereoMethod.Independent; break; case 1: prediction_type = PredictionType.Levinson; stereo_method = StereoMethod.Independent; window_function = WindowFunction.Bartlett; break; case 2: stereo_method = StereoMethod.Independent; window_function = WindowFunction.Bartlett; break; case 3: stereo_method = StereoMethod.Estimate; window_function = WindowFunction.Bartlett; break; case 4: stereo_method = StereoMethod.Estimate; window_function = WindowFunction.Bartlett; break; case 5: stereo_method = StereoMethod.Estimate; window_method = WindowMethod.Estimate; break; case 6: stereo_method = StereoMethod.Estimate; break; case 7: break; case 8: estimation_depth = 2; lpc_min_precision_search = 0; break; case 9: window_function = WindowFunction.Bartlett; break; case 10: //lpc_max_precision_search = 2; break; case 11: estimation_depth = 5; //lpc_max_precision_search = 2; variable_block_size = 4; break; } return 0; }
public int set_defaults(int lvl) { compression = lvl; if ((lvl < 0 || lvl > 12) && (lvl != 99)) { return -1; } // default to level 5 params window_function = WindowFunction.Flattop | WindowFunction.Tukey; order_method = OrderMethod.Estimate; stereo_method = StereoMethod.Evaluate; window_method = WindowMethod.Evaluate; block_size = 0; block_time_ms = 105; min_modifier = 4; max_modifier = 4; min_prediction_order = 1; max_prediction_order = 12; estimation_depth = 1; adaptive_passes = 0; do_seektable = false; chunk_size = 5; // differences from level 6 switch (lvl) { case 0: stereo_method = StereoMethod.Independent; window_function = WindowFunction.Hann; max_prediction_order = 6; break; case 1: stereo_method = StereoMethod.Independent; window_function = WindowFunction.Hann; max_prediction_order = 8; break; case 2: stereo_method = StereoMethod.Estimate; window_function = WindowFunction.Hann; max_prediction_order = 6; break; case 3: stereo_method = StereoMethod.Estimate; window_function = WindowFunction.Hann; max_prediction_order = 8; break; case 4: stereo_method = StereoMethod.Estimate; window_method = WindowMethod.Estimate; max_prediction_order = 8; break; case 5: stereo_method = StereoMethod.Estimate; window_method = WindowMethod.Estimate; break; case 6: stereo_method = StereoMethod.Estimate; break; case 7: stereo_method = StereoMethod.Estimate; adaptive_passes = 1; min_modifier = 2; break; case 8: adaptive_passes = 1; min_modifier = 2; break; case 9: adaptive_passes = 1; max_prediction_order = 30; min_modifier = 2; break; case 10: estimation_depth = 2; adaptive_passes = 2; max_prediction_order = 30; min_modifier = 2; break; } return 0; }