So I am running my csound instrument on the Bela and got a couple of questions:
1. What is a “Mode Switch” in Bela? Is it sth. related to high cpu and block drop?
2. Running my granulator on Bela mini works fine, and everything seems to be working. But on my own original Bela, it runs for a few secs and then the connection is lost automatically as the Bela console shows. But the Bela still keeps running on its own and then shut down automatically after running for about 30s. I also have to forced unplug it several times. I have the code pasted here.
3. Does Bela have a "preffered" block size for csound? When I run my csound code on bela mini, 16 and 32 seems to be good choices, 64 gets glichy.
Bela board automatically disconnect
- Edited
<CsoundSynthesizer>
<CsOptions>
-odac
</CsOptions>
<CsInstruments>
sr = 44100
ksmps = 32
nchnls = 2
0dbfs = 1
ginFile ftgen 0, 0 ,0 ,1, "guitar.wav", 0, 0, 0; sound source file
giSine ftgen 0,0,65536,10,1
giCosine ftgen 0,0,8193,9,1,1,90
giSigmoRise ftgen 0,0,8193,19,0.5,1,270,1
giSigmoFall ftgen 0,0,8193,19,0.5,1,90,1
giPan ftgen 0, 0, 32768, -21, 1 ; for panning (random values between 0 and 1)
instr 1; Granulator
/*csound instrument parameters*/
giamp = 0.1
gkspeed = 20.0
gkgrainrate = 25.0
gkgrainsize = 110.0;p6;
gkcent = 0.0; p7 transpositionin cent
gkposrand = 0.0 ;p8 ; time position randomness (offset) of the pointer in ms
gkcentrand = 0.0; p9 transposition randomness in cents
ipan = 0.0;p10; panning narrow(0) to wide(1)
idist = 0.5;p11 ; grain distribution (0=periodic, 1=scattered)
/* get lentgh of audio file for transposition and time pointer*/
ifilen tableng ginFile
ifildur = ifilen / sr
/*sync input*/
async = 0.0; disable external sync
/*grain envelope*/
kenv2amt = 0;no secondary enveloping
ienv2tab = -1; default secondary envelope
ienv_attack = giSigmoRise; attack envelope
ienv_decay = giSigmoFall; decay envelope
ksustain_amount = 0; time(infraction of grain duration) as sustain level for each grain.
ka2dratio = 0.5; balance between attack and decay
/*amplitude*/
igainmask = -1; no gain masking
/*transposition*/
gkcentrand rand gkcentrand; random transposition
iorig = 1/ ifildur; original pitch
kwavfreq = iorig * cent(gkcent + gkcentrand)
/*other pitch related params(disabled)*/
ksweepshape =0 ; no frequency sweep
iwavfreqstarttab = -1; default frequency sweep start
iwavfreqendtab = -1; default frequency sweep
awavfm = 0; no FM input
ifmamptab = -1; default FM scaling (=-1)
kfmenv = -1 ; default FM envelope(flat)
/*trainlet related params(disabled)*/
icosine = giCosine; cosine ftable
kTrainCps = gkgrainrate; set trainlet cps equal to grain rate for single-cycle trainlet in each grain
knumpartials = 1; number of partials in trainlet
kchroma = 1;
/*pannings, using channel mask*/
imid = .5; center
ileftmost = imid - ipan/2
irightmost = imid + ipan/2
giPanthis ftgen 0, 0, 32768, -24, giPan, ileftmost, irightmost; reScales gipan according to ipan
tableiw 0, 0, giPanthis; change index 0
tableiw 32766, 1, giPanthis; and 1 for ichannelmasks
ichannelmasks = giPanthis; ftable for panning
/*random gain masking (disabled)*/
krandommask = 0;
/*source waveforms*/
kwaveform1 = ginFile ; source waveform
kwaveform2 = ginFile ; all 4 sources are the same
kwaveform3 = ginFile
kwaveform4 = ginFile
iwaveamptab = -1 ; (default) equal mix of source waveforms and no amplitude for trainlets
/*timepointers*/
afilposphas phasor gkspeed / ifildur
/*generate random deviaton of the time pointer*/
gkposrandsec = gkposrand / 1000 ; ms -> sec
gkposrand = gkposrandsec / ifildur ; phase value (0-1)
gkrndpos linrand gkposrand; ranodm offset in phase values
/*add random deviation to the time pointer*/
asamplepos1 = afilposphas + gkrndpos; resulting phase values (0-1)
asamplepos2 = asamplepos1
asamplepos3 = asamplepos1
asamplepos4 = asamplepos1
/*original key for each source waveform*/
kwavekey1 = 1
kwavekey2 = kwavekey1
kwavekey3 = kwavekey1
kwavekey4 = kwavekey1
/* maximum number of grains per k-period*/
imax_grains = 100
aL, aR partikkel gkgrainrate, idist, -1, async, kenv2amt, ienv2tab, ienv_attack, ienv_decay,
ksustain_amount, ka2dratio, gkgrainsize, giamp, igainmask, kwavfreq,ksweepshape,
iwavfreqstarttab, iwavfreqendtab, awavfm, ifmamptab,kfmenv,icosine, kTrainCps,
knumpartials, kchroma, ichannelmasks, krandommask, kwaveform1, kwaveform2,
kwaveform3, kwaveform4,iwaveamptab, asamplepos1, asamplepos2, asamplepos3,
asamplepos4,kwavekey1, kwavekey2, kwavekey3, kwavekey4, imax_grains
outs aL, aR
endin
</CsInstruments>
<CsScore>
;causes Csound to run for about 7000 years...
f0 z
i1 0 z
</CsScore>
</CsoundSynthesizer>
Keyi 1. What is a “Mode Switch” in Bela? Is it sth. related to high cpu and block drop?
it's something bad. It means that the audio thread has lost real-time priority. Any time it happens, an underrun becomes more likely to occur. If you have a the MSW counter increase regularly, then it must be that some parts of your code to through a non real-time safe path and should be fixed.
- Running my granulator on Bela mini works fine, and everything seems to be working. But on my own original Bela, it runs for a few secs and then the connection is lost automatically as the Bela console shows. But the Bela still keeps running on its own and then shut down automatically after running for about 30s. I also have to forced unplug it several times. I have the code pasted here.
That's weird. Are the two boards running the same version of Csound and of the Bela code? The Bela cape uses slightly more CPU than the BelaMini because of the analog outputs, but that shouldn't cause the different behaviour you are observing. That the program runs for 30 seconds before stopping is even more puzzling.
Keyi . Does Bela have a "preffered" block size for csound? When I run my csound code on bela mini, 16 and 32 seems to be good choices, 64 gets glichy.
On BelaMini and Bela cape rev B, 128 is the maximum I would recommend. On Bela cape Rev C, 64 is the maximum I recommend. In any case, make sure that the ksmps
are the same as the block size. Normally performance improves when increasing the block size, so you should have better performance at 64 than at 32 or 16. That's only in general terms, I have no idea what your Csound code is doing and how that is affected by the ksmps.