As of this writing, the version of Csound available in the Ubuntu repositories is 4.23. But you know: I wanted 5.
Fortunately, I've been compiling programs since the 1980's (TRS-80 Alcor Pascal, anyone?) I've even compiled my own Linux system from source code (Linux from Scratch, LFS id 13279).
That's about where my expertise ends. You write it, I build it and run into the bugs -- and complain when they hit my windshield ;-)
So anyway, from long experience, I've developed a sort of procedure. See, when you custom install packages, a lot of times, the options repeat in later releases. You really don't want to have to slog through the documentation all over again to figure out each option you set the last time you built the program.
My primary programming language nowadays is Python (I wrote a module called PcSets -- which I'd be updating now, if I hadn't got started with Csound!) So I was overjoyed to find Csound was using scons. All you have to do is run into one messy Makefile to appreciate the difference.
So here we go. My ad hoc procedure for compiling Csound 5.08 on Ubuntu, with some advice along the way.
1. The Usual
Download the source, untar it in some safe user-owned directory, and cd inside the archive when it opens. If something goes wrong, just back out, erase the whole thing, and start over from this point by reopening the archive. Unlike eggs, a bad compile can be 'unbroken'.
2. Get Developed
OK. You should be following closely the directions in the Building Csound section of the manual. What we will be doing is adding, not subtracting or replacing.
The manual suggests a number of packages and libraries. Generally, just having a package on your system is not enough. If the guide suggests 'libsndfile', the Ubuntu 'libsndfile1' package won't do it. For each package, you need the development files as well. These contain all the headers the compiler will need for linking to those libraries.
Therefore, for every package you want to play a part in your Csound build, you need the '-dev' version as well. In the case above, you will need both 'libsndfile1' and 'libsndfile1-dev'.
3. Better Living through Logging
You can get a good idea of how well you've met your requirements by running 'scons -h', as suggested in the manual. However, here's where we make a left turn. Ever notice how all that info scrolls by incredibly fast? Frequently, during and after a build, you want to refer back to that scrolled info, but can't -- the program's compiling, or the terminal's long since been shut down.
Solve it through logging. Every time I generate a page full of options, I log the output using something like the following:
scons -h 2>&1 | tee ../options.txt
Now when I open options.txt with a text file editor (usually Kate, because it's fast, clean, and light), I have all the possibilities layed out before me. This is going to be important, because the next step is
4. Faster Optionlists, Cut! Paste!
One of the aggravating problems in the shell is the unintentional typo that has hilarious consequences (when you talk about it months later). It's not that funny when it happens. I stopped this a long time ago by writing out the exact command I was going to use in advance, and by doing as little typing as was necessary.
Remember 'options.txt'? Toward the end, the options look sort of like this excerpt:
...
pythonVersion: Set to the Python version to be used.
default: 2.5
actual: 2.5
buildCsoundVST: Set to 1 to build CsoundVST (needs CsoundAC, FLTK, boost, Python, SWIG).
default: 0
actual: 0
buildCsoundAC: Set to 1 to build CsoundAC (needs FLTK, boost, Python, SWIG).
default: 0
actual: 0
buildCsound5GUI: Build FLTK GUI frontend (requires FLTK 1.1.7 or later).
default: 0
actual: 0
...
Now, this list goes on, and on, and on. If you think you're going to memorize a list of 20 or so CamelCASE OpTionS with the correct values -- well, good luck. Typing this in by hand is the quick route to a headache. Here's a test -- don't look back at the list above -- and no fair answering if you're a Csound developer -- was that a.) buildCsound5gui, b.) buildCSound5GUI, or c.) buildCsoundGUI? And was it set or not set?
The better way is to avoid the issue. Open a new text file. We will call it options.sh, just in case you want to run it like a shell script. Write down everything, and every option you want. Do NOT rely on the old Mark I eyeball for this -- for each option, highlight the word in the text file, and copy it into the options.sh file using the middle mouse button. That way, if something goes wrong, it's at least not your typo.
By the time I was finished going through each option, and writing my options.sh file, it looked like this:
scons \
useDouble=1 \
buildCsoundAC=1 \
buildCsound5GUI=1 \
useOSC=1 \
buildPythonOpcodes=1 \
buildRelease=1 \
buildStkOpcodes=1 \
buildVirtual=1 \
buildInterfaces=1 \
buildCSEditor=1 \
buildNewParser=1 \
buildLoris=0
12 options, correctly named, correctly set. Ready to go! (Your options may be different depending on what you want to build and what you have on your system.)
5. Boo Boos
I meant to build the Loris opcodes. Unfortunately, on my system, when I unpacked the Loris code as directed, and set buildLoris=1, the compile failed, saying it couldn't find 'Opcodes/Loris/lorisgens5.C'. My best guess is that somewhere in the code, scons is being told to look for a file that's no longer necessary or no longer included. I presume it will be fixed in a later update. In the meantime, I have, what, 1403 opcodes to play with? I'll get by.
I also meant to try running the gcc 4.0 optimizations, but again, I had a phantom file problem. These things happen. I just applied a heavy dose of forgeddaboutit and moved on. After all, my goal was to make music, not improve Csound's performance speed by 5%.
6. Install!
Using the command line above (which I copied and pasted into the shell window), Csound5 compiled with no problems on my system. I've been running 5 since 5.06.
And maybe by the time we reach 5.23, I'll be good at it! ;-)
7. The Step Beyond the Last Step
So you ran ./install.py, and Csound is now on your system. A lot of people at this point erase their build directory, and send the source code tarball off to an archive somewhere.
All my source code is stored in /usr/local/src, in a separate directory for each complete package. Therefore, anything I needed to compile Csound 5 is in the /usr/local/src/Csound5 directory.
That includes the options files I generated!
That way, I only have to figure this out once every few versions. I look through the Changelog, and if anything that affects the compile options has come up, I will redo the option list. But 'options.txt' and 'options.sh' are stored right along with the source code -- there's never any doubt about "Hmm, did I compile in this or that feature?" I can just open the command file and look.
If you are super paranoid, you can even do the logfile trick during the install. This is how I caught a number of errors during Linux From Scratch -- I could go back into the log of the build and see any errors or accidents.
And no complaining about cluttering up the hard drive with text files. I mean, we generate 10 Mb audio files all the time -- I don't think the hard drive is going to implode because of one more 4.0 K text file. However, it does make organizing the source code into separate folders (by topic) absolutely necessary.
I hope this article was helpful. Failing that, maybe it was odd enough to be amusing ;-)



And now Ubuntu Hardy is, I
And now Ubuntu Hardy is, I presume, using the Debian Sid version of Csound 5.08 now that you've compiled and installed it all! I'm currently using it and it seems to work pretty well, but that's not stopping me from reinventing the wheel by following your directions to try installing it on Slackware. Maybe this time I'll succeed. ;)
BTW thanks much for your valuable post. There is much in here that would help me to compile Jack and Ardour, or any other large-scale program for that matter.
Richard
:)
I'm glad you found my post useful. Yeah, I upgraded to Hardy last weekend, and the default Csound is 5.08 ... problem is, there's no telling when changes will migrate downstream after this point. So I kept my custom compiled Csound in /usr/local. When the upgrade to 5.09 comes, I'm ready.
Further, I think Debian leaves out a few of the opcodes (the scanned synthesis ones, for example) because of incompatibility with the Debian Free Software Guidelines. Some people just have to try everything on the salad bar :D
---
http://www.jamendo.com/en/artist/bruce.h.mccosar
http://bmccosar.wordpress.com/
Yes, that's another thing
Yes, that's another thing that appeals to me about Slackware, you're not hobbled by restrictions right out of the gate. I'm currently raiding Slackbuilds.org as libsndfile wouldn't compile in its pristine state due to some conflicts with flac; the slackbuild had a patch for it and so far, so good. I must confess going beyond configure-make-make install is a bit out of my comfort zone...ultimately a good thing. One thing (among many, to be sure) I'm unclear on is whether there's a place where the dependency sources need to be in order for scons to compile Csound successfully.
The secret ingredient
Most of the modern library packages keep themselves organized through Pkg-config. On installation, the libraries literally write down instructions on how to find their files, which versions are installed, and so on.
---
http://www.jamendo.com/en/artist/bruce.h.mccosar
http://bmccosar.wordpress.com/
Thanks, that's good to know
So I think I'm covered dependency-wise. I cd'ed into the directory and attempted 'scons -h' which gave me the generic help message. So I tried the installer:
bash-3.1# ./installer
Segmentation fault
I downloaded the float 32 version, and my laptop has an Athlon X2 AMD 64 processor, but I don't think that should make a difference. Is this the same version you tried? Should it matter?
Whoops, my bad, I just realized I was using the binary installer. I just downloaded the source, tar zxvf'ed and cd'ed into it, did a 'scons -h' and it all checks out as far as I can tell. Now for the moment of truth...
Upcoming update...
There's some extra magic I just learned thanks to John ffitch (on the email Csound users list). If you get it to compile that first time, I can give you tips on turning it into a monster truck system. I learned how to turn on the gcc 4 cpu optimizations, and even install the csnd and CsoundAC Python modules. Looks like I'll have to write a 2nd article on compiling this for Hardy.
--
http://www.jamendo.com/en/artist/bruce.h.mccosar
http://bmccosar.wordpress.com/
I managed to compile it without running into errors...
except afterward when I discovered I hadn't set OPCODEDIR. :(
On the plus side, this is a personal first for me compiling anything big other than a kernel :)
Okay, I temporarily forgot...
...what an environment variable was, then remembered I just needed to add them to my .bashrc (there's probably a correlative file to set them system-wide, but I'm the only one using this laptop anyway). As it is, it doesn't matter for now because this variable
CSSTRNGS=/usr/local/share/csound/xmg
points to a nonexistent directory/file, thus causing csound to deliver the following error message:
$ csound tutorial.csd
time resolution is 0.587 ns
0dBFS level = 32768.0
Csound version 5.08 beta (float samples) May 2 2008
libsndfile-1.0.17
UnifiedCSD: tutorial.csd
STARTING FILE
Creating options
Creating orchestra
Creating score
orchname: /tmp/file99ccj2.orc
scorename: /tmp/file2A3TsU.sco
orch compiler:
28 lines read
instr 1
error: no legal opcode, line 32:
aout vco2 iamplitude, ifrequency
error: input arg 'aout' used before defined, line 34:
outs aout, aout
error: input arg 'aout' used before defined, line 34:
outs aout, aout
################################################################
# WARNING: OPCODEDIR IS NOT SET ! #
# Csound requires this environment variable to be set to find #
# its plugin libraries. If it is not set, you may experience #
# missing opcodes, audio/MIDI drivers, or utilities. #
################################################################
3 syntax errors in orchestra. compilation invalid
Removing temporary file /tmp/file2A3TsU.sco ...
Removing temporary file /tmp/file99ccj2.orc ...
Any idea how to fix this?
My guess is that the
My guess is that the environment variables are set in your .bashrc file, but not exported. This is what the relevant section of my .bashrc file looks like:
# for csound
export OPCODEDIR64=/usr/local/lib/csound/plugins64
export CSSTRNGS=/usr/local/share/csound/xmg
export RAWWAVE_PATH=/usr/local/share/csound/rawwaves
The 'export' keyword makes all the difference, bringing the variables into your actual bash session. To get this to work, change the file as above, then close the terminal window. When you reopen, it should work.
The xmg should be empty unless you chose to internationalize your messages (I think). At any rate all three of the above should point to directories, not files.
---
http://www.jamendo.com/en/artist/bruce.h.mccosar
http://bmccosar.wordpress.com/
Oh yes, that 'export' command
that I should be familiar with by now. ;) My problem, though, is not whether xmg is empty or not, it's that it doesn't at all exist:
$ ls -l /usr/local/share
total 4
drwxr-xr-x 3 root root 4096 2008-05-01 22:59 doc
$ ls -l /usr/local/share/doc
total 4
drwxr-xr-x 2 root root 4096 2008-05-02 21:39 csound
$ ls -l /usr/local/share/doc/csound/
total 388
-rw-r--r-- 1 root root 26430 2005-04-16 14:21 COPYING
-rw-r--r-- 1 root root 352265 2008-03-16 07:50 ChangeLog
-rw-r--r-- 1 root root 628 2008-01-25 00:11 INSTALL
-rw-r--r-- 1 root root 1828 2008-03-16 07:50 readme-csound5.txt
I compiled with just 'scons' and no options because I was getting errors, so I guess I need to dig a little deeper.
SUCCESS!!
I uninstalled and recompiled:
# scons useDouble=1 buildCsoundAC=1 buildCsound5GUI=1 useOSC=1 buildPythonOpcodes=1 buildRelease=1 buildStkOpcodes=1 buildVirtual=1 buildInterfaces=1 buildCSEditor=1 buildNewParser=1
and for some reason the thing works:
$ csound tutorial.csd
PortAudio real-time audio module for Csound
virtual_keyboard real time MIDI plugin for Csound
0dBFS level = 32768.0
Csound version 5.08 (double samples) May 3 2008
libsndfile-1.0.17
UnifiedCSD: tutorial.csd
STARTING FILE
Creating options
Creating orchestra
Creating score
orchname: /tmp/fileaT3av9.orc
scorename: /tmp/file6By0Q8.sco
rtaudio: ALSA module enabled
orch compiler:
28 lines read
instr 1
Elapsed time at end of orchestra compile: real: 0.029s, CPU: 0.000s
sorting score ...
... done
Elapsed time at end of score sort: real: 0.029s, CPU: 0.000s
Csound version 5.08 (double samples) May 3 2008
0dBFS level = 32767.0
orch now loaded
audio buffered in 4096 sample-frame blocks
ALSA output: total buffer size: 8192, period size: 4096
writing 16384-byte blks of shorts to devaudio
SECTION 1:
B 0.000 .. 1.000 T 1.000 TT 1.000 M: 0.0 0.0
new alloc for instr 1:
B 1.000 .. 6.000 T 6.000 TT 6.000 M: 2365.0 2365.0
Score finished in csoundPerform().
inactive allocs returned to freespace
end of score. overall amps: 2365.0 2365.0
overall samples out of range: 0 0
0 errors in performance
Elapsed time at end of performance: real: 5.745s, CPU: 0.180s
65 16384-byte soundblks of shorts written to devaudio
richard@richard-laptop:~/usb/csound$ csound tutorial.csd
PortAudio real-time audio module for Csound
virtual_keyboard real time MIDI plugin for Csound
0dBFS level = 32768.0
Csound version 5.08 (double samples) May 3 2008
libsndfile-1.0.17
UnifiedCSD: tutorial.csd
STARTING FILE
Creating options
Creating orchestra
Creating score
orchname: /tmp/fileVmRkRx.orc
scorename: /tmp/fileyX4azV.sco
rtaudio: ALSA module enabled
orch compiler:
28 lines read
instr 1
Elapsed time at end of orchestra compile: real: 0.023s, CPU: 0.010s
sorting score ...
... done
Elapsed time at end of score sort: real: 0.023s, CPU: 0.010s
Csound version 5.08 (double samples) May 3 2008
0dBFS level = 32767.0
orch now loaded
audio buffered in 4096 sample-frame blocks
ALSA output: total buffer size: 8192, period size: 4096
writing 16384-byte blks of shorts to devaudio
SECTION 1:
B 0.000 .. 1.000 T 1.000 TT 1.000 M: 0.0 0.0
new alloc for instr 1:
B 1.000 .. 6.000 T 6.000 TT 6.000 M: 2365.0 2365.0
Score finished in csoundPerform().
inactive allocs returned to freespace
end of score. overall amps: 2365.0 2365.0
overall samples out of range: 0 0
0 errors in performance
Elapsed time at end of performance: real: 5.740s, CPU: 0.170s
65 16384-byte soundblks of shorts written to devaudio
Thanks much for the help, Bruce. BTW, my name's Richard Benedict and I'm just teaching guitar in Toronto. I've been slowwwwly learning a bit of csound over the years, and I have to say it's very rewarding to actually accomplished this. Now I can get back to that piece I was working on...
Cheers!
Richard
optimizations
Hey, congrats. And it's good to meet you. I'm relatively new to Csound, but I come from a long time programming background, so some of these bits are second nature to me now.
But here's one I just learned:
Use your original options file, but see if it compiles with an additional flag:
gcc4opt=native
This automatically detects your cpu and fine tunes the build to take advantage of extra instruction sets you might have available. On mine, the difference was immediately noticeable -- running csound went from being a process I could watch happen on a terminal to one I saw blur by in a rush of text.
If you're interested in installing the csnd and csoundAC python modules, I'm on that one, too ;-)
---
http://www.jamendo.com/en/artist/bruce.h.mccosar
http://bmccosar.wordpress.com/
What is 'csnd'?
I couldn't find it in the 'scons -h' output.
I guess it doesn't matter that much
I have a working csound with the CsoundAC module included but not gcc4opt, though I may decide to recompile with the latter included, if I have the time. Thanks again for the help.