ksmps — Sets the number of samples in a control period.


These statements are global value assignments, made at the beginning of an orchestra, before any instrument block is defined. Their function is to set certain reserved symbol variables that are required for performance. Once set, these reserved symbols can be used in expressions anywhere in the orchestra.


ksmps = iarg


ksmps = (optional) -- set the number of samples in a control period. This value must equal sr/kr. The default value is 10.

In addition, any global variable can be initialized by an init-time assignment anywhere before the first instr statement. All of the above assignments are run as instrument 0 (i-pass only) at the start of real performance.

Beginning with Csound version 3.46, either ksmps may be omitted. Csound will attempt to calculate the omitted value from the specified sr and krvalues, but it should evaluate to an integer.

[Warning] Warning

ksmps must be an integer value.


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

Example 510. Example of the ksmps 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
-odac      ;;;realtime audio out

; By Stefano Cucchi - 2024


sr = 48000 

; If you set ksmps = 24000, then kr = 2, so you hear 2 step every sec.
ksmps = 24000

; If you set ksmps = 32, then kr = 1500. You can hear a smooth glissando
;ksmps = 32 

nchnls = 2
0dbfs = 1

instr 1
  kamp = 0.4
  kfreq expseg p4, p3, p5
  a1 oscil3 kamp, kfreq, 1
  outs a1, a1


f 1 0 524288 10 1

i 1 0 15 100  13000

See also

Orchestra Header Statements


Thanks to a note from Gabriel Maldonado, added a warning about integer values.