trim
Prev | Orchestra Opcodes and Operators | Next

## trim

trim — Adjust size o a one-dimensional array.

## Description

Lengthen or shorten a one-dimensional array.

## Syntax

    trim_i iarray, ilen

    trim xarray, klen

## Performance

iarray -- a one-dimensional irate array

xarray -- a one-dimensional array

klen -- desired length

Makes the array the desired length, either truncating or padding with zero/Null values.

## Examples

Here is an example of the trim opcode. It uses the file trim.csd.

Example 1079. Example of the trim opcode.

See the sections Real-time Audio and Command Line Flags for more information on using command line flags.

    <CsoundSynthesizer>
    <CsOptions>
    -n
    </CsOptions>
    <CsInstruments>
    instr 1
        kA1[]   fillarray       0, 1, 2, 3, 4, 5, 6, 7 ; <-- 8 elements
                printf          "lenarray(kA1) before slicearray: %d\n", 1, lenarray:k(kA1)
                kA1     slicearray      kA1, 1, 4 ; <-- 4 elements
                printf          "lenarray(kA1) AFTER  slicearray: %d\n", 1, lenarray:k(kA1)
                trim            kA1, 4
                printks         "kA1 after trim: { ", 0
          kCnt    =               0

        while (kCnt < lenarray:k(kA1)) do
                        printf  "%d ", kCnt + 1, kA1[kCnt]
                kCnt    +=      1
         od

                printks         "}\n", 0
                turnoff
    endin

    </CsInstruments>

    <CsScore>
    i1  0 0.1
    e
    </CsScore>

    </CsoundSynthesizer>

## See Also

slicearray

## Credits

Author: John ffitch 2018

New in version 6.12

Prev | Up | Next
trigseq | Home | trirand