Showing posts with label realtime. Show all posts
Showing posts with label realtime. Show all posts

Saturday, June 22, 2013

Real time audio programming languages

Introduction

Over the last couple of years I've written various real-time audio programs. Its difficult to adhere to real-time regulations: you've got to get threading and memory management right.

C++ is the often concidered the obvious choice language for large real-time audio programs: its a compiled language, and is deterministic in time if used carefully. This is necessary for real time (RT) work, and rules out VM based languages like Python for any low-latency work.

In C++ there's many a way to achieve real-time, one of which I have detailed here: https://github.com/harryhaaren/fypRealtimeCppPrograming

Other languages

C++ is one way to go, but in recent times there are various other programming languages which are becoming increasingly attractive to the real-time audio programmer. Particularly these two languages have caught my eye recently:

Rust : http://www.rust-lang.org
Iolanguage: http://iolanguage.org

Both of these languages have certain characteristics which make them possible candidates for RT programming.

Rust

Language Overview

Rust is a language that focuses on "blocks", using boundaries. Integrity, availability and concurrency are its main goals. It uses lightweight tasks with message passing for concurrency, no shared memory.

The Interesting Stuff

I'm most intrigued by the memory management of the language: everything is static unless declared "mut" (or "mutable"), and ownership of objects is very strict. This means that managing resources in a real-time safe way is well defined, and hence the code will be maintainable.

Three different "pointer" types exist, as well as new concepts like owned boxes and managed boxes... these new concepts may aid memory allocation troubles, but perhaps it complicates them too, I don't have much experience yet with it, so only time will tell...

Learning It

Most of what I know comes straight from their homepage or tutorial:
Homepage: www.rust-lang.org
Tutorial: http://static.rust-lang.org/doc/0.6/tutorial.html

 

Conclusion

A cool language, and if the memory concepts prove useful, it could be an awesome new language to learn for the audio-programming enthusiast.

 

IOlanguage

Language Overview

This is a smalltalk inspired language, while also incorporating various different elements from other languages together. Actors based concurrency is used (a la Act1), while it is also kept small for embeddable purposes. Runs in a small VM.

The Interesting Stuff

Intensive inspecting of object instances / program state (like LISP) aids debugging significantly. Extensive concurrency possibilities: co-routines, actors, futures and yield statements allow for flexible "time" programming.

 

Learning It

Extensive documentation and example code here:
http://iolanguage.org/scm/io/docs/IoGuide.html#Introduction

Conclusion

Cool language, unfortunately probably not fully real-time safe / deterministic due to running in a VM.

Sum Up

"So what language will I use for my next project?" I hear you ask: well I'm staying with the tried and tested C++ for a while. I've dabbled with Vala previously ( see ValaLooper and Prehear ), but they're not quite suitable to RT work in my opinion.

Although its nice to work with a slightly higher level language, its hard to determine if the generated code is genuinely real-time safe.

The perfect real-time safe code for me is code that is so simple, that proving its real-time safe under any conditions is trivial. Then the code is maintainable and readable.

Know of any RT capable language I've left out? Get in touch: I'm interested in hearing about it!

Wednesday, May 2, 2012

Luppp milestone: Timestretch!

Although its been a relatively quite period for development (due to lots of deadlines) today one of Luppp's long term goals has been reached: on-the-fly time stretching per track.

For the non-techie: This means that you can play a melody loop, and slow it down or speed it up, and the audio will remain in the same key! (No turntable RPM effect? Nope :)

Mandatory examples:

Although I'd call the quality "passable" is obviously not fantastic but there's some parameters in the algorithm that are available to tweak, so I hope to be able to improve it a bit a least :)

So when is a beta release?? Don't hold your breath, sorry. There's still some work to be done before Luppp will be ready for prime-time, but until then feel free to test it if you're interested!

Will keep you posted, -Harry

Saturday, December 17, 2011

Arch Linux : The quest for a minimal system with maximal RT performance

Hey All,

My install of TangoStudio is getting old, and its repos are getting polluted with conflicts & nastiness, that means a reinstall! So a quick bit of searching for a minimal yet configurable, RT capable and rock-solid led to some intresting distro choices.

TangoStudio - Worked well enough ( 30ms lowest lat on stock kernel )
64Studio - a touch oudated by now, but it was always very good
Pure::Dyne - personal favorite for a while, also gone a touch out of date
Gentoo - probably not good for a non-kernel hacker type... but then



Arch has been a distro I've tried a couple of times because I love the sound of it:
Arch Linux, a lightweight and flexible Linux® distribution that tries to Keep It Simple.
However any time I tried it I had been put off by its "initial configuration" that needs doing before you can get yourself online to look at some forums / wiki's for help!

So off I went, download the 380mb ISO, install it on a seperate partition, get going. You get a minimal system that drops to a root prompt on install, and "startx" isn't going to help much untill you install you video driver packages etc. Note this can be done during install but I opted not to, as I wanted the control to select only needed packages.

So after a bit of haggling with the X server, reading some wiki entries using the text only webbroswer links, and installing the "slim" display manager, messing with /etc/inittab and ~/.xinitrc there's a system up and running, straight to a graphical logic screen (with awesome "darch-white" theme") and then to a barebones LXDE desktop with OpenBox as WM.

The speed of the menu's & actions in unreal, it feels like its there before you clicked. Some small issues with ugly themes and nasty font's were quickly ironed out using lxapperance.

Couple of "nasty" little things:
-Hotkeys: https://wiki.archlinux.org/index.php/Xbindkeys
-Keymap: https://wiki.archlinux.org/index.php/loadkeys
-Touchpad: https://wiki.archlinux.org/index.php/Touchpad

Then on to the audio side of things:
There's a project called ArchAudio, who are maintaining lots of up to date software for audio / multimedia purposes, you'll want to install that repo:
http://archaudio.org/packages/ has all the info you'll need!

I'm a JACK1 user, so first thing I wanted to do was install that:
the "Extra" repository has a build of 0.121.3, so a simple pacman -S extra/jack1 done the trick. FFADO installation for my Echo AudioFire was quick and painless: pacman -S libffado That installs your needed library, the ffado-mixer, ffado-test etc programs, and sets up the privelidges so that you can run JACK in RT mode.

If you want to use this install as your "daily", you'll need to install a mountain of stuff, things like gtkmm,flashplayers, media players, codecs, etc. But if you want to run audio... no need. Actually you'd be better off without that stuff.

The end result:
A system that will run JACK @ 4ms latency, 192kHz samplerate, with a *non-RT* kernel. That's currently still compiling, and I'm hoping to squeeze another ms or 2 off the RT_PREEMPT & IRQ tuning (& IRQ threading.. but that's dangerous territory AFAIK!)

So far I'm very satisfied with Arch and its amazing documentation :)
Will keep this up to date with the RT kernel progress & latency tuning,
-Harry