I have a 2D graph which takes a long time to process.

The code processes all the horizontal lines in a loop as small workloads, and adds the lines to a big 2D array.

I don't know how to do the horizontal lines on multiple threads, and write to the big array on the main thread. I have written some multi-thread code which writes the graph wrong. It crashes with an "out of range" exception if I queue the big 2D graph on the main thread.

Here is the code, please suggest a workaround, cheers!

function run () {

        var tfgraph = GetComponent.<TFgraph>();
        var graphLenSamples = NumCubes*TEXSIZE*skipGraphX;
        var fastRunFreqs = TEXSIZE/20;
        var a1: float[] = new float [10];

        for ( var j = 0; j < TEXSIZE; j+= 1)// FREQUENCY SWEEPS Y AXIS------------------

            buttonText= (j*100/TEXSIZE).ToString() + " % ";  yield WaitForSeconds(0.001); 
            var filterSweepFreq  : float = p2f ((higestNote/TEXSIZE)*j) ; //map texsize up to 132 notes and p2f it. //lowestNote
            var SamplesPerPeriod : float =  (srate/filterSweepFreq)/4.0;
            Loom.RunAsync(function() {//multithread start
            var filter   = new BiQuad1.BandpassFilter(srate, filterSweepFreq);  
            var thresh   = 0.08;
            var delay   :float[]  =     new float[samples.Length/2+30000];  
            for (  var i = 0; i <graphLenSamples; ++i) // SAMPLES INTO FILTER------------------
                delay[i] =  filter.Process( AudioBits[i] )*10.0;

                var data2  = ap1(filterSweepFreq, delay[i]) ;

                delay[i]   =  Mathf.Sqrt( data2*data2 + delay[i]*delay[i] )*(1.0/loudestSample) ; //get envelope of signal. 

                if(i%skipGraphX == 0)
                Loom.QueueOnMainThread(function() {//main thread    
                writebig((i+FFWsecs*srate)/skipGraphX, j, delay[i]*amplifySignal, finishTex) ;
                });//end main thread

            });//end multithread


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.