Csound Csound-dev Csound-tekno Search About

Some suggestion about little enhancements to existing opcodes

Date1999-09-04 10:34
FromGabriel Maldonado
SubjectSome suggestion about little enhancements to existing opcodes
Hallo john,
here are some hints to enhance some existing opcode.
---------------------
powoftwo and logbtwo can run at a-rate by simply adding the following
lines to entry.c:

{ "powoftwo_a",S(EVAL),    4,      "a",    "a",    NULL, NULL 
,powoftwo          },
{ "logbtwo_a",S(EVAL),    4,      "a",    "a",    NULL, NULL, 
logbasetwo     },
---------------------

poscil family can support negative frequencies by simply adding the
corresponding code:

void posc(POSC *p)
{
    float	*out = p->out, *ft = p->ftp->ftable;
    float	*curr_samp, fract;
    double	phs = p->phs;
    double      si = *p->freq * p->tablen / esr;
    long	n = ksmps;
    float       amp = *p->amp;

    do {
      curr_samp = ft + (long)phs;
      fract     = (float)(phs - (long)phs);
      *out++    = amp * (*curr_samp +(*(curr_samp+1)-*curr_samp)*fract);
      phs      += si;
      while (phs >= p->tablen)
        phs -= p->tablen;
      while (phs < 0 )			/********** HERE IS THE CODE TO ADD ******/
        phs += p->tablen;		/*****************************************/

    } while (--n);
    p->phs = phs;
}
... and so on for kposc(), lposc(), posc3() etc. I will send you the
complete file in anoter message. 
Notice that poscil family allows to use function tables whose length is
not a power of two (with a very little modification in the
initialization code). 
What do you think to extend GEN functions in order to allow to create
non-power-of-two tables? One can use a negative number to indicate the
table number that will skip power-of-two checking.

-------------------------

wguide1 and wguide2 cannot vary the frequency continusly without an
audible distortion when kr is different from sr. This happens because
the frequency input argument of these opcodes is k-type. I strongly
suggest to change it to a-rate. This will allow also hybrid FM with an
oscillator modulating the the frequency of wguide instruments. THe
modification is very very simple. I send the source file in a separate
message.

--------------------------

At present time the phase of phasor opcode is stored into a float
variable. What do you think to store it in a double variable? This will
improve frequency resolution of phasor a lot, practically without
slowing speed.

It is sufficient to change the structure of phasor as follows:

typedef struct {
	OPDS	h;
	float	*sr, *xcps, *iphs;
	float	curphs;
} PHSOR;

...into...

typedef struct {
	OPDS	h;
	float	*sr, *xcps, *iphs;
	double	curphs;
} PHSOR;

and, in the declaration section of kphsor()and phsor() functions
change...

float	phs;

...into...

double	phs;

Please tell me if you intend to make these little modifications.

Best

-- 
Gabriel Maldonado

http://web.tiscalinet.it/G-Maldonado/home2.htm