Adding your own Minc functions to einwrap.
Those of you who are interested in creating pieces using some sort of algorithmic control will undoubtedly find it useful to learn how to add your own C functions to the Minc interface. In the process you will also learn how to add signal processing functions.
1) cd to a good working location
2) tar xvf /u/paul/m325/my_einwrap.tar
you will now have a directory call my_einwrap.
I created a simple example function called gogo.c, whichsimply returns the sum of its arguments.
gogo(float *p, int n_args)
The array of floats, *p contains the arguments listed in parentheses when, in Minc, you say
for example. n_args contains the number of these arguments.
So, for example
would return the value 21 (1+2+3+4+2+9) as the 5th argument to einwrap.
All you have to do now is introduce the name 'gogo' to cmix/einwrap, and add it to the Makefile
To introduce it you would add the following line to the profile.c file.
The name in quotes will be recognized by Minc, and call the function not listed in quotes.
All Minc functions must be declared as type double.
Then just add it to the list of OBJS1 in the Makefile
OBJS1 = e.o mySND.o xaiff.headerinfo.o xaiff.sndloc.o profile.o gogo.o
Now 'make einwrap' will build a cmix/einwrap binary which recognizes the function gogo.
The function e.c contains the main busy work involved in calling nexty.c. Study that if you want to make more complicated signal processing changes. The code should be fairly self-explanatory. You only need to "introduce" functions in the profile.c function which are going to be used in Minc. (Just in case you want to use strings, consult the code for einwrap() and einwrap_in(), or ask me for help. There is a 3rd argument to Minc functions, which is a doubles version of the *p array, and must be used to read string arguments.)
Minc has no convenient way to use arrays. The built in method uses the load_array() and get_array() commands. The first argument of each call is the number (i.e. the name) of the array. There can be up to 32 different arrays. The rest of the arguments, up to 2048 of them, are the values of the array.
num = load_array(0, 1,3,9,8.1,4,8)
loads array 0 with the values 1,3,9,etc. and returns the value 6, which is the number of values in the array.
val = get_array(0, 2)
returns the value 9, the 2nd value of the array (the third, actually, since the first, 0th, value is in location 0)).
num = load_array(0, 1,3,7,6,8,9,11)
for(i=0, i<num; i=i+1)
will call einwrap 7 times at the starting times listed in the array.
Sometimes it is convenient to generate strings which will be used for programs like einwrap or rt.
Minc has a built in function called str_num() (for string,num,string,num etc.) which roughly does the job of printf.
It has the form
str_num("string1", num1, "string2", num2, "string3", num3, ......)
str_num("einwrap(", x=23, ",dur=", x, ")")
will result in the string
being printed out. Note that it is necessary to print the commas.
I generally will create a minc script containing a bunch of these commands, run it using a generic cmix program called ctest, which won't recognize specialized commands such as einwrap(), and grep for the strings.
ctest < minc.file | grep einwrap > output
will save the results generated in the minc.file, which contain
the string einwrap, in a file called output.