reshapearray — Reshape an array, maintaining its capacity
Plugin opcode in emugens.
The reshapearray opcode changes the shape of an array, as long as this does not modify its capacity. It can be used to convert a 1D to a 2D array, or viceversa, or simply to modify the size of its dimensions, as long as the product remains constant.
array[] - The array to be reshaped (this is done inplace)
isize0 - The size of the first dimension
isize1 - The size of the second dimension (0 for 1D arrays). Defaults to 0
Here is an example of the reshapearray opcode. Play reshapearray.csd
Example 896. Example of the reshapearray opcode.
<CsoundSynthesizer> <CsOptions> ;-odac ;;;realtime audio out </CsOptions> <CsInstruments> sr = 44100 ksmps = 64 nchnls = 2 0dbfs = 1 ; This is the example file for reshapearray /* reshapearray Reshape an array, maintaining the capacity of the array (it does NOT resize the array). You can reshape a 2D array to another array of equal capacity of reshape a 1D array to a 2D array, or a 2D array to a 1D array reshapearray array[], inumrows, inumcols=0 works with i and k arrays, at i-time and k-time */ instr 1 ivalues[] fillarray 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 printarray ivalues reshapearray ivalues, 3, 4 printarray ivalues turnoff endin instr 2 kxs[][] init 3, 4 kxs fillarray 0, 1, 2, 3, \ 10, 11, 12, 13, \ 20, 21, 22, 23 reshapearray kxs, 4, 3 printarray kxs, 1, "", "kxs after" turnoff endin instr 3 kxs[][] init 3, 4 kxs fillarray 0, 1, 2, 3, \ 10, 11, 12, 13, \ 20, 21, 22, 23 reshapearray kxs, 12 printarray kxs, 1, "", "kxs after" turnoff endin </CsInstruments> <CsScore> i 1 0 0.01 i 2 1 0.01 i 3 2 0.01 </CsScore> </CsoundSynthesizer>