jaradical

  • 20 hours ago
  • Joined Jan 8, 2023
  • 3 discussions
  • 13 posts
  • Ok - a little more complicated than I had envisaged.

    Would adding it to RTAudioCommandLine.cpp make sense? I can see two ways to handle it:

    1. Like the userBelaConfig in Bela_defaultSettings - look for settings.json and populate the settings with that - probably after userBelaConfig is processed.
    2. As part of Bela_getopt_long, by using --jsopts or similar and providing --jsopts settings.json via the Makefile (with file existence tests etc.)

    I can see the various JSON cpp/h files and could probably have a go at coding something up using them.

    Let me know what you'd prefer, and if we should move this conversation to the github issue instead?

    Cheers

    • Oh yeah, I didn't catch that we already do a basename, I'll update my scripts accordingly.

      I'm wondering if there's any way to make this more generic - something like using jq to parse the settings.json if it exists in the project directory and creating the ARGS from that or something?

    • Brilliant Giulio, it's working now!

      I was poking around in the Makefile, but I can see that /opt/Bela/bela_startup.sh is the place to be.

      I ended up doing it slightly differently like this:

               for PROJECT in "$BELA_HOME"/projects/loop_*; do
                   echo Running $PROJECT;
                   PROJNAME=`basename $PROJECT`
                   if [ "$PROJNAME" == "MYPROJECT" ]; then
                       ARGS="-p32"
                   fi
                   /usr/bin/make -C /root/Bela PROJECT=`basename "${PROJECT}"` CL="${ARGS}" runonly
               done

      Thanks again for your help, and if you'd like to play with it, it's here:

      https://github.com/jazamatronic/bela_pepper_patches/blob/main/drumkit_bela_csound/_main.csd

      Cheers

    • Hello,

      I'm running multiple Csound projects on Pepper using the loop_* project settings (See https://forum.bela.io/d/2983-help-getting-bela-button-to-loop-csound-projects-on-pepper), and it's been working wonderfully so far.

      I've been working on a kind of drum machine, and was having trouble with dropped blocks. To try and fix that I've changed Csound ksmps and the block size in the IDE (and hence settings.json) to 32. The project runs fine when launched from the IDE, but when I get to it from the bela button as part of project looping, it sounds like it's reverted to the default block size of 16 and the mismatch between the Csound ksmps and block size is causing severe distortion and loads of dropped blocks.

      Is there a way to have per project block size settings when using the loop_* functionality?

      Cheers

    • giuliomoro Those two should be good to go, although I'm not certain they're up to date with whatever's running on my pepper. You might want to check that they behave as expected before bundling them in.

      I've got a few others in the pipe - they all work nicely on my PC in CsoundQT - just have to finish up the work to get them onto Pepper - so maybe if you hold off for a little while there'll be a few more available.

      I'll post here when they're ready!

      Cheers

    • G'day Giulio,

      Thanks for all the details, it certainly gave me enough to try some things out. As I'm using all of Pepper's buttons in my patch and wanted to make sure I could use the bela cape button that I'd broken out to the front panel I didn't follow your instructions to the letter. Also, it's a PITA to remove and reinstall in the rack, so I'm trying to avoid having to update/flash or what have you. Anyway I think it's mostly working now - here's how I went about it.

      I created a short script, similar to /opt/Bela/bela_button_hold.sh called /opt/Bela/bela_button_click.sh that contained make stoprunning command:

      #!/bin/bash                                                                                                                           
      #this file is executed when the button on the Bela cape is pressed momentarily                                                        
                                                                                                                                            
      CUSTOM_FILE=/opt/Bela/local/`basename $0`                                                                                             
      [ -f $CUSTOM_FILE ] &&\                                                                                                               
      {                                                                                                                                     
              echo "Bela button clicked, running $CUSTOM_FILE"                                                                              
              $CUSTOM_FILE                                                                                                                  
              exit                                                                                                                          
      }                                                                                                                                     
      echo Bela button clicked, stopping current project                                                                                    
      make --no-print-directory -C /root/Bela stoprunning           

      Then, I updated /lib/systemd/system/bela_button.service as such:

      [Unit]                                                                                                                                
      Description=Monitor the Bela cape button                                                                                              
      After=networking-online.target                                                                                                        
                                                                                                                                            
      [Service]                                                                                                                             
      Type=simple                                                                                                                           
      ExecStart=/usr/bin/stdbuf -oL -eL /usr/local/bin/bela-cape-btn --pin 115 --click /opt/Bela/bela_button_click.sh --hold /opt/Bela/bela_button_hold.sh --delay 20 --monitor-click 1                                                                                           
      Environment=HOME=/root                                                                                                                
      
      [Install]                                                                                                                             
      WantedBy=default.target

      Finally, I had to intercept the button press to stop csound from eating it, so I changed the /root/Bela/Makefile csound command to:

      RUN_COMMAND?=bash -c 'belacsound --stop-button-pin -1 --csd=$(CSOUND_FILE) $(COMMAND_LINE_OPTIONS) 2>&1'                              

      And with that, I can cycle between the two csound patches I currently have running on the board with the bela button, thanks!

      Might be problematic if I mix and match engines in my projects, but for now they're all csound.

      Can you spot any foreseeable problems doing it this way?

      Cheers

      • Hi,

        I've added a push button to my Pepper for front panel access to the Bela Button.
        I'd like to be able to loop through my Csound projects, but I'm having trouble getting it to function as desired.
        I've followed the instructions from https://learn.bela.io/using-bela/bela-techniques/running-projects-on-boot/ and have currently got two projects loop_a_project and loop_b_project.
        loop_a_project starts correctly on boot, but when I hit the button, I no longer get sound from Pepper, but loop_b_project doesn' t appear to start.

        Here is some messages I caught from journalctl:

        Mar 22 18:47:34 bela stdbuf[251]: Button pressed, quitting
        Mar 22 18:47:34 bela kernel: rtdm_pruss_irq_close
        Mar 22 18:47:34 bela stdbuf[202]: Click detected -- no action
        
        Broadcast message from root@bela (somewhere) (Wed Mar 22 18:47:49 2023):
        
        Bela button held, restarting
        
        Mar 22 18:47:49 bela stdbuf[202]: Bela button held, running /opt/Bela/local/bela_button_hold.sh

        Note that I've changed the hold behaviour to reboot instead of shutdown.

        I checked the bela_startup.service after having pressed the button, it looks like it's continuing to run:

        root@bela:/lib/systemd/system# systemctl status bela_startup.service
        ● bela_startup.service - Run Bela at boot
           Loaded: loaded (/lib/systemd/system/bela_startup.service; enabled; vendor preset: enabled)
           Active: active (running) since Thu 2016-11-03 17:16:50 UTC; 5min ago
         Main PID: 249 (bela_startup.sh)
            Tasks: 11 (limit: 4915)
           CGroup: /system.slice/bela_startup.service
                   ├─249 /bin/bash /opt/Bela/bela_startup.sh
                   ├─279 /usr/bin/make -C /root/Bela PROJECT=loop_a_morphing_wavefolder CL= runonly
                   ├─443 /bin/sh -c sync& cd /root/Bela/projects/loop_a_morphing_wavefolder && bash -c 'belacsound --csd=/root/Bela/projects/loop_a_morphing_wavefolde
                   ├─445 bash -c belacsound --csd=/root/Bela/projects/loop_a_morphing_wavefolder/_main.csd  2>&1
                   └─452 belacsound --csd=/root/Bela/projects/loop_a_morphing_wavefolder/_main.csd
        
        Nov 03 17:16:55 bela stdbuf[249]: [commit: ea6cd697190d99414f8097b385c1b0e4d61fdb04]
        Nov 03 17:16:55 bela stdbuf[249]: libsndfile-1.0.27
        Nov 03 17:16:55 bela stdbuf[249]: sr = 44100.0, kr = 2756.250, ksmps = 16
        Nov 03 17:16:55 bela stdbuf[249]: 0dBFS level = 1.0, A4 tuning = 440.0
        Nov 03 17:16:57 bela stdbuf[249]: audio buffered in 256 sample-frame blocks
        Nov 03 17:16:57 bela stdbuf[249]: SECTION 1:
        Nov 03 17:16:57 bela stdbuf[249]: Initialising spinlock...
        Nov 03 17:16:57 bela stdbuf[249]: Starting realtime mode queue: 0xb533d010 thread: 0x16e0890
        Nov 03 17:16:57 bela stdbuf[249]: Underrun detected: 12 blocks dropped
        Nov 03 17:17:47 bela stdbuf[249]: Button pressed, quitting

        I also tried adjusting the csound launch command to belacsound --stop-button-pin 115 but after a quick look through the code I'm not sure that particular plumbing is hooked up.

        Any ideas what's going on or what to look at next to further debug?

        Cheers

      • If you ignore the -5V source and the 1k resistor connecting it to the op-amp's inverting input you've got an amplifier with a gain of -2 (Rfb/R1 = 1000/500 = 2, and it's inverting, so -2) . Putting in an AC signal with a range of 0-5V would give you 0 to -10V on the output. Then, ignoring the AC source and the 500R resistor, and just taking the -5V and the 1K resistor, we have an amplifier with a gain of -1. So -5V in gives 5V out. Now it's a summing amplifier, so we sum 0 to -10 with 5, to give us 5 to -5V. To make it work as a summer you need to ground the non-inverting input so that the feedback forces the inverting input to 0, giving a virtual ground there.

        There's probably other ways to do it, but that's how I would go about it.

        Cheers

      • giuliomoro Also, I'd go for larger resistors.

        Yes, laziness on my behalf, the default resistor value in falstad was 1k and I just ran with it.

      • Thanks for the useful tip - I was seeing the same problem where my Csound projects selected to run on boot would fail with a Segmentation fault.

        I can confirm that upgrading to csound 6.18 from the link above has resolved this issue.

        Cheers