protected override void InitalizeConcreteAudioEffect() { AudioDistortionEffect.DistortionEffectInit((float)audioEffectParameters["Maxmimum Value"]); }
private void DistortionEffectWorkHandler(object sender, DoWorkEventArgs e) { 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); float biggest = samplesToProcess.Max() / 8f; AudioDistortionEffect.DistortionEffectInit(biggest); 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] = AudioDistortionEffect.DistortionEffectProcess(samplesToProcess[i], ref elapsedTime); 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) { elapsedTime = 0; samplesToProcess[i] = AudioDistortionEffect.DistortionEffectProcess(samplesToProcess[i], ref elapsedTime); 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 Distortion 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!"; } }
public void PorcessSample(object sampleToProcess, ref int timeElapsed) { AudioDistortionEffect.DistortionEffectProcess((float)sampleToProcess, ref timeElapsed); }