Exemple #1
0
        static Trig()
        {
            _mask = ~(-1 << ResolutionInBits);
            var sampleCount = _mask + 1;

            _sinBuffer = UnsafeBuffer.Create(sampleCount, sizeof(float));
            _cosBuffer = UnsafeBuffer.Create(sampleCount, sizeof(float));
            _sinPtr = (float*) _sinBuffer;
            _cosPtr = (float*) _cosBuffer;

            const float twoPi = (float) (Math.PI * 2.0);
            const float pi2 = (float) (Math.PI / 2.0);
            _indexScale = sampleCount / twoPi;

            for (var i = 0; i < sampleCount; i++)
            {
                _sinPtr[i] = (float) Math.Sin((i + 0.5f) / sampleCount * twoPi);
                _cosPtr[i] = (float) Math.Cos((i + 0.5f) / sampleCount * twoPi);
            }

            for (var angle = 0.0f; angle < twoPi; angle += pi2)
            {
                _sinPtr[(int) (angle * _indexScale) & _mask] = (float) Math.Sin(angle);
                _cosPtr[(int) (angle * _indexScale) & _mask] = (float) Math.Cos(angle);
            }
        }
Exemple #2
0
        private void ProcessSquelch(float* audio, int length)
        {
            if (_squelchThreshold > 0)
            {
                if (_hissBuffer == null || _hissBuffer.Length != length)
                {
                    _hissBuffer = UnsafeBuffer.Create(length, sizeof(float));
                    _hissPtr = (float*) _hissBuffer;
                }

                Utils.Memcpy(_hissPtr, audio, length * sizeof(float));

                _hissFilter.Process(_hissPtr, length);

                for (var i = 0; i < _hissBuffer.Length; i++)
                {
                    var n = (1 - _noiseAveragingRatio) * _noiseLevel + _noiseAveragingRatio * Math.Abs(_hissPtr[i]);
                    if (!float.IsNaN(n))
                    {
                        _noiseLevel = n;
                    }
                    if (_noiseLevel > _noiseThreshold)
                    {
                        audio[i] = 0.0f;
                    }
                }

                _isSquelchOpen = _noiseLevel < _noiseThreshold;
            }
            else
            {
                _isSquelchOpen = true;
            }
        }
Exemple #3
0
        static void Main(string[] args)
        {
            Console.Write("Log name: ");
            name = Console.ReadLine();
            log = new SEC.Log.Log(@"C:\temp\" + name + ".log");
            exporter = new SEC.Log.Exporter(log);

            Console.Write("Log description: ");
            desc = Console.ReadLine();

            status = (float*)Marshal.AllocHGlobal(sizeof(float));
            *status = 0;

            //Thread exporterThread = new Thread(new ThreadStart(ExportToSql));
            //exporterThread.Start();

            //double currentStatus = Math.Round(*status, 0);

            //while (exporterThread.IsAlive)
            //{
            //    if (currentStatus != Math.Round(*status, 0))
            //    {
            //        currentStatus = Math.Round(*status, 0);
            //        Console.WriteLine(currentStatus);
            //    }                
            //}

            exporter.ExportToSqlServer(@"localhost", "SEC", desc, status);

            Marshal.FreeHGlobal((IntPtr)status);

            Console.WriteLine("Done :)");
            Console.ReadLine();
        }
 public VertexCodec(Vector3* sPtr, int count, bool removeZ)
 {
     _srcCount = count;
     _srcElements = 3;
     _pData = (float*)sPtr;
     Evaluate(removeZ);
 }
Exemple #5
0
        private unsafe void btnExtractContent_Click(object sender, EventArgs e)
        {
            // Checking if we have the data that we need to get started.
            if (this.InputOk())
            {
                // Marks the reseted flag to false.
                // This will cause the progress bar to be reseted once the thread dies.
                this.reseted = false;

                // Disabling the controls.
                this.ChangeControlsStatus(false);

                // Creates the log.
                this.myLog = new Log.Log(txtLogPath.Text);

                // Check if the status variable isn't already allocated.
                if (this.status != null)
                {
                    Marshal.FreeHGlobal((IntPtr)status);
                }

                //Creates the status variable.
                this.status = (float *) Marshal.AllocHGlobal(sizeof(float));

                this.extractionThread = new Thread(new ThreadStart(ExtractionThread));

                // Enables the timer that updates the progress bar.
                tmrExporterThread.Enabled = true;

                // Starts the thread.
                this.extractionThread.Start();
            }
        }
        public VertexBuffer(int vertexCapacity, int indexCapacity)
        {
            declarations = new List<VertexDeclaration>();

            int tmp;
            GL.GenVertexArrays(1, out tmp);
            VertexArrayObject = tmp;
            GL.BindVertexArray(VertexArrayObject);

            GL.GenBuffers(1, out tmp);
            VertexDataBufferObject = tmp;

            GL.GenBuffers(1, out tmp);
            IndexDataBufferObject = tmp;

            UsageMode = BufferUsageHint.DynamicDraw;

            vertexDataLength = vertexCapacity;
            indexDataLength = indexCapacity;

            _indexDataPointer = Marshal.AllocHGlobal(indexDataLength * sizeof(int));
            IndexData = (int*)_indexDataPointer.ToPointer();

            _vertexDataPointer = Marshal.AllocHGlobal(vertexDataLength * sizeof(float));
            VertexData = (float*)_vertexDataPointer.ToPointer();

            voffset = 0;
            ioffset = 0;
            stride = 0;
        }
 public unsafe NumericUpDown()
 {
     InitializeComponent();
     Value = 0;
     m_pfValue = null;
     m_Increase_Button.ValueChanged += new RoutedPropertyChangedEventHandler<object>(ValueChangedCallback);
     m_Temp = new float[1];
 }
Exemple #8
0
 static unsafe WaveFile()
 {
     for (int index = 0; index < 256; ++index)
     WaveFile._lutu8[index] = (float) (index - 128) * (1.0 / (double) sbyte.MaxValue);
       WaveFile._lut16 = (float*) (void*) WaveFile._lut16Buffer;
       for (int index = 0; index < 65536; ++index)
     WaveFile._lut16[index] = (float) (index - 32768) * 3.051851E-05f;
 }
Exemple #9
0
 public unsafe NoiseFilter(int fftSize = 4096)
     : base(fftSize)
 {
     this._gainBuffer1 = UnsafeBuffer.Create(fftSize, 4);
       this._gainPtr1 = (float*) (void*) this._gainBuffer1;
       this._gainBuffer2 = UnsafeBuffer.Create(fftSize, 4);
       this._gainPtr2 = (float*) (void*) this._gainBuffer2;
 }
Exemple #10
0
 public unsafe void Dispose()
 {
     this._coeffBuffer = (UnsafeBuffer) null;
       this._queueBuffer = (UnsafeBuffer) null;
       this._coeffPtr = (float*) null;
       this._queuePtr = (float*) null;
       GC.SuppressFinalize((object) this);
 }
 public VertexCodec(Vector3[] vertices, bool removeZ)
 {
     _srcCount = vertices.Length;
     _srcElements = 3;
     _handle = GCHandle.Alloc(vertices, GCHandleType.Pinned);
     _pData = (float*)_handle.AddrOfPinnedObject();
     Evaluate(removeZ);
 }
 public VertexCodec(Vector2[] vertices)
 {
     _srcCount = vertices.Length;
     _srcElements = 2;
     _handle = GCHandle.Alloc(vertices, GCHandleType.Pinned);
     _pData = (float*)_handle.AddrOfPinnedObject();
     Evaluate(false);
 }
Exemple #13
0
 public void Dispose()
 {
     _coeffBuffer = null;
     _queueBuffer = null;
     _coeffPtr = null;
     _queuePtr = null;
     GC.SuppressFinalize(this);
 }
Exemple #14
0
		/// <summary>
		/// Initializes the specified descriptor.
		/// </summary>
		/// <param name="descriptor">The descriptor.</param>
		protected void Initialize(Vector3Descriptor descriptor)
		{
			Initialize(descriptor.Base);

			_x = descriptor.X;
			_y = descriptor.Y;
			_z = descriptor.Z;
		}
Exemple #15
0
 static SdrIqDevice()
 {
     _lut16 = (float*) _lut16Buffer;
     const float scale16 = 1.0f / 32767.0f;
     for (var i = 0; i < 65536; i++)
     {
         _lut16[i] = (i - 32768) * scale16;
     }
 }
 static unsafe BladeRFDevice()
 {
     _lutPtr = (float*)_lutBuffer;
     const float scale = 1.0f / 2048.0f;
     for (int i = 0; i < 4096; ++i)
     {
         _lutPtr[i] = (((i + 2048) % 4096) - 2048) * scale;
     }
 }
Exemple #17
0
        public Exporter(string logPath, string sqlServerAddress, string databaseName, string logDescription)
        {
            BaseLog = new Log.Log(logPath);
            SqlServerAddress = sqlServerAddress;
            DatabaseName = databaseName;
            LogDescription = logDescription;

            this.status = (float*)Marshal.AllocHGlobal(sizeof(float));
        }
Exemple #18
0
        static RtlDevice()
        {
            _lutPtr = (float*) _lutBuffer;

            const float scale = 1.0f / 127.0f;
            for (var i = 0; i < 256; i++)
            {
                _lutPtr[i] = (i - 128) * scale;
            }
        }
        static RtlTcpIO()
        {
            _lutPtr = (float*) _lutBuffer;

            const float scale = 1.0f / 127.5f;
            for (var i = 0; i < 256; i++)
            {
                _lutPtr[i] = (i - 127.5f) * scale;
            }
        }
Exemple #20
0
 static LibV4LIO()
 {
     Console.WriteLine("LibV4LIO() static");
     // populate 16bit LUT
     _lutPtr = (float *)_lutBuffer;
     for (var i = 0; i < 65536; i++)
     {
         _lutPtr[i] = (i - 32767.5f) / 32767.5f;
     }
 }
Exemple #21
0
 public unsafe XYNumeric()
 {
     InitializeComponent();
     m_X_numericUpDown.m_Increase_Button.ValueChanged += new RoutedPropertyChangedEventHandler<object>(_ValueChanged);
     m_Y_numericUpDown.m_Increase_Button.ValueChanged += new RoutedPropertyChangedEventHandler<object>(_ValueChanged);
     fixed (float* l_pData = m_TempValue)
     {
         m_TempValue2 = l_pData;
     }
 }
Exemple #22
0
 public unsafe IQBalancer()
 {
     this._dcRemoverIBuffer = UnsafeBuffer.Create(sizeof (DcRemover));
       this._dcRemoverI = (DcRemover*) (void*) this._dcRemoverIBuffer;
       this._dcRemoverI->Init(1E-05f);
       this._dcRemoverQBuffer = UnsafeBuffer.Create(sizeof (DcRemover));
       this._dcRemoverQ = (DcRemover*) (void*) this._dcRemoverQBuffer;
       this._dcRemoverQ->Init(1E-05f);
       this._windowBuffer = UnsafeBuffer.Create((Array) FilterBuilder.MakeWindow(WindowType.Hamming, 1024));
       this._windowPtr = (float*) (void*) this._windowBuffer;
       this._isMultithreaded = Environment.ProcessorCount > 1;
 }
Exemple #23
0
        public NoiseFilter(int fftSize)
            : base(fftSize)
        {
            _gainBuffer = UnsafeBuffer.Create(fftSize, sizeof(float));
            _gainPtr = (float*) _gainBuffer;

            _smoothedGainBuffer = UnsafeBuffer.Create(fftSize, sizeof(float));
            _smoothedGainPtr = (float*) _smoothedGainBuffer;

            _powerBuffer = UnsafeBuffer.Create(fftSize, sizeof(float));
            _powerPtr = (float*) _powerBuffer;
        }
 public IQBalancer()
 {
     _dcRemoverIBuffer = UnsafeBuffer.Create(sizeof(DcRemover));
     _dcRemoverI = (DcRemover*) _dcRemoverIBuffer;
     _dcRemoverI->Init(DcTimeConst);
     _dcRemoverQBuffer = UnsafeBuffer.Create(sizeof(DcRemover));
     _dcRemoverQ = (DcRemover*) _dcRemoverQBuffer;
     _dcRemoverQ->Init(DcTimeConst);
     var window = FilterBuilder.MakeWindow(WindowType.Hamming, FFTBins);
     _windowBuffer = UnsafeBuffer.Create(window);
     _windowPtr = (float*) _windowBuffer;
     _isMultithreaded = Environment.ProcessorCount > 1;
 }
Exemple #25
0
    static LnOnePlusExp()
    {
        _pos_vals = (float*)Memory.malloc(sizeof(float) * _count);
        _neg_vals = (float*)Memory.malloc(sizeof(float) * _count);

        const double _dscale = ((_count - 1) / (double)_max);

        for (int k = 0; k < _count; k++)
        {
            double x = k;
            _pos_vals[k] = (float)Math.Log(1.0 + Math.Exp(x / _dscale));
            _neg_vals[k] = (float)Math.Log(1.0 + Math.Exp(-x / _dscale));
        }
    }
        static WaveFile()
        {
            _lutu8 = (float*) _lutu8Buffer;
            const float scale8 = 1.0f / 127.0f;
            for (var i = 0; i < 256; i++)
            {
                _lutu8[i] = (i - 128) * scale8;
            }

            _lut16 = (float*) _lut16Buffer;
            const float scale16 = 1.0f / 32767.0f;
            for (var i = 0; i < 65536; i++)
            {
                _lut16[i] = (i - 32768) * scale16;
            }
        }
Exemple #27
0
        private void ProcessMono(float* baseBand, float* interleavedStereo, int length)
        {
            #region Prepare buffer

            if (_channelABuffer == null || _channelABuffer.Length != length)
            {
                _channelABuffer = UnsafeBuffer.Create(length, sizeof(float));
                _channelAPtr = (float*)_channelABuffer;
            }

            #endregion

            #region Decimate L+R

            Utils.Memcpy(_channelAPtr, baseBand, length * sizeof(float));
            _channelADecimator.Process(_channelAPtr, length);

            #endregion

            #region Filter L+R

            length /= _audioDecimationFactor;
            _channelAFilter.Process(_channelAPtr, length);

            #endregion

            #region Process deemphasis

            for (var i = 0; i < length; i++)
            {
                _deemphasisAvgL += _deemphasisAlpha * (_channelAPtr[i] - _deemphasisAvgL);
                _channelAPtr[i] = _deemphasisAvgL;
            }

            #endregion

            #region Fill output buffer

            for (var i = 0; i < length; i++)
            {
                var sample = _channelAPtr[i] * AudioGain;
                interleavedStereo[i * 2] = sample;
                interleavedStereo[i * 2 + 1] = sample;
            }

            #endregion
        }
 public Resampler(double inputSampleRate, double outputSampleRate, int taps)
 {
     DoubleToFraction(outputSampleRate / inputSampleRate, out _interpolationFactor, out _decimationFactor);
     var filterLenght = (int) (500.0 / 32000 * inputSampleRate) / _interpolationFactor * _interpolationFactor;
     _tapsPerPhase = filterLenght / _interpolationFactor;
     _firKernelBuffer = UnsafeBuffer.Create(filterLenght, sizeof(float));
     _firKernel = (float*) _firKernelBuffer;
     var cutoff = Math.Min(inputSampleRate, outputSampleRate) * ProtectedPassband;
     var kernel = FilterBuilder.MakeLowPassKernel(inputSampleRate * _interpolationFactor, filterLenght - 1, cutoff, WindowType.BlackmanHarris4);
     fixed (float* ptr = kernel)
     {
         for (var i = 0; i < kernel.Length; i++)
         {
             ptr[i] *= _interpolationFactor;
         }
         Utils.Memcpy(_firKernel, ptr, filterLenght * sizeof(float));
     }
     _firQueueBuffer = UnsafeBuffer.Create(filterLenght, sizeof(float));
     _firQueue = (float*) _firQueueBuffer;
 }
        /// <summary>
        /// Generic convertor for float
        /// </summary>
        public static void ConverterFloatToFloatGeneric(IntPtr inputInterleavedBuffer, IntPtr[] asioOutputBuffers, int nbChannels, int nbSamples)
        {
            unsafe
            {
                float* inputSamples = (float*)inputInterleavedBuffer;
                float*[] samples = new float*[nbChannels];
                for (int i = 0; i < nbChannels; i++)
                {
                    samples[i] = (float*)asioOutputBuffers[i];
                }

                for (int i = 0; i < nbSamples; i++)
                {
                    for (int j = 0; j < nbChannels; j++)
                    {
                        *(samples[j]++) = *inputSamples++;
                    }
                }
            }
        }
Exemple #30
0
 static unsafe Trig()
 {
     int length = Trig._mask + 1;
       Trig._sinBuffer = UnsafeBuffer.Create(length, 4);
       Trig._cosBuffer = UnsafeBuffer.Create(length, 4);
       Trig._sinPtr = (float*) (void*) Trig._sinBuffer;
       Trig._cosPtr = (float*) (void*) Trig._cosBuffer;
       Trig._indexScale = (float) length / 6.283185f;
       for (int index = 0; index < length; ++index)
       {
     Trig._sinPtr[index] = (float) Math.Sin(((double) index + 0.5) / (double) length * 6.28318548202515);
     Trig._cosPtr[index] = (float) Math.Cos(((double) index + 0.5) / (double) length * 6.28318548202515);
       }
       float num = 0.0f;
       while ((double) num < 6.28318548202515)
       {
     Trig._sinPtr[(int) ((double) num * (double) Trig._indexScale) & Trig._mask] = (float) Math.Sin((double) num);
     Trig._cosPtr[(int) ((double) num * (double) Trig._indexScale) & Trig._mask] = (float) Math.Cos((double) num);
     num += 1.570796f;
       }
 }
Exemple #31
0
        /// <summary>
        ///   This method should be implemented by inheriting classes to implement the
        ///   actual feature extraction, transforming the input image into a list of features.
        /// </summary>
        ///
        protected override IEnumerable <FeatureDescriptor> InnerTransform(UnmanagedImage image)
        {
            // make sure we have grayscale image
            UnmanagedImage grayImage = null;

            if (image.PixelFormat == PixelFormat.Format8bppIndexed)
            {
                grayImage = image;
            }
            else
            {
                // create temporary grayscale image
                grayImage = Grayscale.CommonAlgorithms.BT709.Apply(image);
            }


            // get source image size
            int width  = grayImage.Width;
            int height = grayImage.Height;
            int stride = grayImage.Stride;
            int offset = stride - width;


            // 1. Calculate partial differences
            if (direction == null || height > direction.GetLength(0) || width > direction.GetLength(1))
            {
                direction = new float[height, width];
                magnitude = new float[height, width];
            }
            else
            {
                System.Diagnostics.Debug.Write(String.Format("Reusing storage for direction and magnitude. " +
                                                             "Need ({0}, {1}), have ({1}, {2})", height, width, direction.Rows(), direction.Columns()));
            }


            unsafe
            {
                fixed(float *ptrDir = direction, ptrMag = magnitude)
                {
                    // Begin skipping first line
                    byte * src = (byte *)grayImage.ImageData.ToPointer() + stride;
                    float *dir = ptrDir + width;
                    float *mag = ptrMag + width;

                    // for each line
                    for (int y = 1; y < height - 1; y++)
                    {
                        // skip first column
                        dir++; mag++; src++;

                        // for each inner pixel in line (skipping first and last)
                        for (int x = 1; x < width - 1; x++, src++, dir++, mag++)
                        {
                            // Retrieve the pixel neighborhood
                            byte a11 = src[+stride + 1], a12 = src[+1], a13 = src[-stride + 1];
                            byte a21 = src[+stride + 0], /*  a22    */ a23 = src[-stride + 0];
                            byte a31 = src[+stride - 1], a32 = src[-1], a33 = src[-stride - 1];

                            // Convolution with horizontal differentiation kernel mask
                            float h = ((a11 + a12 + a13) - (a31 + a32 + a33)) * 0.166666667f;

                            // Convolution with vertical differentiation kernel mask
                            float v = ((a11 + a21 + a31) - (a13 + a23 + a33)) * 0.166666667f;

                            // Store angles and magnitudes directly
                            *dir = (float)Math.Atan2(v, h);
                            *mag = (float)Math.Sqrt(h * h + v * v);
                        }

                        // Skip last column
                        dir++; mag++; src += offset + 1;
                    }
                }
            }

            // Free some resources which wont be needed anymore
            if (image.PixelFormat != PixelFormat.Format8bppIndexed)
            {
                grayImage.Dispose();
            }



            // 2. Compute cell histograms
            int cellCountX = (int)Math.Floor(width / (double)cellSize);
            int cellCountY = (int)Math.Floor(height / (double)cellSize);

            if (histograms == null || cellCountX > histograms.GetLength(0) || cellCountY > histograms.GetLength(1))
            {
                this.histograms = new double[cellCountX, cellCountY][];
                for (int i = 0; i < cellCountX; i++)
                {
                    for (int j = 0; j < cellCountY; j++)
                    {
                        this.histograms[i, j] = new double[NumberOfBins];
                    }
                }
            }
            else
            {
                System.Diagnostics.Debug.Write(String.Format("Reusing storage for histograms. " +
                                                             "Need ({0}, {1}), have ({1}, {2})", cellCountX, cellCountY, histograms.Rows(), histograms.Columns()));
            }

            // For each cell
            for (int i = 0; i < cellCountX; i++)
            {
                for (int j = 0; j < cellCountY; j++)
                {
                    // Compute the histogram
                    double[] histogram = this.histograms[i, j];
                    Array.Clear(histogram, 0, histogram.Length);

                    int startCellX = i * cellSize;
                    int startCellY = j * cellSize;

                    // for each pixel in the cell
                    for (int x = 0; x < cellSize; x++)
                    {
                        for (int y = 0; y < cellSize; y++)
                        {
                            double ang = direction[startCellY + y, startCellX + x];
                            double mag = magnitude[startCellY + y, startCellX + x];

                            // Get its angular bin
                            int bin = (int)System.Math.Floor((ang + Math.PI) * binWidth);

                            histogram[bin] += mag;
                        }
                    }
                }
            }

            // 3. Group the cells into larger, normalized blocks
            int blocksCountX = (int)Math.Floor(cellCountX / (double)blockSize);
            int blocksCountY = (int)Math.Floor(cellCountY / (double)blockSize);

            var blocks = new List <FeatureDescriptor>();

            for (int i = 0; i < blocksCountX; i++)
            {
                for (int j = 0; j < blocksCountY; j++)
                {
                    double[] block = new double[blockSize * blockSize * numberOfBins];

                    int startBlockX = i * blockSize;
                    int startBlockY = j * blockSize;
                    int c           = 0;

                    // for each cell in the block
                    for (int x = 0; x < blockSize; x++)
                    {
                        for (int y = 0; y < blockSize; y++)
                        {
                            double[] histogram = histograms[startBlockX + x, startBlockY + y];

                            // Copy all histograms to the block vector
                            for (int k = 0; k < histogram.Length; k++)
                            {
                                block[c++] = histogram[k];
                            }
                        }
                    }

                    // TODO: Remove this block and instead propose a general architecture
                    //       for applying normalizations to descriptor blocks
                    if (normalize)
                    {
                        block.Divide(block.Euclidean() + epsilon, result: block);
                    }

                    blocks.Add(block);
                }
            }

            return(blocks);
        }
 private static extern void LearnAll(int totalNumInstances, int *instSizes, int **instIndices,
                                     float **instValues, float *labels, bool tuneLR, ref float lr, float l2Const, float piw, float *weightVector, ref float bias,
                                     int numFeatres, int numPasses, int numThreads, bool tuneNumLocIter, ref int numLocIter, float tolerance, bool needShuffle, bool shouldInitialize,
                                     State *state, ChannelCallBack info);
Exemple #33
0
 static void HandlePrepareCacheCallback(MapLayerID inlayer, float *inTotalMapBoundsLeftTopRightBottom, MapProjectionID projection, void *inrefcon)
 {
     ref readonly RectF bounds = ref Unsafe.AsRef <RectF>((RectF *)inTotalMapBoundsLeftTopRightBottom);
Exemple #34
0
 public static unsafe void PrioritizeTextures(this ExtTextureObject thisApi, [Flow(FlowDirection.In)] uint n, [Count(Parameter = "n"), Flow(FlowDirection.In)] ReadOnlySpan <Texture> textures, [Count(Parameter = "n"), Flow(FlowDirection.In)] float *priorities)
 {
     // SpanOverloader
     thisApi.PrioritizeTextures(n, in textures.GetPinnableReference(), priorities);
 }
Exemple #35
0
 public static float *Add(float *v1, float v2)
 {
     v1[0] = v1[0] + v2; v1[1] = v1[1] + v2; v1[2] = v1[2] + v2; return(v1);
 }
 internal extern static unsafe void glGetCombinerOutputParameterfvNV(Int32 stage, Int32 portion, Int32 pname, float * @params);
 public void GetDesktopDpi([NativeTypeName("FLOAT *")] float *dpiX, [NativeTypeName("FLOAT *")] float *dpiY)
 {
     ((delegate * unmanaged <ID2D1Factory3 *, float *, float *, void>)(lpVtbl[4]))((ID2D1Factory3 *)Unsafe.AsPointer(ref this), dpiX, dpiY);
 }
Exemple #38
0
 public static extern unsafe void alListenerfv(All key, float *values);
Exemple #39
0
 public static extern unsafe void alGetSourcefv(int source, All param, [Out] out float *values);
Exemple #40
0
 public static extern unsafe void alGetListenerfv(All key, [Out] out float *values);
Exemple #41
0
 public static extern unsafe void alGetListener3f(All key, [Out] out float *value1, [Out] out float *value2, [Out] out float *value3);
Exemple #42
0
 internal static extern unsafe void AddScaleSU(float a, /*_In_ const*/ float *ps, /*_In_ const*/ int *pi, /*_Inout_*/ float *pd, int c);
Exemple #43
0
 internal static extern unsafe void ScaleAddU(float a, float b, /*_Inout_*/ float *pd, int c);
Exemple #44
0
 internal static extern unsafe float AddScalarU(float a, /*_Inout_*/ float *pd, int c);
        public void Process(float *buffer, int length)
        {
            for (var i = 0; i < length; i++)
            {
                var sample = buffer[i];    //get latest input sample

                if (sample == 0.0)
                {
                    continue;
                }

                sample *= 1000.0f;

                //Get delayed sample of input signal
                var delayedin = _sigDelayBufPtr[_sigDelayPtr];
                //put new input sample into signal delay buffer
                _sigDelayBufPtr[_sigDelayPtr++] = sample;
                if (_sigDelayPtr >= _delaySamples)    //deal with delay buffer wrap around
                {
                    _sigDelayPtr = 0;
                }

                //convert |mag| to log |mag|
                var mag = (float)Math.Log10(Math.Abs(sample));
                if (float.IsNaN(mag) || float.IsInfinity(mag))
                {
                    mag = -8.0f;
                }

                //create a sliding window of '_WindowSamples' magnitudes and output the peak value within the sliding window
                var tmp = _magBufPtr[_magBufPos];    //get oldest mag sample from buffer into tmp
                _magBufPtr[_magBufPos++] = mag;      //put latest mag sample in buffer;
                if (_magBufPos >= _windowSamples)    //deal with magnitude buffer wrap around
                {
                    _magBufPos = 0;
                }
                if (mag > _peak)
                {
                    _peak = mag;    //if new sample is larger than current peak then use it, no need to look at buffer values
                }
                else
                {
                    if (tmp == _peak)  //tmp is oldest sample pulled out of buffer
                    {                  //if oldest sample pulled out was last peak then need to find next highest peak in buffer
                        _peak = -8.0f; //set to lowest value to find next max peak
                        //search all buffer for maximum value and set as new peak
                        for (var j = 0; j < _windowSamples; j++)
                        {
                            tmp = _magBufPtr[j];
                            if (tmp > _peak)
                            {
                                _peak = tmp;
                            }
                        }
                    }
                }

                if (UseHang)
                {                           //using hang timer mode
                    if (_peak > _attackAve) //if magnitude is rising (use _AttackRiseAlpha time constant)
                    {
                        _attackAve = (1.0f - _attackRiseAlpha) * _attackAve + _attackRiseAlpha * _peak;
                    }
                    else                    //else magnitude is falling (use  _AttackFallAlpha time constant)
                    {
                        _attackAve = (1.0f - _attackFallAlpha) * _attackAve + _attackFallAlpha * _peak;
                    }

                    if (_peak > _decayAve)    //if magnitude is rising (use _DecayRiseAlpha time constant)
                    {
                        _decayAve  = (1.0f - _decayRiseAlpha) * _decayAve + _decayRiseAlpha * _peak;
                        _hangTimer = 0;    //reset hang timer
                    }
                    else
                    {    //here if decreasing signal
                        if (_hangTimer < _hangTime)
                        {
                            _hangTimer++; //just inc and hold current _DecayAve
                        }
                        else              //else decay with _DecayFallAlpha which is RELEASE_TIMECONST
                        {
                            _decayAve = (1.0f - _decayFallAlpha) * _decayAve + _decayFallAlpha * _peak;
                        }
                    }
                }
                else
                {                           //using exponential decay mode
                    // perform average of magnitude using 2 averagers each with separate rise and fall time constants
                    if (_peak > _attackAve) //if magnitude is rising (use _AttackRiseAlpha time constant)
                    {
                        _attackAve = (1.0f - _attackRiseAlpha) * _attackAve + _attackRiseAlpha * _peak;
                    }
                    else                    //else magnitude is falling (use  _AttackFallAlpha time constant)
                    {
                        _attackAve = (1.0f - _attackFallAlpha) * _attackAve + _attackFallAlpha * _peak;
                    }

                    if (_peak > _decayAve)    //if magnitude is rising (use _DecayRiseAlpha time constant)
                    {
                        _decayAve = (1.0f - _decayRiseAlpha) * _decayAve + _decayRiseAlpha * _peak;
                    }
                    else                    //else magnitude is falling (use _DecayFallAlpha time constant)
                    {
                        _decayAve = (1.0f - _decayFallAlpha) * _decayAve + _decayFallAlpha * _peak;
                    }
                }

                //use greater magnitude of attack or Decay Averager
                mag = _attackAve > _decayAve ? _attackAve : _decayAve;

                //calc gain depending on which side of knee the magnitude is on
                float gain;
                if (mag <= _knee)        //use fixed gain if below knee
                {
                    gain = _fixedGain;
                }
                else                //use variable gain if above knee
                {
                    gain = AGCOutscale * (float)Math.Pow(10.0, mag * (_gainSlope - 1.0));
                }

                buffer[i] = delayedin * gain * 0.00001f;
            }
        }
Exemple #46
0
 public static extern unsafe void alSourcefv(int source, All key, float *values);
 internal extern static unsafe void glGetFinalCombinerInputParameterfvNV(Int32 variable, Int32 pname, float * @params);
Exemple #48
0
        protected override unsafe void UpdateParameters()
        {
            base.UpdateParameters();

            Vector2 jitterPixels;

            jitteringFrameCount++;
            jitteringFrameCount %= 16;

            // Compute jittering

            var jitteringOffset = SampleJitterNormalized16(jitteringFrameCount) * JitteringMagnitude;

            jitterPixels.X = jitteringOffset[0];
            jitterPixels.Y = -jitteringOffset[1];

            const float Sharpness = 1.0f + (-0.25f) * 0.5f;

            float totalWeight    = 0.0f;
            float totalWeightLow = 0.0f;

            float  weightCenter;
            float  weightLowCenter;
            float *weights    = stackalloc float[8];
            float *weightLows = stackalloc float[8];

            for (var i = 0; i < 8; ++i)
            {
                // Exponential fit to Blackman-Harris 3.3
                float pixelOffsetX = SampleOffsets[i][0] - jitterPixels[0];
                float pixelOffsetY = SampleOffsets[i][1] - jitterPixels[1];
                pixelOffsetX *= Sharpness;
                pixelOffsetY *= Sharpness;
                weights[i]    = (float)Math.Exp(-2.29f * (pixelOffsetX * pixelOffsetX + pixelOffsetY * pixelOffsetY));
                totalWeight  += weights[i];

                // Lowpass.
                pixelOffsetX    = SampleOffsets[i][0] - jitterPixels[0];
                pixelOffsetY    = SampleOffsets[i][1] - jitterPixels[1];
                pixelOffsetX   *= 0.25f;
                pixelOffsetY   *= 0.25f;
                pixelOffsetX   *= Sharpness;
                pixelOffsetY   *= Sharpness;
                weightLows[i]   = (float)Math.Exp(-2.29f * (pixelOffsetX * pixelOffsetX + pixelOffsetY * pixelOffsetY));
                totalWeightLow += weightLows[i];
            }

            {
                float pixelOffsetX = SampleOffsets[8][0] - jitterPixels[0];
                float pixelOffsetY = SampleOffsets[8][1] - jitterPixels[1];
                pixelOffsetX *= Sharpness;
                pixelOffsetY *= Sharpness;
                weightCenter  = (float)Math.Exp(-2.29f * (pixelOffsetX * pixelOffsetX + pixelOffsetY * pixelOffsetY));
                totalWeight  += weightCenter;
                weightCenter /= totalWeight;

                // Lowpass.
                pixelOffsetX     = SampleOffsets[8][0] - jitterPixels[0];
                pixelOffsetY     = SampleOffsets[8][1] - jitterPixels[1];
                pixelOffsetX    *= 0.25f;
                pixelOffsetY    *= 0.25f;
                pixelOffsetX    *= Sharpness;
                pixelOffsetY    *= Sharpness;
                weightLowCenter  = (float)Math.Exp(-2.29f * (pixelOffsetX * pixelOffsetX + pixelOffsetY * pixelOffsetY));
                totalWeightLow  += weightLowCenter;
                weightLowCenter /= totalWeightLow;
            }

            for (var i = 0; i < 8; ++i)
            {
                weights[i]    /= totalWeight;
                weightLows[i] /= totalWeightLow;
            }

            // Set cbuffer variables
            Parameters.Set(TemporalAntiAliasShaderKeys.u_BlendWeightMin, BlendWeightMin);
            Parameters.Set(TemporalAntiAliasShaderKeys.u_BlendWeightMax, BlendWeightMax);
            Parameters.Set(TemporalAntiAliasShaderKeys.u_HistoryBlurAmp, HistoryBlurAmp);
            Parameters.Set(TemporalAntiAliasShaderKeys.u_LumaContrastFactor, LumaContrastFactor);
            Parameters.Set(TemporalAntiAliasShaderKeys.u_VelocityDecay, VelocityDecay);

            Parameters.Set(TemporalAntiAliasShaderKeys.u_WeightCenter, weightCenter);
            Parameters.Set(TemporalAntiAliasShaderKeys.u_WeightLowCenter, weightLowCenter);
            Parameters.Set(TemporalAntiAliasShaderKeys.u_Weight1, *(Vector4 *)&weights[0]);
            Parameters.Set(TemporalAntiAliasShaderKeys.u_Weight2, *(Vector4 *)&weights[1]);
            Parameters.Set(TemporalAntiAliasShaderKeys.u_WeightLow1, *(Vector4 *)&weights[0]);
            Parameters.Set(TemporalAntiAliasShaderKeys.u_WeightLow2, *(Vector4 *)&weights[1]);
        }
 internal extern static unsafe void glCombinerParameterfvNV(Int32 pname, float * @params);
Exemple #50
0
        public unsafe override void render(float elapsedTime)
        {
            Device device = GuiController.Instance.D3dDevice;

            Control panel3d = GuiController.Instance.Panel3d;

            time += elapsedTime;
            TgcD3dInput d3dInput = GuiController.Instance.D3dInput;

            //Obtener variacion XY del mouse
            if (d3dInput.buttonDown(TgcD3dInput.MouseButtons.BUTTON_LEFT))
            {
                float mouseX = d3dInput.XposRelative;
                float mouseY = d3dInput.YposRelative;
                float an     = mouseX * 0.1f;

                float x = (float)(LookFrom.X * Math.Cos(an) + LookFrom.Z * Math.Sin(an));
                float z = (float)(LookFrom.Z * Math.Cos(an) - LookFrom.X * Math.Sin(an));
                LookFrom.X  = x;
                LookFrom.Z  = z;
                LookFrom.Y += mouseY * 150f;
            }

            //Determinar distancia de la camara o zoom segun el Mouse Wheel
            if (d3dInput.WheelPos != 0)
            {
                Vector3 vdir = LookFrom - LookAt;
                vdir.Normalize();
                LookFrom = LookFrom - vdir * (d3dInput.WheelPos * 500);
            }

            device.Transform.View = Matrix.LookAtLH(LookFrom, LookAt, new Vector3(0, 1, 0));

            Matrix ant_Proj  = device.Transform.Projection;
            Matrix ant_World = device.Transform.World;
            Matrix ant_View  = device.Transform.View;

            device.Transform.Projection = Matrix.Identity;
            device.Transform.World      = Matrix.Identity;
            device.Transform.View       = Matrix.Identity;
            device.SetRenderState(RenderStates.AlphaBlendEnable, false);

            // rt1= velocidad
            Surface pOldRT = device.GetRenderTarget(0);
            Surface pSurf  = g_pVelocidadOut.GetSurfaceLevel(0);

            device.SetRenderTarget(0, pSurf);
            Surface pOldDS = device.DepthStencilSurface;

            device.DepthStencilSurface = g_pDepthStencil;
            // rt2 = posicion
            Surface pSurf2 = g_pPosOut.GetSurfaceLevel(0);

            device.SetRenderTarget(1, pSurf2);

            device.Clear(ClearFlags.Target | ClearFlags.ZBuffer, Color.Black, 1.0f, 0);
            device.BeginScene();

            effect.SetValue("elapsedTime", elapsedTime);
            effect.Technique = "ComputeVel";
            effect.SetValue("g_pVelocidad", g_pVelocidad);
            effect.SetValue("g_pPos", g_pPos);
            device.VertexFormat = CustomVertex.PositionTextured.Format;
            device.SetStreamSource(0, g_pVBV3D, 0);
            effect.Begin(FX.None);
            effect.BeginPass(1);
            device.DrawPrimitives(PrimitiveType.TriangleStrip, 0, 2);
            effect.EndPass();
            effect.End();
            device.EndScene();


            // leo los datos de la textura de velocidades
            // ----------------------------------------------------------------------
            Surface pDestSurf = g_pTempVel.GetSurfaceLevel(0);

            device.GetRenderTargetData(pSurf, pDestSurf);
            Surface pDestSurf2 = g_pTempPos.GetSurfaceLevel(0);

            device.GetRenderTargetData(pSurf2, pDestSurf2);

            float *pDataVel = (float *)pDestSurf.LockRectangle(LockFlags.None).InternalData.ToPointer();
            float *pDataPos = (float *)pDestSurf2.LockRectangle(LockFlags.None).InternalData.ToPointer();

            for (int i = 0; i < MAX_DS; i++)
            {
                for (int j = 0; j < MAX_DS; j++)
                {
                    vel_x[i, j] = *pDataVel++;
                    vel_z[i, j] = *pDataVel++;
                    pDataVel++;     // no usado
                    pDataVel++;     // no usado

                    pos_x[i, j] = *pDataPos++;
                    pos_z[i, j] = *pDataPos++;
                    pos_y[i, j] = *pDataPos++;
                    pDataPos++;     // no usado
                }
            }
            pDestSurf.UnlockRectangle();
            pDestSurf2.UnlockRectangle();

            pSurf.Dispose();
            pSurf2.Dispose();

            device.SetRenderTarget(0, pOldRT);
            device.SetRenderTarget(1, null);
            device.DepthStencilSurface = pOldDS;

            // swap de texturas
            Texture aux = g_pVelocidad;

            g_pVelocidad    = g_pVelocidadOut;
            g_pVelocidadOut = aux;
            aux             = g_pPos;
            g_pPos          = g_pPosOut;
            g_pPosOut       = aux;


            // dibujo pp dicho ----------------------------------------------
            device.Transform.Projection = ant_Proj;
            device.Transform.World      = ant_World;
            device.Transform.View       = ant_View;

            device.BeginScene();
            device.Clear(ClearFlags.Target | ClearFlags.ZBuffer, Color.Black, 1.0f, 0);

            //Renderizar terreno
            if ((bool)GuiController.Instance.Modifiers["dibujar_terreno"])
            {
                terrain.render();
            }

            // dibujo las particulas como point sprites
            mesh.Effect    = effect;
            mesh.Technique = "DefaultTechnique";
            effect.SetValue("texDiffuseMap", g_pBaseTexture);

            CustomVertex.PositionColored[,] vertices = new CustomVertex.PositionColored[MAX_DS, MAX_DS];
            for (int i = 0; i < MAX_DS; i++)
            {
                for (int j = 0; j < MAX_DS; j++)
                {
                    float x0 = pos_x[i, j];
                    float z0 = pos_z[i, j];
                    float H  = pos_y[i, j];
                    vertices[i, j] = new CustomVertex.PositionColored(x0, H + esfera_radio, z0, Color.Blue.ToArgb());
                }
            }
            g_pVB.SetData(vertices, 0, LockFlags.None);

            device.VertexFormat = CustomVertex.PositionColored.Format;
            device.SetStreamSource(0, g_pVB, 0);
            device.SetTexture(0, null);
            device.SetRenderState(RenderStates.PointSize, 32);
            device.SetRenderState(RenderStates.PointScaleEnable, true);
            device.SetRenderState(RenderStates.PointSpriteEnable, true);
            device.DrawPrimitives(PrimitiveType.PointList, 0, MAX_DS * MAX_DS);
            device.EndScene();
        }
Exemple #51
0
 public int get_EngineConfidence([NativeTypeName("float *")] float *EngineConfidence)
 {
     return(((delegate * unmanaged <ISpeechPhraseRule *, float *, int>)(lpVtbl[14]))((ISpeechPhraseRule *)Unsafe.AsPointer(ref this), EngineConfidence));
 }
Exemple #52
0
 public static extern unsafe void alGetFloatv(All capability, [Out] out float *values);
 public int CreateStrokeStyle([NativeTypeName("const D2D1_STROKE_STYLE_PROPERTIES1 *")] D2D1_STROKE_STYLE_PROPERTIES1 *strokeStyleProperties, [NativeTypeName("const FLOAT *")] float *dashes, [NativeTypeName("UINT32")] uint dashesCount, ID2D1StrokeStyle1 **strokeStyle)
 {
     return(((delegate * unmanaged <ID2D1Factory3 *, D2D1_STROKE_STYLE_PROPERTIES1 *, float *, uint, ID2D1StrokeStyle1 **, int>)(lpVtbl[18]))((ID2D1Factory3 *)Unsafe.AsPointer(ref this), strokeStyleProperties, dashes, dashesCount, strokeStyle));
 }
 internal static extern unsafe void core_Mat_data(IntPtr mat, out float *output);
 internal extern static unsafe void glWeightfvARB(Int32 size, float *weights);
Exemple #56
0
 public static float *Mult(float *v1, float v2)
 {
     v1[0] = v1[0] * v2; v1[1] = v1[1] * v2; v1[2] = v1[2] * v2; return(v1);
 }
Exemple #57
0
        unsafe void FaceVertices(ref float *ptr, ref Vector3d corner, ref Vector3d side1, ref Vector3d side2, ref Vector3d n, ref Vector3 color,
                                 bool txt, bool col, bool normal, bool ptsize)
        {
            // Upper left.
            if (txt)
            {
                Fill(ref ptr, 0.0f, 0.0f);
            }
            if (col)
            {
                Fill(ref ptr, ref color);
            }
            if (normal)
            {
                Fill(ref ptr, ref n);
            }
            if (ptsize)
            {
                *ptr++ = 1.0f;
            }
            Fill(ref ptr, Vector3d.TransformPosition(corner, objectMatrix));

            // Upper right.
            if (txt)
            {
                Fill(ref ptr, 1.0f, 0.0f);
            }
            if (col)
            {
                Fill(ref ptr, ref color);
            }
            if (normal)
            {
                Fill(ref ptr, ref n);
            }
            if (ptsize)
            {
                *ptr++ = 1.0f;
            }
            Fill(ref ptr, Vector3d.TransformPosition(corner + side1, objectMatrix));

            // Lower left.
            if (txt)
            {
                Fill(ref ptr, 0.0f, 1.0f);
            }
            if (col)
            {
                Fill(ref ptr, ref color);
            }
            if (normal)
            {
                Fill(ref ptr, ref n);
            }
            if (ptsize)
            {
                *ptr++ = 1.0f;
            }
            Fill(ref ptr, Vector3d.TransformPosition(corner + side2, objectMatrix));

            // Lower right.
            if (txt)
            {
                Fill(ref ptr, 1.0f, 1.0f);
            }
            if (col)
            {
                Fill(ref ptr, ref color);
            }
            if (normal)
            {
                Fill(ref ptr, ref n);
            }
            if (ptsize)
            {
                *ptr++ = 1.0f;
            }
            Fill(ref ptr, Vector3d.TransformPosition(corner + side1 + side2, objectMatrix));
        }
 private static extern void MapBackWeightVector(float *weightVector, State *state);
Exemple #59
0
 public static float *Sub(float *v1, float v2)
 {
     v1[0] = v1[0] - v2; v1[1] = v1[1] - v2; v1[2] = v1[2] - v2; return(v1);
 }
Exemple #60
0
 public static extern unsafe void alBufferfv(uint buffer, All param, float *values);