I've just reinvented remote-procedure-calls, strings, linked lists and
bunch of other stuff while writing the new standalone C implementation of
Ecasound Control Interface (ECI) (ugh, C, ugh ;)). But I think the work
was worth it. Next I'll demonstrate how to develop a simple app taking
advantage of both JACK and LADSPA (with real-time parameter control) with
a minimum amount of developer effort. If you are now wondering why I'm
writing about this, jump to (6). ;)
--
1. Requirements (for this specific example)
- jack-CVS installed and running
- Steve's plate reverb LADSPA plugin installed
- ecasound-CVS installed
--
2. The Application
--cut--
#include <ecasoundc.h>
int main(int argc, char *argv[])
{
eci_init();
/* create the chainsetup and one chain */
eci_command("cs-add jackdemo_chainsetup");
eci_command("c-add chain1");
/* add the audio inputs and outputs */
eci_command("ai-add foo.wav");
eci_command("ao-add jack_alsa,out");
/* add an LADSPA plate reverb */
eci_command("cop-add -el:plate,50,0.5,0.5");
/* select the 3rd param (wet/dry) for real-time control */
eci_command("copp-select 3");
/* connect the setup and start */
eci_command("cs-connect");
eci_command("start");
while(1) {
double curpos;
sleep(1);
/* fetch current play position */
eci_command("get-position");
curpos = eci_last_float();
if (curpos > 10.0) {
/* at pos=10sec, quit playing */
break;
}
else if (curpos > 5.0) {
/* at pos=5sec, set reverb length to 80% */
eci_command_float_arg("copp-set", 0.8);
}
}
eci_command("stop");
eci_command("cs-disconnect");
eci_cleanup();
return(0);
}
--cut--
---
3. Compiling
gcc -o jackdemo jackdemo.c -lecasoundc
---
4. Running
./jackdemo
---
5. Dependencies
--cut--
###| ~|$ ldd ./jackdemo
libc.so.6 => /lib/i686/libc.so.6 (0x42000000)
/lib/ld-linux.so.2 => /lib/ld-linux.so.2 (0x40000000)
###| ~|$ du -h jackdemo
52k jackdemo
###| ~|$ file jackdemo
jackdemo: ELF 32-bit LSB executable, Intel 80386, version 1, dynamically linked (uses shared libs), not stripped
--cut--
---
6. The Catch
The created binary, jackdemo, does not rely on any external libraries. No
dependency to ecasound libraries, JACK libraries, C++ runtime, threading
support... just the basic C runtime! In other words jackdemo does not
create depency-hells. ;)
...
PS Although the example looks simple, a lot happens underneath.
'foo.wav' is read using a double-buffering disk i/o subsystem.
If jackdemo is run with root privileges, all memory is locked
and realtime scheduling is used. In otherwords, jackdemo
takes advantage of all known tricks to achieve reliable
audio performance in Linux.
--
http://www.eca.cx
Audio software for Linux!
-----Original Message-----
> From: Likai Liu
> To: linux-audio-dev(a)music.columbia.edu
> Sent: 10/19/02 1:42 PM
> Subject: Re: [linux-audio-dev] soft synth as a plugin
>
> STEFFL, ERIK (SBCSI) wrote:
>
> >>erm, sorry, but why not use pointers
> >>
> > it's dangerous... null pointers, memory leaks etc. tendency is not to
> use
> >pointers unless absolutely neccessary...
> >
> References in C++ are just pointers in a sugared form. Actually they are
EVERYTHING in ALL computer languages is just sugar, all these languages
(the turing complete ones) are same, apart from syntactic sugar. so your
statement doesn't really say anything.
> the same thing in a slightly different syntax. There is no memory safety
>
> in C/C++, so you end up having the same risks no matter you use pointers
no you don't. just because it's still risky doesn't mean it is the SAME.
C++ is quite unsafe as far as memory management goes but certain practices
can lead to memory mismanagement much easier - one of the practices that can
help is using references instead of pointers.
when using references it's quite hard (=harder then when using pointers)
to:
free already free-ed memory
create NULL reference
have a memory leak
> or references. The difference of the performance probably lies in the
> fact that the compiler understands your code better with references,
> hence it can do better optimizations. My guess is that references are
> easier to optimize against because you don't do pointer arithmetics and
> pointer type-casting on references.
I don't believe there is performance difference. is there anything that
suggests there is?
erik
Hi,
I just heard that there's an alpha version of SuperCollider for Linux. Since I
haven't seen this news on this list it might be either because it hasn't been
on the list or that I overlooked it :)
You can download it here:
http://swiki.hfbk-hamburg.de:8888/MusicTechnology/422
(and with .tgz it seems a gzipped file, but it's just a tar!)
(Too bad I still can't test it myself because of lack of jack, or to be
precisely, ALSA...)
bye,
Kasper
>>indeed, for a plugin soft-synth, it would only ever make sense to write
>>it in c/c++ or assembler really, a question of speed. Are there really
>>people who seriously want to write a synth in aynthing else?
> OTOH, CLM is written in Lisp, (hence the name), and some modern Lisps
> (i.e. CMUCL) claim to be as fast as C for floats. So I suppose you could write DSP
> code in Lisp if you really wanted to.
I did some timing tests in cmucl and was amazed at the performance
it was getting -- it is close to C, but (sigh... there's always
a catch), you have to be extremely explicit about types, so
all that beautiful lisp code gets buried under type declarations.
At least the cmucl guys are making progress in this area.
In normal use, CLM "instruments" are translated into C and
run as foreign functions (so all the DSP stuff is happening
at C speeds), and lisp provides an interactive environment
to work in (the "listener").
So, yes it is perfectly possible to do real-time synthesis
while writing the DSP-related code in Lisp/Scheme; there are
examples in both CLM and Snd.
>
>It builds fine with gcc3 after a bit of auto* hackery (ran ./ltconfig
>ltmain.sh, automake -a), but there is no UI yet, so you can't see what
>you're doing.
>
I am not so lucky yet... anyway i saw that SC does use both C++ and ObjC.
I thought its not possible to mix them with gcc. Would be realy cool if
that has been fixed with gcc3.
- Stefan
_________________________________________________________________
Broadband? Dial-up? Get reliable MSN Internet Access.
http://resourcecenter.msn.com/access/plans/default.asp
> > >The occasionaly discussed jack session
> > > saving gizmo would be a knock dead feature.
> >
> > And any offering to the general public that doesn't contain this feature
> > will probably end up just plain dead. Be patient.
>
>
> I'm not a patient man ;)
I didn't mean you. I meant that anyone interested in announcing linux
audio to the world should wait until this level of functionality is
present. I'm not suggesting that anyone delay development of the gizmo.
The closest thing that I have used is OMS on the mac. It's quite
different than a jack environment but it does allow me to save synth
midi routings and send/receive channels, and provides synth names to
midi apps so I can refer to them directly in my sequencer app.
Tom
>
>are different versions of gcc3 ABI - compatible?
>
AFAIK all versions of gcc3 except version 3.0 which had a bug are
compatible.
- Stefan
_________________________________________________________________
Surf the Web without missing calls! Get MSN Broadband.
http://resourcecenter.msn.com/access/plans/freeactivation.asp
>On Fri, Oct 18, 2002 at 06:47:15 +0000, Stefan Nitschke wrote:
> > -O3 with C is broken, i got an endless loop!
>
>What gcc version? What flags did you use with C?
>
I used gcc 3.2 that comes with SuSE 8.1.
Today i changed the initial values to a=0.5; b=0.0000001; x=0.1; and now
-O3 works!?? Here are the results:
C: -O3 -march=pentium
user 0m11.380s
C++: -O3 -march=pentium
user 0m11.960s
BTW to my surprise today i was able to use ardour without freezing my
machine
as it always did last week. I didnt changed the system and used the same
binaries.
I never saw such a random problem on a linux box before.
>The test I did had the C code using a struct, and I used the . syntax for
>c++ method calls FWIW. I'l dig out the code in a min.
>
>I think it was loop unrolling that was crappy in c++.
>
That would be a bad thing.
- Stefan
_________________________________________________________________
Broadband? Dial-up? Get reliable MSN Internet Access.
http://resourcecenter.msn.com/access/plans/default.asp
> Things like jack have to be graphically wrappered or hidden too, no
> scrolling text windows of xruns. The occasionaly discussed jack session
> saving gizmo would be a knock dead feature.
And any offering to the general public that doesn't contain this feature
will probably end up just plain dead. Be patient.
Tom
>
>erm, sorry, but why not use pointers?
>
Just out of couriosity i made a benchmark test between C and C++ with
gcc3. I dont have a clue abour x86 assembler so i made a measurement.
Here is the C code (not realy useful as real code would have a need for a
struct and a pointer operation to call the filter() function) and the
C++ code.
Both "simulate" a low pass filter and are compiled with:
gcc -O2 -march=pentium -o filter filter.xx
-O3 with C is broken, i got an endless loop!
---------
double x1,y1,a,b;
const double filter(const double x)
{
register double y;
y = a*(x + x1) - b*y1;
x1 = x;
y1 = y;
return y;
}
int main()
{
double x=1;
int i;
x1 = y1 = 0;
a = b = 0.5;
for (i=0; i<1000000000; ++i) {
x = filter(x);
}
}
---------
class LowPass {
public:
LowPass() { x1 = y1 = 0; a = b = 0.5; };
~LowPass() {};
const double filter(const double x);
private:
double x1,y1,a,b;
};
inline const double LowPass::filter(const double x)
{
register double y;
y = a*(x + x1) - b*y1;
x1 = x;
y1 = y;
return y;
}
int main()
{
//LowPass* LP = new LowPass();
LowPass LP;
double x=1;
for (int i=0; i<1000000000; ++i) {
//x = LP->filter(x);
x = LP.filter(x);
}
}
---------
The results on my AthlonXP machine are:
C++ with member:
real 0m11.847s
user 0m11.850s
sys 0m0.000s
C++ with new() and pointer:
real 0m12.337s
user 0m12.330s
sys 0m0.000s
C:
real 0m16.673s
user 0m16.670s
sys 0m0.000s
Well, i will stay with pointer less C++ :-)
- Stefan
_________________________________________________________________
Surf the Web without missing calls! Get MSN Broadband.
http://resourcecenter.msn.com/access/plans/freeactivation.asp