working on it ...

Filters

Explore Public Snippets

Sort by

Found 2,097 snippets matching: float

    public by Geometry  76097  0  5  0

    Convert: Converts a array of signed 32-bit integer samples into a array of 32-bit floating point samples.

    Converts a array of signed 32-bit integer samples into a array of 32-bit floating point samples. The original sample. The resulting sample.
    /// <summary>
    ///   Converts a array of signed 32-bit integer samples
    ///   into a array of 32-bit floating point samples.
    /// </summary>
    /// 
    /// <param name="from">The original sample.</param>
    /// <param name="to">The resulting sample.</param>
    /// 
    public static void Convert(Int32[] from, Int32[] to)
    {
        for (int i = 0; i < from.Length; i++)
            to[i] = (int)((double)from[i] * 0x7FFFFFFF);
    }

    public by Geometry  62423  0  5  0

    Round: Rounds a double-precision floating-point number array to a specified number of fractional digits.

    Rounds a double-precision floating-point number array to a specified number of fractional digits.
    /// <summary>
    ///   Rounds a double-precision floating-point number array to a specified number of fractional digits.
    /// </summary>
    public static double[] Round(double[] vector, int decimals = 0)
    {
        if (vector == null) throw new ArgumentNullException("vector");
    
        double[] result = new double[vector.Length];
        for (int i = 0; i < result.Length; i++)
            result[i] = Math.Round(vector[i], decimals);
        return result;
    }

    public by cghersi  3789  1  9  0

    Safe conversion of string to float in SQL Server 2012

    This function allows a safe conversion of strings to float values.
    CREATE FUNCTION [dbo].[isFloatTryConvertible] (@str nvarchar(70))
    RETURNS bit WITH SCHEMABINDING
    AS
    BEGIN
    	DECLARE @res bit = 0;
    
    	IF (TRY_CONVERT(float, @str) IS NOT NULL)
    		SET @res = 1;
    	
    	RETURN @res;
    END

    public by Geometry  1385  0  5  0

    Convert: Converts a 32-bit float sample into a 16-bit integer sample.

    Converts a 32-bit float sample into a 16-bit integer sample. The original sample. The resulting sample.
    /// <summary>
    ///   Converts a 32-bit float sample
    ///   into a 16-bit integer sample.
    /// </summary>
    /// <param name="from">The original sample.</param>
    /// <param name="to">The resulting sample.</param>
    public static void Convert(float from, out short to)
    {
        to = (short)(from * (32767f));
    }

    public by Geometry  1091  0  6  0

    Convert: Converts a array of signed 32-bit float samples into a array of 8-bit unsigned byte samples.

    Converts a array of signed 32-bit float samples into a array of 8-bit unsigned byte samples. The original sample. The resulting sample.
    /// <summary>
    ///   Converts a array of signed 32-bit float samples
    ///   into a array of 8-bit unsigned byte samples.
    /// </summary>
    /// 
    /// <param name="from">The original sample.</param>
    /// <param name="to">The resulting sample.</param>
    /// 
    public static void Convert(float[] from, byte[] to)
    {
        for (int i = 0; i < from.Length; i++)
            to[i] = (byte)(128 + ((byte)(to[i] * (127f))));
    }

    public by Geometry  1081  0  6  0

    FromArray: Creates a new Signal from a float array.

    Creates a new Signal from a float array.
    /// <summary>
    ///   Creates a new Signal from a float array.
    /// </summary>
    /// 
    public static Signal FromArray(Array signal, int size, int channels, int sampleRate,
        SampleFormat format = SampleFormat.Format32BitIeeeFloat)
    {
        int sampleSize = GetSampleSize(format) / 8;
    
        byte[] buffer = new byte[size * sampleSize];
        Buffer.BlockCopy(signal, 0, buffer, 0, buffer.Length);
        int samples = size / channels;
    
        return new Signal(buffer, channels, samples, sampleRate, format);
    }

    public by Geometry  1000  0  6  0

    Convert: Converts a matrix of 32-bit float samples into a matrix of 16-bit integer samples.

    Converts a matrix of 32-bit float samples into a matrix of 16-bit integer samples. The original sample. The resulting sample.
    #endregion
    
    #region From Single (float) to Int16 (short)
    /// <summary>
    ///   Converts a matrix of 32-bit float samples
    ///   into a matrix of 16-bit integer samples.
    /// </summary>
    /// <param name="from">The original sample.</param>
    /// <param name="to">The resulting sample.</param>
    public static void Convert(float[][] from, short[][] to)
    {
        for (int i = 0; i < from.Length; i++)
            for (int j = 0; i < from[0].Length; j++)
                to[i][j] = (short)(from[i][j] * (32767f));
    }

    public by Geometry  998  0  5  0

    Convert: Converts a array of 32-bit float samples into a array of 16-bit integer samples.

    Converts a array of 32-bit float samples into a array of 16-bit integer samples. The original sample. The resulting sample.
    /// <summary>
    ///   Converts a array of 32-bit float samples
    ///   into a array of 16-bit integer samples.
    /// </summary>
    /// <param name="from">The original sample.</param>
    /// <param name="to">The resulting sample.</param>
    public static void Convert(float[] from, short[] to)
    {
        for (int i = 0; i < from.Length; i++)
            to[i] = (short)(from[i] * (32767f));
    }

    public by Geometry  971  0  5  0

    Convert: Converts a signed 32-bit float sample into a 8-bit unsigned byte sample.

    Converts a signed 32-bit float sample The original sample. The resulting sample.
    /// <summary>
    ///   Converts a signed 32-bit float sample
    ///   into a 8-bit unsigned byte sample.
    /// </summary>
    /// <param name="from">The original sample.</param>
    /// <param name="to">The resulting sample.</param>
    public static void Convert(float from, out byte to)
    {
        to = (byte)(128 + ((byte)(from * (127f))));
    }

    public by Geometry  795  0  5  0

    Convert: Converts a matrix of signed 32-bit float samples into a matrix of 8-bit unsigned byte samples.

    Converts a matrix of signed 32-bit float samples into a matrix of 8-bit unsigned byte samples. The original sample. The resulting sample.
    #endregion
    
    #endregion
    
    
    #region From Single (float)
    
    #region From Single (float) to UInt8 (byte)
    /// <summary>
    ///   Converts a matrix of signed 32-bit float samples
    ///   into a matrix of 8-bit unsigned byte samples.
    /// </summary>
    /// 
    /// <param name="from">The original sample.</param>
    /// <param name="to">The resulting sample.</param>
    /// 
    public static void Convert(float[][] from, byte[][] to)
    {
        for (int i = 0; i < from.Length; i++)
            for (int j = 0; j < from[0].Length; j++)
                to[i][j] = (byte)(128 + ((byte)(to[i][j] * (127f))));
    }
    • Public Snippets
    • Channels Snippets