Csound Csound-dev Csound-tekno Search About

[Csnd] A random reading

Date2023-07-17 16:42
FromEnrico Francioni <00000005323c8739-dmarc-request@LISTSERV.HEANET.IE>
Subject[Csnd] A random reading
Hi everyone. 

I would like to create an algorithm (csd) for which from an audio file: 
1. can send running only short fragments of the file; 
2. the fragments of the audio file must have a variable duration each time (included between a minimum and a maximum value); 
3. the fragments will have to be alternated with pauses also from the variable duration; 
4. randomize the skiptime value, then at each call a different value (randomic).

Is there any experience on this yet? Is there any idea...?
Thanks for any help, 
Enrico

Csound mailing list
Csound@listserv.heanet.ie
https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
Send bugs reports to
        https://github.com/csound/csound/issues
Discussions of bugs and features can be posted here

Date2023-07-17 16:56
From"Jeanette C."
SubjectRe: [Csnd] A random reading
Hi Enrico,
I can think of at least two possibilities. One using diskin or diskin2
and two iinstruments. Have one controlling instrument with your
"algorithm" and one playing iinstrument. The basic structure could be
something like this:
kTrigFreq init 1
kTrig = metro(kTriigFreq)

if (kTrig == 1) then
   ; computer your random values
   ; infer the new metronome frequency with something like 1/(kEnd -
   ; kStart)
   ; schedulek your instrument with skiptime and all other params
endif

To get the alternating silences, you could have an additional variable
switched over each time you are insiide the if statement to either
schedule your play instrument or do nothing.

Would that do? In one instrument you might do someting with table
reading through a scaled phasor added to a or a-rate offset and use a
kind of gate to llet audio go out or silence it.

Best wishes and HTH,

Jeanette

Jul 17 2023, Enrico Francioni has written:

> Hi everyone.
>
> I would like to create an algorithm (csd) for which from an audio file:
> 1. can send running only short fragments of the file;
> 2. the fragments of the audio file must have a variable duration each time (included between a minimum and a maximum value);
> 3. the fragments will have to be alternated with pauses also from the variable duration;
> 4. randomize the skiptime value, then at each call a different value (randomic).
>
> Is there any experience on this yet? Is there any idea...?
> Thanks for any help,
> Enrico
>
> Csound mailing list
> Csound@listserv.heanet.ie
> https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
> Send bugs reports to
>        https://github.com/csound/csound/issues
> Discussions of bugs and features can be posted here
>

-- 
  * Website: http://juliencoder.de - for summer is a state of sound
  * Youtube: https://www.youtube.com/channel/UCMS4rfGrTwz8W7jhC1Jnv7g
  * Audiobombs: https://www.audiobombs.com/users/jeanette_c
  * GitHub: https://github.com/jeanette-c

Skip on the drinks Head to the floor
Makin' my way Past the show
My body's taken over And I want some more <3
(Britney Spears)

Csound mailing list
Csound@listserv.heanet.ie
https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
Send bugs reports to
        https://github.com/csound/csound/issues
Discussions of bugs and features can be posted here

Date2023-07-18 07:00
FromST Music
SubjectRe: [Csnd] A random reading
AttachmentsEx_1.csd  Ex_3.csd  Ex_2.csd  
Further to Jeanette's suggestion, the following: 

1. plays a random length segment of a soundfile followed by an equal length of silence
2. each segment is enveloped to avoid clicks & will play contiguously through the soundfile (each random segment starts where the previous one ended)
3. it will wrap when the sum of the segments exceeds the length of the soundfile

Certainly not as comprehensive as Oeyvind's impressive instr but perhaps a little easier to modify depending on your intended use (and was a fun challenge for me!).

<CsoundSynthesizer>
<CsOptions>
-o dac -m2
; -o test_ex1.wav
</CsOptions>
;================================
<CsInstruments>

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

        seed 0
giOff   init 0 ; value to offset soundfile

instr trig
  ; random durations will be divided in half in instr 1
  ; if KDur = 1 second, sfile plays for .5 seconds
  ; then there is silence for .5 seconds
  kDur    init 2
  kTrig   metro 1/kDur
  kMin  = .125 ; min. duration in seconds
  kMax  = 1 ; max. dur
  kDur  = trandom(kTrig, kMin, kMax) ; create random dur each time metro triggers
  schedkwhen kTrig, 0, 2, 1, 0, kDur
endin

instr 1
  print p3
  iDur  = p3 / 2 ; divide random durations in half
  print iDur
  print giOff
  iAmp  = .8
  aEnv  = linseg:a(0, .003, iAmp, iDur - .007, iAmp, .003, 0)
  aSig diskin "fox.wav", 1, giOff, 1
  outs aSig * aEnv, aSig * aEnv
  giOff += iDur
  print giOff
endin 

</CsInstruments>
;================================
<CsScore>
i"trig"  0  16
</CsScore>
</CsoundSynthesizer>

The above is attached as Ex_1.csd

I left the print statements in to help illustrate how it works.

Ex_2.csd is similar but uses some global variables to adjust for whether the sfile is mono or stereo. Instead of using an if statement that would be instantiated numerous times I thought it more efficient to just use seperate instr.

I wasn't sure whether you wanted every random segment to be contiguous. Ex_3.csd differs from 2 in that every random segment starts from a different place in the sfile.

It's quite possible you could recreate this as a single instr using triglinseg but as that opcode will not work on Android devices I was unable to test it.

Best,
Scott

On Mon, Jul 17, 2023, 11:42 a.m. Enrico Francioni <00000005323c8739-dmarc-request@listserv.heanet.ie> wrote:
Hi everyone.

I would like to create an algorithm (csd) for which from an audio file:
1. can send running only short fragments of the file;
2. the fragments of the audio file must have a variable duration each time (included between a minimum and a maximum value);
3. the fragments will have to be alternated with pauses also from the variable duration;
4. randomize the skiptime value, then at each call a different value (randomic).

Is there any experience on this yet? Is there any idea...?
Thanks for any help,
Enrico

Csound mailing list
Csound@listserv.heanet.ie
https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
Send bugs reports to
        https://github.com/csound/csound/issues
Discussions of bugs and features can be posted here
Csound mailing list Csound@listserv.heanet.ie https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to https://github.com/csound/csound/issues Discussions of bugs and features can be posted here

Date2023-07-19 00:50
FromBill Alves
SubjectRe: [Csnd] A random reading
Here is a csd I’ve had a lot of fun with. It loads a sample into a function table and plays back fragments (that I’ve called grains) by triggering a second instrument. The playback loops. Meanwhile I’ve set up the first instrument to take input from my Novation Launch Control MIDI knobs via ctrl7. With them I can control the grain density, duration, frequency, stereo, but crucially the amount of randomness. If I turn up the randomness, the grains start appearing out of order from the original timing. Of course these controller inputs could just as easily be widgets or envelopes or whatever, but there’s a tactile joy in playing with the knobs.

<CsoundSynthesizer>
<CsOptions>
</CsOptions>
<CsInstruments>
sr = 44100
kr = 2205
nchnls = 2
nchnls_i = 1
0dbfs = 1

gisamp ftgen 0,0,65536,1,”mysample.aif",0,0,0
;replace with your sound file name of course
;change table size or use deferred table size depending on your sound file
gislen filelen "mysample.aif"
gitlen tableng gisamp
gilplen = 2*sr

instr 1 ; repeats sample while MIDI controllers change playback
knextstart init 0
kcurtime timeinsts
kdur ctrl7 9,21,0,0.5 ; grain duration
koverlap ctrl7 9,22,1,8 ; grain overlap, hence density
kfreq ctrl7 9,23,0.2,5 ; change in sample frequency
krandamt ctrl7 9,42,0,0.1 ; amount of randomness in time passing thru sample
kpanctr ctrl7 9,24,0,0.5 ; change in stereo center
kpanspread ctrl7 9,44,0,0.5 ; change in grain stereo spread
if (kcurtime >= knextstart) then
khop = kdur/koverlap
khopoff gauss krandamt
ksoffamt = krandamt*10*gitlen
ksoff gauss ksoffamt
kpan gauss kpanspread
kpan = 0.5 + kpanctr + kpanspread
kspos = (abs(ksoff)+kcurtime*sr)%(gislen*sr)
schedkwhen 1,0,9,2,0,kdur,kspos,kfreq,kpan
knextstart = knextstart + khop + khopoff
endif
endin

instr 2 ; play single grain; p4 = start time in table, p5 = freq ratio, p6 = pan
kenv expseg 0.0001,p3/2,0.73,p3/2,0.0001
asig oscil kenv,p5/gislen,gisamp,p4/gitlen
out sqrt(1-p6)*asig,sqrt(p6)*asig
endin

</CsInstruments>
<CsScore>
i1 0.1 999

</CsScore>
</CsoundSynthesizer>




On Jul 17, 2023, at 8:42 AM, Enrico Francioni <00000005323c8739-dmarc-request@LISTSERV.HEANET.IE> wrote:

Hi everyone.

I would like to create an algorithm (csd) for which from an audio file:
1. can send running only short fragments of the file;
2. the fragments of the audio file must have a variable duration each time (included between a minimum and a maximum value);
3. the fragments will have to be alternated with pauses also from the variable duration;
4. randomize the skiptime value, then at each call a different value (randomic).

Is there any experience on this yet? Is there any idea...?
Thanks for any help,
Enrico

Csound mailing list
Csound@listserv.heanet.ie
https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
Send bugs reports to
       https://github.com/csound/csound/issues
Discussions of bugs and features can be posted here

Bill Alves
Professor of Music, The Claremont Colleges
Harvey Mudd College
301 Platt Blvd. Claremont CA 91711
http://pages.hmc.edu/alves/
http://www.billalves.com/




Date2023-07-24 18:32
From"Dr. Richard Boulanger"
SubjectRe: [Csnd] A random reading
Hello Bill,

Thanks for sharing this - it's cool and fun.

- Dr.B


Dr. Richard Boulanger

Professor

Electronic Production and Design

Berklee College of Music

Professional Writing & Technology Division



On Tue, Jul 18, 2023 at 7:51 PM Bill Alves <alves@g.hmc.edu> wrote:
Here is a csd I’ve had a lot of fun with. It loads a sample into a function table and plays back fragments (that I’ve called grains) by triggering a second instrument. The playback loops. Meanwhile I’ve set up the first instrument to take input from my Novation Launch Control MIDI knobs via ctrl7. With them I can control the grain density, duration, frequency, stereo, but crucially the amount of randomness. If I turn up the randomness, the grains start appearing out of order from the original timing. Of course these controller inputs could just as easily be widgets or envelopes or whatever, but there’s a tactile joy in playing with the knobs.

<CsoundSynthesizer>
<CsOptions>
</CsOptions>
<CsInstruments>
sr = 44100
kr = 2205
nchnls = 2
nchnls_i = 1
0dbfs = 1

gisamp ftgen 0,0,65536,1,”mysample.aif",0,0,0
;replace with your sound file name of course
;change table size or use deferred table size depending on your sound file
gislen filelen "mysample.aif"
gitlen tableng gisamp
gilplen = 2*sr

instr 1 ; repeats sample while MIDI controllers change playback
knextstart init 0
kcurtime timeinsts
kdur ctrl7 9,21,0,0.5 ; grain duration
koverlap ctrl7 9,22,1,8 ; grain overlap, hence density
kfreq ctrl7 9,23,0.2,5 ; change in sample frequency
krandamt ctrl7 9,42,0,0.1 ; amount of randomness in time passing thru sample
kpanctr ctrl7 9,24,0,0.5 ; change in stereo center
kpanspread ctrl7 9,44,0,0.5 ; change in grain stereo spread
if (kcurtime >= knextstart) then
khop = kdur/koverlap
khopoff gauss krandamt
ksoffamt = krandamt*10*gitlen
ksoff gauss ksoffamt
kpan gauss kpanspread
kpan = 0.5 + kpanctr + kpanspread
kspos = (abs(ksoff)+kcurtime*sr)%(gislen*sr)
schedkwhen 1,0,9,2,0,kdur,kspos,kfreq,kpan
knextstart = knextstart + khop + khopoff
endif
endin

instr 2 ; play single grain; p4 = start time in table, p5 = freq ratio, p6 = pan
kenv expseg 0.0001,p3/2,0.73,p3/2,0.0001
asig oscil kenv,p5/gislen,gisamp,p4/gitlen
out sqrt(1-p6)*asig,sqrt(p6)*asig
endin

</CsInstruments>
<CsScore>
i1 0.1 999

</CsScore>
</CsoundSynthesizer>




On Jul 17, 2023, at 8:42 AM, Enrico Francioni < 00000005323c8739-dmarc-request@LISTSERV.HEANET.IE> wrote:

Hi everyone.

I would like to create an algorithm (csd) for which from an audio file:
1. can send running only short fragments of the file;
2. the fragments of the audio file must have a variable duration each time (included between a minimum and a maximum value);
3. the fragments will have to be alternated with pauses also from the variable duration;
4. randomize the skiptime value, then at each call a different value (randomic).

Is there any experience on this yet? Is there any idea...?
Thanks for any help,
Enrico

Csound mailing list
Csound@listserv.heanet.ie
https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
Send bugs reports to
       https://github.com/csound/csound/issues
Discussions of bugs and features can be posted here

Bill Alves
Professor of Music, The Claremont Colleges
Harvey Mudd College
301 Platt Blvd. Claremont CA 91711
http://pages.hmc.edu/alves/
http://www.billalves.com/



Csound mailing list Csound@listserv.heanet.ie https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to https://github.com/csound/csound/issues Discussions of bugs and features can be posted here
Csound mailing list Csound@listserv.heanet.ie https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to https://github.com/csound/csound/issues Discussions of bugs and features can be posted here

Date2023-07-24 18:35
From"Dr. Richard Boulanger"
SubjectRe: [Csnd] A random reading
Thanks for sharing Scott.  These are cool and lay the foundation for some nice explorations.

- Dr.B


Dr. Richard Boulanger

Professor

Electronic Production and Design

Berklee College of Music

Professional Writing & Technology Division



On Tue, Jul 18, 2023 at 2:01 AM ST Music <stunes6556@gmail.com> wrote:
Further to Jeanette's suggestion, the following: 

1. plays a random length segment of a soundfile followed by an equal length of silence
2. each segment is enveloped to avoid clicks & will play contiguously through the soundfile (each random segment starts where the previous one ended)
3. it will wrap when the sum of the segments exceeds the length of the soundfile

Certainly not as comprehensive as Oeyvind's impressive instr but perhaps a little easier to modify depending on your intended use (and was a fun challenge for me!).

<CsoundSynthesizer>
<CsOptions>
-o dac -m2
; -o test_ex1.wav
</CsOptions>
;================================
<CsInstruments>

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

        seed 0
giOff   init 0 ; value to offset soundfile

instr trig
  ; random durations will be divided in half in instr 1
  ; if KDur = 1 second, sfile plays for .5 seconds
  ; then there is silence for .5 seconds
  kDur    init 2
  kTrig   metro 1/kDur
  kMin  = .125 ; min. duration in seconds
  kMax  = 1 ; max. dur
  kDur  = trandom(kTrig, kMin, kMax) ; create random dur each time metro triggers
  schedkwhen kTrig, 0, 2, 1, 0, kDur
endin

instr 1
  print p3
  iDur  = p3 / 2 ; divide random durations in half
  print iDur
  print giOff
  iAmp  = .8
  aEnv  = linseg:a(0, .003, iAmp, iDur - .007, iAmp, .003, 0)
  aSig diskin "fox.wav", 1, giOff, 1
  outs aSig * aEnv, aSig * aEnv
  giOff += iDur
  print giOff
endin 

</CsInstruments>
;================================
<CsScore>
i"trig"  0  16
</CsScore>
</CsoundSynthesizer>

The above is attached as Ex_1.csd

I left the print statements in to help illustrate how it works.

Ex_2.csd is similar but uses some global variables to adjust for whether the sfile is mono or stereo. Instead of using an if statement that would be instantiated numerous times I thought it more efficient to just use seperate instr.

I wasn't sure whether you wanted every random segment to be contiguous. Ex_3.csd differs from 2 in that every random segment starts from a different place in the sfile.

It's quite possible you could recreate this as a single instr using triglinseg but as that opcode will not work on Android devices I was unable to test it.

Best,
Scott

On Mon, Jul 17, 2023, 11:42 a.m. Enrico Francioni <00000005323c8739-dmarc-request@listserv.heanet.ie> wrote:
Hi everyone.

I would like to create an algorithm (csd) for which from an audio file:
1. can send running only short fragments of the file;
2. the fragments of the audio file must have a variable duration each time (included between a minimum and a maximum value);
3. the fragments will have to be alternated with pauses also from the variable duration;
4. randomize the skiptime value, then at each call a different value (randomic).

Is there any experience on this yet? Is there any idea...?
Thanks for any help,
Enrico

Csound mailing list
Csound@listserv.heanet.ie
https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
Send bugs reports to
        https://github.com/csound/csound/issues
Discussions of bugs and features can be posted here
Csound mailing list Csound@listserv.heanet.ie https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to https://github.com/csound/csound/issues Discussions of bugs and features can be posted here
Csound mailing list Csound@listserv.heanet.ie https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to https://github.com/csound/csound/issues Discussions of bugs and features can be posted here