String -- a string that names an opcode function, at i-rate for maparrayi or k-rate for maparray.
Performance
karray -- array for answers.
kinarray -- array for arguments to the function.
Replacing tabmap and tabmap_i
tabmap maps a k-rate array during initialization and on each control cycle. Change kResult = tabmap(kSource, "abs") to kResult = maparray(kSource, "abs").
tabmap_i and its alias tabmapi run only at initialization. Replace either name with maparrayi to keep that timing. maparray_i is the older spelling of maparrayi.
The source must be initialized and one-dimensional. Use a supported one-input scalar function such as abs. Initialization-only mapping requires its i-rate form. Repeated k-rate mapping needs both i-rate and k-rate forms. This is not an interface for arbitrary stateful opcodes.
Examples
Here is an example of the maparray opcode. It uses the file maparray-modern.csd.
<CsoundSynthesizer><CsOptions>; Select audio/midi flags here according to platform-n
</CsOptions><CsInstruments>sr=44100ksmps=32nchnls=20dbfs=1instr1;create an array and fill with numbersArrSrc:k[]=fillarray(1.01,2.02,3.03,4.05,5.08,6.13,7.21);print source arrayprintf("%s",1,"\nSource array:\n")ndx:k=0untilndx==lenarray(ArrSrc)doprintf("ArrSrc[%d] = %f\n",ndx+1,ndx,ArrSrc[ndx])ndx+=1od;create an empty array for the resultsArrRes:k[]=init(7);apply the sqrt() function to each elementArrRes=maparray(ArrSrc,"sqrt");print the resultprintf("%s",1,"\nResult after applying sqrt() to source array\n")ndx=0untilndx==lenarray(ArrRes)doprintf("ArrRes[%d] = %f\n",ndx+1,ndx,ArrRes[ndx])ndx+=1od;apply the log() function to each elementArrRes=maparray(ArrSrc,"log");print the resultprintf("%s",1,"\nResult after applying log() to source array\n")ndx=0untilndx==lenarray(ArrRes)doprintf("ArrRes[%d] = %f\n",ndx+1,ndx,ArrRes[ndx])ndx+=1od;apply the int() function to each elementArrRes=maparray(ArrSrc,"int");print the resultprintf("%s",1,"\nResult after applying int() to source array\n")ndx=0untilndx==lenarray(ArrRes)doprintf("ArrRes[%d] = %f\n",ndx+1,ndx,ArrRes[ndx])ndx+=1od;apply the frac() function to each elementArrRes=maparray(ArrSrc,"frac");print the resultprintf("%s",1,"\nResult after applying frac() to source array\n")ndx=0untilndx==lenarray(ArrRes)doprintf("ArrRes[%d] = %f\n",ndx+1,ndx,ArrRes[ndx])ndx+=1od;turn instrument instance offturnoff()endin</CsInstruments><CsScore>i100.1e</CsScore></CsoundSynthesizer>
Here is an example of the maparray opcode. It uses the file maparray.csd.
<CsoundSynthesizer><CsOptions>; Select audio/midi flags here according to platform-n
</CsOptions><CsInstruments>sr=44100ksmps=32nchnls=20dbfs=1instr1;create an array and fill with numberskArrSrc[]fillarray1.01,2.02,3.03,4.05,5.08,6.13,7.21;print source arrayprintf"%s",1,"\nSource array:\n"kndx=0untilkndx==lenarray(kArrSrc)doprintf"kArrSrc[%d] = %f\n",kndx+1,kndx,kArrSrc[kndx]kndx+=1od;create an empty array for the resultskArrRes[]init7;apply the sqrt() function to each elementkArrResmaparraykArrSrc,"sqrt";print the resultprintf"%s",1,"\nResult after applying sqrt() to source array\n"kndx=0untilkndx==lenarray(kArrRes)doprintf"kArrRes[%d] = %f\n",kndx+1,kndx,kArrRes[kndx]kndx+=1od;apply the log() function to each elementkArrResmaparraykArrSrc,"log";print the resultprintf"%s",1,"\nResult after applying log() to source array\n"kndx=0untilkndx==lenarray(kArrRes)doprintf"kArrRes[%d] = %f\n",kndx+1,kndx,kArrRes[kndx]kndx+=1od;apply the int() function to each elementkArrResmaparraykArrSrc,"int";print the resultprintf"%s",1,"\nResult after applying int() to source array\n"kndx=0untilkndx==lenarray(kArrRes)doprintf"kArrRes[%d] = %f\n",kndx+1,kndx,kArrRes[kndx]kndx+=1od;apply the frac() function to each elementkArrResmaparraykArrSrc,"frac";print the resultprintf"%s",1,"\nResult after applying frac() to source array\n"kndx=0untilkndx==lenarray(kArrRes)doprintf"kArrRes[%d] = %f\n",kndx+1,kndx,kArrRes[kndx]kndx+=1od;turn instrument instance offturnoffendin</CsInstruments><CsScore>i100.1e</CsScore></CsoundSynthesizer>