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, ftlen 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, and mary.wav.

Example 293. 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
    ; Audio out   Audio in
    -odac           -iadc    ;;;RT audio I/O
    ; For Non-realtime ouput leave only the line below:
    ; -o nsamp.wav -W ;;; for file output any platform
    </CsOptions>
    <CsInstruments>

    ; Initialize the global variables.
    sr = 44100
    kr = 4410
    ksmps = 10
    nchnls = 1

    ; Instrument #1.
    instr 1
      ; Print out the size (in samples) of Table #1.
      isz = nsamp(1)
      print isz
    endin

    </CsInstruments>
    <CsScore>

    ; Table #1: Use an audio file.
    f 1 0 262144 1 "mary.wav" 0 0 0

    ; Play Instrument #1 for 1 second.
    i 1 0 1
    e

    </CsScore>
    </CsoundSynthesizer>

Since the audio file “mary.wav” has 154390 samples, its output should include a line like this:

    instr 1:  isz = 154390.000

## See Also

ftchnls, ftlen, ftlptim, ftsr

## Credits

Author: Gabriel Maldonado
Italy
October 1998

Example written by Kevin Conder.

Prev | Up | Next
nrpn | Home | nstrnum