Hi, new day, new troubles... :-)

I have C++ code which needs to restart the audio engine. As far as I can tell, I'm doing everything correctly, calling
Bela_initAudio(); // setup() is called
Bela_startAudio(); // returns 0, render() called repeatedly
Bela_stopAudio(); // stops render()
Bela_cleanupAudio(); // cleanup() is called
...
Bela_initAudio(); // setup() is called
Bela_startAudio(); // returns 0
...

at which point render() is never called. I'd be happy to put together an example project demonstrating the problem if that would help.

Thanks, Jeremy

Bela_startAudio creates and starts the audio thread, which in turn calls render() repeatedly.
can you

cat /proc/xenomai/sched 

and

cat /proc/xenomai/stat

and post the results here ?
These show the scheduler state and CPU usage of the existing threads, respectively.

It would also help to set gRTAudioVerbose=1 and / or add some printfs in PRU::loop()

Hi,

This is during the first run of the init/cleanup cycle:
root@bela ~$ cat /proc/xenomai/sched
CPU PID CLASS PRI TIMEOUT TIMEBASE STAT NAME
0 0 idle -1 - master R ROOT
0 6499 rt 95 17us master D bela-audio
root@bela ~$ cat /proc/xenomai/stat
CPU PID MSW CSW PF STAT %CPU NAME
0 0 0 1180400 0 00500080 98.7 ROOT
0 6499 2 60172 1 00300184 0.0 bela-audio
0 0 0 3499363 0 00000000 0.1 IRQ67: [timer]

Now I set it back up:
root@bela ~$ cat /proc/xenomai/sched
CPU PID CLASS PRI TIMEOUT TIMEBASE STAT NAME
0 0 idle -1 - master R ROOT
root@bela ~$ cat /proc/xenomai/stat
CPU PID MSW CSW PF STAT %CPU NAME
0 0 0 1734565 0 00500080 71.7 ROOT
0 0 0 4065005 0 00000000 1.3 IRQ67: [timer]

Which reflects what I see. Changing the RTAudio verbosity didn't seem to make much of a difference. Upping the Bela verbosity (in the Settings struct) doesn't show anything weird or different between the two init/cleanup cycles. However, the PRU::loop() printfs show the following:

setup()
audio inited
audio started: 0
entering PRU::loop while(!gShouldStop)
Using embedded PRU code
(... runs ...)
Enter new library name for RT loading > someLib2.so
Stopping audio...
exiting PRU::loop while(!gShouldStop)
cleanup()
-> Opened someLib2.so
numInputs: 0
numOutputs: 2
numParams: 8
Starting with period size 16; analog enabled
DAC level 0dB; ADC level -6dB; headphone level -6dB
Warning: couldn't export GPIO test pin
setup()
audio inited
audio started: 0
entering PRU::loop while(!gShouldStop)
exiting PRU::loop while(!gShouldStop)
Using embedded PRU code

So the PRU::loop while() is exiting immediately, and I can confirm that is because gShouldStop isn't being reset when calling Bela_initAudio()... I suppose I can set that manually in setup() as a workaround.

int gShouldStop = false;
is a global variable that is set to false at initialization time but never reset to false once the program runs. It is probably a good idea to add such reset into Bela_initAudio() or Bela_startAudio().