Using Csound as a c/c++ library

Dear Csounders!

(How) Is it possible to use Csound as a library in a c/c++ application?

If i.e. we want to make some simple c/c++ application where we would like to filter or generate something, is it possible to benefit from well written c-algorithms from csound src code and then use them directly without making a .csd design?

It’s quite straightforward. Check out the examples here:

There are example visual studio and xcode projects there that will link to Csound if it has been installed in the standard directories.

Hi @rory! Thanks for your reply but I think I wasn’t clear enough as I posted the question.

So when using Csound API the basic principle, if I understand it correctly, is something like this; you make your csound design and then you make an object, compile it and then you interact with it using API. But what I mean is, is it possible to use only csound algorithms without creating an csound design?

I.e. csound/pffft.h at master · csound/csound · GitHub is an excellent example of ‘stand-alone’ algorithm that I can include in c/c++ app if I need to make just a fft on some data that I have. Here I don’t need an csd design, just some buffers :smiley:

Now, I’ve looked (briefly I must admit) over some of the csound src code and so far I’ve seen only functions/algorithms that require Csound object as an input parameter like i.e. csound/circularbuffer.c at master · csound/csound · GitHub and many others similarly.

Is there a way to overcome this some ‘hack’ or workaround?

Sorry, you’re right, I read your post too quickly!

@stevenyi once did some work on a framework that would let you call Csound opcodes directly from your C++ applications. That’s pregnant with looking at.

Of course you are free to use any of the Csound source code as long as you respect the license. But I’m not sure how easy it might be to use chunks of Csound source in your own applications.

1 Like

Is that framework from @stevenyi open somewhere?

The original paper is at: https://www.cs.cmu.edu/~rbd/papers/Extending-Aura-ICMC-SMC-2014.pdf. I think the code may still be found in the Aura repository but would need to look. The plan was to use it as a new UGEN API in Csound7 but that hasn’t been done yet. I have heard this work was used in another project but wasn’t made public, but I heard it was still easy enough to modify and repurpose. Let me know if you have any questions.

Thanks @stevenyi. Aura looks very interesting!

I’ve looked on github for Aura repository but didn’t find anything, could you post here a link to it?

I’m still relatively new to Csound but it is an extremely cool language and having an option to use its opcodes directly in c++ app would give it a whole new usage dimension :slight_smile:

Take a look at: https://sourceforge.net/projects/aurart/

1 Like

Using opcodes directly from c (or c++) is possible but you still need a CSOUND * instance since opcodes need access to it for any interaction with the system (allocating memory, printing messages, etc). It is not trivial to do. If you want to look at a working version of this approach you can take a look at the code of “poly” (https://github.com/csound-plugins/csound-plugins/blob/master/src/poly/src/poly.c). Within this opcode we run another opcode a given number of times. The poly opcode allocates/frees all memory for the wrapped opcode and calls its init and perf functions as needed, in fact doing exactly what csound itself does.

1 Like