Exemplo n.º 1
0
        public override SpectrumContainer CreateSpectrum(SpectrumCreatorSettings settings)
        {
            //settings.AudioContainer.SampleRate
            var slices = new List <SpectrumSlice>();

            for (var frequency = settings.SpectrumMinFrequency; frequency < settings.SpectrumMaxFrequency; frequency += settings.SpectrumFrequencyStep)
            {
                var scale = frequency;

                for (int i = 0; i < 100; i++)
                {
                }
            }

            Console.WriteLine("!!!");
            var container = new SpectrumContainer(slices);

            return(container);
        }
Exemplo n.º 2
0
        public override unsafe SpectrumContainer CreateSpectrum(SpectrumCreatorSettings settings)
        {
            nuint signalsBufferElementsCount = (nuint)AudioContainer.SamplesCount;
            nuint signalsBufferSize          = signalsBufferElementsCount * sizeof(float);
            var   signalsBuffer = _cl.CreateBuffer(_context, CLEnum.MemReadOnly, signalsBufferSize, null, out var errorCode);

            CheckSuccess(errorCode);

            nuint bufferOutputElementsCount = 10;
            nuint bufferKernelOutputSize    = bufferOutputElementsCount * sizeof(float);
            var   bufferKernelOutput        = _cl.CreateBuffer(_context, CLEnum.MemWriteOnly, bufferKernelOutputSize, null, out errorCode);

            CheckSuccess(errorCode);

            var signalsInputHostBuffer = new UnmanagedArray <float>(signalsBufferElementsCount);

            signalsInputHostBuffer[0] = 6;
            signalsInputHostBuffer[1] = 8;
            _cl.EnqueueWriteBuffer(_commandQueue, signalsBuffer, true, 0, signalsBufferSize, signalsInputHostBuffer, 0, 0, out var @event);


            var res = _cl.SetKernelArg(_kernelHandle, 0, (nuint)sizeof(nuint), signalsBuffer);

            CheckSuccess(res);
            res = _cl.SetKernelArg(_kernelHandle, 1, (nuint)sizeof(nuint), bufferKernelOutput);
            CheckSuccess(res);

            //var globalWorkSize = new UnmanagedArray<nuint>(3)
            //{
            //    bufferInputElementsCount, 0, 0
            //};
            var localWorkSize = new UnmanagedArray <nuint>(3)
            {
                1, 1, 1
            };

            res = _cl.EnqueueNdrangeKernel(_commandQueue, _kernelHandle, 1, 0, signalsBufferElementsCount, localWorkSize, 0, null, out var calculateEvent);
            CheckSuccess(res);

            _cl.Finish(_commandQueue);

            var outputHostBuffer = new UnmanagedArray <float>(bufferKernelOutputSize / sizeof(float));

            res = _cl.EnqueueReadBuffer(_commandQueue, bufferKernelOutput, true, 0, bufferKernelOutputSize, outputHostBuffer, 0, null, out @event);
            CheckSuccess(res);

            var slices = new List <SpectrumSlice>();

            SpectrumContainer = new SpectrumContainer(slices);

            var x = outputHostBuffer[0];


            _cl.ReleaseMemObject(signalsBuffer);
            _cl.ReleaseMemObject(bufferKernelOutput);
            _cl.ReleaseKernel(_kernelHandle);
            _cl.ReleaseProgram(_program);


            return(SpectrumContainer);
        }