-odac -d -m128
sr = 44100
ksmps = 32
nchnls = 2
0dbfs = 1
/*********************************************************************************/
/********************************* Initialization ******************************/
/***************************** Preperformance Settings ***************************/
/*********************************************************************************/
iSizeBuffer1 = 700 ;The Size of Buffer 1 for Instrument 1.
iSizeBuffer2 = 700 ;The Size of Buffer 2 for Instrument 2.
iSizeBuffer3 = 700 ;The Size of Buffer 3 for Instrument 3.
iSizeBuffer4 = 700 ;The Size of Buffer 4 for Instrument 4.
iSizeBuffer5 = 700 ;The Size of Buffer 5 for Instrument 5.
giDelayTime_Instr4 = 100 ;The delay time for Instrument 4.
/*********************************************************************************/
/********************************** Volume Controller **************************/
/*********************************************************************************/
opcode ShowLED_a, 0, Sakkk
Soutchan, asig, ktrig, kdb, kdbrange xin
kdispval max_k asig, ktrig, 1
if kdb != 0 then
kdb = dbfsamp(kdispval)
kval = (kdbrange + kdb) / kdbrange
else
kval = kdispval
endif
if ktrig == 1 then
outvalue Soutchan, kval
endif
endop
opcode ShowOver_a, 0, Sakk
Soutchan, asig, ktrig, khold xin
kon init 0
ktim times
kstart init 0
kend init 0
khold = (khold < .01 ? .01 : khold); avoiding too short hold times
kmax max_k asig, ktrig, 1
if kon == 0 && kmax > 1 && ktrig == 1 then
kstart = ktim
kend = kstart + khold
outvalue Soutchan, kmax
kon = 1
endif
if kon == 1 && ktim > kend && ktrig == 1 then
outvalue Soutchan, 0
kon = 0
endif
endop
/*********************************************************************************/
/*********************************************************************************/
/*********************************************************************************/
/****************************** FTs, Timer and Mic Input ***********************/
/*********************************************************************************/
giBuffer1 ftgen 0, 0, iSizeBuffer1*sr, 2, 0 ;Buffer for Instrument 1 (Record and Playback)
giBuffer1LenSec = ftlen(giBuffer1)/sr
giBuffer2 ftgen 0, 0, iSizeBuffer2*sr, 2, 0 ;Buffer for Instrument 2 (Record and Playback)
giBuffer2LenSec = ftlen(giBuffer2)/sr
giBuffer3 ftgen 0, 0, iSizeBuffer3*sr, 2, 0 ;Buffer for Instrument 3 (Record and Playback)
giBuffer3LenSec = ftlen(giBuffer3)/sr
giBuffer4 ftgen 0, 0, iSizeBuffer4*sr, 2, 0 ;Buffer for Instrument 4 (Record and Playback)
giBuffer4LenSec = ftlen(giBuffer4)/sr
giBuffer5 ftgen 0, 0, iSizeBuffer5*sr, 2, 0 ;Buffer for Instrument 5 (Record and Playback)
giBuffer5LenSec = ftlen(giBuffer5)/sr
seed 0
instr Timer ;Main Timer!
kSecs timeinsts
outvalue "timer", kSecs
outvalue "min", int(kSecs/60)
outvalue "sec", int(kSecs%60)
endin
schedule "Timer", 0, 9999
instr Mic ;Global Mic input. Always be seen and have a vol controller.
;aMic inch 1
;aMic diskin "Reich.wav", 1, 0
aMic diskin "Chord.wav", 1, 0
kAmp_Mic invalue "amp_mic"
kAmp_Mic port kAmp_Mic,0.1
gaMic = aMic*ampdb(kAmp_Mic)
gkTrigDisp metro 10
gkshowdb = 1
gkdbrange = 60
ShowLED_a "SchPre_Amp_Mic", gaMic, gkTrigDisp, gkshowdb, gkdbrange
ShowOver_a "SchPreOver_Amp_Mic", gaMic, gkTrigDisp, 2
endin
schedule "Mic", 0, 9999
/*********************************************************************************/
/********************************** Instrument 1 *******************************/
/*************************** Random Panning and Dynamics *************************/
/*********************************************************************************/
instr Record1 ;Record on Buffer 1
aMic = gaMic
aMic linenr aMic, 0.5, 0.5, 0.01
aPointer linseg 0, giBuffer1LenSec, ftlen(giBuffer1)
tablew aMic, aPointer, giBuffer1
endin
instr PlayBack1 ;Playback what is recorded on Buffer 1
aPointer linseg 0, giBuffer1LenSec, ftlen(giBuffer1)
aPlayback table aPointer, giBuffer1
aOut linenr aPlayback, 0.1, 0.1, 0.01
kVol1 invalue "vol1"
kVol1 port kVol1,0.01
kDynamicSpeed invalue "k1" ;Random Dynamics controlled by Knob 1.
kDynamicSpeed port kDynamicSpeed,0.01
kAmpSpeed randomi 0, 1, kDynamicSpeed*2
aOut = kAmpSpeed*aOut*ampdb(kVol1)
ShowLED_a "SchPre_asig_instr1", aOut, gkTrigDisp, gkshowdb, gkdbrange
ShowOver_a "SchPreOver_asig_instr1", aOut, gkTrigDisp, 2
kPanSpeed invalue "k1" ;Random Panning controlled by Knob 1.
kPan randomi 0, 1, kPanSpeed
aOutL, aOutR pan2 aOut, kPan
chnmix aOutL, "PlayBack1_1"
chnmix aOutR, "PlayBack1_2"
endin
instr Play1 ;Call two instruments "PlayBack1" and "Record1" - controled by widgets
schedule "PlayBack1", 0, 999
schedule "Record1", 0, 999
endin
instr Stop1 ;Stop two instruments "PlayBack1" and "Record1" - controled by widgets
turnoff2 "PlayBack1", 0, 1
turnoff2 "Record1", 0, 1
turnoff
endin
/*********************************************************************************/
/********************************** Instrument 2 *******************************/
/********************************* Pitch Shifting *******************************/
/*********************************************************************************/
instr Record2 ;Record on Buffer 2
aMic = gaMic
aMic linenr aMic, 0.5, 0.5, 0.01
aPointer linseg 0, giBuffer2LenSec, ftlen(giBuffer2)
tablew aMic, aPointer, giBuffer2
endin
instr PlayBack2 ;Playback what is recorded on Buffer 2
aPointer linseg 0, giBuffer2LenSec, ftlen(giBuffer2)
aPlayback table aPointer, giBuffer2
aOut linenr aPlayback, 0.1, 0.1, 0.01
/*\\\\\\\\\\\\\\\\\\\\\\\\\\\\ FFT \\\\\\\\\\\\\\\\\\\\\\\\\\\*/
ifftsize = 2048
ioverlap = ifftsize/8
iwinsize = ifftsize
iwintype = 1
kScal invalue "k2"
kScal port kScal, 0.1
kFreez invalue "m2"
fsig pvsanal aOut, ifftsize, ioverlap, iwinsize, iwintype
fsigg pvscale fsig, kScal ;control from widgets
fsiggg pvsfreeze fsigg, kFreez, kFreez
aOut pvsynth fsiggg
/*\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\*/
kVol2 invalue "vol2"
kVol2 port kVol2,0.01
aOut = aOut*ampdb(kVol2)
ShowLED_a "SchPre_asig_instr2", aOut, gkTrigDisp, gkshowdb, gkdbrange
ShowOver_a "SchPreOver_asig_instr2", aOut, gkTrigDisp, 2
chnmix aOut, "PlayBack2_1"
chnmix aOut, "PlayBack2_2"
endin
instr Play2 ;Call two instruments "PlayBack2" and "Record2" - controled by widgets
schedule "PlayBack2", 0, 999
schedule "Record2", 0, 999
endin
instr Stop2 ;Stop two instruments "PlayBack2" and "Record2" - controled by widgets
turnoff2 "PlayBack2", 0, 1
turnoff2 "Record2", 0, 1
turnoff
endin
/*********************************************************************************/
/********************************** Instrument 3 *******************************/
/*************************** Random Layers with Panning **************************/
/*********************************************************************************/
instr Record3 ;Record on Buffer 3
aMic = gaMic
aMic linenr aMic, 0.5, 0.5, 0.01
aPointer linseg 0, giBuffer3LenSec, ftlen(giBuffer3)
tablew aMic, aPointer, giBuffer3
endin
instr PlayBack3 ;Playback what is recorded on Buffer 3
aPointer linseg 0, giBuffer3LenSec, ftlen(giBuffer3)
aPlayback table aPointer, giBuffer3
aOut linenr aPlayback, 0.1, 0.1, 0.01
kVol3 invalue "vol3"
kVol3 port kVol3,0.01
aOut = aOut*ampdb(kVol3)
ShowLED_a "SchPre_asig_instr3", aOut, gkTrigDisp, gkshowdb, gkdbrange
ShowOver_a "SchPreOver_asig_instr3", aOut, gkTrigDisp, 2
/*\\\\\\\\\\\\\\\\\\\\ Layers with Panning\\\\\\\\\\\\\\\\\\\\*/
aDel1 delay aOut, 0.05
aDel2 delay aOut, 0.2
aDel3 delay aOut, 0.5
aDel4 delay aOut, 0.9
kPanSpeed invalue "k3" ;Random Panning controlled by Knob 3.
kPanSpeed port kPanSpeed,0.01
kPan randomi 0, 1, kPanSpeed
aOutL0, aOutR0 pan2 aOut, kPan
kPan randomi 0 , 1.5, kPanSpeed
aOutL1, aOutR1 pan2 aDel1, kPan
kPan randomi 0 , 2, kPanSpeed
aOutL2, aOutR2 pan2 aDel2, kPan
kPan randomi 0 , 2.5, kPanSpeed
aOutL3, aOutR3 pan2 aDel3, kPan
kPan randomi 0 , 7, kPanSpeed
aOutL4, aOutR4 pan2 aDel4, kPan ;Later Delay Lines have more intense pannings.
aDelOverallL = aOutL0 + aOutL1 + aOutL2 + aOutL3 + aOutL4
aDelOverallR = aOutR0 + aOutR1 + aOutR2 + aOutR3 + aOutR4
aOutL = aDelOverallL/5
aOutR = aDelOverallR/5
chnmix aOutL, "PlayBack3_1"
chnmix aOutR, "PlayBack3_2"
endin
instr Play3 ;Call two instruments "PlayBack3" and "Record3" - controled by widgets
schedule "PlayBack3", 0, 999
schedule "Record3", 0, 999
endin
instr Stop3 ;Stop two instruments "PlayBack3" and "Record3" - controled by widgets
turnoff2 "PlayBack3", 0, 1
turnoff2 "Record3", 0, 1
turnoff
endin
/*********************************************************************************/
/********************************** Instrument 4 *******************************/
/********************************* Dancing Layers ********************************/
/*********************************************************************************/
instr Record4 ;Record on Buffer 4
aMic = gaMic
aMic linenr aMic, 0.5, 0.5, 0.01
aPointer linseg 0, giBuffer4LenSec, ftlen(giBuffer4)
tablew aMic, aPointer, giBuffer4
endin
instr PlayBack4 ;Playback what is recorded on Buffer 4
aPointer linseg 0, giBuffer4LenSec, ftlen(giBuffer4)
aPlayback table aPointer, giBuffer4
aOut linenr aPlayback, 0.1, 0.1, 0.01
/*\\\\\\\\\\\\\\\\\\\\\\\\\\ Layers \\\\\\\\\\\\\\\\\\\\\\\\\\*/
iDelayTime = giDelayTime_Instr4
aDel delay aOut, iDelayTime
kVol4 invalue "vol4"
kVol4 port kVol4,0.01
aDel = aDel*ampdb(kVol4)
/*\\\\\\\\\\\\\\\\\\\\\\\\\\\\ FFT \\\\\\\\\\\\\\\\\\\\\\\\\\\*/
ifftsize = 2048
ioverlap = ifftsize/8
iwinsize = ifftsize
iwintype = 1
kScal1 = 1.26 ;Major 3rd higher
kScal2 = 0.84 ;Minor 3rd lower
fsig pvsanal aDel, ifftsize, ioverlap, iwinsize, iwintype
fsig1 pvscale fsig, kScal1
aOut1 pvsynth fsig1
fsig2 pvscale fsig, kScal2
aOut2 pvsynth fsig2
/*\\\\\\\\\\\\\\\\\\\ Periodic Amplitudes \\\\\\\\\\\\\\\\\\\*/
iPTA = 8 ;Period Time for Amp of aDel
kAmp_aDel linseg 0, iPTA, 1, iPTA, 0, iPTA, 1, iPTA, 0, iPTA, 1, iPTA, 0, iPTA, 1, iPTA, 0, iPTA, 1, iPTA, 0, iPTA, 1, iPTA, 0, iPTA, 1, iPTA, 0, iPTA, 1, iPTA, 0, iPTA, 1, iPTA, 0, iPTA, 1
aDel = kAmp_aDel*aDel
;Period Time for Amp of aOut1 and aOut2 is half of aDel
kAmp_aOut1 linseg 0, iPTA/2, 1, iPTA/2, 0, iPTA/2, 1, iPTA/2, 0, iPTA/2, 1, iPTA/2, 0, iPTA/2, 1, iPTA/2, 0, iPTA, 1, iPTA/2, 0, iPTA, 1, iPTA/2, 0, iPTA, 1, iPTA/2, 0, iPTA, 1, iPTA/2, 0, iPTA, 1, iPTA/2, 0, iPTA, 1, iPTA/2, 0, iPTA, 1, iPTA/2, 0, iPTA, 1, iPTA/2, 0, iPTA, 1, iPTA/2, 0, iPTA, 1, iPTA/2, 0, iPTA, 1, iPTA/2, 0, iPTA, 1, iPTA/2, 0, iPTA, 1, iPTA/2, 0, iPTA, 1, iPTA/2, 0, iPTA, 1, iPTA/2, 0, iPTA, 1
aOut1 = kAmp_aOut1*aOut1
kAmp_aOut2 linseg 1, iPTA/2, 0, iPTA/2, 1, iPTA/2, 0, iPTA/2, 1, iPTA/2, 0, iPTA/2, 1, iPTA/2, 0, iPTA, 1, 1, iPTA/2, 0, iPTA, 1, 1, iPTA/2, 0, iPTA, 1, 1, iPTA/2, 0, iPTA, 1, 1, iPTA/2, 0, iPTA, 1, 1, iPTA/2, 0, iPTA, 1, 1, iPTA/2, 0, iPTA, 1, 1, iPTA/2, 0, iPTA, 1, 1, iPTA/2, 0, iPTA, 1, 1, iPTA/2, 0, iPTA, 1, 1, iPTA/2, 0, iPTA, 1, 1, iPTA/2, 0, iPTA, 1, 1, iPTA/2, 0, iPTA, 1, 1, iPTA/2, 0, iPTA, 1, 1, iPTA/2, 0, iPTA, 1, 1, iPTA/2, 0, iPTA, 1, 1, iPTA/2, 0, iPTA, 1, 1, iPTA/2, 0, iPTA, 1, 1, iPTA/2, 0, iPTA, 1
aOut2 = kAmp_aOut2*aOut2
/*\\\\\\\\\\\\\\\\\\\\\\\\\\ Panning\\\\\\\\\\\\\\\\\\\\\\\\\*/
aOutL0, aOutR0 pan2 aDel, 0.5 ;Original sound in center (with delay)
kPan1 linseg giBuffer4LenSec-1, giBuffer4LenSec-1, 0 ;1st Layer: starts from R to L, so ia in linseg must be an even number. Thats why I decrease 1 of giBuffer4LenSec, because giBuffer4LenSec was 999 so it is odd. Another important thing is that if ia and idur are the same, every period of panning will take 2 secs. If we want every period takes 1 sec, we must divide the idur by 2.
aOutL1, aOutR1 pan2 aOut1, kPan1
kPan2 linseg 0, giBuffer4LenSec, giBuffer4LenSec ;2nd Layer: starts from L to R
aOutL2, aOutR2 pan2 aOut2, kPan2
aDelOverallL = aOutL0 + aOutL1 + aOutL2
aDelOverallR = aOutR0 + aOutR1 + aOutR2
aOutMain = (aDelOverallL+aDelOverallR)/2
ShowLED_a "SchPre_asig_instr4", aOutMain, gkTrigDisp, gkshowdb, gkdbrange
ShowOver_a "SchPreOver_asig_instr4", aOutMain, gkTrigDisp, 2
aOutL = aDelOverallL/3
aOutR = aDelOverallR/3
chnmix aOutL, "PlayBack4_1"
chnmix aOutR, "PlayBack4_2"
endin
instr Play4 ;Call two instruments "PlayBack4" and "Record4" - controled by widgets
schedule "PlayBack4", 0, 999
schedule "Record4", 0, 999
endin
instr Stop4 ;Stop two instruments "PlayBack4" and "Record4" - controled by widgets
turnoff2 "PlayBack4", 0, 1
turnoff2 "Record4", 0, 1
turnoff
endin
/*********************************************************************************/
/********************************** Instrument 5 *******************************/
/******************************** Grain Distributor ******************************/
/*********************************************************************************/
instr Record5 ;Record on Buffer 5
aMic = gaMic
aMic linenr aMic, 0.5, 0.5, 0.01
aPointer linseg 0, giBuffer5LenSec, ftlen(giBuffer5)
tablew aMic, aPointer, giBuffer5
endin
instr PlayBack5 ;Granular_machine
;get regularity (0) to irregularity (1)
;kIrregularity = 1
kIrregularity invalue "irregularity"
kK5 invalue "k5"
kK5 port kK5, 0.01
kGrainDensity = kK5*100
kGrainSize = kK5*50
;transposition (cent)
kTransCent init 0
;create the pointer that moves randomly
kPointerMax linseg 0, giBuffer5LenSec, 1 ;This pointer moves with the usual speed.
kPointer randomi 0, kPointerMax, 2 ;This pointer moves randomly from starting point to the point of current moment.
kMetro metro kGrainDensity
;if the metronome ticks
if kMetro == 1 then
;apply an offset for getting a-synchronous granular synthesis
kOffset random 0, kGrainSize*kIrregularity
;we call the playing instrument
event "i", "Play_Grain", kOffset/1000, kGrainSize/1000, kPointer*giBuffer5LenSec, kTransCent
endif
endin
instr Play_Grain ;Is palyed by the granular machine.
iSkiptime = p4
iTransCent = p5
iSpeed = cent(iTransCent)
iPhase = iSkiptime / giBuffer5LenSec
;use an interpolating oscillator to read the table
aTable poscil3 1, iSpeed/giBuffer5LenSec, giBuffer5, iPhase
;Put volume control on the sound.
kVol invalue "vol5"
aVol = aTable * ampdb(kVol)
;Put fade in/out on the sound which has volume.
aOut linen aVol, p3/2, p3, p3/2
chnmix aOut, "aOut_to_Pan_Instr"
endin
instr Pan ;Add panning to the output of the 5th instrument.
aIn chnget "aOut_to_Pan_Instr"
kPan randomi 0, 1, 5
aOutL, aOutR pan2 aIn, kPan
ShowLED_a "SchPre_asig_instr5", aIn, gkTrigDisp, gkshowdb, gkdbrange
ShowOver_a "SchPreOver_asig_instr5", aIn, gkTrigDisp, 2
chnmix aOutL, "PlayBack5_1"
chnmix aOutR, "PlayBack5_2"
chnclear "aOut_to_Pan_Instr"
endin
instr Play5 ;Call three instruments "PlayBack5", "Record5" and "Pan" - controled by widgets
schedule "PlayBack5", 0, 999
schedule "Record5", 0, 999
schedule "Pan", 0, 999
endin
instr Stop5 ;Stop three instruments "PlayBack5", "Record5" and "Pan" - controled by widgets
turnoff2 "PlayBack5", 0, 1
turnoff2 "Record5", 0, 1
turnoff2 "Pan", 0, 1
turnoff
endin
/*********************************************************************************/
/********************************** Main Sound Outputs **************************/
/*********************************************************************************/
instr Output
aPlayBack1_1 chnget "PlayBack1_1" ;1st Instrument
aPlayBack1_2 chnget "PlayBack1_2"
aPlayBack2_1 chnget "PlayBack2_1" ;2nd Instrument
aPlayBack2_2 chnget "PlayBack2_2"
aPlayBack3_1 chnget "PlayBack3_1" ;3rd Instrument
aPlayBack3_2 chnget "PlayBack3_2"
aPlayBack4_1 chnget "PlayBack4_1" ;4th Instrument
aPlayBack4_2 chnget "PlayBack4_2"
aPlayBack5_1 chnget "PlayBack5_1" ;5th Instrument
aPlayBack5_2 chnget "PlayBack5_2"
a1 = aPlayBack1_1 + aPlayBack2_1 + aPlayBack3_1 + aPlayBack4_1 + aPlayBack5_1 ;overall
a2 = aPlayBack1_2 + aPlayBack2_2 + aPlayBack3_2 + aPlayBack4_2 + aPlayBack5_2
/*********************** Volume Controller ***********************/
/*\\\\\\\\\\\\\\\\\\\\\\\\\ Left Channel \\\\\\\\\\\\\\\\\\\\\*/
kDb_1 invalue "amp_sig1"
kDb_1 port kDb_1, 0.1
a1 = a1*ampdb(kDb_1)
ShowLED_a "SchPre_asig1", a1, gkTrigDisp, gkshowdb, gkdbrange
ShowOver_a "SchPreOver_asig1", a1, gkTrigDisp, 2
/*\\\\\\\\\\\\\\\\\\\\\\\\\ Right Channel \\\\\\\\\\\\\\\\\\\\\*/
kDb_2 invalue "amp_sig2"
kDb_2 port kDb_2 ,0.1
a2 = a2*ampdb(kDb_2)
ShowLED_a "SchPre_asig2", a2, gkTrigDisp, gkshowdb, gkdbrange
ShowOver_a "SchPreOver_asig2", a2, gkTrigDisp, 2
/******************************************************************/
outch 1, a1, 2, a2
chnclear "PlayBack1_1"
chnclear "PlayBack1_2"
chnclear "PlayBack2_1"
chnclear "PlayBack2_2"
chnclear "PlayBack3_1"
chnclear "PlayBack3_2"
chnclear "PlayBack4_1"
chnclear "PlayBack4_2"
chnclear "PlayBack5_1"
chnclear "PlayBack5_2"
endin
schedule "Output", 0, 9999
/*********************************************************************************/
/*************************************** Record ********************************/
/*********************************************************************************/
instr RecordComplete ;Complete recording of the Original Mic Input and performance. Name of the file must change everytime for avoiding oversaving.
a1, a2 monitor
fout "Original_Mic_Input", 16, gaMic
fout "Recording.wav", 16, a1, a2
endin
;schedule "RecordComplete", 0, 9999