Csound Csound-dev Csound-tekno Search About

[Csnd] Csound real-time CPU performance in Linux

Date2005-09-20 14:49
FromHector Centeno
Subject[Csnd] Csound real-time CPU performance in Linux
Hi,

I was wondering if the CPU usage of Csound in my Linux system is normal. 
I've been using Csound mainly for creating real-time midi instruments 
and I find myself often limited by the high use of CPU some opcodes 
have. For example, the following instrument won't let me play a 
polyphony higher than 3 notes:

iamp                           ampmidi        7000
ifreq                           cpstmid        6
kenv                           linenr        iamp*5, 0, 1, .01
apure                         loscil        kenv, ifreq, 13, 1, 2, 1, 12911
apureCmb                 moogladder        apure, 400, 1
apurerL, apurerR     freeverb        apureCmb, apureCmb, 0, 0
                                   outs         apurerL, apurerR

Trying more than 3 notes uses 100% of the CPU and sound crackling 
begins. In this case the moogladder seems to be using a lot of CPU but I 
don't know if this is an expected behaviour. My system consists of a 
Pentium 4HT 2.8 ghz, 1 gig ram using agnula Linux (with the tweaked 
kernel for realtime preemption) and a M-Audio Audiophile interface. I 
built Csound from CVS with the Jack module and Portmidi. I set the -b 
and -B flags according to the manual (matching Jack's that is presently 
using 128 frames, 2 periods).

Beside this problem I also found that while running Csound any video 
activity produces clicks in the output (i.e. minimizing, maximizing or 
opening windows, sequencer software redrawing the display, etc) even 
while using very low CPU. This problem is not present using other audio 
programs (e.g. ardour, jackrack, linuxsampler). This problem is reduced 
by increasing the -B flag but obviously that makes latency higher.

Thanks in advance,

Hector
-- 
Send bugs reports to this list.
To unsubscribe, send email to csound-unsubscribe@lists.bath.ac.uk

Date2005-09-20 15:59
FromVictor Lazzarini
SubjectRe: [Csnd] Csound real-time CPU performance in Linux
Tested here with a slightly older version of csound5 on windows (2.8 ghz),
I could get 5 simultaneous notes. Because your envelope decay is quite
long, you might actually be using up polyphony without noticing.

Victor

At 14:49 20/09/2005, you wrote:
>Hi,
>
>I was wondering if the CPU usage of Csound in my Linux system is normal. 
>I've been using Csound mainly for creating real-time midi instruments and 
>I find myself often limited by the high use of CPU some opcodes have. For 
>example, the following instrument won't let me play a polyphony higher 
>than 3 notes:
>
>iamp                           ampmidi        7000
>ifreq                           cpstmid        6
>kenv                           linenr        iamp*5, 0, 1, .01
>apure                         loscil        kenv, ifreq, 13, 1, 2, 1, 12911
>apureCmb                 moogladder        apure, 400, 1
>apurerL, apurerR     freeverb        apureCmb, apureCmb, 0, 0
>                                   outs         apurerL, apurerR
>
>Trying more than 3 notes uses 100% of the CPU and sound crackling begins. 
>In this case the moogladder seems to be using a lot of CPU but I don't 
>know if this is an expected behaviour. My system consists of a Pentium 4HT 
>2.8 ghz, 1 gig ram using agnula Linux (with the tweaked kernel for 
>realtime preemption) and a M-Audio Audiophile interface. I built Csound 
>from CVS with the Jack module and Portmidi. I set the -b and -B flags 
>according to the manual (matching Jack's that is presently using 128 
>frames, 2 periods).
>
>Beside this problem I also found that while running Csound any video 
>activity produces clicks in the output (i.e. minimizing, maximizing or 
>opening windows, sequencer software redrawing the display, etc) even while 
>using very low CPU. This problem is not present using other audio programs 
>(e.g. ardour, jackrack, linuxsampler). This problem is reduced by 
>increasing the -B flag but obviously that makes latency higher.
>
>Thanks in advance,
>
>Hector
>--
>Send bugs reports to this list.
>To unsubscribe, send email to csound-unsubscribe@lists.bath.ac.uk

Victor Lazzarini
Music Technology Laboratory
Music Department
National University of Ireland, Maynooth 

-- 
Send bugs reports to this list.
To unsubscribe, send email to csound-unsubscribe@lists.bath.ac.uk

Date2005-09-20 16:04
FromVictor Lazzarini
SubjectRe: [Csnd] Csound real-time CPU performance in Linux
The moog filter is a little costly in terms of computation, but that
can be improved perhaps (I know how just have to get round to doing it).
Mind you, I tried the moogvcf and that one is even worse (could only get
2 simultaneous notes without dropouts).

Victor

At 14:49 20/09/2005, you wrote:
>Hi,
>
>I was wondering if the CPU usage of Csound in my Linux system is normal. 
>I've been using Csound mainly for creating real-time midi instruments and 
>I find myself often limited by the high use of CPU some opcodes have. For 
>example, the following instrument won't let me play a polyphony higher 
>than 3 notes:
>
>iamp                           ampmidi        7000
>ifreq                           cpstmid        6
>kenv                           linenr        iamp*5, 0, 1, .01
>apure                         loscil        kenv, ifreq, 13, 1, 2, 1, 12911
>apureCmb                 moogladder        apure, 400, 1
>apurerL, apurerR     freeverb        apureCmb, apureCmb, 0, 0
>                                   outs         apurerL, apurerR
>
>Trying more than 3 notes uses 100% of the CPU and sound crackling begins. 
>In this case the moogladder seems to be using a lot of CPU but I don't 
>know if this is an expected behaviour. My system consists of a Pentium 4HT 
>2.8 ghz, 1 gig ram using agnula Linux (with the tweaked kernel for 
>realtime preemption) and a M-Audio Audiophile interface. I built Csound 
>from CVS with the Jack module and Portmidi. I set the -b and -B flags 
>according to the manual (matching Jack's that is presently using 128 
>frames, 2 periods).
>
>Beside this problem I also found that while running Csound any video 
>activity produces clicks in the output (i.e. minimizing, maximizing or 
>opening windows, sequencer software redrawing the display, etc) even while 
>using very low CPU. This problem is not present using other audio programs 
>(e.g. ardour, jackrack, linuxsampler). This problem is reduced by 
>increasing the -B flag but obviously that makes latency higher.
>
>Thanks in advance,
>
>Hector
>--
>Send bugs reports to this list.
>To unsubscribe, send email to csound-unsubscribe@lists.bath.ac.uk

Victor Lazzarini
Music Technology Laboratory
Music Department
National University of Ireland, Maynooth 

-- 
Send bugs reports to this list.
To unsubscribe, send email to csound-unsubscribe@lists.bath.ac.uk

Date2005-09-20 16:09
FromAnthony Kozar
SubjectRe: [Csnd] Csound real-time CPU performance in Linux
The freeverb opcode is likely the problem.  Reverbs are very CPU intensive
and you are getting a separate instance of freeverb for each note.  Try
moving the freeverb (and outs) to a separate instrument (with higher number)
and using global variables to route the output of each note to the reverb.
Then, only create a single i-statement for the reverb instrument in your
score.

Anthony Kozar
anthonykozar@sbcglobal.net
http://akozar.spymac.net/

PS.  There are many examples of how to do this type of effects routing out
there on the web.


Hector Centeno wrote on 9/20/05 9:49 AM:

> For example, the following instrument won't let me play a
> polyphony higher than 3 notes:
> 
> iamp                           ampmidi        7000
> ifreq                           cpstmid        6
> kenv                           linenr        iamp*5, 0, 1, .01
> apure                         loscil        kenv, ifreq, 13, 1, 2, 1, 12911
> apureCmb                 moogladder        apure, 400, 1
> apurerL, apurerR     freeverb        apureCmb, apureCmb, 0, 0
> outs         apurerL, apurerR

-- 
Send bugs reports to this list.
To unsubscribe, send email to csound-unsubscribe@lists.bath.ac.uk

Date2005-09-20 16:45
FromIstvan Varga
SubjectRe: [Csnd] Csound real-time CPU performance in Linux
Anthony Kozar wrote:

> The freeverb opcode is likely the problem.  Reverbs are very CPU intensive
> and you are getting a separate instance of freeverb for each note.  Try
> moving the freeverb (and outs) to a separate instrument (with higher number)
> and using global variables to route the output of each note to the reverb.
> Then, only create a single i-statement for the reverb instrument in your
> score.

While the freeverb opcode does not actually use more than a few percents of CPU
time even on my old 1.3 GHz CPU, running it in a separate instrument is definitely
useful not only for the improved performance, but also to allow the reverb to fade
out without having to extend the note duration by several seconds.
It is important, however, to filter the signal with the 'denorm' opcode (adds
noise at a very low level, something like 1e-20) before applying the reverb,
because freeverb (and in fact many other reverb and IIR filter opcodes as well)
can slow down by a factor of up to 100 in the case of long silent sections of
input that result in the reverb level decaying to denormalized range.
Also, what is ksmps set to ? It may be trivial, but having ksmps less than 10
is not really good for real-time use.
-- 
Send bugs reports to this list.
To unsubscribe, send email to csound-unsubscribe@lists.bath.ac.uk

Date2005-09-20 16:50
FromIstvan Varga
SubjectRe: [Csnd] Csound real-time CPU performance in Linux
Hector Centeno wrote:

> Beside this problem I also found that while running Csound any video 
> activity produces clicks in the output (i.e. minimizing, maximizing or 
> opening windows, sequencer software redrawing the display, etc) even 
> while using very low CPU. This problem is not present using other audio 
> programs (e.g. ardour, jackrack, linuxsampler). This problem is reduced 
> by increasing the -B flag but obviously that makes latency higher.

Using the --sched flag may fix this, but beware that it requires running
Csound as root, and if the CPU usage reaches 100%, it may lock up the system.
The latter problem can be solved by running a "watchdog" utility (I posted
one to the list some time ago) in the background, that terminates real-time
processes if the CPU usage is too high for more than a few seconds.
-- 
Send bugs reports to this list.
To unsubscribe, send email to csound-unsubscribe@lists.bath.ac.uk

Date2005-09-20 16:56
FromHector Centeno
SubjectRe: [Csnd] Csound real-time CPU performance in Linux
Victor Lazzarini wrote:

> Tested here with a slightly older version of csound5 on windows (2.8 
> ghz),
> I could get 5 simultaneous notes. Because your envelope decay is quite
> long, you might actually be using up polyphony without noticing.
>
> Victor
>
> At 14:49 20/09/2005, you wrote:
>
>> Hi,
>>
>> I was wondering if the CPU usage of Csound in my Linux system is 
>> normal. I've been using Csound mainly for creating real-time midi 
>> instruments and I find myself often limited by the high use of CPU 
>> some opcodes have. For example, the following instrument won't let me 
>> play a polyphony higher than 3 notes:
>>
>> iamp                           ampmidi        7000
>> ifreq                           cpstmid        6
>> kenv                           linenr        iamp*5, 0, 1, .01
>> apure                         loscil        kenv, ifreq, 13, 1, 2, 1, 
>> 12911
>> apureCmb                 moogladder        apure, 400, 1
>> apurerL, apurerR     freeverb        apureCmb, apureCmb, 0, 0
>>                                   outs         apurerL, apurerR
>>
>> Trying more than 3 notes uses 100% of the CPU and sound crackling 
>> begins. In this case the moogladder seems to be using a lot of CPU 
>> but I don't know if this is an expected behaviour. My system consists 
>> of a Pentium 4HT 2.8 ghz, 1 gig ram using agnula Linux (with the 
>> tweaked kernel for realtime preemption) and a M-Audio Audiophile 
>> interface. I built Csound from CVS with the Jack module and Portmidi. 
>> I set the -b and -B flags according to the manual (matching Jack's 
>> that is presently using 128 frames, 2 periods).
>>
>> Beside this problem I also found that while running Csound any video 
>> activity produces clicks in the output (i.e. minimizing, maximizing 
>> or opening windows, sequencer software redrawing the display, etc) 
>> even while using very low CPU. This problem is not present using 
>> other audio programs (e.g. ardour, jackrack, linuxsampler). This 
>> problem is reduced by increasing the -B flag but obviously that makes 
>> latency higher.
>>
>> Thanks in advance,
>>
>> Hector
>> -- 
>> Send bugs reports to this list.
>> To unsubscribe, send email to csound-unsubscribe@lists.bath.ac.uk
>
>
> Victor Lazzarini
> Music Technology Laboratory
> Music Department
> National University of Ireland, Maynooth

Thank you for testing. I can't get more than 3 simultaneous notes and 
for testing I'm simply pressing the keys on my keyboard and holding them 
without releasing so the envelope shouldn't be a problem. I tried taking 
out the freeverb opcode and the performance is exactly the same. It 
seems that for some reason my system has less power than yours even 
though we have the same processor speed and agnula Linux is supposed to 
be lightweighted (is the OS make a difference here?). Any ideas about my 
other problem? (the crackling with the video activity, it happens even 
with simple instruments)

Hector
-- 
Send bugs reports to this list.
To unsubscribe, send email to csound-unsubscribe@lists.bath.ac.uk

Date2005-09-20 17:18
FromHector Centeno
SubjectRe: [Csnd] Csound real-time CPU performance in Linux
Istvan Varga wrote:

> Anthony Kozar wrote:
>
>> The freeverb opcode is likely the problem.  Reverbs are very CPU 
>> intensive
>> and you are getting a separate instance of freeverb for each note.  Try
>> moving the freeverb (and outs) to a separate instrument (with higher 
>> number)
>> and using global variables to route the output of each note to the 
>> reverb.
>> Then, only create a single i-statement for the reverb instrument in your
>> score.
>
>
> While the freeverb opcode does not actually use more than a few 
> percents of CPU
> time even on my old 1.3 GHz CPU, running it in a separate instrument 
> is definitely
> useful not only for the improved performance, but also to allow the 
> reverb to fade
> out without having to extend the note duration by several seconds.
> It is important, however, to filter the signal with the 'denorm' 
> opcode (adds
> noise at a very low level, something like 1e-20) before applying the 
> reverb,
> because freeverb (and in fact many other reverb and IIR filter opcodes 
> as well)
> can slow down by a factor of up to 100 in the case of long silent 
> sections of
> input that result in the reverb level decaying to denormalized range.
> Also, what is ksmps set to ? It may be trivial, but having ksmps less 
> than 10
> is not really good for real-time use.

Thanks a lot for your reply and for the information about freeverb. I 
have ksmps set to 10.
I guess what I get is what my system and Csound can normally deliver so 
I'll learn to live with it.

cheers,

Hector
-- 
Send bugs reports to this list.
To unsubscribe, send email to csound-unsubscribe@lists.bath.ac.uk

Date2005-09-20 18:07
FromVictor Lazzarini
SubjectRe: [Csnd] Csound real-time CPU performance in Linux
I was also running at ksmps= 10.

Victor

At 17:18 20/09/2005, you wrote:
>Istvan Varga wrote:
>
>>Anthony Kozar wrote:
>>
>>>The freeverb opcode is likely the problem.  Reverbs are very CPU intensive
>>>and you are getting a separate instance of freeverb for each note.  Try
>>>moving the freeverb (and outs) to a separate instrument (with higher number)
>>>and using global variables to route the output of each note to the reverb.
>>>Then, only create a single i-statement for the reverb instrument in your
>>>score.
>>
>>
>>While the freeverb opcode does not actually use more than a few percents 
>>of CPU
>>time even on my old 1.3 GHz CPU, running it in a separate instrument is 
>>definitely
>>useful not only for the improved performance, but also to allow the 
>>reverb to fade
>>out without having to extend the note duration by several seconds.
>>It is important, however, to filter the signal with the 'denorm' opcode (adds
>>noise at a very low level, something like 1e-20) before applying the reverb,
>>because freeverb (and in fact many other reverb and IIR filter opcodes as 
>>well)
>>can slow down by a factor of up to 100 in the case of long silent sections of
>>input that result in the reverb level decaying to denormalized range.
>>Also, what is ksmps set to ? It may be trivial, but having ksmps less than 10
>>is not really good for real-time use.
>
>Thanks a lot for your reply and for the information about freeverb. I have 
>ksmps set to 10.
>I guess what I get is what my system and Csound can normally deliver so 
>I'll learn to live with it.
>
>cheers,
>
>Hector
>--
>Send bugs reports to this list.
>To unsubscribe, send email to csound-unsubscribe@lists.bath.ac.uk

Victor Lazzarini
Music Technology Laboratory
Music Department
National University of Ireland, Maynooth 

-- 
Send bugs reports to this list.
To unsubscribe, send email to csound-unsubscribe@lists.bath.ac.uk

Date2005-09-20 18:08
FromIstvan Varga
SubjectRe: [Csnd] Csound real-time CPU performance in Linux
Hector Centeno wrote:

> Thanks a lot for your reply and for the information about freeverb. I 
> have ksmps set to 10.
> I guess what I get is what my system and Csound can normally deliver so 
> I'll learn to live with it.

Well, something could definitely be improved as I can run 4 instances
of the instrument (with sr=48000, ksmps=10, -b 64, -B 1024), but on
a CPU that is less than half as fast. I do not know the reason of this
difference, but one thing that you should try is using less expensive
filters instead of moogladder.
-- 
Send bugs reports to this list.
To unsubscribe, send email to csound-unsubscribe@lists.bath.ac.uk

Date2005-09-20 22:48
FromIain Duncan
SubjectRe: [Csnd] Csound real-time CPU performance in Linux
Something must be wrong in the setup I think. I can run bundles of 
moogvcfs on my system in real time, along with crap loads of other 
stuff. ( AMD 3000+ ) Pretty sure we have at least 10 moogvcfs as well as 
couple of reverbs and loads of delays. You definitely get better 
performance using:

-+rtaudio=alsa --expression-opt --sched

I am using Gentoo linux with a 2.6.12 kernel patched for lowlatency and 
csound5.

Iain


Victor Lazzarini wrote:
> The moog filter is a little costly in terms of computation, but that
> can be improved perhaps (I know how just have to get round to doing it).
> Mind you, I tried the moogvcf and that one is even worse (could only get
> 2 simultaneous notes without dropouts).
> 
> Victor
> 
> At 14:49 20/09/2005, you wrote:
> 
>> Hi,
>>
>> I was wondering if the CPU usage of Csound in my Linux system is 
>> normal. I've been using Csound mainly for creating real-time midi 
>> instruments and I find myself often limited by the high use of CPU 
>> some opcodes have. For example, the following instrument won't let me 
>> play a polyphony higher than 3 notes:
>>
>> iamp                           ampmidi        7000
>> ifreq                           cpstmid        6
>> kenv                           linenr        iamp*5, 0, 1, .01
>> apure                         loscil        kenv, ifreq, 13, 1, 2, 1, 
>> 12911
>> apureCmb                 moogladder        apure, 400, 1
>> apurerL, apurerR     freeverb        apureCmb, apureCmb, 0, 0
>>                                   outs         apurerL, apurerR
>>
>> Trying more than 3 notes uses 100% of the CPU and sound crackling 
>> begins. In this case the moogladder seems to be using a lot of CPU but 
>> I don't know if this is an expected behaviour. My system consists of a 
>> Pentium 4HT 2.8 ghz, 1 gig ram using agnula Linux (with the tweaked 
>> kernel for realtime preemption) and a M-Audio Audiophile interface. I 
>> built Csound from CVS with the Jack module and Portmidi. I set the -b 
>> and -B flags according to the manual (matching Jack's that is 
>> presently using 128 frames, 2 periods).
>>
>> Beside this problem I also found that while running Csound any video 
>> activity produces clicks in the output (i.e. minimizing, maximizing or 
>> opening windows, sequencer software redrawing the display, etc) even 
>> while using very low CPU. This problem is not present using other 
>> audio programs (e.g. ardour, jackrack, linuxsampler). This problem is 
>> reduced by increasing the -B flag but obviously that makes latency 
>> higher.
>>
>> Thanks in advance,
>>
>> Hector
>> -- 
>> Send bugs reports to this list.
>> To unsubscribe, send email to csound-unsubscribe@lists.bath.ac.uk
> 
> 
> Victor Lazzarini
> Music Technology Laboratory
> Music Department
> National University of Ireland, Maynooth
-- 
Send bugs reports to this list.
To unsubscribe, send email to csound-unsubscribe@lists.bath.ac.uk

Date2005-09-20 22:51
FromIain Duncan
SubjectRe: [Csnd] Csound real-time CPU performance in Linux
> Thanks a lot for your reply and for the information about freeverb. I 
> have ksmps set to 10.
> I guess what I get is what my system and Csound can normally deliver so 
> I'll learn to live with it.

Aha, that's the problem. For live use, one is much better off setting 
ksmps to 64 or even 128, and then making anything that needs to be 
smooth an audio rate signal, or interpolate when necessary. I find that 
as long as my amplitude controls are all a-rate, the sound degradation 
is really not too noticeable, but the real time capability is massively 
increased. Pitch controls seem to be fine at krate, ksmp=64.

I also run a light weight window manager ( fluxbox ).

Hope that helps!
Iain
-- 
Send bugs reports to this list.
To unsubscribe, send email to csound-unsubscribe@lists.bath.ac.uk

Date2005-09-20 22:52
FromIain Duncan
SubjectRe: [Csnd] Csound real-time CPU performance in Linux
>> Beside this problem I also found that while running Csound any video 
>> activity produces clicks in the output (i.e. minimizing, maximizing or 
>> opening windows, sequencer software redrawing the display, etc) even 
>> while using very low CPU. This problem is not present using other 
>> audio programs (e.g. ardour, jackrack, linuxsampler). This problem is 
>> reduced by increasing the -B flag but obviously that makes latency 
>> higher.
> 
> 
> Using the --sched flag may fix this, but beware that it requires running
> Csound as root, and if the CPU usage reaches 100%, it may lock up the 
> system.
> The latter problem can be solved by running a "watchdog" utility (I posted
> one to the list some time ago) in the background, that terminates real-time
> processes if the CPU usage is too high for more than a few seconds.

Istvan, do you think you could add that watchdog utility to the packages 
available on Sourceforge?

Thanks
Iain
-- 
Send bugs reports to this list.
To unsubscribe, send email to csound-unsubscribe@lists.bath.ac.uk

Date2005-09-21 02:25
FromHector Centeno
SubjectRe: [Csnd] Csound real-time CPU performance in Linux
Iain Duncan wrote:

>
>> Thanks a lot for your reply and for the information about freeverb. I 
>> have ksmps set to 10.
>> I guess what I get is what my system and Csound can normally deliver 
>> so I'll learn to live with it.
>
>
> Aha, that's the problem. For live use, one is much better off setting 
> ksmps to 64 or even 128, and then making anything that needs to be 
> smooth an audio rate signal, or interpolate when necessary. I find 
> that as long as my amplitude controls are all a-rate, the sound 
> degradation is really not too noticeable, but the real time capability 
> is massively increased. Pitch controls seem to be fine at krate, ksmp=64.
>
> I also run a light weight window manager ( fluxbox ).
>
> Hope that helps!
> Iain

thanks for your advice... I did set ksmps to 128 and still can't get 
more than 3 instances running at the same time... strange, eh?? 
Something should be wrong with my system or maybe the way I compiled Csound.

hector
-- 
Send bugs reports to this list.
To unsubscribe, send email to csound-unsubscribe@lists.bath.ac.uk

Date2005-09-23 10:20
FromIstvan Varga
SubjectRe: [Csnd] Csound real-time CPU performance in Linux
Iain Duncan wrote:

> Istvan, do you think you could add that watchdog utility to the packages 
> available on Sourceforge?

There is a new format for the --sched option that creates a watchdog
thread running at a high priority (so that it is not locked up by the
audio thread). This will terminate if the CPU usage exceeds some limit
for a specified amount of time. For example:

   --sched=99,98,5

this will run the audio thread with SCHED_RR policy and a priority of
99 (can be changed in case there are multiple real time processes), and
checks the average CPU usage every 5 seconds, terminating if it is more
than 98 percent.
This feature is not well tested yet, so feedback on how well it works
in practice is welcome.

By the way, there is also --sched=-20 to run with a nice level of -20;
this is safer than SCHED_RR, but is not as effective at preventing
dropouts in the audio output.
-- 
Send bugs reports to this list.
To unsubscribe, send email to csound-unsubscribe@lists.bath.ac.uk