[Cs-dev] Trying to set up a C++ project using CSound API
Date | 2015-07-25 21:23 |
From | iron_attorney |
Subject | [Cs-dev] Trying to set up a C++ project using CSound API |
Hi there, this is my first post to this forum! Hello all! I am desperately struggling to use CSound within a C++ project. I am trying to make a random music generator. I know there is probably extensive coverage of such issues already in this forum, however I have read through the manual extensively, followed a good few tips that I have read already from this forum, and I have frantically searched google and read many things and watched many tutorials to try to resolve my issues, and to no avail. Here is where I am at: I have CSound 6 installed, and I am using Visual Studio 14 (2015). I am already a capable user of CSound, and I am ok at coding both C++ and C#. I have linked to all the CSound headers from my project, and at the top of my C++ project, I have: #include "CSound/csound.hpp". This is the correct location of this header, and it does appear to find it as far as I can tell. I have included all other headers aswell, because VS14 threw up erros, presumably because the csound.hpp file references other header files. I have then taken the csound64.dll file, and using VS14 command prompt tools, created a .def file, and used that to create a csound64.lib file (along with a csound64.exe file). So far, these steps all seemed to work, though I have some confusion already about which command prompt tools to use. I can choose between either x86 or x64 toolkits (both native and cross). I'm assuming as I am running a 64 bit pc, and the file using the 64 in it's name, that I should use the 64 bit toolkit. I have making a .lib using both versions anyway. I copied the .dll, .def, .lib and .exe file into a folder within my C++ project folder, and followed instructions online to link to the .lib file. I now recieve an error stating that libFLAC-8.dll is missing or something to that effect. I read in this forum that this may be related to libstdc++-6.dll. I have therefor tried to make .lib files from both libstdc++-6.dll and libFLAC-8.dll. Unfortunately, my command prompt throws up errors throughout the process of turning the .def into a .lib, and both the .lib and .exe turn out almost empty. So, I am now quite stuck, and I have many questions! Have I done things right so far? Do I need to link to more .dlls? Should I have moved headers and libraries to the C++ project folder or linked directly to CSound folder? Can anyone give me a list of every file from CSound I will need to add to the project to make it work? Would it be easier to get this to work in C#? Would it be easier to get this to work in a different C++ compiler? Would it be easier to do it on Linux instead? I appologise for the long post, but I am starting to lose sleep over this! Haha, cheers in advance for any help! ps, would what I am attempting to do be classified as "compiling CSound"? Pete -- View this message in context: http://csound.1045644.n5.nabble.com/Trying-to-set-up-a-C-project-using-CSound-API-tp5742885.html Sent from the Csound - Dev mailing list archive at Nabble.com. ------------------------------------------------------------------------------ _______________________________________________ Csound-devel mailing list Csound-devel@lists.sourceforge.net |
Date | 2015-07-25 21:52 |
From | Steven Yi |
Subject | Re: [Cs-dev] Trying to set up a C++ project using CSound API |
Hi Pete, It sounds like you're just compiling against Csound. It seems to me that the issue is that you're trying to compile as x64; if you're using the installer version of Csound, those should be x86 (32-bit). I'm not so good with Windows dev, but I would have thought that you'd only need to link to libcsound64.dll, and the rest would come in transitively. Hope that helps! steven On Sat, Jul 25, 2015 at 4:23 PM, iron_attorney |
Date | 2015-07-25 22:07 |
From | Michael Gogins |
Subject | Re: [Cs-dev] Trying to set up a C++ project using CSound API |
Attachments | None None |
You have to compile for 32 bit CPU architecture, i.e. use the x86 toolkit. Also, Csound is built with MinGW, not Microsoft C++. This will be fine for you to use the Microsoft compiler, if you #include only csound.hpp and no other C++ headers from Csound and link with csound64.lib, which should have been provided with the installer. The 64 in csound64 refers to audio sample size, not CPU architecture, so don't be confused by that. All the Dlls in the csound bin dir need to go in your program's bin dir, this includes the MinGW C++ support libraries that some python opcodes use. Hope this helps, On Jul 25, 2015 4:24 PM, "iron_attorney" <pete.soundtechnician@gmail.com> wrote:
Hi there, this is my first post to this forum! Hello all! |
Date | 2015-07-27 15:02 |
From | iron_attorney |
Subject | Re: [Cs-dev] Trying to set up a C++ project using CSound API |
Thank you both for your swift responses, they have cleared a few things up for me! I have remade the csound64.lib using the x86 toolkit. I wondered if it might make a difference if the headers and libraries were in the same file structure within my project as they appear within Csound, so I created a Csound6 folder in my project and copied the bin and include folders from Csound directly into this folder. So I have: the entire contents of the folders "bin" and "include" in my project directories I have added all headers to the headers folder in the visual studio project (otherwise it says it can't find them) I have included the csound.cpp header file in my code I have linked to the bin folder in my project settings I have linked to csound64.lib in my project settings When I run the project, I am still getting this error message: "This program can't start because libFLAC-8.dll is missing from your computer. Try reinstalling the program to fix this problem" Is this a .dll that's meant to come with windows or a csound specific one? I can't remember if I already mentioned it, but I'm using windows 8.1 if that's going to make any difference to how csound works. Thanks in advance, Pete -- View this message in context: http://csound.1045644.n5.nabble.com/Trying-to-set-up-a-C-project-using-CSound-API-tp5742885p5742896.html Sent from the Csound - Dev mailing list archive at Nabble.com. ------------------------------------------------------------------------------ _______________________________________________ Csound-devel mailing list Csound-devel@lists.sourceforge.net |
Date | 2015-07-27 15:21 |
From | Rory Walsh |
Subject | Re: [Cs-dev] Trying to set up a C++ project using CSound API |
Is that dll not in your Csound bin? You don't have to include all that stuff directly into your project, you just need to make sure Windows can find the dlls, and that MSVC can find the header and lib paths. It's been mentioned before on the list, but Windows is the most complex environment to get set up on with Csound, especially if you are using MSVC. I always advise my students to install Linux on a small partition and get to grips with the API there. In about an hours or so you should be fully set up. Alternatively keep plugging away with MSVC. I used to use it a lot for Csound API but gave up on it years ago. In the long run it saved me a lot of heart ache. I now build all my Windows Csound software with makefiles and mingw. On 27 July 2015 at 15:02, iron_attorney |
Date | 2015-07-27 18:19 |
From | Michael Gogins |
Subject | Re: [Cs-dev] Trying to set up a C++ project using CSound API |
Attachments | None None |
The issue here is that the MinGW runtime libraries need to also be in the bin dir. I think. Regards, Mike ----------------------------------------------------- Michael GoginsIrreducible Productions http://michaelgogins.tumblr.com Michael dot Gogins at gmail dot com On Mon, Jul 27, 2015 at 10:21 AM, Rory Walsh <rorywalsh@ear.ie> wrote: Is that dll not in your Csound bin? You don't have to include all that |
Date | 2015-07-28 16:31 |
From | Peter Burgess |
Subject | Re: [Cs-dev] Trying to set up a C++ project using CSound API |
Attachments | None None |
Ok, I've tried referencing the MinGW bin using envirenment path variables in MSVS, adding the MinGW bin files to my project bin, and I have a copy of libFLAC-8.dll that I downloaded off the internet (so I can't be sure if it's right or not) and I have tried putting that in a few places to get it to work. So far, I still just get the same error message. I don't suppose anyone has the proper libFLAC-8.dll do they? I can't find it anywhere in csound or mingw as has been sugested. I am starting to get tired of plugging away with MSVS. It's been stringing me along for too long. I'm not sure which route to take now. I have a multiboot desktop with a linux partition ready to go, as I am trying to make the move to linux as much as possible. I've also just checked to see if I can repartition my laptop without having to reformat everything, and apparently these days you can. I guess this might be the answer. Although I already have a copy of MinGW (I downloaded it when I noticed all the Csound API instructions were for MinGW). I've never done command line compiling before, looks scary! If I was to go with linux, are there any compilers with frontends that work well for Csound? Or will it still be a terminal deal?"You don't have to include all that stuff directly into your project, you just need to make sure Windows can find the dlls, and that MSVC can find the header and lib paths." I know this isn't a direct Csound question, but does the compiler include all the dlls and that into the final .exe? So the compiler only needs to copy them or something? Sorry, I am very new to this area of programing. On Mon, Jul 27, 2015 at 6:19 PM, Michael Gogins <michael.gogins@gmail.com> wrote:
|
Date | 2015-07-28 17:21 |
From | Peter Burgess |
Subject | Re: [Cs-dev] Trying to set up a C++ project using CSound API |
Attachments | None None |
To add an update, I've just recreated the project in a new location, and used MinGW (still in windows 8.1) to compile it. It seems to compile just fine, but when I run the resulting .exe I get the exact same error regarding libFLAC-8.dll. What the hell is this illusive file? Boy it's really breaking my balls! :D PeteOn Tue, Jul 28, 2015 at 4:31 PM, Peter Burgess <pete.soundtechnician@gmail.com> wrote:
|
Date | 2015-07-28 17:40 |
From | Rory Walsh |
Subject | Re: [Cs-dev] Trying to set up a C++ project using CSound API |
I faced lots of issues like this in the past. In the end I found it quicker to compile my own version of Csound and link to that. My version doesn't use libFLAC-8.dll, but when I saw quicker, it did take me quite some time to get my environment set up. If you have Linux already up and running I would take a step in that direction. Follow the instructions here to build Csound yourself: https://github.com/csound/csound/blob/develop/BUILD.md#debian It shouldn't take more than a few moments. Then have a go at compiling some of these examples from the command line. Instructions are given: https://github.com/csound/csoundAPI_examples/tree/master/cpp If that all works and you get some basic examples compiling you can start thinking of an IDE to use. There are no shortage of IDEs to use on Linux. If you happen to like the overall layout of MSVC, you can try CodeLite. Netbeans is another popular one along with KDevelop. I think QTCreator also runs fine on Linux. On 28 July 2015 at 17:21, Peter Burgess |
Date | 2015-07-29 12:15 |
From | Peter Burgess |
Subject | Re: [Cs-dev] Trying to set up a C++ project using CSound API |
Attachments | None None |
Thanks very much for all the info! It sounds like linux might be the way forward. I am half tempted to ask how you compiled Csound without the need for libFLAC-8.dll... is that likely to be way over my head? Failing that, I guess I'll switch to linux. I pressume that this libFLAC error isn't a common problem when using linux then?On Tue, Jul 28, 2015 at 5:40 PM, Rory Walsh <rorywalsh@ear.ie> wrote: I faced lots of issues like this in the past. In the end I found it |
Date | 2015-07-29 12:50 |
From | Rory Walsh |
Subject | Re: [Cs-dev] Trying to set up a C++ project using CSound API |
The libFLAC issues is most likely a libsndilfe dependency. There is minimal instructions on how to build on Windows for mingw here: https://github.com/csound/csound/blob/develop/BUILD.md#mingw32 There are rarely issues like this when working on Linux. Linux package managers are great at installing everything you may need. ------------------------------------------------------------------------------ _______________________________________________ Csound-devel mailing list Csound-devel@lists.sourceforge.net |
Date | 2015-07-29 14:43 |
From | Michael Gogins |
Subject | Re: [Cs-dev] Trying to set up a C++ project using CSound API |
Attachments | None None |
This error is a false positive. You do not need this library. You do need to have all the dlls in the windows installer bin dir in your projects bin dir. Regards, On Jul 29, 2015 7:16 AM, "Peter Burgess" <pete.soundtechnician@gmail.com> wrote:
|
Date | 2015-07-31 13:59 |
From | Peter Burgess |
Subject | Re: [Cs-dev] Trying to set up a C++ project using CSound API |
Attachments | None None |
Mike: when you say the windows installer bin for, do you mean the windows csound bin? Or windows bin? I have added the whole csound bin to my project directory already. Rory: Cheers for the info! I've had a look through and still wrestling with it. I've also foolishly just accepted an upgrade to windows 10 on my laptop, which is aweful! So that's pushed me to finally wipe the whole system and install ubuntu. So I'm gonna start my csound journey again on there. I'll message again if I hit any problems, but I think I have enough understanding and resources now to get it up and running myself on Linux. Cheers for the help from all three of you! Also props to Rory and mike, at least 50% of the csound resources I've found have involved one of you. Pete On 29 Jul 2015 14:43, "Michael Gogins" <michael.gogins@gmail.com> wrote:
|
Date | 2015-07-31 14:24 |
From | Michael Gogins |
Subject | Re: [Cs-dev] Trying to set up a C++ project using CSound API |
Attachments | None None |
Typically C:\Program Files (x86)\Csound6\bin. I think things will go more smoothly on Ubuntu. This is what I use when I work on Linux. I am sure that Windows, OS X, and Linux are roughly on the same level of quality when it comes to actually running programs and supporting the user, but I have no doubt that Linux is far superior when it comes to installing software and building software. Regards, Mike ----------------------------------------------------- Michael GoginsIrreducible Productions http://michaelgogins.tumblr.com Michael dot Gogins at gmail dot com On Fri, Jul 31, 2015 at 8:59 AM, Peter Burgess <pete.soundtechnician@gmail.com> wrote:
|
Date | 2015-08-02 09:57 |
From | Peter Burgess |
Subject | Re: [Cs-dev] Trying to set up a C++ project using CSound API |
Attachments | None None |
Well you guys weren't wrong! I've been playing with it only this morning on ubuntu and Ive got much further than ever before! I had to copy a version of "float-version.h" into the include directory to satisfy my compiler, but that was no biggy. "return csoundCompileCsd(csound, csd)" Which gives the error "undefined reference to 'csoundCompileCsd' ". Simply commenting this line out allows me to build and run my program with a warning, and so it seems besides this line it works :D anyone else come across this error? Just in case it's important, I am using the files from Csound 6.05 to build my project, however the installed version of Csound is 6.02 (the version available on the software centre). Is this going to effect how it works? Pete Typically C:\Program Files (x86)\Csound6\bin. I think things will go more smoothly on Ubuntu. This is what I use when I work on Linux. I am sure that Windows, OS X, and Linux are roughly on the same level of quality when it comes to actually running programs and supporting the user, but I have no doubt that Linux is far superior when it comes to installing software and building software. Regards, Mike ----------------------------------------------------- Michael GoginsIrreducible Productions http://michaelgogins.tumblr.com Michael dot Gogins at gmail dot com On Fri, Jul 31, 2015 at 8:59 AM, Peter Burgess <pete.soundtechnician@gmail.com> wrote:
------------------------------------------------------------------------------ _______________________________________________ Csound-devel mailing list Csound-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/csound-devel |
Date | 2015-08-02 10:24 |
From | Rory Walsh |
Subject | Re: [Cs-dev] Trying to set up a C++ project using CSound API |
Attachments | None None |
You're using new source, but linking against the old API. If you build Csound yourself from the git repo and run 'sudo make install' and 'sudo ldconfig' you should be fine. But if you don't need the compileCSD function then just keep going as you are. On 2 August 2015 at 10:57, Peter Burgess <pete.soundtechnician@gmail.com> wrote:
|
Date | 2015-08-02 11:12 |
From | Peter Burgess |
Subject | Re: [Cs-dev] Trying to set up a C++ project using CSound API |
Attachments | None None |
Ok cool, so this error is due to the older api. Well I don't know yet what that function does (I'll look it up later) but its best I have all tools available just in case. I'll have a go at building it :D After that, hopefully its just a case of getting to grips with it, I'll report back and let you know how I get on! On 2 Aug 2015 10:25, "Rory Walsh" <rorywalsh@ear.ie> wrote:
|
Date | 2015-08-03 13:51 |
From | Peter Burgess |
Subject | Re: [Cs-dev] Trying to set up a C++ project using CSound API |
Attachments | None None |
Ok, I'm back again! Sorry to keep picking your brains, but I have a question regarding the interaction between my c++ code and Csound. So I've been following Rory's document " Introduction to using the
I'm up to part 3, communicating with Csound, and at the end it says: "You can test the the above program by running it with the following csound instrument:" and a basic orchestra script is shown. But how do I access this orchestra code from my script? My initial instinct is that I need to add a void in my c++ code containing the orchestra code, so I can make that void an argument of "csoundCreate(0)", replacing the 0. Or do I need to write a .csd or .orc file and reference that in my script? Again, I'm sorry to pester you guys, really thought I could make it on my own from here! Cheers in advance! Pete On 2 Aug 2015 11:12, "Peter Burgess" <pete.soundtechnician@gmail.com> wrote:
|
Date | 2015-08-03 14:06 |
From | Rory Walsh |
Subject | Re: [Cs-dev] Trying to set up a C++ project using CSound API |
Attachments | None None |
The best way is using channels. Make calls to Csound::SetChannel() in your C++ code, and then use chnget in your Csound code. That resource you are looking at is a little C heavy. You'd be better off following the examples here: https://github.com/csound/csoundAPI_examples/tree/master/cpp Note that you will need to run Csound in its own thread if you want to start communicated with it in realtime while the instrument is performing. On 3 August 2015 at 14:51, Peter Burgess <pete.soundtechnician@gmail.com> wrote:
|
Date | 2015-08-03 14:21 |
From | Michael Gogins |
Subject | Re: [Cs-dev] Trying to set up a C++ project using CSound API |
Attachments | None None |
It is not necessary to run a separate thread if you run your own code in a loop like this: CSOUND* my_csound_ptr = csoundCreate(my_host_data_ptr); csoundCompileCsd(csound_ptr, "MyCsdFile.csd"); bool is_finished = false; MYFLT channelValue = 1.0; while (!is_finished) { csoundSetChannel(csound_ptr, "MyChanne", channelValue); is_finished = csoundPerformKsmps(csound_ptr); } It is somewhat cleaner to run a separate thread. I would use boost to do this, use a boost thread and a boost lockfree queue to get the Csound messages out of the Csound thread and into your main app thread. You don't need to use queues for the channel values, although you can, because the channel APIs are thread-safe. Regards, Mike ----------------------------------------------------- Michael GoginsIrreducible Productions http://michaelgogins.tumblr.com Michael dot Gogins at gmail dot com On Mon, Aug 3, 2015 at 9:06 AM, Rory Walsh <rorywalsh@ear.ie> wrote:
|
Date | 2015-08-03 14:34 |
From | Rory Walsh |
Subject | Re: [Cs-dev] Trying to set up a C++ project using CSound API |
Attachments | None None |
Here's another example. Csd is provided below. You will need to provide include paths for csPerfThread.hpp, and link with -lcsnd6. My command line looks like this: #include <iostream>g++ realTimeCom.cpp -o test -I ../../cabbageaudio/csound/include/ -I ../../cabbageaudio/csound/interfaces/ -L ../../cabbageaudio/csound/build/ -lcsnd6 -lcsound64 //=================================================== #include "csound.hpp" #include "csPerfThread.hpp" using namespace std; int main(int argc, char *argv[]) { //create an instance of Csound Csound* csound = new Csound(); //set CsOptions int freq=0; //compile csd csound->Compile("test.csd"); //set up CsoundPerfThread object CsoundPerformanceThread* perfThread = new CsoundPerformanceThread(csound); //start Csound performance perfThread->Play(); //keep the application running while performance is ongoing while(perfThread->GetStatus() == 0) { //grab the freq we wish to send to Csound.. cin >> freq; csound->SetChannel("freq", freq); } //free Csound and thread objects delete csound, perfThread; return 0; } //==================================================== <CsoundSynthesizer> <CsOptions> -odac </CsOptions> <CsInstruments> sr = 44100 ksmps = 64 nchnls = 2 0dbfs = 1 instr 1 k1 chnget "freq" a1 oscili 1, k1, 1 outs a1, a1 endin </CsInstruments> <CsScore> f1 0 1024 10 1 i1 0 3600 </CsScore> </CsoundSynthesizer> //==================================================== On 3 August 2015 at 15:21, Michael Gogins <michael.gogins@gmail.com> wrote:
|
Date | 2015-08-04 11:19 |
From | Peter Burgess |
Subject | Re: [Cs-dev] Trying to set up a C++ project using CSound API |
Attachments | None None |
You guys are awesome! Thank you both for your help, I've got it up and running now :D I'm understanding what each bit means now too. More to the point, I finally have sound! You don't know how long I've been trying just to get sound out of c++. Struggled for ages with the synthesis toolkit aswell, I could achieve neither realtime output (couldn't send data to the dac), or working audio file output (all wav/aiff files were unrecognised by any program including my daw!) . I have but 2 final questions for you guys.On Mon, Aug 3, 2015 at 2:34 PM, Rory Walsh <rorywalsh@ear.ie> wrote:
|
Date | 2015-08-04 12:59 |
From | Michael Gogins |
Subject | Re: [Cs-dev] Trying to set up a C++ project using CSound API |
The documentation for using the Csound API consists of the doxygen documents (what you call the GitHub documentation) which is, as you say, not complete; some articles in the Csound Journal; and the examples in GitHub. I have entered a request in GitHub to make the API documentation more finished and to include some basic examples. People have talked about creating a separate API document for years. I thought that was a bad idea, and the fact that it hasn't happened indicates I was right. It will be easier and better to update the Doxygen comments. Most of us who do score generation use the Csound API but do the actual score generation in another language. I have used for this purpose over the years Visual Basic, Pascal, Mathematica, C++, Java, Lua and LuaJIT, and JavaScript. I have done a lot of work using LuaJIT because I embedded it in Csound and that enables all my code for a whole piece to go into the CSD file, but I am moving most of my work into JavaScript as that enables tighter integration with custom user interfaces and other features in Web browsers or standalone HTML hosts such as NW.js. Then the generated score is entered into Csound by calling csoundReadScore, csoundInputMessage (but has limited capacity), or csoundScoreEvent. Most of the sophisticated algorithmic composition libraries are written in a functional programming language such as Lisp, Scheme, or Haskell. The problem with this is that these languages were not designed to run embedded in a Web browser or in Csound (it was easy to embed LuaJIT in Csound). It would be really great if somebody could manage to embed usable versions of Scheme or Lisp (or Haskell!) in either NW.js or Csound, that would create an unequaled computer music environment. Since both LuaJIT and JavaScript have more or less the same functional programming features as Scheme, another option would be to port the needed stuff from Common Music, Open Music, Euterpea, etc. to JavaScript. I think I will do some of this myself, but it will only be for those features of these systems that I see a need for in pieces that I am actually working on. But honestly, I would prefer it if I could run Open Music or Euterpea in a Web browser. I'm going to rant on a bit here. Computer music is full of cul de sacs, personal and academic projects to re-invent the wheel. On the one hand these are a great source of invention and originality, on the other hand they tend to divide up the field into a bunch of little fiefdoms of mutual incompatibility and non-communication. I urge all people starting big projects in computer music not to re-invent the wheel, and to start out from a base of widely used languages and systems wherever possible, in the hopes of creating wider communities. Regards, Mike ----------------------------------------------------- Michael Gogins Irreducible Productions http://michaelgogins.tumblr.com Michael dot Gogins at gmail dot com On Tue, Aug 4, 2015 at 6:19 AM, Peter Burgess |