Making A DCT in a for loop faster

Hi All,


I need to run a DCT on multiple signals (time slices of the same audio signal).


My current code looks like this:


var ci = Array(stride(from: Float(0), to: Float(y.count), by: Float(p)))


var c = Array<Float>(repeating:0.0, count:y.count)


for (index,value) in ci.enumerated() {


var i = index

var v = Int(value)

var newArray = Array(y[v...(v+Int(p)-1)])


let DCTSetup = vDSP_DCT_CreateSetup(nil, vDSP_Length(newArray.count), vDSP_DCT_Type.II)


var nac = Array<Float>(repeating:0.0, count:newArray.count)

vDSP_DCT_Execute(DCTSetup!, &newArray, &nac)


//c.append(contentsOf: nac)

c.insert(contentsOf: nac, at: v)

}


//c.removeFirst()


But this is taking ages. So for a 10 second audio sample it takes well over 60 seconds.

Is there a way of doing a DCT on multiple signal quickly? (I have made up an array of each sample appended to the other for this computation).


Hope you can help,


Best,


Feras A.

Replies

Did you try to use Instruments / Time to understand where you spend most time ?