change matrix dimensions from inside custom external
Feb 14 2015 | 5:02 pm
hi there
i'm working on an external that does phase vocoder analysis of buffer based audio data and stores the results into a user specified jitter matrix. as i don't know the length of the audio data before hand, i need to be able to change the matrix dimensions before starting to write into it.
i found a very easy way to do this, but i'm not sure whether it's safe!
basically i'm filling out a t_jit_matrix_info with the dimensions i need and apply it to the matrix in question through _jit_sym_setinfo (see code below).
obviously there's some memory (re)allocation going on under the hood - do i need to watch out for something?
so far it seems to work just fine.
thanks,
volker.
int myObj_checkDims(t_myObj *x, long dim0, long dim1, long pc) { t_jit_matrix_info minfo; void *matrix; long savelock; matrix = jit_object_findregistered(x->matrix_name); if (matrix&&jit_object_method(matrix, _jit_sym_class_jit_matrix)) { savelock = (long) jit_object_method(matrix,_jit_sym_lock,1); jit_object_method(matrix,_jit_sym_getinfo,&minfo); // check if dimensions changed if(minfo.dim[0]!=dim0 || minfo.dim[1]!=dim1 || minfo.planecount!=pc) { minfo.dim[0] = dim0; minfo.dim[1] = dim1; minfo.planecount = pc; // set correct matrix dims and planecount... jit_object_method(matrix,_jit_sym_setinfo,&minfo); } jit_object_method(matrix,_jit_sym_lock,savelock); return 1; } else { jit_error_sym(x,_jit_sym_err_calculate); return 0; } }