This should play if your Web browser has WebAssembly enabled (most do). Most examples will play unless they need to load files. The first time you click Play, Csound will spend a few seconds loading, then play. You can edit this code and replay it.
; Select audio/midi flags here according to platform ; Audio out Audio in No messages -odac -iadc -d ;;;RT audio I/O ; For Non-realtime ouput leave only the line below: ; -o planet.wav -W ;;; for file output any platform ; Required settings for WebAudio: sr = 48000 ksmps = 128 nchnls = 2 nchnls_i = 1 ; Initialize the global variables. ; sr = 44100 ; kr = 44100 ; ksmps = 1 ; nchnls = 2 ; Instrument #1 - a planet oribiting in 3D space. instr 1 ; Create a basic tone. kamp init 5000 kcps init 440 ifn = 1 asnd oscil kamp, kcps, ifn ; Figure out its X, Y, Z coordinates. km1 init 0.5 km2 init 0.35 ksep init 2.2 ix = 0 iy = 0.1 iz = 0 ivx = 0.5 ivy = 0 ivz = 0 ih = 0.0003 ifric = -0.1 ax1, ay1, az1 planet km1, km2, ksep, ix, iy, iz, \ ivx, ivy, ivz, ih, ifric ; Place the basic tone within 3D space. kx downsamp ax1 ky downsamp ay1 kz downsamp az1 idist = 1 ift = 0 imode = 1 imdel = 1.018853416 iovr = 2 aw2, ax2, ay2, az2 spat3d asnd, kx, ky, kz, idist, \ ift, imode, imdel, iovr ; Convert the 3D sound to stereo. aleft = aw2 + ay2 aright = aw2 - ay2 outs aleft, aright endin ; Table #1 a sine wave. f 1 0 16384 10 1 ; Play Instrument #1 for 10 seconds. i 1 0 10 e