csound / manual

Csound Reference Manual (English)
Other
45 stars 28 forks source link

opcodes need cool examples #738

Open tjingboem opened 1 month ago

tjingboem commented 1 month ago

There are examples for these opcodes but they only print a value. Cool examples can be added to show their (basic) musical application

AsterixMusic commented 1 month ago

Example for "ksmps"


<CsoundSynthesizer>
<CsOptions>

; Select audio/midi flags here according to platform
-odac      ;;;realtime audio out
;-iadc    ;;;uncomment -iadc if realtime audio input is needed too

; By Stefano Cucchi - 2024

</CsOptions>

<CsInstruments>

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
endin

</CsInstruments>
<CsScore>

f 1 0 524288 10 1

i 1 0 15 100  13000

e

</CsScore>
</CsoundSynthesizer>
tjingboem commented 1 month ago

ksmps.csd added, thanks!

https://csound.com/manual/ksmps.html

csounder commented 1 month ago

In the comments, I think you mean to say... (you say 24000 in both cases.

; If you set ksmps = 32, then kr = 1.500: you can hear a smooth glissando

;ksmps = 32

- Dr.B

Dr. Richard Boulanger

Professor

Electronic Production and Design

Berklee College of Music

Professional Writing & Technology Division

On Sun, Jun 2, 2024 at 2:55 PM Stefano Cucchi @.***> wrote:

Example for "ksmps"

; Select audio/midi flags here according to platform -odac ;;;realtime audio out;-iadc ;;;uncomment -iadc if realtime audio input is needed too ; 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 = 24000, then kr = 1.500: you can hear a smooth glissando;ksmps = 32 nchnls = 20dbfs = 1instr 1 kamp = 0.4 kfreq expseg p4, p3, p5 a1 oscil3 kamp, kfreq, 1 outs a1, a1endin f 1 0 524288 10 1i 1 0 15 100 13000e

— Reply to this email directly, view it on GitHub https://us-west-2.protection.sophos.com?d=github.com&u=aHR0cHM6Ly9naXRodWIuY29tL2Nzb3VuZC9tYW51YWwvaXNzdWVzLzczOCNpc3N1ZWNvbW1lbnQtMjE0Mzk4NTU4Mg==&i=NWYxNzBkMDNiNTVmZGEwZmIyNjczYmRm&t=NDR3ZkVqRGNjYzlYazZmbkhXMFJoUnU0Z3VJRlZhV01ieWpZVkJveGtmVT0=&h=51156587e7a841059e642fb34b2d62f1&s=AVNPUEhUT0NFTkNSWVBUSVZ-CzEl059Ym1RlqwKl3ZhNfC-dR2N5IDL9CUAdMA_6tA, or unsubscribe https://us-west-2.protection.sophos.com?d=github.com&u=aHR0cHM6Ly9naXRodWIuY29tL25vdGlmaWNhdGlvbnMvdW5zdWJzY3JpYmUtYXV0aC9BQUxXWUZWNjZDUE1HM1BFTUozWDNBTFpGTlRESkFWQ05GU002QUFBQUFCSVNSNElFS1ZISTJEU01WUVdJWDNMTVY0M09TTFRPTjJXS1EzUE5WV1dLM1RVSE1aRENOQlRIRTRES05KWUdJ&i=NWYxNzBkMDNiNTVmZGEwZmIyNjczYmRm&t=d0ZkRzRBdVU3U2J5M3lSN0hoK1hIZk1xZVBrTUFPZnl5NHQ0MVA2aWhpWT0=&h=51156587e7a841059e642fb34b2d62f1&s=AVNPUEhUT0NFTkNSWVBUSVZ-CzEl059Ym1RlqwKl3ZhNfC-dR2N5IDL9CUAdMA_6tA . You are receiving this because you are subscribed to this thread.Message ID: @.***>

AsterixMusic commented 1 month ago

2 examples for "poisson"

1) simple example


<CsoundSynthesizer>
<CsOptions>

; Select audio/midi flags here according to platform
-odac     ;;;realtime audio out
;-iadc    ;;;uncomment -iadc if RT audio input is needed too
; For Non-realtime ouput leave only the line below:
; -o loop_ge.wav -W ;;; for file output any platform

; By Stefano Cucchi - 2024

</CsOptions>
<CsInstruments>

; Initialize the global variables.

sr     =        48000
kr     =        32
nchnls =        2
0dbfs = 1

instr 1

klambda expseg p4, p3, p5
kpitch poisson klambda
printk (ksmps/sr),kpitch ;prints every k-period

a1 oscili 0.3, kpitch, 1
outs a1, a1

endin

</CsInstruments>
<CsScore>

f1 0 4096 10 1 0.1 0 0.2 0 0.3 0 0.1

i 1 0 10 300 300

e

</CsScore>

</CsoundSynthesizer>

2) "musical" example


<CsoundSynthesizer>
<CsOptions>

; Select audio/midi flags here according to platform
-odac     ;;;realtime audio out
;-iadc    ;;;uncomment -iadc if RT audio input is needed too
; For Non-realtime ouput leave only the line below:
; -o loop_ge.wav -W ;;; for file output any platform

; By Stefano Cucchi - 2024

</CsOptions>
<CsInstruments>

sr      =      48000
kr      =       4800
ksmps   =       10
nchnls  =   2
0dbfs  = 1

instr 1

klambda1 linseg p4, p3, p5
kindex poisson klambda1

klambda2 linseg p6, p3, p7
ktrigfreq poisson klambda2

ksig oscil 1, ktrigfreq
ktrig trigger ksig, 0, 0

schedkwhen ktrig, 0, 20, 10, 0, 0.2, kindex, 10

endin 

instr 10      

kcnt = p4
kpc     table   kcnt, p5         
kcps    =       cpspch(kpc)   

asig1    oscil   0.5, kcps, 1    

kenvelope linseg 0, p3*0.5, 1, p3*0.5, 0

asig1 = asig1*kenvelope
outs asig1, asig1  

endin       

</CsInstruments>
<CsScore>

f 1 0 4096 10 1 0 1 0 1 0 0 1 1 

f 10 0 24 -2 8.00 8.01 8.02 8.03 8.04 8.05 8.06 8.07 8.08 8.09 8.10 8.11 9.00 9.01 9.02 9.03 9.04 9.05 9.06 9.07 9.08 9.09 9.10 9.11 

i1 0 30 0 23 2 17

e

</CsScore>
tjingboem commented 1 month ago

Could you @AsterixMusic agree to change the examples to sr = 44100 ksmps = 32 nchnls = 2 0dbfs = 1

It will sound a bit different. Can you check them out please?

AsterixMusic commented 1 month ago

@tjingboem You can change the examples!

tjingboem commented 1 month ago

thanks. I changed them a bit they will be part of the manual soon

csounder commented 1 month ago

All three of these are wonderful examples - thanks Stefano!!!

I hope that you can find the time to make more of the 'missing' opcode examples.

THANKS!

- Dr.B

Dr. Richard Boulanger

Professor

Electronic Production and Design

Berklee College of Music

Professional Writing & Technology Division

On Sun, Jun 2, 2024 at 2:55 PM Stefano Cucchi @.***> wrote:

Example for "ksmps"

; Select audio/midi flags here according to platform -odac ;;;realtime audio out;-iadc ;;;uncomment -iadc if realtime audio input is needed too ; 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 = 24000, then kr = 1.500: you can hear a smooth glissando;ksmps = 32 nchnls = 20dbfs = 1instr 1 kamp = 0.4 kfreq expseg p4, p3, p5 a1 oscil3 kamp, kfreq, 1 outs a1, a1endin f 1 0 524288 10 1i 1 0 15 100 13000e

— Reply to this email directly, view it on GitHub https://us-west-2.protection.sophos.com?d=github.com&u=aHR0cHM6Ly9naXRodWIuY29tL2Nzb3VuZC9tYW51YWwvaXNzdWVzLzczOCNpc3N1ZWNvbW1lbnQtMjE0Mzk4NTU4Mg==&i=NWYxNzBkMDNiNTVmZGEwZmIyNjczYmRm&t=NDR3ZkVqRGNjYzlYazZmbkhXMFJoUnU0Z3VJRlZhV01ieWpZVkJveGtmVT0=&h=51156587e7a841059e642fb34b2d62f1&s=AVNPUEhUT0NFTkNSWVBUSVZ-CzEl059Ym1RlqwKl3ZhNfC-dR2N5IDL9CUAdMA_6tA, or unsubscribe https://us-west-2.protection.sophos.com?d=github.com&u=aHR0cHM6Ly9naXRodWIuY29tL25vdGlmaWNhdGlvbnMvdW5zdWJzY3JpYmUtYXV0aC9BQUxXWUZWNjZDUE1HM1BFTUozWDNBTFpGTlRESkFWQ05GU002QUFBQUFCSVNSNElFS1ZISTJEU01WUVdJWDNMTVY0M09TTFRPTjJXS1EzUE5WV1dLM1RVSE1aRENOQlRIRTRES05KWUdJ&i=NWYxNzBkMDNiNTVmZGEwZmIyNjczYmRm&t=d0ZkRzRBdVU3U2J5M3lSN0hoK1hIZk1xZVBrTUFPZnl5NHQ0MVA2aWhpWT0=&h=51156587e7a841059e642fb34b2d62f1&s=AVNPUEhUT0NFTkNSWVBUSVZ-CzEl059Ym1RlqwKl3ZhNfC-dR2N5IDL9CUAdMA_6tA . You are receiving this because you are subscribed to this thread.Message ID: @.***>

AsterixMusic commented 1 month ago

Simple example using FRAC and FLOOR


<CsoundSynthesizer>
<CsOptions>
; Select audio/midi flags here according to platform
-odac     ;;;RT audio out
;-iadc    ;;;uncomment -iadc if RT audio input is needed too
; For Non-realtime ouput leave only the line below:
; -o FracFloor.wav -W ;;; for file output any platform

; By Stefano Cucchi 2024

</CsOptions>

<CsInstruments>

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

instr 1

gkrandom randomh 1, 45, 300, 2,  3 ; generate some random numbers
gkrandomINT = floor (gkrandom) ; take the integer part
gkrandomFRAC = frac (gkrandom) ; take the fractional part

endin

instr 10

  ktrigger metro 4
  kmintim = 0
  kmaxnum = 10
  kinsnum = 20
  kwhen = 0
  kdur = ktrigger*0.25

  schedkwhen ktrigger, kmintim, kmaxnum, kinsnum, kwhen, kdur

endin

instr 20

  irandomINT = i(gkrandomINT) 
  irandomFRAC = i(gkrandomFRAC)

  ; Use the integer part to control the number of harmonics of every note
  ; after converting (k) value to (i)

  a1 buzz 0.5, 120, irandomINT, 1 

  kenvelope linseg 0, p3*0.1, 1, p3*0.8, 1, p3*0.1, 0

  a1 = a1*kenvelope

  aL, aR pan2 a1, irandomFRAC, 1 ; use the fractional part to control the pan position 
  outs aL, aR

endin

</CsInstruments>
<CsScore>

f 1 0 16384 10 1

i 1 0 10

i 10 0 10 

e
tjingboem commented 1 month ago

what a fun example! thanks!

I added some printing of floor and frac

csounder commented 1 month ago

nice frac floor

- Dr.B

Dr. Richard Boulanger

Professor

Electronic Production and Design

Berklee College of Music

Professional Writing & Technology Division

On Sat, Jun 8, 2024 at 3:39 PM Stefano Cucchi @.***> wrote:

Simple example using FRAC and FLOOR

; Select audio/midi flags here according to platform -odac ;;;RT audio out;-iadc ;;;uncomment -iadc if RT audio input is needed too; For Non-realtime ouput leave only the line below:; -o FracFloor.wav -W ;;; for file output any platform ; By Stefano Cucchi 2024 sr = 44100ksmps = 320dbfs = 1nchnls = 2instr 1gkrandom randomh 1, 45, 300, 2, 3 ; generate some random numbersgkrandomINT = floor (gkrandom) ; take the integer partgkrandomFRAC = frac (gkrandom) ; take the fractional partendininstr 10 ktrigger metro 4 kmintim = 0 kmaxnum = 10 kinsnum = 20 kwhen = 0 kdur = ktrigger*0.25 schedkwhen ktrigger, kmintim, kmaxnum, kinsnum, kwhen, kdur endininstr 20 irandomINT = i(gkrandomINT) irandomFRAC = i(gkrandomFRAC) ; Use the integer part to control the number of harmonics of every note ; after converting (k) value to (i) a1 buzz 0.5, 120, irandomINT, 1 kenvelope linseg 0, p3*0.1, 1, p3*0.8, 1, p3*0.1, 0 a1 = a1*kenvelope aL, aR pan2 a1, irandomFRAC, 1 ; use the fractional part to control the pan position outs aL, aR endin f 1 0 16384 10 1i 1 0 10i 10 0 10 e — Reply to this email directly, view it on GitHub , or unsubscribe . You are receiving this because you commented.Message ID: ***@***.***>