예제 #1
0
        private void FlangerEffectWorkHandler(object sender, DoWorkEventArgs e)
        {
            List <object> passedParams = e.Argument as List <object>;
            int           effectRate   = (int)passedParams[0];
            int           maxD         = (int)passedParams[1];
            int           minD         = (int)passedParams[2];
            double        fwv          = (double)passedParams[3];
            double        step         = (double)passedParams[4];
            double        fbv          = (double)passedParams[5];

            audioItem = AudioItemManager.GetAudioItem();

            if (audioItem != null)
            {
                SetMaxProgressBar();
                float[] samplesToProcess;
                long    beginIndex, endIndex;
                int     seconds, miliseconds, minutes;
                int     elapsedTime = 0;
                int     fullTime    = 0;
                SetDataForProcessing(out samplesToProcess, out minutes, out beginIndex, out endIndex, out seconds, out miliseconds);

                AudioFlangerEffect.FlangerInit((short)effectRate, 16000, (short)maxD, (short)minD, fwv, step, fbv);

                if (threadsValue > 1)
                {
                    samplesCountForThreads = (int)((endIndex - beginIndex) / threadsValue);
                    samplesThreadToProcess = new int[threadsValue];

                    for (int i = 0; i < threadsValue; i++)
                    {
                        samplesThreadToProcess[i] = (int)beginIndex + (samplesCountForThreads * i);
                    }
                    samplesThreadToProcess[threadsValue - 1] = (int)endIndex - 1;

                    for (int x = 0; x < threadsValue - 1; x++)
                    {
                        int startIndex, stopIndex;
                        startIndex = samplesThreadToProcess[x];
                        stopIndex  = samplesThreadToProcess[x + 1];


                        threads.Add(new Thread(() =>
                        {
                            for (int i = startIndex; i < stopIndex + 1; i++)
                            {
                                samplesToProcess[i] = AudioFlangerEffect.FlangerProcess(samplesToProcess[i], ref elapsedTime);
                                AudioFlangerEffect.FlangerSweep();
                                fullTime += elapsedTime;
                            }
                        }));
                    }

                    for (int i = 0; i < threadsValue - 1; i++)
                    {
                        threads[i].Start();
                        threads[i].Join();
                        var first = i;
                        var range = threadsValue - 1;
                        var z     = (double)first / range;
                        worker.ReportProgress((int)(z * 100));
                    }
                }
                else
                {
                    for (long i = beginIndex; i < endIndex; ++i)
                    {
                        samplesToProcess[i] = AudioFlangerEffect.FlangerProcess(samplesToProcess[i], ref elapsedTime);
                        AudioFlangerEffect.FlangerSweep();
                        if (i % 8000 == 0 && i != 0)
                        {
                            var first = i - beginIndex;
                            var range = endIndex - beginIndex;
                            var x     = (double)first / range;
                            worker.ReportProgress((int)(x * 100));
                            System.Threading.Thread.Sleep(50);
                        }
                        fullTime += elapsedTime;
                    }
                }

                ResetProgressBar();

                audioItem.ProcessedAudioBuffer = samplesToProcess;

                AudioItemManager.SetAudioItem(audioItem);

                var milisecondsTime = (double)fullTime / 1000;

                e.Result = "Selection : " + minutes + ":" + seconds + ":" + miliseconds + " - " + AudioItemManager.Instance.GetEndSpan().Minutes.ToString() + ":" + AudioItemManager.Instance.GetEndSpan().Seconds.ToString() + ":" + AudioItemManager.Instance.GetEndSpan().Milliseconds.ToString()
                           + "  " + " -> Processed Flanger effect on audio sample!" + "\nProcessing range length: " + (endIndex - beginIndex).ToString() +
                           "\n" + dllType.ToString() + " library time elapsed: " + milisecondsTime.ToString() + " msec" + "\nThreads count: " + threadsValue.ToString();
            }
            else
            {
                e.Result = "Audio not loaded!";
            }
        }
예제 #2
0
 public void PorcessSample(object sampleToProcess, ref int timeElapsed)
 {
     AudioFlangerEffect.FlangerProcess((float)sampleToProcess, ref timeElapsed);
     AudioFlangerEffect.FlangerSweep();
 }