[Csnd] Ipitch and Syncgrain
Date | 2017-09-17 13:21 |
From | Tarek Wayne |
Subject | [Csnd] Ipitch and Syncgrain |
Hi all! I would like to replace kpitch with ipitch in Syncgrain and I am sure I am way off track as since I want to keep everything else k-rate there are some mathematical conflicts..(??)<CsoundSynthesizer> <CsOptions> --env:SSDIR+=../SourceMaterials </CsOptions> <CsInstruments> sr = 44100 ;SAMPLE RATE ksmps = 100 ;NUMBER OF AUDIO SAMPLES IN EACH CONTROL CYCLE nchnls = 2 ;NUMBER OF CHANNELS (2=STEREO) 0dbfs = 1 ;MAXIMUM AMPLITUDE REGARDLESS OF BIT DEPTH ; WINDOWING FUNCTIONS USED TO DYNAMICALLY SHAPE THE GRAINS ; NUM | INIT_TIME | SIZE | GEN_ROUTINE | PARTIAL_NUM | STRENGTH | PHASE ;GRAIN ENVELOPE WINDOW FUNCTION TABLES: giwfn1 ftgen 0, 0, 131072, 9, .5, 1, 0 ; HALF SINE giwfn2 ftgen 0, 0, 131072, 7, 0, 3072, 1, 128000, 0 ; PERCUSSIVE - STRAIGHT SEGMENTS giwfn3 ftgen 0, 0, 131072, 5, .001, 3072, 1, 128000, .001 ; PERCUSSIVE - EXPONENTIAL SEGMENTS giwfn4 ftgen 0, 0, 131072, 7, 0, 1536, 1, 128000, 1, 1536, 0 ; GATE - WITH DE-CLICKING RAMP UP AND RAMP DOWN SEGMENTS giwfn5 ftgen 0, 0, 131072, 7, 0, 128000, 1, 3072, 0 ; REVERSE PERCUSSIVE - STRAIGHT SEGMENTS giwfn6 ftgen 0, 0, 131072, 5, .001, 128000, 1, 3072, .001 ; REVERSE PERCUSSIVE - EXPONENTIAL SEGMENTS ;TABLE FOR EXP SLIDER giExp1 ftgen 0, 0, 129, -25, 0, 0.001, 128, 1.0 giExp2000 ftgen 0, 0, 129, -25, 0, 1.0, 128, 2000.0 instr 10 ;GUI ktrig metro 10 if (ktrig == 1) then gkMIDItoDensity invalue "MtoDensity" gkMIDItoPitch invalue "MtoPitch" gkwfn invalue "Grain_Envelope" kfreeze invalue "Freeze" gkamp invalue "Amplitude" kfreq invalue "Density" gkfreq tablei kfreq, giExp2000, 1 outvalue "Density_Value", gkfreq gkpitch invalue "Pitch" gkprate invalue "Progress_Rate"
if kfreeze=1 then outvalue "Progress_Rate",0 endif
kgrsize invalue "Grain_Size" gkgrsize tablei kgrsize, giExp1, 1 outvalue "Grain_Size_Value", gkgrsize gkfreqOS invalue "Grain_Density_Offset" gksizeOS invalue "Grain_Size_Rnd_Offset" gkAtt invalue "Attack_Time" gkRel invalue "Release_Time" ;AUDIO FILE CHANGE / LOAD IN TABLES ******************************************************************************************************** ;Have put all this stuff in instr 10 to reduce the respons time when playing with midi Sfile_new strcpy "" ;INIT TO EMPTY STRING Sfile invalue "_Browse" Sfile_old strcpyk Sfile_new Sfile_new strcpyk Sfile kfile strcmpk Sfile_new, Sfile_old gkfile_new init 0 if kfile != 0 then ;IF A BANG HAD BEEN GENERATED IN THE LINE ABOVE gkfile_new = 1 ;Flag to inform instr 1 that a new file is loaded reinit NEW_FILE ;REINITIALIZE FROM LABEL 'NEW_FILE' endif NEW_FILE: ;FUNCTION TABLES NUMBERS OF THE SOUND FILE THAT WILL BE GRANULATED ichn filenchnls Sfile if ichn == 1 then giFileL ftgentmp 0, 0, 0, 1, Sfile, 0, 0, 1 ;READ MONO AUDIO FILE CHANNEL 1 giFileR = giFileL else giFileL ftgentmp 0, 0, 0, 1, Sfile, 0, 0, 1 ;READ STEREO AUDIO FILE CHANNEL 1 giFileR ftgentmp 0, 0, 0, 1, Sfile, 0, 0, 2 ;READ STEREO AUDIO FILE CHANNEL 2 endif ;******************************************************************************************************************************************* endif endin instr 1 ; triggers instrument 2 ktrigger metro 0.08 ;metronome of triggers. One every 12.5s schedkwhen ktrigger,0,0,3,0,60 ;trigger instr. 2 for 40s endin instr 3 ;SYNCGRAIN INSTRUMENT if p4!=0 then ;MIDI ioct = p4 koct = p5 ;READ OCT VALUE FROM MIDI INPUT icps = cpsoct(ioct) kcps = cpsoct(koct) ;CONVERT TO CPS ;PITCH BEND============================================================================================================ iSemitoneBendRange = 12 ;PITCH BEND RANGE IN SEMITONES imin = 0 ;EQUILIBRIUM POSITION imax = iSemitoneBendRange * .0833333 ;MAX PITCH DISPLACEMENT (IN oct FORMAT) ibend pchbend imin, imax ;PITCH BEND VARIABLE (IN oct FORMAT) icps = cpsoct(ioct + ibend) ;SET FUNDAMENTAL ;======================================================================================================================= endif iporttime = 0.1 ;PORTAMENTO TIME kporttime linseg 0,0.01,iporttime,1,iporttime ;USE OF A RAMPING UP ENVELOPE PREVENTS GLIDING PARAMETERS EACH TIME A NOTE IS RESTARTED if p4!=0 && gkMIDItoPitch=1 then ;IF THIS IS A MIDI ACTIVATED NOTE AND MIDI-TO-PITCH SWITCH IS ON... ipitch = icps/cpsoct(8) ;MAP TO MIDI NOTE VALUE TO PITCH (CONVERT TO RATIO: MIDDLE C IS POINT OF UNISON) else ;OTHERWISE... kpitch portk gkpitch, iporttime ;USE THE SLIDER VALUE endif ;END OF THIS CONDITIONAL BRANCH if p4!=0 && gkMIDItoDensity=1 then ;IF THIS IS A MIDI ACTIVATED NOTE AND MIDI-TO-PITCH SWITCH IS ON... kfreq = kcps else ;OTHERWISE... kfreq portk gkfreq, kporttime ;USE THE GUI SLIDER VALUE endif ;END OF THIS CONDITIONAL BRANCH if gkfile_new = 1 then ;test if a new file is loaded by instr 10 gkfile_new = 0 ;flag to zero for next file change reinit START ;REINITIALIZE FROM LABEL 'NEW_FILE1' endif kSwitch changed gkwfn if kSwitch=1 then reinit START endif kgrsize portk gkgrsize, kporttime kprate portk gkprate, kporttime iolaps = 2000 ;NUMBER OF ALLOWED OVERLAPS - BEST JUST TO GIVE THIS A LARGE CONSTANT VALUE kfreqOS rand gkfreqOS ;kfreqOS IS A K-RATE RANDOM NUMBER WITHIN THE RANGE -gkfreqOS TO gkfreqOS kfreqOS = kfreqOS * kfreq ;kfreqOS IS REDEFINED RELATIVE TO THE CURRENT VALUE OF kfreq
kgrsizeOS gauss gksizeOS ;kgrsizeOS IS A K-RATE GAUSSIAN RANDOM NUMBER WITHIN THE RANGE -gksizeOS TO gksizeOS kgrsizeOS = kgrsizeOS * kgrsize ;kgrsizeOS IS REDEFINED RELATIVE TO THE CURRENT VALUE OF kgrsize START: iwfn = giwfn1 + i(gkwfn) ;FUNCTION TABLE NUMBER FOR WINDOWING FUNCTION IS DERIVED asigL syncgrain gkamp, kfreq+kfreqOS, ipitch, kgrsize+kgrsizeOS, kprate, giFileL, iwfn, iolaps ; LEFT CHANNEL asigR syncgrain gkamp, kfreq+kfreqOS, ipitch, kgrsize+kgrsizeOS, kprate, giFileR, iwfn, iolaps ; RIGHT CHANNEL rireturn aenv expsegr 0.0001,i(gkAtt),1,i(gkRel),0.0001 ;CLOUD AMPLITUDE ENVELOPE asigL = asigL * aenv ;APPLY AMPLITUDE ENVELOPE asigR = asigR * aenv ;APPLY AMPLITUDE ENVELOPE outs asigL, asigR endin instr 2 ;INIT outvalue "_SetPresetIndex", 0 endin </CsInstruments> <CsScore> ;INSTR | START | DURATION i 10 0 3600 ;GUI i 1 0 3600 i 2 0.1 0 ;INIT </CsScore> </CsoundSynthesizer> |
Date | 2017-09-17 14:55 |
From | John ff |
Subject | Re: [Csnd] Ipitch and Syncgrain |
Why not just change pitch to kpitch throughout?
Sent from Blue
On 17 Sep 2017, at 13:23, Tarek Wayne <wstlopez@GMAIL.COM> wrote:
|
Date | 2017-09-17 15:25 |
From | Tarek Wayne |
Subject | Re: [Csnd] Ipitch and Syncgrain |
Maybe I wasn't clear... The original code uses kpitch(so I wouldn't have had to tamper with it).. I have added schedwhen and substituted kpitch for ipitch because I want the pitch change to overlap with the previous selected pitch, as opposed to directly transposing to the selected pitch On 17 Sep 2017 15:56, "John ff" <jpff@codemist.co.uk> wrote:
|
Date | 2017-09-17 15:49 |
From | Steven Yi |
Subject | Re: [Csnd] Ipitch and Syncgrain |
I'm a bit confused in reading this code regarding the use of reinit. Not knowing what the original code is, nor having any widgets defined in the posted example (so not knowing the range of values being used for invalues), is the goal for this CSD to add using MIDI? Could you post a complete example and original? I think seeing the two might help to understand what the goal is lead to better advice. On Sun, Sep 17, 2017 at 10:25 AM, Tarek Wayne |
Date | 2017-09-17 20:15 |
From | Tarek Wayne |
Subject | Re: [Csnd] Ipitch and Syncgrain |
Ok, so the reinit is part of the original syncgrain code(included in the McGurdy Collection that comes with Csound).. just has to do with loading the soundfile via the browser i think..kamp 0 to 1 kfreq 0 to1 ipitch/kpitch -2 to 2 kprate -.25 to .25(modified from -1 to 1) kgrsize 0 to 1 kfreqOS 0 to 1 kgrsizeOS 0 to 1 kAtt .05 to 10 kRel .05 to 10 The goal? Simply to maintain the functionality of the original code included with Csound, using Ipitch and schedwhen instead of kpitch to achieve the overlapping effect(two events playing at once briefly at different pitches to transition from one pitch to another as opposed to directly going to the next chosen pitch) I mentioned in the original post. As you see the widget used is QuteCSound... Could you clarify what you mean by complete example? ;Written by Iain McCurdy, 2006 ;Modified for QuteCsound by René, October 2010, updated Feb 2011 ;Tested on Ubuntu 10.04 with csound-float 5.13.0 and QuteCsound svn rev 817 ;An INIT preset is called at the start of csound (inst 2), a valid (mono or stereo) audio file have to be selected and preset 0 saved before playing. ;Notes on modifications from original csd: ; Add table(s) for exp slider ; Add Browser for audio files, accept mono or stereo wav files ; Instrument 1 is activated by MIDI and by the GUI ; Removed Recording instrument, included in QuteCsound ; Removed "Instructions and Info Panel" for the gui to fit in a 1200x800 screen ; syncgrain ; ---------------------------------------------------------------------------------------------------------------------------- ; Syncgrain offers granular synthesis upon a stored sound file stored in a gen 1 function table. ; Syncgrain's strength lies in its use of k-rate control for its main input arguments which encourages real time manipulation. ; Another distinctive feature of syncgrain is the interaction between the density (kfreq), grain size (kgrsize) and progress ; rate (kprate). Density or grain frequency (kfreq) defines the number of grains per second. Higher values for grain density ; have the effect of increasing the progress rate through the sound file (kprate). Increasing the grain size also increases the ; rate of progress through the sound file. ; The progress rate (kprate) defines the location from where a grain will begin playback as a fraction of the previous grain's ; entire trajectory. If progress rate is given a value of 1 then a grain will begin exactly where the previous grain finished. ; If progress rate is given a value of 0.5 then it will begin at the halfway point of the previous grain's trajectory. ; Negative values for progress rate cause the progress pointer to move backwards through the file (but playback of each grain ; is still forwards). ; The user is required to provide an amplitude envelope which is stored in a function table. In this example the user is provided ; with six grain envelopes from which to choose. ; Details are provided on the interface. Some additional functions have been added that are not part of the original opcode: ; 'Grain Density' (frequency) and 'Grain Size' can be randomized. The 'Freeze' button sets the 'Progress Rate' slider to zero ; thereby effectively freezing progress through the sound file. ; This instrument can also be activated via MIDI. MIDI pitch values can be mapped to grain density and/or to the pitch of the ; material contained within the grain. In the latter mapping option, middle C is the point at which no transposition occurs. ; Using MIDI activation, polyphony is possible. ; The attack and release times of an amplitude envelope applied to the entire grain cloud can be modulated by the user using two ; on screen sliders. These controls are probably most useful when triggering this example via MIDI. ;my flags on Ubuntu: -odac -b1024 -B2048 -+rtaudio=alsa -+rtmidi=alsa -Ma -m0 --midi-key-oct=4 --midi-velocity-amp=5 <CsoundSynthesizer> <CsOptions> --env:SSDIR+=../SourceMaterials </CsOptions> <CsInstruments> sr = 44100 ;SAMPLE RATE ksmps = 100 ;NUMBER OF AUDIO SAMPLES IN EACH CONTROL CYCLE nchnls = 2 ;NUMBER OF CHANNELS (2=STEREO) 0dbfs = 1 ;MAXIMUM AMPLITUDE REGARDLESS OF BIT DEPTH ; WINDOWING FUNCTIONS USED TO DYNAMICALLY SHAPE THE GRAINS ; NUM | INIT_TIME | SIZE | GEN_ROUTINE | PARTIAL_NUM | STRENGTH | PHASE ;GRAIN ENVELOPE WINDOW FUNCTION TABLES: giwfn1 ftgen 0, 0, 131072, 9, .5, 1, 0 ; HALF SINE giwfn2 ftgen 0, 0, 131072, 7, 0, 3072, 1, 128000, 0 ; PERCUSSIVE - STRAIGHT SEGMENTS giwfn3 ftgen 0, 0, 131072, 5, .001, 3072, 1, 128000, .001 ; PERCUSSIVE - EXPONENTIAL SEGMENTS giwfn4 ftgen 0, 0, 131072, 7, 0, 1536, 1, 128000, 1, 1536, 0 ; GATE - WITH DE-CLICKING RAMP UP AND RAMP DOWN SEGMENTS giwfn5 ftgen 0, 0, 131072, 7, 0, 128000, 1, 3072, 0 ; REVERSE PERCUSSIVE - STRAIGHT SEGMENTS giwfn6 ftgen 0, 0, 131072, 5, .001, 128000, 1, 3072, .001 ; REVERSE PERCUSSIVE - EXPONENTIAL SEGMENTS ;TABLE FOR EXP SLIDER giExp1 ftgen 0, 0, 129, -25, 0, 0.001, 128, 1.0 giExp2000 ftgen 0, 0, 129, -25, 0, 1.0, 128, 2000.0 instr 10 ;GUI ktrig metro 10 if (ktrig == 1) then gkMIDItoDensity invalue "MtoDensity" gkMIDItoPitch invalue "MtoPitch" gkwfn invalue "Grain_Envelope" kfreeze invalue "Freeze" gkamp invalue "Amplitude" kfreq invalue "Density" gkfreq tablei kfreq, giExp2000, 1 outvalue "Density_Value", gkfreq gkpitch invalue "Pitch" gkprate invalue "Progress_Rate"
if kfreeze=1 then outvalue "Progress_Rate",0 endif
kgrsize invalue "Grain_Size" gkgrsize tablei kgrsize, giExp1, 1 outvalue "Grain_Size_Value", gkgrsize gkfreqOS invalue "Grain_Density_Offset" gksizeOS invalue "Grain_Size_Rnd_Offset" gkAtt invalue "Attack_Time" gkRel invalue "Release_Time" ;AUDIO FILE CHANGE / LOAD IN TABLES ******************************************************************************************************** ;Have put all this stuff in instr 10 to reduce the respons time when playing with midi Sfile_new strcpy "" ;INIT TO EMPTY STRING Sfile invalue "_Browse" Sfile_old strcpyk Sfile_new Sfile_new strcpyk Sfile kfile strcmpk Sfile_new, Sfile_old gkfile_new init 0 if kfile != 0 then ;IF A BANG HAD BEEN GENERATED IN THE LINE ABOVE gkfile_new = 1 ;Flag to inform instr 1 that a new file is loaded reinit NEW_FILE ;REINITIALIZE FROM LABEL 'NEW_FILE' endif NEW_FILE: ;FUNCTION TABLES NUMBERS OF THE SOUND FILE THAT WILL BE GRANULATED ichn filenchnls Sfile if ichn == 1 then giFileL ftgentmp 0, 0, 0, 1, Sfile, 0, 0, 1 ;READ MONO AUDIO FILE CHANNEL 1 giFileR = giFileL else giFileL ftgentmp 0, 0, 0, 1, Sfile, 0, 0, 1 ;READ STEREO AUDIO FILE CHANNEL 1 giFileR ftgentmp 0, 0, 0, 1, Sfile, 0, 0, 2 ;READ STEREO AUDIO FILE CHANNEL 2 endif ;******************************************************************************************************************************************* endif endin instr 1 ;SYNCGRAIN INSTRUMENT if p4!=0 then ;MIDI koct = p4 ;READ OCT VALUE FROM MIDI INPUT kcps = cpsoct(koct) ;CONVERT TO CPS ;PITCH BEND============================================================================================================ iSemitoneBendRange = 12 ;PITCH BEND RANGE IN SEMITONES imin = 0 ;EQUILIBRIUM POSITION imax = iSemitoneBendRange * .0833333 ;MAX PITCH DISPLACEMENT (IN oct FORMAT) kbend pchbend imin, imax ;PITCH BEND VARIABLE (IN oct FORMAT) kcps = cpsoct(koct + kbend) ;SET FUNDAMENTAL ;======================================================================================================================= endif iporttime = 0.1 ;PORTAMENTO TIME kporttime linseg 0,0.01,iporttime,1,iporttime ;USE OF A RAMPING UP ENVELOPE PREVENTS GLIDING PARAMETERS EACH TIME A NOTE IS RESTARTED if p4!=0 && gkMIDItoPitch=1 then ;IF THIS IS A MIDI ACTIVATED NOTE AND MIDI-TO-PITCH SWITCH IS ON... kpitch = kcps/cpsoct(8) ;MAP TO MIDI NOTE VALUE TO PITCH (CONVERT TO RATIO: MIDDLE C IS POINT OF UNISON) else ;OTHERWISE... kpitch portk gkpitch, kporttime ;USE THE SLIDER VALUE endif ;END OF THIS CONDITIONAL BRANCH if p4!=0 && gkMIDItoDensity=1 then ;IF THIS IS A MIDI ACTIVATED NOTE AND MIDI-TO-PITCH SWITCH IS ON... kfreq = kcps else ;OTHERWISE... kfreq portk gkfreq, kporttime ;USE THE GUI SLIDER VALUE endif ;END OF THIS CONDITIONAL BRANCH if gkfile_new = 1 then ;test if a new file is loaded by instr 10 gkfile_new = 0 ;flag to zero for next file change reinit START ;REINITIALIZE FROM LABEL 'NEW_FILE1' endif kSwitch changed gkwfn if kSwitch=1 then reinit START endif kgrsize portk gkgrsize, kporttime kprate portk gkprate, kporttime iolaps = 2000 ;NUMBER OF ALLOWED OVERLAPS - BEST JUST TO GIVE THIS A LARGE CONSTANT VALUE kfreqOS rand gkfreqOS ;kfreqOS IS A K-RATE RANDOM NUMBER WITHIN THE RANGE -gkfreqOS TO gkfreqOS kfreqOS = kfreqOS * kfreq ;kfreqOS IS REDEFINED RELATIVE TO THE CURRENT VALUE OF kfreq
kgrsizeOS gauss gksizeOS ;kgrsizeOS IS A K-RATE GAUSSIAN RANDOM NUMBER WITHIN THE RANGE -gksizeOS TO gksizeOS kgrsizeOS = kgrsizeOS * kgrsize ;kgrsizeOS IS REDEFINED RELATIVE TO THE CURRENT VALUE OF kgrsize START: iwfn = giwfn1 + i(gkwfn) ;FUNCTION TABLE NUMBER FOR WINDOWING FUNCTION IS DERIVED asigL syncgrain gkamp, kfreq+kfreqOS, kpitch, kgrsize+kgrsizeOS, kprate, giFileL, iwfn, iolaps ; LEFT CHANNEL asigR syncgrain gkamp, kfreq+kfreqOS, kpitch, kgrsize+kgrsizeOS, kprate, giFileR, iwfn, iolaps ; RIGHT CHANNEL rireturn aenv expsegr 0.0001,i(gkAtt),1,i(gkRel),0.0001 ;CLOUD AMPLITUDE ENVELOPE asigL = asigL * aenv ;APPLY AMPLITUDE ENVELOPE asigR = asigR * aenv ;APPLY AMPLITUDE ENVELOPE outs asigL, asigR endin instr 2 ;INIT outvalue "_SetPresetIndex", 0 endin </CsInstruments> <CsScore> ;INSTR | START | DURATION i 10 0 3600 ;GUI i 2 0.1 0 ;INIT </CsScore> </CsoundSynthesizer> On 17 September 2017 at 16:49, Steven Yi <stevenyi@gmail.com> wrote: I'm a bit confused in reading this code regarding the use of reinit. |
Date | 2017-09-17 20:17 |
From | Tarek Wayne |
Subject | Re: [Csnd] Ipitch and Syncgrain |
kamp 0 to 1 kfreq 0 to1 ipitch/kpitch -2 to 2 kprate -.25 to .25(modified from -1 to 1) kgrsize 0 to 1 kfreqOS 0 to 1 kgrsizeOS 0 to 1 kAtt .05 to 10 kRel .05 to 10 I did not specify that the above refers to the values you mentioned. On 17 September 2017 at 21:15, Tarek Wayne <wstlopez@gmail.com> wrote:
|
Date | 2017-09-17 21:11 |
From | Steven Yi |
Subject | Re: [Csnd] Ipitch and Syncgrain |
I'm not seeing the original in CsoundQT. Anyways, CsoundQT stores additional values in the CSD, particularly the widgets for the project. Within CsoundQT, it doesn't show the widgets, but you can see what they look like in the file itself, such as in here: https://github.com/CsoundQt/CsoundQt/blob/develop/examples/Synths/String_Phaser.csd Trying to run your file without the widgets isn't going to work out. Maybe could you just send your project as an attachment? On Sun, Sep 17, 2017 at 3:15 PM, Tarek Wayne |
Date | 2017-09-19 11:58 |
From | Tarek Wayne |
Subject | Re: [Csnd] Ipitch and Syncgrain |
Thanks for taking the time to investigate. I tried copying and pasting the code I sent to see if it worked on my setup and I had a similar problem. The widget itself isn't so much a problem as one can just create sliders with the appropriate values, the problem that the gui is necessary for loading the .wav I have an alternate version I modified for use in pure data, where the .wav is loaded from the code like normal.. I'll modify the other one too and send the .csd(s) when time permits...thanks again:-) On 17 Sep 2017 22:12, "Steven Yi" <stevenyi@gmail.com> wrote: I'm not seeing the original in CsoundQT. Anyways, CsoundQT stores |