Since the version 5 of
csound, a rich API has been developed for use by many languages (C++, python, java, lua...). The csound developers have done a great job, and has made possible to build really sophisticated application that embeds the csound engine.
HPKComposer is based on that capability. I wanted a common paradigm for controlling the evolution of both visual and audio parameters. This paradigm is the use of looped linear segments: it is simple and different cycle durations provide an ever changing result. Csound has an opcode for doing that (loopseg) and that is fine: as sound parameters must be refreshed at a much higher rate than the graphical one, the audio engine must drive the graphical world. This is made possible by another csound 5 feature: the software bus and the capability to export a global variable as a channel of the bus. This global variable can be read by the host program using the csound API, and this is how the loopseg values are passed to HPKComposer for controlling the graphical evolution.
Thus HPKComposer real time performance program is a java program using two threads:
- the master thread is controlling all the image processing and read the values generated by the csound engine
- the secondary thread, created by the master thread, run the csound engine
This is working nicely, very stable and smooth.
Another interesting feature of the csound API is the possibility to advance the csound execution engine for a precise amount of samples. It is perfect for writing image buffer to disk: the csound thread run the audio engine for the number of samples required for a video frame, the main thread read the loopseg values, calculate the image and draw it to disk. This is how I produce the sequence of images that VirtualDub will transform in a video.