sr — Sets the audio sampling rate.


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.


sr = iarg


sr = (optional) -- set sampling rate to iarg samples per second per channel. The default value is 44100.

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, sr may be omitted. The sample rate will be calculated from kr and ksmps, but this must evaluate to an integer. If none of these global values is defined, the sample rate will default to 44100. You will usually want to use a value that your soundcard supports, like 44100 or 48000, otherwise, the audio generated by csound may be unplayable, or you will get an error if you attempt to run in real-time. You may naturally use a sample rate like 96000, for off-line rendering even if your soundcard does not support it. Csound will generate a valid file that can be played on capable systems.


sr = 10000
kr = 500
ksmps = 20
gi1 = sr/2.
ga init 0
itranspose = octpch(.0l)

Here is another example of the sr opcode. It uses the file sr.csd.

Example 1027. Example of the sr 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
; -iadc    ;;;uncomment -iadc if real audio input is needed too
; For Non-realtime ouput leave only the line below:
; -o sr.wav -W ;;; for file output any platform

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

instr 1	;use sr to find maximum harmonics

ihar	= int(sr/2/p4)		; maximum possible number of harmonics w/o aliasing
prints  "maximum number of harmonics = %d \\n", ihar
kenv	linen .5, 1, p3, .2	; envelope
asig	buzz  kenv, p4, ihar, 1
	outs  asig, asig

f1 0 4096 10 1	;sine wave

i 1 0 3 100	;different frequencies
i 1 + 3 1000
i 1 + 3 10000

Its output should include lines like this:

maximum number of harmonics = 240 
maximum number of harmonics = 24 
maximum number of harmonics = 2 

See also

Orchestra Header Statements