csounder You might need to make changes to the Csound examples, as I suggested to you previously
using this as a default header for the .csd files

will do once the release is ready.

csounder - any suggestions about what might have changed, or what might now be required.

nothing as far as I know 🙁 send me an example passthrough patch and I can have a look

When I comment out the RtMIDI=NULL from the 4-MIDI example, it runs, but...

there are a lot of little clicks now (possibly data-lates as Barry Vercoe used to call them?)

and the console does report a lot of dropouts and mode switches (which might explain the clicks)

Underrun detected: 1 blocks dropped
Underrun detected: 1 blocks dropped

Underrun detected: 1 blocks dropped
Underrun detected: 1 blocks dropped
rtevent: T 12.251 TT 12.251 M: 0.06069 0.08127
rtevent: T 12.263 TT 12.263 M: 0.04022 0.04759
Underrun detected: 1 blocks dropped
Underrun detected: 1 blocks dropped

Underrun detected: 1 blocks dropped

Underrun detected: 1 blocks dropped
35608 mode switches detected on the audio thread.
Underrun detected: 1 blocks dropped
38370 mode switches detected on the audio thread.
41137 mode switches detected on the audio thread.
backtrace() returned 0 addresses
Csound tidy up: Terminated
Makefile:595: recipe for target 'runide' failed
make: *** [runide] Terminated
inactive allocs returned to freespace
end of score. overall amps: 0.15828 0.15978
overall samples out of range: 0 0
0 errors in performance
Elapsed time at end of performance: real: 16.050s, CPU: 7.453s
Bela stopped
root@bela ~/Bela#

I am using the following sample rate and krate settings

sr = 44100
ksmps = 8. or ksmps = 16
nchnls = 2
0dbfs = 1

I see. Mode switches are happening.

Was this not happening in the script you previously mentioned was working fine? If that's the case, could you send me the well behaving script?

    giuliomoro There were almost always "some" mode switches and dropped blocks, but never this many and never these little cricket clicks. I will send you a few files to test. Working on them now.

    sounds like this is not a viable solution then, and I may have to revert to the previous one. Can you send me some example code that uses multiple MIDI devices? Then I can figure out how to make it work with the "Bela" MIDI API.

      giuliomoroRunning multiple MIDI devices is not a top priority, but it would be nice to connect a hub to the bela and just use any of the controllers that one has connected.

      The strange thing now, is that realtime audio in does not work with the latest bela2 (it could be connected perhaps?)
      - and so, this might not be portMIDI related.

      in the examples, the audio loopback still works, but none of my 50+ audio examples work any longer
      - and the console does not report any issues.

      As a test example, you could just use the previous example with the 'ins' opcode
      - this works on the laptop and this worked previously

      I tried forcing the comandline with a -iadc and -odac and --realtime and --daemon, but this made no difference.

      <CsoundSynthesizer>
      <CsOptions>
      </CsOptions>
      <CsInstruments>
      
      sr       = 44100
      ksmps    = 16
      nchnls   = 2
      0dbfs    = 1
      
      instr    1 ; Stereo delay with normal and cross-feedback
      
      ilevl    = p4      ; Output level
      idelay1  = p5/1000 ; L delay in ms
      idelay2  = p6/1000 ; R delay in ms
      ifdbk1   = p7      ; L feedback
      ifdbk2   = p8      ; R feedback
      ifdbkx   = p9      ; X Feedback
      ifreq1   = p10     ; L cutoff
      ifreq2   = p11     ; R cutoff
      imix     = p12     ; Mix: 0=Dry 1=Delay
      afdbk1   init 0
      afdbk2   init 0
      
      ainL, ainR ins
      ain = ainL+ainR
      
      ;ain      soundin  "sp_hellorcb.aif"   ; Does NOT work on Bela
      ;ain     diskin "sp_hellorcb.aif", 1    ; WORKS on Bela
      
      ain1     = ain + afdbk1*ifdbk1 + afdbk2*ifdbkx
      ain2     = ain + afdbk2*ifdbk2 + afdbk1*ifdbkx
      adelay1  delay  ain1, idelay1
      adelay2  delay  ain2, idelay2
      adelay1  butterlp  adelay1, ifreq1
      adelay2  butterlp  adelay2, ifreq2
      afdbk1   = adelay1
      afdbk2   = adelay2
      aout1    = adelay1*imix + ain*(1 - imix)
      aout2    = adelay2*imix + ain*(1 - imix)
      outs1    aout1*ilevl
      outs2    aout2*ilevl
      
      endin
      
      </CsInstruments>
      <CsScore>
      ;Delay in ms, Filt in Hz. Total feedback should be <1?
      
      ;   Strt  Leng   Levl  DelyL DelyR FeedL FeedR XFeed FiltL FiltR Mix
      i1  0.00  10.00  1.00  500   400   0.40  0.40  0.40  2500  2500  0.50
      e
      </CsScore>
      </CsoundSynthesizer>

        csounder As a test example, you could just use the previous example with the 'ins' opcode

        which one please? I am not sure I understand which one you are referring to.

        In the meantime, you can try 6.15-bela3 release:

        • restores MIDI functionality (or at least it should, let me know)
        • adds support for Trill Craft. You have to specify 30 "touches", and the touch size for each will be the reading from each individual pad ( I think -- completely untested)

          giuliomoro I will try the latest version, and solder up my Trill Crafts for those tests too!

          Here is a working MIDI .csd, in the CsOptions section, you will see command lines for:
          previous Bela 6.15 (with no multiple MIDI support, but excellent MIDI)
          Bela 6.15 v2 (with multiple MIDI support, working!... but many Mode switches and Dropped blocks)
          the command line settings I use on the Mac, to run Csound with multiple MIDI devices in the terminal

          As you will see from the .csd below, it is reading MIDI CCs 1-9 (typically from my nanoControl)

          <CsoundSynthesizer>
          <CsOptions>
          ;-Mhw:1,0,0 -+rtmidi=NULL --daemon -dm0 ; Bela 6.15 v1
          ;-Mhw:1,0,0 --daemon -dm0 ; Bela 6.15 v2
          -Mhw:1,0,0 -Ma --daemon -dm0 ; Bela 6.15 v2 (multiple MIDI devices)
          ;csound -+rtaudio=pa_cb -iadc1 -odac1 -+rtmidi=portmidi -Ma --env:CSNOSTOP=yes ; Mac commandline
          </CsOptions>
          <CsInstruments>
          
          sr		= 44100
          ksmps	= 16
          nchnls	= 2
          0dbfs	= 1
          
          gaRvb	init 0
          
          ctrlinit	1,   1,100, 2,0, 3,0, 4,64, 5,1, 6,10, 7,100, 8,10, 9,76
          
          		instr	1
          icps	cpsmidi
          iamp	ampmidi .5
          
          kamp	midic7 1, 0,1
          kamp	port 	kamp,.1	
          kcar	midic7 2, 1,4
          kcar	port 	kcar,.01
          kmod	midic7 3, 1,10
          kmod	port 	kmod,.01
          kindx	midic7 4, 1,13
          kindx	port	kindx,.01
          iatk	midic7 5, .001,1
          idec	midic7 6, .01,1
          isus	midic7 7, 0,1
          irel	midic7 8, .01,2
          kWet	midic7 9, 0,1
          
          asig	foscil	kamp*iamp, icps, kcar, 1+(kmod), kindx, 1
          kmgate	mxadsr	iatk, idec, isus, irel
          
          aDry	=	asig * kmgate
          
          		vincr 	gaRvb, aDry * kWet
          
          		outs		aDry, aDry
          		endin
          
          		instr 99
          		denorm	gaRvb
          awetL,awetR freeverb gaRvb, gaRvb, .9, .5
          		outs awetL, awetR
          		clear gaRvb
          		endin
          
          </CsInstruments>
          
          <CsScore>
          f1	0	16384	10	1
          i 1  0 z
          i 99 0 z
          </CsScore>
          
          </CsoundSynthesizer>

          giuliomoro to test and see/hear if realtime audio in is working again, you would use the version of the stereo-delay instrument that includes the two uncommented lines (and plug in your iPhone or a Microphone):

          ainL, ainR ins
          ain = ainL+ainR

          to test if the soundin opcode is working, you need to add your own mono sample to the project and uncomment
          the ain line with the soundin opcode.

          ;ain soundin "sp_hellorcb.aif" ; Does NOT work on Bela.

          • you should replace "sp_hellorcb.aif" with the name of your uploaded mono sample.
            It can be either a wave or aiff - for instance

          ain soundin "sp_hellogiulio.wav"

          and if instead, you were to uncomment the line using diskin opcode, you will hear/see that it does work

          ain diskin "sp_hellorcb.aif", 1 ; WORKS on Bela

          I will try your latest build now.

          Best,

          -dB

            giuliomoro I would love to provide several additional example instruments that would show additional ways of working with the Bela and Csound - and that sound great too! I will pull them together and you can see which you might like to include.

            giuliomoro I am trying the 6.15-bela3 release now.

            Are these the messages that you would expect to appear in my terminal when updating?

            apt install ~/Bela/projects/updateCsound/csound-6.0.0-Linux-bela3.deb
            Reading package lists... Done
            Building dependency tree

            Reading state information... Done
            Note, selecting 'csound:amd64' instead of '/root/Bela/projects/updateCsound/csound-6.0.0-Linux-bela3.deb'
            The following packages will be REMOVED:
            csound
            The following NEW packages will be installed:
            csound:amd64
            0 upgraded, 1 newly installed, 1 to remove and 0 not upgraded.
            Need to get 0 B/7531 kB of archives.
            After this operation, 1024 B of additional disk space will be used.
            Do you want to continue? [Y/n] Y
            Get:1 /root/Bela/projects/updateCsound/csound-6.0.0-Linux-bela3.deb csound amd64 6.0.0 [7531 kB]
            perl: warning: Setting locale failed.
            perl: warning: Please check that your locale settings:
            LANGUAGE = (unset),
            LC_ALL = (unset),
            LANG = "en_US.UTF-8"
            are supported and installed on your system.
            perl: warning: Falling back to the standard locale ("C").
            locale: Cannot set LC_CTYPE to default locale: No such file or directory
            locale: Cannot set LC_MESSAGES to default locale: No such file or directory
            locale: Cannot set LC_ALL to default locale: No such file or directory
            dpkg: error processing archive /root/Bela/projects/updateCsound/csound-6.0.0-Linux-bela3.deb (--unpack):
            package architecture (amd64) does not match system (armhf)
            Errors were encountered while processing:
            /root/Bela/projects/updateCsound/csound-6.0.0-Linux-bela3.deb
            E: Sub-process /usr/bin/dpkg returned an error code (1)
            root@bela:~#

              giuliomoro 6.15-bela3 release - initial test

              1. not sure it was installed correctly? sorry
              2. as I noted previously, in 6.15-bela2, realtime audio-in does not work so...
                2a. I rolled back to 6.15-bela1, and... realtime audio-in WORKS (yes!) - in this version, and also...
                2b. To my surprise, multiple MIDI inputs WORK with this older version (?)

              with the following command line in the csOptions:

              -Mhw:1,0,0 -Ma --daemon ; -dm0

              The console still reports a lot of dropouts and a lot of ModeSwitch changes, but not as many as in 6.15 v2

              =====

              Building project ...
              Build finished
              Running project ...
              0"058.644| WARNING: [main] duplicate call from main program to xenomai_init() ignored
              0"058.939| WARNING: [main] (xeno-config --no-auto-init disables implicit call)
              0dBFS level = 32768.0
              --Csound version 6.15 (float samples) Oct 15 2020
              [commit: c329d91b2527e96f05ecb47837e2bfd3b68f5be7]
              libsndfile-1.0.27
              Device type: Bar (1)
              Address: 0x20
              Firmware version: 2
              Device type: Square (2)
              Address: 0x28
              Firmware version: 2
              Device type: Ring (4)
              Address: 0x38
              Firmware version: 2
              Device type: Hex (5)
              Address: 0x40
              Firmware version: 2
              realtime mode enabled
              WARNING: [mcould not open library '/usr/lib/csound/plugins-6.0/libfluidOpcodes.so' (libfluidsynth.so.1: cannot open shared object file: No such file or directory)
              WARNING: could not open library '/usr/lib/csound/plugins-6.0/libosc.so' (liblo.so.7: cannot open shared object file: No such file or directory)[m
              [mUnifiedCSD: /root/Bela/projects/Oct25/MIDI-FMcc1-8.csd
              STARTING FILE
              Creating options
              Creating orchestra
              closing tag
              Creating score
              realtime mode enabled
              rtmidi: ALSA Raw MIDI module enabled
              sorting score ...
              ... done
              setting dummy interface
              midi channel 1 using instr 1
              midi channel 2 using instr 1

              midi channel 63 using instr 1
              midi channel 64 using instr 1
              displays suppressed
              0dBFS level = 1.0
              ALSA midi: Using all devices.
              ALSA: opened MIDI input device 'hw:0,0'
              ALSA: opened MIDI input device 'hw:1,0'
              ALSA: opened MIDI input device 'hw:2,0'
              orch now loaded
              audio buffered in 256 sample-frame blocks
              SECTION 1:
              Initialising spinlock...
              Starting realtime mode queue: 0xb5027010 thread: 0xdabb78
              Underrun detected: 39 blocks dropped
              Underrun detected: 1 blocks dropped

              Underrun detected: 1 blocks dropped
              2135 mode switches detected on the audio thread.
              Underrun detected: 1 blocks dropped
              Underrun detected: 1 blocks dropped
              Und

              Underrun detected: 1 blocks dropped
              Underrun detected: 1 blocks dropped
              Underrun detected: 1 blocks dropped
              Underrun detected: 1 blocks dropped

              Underrun detected: 1 blocks dropped
              Underrun detected: 1 blocks dropped
              10695 mode switches detected on the audio thread.
              Underrun detected: 1 blocks dropped

              Underrun detected: 1 blocks dropped
              backtrace() returned 0 addresses
              Csound tidy up: Terminated
              Makefile:595: recipe for target 'runide' failed
              make: *** [runide] Terminated
              Underrun detected: 1 blocks dropped
              15004 mode switches detected on the audio thread.
              inactive allocs returned to freespace
              end of score. overall amps: 0.41622 0.35189
              overall samples out of range: 0 0
              0 errors in performance
              Bela stopped
              root@bela ~/Bela#

              csounder Are these the messages that you would expect to appear in my terminal when updating?

              no. Something was broken in the package. I uploaded another bela4 version that fixes that.

              csounder
              to test if the soundin opcode is working, you need to add your own mono sample to the project and uncomment
              the ain line with the soundin opcode.

              ;ain soundin "sp_hellorcb.aif" ; Does NOT work on Bela.

              OK, I can reproduce that this doesn't work. In the source code of soundin I see a comment that says soundin now uses diskin2 VL 24-12-16. Not sure if that means anything to you?

                giuliomoro the comment in the code is by Victor Lazzarini - it would be great if you contacted him about this (on the Bela at least) bug. It does confirm that the console is reporting this fact (feature? bug?) when the .csd is loaded and it reports that diskin2 has loaded the sample "sp_hellorcb.aif" - when the soundin opcode is used in the .csd file - but, then... there is silence, no sound, as if the file is loaded and there is no 'error' but the rest of the instrument can't find it. curious. I am sure Victor will have a suggestion and an explanation.

                giuliomoro testing 615-bela5 now.

                Awesome.

                All seems to be working very very well. THANKS!

                (I will report on the Trills in the next post - my Trill Craft is soldered and ready, but that test will wait until tomorrow)

                Here are some details (30 or so models tested - NoteList, Generative, MIDI, Audio Processing, MIDI with Audio)

                Warnings in the console about missing libraries - gone! - check
                Audio IN - check
                MIDI IN - check
                - even Multiple Simultaneous MIDI controllers plugged into a USB HUB (are powered and working) - check
                (when using the: -Ma command line flag)
                MIDI and Audio at the same time - check (controlling Audio FX from MIDI sliders and knobs)

                now, in some MIDI instruments, there do still seem to be an ever-increasing number of mode switching in the audio thread happening, especially when I am using real-time MIDI in, and even more when I have Multiple MIDI in set (-Ma), or without -Ma, but when I am playing lots of notes from my controller keyboard.

                ? do I need to "uninstall" portMIDI ?

                - if so, how do I do this

                Finally, for now, as you know, the soundin opcode is still not working correctly,
                - maybe it will not work on the Bela?
                - maybe this is by design and is related to memory issues and buffering issues?

                BUT WOW - this is a really wonderful update. THANKS.
                - I will be making you some model instruments (for testing and sharing)

                  csounder now, in some MIDI instruments, there do still seem to be an ever-increasing number of mode switching in the audio thread happening, especially when I am using real-time MIDI in, and even more when I have Multiple MIDI in set (-Ma), or without -Ma, but when I am playing lots of notes from my controller keyboard

                  Please send me the very code that shows this issue.

                  To uninstall portmidi try

                  dpkg -r libportmidi0

                    giuliomoro

                    doing some sound design with this MIDI instrument with reverb - quite a lot of mode switching still - and some crickets too. Try it out. You might need to change your CC numbers. I am using the Novation LaunchKey mini and it is set up for controllers 21 - 28 by default

                    324559 mode switches detected on the audio thread.
                    327326 mode switches detected on the audio thread.
                    330092 mode switches detected on the audio thread.
                    Underrun detected: 1 blocks dropped
                    332858 mode switches detected on the audio thread.
                    335625 mode switches detected on the audio thread.

                    ======

                    ; Adam Boulanger
                    ; MIDI added to Hans Mikelson's 'River' instrument from The Csound Catalog
                    <CsoundSynthesizer>
                    <CsOptions>
                    -Mhw:1,0,0 --daemon -dm0
                    </CsOptions>
                    <CsInstruments>
                    
                    sr     = 44100
                    ksmps  = 16
                    nchnls = 2
                    0dbfs  = 1
                    
                    maxalloc 1, 6
                    
                    	ctrlinit 1, 21, 110, 22,110, 23,120, 24,1, 25,0, 26,64
                    
                    garvb		init	0	
                    
                    			instr 	1
                    			
                    iamp		ampmidi .75
                    kcps		cpsmidib 1
                    icps        cpsmidi
                    
                    kvol        midic7  21, 0,1
                    kcut1		midic7	22, 50,800						;Added:Tune reson filters
                    kcut2		midic7	23, 50,800
                    kcut3		midic7	24, 440,880
                    kmod		midic7	25, .6, 1.4					
                    krvbsend	midic7	26, 0,.5
                    
                    klfo		lfo		kmod, .02+rnd(.09)
                    aplk		pluck 	iamp, kcps+klfo, icps, 0, 1
                    asig        dcblock2 aplk
                    af1			reson	asig, kcut1+rnd(440), 80
                    af2			reson	asig, kcut2+rnd(222), 80
                    af3			reson	asig, kcut3+rnd(880), 80
                    abalnc		balance af1+af2+af3, asig
                    afinal		linenr	abalnc, .01, .4, .5
                    adry		=		afinal*kvol
                    			outs 	adry,adry
                    			vincr	garvb, adry*krvbsend
                    			
                    			endin
                    			
                            	instr  	Reverb
                    irevtm    	=       2.6
                    ihidif    	=       0.2
                            	denorm garvb
                    aout      	reverb2	garvb, irevtm, ihidif     	; DELAY FOR TIME
                              	out		aout            	 		; OUTPUT THE CHANNEL
                    			clear	garvb
                              	endin
                              	
                    </CsInstruments>
                    <CsScore>
                    f0  z
                    f1	0	16384	10	1							; sine wave
                    i "Reverb" 0	-1 	    
                    </CsScore>
                    </CsoundSynthesizer>

                    giuliomoro for comparison, you might be interested in the fact that this instrument, that uses more CPU but does not have any reverb running, does not report and mode switching or dropped blocks

                    
                    <CsoundSynthesizer>
                    <CsOptions>
                    -Mhw:1,0,0 -+rtmidi=NULL --daemon -dm0
                    </CsOptions>
                    <CsInstruments>
                    
                    sr     = 44100
                    ksmps  = 16
                    nchnls = 2
                    0dbfs  = 1
                    
                    maxalloc 1,6
                    
                    ; Initialize the global variables.
                    ; Table #1 - initial position
                    git1 ftgen 1, 0, 128, 7, 0, 64, 1, 64, 0
                    ; Table #2 - masses
                    git2 ftgen 2, 0, 128, -7, 1, 128, 1
                    ; Table #3 - stiffness
                    git3 ftgen 3, 0, 128, -7, 0, 64, 100, 64, 0
                    ; Table #4 - damping
                    git4 ftgen 4, 0, 128, -7, 1, 128, 1
                    ; Table #5 - initial velocity
                    git5 ftgen 5, 0, 128, -7, 0, 128, 0
                    
                    instr 1
                      iamp ampmidi .75
                      ipch cpsmidi 
                      kenv	madsr .1,.12,.68,.3
                      ipos = 1
                      imass = 2
                      istiff = git3
                      idamp = 4
                      ivel = 5
                      a1 scantable iamp, ipch, ipos, imass, git3, idamp, ivel
                      a2 dcblock a1
                      outs a2*kenv,a2*kenv
                    endin
                    </CsInstruments>
                    
                    <CsScore>
                    f0 z
                    </CsScore>
                    </CsoundSynthesizer>