# Using Csound as a c/c++ library

**URL:** <https://forum.csound.com/t/using-csound-as-a-c-c-library/845>\
**Category:** Developers\
**Created:** [September 30, 2022, 10:35am UTC](https://forum.csound.com/t/using-csound-as-a-c-c-library/845 "2022-09-30T10:35:58Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Lovre](https://forum.csound.com/letter_avatar_proxy/v4/letter/l/bbce88/32.png) [@Lovre](https://forum.csound.com/u/Lovre)\
**Post date:** [September 30, 2022, 10:35am UTC](https://forum.csound.com/t/using-csound-as-a-c-c-library/845/1 "2022-09-30T10:35:58Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![rory](https://forum.csound.com/user_avatar/forum.csound.com/rory/32/7_2.png) [@rory](https://forum.csound.com/u/rory)\
**Post date:** [September 30, 2022, 11:08am UTC](https://forum.csound.com/t/using-csound-as-a-c-c-library/845/2 "2022-09-30T11:08:02Z")

</div>

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

> **[GitHub - csound/csoundAPI\_examples: Examples for learning the Csound API from...](https://github.com/csound/csoundAPI_examples)**
>
> Examples for learning the Csound API from various languages - GitHub - csound/csoundAPI\_examples: Examples for learning the Csound API from various languages

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

---

<div class="post-metadata">

**Author:** ![Lovre](https://forum.csound.com/letter_avatar_proxy/v4/letter/l/bbce88/32.png) [@Lovre](https://forum.csound.com/u/Lovre)\
**Post date:** [September 30, 2022, 11:48am UTC](https://forum.csound.com/t/using-csound-as-a-c-c-library/845/3 "2022-09-30T11:48:48Z")

</div>

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](https://github.com/csound/csound/blob/master/H/pffft.h) 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 😃

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](https://github.com/csound/csound/blob/master/InOut/circularbuffer.c) and many others similarly.

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

---

<div class="post-metadata">

**Author:** ![rory](https://forum.csound.com/user_avatar/forum.csound.com/rory/32/7_2.png) [@rory](https://forum.csound.com/u/rory)\
**Post date:** [September 30, 2022, 3:42pm UTC](https://forum.csound.com/t/using-csound-as-a-c-c-library/845/4 "2022-09-30T15:42:29Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Lovre](https://forum.csound.com/letter_avatar_proxy/v4/letter/l/bbce88/32.png) [@Lovre](https://forum.csound.com/u/Lovre)\
**Post date:** [September 30, 2022, 3:52pm UTC](https://forum.csound.com/t/using-csound-as-a-c-c-library/845/5 "2022-09-30T15:52:48Z")

</div>

Is that framework from @stevenyi open somewhere?

---

<div class="post-metadata">

**Author:** ![stevenyi](https://forum.csound.com/user_avatar/forum.csound.com/stevenyi/32/4_2.png) [@stevenyi](https://forum.csound.com/u/stevenyi)\
**Post date:** [September 30, 2022, 4:35pm UTC](https://forum.csound.com/t/using-csound-as-a-c-c-library/845/6 "2022-09-30T16:35:24Z")

</div>

The original paper is at: [https://www.cs.cmu.edu/~rbd/papers/Extending-Aura-ICMC-SMC-2014.pdf](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.

---

<div class="post-metadata">

**Author:** ![Lovre](https://forum.csound.com/letter_avatar_proxy/v4/letter/l/bbce88/32.png) [@Lovre](https://forum.csound.com/u/Lovre)\
**Post date:** [September 30, 2022, 5:54pm UTC](https://forum.csound.com/t/using-csound-as-a-c-c-library/845/7 "2022-09-30T17:54:29Z")

</div>

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 🙂

---

<div class="post-metadata">

**Author:** ![stevenyi](https://forum.csound.com/user_avatar/forum.csound.com/stevenyi/32/4_2.png) [@stevenyi](https://forum.csound.com/u/stevenyi)\
**Post date:** [September 30, 2022, 6:13pm UTC](https://forum.csound.com/t/using-csound-as-a-c-c-library/845/8 "2022-09-30T18:13:21Z")

</div>

Take a look at: [https://sourceforge.net/projects/aurart/](https://sourceforge.net/projects/aurart/)

---

<div class="post-metadata">

**Author:** ![eduardomoguillansky](https://forum.csound.com/user_avatar/forum.csound.com/eduardomoguillansky/32/437_2.png) [@eduardomoguillansky](https://forum.csound.com/u/eduardomoguillansky)\
**Post date:** [October 1, 2022, 12:29pm UTC](https://forum.csound.com/t/using-csound-as-a-c-c-library/845/9 "2022-10-01T12:29:19Z")

</div>

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](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.
