Ejemplo n.º 1
0
        public void Evaluate(int SpreadMax)
        {
            if (Inputs.IsChanged)
            {
                var count = Inputs.SliceCount;
                if (Inputs[0].SliceCount == 0)
                {
                    count = 0;
                }

                OutBuffer.Resize(count, () => { return(new TOperator()); }, s => { if (s != null)
                                                                                   {
                                                                                       s.Dispose();
                                                                                   }
                                 });
                for (int outSlice = 0; outSlice < OutBuffer.SliceCount; outSlice++)
                {
                    if (OutBuffer[outSlice] == null)
                    {
                        OutBuffer[outSlice] = new TOperator();
                    }
                    (OutBuffer[outSlice] as AudioSignalOperator).Inputs = Inputs[outSlice];
                }
            }
        }
Ejemplo n.º 2
0
        public void Evaluate(int SpreadMax)
        {
            FOutput.Resize(SpreadMax, () => new MemoryComStream(), str => str.Dispose());
            FMmf.SliceCount = SpreadMax;
            for (int i = 0; i < SpreadMax; i++)
            {
                if (string.IsNullOrWhiteSpace(FName[i]))
                {
                    continue;
                }
                if (FOpen[i] && !_mmfs.ContainsKey(FName[i]))
                {
                    try
                    {
                        var mmf = MemoryMappedFile.OpenExisting(FName[i]);
                        _mmfs.Add(FName[i], mmf);
                    }
                    catch
                    { }
                }

                if ((FOpen[i] || FRead[i]) && _mmfs.ContainsKey(FName[i]))
                {
                    var mmf = _mmfs[FName[i]];
                    FMmf[i] = mmf;
                    if (FOutput[i] == null)
                    {
                        FOutput[i] = new MemoryComStream();
                    }
                    if (FSize[i] == 0)
                    {
                        using (var accessor = mmf.CreateViewStream())
                        {
                            FOutput[i].SetLength(accessor.Length);
                            accessor.Position   = 0;
                            FOutput[i].Position = 0;
                            accessor.CopyTo(FOutput[i]);
                            FOutput[i].Position = 0;
                        }
                    }
                    else
                    {
                        using (var accessor = mmf.CreateViewStream(FOffset[i], FSize[i]))
                        {
                            FOutput[i].SetLength(accessor.Length);
                            accessor.Position   = 0;
                            FOutput[i].Position = 0;
                            accessor.CopyTo(FOutput[i]);
                            FOutput[i].Position = 0;
                        }
                    }
                }
            }

            FOutput.Stream.IsChanged = false;
            if (FRead.Any() || FOpen.Any())
            {
                FOutput.Flush(true);
            }
        }
Ejemplo n.º 3
0
        //called when data for any output pin is requested
        public void Evaluate(int SpreadMax)
        {
            if (!_pgready)
            {
                return;
            }
            if (_typeChanged || _firstFrame || _input.Spread.IsChanged)
            {
                Success.SliceCount = _input.Spread.SliceCount;
                Output.Resize(_input.Spread.SliceCount, i => new MemoryStream(), stream => stream?.Dispose());
                _output.ResizeAndDismiss(_input.Spread.SliceCount, i => null);

                for (int i = 0; i < _input.Spread.SliceCount; i++)
                {
                    Output[i] = Output[i] == null ? new MemoryStream() : Output[i];
                    var obj = _input[i];
                    var buf = _output[i];
                    if (obj == null)
                    {
                        Output[i].SetLength(0);
                        continue;
                    }
                    Output[i].Position = 0;
                    int length = 0;
                    try
                    {
                        length     = _ceras.Serialize(obj, ref buf);
                        Success[i] = true;
                    }
                    catch
                    {
                        Success[i] = false;
                        _ceras     = CerasSerializerHelper.Serializer();
                        Output[i].SetLength(0);
                        continue;
                    }
                    Output[i].SetLength(length);
                    Output[i].Write(buf, 0, length);
                    _output[i] = buf;
                }
                Output.Stream.IsChanged = true;
            }
            else
            {
                Output.Stream.IsChanged = false;
            }

            if (_firstFrame)
            {
                _firstFrame = false;
            }
            if (_typeChanged)
            {
                _typeChanged = false;
            }
        }
Ejemplo n.º 4
0
        protected override void FillBuffer(float[] buffer, int offset, int count)
        {
//			PerfCounter.Start("MultiSine");
            var spreadMax = Frequencies.CombineWith(Gains);

            Phases.Resize(spreadMax, () => default(float), f => f = 0);
            for (int slice = 0; slice < spreadMax; slice++)
            {
                var increment = TwoPi * Frequencies[slice] / SampleRate;
                var gain      = Gains[slice];
                var phase     = Phases[slice];

                if (slice == 0)
                {
                    for (int i = 0; i < count; i++)
                    {
                        // Sinus Generator
                        buffer[i] = gain * (float)Math.Sin(phase);

                        phase += increment;
                        if (phase > TwoPi)
                        {
                            phase -= TwoPi;
                        }
                        else if (phase < 0)
                        {
                            phase += TwoPi;
                        }
                    }
                }
                else
                {
                    for (int i = 0; i < count; i++)
                    {
                        // Sinus Generator
                        buffer[i] += gain * (float)Math.Sin(phase);

                        phase += increment;
                        if (phase > TwoPi)
                        {
                            phase -= TwoPi;
                        }
                        else if (phase < 0)
                        {
                            phase += TwoPi;
                        }
                    }
                }


                Phases[slice] = phase; //write back
            }

//			PerfCounter.Stop("MultiSine");
        }
Ejemplo n.º 5
0
        public void Evaluate(int SpreadMax)
        {
            FOutput.Resize(FMmf.SliceCount, () => new MemoryComStream(), str => str.Dispose());
            for (int i = 0; i < FMmf.SliceCount; i++)
            {
                if (FMmf[i] != null && FRead[i])
                {
                    var mutex = MutexIn.TryGetSlice(i);

                    var mmf = FMmf[i];
                    FMmf[i] = mmf;
                    if (FOutput[i] == null)
                    {
                        FOutput[i] = new MemoryComStream();
                    }
                    if (FSize[i] == 0)
                    {
                        mutex?.WaitOne();
                        using (var accessor = mmf.CreateViewStream())
                        {
                            FOutput[i].SetLength(accessor.Length);
                            accessor.Position   = 0;
                            FOutput[i].Position = 0;
                            accessor.CopyTo(FOutput[i]);
                            FOutput[i].Position = 0;
                        }
                        mutex?.ReleaseMutex();
                    }
                    else
                    {
                        mutex?.WaitOne();
                        using (var accessor = mmf.CreateViewStream(FOffset[i], FSize[i]))
                        {
                            FOutput[i].SetLength(accessor.Length);
                            accessor.Position   = 0;
                            FOutput[i].Position = 0;
                            accessor.CopyTo(FOutput[i]);
                            FOutput[i].Position = 0;
                        }
                        mutex?.ReleaseMutex();
                    }
                }
            }

            FOutput.Stream.IsChanged = false;
            if (FRead.Any())
            {
                FOutput.Flush(true);
            }
        }
        //called when data for any output pin is requested
        public void Evaluate(int spreadMax)
        {
            spreadMax = FDirectory.SliceCount
                        .CombineWith(FFileMask)
                        .CombineWith(FReload)
                        .CombineWith(FBufferSize)
                        .CombineSpreads(FPreloadFrames.SliceCount)
                        .CombineSpreads(FVisibleFrameId.SliceCount);


            FPlayers.ResizeAndDispose(spreadMax, (int slice) => new Player(FDirectory[slice], FFileMask[slice], FMemoryPool, FLogger));
            FFrameCount.SliceCount = spreadMax;
            FPreloaded.SliceCount  = spreadMax;

            int texSliceCount = spreadMax.CombineSpreads(SpreadUtils.SpreadMax(FVisibleFrameId as System.Collections.Generic.IEnumerable <ISpread <int> >));

            FTextureOutput.Resize(texSliceCount, () => new DX11Resource <DX11ResourceTexture2D>(), (t) => t.Dispose());
            FWidth.SliceCount  = texSliceCount;
            FHeight.SliceCount = texSliceCount;
            FLoaded.SliceCount = texSliceCount;

            FReadTime.SliceCount   = texSliceCount;
            FDecodeTime.SliceCount = texSliceCount;
            FGPUTime.SliceCount    = texSliceCount;

            for (int i = 0; i < spreadMax; i++)
            {
                if (FPlayers[i].DirectoryName != FDirectory[i] || FPlayers[i].FileMask != FFileMask[i] || FReload[i])
                {
                    FPlayers[i].Dispose();
                    FPlayers[i] = new Player(FDirectory[i], FFileMask[i], FMemoryPool, FLogger);
                }
                FPlayers[i].BufferSize = FBufferSize[i];
                if (FPlayers[i].FrameCount > 0)
                {
                    FPlayers[i].Preload(FPreloadFrames[i]);
                }

                FFrameCount[i] = FPlayers[i].FrameCount;
                FPreloaded[i].AssignFrom(FPlayers[i].Loaded);
            }
        }
Ejemplo n.º 7
0
        public void Evaluate(int SpreadMax)
        {
            if (Inputs.IsChanged)
            {
                //old signals must be disposed
                OutBuffer.Resize(0, () => { return(null); }, s => { if (s != null)
                                                                    {
                                                                        s.Dispose();
                                                                    }
                                 });
                for (int outSlice = 0; outSlice < SpreadMax; outSlice++)
                {
                    var sig = new TOperator();
                    sig.Inputs = new Spread <AudioSignal>(Inputs.SliceCount);

                    for (int i = 0; i < Inputs.SliceCount; i++)
                    {
                        sig.Inputs[i] = Inputs[i][outSlice];
                    }

                    OutBuffer.Add(sig);
                }
            }
        }
Ejemplo n.º 8
0
        public void Evaluate(int spreadMax)
        {
            // SpreadMax is not correct (should be correct in streams branch).
            spreadMax = FDirectoryIn
                        .CombineWith(FFilemaskIn)
                        .CombineWith(FBufferSizeIn)
                        .CombineWith(FVisibleFramesIn)
                        .CombineWith(FPreloadFramesIn)
                        .CombineWith(FReloadIn);

            FImagePlayers.Resize(spreadMax, CreateImagePlayer, DestroyImagePlayer);

            FImagePlayers.SliceCount       = spreadMax;
            FTextureOut.SliceCount         = spreadMax;
            FTextureWidthOut.SliceCount    = spreadMax;
            FTextureHeightOut.SliceCount   = spreadMax;
            FFrameCountOut.SliceCount      = spreadMax;
            FDurationIOOut.SliceCount      = spreadMax;
            FDurationTextureOut.SliceCount = spreadMax;
            FUnusedFramesOut.SliceCount    = spreadMax;
            FLoadedOut.SliceCount          = spreadMax;

            for (int i = 0; i < spreadMax; i++)
            {
                bool reload = FReloadIn[i] || FDirectoryIn.IsChanged || FFilemaskIn.IsChanged;

                var imagePlayer = FImagePlayers[i];

                if (imagePlayer.ThreadsIO != FThreadsIOConfig[i] || imagePlayer.ThreadsTexture != FThreadsTextureConfig[i])
                {
                    DestroyImagePlayer(imagePlayer);
                    imagePlayer      = CreateImagePlayer(i);
                    reload           = true;
                    FImagePlayers[i] = imagePlayer;
                }

                imagePlayer.Directories = FDirectoryIn[i];
                imagePlayer.Filemasks   = FFilemaskIn[i];

                if (reload)
                {
                    imagePlayer.Reload();
                    FMemoryPool.Clear();
                }

                int    frameCount      = 0;
                double durationIO      = 0.0;
                double durationTexture = 0.0;
                int    unusedFrames    = 0;
                var    loadedFrames    = FLoadedOut[i];

                var frame = imagePlayer.Preload(
                    FVisibleFramesIn[i],
                    FPreloadFramesIn[i],
                    FBufferSizeIn[i],
                    out frameCount,
                    out durationIO,
                    out durationTexture,
                    out unusedFrames,
                    ref loadedFrames);

                FTextureOut[i]         = frame;
                FTextureWidthOut[i]    = frame.Select(f => f.Metadata.Width).ToSpread();
                FTextureHeightOut[i]   = frame.Select(f => f.Metadata.Height).ToSpread();
                FFrameCountOut[i]      = frameCount;
                FDurationIOOut[i]      = durationIO;
                FDurationTextureOut[i] = durationTexture;
                FUnusedFramesOut[i]    = unusedFrames;
            }
        }
Ejemplo n.º 9
0
 public static void ResizeAndDispose <T>(this ISpread <T> spread, int sliceCount, Func <int, T> constructor)
     where T : IDisposable
 {
     spread.Resize(sliceCount, constructor, (t) => t.Dispose());
 }
Ejemplo n.º 10
0
 public static void ResizeAndDispose <T>(this ISpread <T> spread, int sliceCount)
     where T : IDisposable, new()
 {
     spread.Resize(sliceCount, () => new T(), (t) => t.Dispose());
 }
Ejemplo n.º 11
0
        protected override void FillBuffer(float[] buffer, int offset, int count)
        {
            //PerfCounter.Start("MultiSineYeppp");
            var spreadMax = Frequencies.CombineWith(Gains);

            Phases.Resize(spreadMax, () => default(float), f => f = 0);

            var oneDArraySize = spreadMax * count;

            //resize arrays
            if (phases.Length != oneDArraySize)
            {
                phases = new double[oneDArraySize];
            }
            if (sines.Length != oneDArraySize)
            {
                sines = new double[oneDArraySize];
            }

            //prepare phase array
            for (int slice = 0; slice < spreadMax; slice++)
            {
                var increment = TwoPi * Frequencies[slice] / SampleRate;
                var phase     = Phases[slice];

                for (int i = 0; i < count; i++)
                {
                    // Sinus Generator
                    phases[i + slice * count] = phase;

                    phase += increment;
                    if (phase > TwoPi)
                    {
                        phase -= TwoPi;
                    }
                    else if (phase < 0)
                    {
                        phase += TwoPi;
                    }
                }

                Phases[slice] = phase;
            }

            //calc sines
            Yeppp.Math.Sin_V64f_V64f(phases, 0, sines, 0, oneDArraySize);

            //write to output
            for (int slice = 0; slice < spreadMax; slice++)
            {
                var gain = Gains[slice];

                if (slice == 0)
                {
                    for (int i = 0; i < count; i++)
                    {
                        // Sinus Generator
                        buffer[i] = gain * (float)sines[i + slice * count];
                    }
                }
                else
                {
                    for (int i = 0; i < count; i++)
                    {
                        // Sinus Generator
                        buffer[i] += gain * (float)sines[i + slice * count];
                    }
                }
            }

            //PerfCounter.Stop("MultiSineYeppp");
        }
Ejemplo n.º 12
0
        public void Evaluate(int spreadMax)
        {
            // SpreadMax is not correct (should be correct in streams branch).
            spreadMax = FDirectoryIn
                        .CombineWith(FFilemaskIn)
                        .CombineWith(FBufferSizeIn)
                        .CombineWith(FFormatIn)
                        .CombineWith(FVisibleFramesIn)
                        .CombineWith(FPreloadFramesIn)
                        .CombineWith(FReloadIn);

            FImagePlayers.Resize(spreadMax, CreateImagePlayer, DestroyImagePlayer);

            FImagePlayers.SliceCount       = spreadMax;
            FTextureOut.SliceCount         = spreadMax;
            FTextureWidthOut.SliceCount    = spreadMax;
            FTextureHeightOut.SliceCount   = spreadMax;
            FFrameCountOut.SliceCount      = spreadMax;
            FDurationIOOut.SliceCount      = spreadMax;
            FDurationTextureOut.SliceCount = spreadMax;
            FUnusedFramesOut.SliceCount    = spreadMax;
            FLoadedOut.SliceCount          = spreadMax;

            // Release unused resources
            // Textures are accessed by render thread only
            // -> if a texture is in the pool it's really not in use
            // -> release all
            FTexturePool.ReleaseUnused(0);
            // Memory is accessed by multiple threads
            // -> if memory is in the pool it could be used by one of them in just a moment
            // -> keep a little of it to avoid too many reallocations
            FMemoryPool.ReleaseUnused(Environment.ProcessorCount);

            for (int i = 0; i < spreadMax; i++)
            {
                var imagePlayer = FImagePlayers[i];
                var reload      = FReloadIn[i];

                if (imagePlayer.ThreadsIO != FThreadsIOConfig[i] || imagePlayer.ThreadsTexture != FThreadsTextureConfig[i])
                {
                    DestroyImagePlayer(imagePlayer);
                    imagePlayer      = CreateImagePlayer(i);
                    reload           = true;
                    FImagePlayers[i] = imagePlayer;
                }

                var rescan = false;
                // Make copies to check for slice wise change
                if (!imagePlayer.Directories.SpreadEqual(FDirectoryIn[i]))
                {
                    imagePlayer.Directories = FDirectoryIn[i].ToSpread();
                    rescan = true;
                }
                if (!imagePlayer.Filemasks.SpreadEqual(FFilemaskIn[i]))
                {
                    imagePlayer.Filemasks = FFilemaskIn[i].ToSpread();
                    rescan = true;
                }

                if (reload)
                {
                    imagePlayer.Reload();
                }
                else if (rescan)
                {
                    imagePlayer.ScanDirectoriesAsync();
                }

                int    frameCount      = 0;
                double durationIO      = 0.0;
                double durationTexture = 0.0;
                int    unusedFrames    = 0;
                var    loadedFrames    = FLoadedOut[i];
                var    format          = EnumEntryToEx9Format(FFormatIn[i]);

                var frame = imagePlayer.Preload(
                    FVisibleFramesIn[i],
                    FPreloadFramesIn[i],
                    FBufferSizeIn[i],
                    format,
                    out frameCount,
                    out durationIO,
                    out durationTexture,
                    out unusedFrames,
                    ref loadedFrames);

                FTextureOut[i]         = frame;
                FTextureWidthOut[i]    = frame.Select(f => f.Metadata.Width).ToSpread();
                FTextureHeightOut[i]   = frame.Select(f => f.Metadata.Height).ToSpread();
                FFrameCountOut[i]      = frameCount;
                FDurationIOOut[i]      = durationIO;
                FDurationTextureOut[i] = durationTexture;
                FUnusedFramesOut[i]    = unusedFrames;
            }
        }
Ejemplo n.º 13
0
        public void Evaluate(int SpreadMax)
        {
            CalculatedSpreadMax = GetSpreadMax(SpreadMax);
            FInternalSignals.Resize(CalculatedSpreadMax, GetInstance, DisposeInstance);

            if (AnyInputChanged())
            {
                for (int i = 0; i < CalculatedSpreadMax; i++)
                {
                    var audioSignal = FInternalSignals[i];

                    if (audioSignal == null)
                    {
                        audioSignal = GetInstance(i);
                    }

                    SetParameters(i, audioSignal);
                }

                var outCount = 0;
                for (int i = 0; i < FInternalSignals.SliceCount; i++)
                {
                    outCount += FInternalSignals[i].Outputs.Count;
                }

                if (FOutputSignals.SliceCount != outCount)
                {
                    FOutputSignals.SliceCount = outCount;

                    var outSlice = 0;
                    for (int i = 0; i < FInternalSignals.SliceCount; i++)
                    {
                        for (int j = 0; j < FInternalSignals[i].Outputs.Count; j++)
                        {
                            FOutputSignals[outSlice] = FInternalSignals[i].Outputs[j];
                            outSlice++;
                        }
                    }
                }
            }

            SetOutputSliceCount(CalculatedSpreadMax);

            for (int i = 0; i < CalculatedSpreadMax; i++)
            {
                var audioSignal = FInternalSignals[i];
                if (audioSignal != null)
                {
                    SetOutputs(i, audioSignal);

                    if (audioSignal.PluginContext != null)
                    {
                        //let plugin editor draw itself
                        if (FFrameDivider == 0)
                        {
                            audioSignal.PluginContext.PluginCommandStub.EditorIdle();
                        }
                    }
                }
            }

            if (FPluginControl.SelectedSignal == null)
            {
                FPluginControl.SelectedSignal = FInternalSignals[0];
            }

            FPluginControl.SetSliceCount(FInternalSignals.SliceCount);

            FFrameDivider++;
            FFrameDivider %= 4;
        }
Ejemplo n.º 14
0
        public override void Evaluate(int SpreadMax)
        {
            CalculatedSpreadMax = GetSpreadMax(SpreadMax);
            FInternalSignals.Resize(CalculatedSpreadMax, GetInstance, x => { if (x != null)
                                                                             {
                                                                                 x.Dispose();
                                                                             }
                                    });

            if (AnyInputChanged())
            {
                for (int i = 0; i < CalculatedSpreadMax; i++)
                {
                    var audioSignal = FInternalSignals[i];

                    if (audioSignal == null)
                    {
                        audioSignal = GetInstance(i);
                    }

                    var tSignal = audioSignal as TSignal;
                    if (tSignal != null)
                    {
                        SetParameters(i, tSignal);
                    }
                }

                var outCount = 0;
                for (int i = 0; i < FInternalSignals.SliceCount; i++)
                {
                    outCount += FInternalSignals[i].Outputs.Count;
                }

                if (FOutputSignals.SliceCount != outCount)
                {
                    //FOutputSignals.SliceCount = outCount;
                    FOutputSignals.ResizeAndDispose(outCount, () => { return(null); });

                    var outSlice = 0;
                    for (int i = 0; i < FInternalSignals.SliceCount; i++)
                    {
                        for (int j = 0; j < FInternalSignals[i].Outputs.Count; j++)
                        {
                            FOutputSignals[outSlice] = FInternalSignals[i].Outputs[j];
                            outSlice++;
                        }
                    }
                }
            }

            SetOutputSliceCount(CalculatedSpreadMax);

            for (int i = 0; i < CalculatedSpreadMax; i++)
            {
                var audioSignal = FInternalSignals[i];

                var tSignal = audioSignal as TSignal;
                if (tSignal != null)
                {
                    SetOutputs(i, tSignal);
                }
            }
        }