Monday, December 19, 2011

Tutorial: Load & Loop Samples

Hey all,

This tutorial will show you how to load a sample into memory, and then play it back trough a JACK port, continually looping. There's not really that much to it, just a bit of thinking of the order things happen, and arrays.

If you've read the "Writing a sample" tutorial, you'll already be familiar with LibSndFile, the library we use to read / write samples, so there's nothing too hard to handle :)

Check out the source here: https://github.com/harryhaaren/Linux-Audio-Programming-Documentation/blob/master/loopedSample/loopedSample.cpp

Any queries / suggestions, you know how to get to me :) -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

Wednesday, November 16, 2011

Tutorial: JACK Ringbuffers

Hey All,

A quick tutorial on basic Jack ringbuffer usage. Ringbuffers are an easy way to exchange data from one thread to another in a realtime safe way. This means that no thread will block when reading or writing, and hence you use ringbuffers in a real-time thread.

For this tutorial I'll be using the "standard" linux audio ringbuffer that comes with JACK. Its docs are available here: http://jackaudio.org/files/docs/html/ringbuffer_8h.html

So what were going to do is:
1. Setup a ring buffer
2. Register a JACK client, and give it a process callback
3. Write data in the "local" thread, ie: our main()
4. Make JACK print out any data it recieves in its RT thread

Note that here the JACK thread is our READ thread , and the main() thread is the WRITE thread. This is important, because a ringbuffer like the JACK one will only work in ONE direction.

Find the well commented source here: https://sites.google.com/site/harryhaaren/Home/main.cpp

Note the compile command is: g++ main.cpp `pkg-config --cflags --libs jack` (its also in the source.. but just to make sure :)

Responses welcome, -Harry

PS: Note there are many different implementations of ringbuffers, all with benefits of their own. The JACK ringbuffer is a simple and IMO easily usable one, and that's the reason I like it. I don't want a fancy impossible multi-read multi-write templated 13 class derived special oval ringbuffer, just something that does what it says on the tin :)

Wednesday, September 21, 2011

Luppp : 30,000 loc

Somewhere yesterday Luppp passed the 30 k lines mark, currently on 30, 255. There's been quite some UI work going on, as well as some (essential) features being implemented in the engine... full update soon :)

Monday, September 5, 2011

Project Piano


A couple of days ago a piano popped up on Adverts.ie, "free to take away". Since I've been wanting to try my hand at some piano tuning without detuing a piano playable, this was the opportunity to get cracking with that. So we picked up the piano from Clonmel, Co. Tipp on Sunday, and took it back home.


After a bit of googling and checking websites I found one that had all the Broadwood serial numbers, and I checked up what its approximate build year was: 1907. That makes her 104 years old :) It seems that the convent in Clonmel bought the piano new, and used it there until they were recently donated new Roland digital pianos, hence this was being thrown out. Some kind folks took it home instead of letting it be thrown in the skip, and they popped it up on adverts which took her to Co Clare.

Everybody that tuned the piano seems to have signed a key: perhaps this is a trait like a mechanic marking when the timing-belt has been done ;)


Today was spent just cleaning it up a bit: there was quite some dust, some spiders, spiderwebs etc, that's all gone. Next up was to take off the action, and the remove the keys.


Each key got a good cleaning with some ivory-friendly cleaning agent, and was then allowed dry off.
Got a good look at the case under the keys didn't show any signs of the wood being worn, so there isn't any need for structural woodworking. Delighted: restoring the action case would have been quite some work.

Then to putting the keys back on, and making them all sit right. A couple of the keys action wasn't smooth enough to lift the key once the hammer's pressure was on it, so some of the pins were bent back into place, a coulpe of others needed a bit of a twist to make it fit.


Once all back in place, it was time to get the tuning gear, and get going. By then end of the day the A's and G's were pretty ok.. even though when I'm next at it, it will probably have sagged enough to not notice much.

That's all for now!

Sunday, August 21, 2011

Luppp: Progress, demo song & video

Hey,

The past while has seen quite some work being done, on various parts that needed attention: the UI, some internal effects & support for instruments, and better LV2 support. Also there's a "scene" thing come into play...

UI wise there's a mechanism in place that will "Osc Blob" send the nessisary information from the Engine, and it plots the wave shape on screen.

For instruments & effects we can now load PureData patches, and communicate with them using the JACK MIDI port. There isn't a lot of "routing" available, its all hard coded CC values at the moment, but that's on a todo list somewhere...

The Lv2 side of things has seen some changes, like a system whereby the Engine dynamically updates the UI of which plugin is loaded where, as well as where it can find the binary files to instantiate the corresponding plugin UI.

Finally the "Scene" thing, basically its a way to organize a song or structure audio clips into groupings that can be played back simultaneously.


So here we have a blank session with 5 "tracks" or "loopers", each track complete with plugin slots, solo mute buttons, a pitch slider (left), and a volume slider (right) and 2D ambisonic panner.

In the scene selector we see each buffer is currently green (play mode, not queued to change). Clicking on the Looper (purple thingy up top) will start recording to that buffer from the JACK audio input. A right-click -> load will let you load a sample into that buffer.


During the loading process (in a non-realtime thread :) the buffer is automatically time-stretched to match the current playback speed to seamlessly loop. All buffers that are recorded using JACK are automatically quantized to the current playback speed, so it all stays in sync.

Up in the top you'll see the new "Global Scene" entrybox, typing a number there will trigger all the buffers to start playing the scene ID that you type in. Some work needs to be done there to make that more user freindly, but for now it provides access to scene changes in a semi-useable way.

Luppp Session 1: Dubstep-y drum N bass-ish track
Note the heavy synth is a PureData patch, the drums were loaded from samples, and the Synth is recorded from the XV-3080 using the JACK audio input. Global scenes are used to switch between the different parts of the song.
video

Here a screencast of the "Global Scene" feature, and some of the Lv2 features. Excuse the rubbish quality, I'm only getting used to exporting from OpenShot at the moment :)

That's all for now, till next time
-Harry

Wednesday, August 17, 2011

Ambisonics & Linux, resources & quick toots

Hey,

I've recently been asked how I do Ambisonics on Linux using open-source tools, so here's a very quick rundown of how it all works:
  1. Get a linux install, preferably "AVLinux" or "TangoStudio". I have experience with both of those and know they work well, and I'm not telling you to abandon your distro of choice here, just for people who are wondering what distro to choose for a new install
  2. Run "sudo apt get install jackd ardour2 amb-plugins" in a terminal to grab the big programs your going to need (if you don't have them already)
  3.  Go to http://kokkinizita.linuxaudio.org/linuxaudio/downloads/index.html
  4.  Download clthreads, clxclient, and ambdec. Perhaps also get the ambdec manual..
  5. Build the 3 just downloaded bits of software, in the following order: cltreads, clxclient, then ambdec. Ambdec needs the other libraries on your system to compile! It should be easy after that & there should be a readme / install file, but just in case:
    1. extract the contents
    2. cd to the new folder (with extracted contents in it)
    3. open a terminal and type "make" & hit enter
    4. now do "sudo make install"
  6. Software is ready, so now read this: http://ardour.org/node/2804
  7. Give it a go
Any questions about the setup feel free to get in touch :)
-Harry

Thursday, June 23, 2011

Luppp: Midi Mapping

Hi,

Today was a productive day, Luppp can now take a MIDI CC, and map it to almost parameter you'd care to mention. Currently if an unknown MIDI CC comes in, it auto-maps that to the last used parameter, but I want to create a nice interface that allows one to change the mappings manually, and of course create presets & such.

No screenshot, its functionality that you'll find in the engine! Perhaps a little demo clip at one point.. who knows. Later!

Tuesday, June 7, 2011

Luppp: 20,000 loc Lv2 support & a CSound display

Hey hey,

20,000 lines of code, some LV2 support, and the beginnings of a CSound haul-over.
For now a quick post, with the mandatory screenshots, later some more info on how its intended to support some of the (fancy) LV2 features like the instance access, and some others :)






Embedding LV2 gui's into the Luppp ui. Pop out windows will be supported too at some point :)
And a CSound text editor based on Gtk Source View, a csound.lang file must be created to syntax highlight all the opcodes & that


Till next! -Harry

Wednesday, May 25, 2011

Lv2: New host lib, lilv, a newbies guid to LV2

Hey All,

Ever tried to get your head around the Lv2 spec? Me too, and if one isn't used to the "lingo" of URI's, RDF's, and various other path etc it can all be a bit daunting. Yet some of the coolest and best plugins (check: this Parametric EQ, or this IR reverb) are on the Lv2 standard, so you really do want to support them...

If you wanna get your hands dirty, skip down to the bulletpoints, that's what you'll need to do to get started!

With this new library from David Robillard writing hosts to use these plugins should become easier & faster. The library I'm talking about here is of course Lilv. It depends on two of Robillards other libraries, namely Serd & Sord.

Serd handles the reading & writing of RDF data, as well as Turtle & NTriples. Don't worry, I don't know what they are either. Perhaps in the future I'll try understand them...
Sord is a library for storing RDF data in memory... apparently we'll need that!?

Getting Started:
Create a folder somewhere where's your gonna do all this stuff.

Grab all of the following:
http://download.drobilla.net/lilv-0.4.0.tar.bz2
http://download.drobilla.net/sord-0.4.0.tar.bz2
http://download.drobilla.net/serd-0.4.0.tar.bz2

Ensure these are installed:
lv2core

Untar the lot of those .tar.bz2's from drobilla, and cd into the serd-0.4.0 dir.
./waf configure
./waf
sudo ./waf install

cd into the sord-0.4.0 dir,
./waf configure
./waf
sudo ./waf install

then cd into lilv-0.4.0
./waf configure

This shouldn't give any problems, as we've just installed the 2 dependencies you probably didn't have. If JACK or any other common issues arise, just fix them.

If you get the following errors:
Checking for header lv2/lv2plug.in/ns/lv2core/lv2.h : no
Checking for header lv2/lv2plug.in/ns/ext/event/event.h : no
Checking for header lv2/lv2plug.in/ns/ext/event/event-helpers.h : no
Checking for header lv2/lv2plug.in/ns/ext/uri-map/uri-map.h : no

Then this is what you do:
1. Direct your browser to http://lv2plug.in/spec/
2. Grab lv2core,lv2-event, and lv2-uri-map.
3. Untar lv2core, ./waf configure, ./waf, ./waf install it (the first one should be fixed now)
4. Run "lv2config", this creates some symlinks around to headers
5. Bop open a terminal, cd /usr/include/lv2/lv2plug.in/ns/
6. sudo mkdir ext
7. Copy the event folder into ext, and copy the uri-map folder in too.
8. *CHECK THE DIRECTORY STRUCTURE!!!* the output of ./waf configure tells you *exactly* where its looking for the files, *PUT THEM THERE*. Can't stress this enough. Use your brain & figure out what's not where its meant to be

./waf configure should print out yes yes yes yes yes yes to all dependencies now, so
./waf build,

Only if *building* fails, ie: ./waf fails like so:
[28/36] c: utils/lv2jack.c -> build/utils/lv2jack.c.7.o
In file included from ../utils/lv2jack.c:29:0:
/usr/include/lv2/lv2plug.in/ns/ext/event/event-helpers.h:28:52: fatal error: lv2/http/lv2plug.in/ns/ext/event/event.h: No such file or directory
compilation terminated.

Get to your favorite text editor, and sudo up the cow powers, because we've got a header to edit.
1. sudo /usr/include/lv2/lv2plug.in/ns/ext/event/event-helpers.h
2. Go to line 28. its contents should be: #include "lv2/http/lv2plug.in/ns/ext/event/event.h"
3. Change those contents to "#include "lv2/lv2plug.in/ns/ext/event/event.h"
4. ./waf build again.

Edit: The author of the event extension is planning a release to fix this issue.

and then sudo ./waf install the whole thing.

Boom! You've got lilv running.
Check the lilv-0.4.0/utils directory for some examples of using the library.
If you've built lilv, then in /build/utils there are the binaries of the examples. Run them while looking at the source, understand what to do.

In the /bindings/python dir there are 2 files, lv2_list.py & lv2_apply.py
They might provide some insight into the steps nessiary to get Lv2 plugins instantiated and in a good mood to work... :D

Finally a huge thanks to all the members of LAD who have developed this awesome standard, awesome plugins, and last but not least, awesome hosts! :D
Cheers, -Harry

Tuesday, May 24, 2011

Luppp: Stage 4

Sup!

Today Luppp got a SoundStretch class, its based on the LGPL library SoundTouch, and provides independant time or pitch scaling. That's pretty awesome :) Bind yer MIDI controller, and you can control the pitch of your loop... for drums its great to get some extra Oomp outta the kick.

The BPMDetect interface from SoundTouch isn't being employed yet, but it won't be long. Also the loading of sample files will be transfered from Looper & Sampler to FileLoader. In there will be the BPM detector, and automatic scaling of BPM of loops to the current BPM, then pushing it into the ResourceHolder buffer.

Also news: wierd ported LADSPA plugins won't crash the system anymore, and the stereo plugins still work on the mono channels, just using the Left ins & outs. A LADSPA GUI has been worked on, just a small dial that displays the value of a controller, but it needs a good rework before its useable.




A LoadSaveBase class is in order, that will be the parent of any class instance that wants to save / load data between sessions. (That's just about every instance... :) All in the pipe!
Till next, -Harry

Edit: Almost forgot, it also sends MIDI CLOCK now, so you can sync your LFO's on external synths to JACK transport :D

Wednesday, May 11, 2011

Luppp: Stage 3

Hey All,

Got some great news... there was a nasty stupid bug in the GUI redraw of the waveforms, (which I mistakenly though was due to threading) but it turns out the code was entering a loop with an increment that evaluated to zero... But its fixed now! :)

So with the GUI up and running one can see how far along the loops are, and what "amount" of the loop is going to be played.. ie "zooming" in on the part of the loop that's active.

Also the engine has been getting some attention during the Linux Audio Conference, held in Maynooth this year! This means that initial CSound support exists, so effects & instruments can be coded up in CSound to be played live as if its an internal synth / effects box. Lots of new possibilites now, and due to the csound .csd files being text based, they will be real easy to share & merge, allowing all users to contribue & share presets for effects with eachother.. :)

Mandatory screenshot:

Till next! -Harry

Friday, April 8, 2011

AVBin : Your favorite interface to Audio & Video

Hey,

Today I spent some time trying to work out the best way to load AV streams (ie: .avi, .vob, .mp3 etc) files into me program. So there are a nice 100 or so ways to do this with different libraries. But what's LGPL and usable? There's a good question.

After a good bit of googling around I found FFMpeg, LibAVCodec, LibAVFormat, LibAVFilter etc... all hard to link to, seperate fast-moving API's and breaking ABI's... nightmare.

In comes LibAVBin, a "thin wrapper" around all the above libraries, and abstracts away the details. Still getting the example to work is a little messy, so heres my own experience with it as of 09-04-11.

Grab the source here: http://code.google.com/p/avbin/

Then read the readme, and hit the SVN command to grab the latest FFMpeg.

./build.sh the library, there's a couple of errors in main, cast "malloc" to (void*), and fix whatever else is needed... I forget!

Then grab: http://code.google.com/p/avbin/source/browse/trunk/example/avbin_dump.c

That's the basic code for analysing a file's media content. From there it should be easy enough to see what's needed. The top of the header file has a nice "tutorial" on what functions need to be called in what order. I'm sure you'll work it out. Any questions, fire away!

Cheers, -Harry

Thursday, April 7, 2011

Exams looming, projects due

Hey,

It's the exam time of year again, so Luppp has been laid to rest for a while, only to (hopefully) be revived once may 12th comes... Many projects due, much work to be doing.

Some small adjustments have been made to the source in the last weeks, but no real new features were implemented, although there is a bit of "conceptual" work going on. A Fluidsynth Soundfont player should be quite easy to integrate, as well as a wavetable synthesiser..

Then some sequencing tools and songs can be created... :-) Well ok, there's a lot of "load/save" stuff still to go on, and some theoretical threading jumble to be sorted out before that day. Lucky there's no deadlines here!

Cheers, -Harry

Tuesday, March 22, 2011

Luppp: Slow Steady Progress

Hey,

Not that much new fancy graphics or anything to show off today. Just that the internal audio / midi code is getting a needed clean-up and haul-over. Also some hard-coded MIDI mappings are in place, currently thinking about how to best implement the binding of the controls...

Some more engine class placement needs to be done before its all sorted out and neat, that's the main work. Its things like transfering ownership of audio buffers to the ResourceHolder class as opposed to each buffer being owned by a seperate "player" class, and no FX or other classes being able to use that buffer.

There should be a noticable performance gain once the changes are in place, as it rips out lots of unneeded signals & slots, and replaces them with a pointerToObject - > doIt () call. Sweet.

Also I've been messing with it recently, here's a little clip of a drum beat (.wav loop) and 3 layers of guitar + some live soloing going on:
LupppGuitarJam by HarryHaaren

Patiently waiting to get MIDI looping in place... :-) -Harry

Sunday, February 27, 2011

Luppp: Update Ambisonic... :-)

Hey,

Over the last week I've been implementing ambisonic support in Luppp. It didn't add up to too much work, only that JACK ports had to be named differently, the signal path adjusted somewhat (1 input, 3 outputs rather than 2 ins ,2 outs.

At the moment 2D horizontal B-Format ambisonic is supported, but implementing the 3D dimension of the first order wouldn't be too much work.. (add another channel to the process() functions.. )



The pan widget got a little haul over just to support 2D's rather than the one...


Till next, -Harry

Sunday, February 20, 2011

Luppp: Update Automation

Sup,

Productivity of today: Automation. Although the widget was already done, and the hard code in place, making it actually effect the parameters in the engine was a little tricky. It now communicates with itself internally (rather than the CPU expensive OSC beforehand). I've had lots of automation tracks running concurrently and there's no problems with performance that I can see. :-)



Here we have a couple of lines, unfortunaly I didn't record the output of Luppp while it was playing the lines, would have been nice...









Also created in the last weeks, a primitive MIDI editor... Clicky in notes, the engine plays them back (sample accurate... :-)

Currently not much can be done bar insert & clear notes. But with a bit of time that will all change...




Also new: Rather than  1 - 2 - 3 - 4 on the screen, I've opted for 4 circles to appear, each a different colour for each bar. Its as easy to follow and a bit more cheerful!

Bottom left of the screenshots there's a "Stop" & "Play" button, which make jack transport start / stop. Useful to not have to switch to QJackCtl everytime.

Till next, -Harry

Thursday, February 3, 2011

Luppp: Update Waveform

Hey,

Today a "ResourceHolder" was implemented, it takes all buffers / MIDI / automation data, and stores it. Nothing else. But it means there's a centralized place from which both the GUI & the engine can access the data, and allows much easier plotting of data on screen... See attached:


So there's 3 piano wavs on the top 3 loopers, some drum & bass drums on strip 3. Breaks & noises on 4, leaves some synths on 5  :-)



All in all... happy that this got done, no clean solution came to mind since the last update, so its had been while in the pipeline.
Till next, -Harry

Sunday, January 16, 2011

Luppp : Update Funky

Hey,

Its a special day: 10,000+ lines.

Lots of work been done: UI got a real haul over, but under the bonnet there's a structure for automating data, and some initial multi-threading is going on to keep the RT thread doing what its supposed to!

The following shots nicely show off the funky new UI:



"Loopers", each one will* represent an audio loop, and provide some nice effects like reversing a part of the loop, swapping parts around & beat-grinding...







I've only 2 hands so automation is essential: take it away! Any parameter can be controlled via OSC! Working on an implementation of MIDI LEARN, to open access to every MIDI thing out there







Finally (& most funky): The mixer.

Needs a little overhaul to not look your tripping, but basic features are there, the big orange is the fader, red-green-blue is a 3 band eq, under it the black line shows PAN (all 0 in shot).




Will post back when that 60's look is gone, -Harry

Wednesday, January 5, 2011

Luppp: Getting there

Hey all,

Serious progress going on! Audio input can be recorded (in time with the timebase) played back at a certain bpm (in sync with other files at the same bpm) effects can be applied to the signal stream (LADSPA only for now), and the resulting signals can be mixed with logarithmic faders, and finally the peak meters show you your levels ;-)


As you can see: there's a shiny "Add Track" button at the top of the screen, dynamically adds tracks to infinity...

The number in the left of the "track" widgets is its OSC ID, you'll need it to do things to that track!

The smaller numbers show how many beats there are in the loaded sample, and how many have elapsed.

The record button is there so you can enable.. duh


The orange faders give volume control (with a log scale of x^3, feels nice with a MIDI controller ;-)  Then the master output levels, and then the HUGE number to tell you what beat your on!

Next features: PFL on each mixer track, master faders, PFL faders, busses (sends), GUI interface to LADSPA effects (engine done :-)

Also needed: Some threading to allow RT thread not have to load / write audio samples, send large OSC messages etc. Working on it!

Cheers, till next! -Harry