u/AdCompetitive1256

A realtime thread creation with SCHED_FIFO flag worked for months, then today it keeps failing.

Long story short, I have a DietPi Armbian Trixie OS with kernel v6.18 installed on what used to be an Android STB (Amlogic S905X)

I have been developing my realtime audio app with it for the past 3 months. The app creates a thread for the audio tasks with a SCHED_FIFO flag, using pthread.

10 hours ago, I shutdown the system as usual, and went to do other things, then came back later to it to continue working on the app again as usual. Booted into the system, but suddenly the compiled app couldn't create the thread, no matter how many times I tried, even across multiple reboots and power cycles.

The returned error code from trying to create the thread is 1, which means the kernel is not allowing the SCHED_FIFO flag anymore. Replaced the flag with SCHED_OTHER, and the thread creation is always a success and my app runs fine.

Why??

The box does not have internet connection, and the last time I updated the system was after I installed it, which is 3 months ago.

I don't understand why suddenly the OS decided that I should not have the permission for a real-time thread, even though I did not make any changes to the system. Why would I mess around with it? I'm a noob Linux user, this is the longest I have been on the OS.

Have any of you experienced this before? And if you did, how would you be able to fix it, other than reinstalling?

reddit.com
u/AdCompetitive1256 — 1 day ago

Neural guitar amp with Pi Zero W

EDIT: The amplifier models are mini Gated Recurrent Unit (GRU), machine learning/trained models, same as WaveNet, LSTM, Conv1D that you find with NAM (Neural Amplifier Models). For mine, I did not use PyTorch, TensorFlow, RNNX, etc to train the models. Everything is written in old school C++ (C99)

Sorry for the high pitch whining background noise. Such is the build quality of a cheap $1 USB audio dongle that's been butchered for lower cost. Going with the Pi's native I2S controller would be the better choice for interfacing with a stereo CODEC to get a cleaner audio capture.

Wrote a simple CLI app for monitoring the CPU and for stress testing the realtime audio pipeline. I have ran it for 24/7 and I'm very happy with the result. Low latency, and without buffer overruns/underruns.

Can't say the same when trying it on Cortex A53 (Amlogic S905X) because Linux scheduler is bouncing things around between all CPU cores, causing random buffer overruns. I have tried setting CPU affinity, even isolating CPU core #3 just for my app, but only by choosing a buffer size of 1024 samples, the problem go away for good.

If anyone knows other tricks that can prevent it from happening without sacrificing low latency, I'm all ear! :)

But for now, I'm staying with the Pi Zero W.

u/AdCompetitive1256 — 6 days ago
▲ 9 r/esp32

Setup:

- 48kHz sample rate.

- 24 bit stereo CODEC, set to master.

- ESP32 S3 as slave.

- I2S protocol, 32 bit stereo, using the standard i2s driver instead of legacy i2s.

- esp_device_uac v1.2.3, configured as 16 bit stereo 2 in 2 out endpoints.

- tinyusb v0.17.2

- ESP IDF v5.3.5

Playback works great, but capture has an issue: host is seeing the signed PCM 16 bit audio samples as unsigned. However, despite the DAW live monitoring meter is pegged to max, the actual audio samples themselves are ok (as you can see in the video when I touched the tip of the jack plug), but not if recorded.

At first, I thought it's because of ASIO4ALL, so I tried waveIn and WASAPI as well. The behavior is consistent across all of them, even across different DAWs. I have not tried with ALSA Linux though.

I also thought maybe it was because uint8_t is being used as the buffer data type in the USB audio callbacks, so i changed the typedef to use void and removed the intentional uint8_t typecasting in usb_device_uac before it passes the buffer to tinyusb tud_audio_write, but this does not solve the issue at all. I'm really stumped and I can't figure out the solution, lol.

Perhaps someone can help me please take a look at the project files and point out where the mistake is? Thanks a bunch! :)

usb audio.zip (link expires in 1 week)

https://limewire.com/d/jBg4Q#ydJxOz1F5F

u/AdCompetitive1256 — 12 days ago