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


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


nsamp(x) (init-rate args only)


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.


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

Example 281. Example of the nsamp opcode.

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

; 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

; 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


; 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


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


Author: Gabriel Maldonado
October 1998

Example written by Kevin Conder.