Example #1
0
 protected override void InitalizeConcreteAudioEffect()
 {
     AudioTremoloEffect.TremoloEffectInit((short)audioEffectParameters["Effect Rate"], (double)audioEffectParameters["Depth Rate"]);
 }
        private void TremoloWaveEffectWorkHandler(object sender, DoWorkEventArgs e)
        {
            List <object> passedParams = e.Argument as List <object>;
            int           effectRate   = (int)passedParams[0];
            double        depthRate    = (double)passedParams[1];

            this.disp.Invoke(DispatcherPriority.Normal, new Action(delegate()
            {
                audioItem = AudioItemManager.GetAudioItem();
            }));

            if (audioItem != null)
            {
                SetMaxProgressBar();

                float[] samplesToProcess;
                long    beginIndex, endIndex;
                int     seconds, miliseconds, minutes;
                int     timeElapsed = 0;
                int     fullTime    = 0;
                SetDataForProcessing(out samplesToProcess, out minutes, out beginIndex, out endIndex, out seconds, out miliseconds);

                AudioTremoloEffect.TremoloEffectInit((short)effectRate, depthRate);

                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] = AudioTremoloEffect.TremoloEffectProcess(samplesToProcess[i], ref timeElapsed);
                                fullTime           += timeElapsed;
                            }
                        }));
                    }
                    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] = AudioTremoloEffect.TremoloEffectProcess(samplesToProcess[i], ref timeElapsed);
                        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   += timeElapsed;
                        timeElapsed = 0;
                    }
                }

                ResetProgressBar();

                audioItem.ProcessedAudioBuffer = samplesToProcess;

                AudioItemManager.SetAudioItem(audioItem);

                var milisecondsTime = fullTime / 1000;

                e.Result = "Selection : " + minutes + ":" + seconds + ":" + miliseconds + " - " + AudioItemManager.Instance.GetEndSpan().Minutes.ToString() + ":" + AudioItemManager.Instance.GetEndSpan().Seconds.ToString() + ":" + AudioItemManager.Instance.GetEndSpan().Milliseconds.ToString()
                           + "  " + " -> Processed Tremolo 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!";
            }
        }
Example #3
0
 public void PorcessSample(object sampleToProcess, ref int timeElapsed)
 {
     AudioTremoloEffect.TremoloEffectProcess((float)sampleToProcess, ref timeElapsed);
 }