working on it ...

## Filters

Sort by

Found 2,097 snippets matching: float

### 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);
}```

### 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;
}```

### 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```

### 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));
}```

### 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))));
}```

### 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);
}```

### 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));
}```

### 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));
}```

### 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))));
}```

### 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