nsamp
Prev | Orchestra Opcodes and Operators | Next

## nsamp

nsamp — Returns the number of samples loaded into a stored function table number.

## Description

Returns the number of samples loaded into a stored function table number.

## Syntax

    nsamp(x) (init-rate args only)

## Performance

Returns the number of samples loaded into stored function table number x by GEN01. This is useful when a sample is shorter than the power-of-two function table that holds it. New in Csound version 3.49.

As of Csound version 5.02, nsamp works with deferred-length function tables (see GEN01).

nsamp differs from ftlen in that nsamp gives the number of sample frames loaded, while ftlen gives the total number of samples. For example, with a stereo sound file of 10000 samples, ftlen() would return 19999 (i.e. a total of 20000 mono samples, not including a guard point), but nsamp() returns 10000.

## Examples

Here is an example of the nsamp opcode. It uses the file nsamp.csd, kickroll.wav. and fox.wav.

Example 493. Example of the nsamp opcode.

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

    <CsoundSynthesizer>
    <CsOptions>
    ; Select audio/midi flags here according to platform
    -odac     ;;;realtime audio out
    ;-iadc    ;;;uncomment -iadc if realtime audio input is needed too
    ; For Non-realtime ouput leave only the line below:
    ; -o nsamp.wav -W ;;; for file output any platform
    </CsOptions>
    <CsInstruments>
    ; slightly adapted example from Jonathan Murphy Dec 2006

    sr = 44100
    ksmps = 32
    nchnls = 2
    0dbfs  = 1

    instr 1

    ifn   =  p4	; table number
    ilen  =  nsamp(ifn)
    prints "actual numbers of samples = %d\n", ilen
    itrns =  1	; no transposition
    ilps  =  0	; loop starts at index 0
    ilpe  =  ilen	; ends at value returned by nsamp above
    imode =  1	; loops forward
    istrt =  0	; commence playback at index 0 samples
    ; lphasor provides index into f1
    alphs lphasor itrns, ilps, ilpe, imode, istrt
    atab  tablei  alphs, ifn
          outs atab, atab

    endin
    </CsInstruments>
    <CsScore>
    f 1 0 262144 1 "kickroll.wav" 0 4 1	;stereo file in table, with lots of zeroes
    f 2 0 262144 1 "fox.wav" 0 4 1		;mono file in table, with lots of zeroes

    i1 0 10 1
    i1 + 10 2
    e

    </CsScore>
    </CsoundSynthesizer>

Since the stereo audio file “kickroll.wav” has 37792 samples and the mono file “fox.wav” has 121569 samples, its output should include lines like these:

    actual numbers of samples = 37792
    actual numbers of samples = 121569

## See Also

ftchnls, ftlen, ftlptim, ftsr

## Credits

Author: Gabriel Maldonado
Italy
October 1998

Prev | Up | Next
nrpn | Home | nstrnum