Csound Csound-dev Csound-tekno Search About

Fwd: Re: Linux Csound and Posix.1b

Date1998-06-28 01:25
FromPaul Winkler
SubjectFwd: Re: Linux Csound and Posix.1b
Dear folks,

I'm posting this because it came up in a private correspondence and I 
thought it might be of interest. I don't really know *anything* about 
posix.1b , and I'm way too new to system programming to really 
understand this, but Jay seemed to think it might be worth looking into 
as a way to improve the Linux (and Solaris?) version's realtime 
performance. As long as it didn't cause the linux version to 
irretrievably fork, this sounds interesting to me...

(We were talking about csound realtime output. Jay hasn't tried csound 
yet; I was telling him about it. I've noted which of us said what, for 
clarity.)

>Date: Sat, 27 Jun 1998 16:16:18 -0700
>From: Jay Ts 
>To: zarmzarm@hotmail.com
>Subject: Re: Csound and sound synthesis
(snip)

Jay:
>> >Is that "realtime" as in POSIX.1b real time?
>>

Paul:
>> I don't think so. Csound has realtime outs in the Mac and Windows
>> versions, too.

Jay:
>> > I was just looking over
>> >that (it was added to Linux recently (and Solaris too), and is now 
used
>> >by cdrecord to avoid buffer underruns while burning CD-Rs).  If 
Csound
>> >doesn't have it, it looks like it would be simple to add.  See 'man 
2
>> >sched_setscheduler' for details.  Also 'man 2 mlockall'.

Paul:
>> Interesting. This would meet with some resistance in the Csound
>> community, though, since one of the things people like about it is a
>> high degree of platform independence.

Jay:
>It is (in theory, at least) possible to have platform independence and
>support all platforms well.
>
>Adding POSIX.1b support would apparently simply be a matter of adding
>some pieces of code like,
>
>#ifdef LINUX
>        /* realtime code here */
>#endif
>
>I do not pretend to be an expert, or anywere near, on POSIX.1b at the
>moment, but I've looked at the manual pages, and it *looks* very
>simple!  During initialization, simply call mlockall() to lock all the
>process' pages into memory, then do a sched_setscheduler() to add the
>process to the real-time queue.  Like this:
>
>#include 
>#include 
>
>main()
>{
>        struct sched_param s_parm;
>
>        /* lock *all* pages into memory */
>        if(mlockall(MCL_FUTURE) == -1) perror("mlockall");
>
>        /* make this process a real-time one */
>        s_parm.sched_priority = 1;      /* can be 1-99 */
>        if(sched_setscheduler(0,SCHED_FIFO,&s_parm) == -1)
>                perror("sched_setscheduler");
>
>        /* from here on, operate in real-time mode */
>        printf("hello, world\n");
>}
>
>At least that seemed to work when run with superuser (root) permissions
>(required for the mlockall() and sched_setscheduler() calls).  You 
might
>try throwing the above code into csound's main() routine near the start
>and see if it makes any difference.  You might get lucky.  Hopefully, 
it
>will not lock up your system, which will happen if the real-time 
process
>enters an infinite loop (containing no system calls)!

(end of mail excerpt)

Regards,

PW

______________________________________________________
Get Your Private, Free Email at http://www.hotmail.com

Date1998-06-28 13:53
FromNicola Bernardini
SubjectRe: Fwd: Re: Linux Csound and Posix.1b
Dear Paul,

I think you are bringing up some interesting points, at least for
the linux community.

On Sun, 28 Jun 1998, Paul Winkler wrote:

[snip]
> Jay:
> >> >Is that "realtime" as in POSIX.1b real time?

I think we are talking about two different things:

1) "realtime" in csound means that the samples are spitted out as they
   are being calculated; if the machine makes it in time to calculate
   the next sample (or the next buffer) before the next sample is
   actually due out, you're in real real-time, otherwise you're not
   (your sound gets chopped off - has a hole in it)

2) "realtime" in Linux (and indeed, in all unix systems) is totally another
   story (and a very hairy one at that); it implies that the process that
   is actually running in real-time is *guaranteed* to make it before
   the next *hardware* deadline (i.e. an interrupt or something) is
   met; all these system calls (set_scheduler(), mlockall() etc.) are
   dealing with this hairy problem.

Now, AFAIK, last time I tried Posix 1003.1b (ex-Posix.4) calls on my
2.0.xx kernel half of them were not implemented (mlockall() in particular).
I have noticed that the linux pd porting by guenter geiger is sporting
a couple of set_scheduler() calls and that pd is actually running
nicely and smoothly when other processes are running on the same machine.
Besides, I think that the real serious hacking that is happening/has
happened on 2.1 kernels has to do with Posix.1b calls and handling.
So, we could probably think about doing that to allow csound to run
smoothly in real-time situation. But instead of putting lots of #ifdefs
all over the place, I would just add two calls:

	enter_real_time();
	....
	exit_real_time();

and then make all the implementations on different files:

realtime-linux.c
realtime-win95.c
realtime-dummy.c
etc.

so that anyone can write and link the correct file (just as it has been
done for the windowing system) and it would be a nice and clean little
job that can be done better and better as kernel stuff gets available.
(The boring part of it is that csound would need to run as super-user
and/or suid; but there's little to do about that).

Btw, I am no expert on Posix.1b at all, but I happen to have a couple
of books which help me a lot in these cases:

"Posix programmer's guide" by Donald Lewine (O'Reilly)
"Posix.4" by Bill Gallmeister (O'Reilly)

(These O'Reilly books are real nice for these kind of things).

ciao

Nicola

------------------------------------------------------------------------
Nicola Bernardini
E-mail: nicb@axnet.it
 
Re graphics: A picture is worth 10K words -- but only those to describe
the picture.  Hardly any sets of 10K words can be adequately described
with pictures.




Received: from stork.maths.bath.ac.uk by omphalos.maths.Bath.AC.UK id aa05441;
          28 Jun 98 15:22 BST
Received: from pat.bath.ac.uk by stork.maths.Bath.AC.UK id aa12608;
          28 Jun 98 15:22 BST
Received: (qmail 21063 invoked from network); 28 Jun 1998 14:22:04 -0000
Received: from hermes.ex.ac.uk (HELO exeter.ac.uk) (144.173.6.14)
  by pat.bath.ac.uk with SMTP; 28 Jun 1998 14:22:04 -0000
Received: from noether [144.173.8.10] by hermes via SMTP (PAA04868); Sun, 28 Jun 1998 15:15:28 +0100 (BST)
Received: from hermes.ex.ac.uk by maths.ex.ac.uk; Sun, 28 Jun 98 15:14:55 +0100
Received: from lt@westnet.com [206.24.6.2] by hermes via ESMTP (PAA13703); Sun, 28 Jun 1998 15:14:45 +0100 (BST)
Received: from localhost (lt@localhost)
	by westnet.com (8.9.0/8.9.0) with SMTP id KAA16460;
	Sun, 28 Jun 1998 10:14:38 -0400 (EDT)
Date: Sun, 28 Jun 1998 10:14:36 -0400 (EDT)
From: Larry Troxler 
To: Paul Winkler 
Cc: csound@maths.ex.ac.uk
Subject: Re: Fwd: Re: Linux Csound and Posix.1b
In-Reply-To: <19980628082550.3824.qmail@hotmail.com>
Message-Id: 
Mime-Version: 1.0
Content-Type: TEXT/PLAIN; charset=US-ASCII
Sender: owner-csound-outgoing@maths.ex.ac.uk
Precedence: bulk


AFAIK, Linux Csound already uses the Posix real-time scheduling. At least,
my copy does.

It would be pretty much impossible to use it as a MIDI instrument without
it.

Larry


--  Larry Troxler  --  lt@westnet.com  --  Patterson, NY USA  --
  




Received: from stork.maths.bath.ac.uk by omphalos.maths.Bath.AC.UK id aa06032;
          28 Jun 98 23:49 BST
Received: from mercury.bath.ac.uk by stork.maths.Bath.AC.UK id aa26385;
          28 Jun 98 23:49 BST
Received: (qmail 27210 invoked from network); 28 Jun 1998 22:49:17 -0000
Received: from hermes.ex.ac.uk (HELO exeter.ac.uk) (144.173.6.14)
  by mercury.bath.ac.uk with SMTP; 28 Jun 1998 22:49:17 -0000
Received: from noether [144.173.8.10] by hermes via SMTP (XAA06536); Sun, 28 Jun 1998 23:41:38 +0100 (BST)
Received: from hermes.ex.ac.uk by maths.ex.ac.uk; Sun, 28 Jun 98 23:41:14 +0100
Received: from mail1.doit.wisc.edu [144.92.9.40] by hermes via ESMTP (XAA08019); Sun, 28 Jun 1998 23:41:07 +0100 (BST)
Received: from [206.173.190.231] by mail1.doit.wisc.edu
          id RAA20972 (8.8.6/50); Sun, 28 Jun 1998 17:40:57 -0500
Message-Id: 
In-Reply-To: <19980627032936.19849.qmail@hotmail.com>
Mime-Version: 1.0
Content-Type: text/plain; charset="us-ascii"
Date: Sun, 28 Jun 1998 17:44:36 -0500
To: Paul Winkler , csound@maths.ex.ac.uk
From: "Daniel W. Hosken" 
Subject: RE: [??theory] ambient music, harmony
Sender: owner-csound-outgoing@maths.ex.ac.uk
Precedence: bulk

The revised edition in paperback (1992) of the Pierce book is published by
W.H. Freeman and Co (ISBN: 07167-6005-3). I don't know if the Scientific
American Library version is still in print or not.

I also think that this book is an excellent introduction to acoustics and
psychoacoustics.

--Dan Hosken

At 8:29 PM -0700 6/26/98, Paul Winkler wrote:
>As long as we're bringing up books on basic psychoacoustic (= perception
>of sound) theory, I can't help recommending "The Science of Musical
>Sound" by John R. Pierce (pub: Scientific American Library, ISBN:
>0-7167-1508-2).
>Check your library, or buy it if it's still in print.







Received: from stork.maths.bath.ac.uk by omphalos.maths.Bath.AC.UK id aa06946;
          29 Jun 98 10:31 BST
Received: from mercury.bath.ac.uk by stork.maths.Bath.AC.UK id aa11155;
          29 Jun 98 10:31 BST
Received: (qmail 23763 invoked from network); 29 Jun 1998 09:31:26 -0000
Received: from hermes.ex.ac.uk (HELO exeter.ac.uk) (144.173.6.14)
  by mercury.bath.ac.uk with SMTP; 29 Jun 1998 09:31:26 -0000
Received: from noether [144.173.8.10] by hermes via SMTP (KAA04424); Mon, 29 Jun 1998 10:23:02 +0100 (BST)
Received: from hermes.ex.ac.uk by maths.ex.ac.uk; Mon, 29 Jun 98 10:22:32 +0100
Received: from f10.hotmail.com [207.82.250.21] by hermes via SMTP (KAA12882); Mon, 29 Jun 1998 10:22:25 +0100 (BST)
Received: (qmail 24129 invoked by uid 0); 29 Jun 1998 09:22:00 -0000
Message-Id: <19980629092200.24128.qmail@hotmail.com>
Received: from 207.172.192.1 by www.hotmail.com with HTTP;
	Mon, 29 Jun 1998 02:21:59 PDT
X-Originating-Ip: [207.172.192.1]
From: Paul Winkler 
To: RWD@cableinet.co.uk
Cc: csound@maths.ex.ac.uk
Subject: Re: Pitch Hell, was: Harmonics, physics, chords etc.
Content-Type: text/plain
Date: Mon, 29 Jun 1998 02:21:59 PDT
Sender: owner-csound-outgoing@maths.ex.ac.uk
Precedence: bulk

Good God! Richard, I can't imagine trying to play in those 
circumstances! I have a hard enough time dealing with being in a rock 
band where all the pitched instruments are pretty much fixed intonation. 
(except voice of course).

Which reminds me of another curious phenomenon -- has anyone else 
noticed apparent pitch changing as a function of volume? I can hear as 
much as a quarter-tone shift when we go from a loud part to a quiet part 
-- it's vivid at the time, but nonexistent on tapes of the event (which 
of course are listened to at much lower volume). But the tape does 
reveal that I'm singing hopelessly sharp on the loud sections, by trying 
to match the upward shift I hear! This happens to me all the time, 
though I'm slowly learning to compensate. Am I just crazy?

regards,

PW

(snip)
>As a flute player, I have to deal with this problem any time I play in 
an
>orchestra. As I will often be playing the highest note in the wind 
section, any
>deviation from good tuning will have a devastating effect on the 
harmoniousness
>of the whole section. A group of expert players will be continually
>'negotiating' tuning amonst themselves to reduce beats and inharmonic 
resultant
>tones to a minimum, the ultimate determinant generally being the bass 
note - but
>less so if that note is not the root of the chord. There has been 
little
>research into exactly how this is managed, but I feel that knowledge of 
the
>primary principles of harmony is crucial - we learn to hear what the 
harmonic
>root note is, of any chord we are playing, whether at the top, the 
bass, or in
>the middle, and negotiate tuning towards that note. Needless to say, 
equal
>temperament has little to offer here - we create new mean-tone tunings
>on-the-fly, as it were.
(snip)
>Richard Dobson


______________________________________________________
Get Your Private, Free Email at http://www.hotmail.com



Received: from stork.maths.bath.ac.uk by omphalos.maths.Bath.AC.UK id aa06953;
          29 Jun 98 10:33 BST
Received: from pat.bath.ac.uk by stork.maths.Bath.AC.UK id aa11181;
          29 Jun 98 10:33 BST
Received: (qmail 20747 invoked from network); 29 Jun 1998 09:32:59 -0000
Received: from hermes.ex.ac.uk (HELO exeter.ac.uk) (144.173.6.14)
  by pat.bath.ac.uk with SMTP; 29 Jun 1998 09:32:59 -0000
Received: from noether [144.173.8.10] by hermes via SMTP (KAA22646); Mon, 29 Jun 1998 10:25:27 +0100 (BST)
Received: from hermes.ex.ac.uk by maths.ex.ac.uk; Mon, 29 Jun 98 10:24:48 +0100
Received: from f173.hotmail.com [207.82.251.59] by hermes via SMTP (KAA19912); Mon, 29 Jun 1998 10:24:41 +0100 (BST)
Received: (qmail 4563 invoked by uid 0); 29 Jun 1998 09:24:16 -0000
Message-Id: <19980629092416.4562.qmail@hotmail.com>
Received: from 207.172.192.1 by www.hotmail.com with HTTP;
	Mon, 29 Jun 1998 02:24:15 PDT
X-Originating-Ip: [207.172.192.1]
From: Paul Winkler 
To: lt@westnet.com
Cc: csound@maths.ex.ac.uk
Subject: Re: Fwd: Re: Linux Csound and Posix.1b
Content-Type: text/plain
Date: Mon, 29 Jun 1998 02:24:15 PDT
Sender: owner-csound-outgoing@maths.ex.ac.uk
Precedence: bulk

Whoops! That's what I get for not doing a grep on the sources before 
bringing up this subject!

regards,

PW

p.s. Hey Larry -- where's Patterson? I'm in Brooklyn.

>Date: Sun, 28 Jun 1998 10:14:36 -0400 (EDT)
>From: Larry Troxler 
>To: Paul Winkler 
>cc: csound@noether.ex.ac.uk
>Subject: Re: Fwd: Re: Linux Csound and Posix.1b
>
>
>AFAIK, Linux Csound already uses the Posix real-time scheduling. At 
least,
>my copy does.
>
>It would be pretty much impossible to use it as a MIDI instrument 
without
>it.
>
>Larry
>
>
>--  Larry Troxler  --  lt@westnet.com  --  Patterson, NY USA  --
>  
>
>


______________________________________________________
Get Your Private, Free Email at http://www.hotmail.com



Received: from stork.maths.bath.ac.uk by omphalos.maths.Bath.AC.UK id aa07054;
          29 Jun 98 11:37 BST
Received: from pat.bath.ac.uk by stork.maths.Bath.AC.UK id aa13309;
          29 Jun 98 11:37 BST
Received: (qmail 25667 invoked from network); 29 Jun 1998 10:37:29 -0000
Received: from hermes.ex.ac.uk (HELO exeter.ac.uk) (144.173.6.14)
  by pat.bath.ac.uk with SMTP; 29 Jun 1998 10:37:29 -0000
Received: from noether [144.173.8.10] by hermes via SMTP (LAA12078); Mon, 29 Jun 1998 11:19:39 +0100 (BST)
Received: from hermes.ex.ac.uk by maths.ex.ac.uk; Mon, 29 Jun 98 11:19:05 +0100
Received: from jaguars-int.cableinet.net [193.38.113.9] by hermes via SMTP (LAA14922); Mon, 29 Jun 1998 11:18:58 +0100 (BST)
Received: (qmail 19320 invoked from network); 29 Jun 1998 10:12:07 -0000
Received: from unknown (HELO cableinet.co.uk) (194.117.146.163)
  by jaguars with SMTP; 29 Jun 1998 10:12:07 -0000
Message-Id: <359768DB.357036CC@cableinet.co.uk>
Date: Mon, 29 Jun 1998 11:13:47 +0100
From: Richard Dobson 
Organization: Composers Desktop project
X-Mailer: Mozilla 4.04 [en] (Win95; I)
Mime-Version: 1.0
To: csound@maths.ex.ac.uk
Subject: Re: Pitch Hell, was: Harmonics, physics, chords etc.
References: <19980629092200.24128.qmail@hotmail.com>
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Sender: owner-csound-outgoing@maths.ex.ac.uk
Precedence: bulk

In practice, it's mostly instinctual, and, also, for modern wind instruments,
tuning is cloesly connected to tone quality - by trying to get the best colour
on a note, there's a strong likelihood of it being in tune too. By contrast, I
recently took up baroque flute, and playing it in tune is desperately hard, not
only because the instrument is innately afflicted that way, but because I have
yet to learn what each note sounds like, when in tune.

Re loudness effects: the phenomenon has been reported in psycho-acoustic tests,
where a tone played at full volume (through speakers or headphones) is perceived
as dropping in pitch, compared to the same tone played softly. It is easy to
explore this with headphones, for example. Many musicians exploit this,
unconsciously or ortherwise, by playing quiet notes a little sharp, to suggest
even greater quietness. Of course, quiet notes have little acoustic energy, and
are thus less likely to clash with other sounds. Loud sharp notes are much more
apparent! Unfortunately, it happens all too often, as performers attempt to get
more power and brilliance in their sound. Most musicians are guilty of this from
time to time, but string-players seem especially susceptible - they take their A
from the oboe, and then play sharper anyway... :-(

Also, if you are singing, you are presumably singing the melody, and you may
simply be using what I call the 'melodic' scale, rather than the 'harmonic'
scale. The former is Pythagorean, and has high thirds, sixths and sevenths
(especially in ascending passages), whereas the latter is mean-tone with small
(pure) thirds, etc. It is also more remote from equal temperament, and thus for
many singers much more difficult to achieve. It's a BIG topic! The real trick, I
have found, is to discover what the legitimately 'mobile' notes are, which you
can then place slightly higher or lower in pitch, for expressive effect. This is
usually very context-dependent. Many singers pitch the minor third too low, and
drop desperately in tuning thereafter. Similarly, if the major third or seventh
is pitched too high (which it might well be for expressive reasons), but the
folowing semitone is also too wide, then your overall pitch has just gone
through the barrier. Indian classical musicians are the consummate experts in
this art - helped by the fact they have a secure drone to work with, and nothing
so tiresome as equal temperament to muddy the waters.

To bring this topic a little more into the Csound fold, perhaps there is a need
for an opcode to reconfigure the cpspch calculations, for different scales?


Richard Dobson

Paul Winkler wrote:
> 
> Good God! Richard, I can't imagine trying to play in those
> circumstances! I have a hard enough time dealing with being in a rock
> band where all the pitched instruments are pretty much fixed intonation.
> (except voice of course).
> 
> Which reminds me of another curious phenomenon -- has anyone else
> noticed apparent pitch changing as a function of volume? I can hear as
> much as a quarter-tone shift when we go from a loud part to a quiet part
> -- it's vivid at the time, but nonexistent on tapes of the event (which
> of course are listened to at much lower volume). But the tape does
> reveal that I'm singing hopelessly sharp on the loud sections, by trying
> to match the upward shift I hear! This happens to me all the time,
> though I'm slowly learning to compensate. Am I just crazy?
>

Date1998-06-28 15:14
FromLarry Troxler
SubjectRe: Fwd: Re: Linux Csound and Posix.1b
AFAIK, Linux Csound already uses the Posix real-time scheduling. At least,
my copy does.

It would be pretty much impossible to use it as a MIDI instrument without
it.

Larry


--  Larry Troxler  --  lt@westnet.com  --  Patterson, NY USA  --