Csound Csound-dev Csound-tekno Search About

[Cs-dev] Bug report : csound5 output has problems

Date2005-12-27 13:29
FromErik de Castro Lopo
Subject[Cs-dev] Bug report : csound5 output has problems
Hi all,

I found a .ORC and .SCO (inclueded below) which generates a single
bass drum hit on the Csounds.com site.

When I run these through csound5 I get a portion of the output waveform
whic should be zero being decidedly non-zero as can seen here:

    http://www.mega-nerd.com/tmp/bd10.png

I also have Csound Version 4.23f12 installed on this machine and when
it is given the same .ORC and >SCO it does not suffer the same problem.

Cheers,
Erik


;=========================================================================
; bd10.orc by Istvan Varga
sr	=  48000
ksmps	=  2
nchnls	=  1

; From "base_macros.h.orc"
#define MIDI2CPS(MIDI2CPSnot) # (exp(0.057762265*($MIDI2CPSnot)+2.10117844)) #
#define CPS2MIDI(CPS2MIDIcps) # ((log($CPS2MIDIcps)-2.10117844)*17.31234049) #



	seed 0
gax0	init 0

	instr 1

/* ------------------------------------------------------------------------- */

ivol	table 0,64	/* volume					*/
ibpm	table 1,64	/* tempo					*/

irel	table 2,64	/* release time					*/

istrtf1	table 3,64	/* start frequency 1				*/
ifdec1	table 4,64	/* freq. decay speed 1				*/
istrtf2	table 5,64	/* start frequency 2				*/
ifdec2	table 6,64	/* freq. decay speed 2				*/

insmix	table 7,64	/* noise mix					*/

iHP1f	table 8,64	/* HP filter 1 frequency / osc. freq.		*/
iBP1f	table 9,64	/* BP filter 1 frequency / osc. freq.		*/
iBP1b	table 10,64	/* BP filter 1 bandwidth / osc. freq.		*/

iHP2f	table 11,64	/* HP filter 2 frequency / osc. freq.		*/
iHP2m	table 12,64	/* HP filter 2 mix				*/
iHP3f	table 13,64	/* HP filter 3 frequency / osc. freq.		*/
iHP3m	table 14,64	/* HP filter 3 mix				*/

iHPxf	table 15,64	/* output HP filter frequency / note frequency	*/
iHPxr	table 16,64	/* output HP filter resonance			*/

iLPf1	table 17,64	/* output LP filter frequency 1 / osc. freq.	*/
iLPd1	table 18,64	/* output LP filter frequency 1 decay speed	*/
iLPf2	table 19,64	/* output LP filter frequency 2 / osc. freq.	*/
iLPd2	table 20,64	/* output LP filter frequency 2 decay speed	*/

iAM1s	table 21,64	/* amp. envelope 1 start value			*/
iAM1d	table 22,64	/* amp. envelope 1 decay speed			*/
iAM2s	table 23,64	/* amp. envelope 2 start value			*/
iAM2d	table 24,64	/* amp. envelope 2 decay speed			*/

/* ------------------------------------------------------------------------- */

ibtime	=  60/ibpm

p3	=  p3+irel+0.05

imkey	=  p4
imvel	=  p5

icps	=  $MIDI2CPS(imkey)
iamp	=  (0.0039+imvel*imvel/16192)*ivol
kamp	linseg 1,p3-(irel+0.05),1,irel,0,0.05,0

k_	port 1,ibtime/ifdec1,istrtf1		/* calculate base frequency */
k__	port 1,ibtime/ifdec2,istrtf2
kcps	=  icps*k_*k__

kfnum	=  int(256.5+$CPS2MIDI(kcps))		/* square oscillator */

a_	phasor kcps,0
a__	tableikt a_,kfnum,1,0,1
a___	tableikt a_,kfnum,1,0.5,1
a0	=  a__-a___

a_	unirand 2				/* noise generator */
a_	tone a_-1,kcps
a0	=  a0+a_*insmix

a1	=  a0	/* save osc. output */

a0	butterhp a0,iHP1f*kcps			/* HP filter 1 */

a0	butterbp a0,iBP1f*kcps,iBP1b*kcps	/* BP filter 1 */

a_	butterhp a1,iHP2f*kcps			/* HP filter 2 and 3 */
a__	butterhp a1,iHP3f*kcps
a0	=  a0+a_*iHP2m+a__*iHP3m

a0	butterhp a0,iHPxf*icps				/* output HP filter */
a0	pareq a0,iHPxf*icps,iHPxr*1.4142,iHPxr,0

k_	port 0,ibtime/iLPd1,iLPf1			/* output LP filter */
k__	port 0,ibtime/iLPd2,iLPf2
a0	butterlp a0,kcps*(k_+k__)

k_	expseg 1,ibtime/iAM1d,0.5			/* amp. envelopes */
k__	expseg 1,ibtime/iAM2d,0.5
k_	=  (1-k_)*(1-iAM1s)+iAM1s
k__	=  (1-k__)*(1-iAM2s)+iAM2s
a0	=  a0*k_*k__

gax0	=  gax0+(a0*iamp*kamp)

	endin

	instr 90

/* ----------------------- compressor parameters --------------------------- */

iamp	table 25,64	/* output volume				*/
iclpl	table 26,64	/* ouput clip level				*/
imxlvl	table 27,64	/* threshold level				*/
icomp1	table 28,64	/* compression ratio below thr. level		*/
icomp2	table 29,64	/* compression ratio above thr. level		*/
idel1	table 30,64	/* delay time in sec.				*/
iatt	table 31,64	/* envelope attack speed			*/
idec	table 32,64	/* envelope decay speed				*/
ifrq1	table 33,64	/* lowpass filter freq.				*/

/* ------------------------------------------------------------------------- */

icomp1	=  icomp1-1
icomp2	=  icomp2-1
klvl	init 0

a1	=  gax0
ad1	delay a1,idel1
gax0	=  0

atmp	=  abs(a1)				/* klvl = signal level */
ktmp	downsamp atmp
atmp	tone atmp,(ktmp>klvl ? iatt:idec)
atmp	butterlp atmp,ifrq1
klvl	downsamp atmp

ktmp	=  klvl/imxlvl
ktmp	=  (ktmp<1 ? exp(log(ktmp)*icomp1):exp(log(ktmp)*icomp2))

a0	=  (ad1*ktmp*iamp)
a0	limit a0,-iclpl,iclpl
a0	butterlp a0,(sr*0.48)

	out a0

	endin

;=========================================================================
; bd10.sco by Istvan Varga


t 0 150.00	/* tempo */

i 90	0.0000	2.000		/* output instrument */

i 1	 0.000	 0.450	33	120

/* ------------------------------------------------------------------------- */

f 64 0 64 -2	0.7		/* volume				*/
		150		/* tempo				*/

		0.05		/* release time				*/

		5.3333		/* start frequency 1			*/
		16		/* freq. decay speed 1			*/
		0.5		/* start frequency 2			*/
		128		/* freq. decay speed 2			*/

		4.0		/* noise mix				*/

		0.25		/* HP filter 1 frequency / osc. freq.	*/
		1.0		/* BP filter 1 frequency / osc. freq.	*/
		1.0		/* BP filter 1 bandwidth / osc. freq.	*/

		2.0		/* HP filter 2 frequency / osc. freq.	*/
		0.7		/* HP filter 2 mix			*/
		8.0		/* HP filter 3 frequency / osc. freq.	*/
		-2.0		/* HP filter 3 mix			*/

		1.333		/* output HP filter freq. / note freq.	*/
		2.0		/* output HP filter resonance		*/

		12.0		/* output LP filter frq. 1 / osc. freq.	*/
		8		/* output LP filter frq. 1 decay speed	*/
		4.0		/* output LP filter frq. 2 / osc. freq.	*/
		8		/* output LP filter frq. 2 decay speed	*/

		16.0		/* amp. envelope 1 start value		*/
		256		/* amp. envelope 1 decay speed		*/
		0.25		/* amp. envelope 2 start value		*/
		4		/* amp. envelope 2 decay speed		*/

/* ---- compressor parameters ---- */

		30000		/* output volume			*/
		30000		/* output clip level			*/
		1.0		/* threshold level			*/
		1.0		/* compression ratio below thr. level	*/
		0.0		/* compression ratio above thr. level	*/
		0.0002		/* delay time				*/
		5000		/* envelope LP filter 1 freq. (attack)	*/
		500		/* envelope LP filter 1 freq. (decay)	*/
		2000		/* envelope LP filter 2 frequency (Hz)	*/

/* ------------------------------------------------------------------------- */

; From "fgen.h.sco"
#define FGEN128(TABLE'SIZE'SRC'MINH) #

f [ $TABLE + 0 ] 0 $SIZE -30	$SRC	$MINH	2935.49		48000
f [ $TABLE + 1 ] 0 $SIZE -30	$TABLE	$MINH	2770.74		48000
f [ $TABLE + 2 ] 0 $SIZE -30	$TABLE	$MINH	2615.23		48000
f [ $TABLE + 3 ] 0 $SIZE -30	$TABLE	$MINH	2468.45		48000
f [ $TABLE + 4 ] 0 $SIZE -30	$TABLE	$MINH	2329.90		48000
f [ $TABLE + 5 ] 0 $SIZE -30	$TABLE	$MINH	2199.13		48000
f [ $TABLE + 6 ] 0 $SIZE -30	$TABLE	$MINH	2075.71		48000
f [ $TABLE + 7 ] 0 $SIZE -30	$TABLE	$MINH	1959.21		48000
f [ $TABLE + 8 ] 0 $SIZE -30	$TABLE	$MINH	1849.24		48000
f [ $TABLE + 9 ] 0 $SIZE -30	$TABLE	$MINH	1745.45		48000
f [ $TABLE + 10 ] 0 $SIZE -30	$TABLE	$MINH	1647.49		48000
f [ $TABLE + 11 ] 0 $SIZE -30	$TABLE	$MINH	1555.02		48000
f [ $TABLE + 12 ] 0 $SIZE -30	$TABLE	$MINH	1467.75		48000
f [ $TABLE + 13 ] 0 $SIZE -30	$TABLE	$MINH	1385.37		48000
f [ $TABLE + 14 ] 0 $SIZE -30	$TABLE	$MINH	1307.61		48000
f [ $TABLE + 15 ] 0 $SIZE -30	$TABLE	$MINH	1234.22		48000
f [ $TABLE + 16 ] 0 $SIZE -30	$TABLE	$MINH	1164.95		48000
f [ $TABLE + 17 ] 0 $SIZE -30	$TABLE	$MINH	1099.57		48000
f [ $TABLE + 18 ] 0 $SIZE -30	$TABLE	$MINH	1037.85		48000
f [ $TABLE + 19 ] 0 $SIZE -30	$TABLE	$MINH	 979.60		48000
f [ $TABLE + 20 ] 0 $SIZE -30	$TABLE	$MINH	 924.62		48000
f [ $TABLE + 21 ] 0 $SIZE -30	$TABLE	$MINH	 872.73		48000
f [ $TABLE + 22 ] 0 $SIZE -30	$TABLE	$MINH	 823.74		48000
f [ $TABLE + 23 ] 0 $SIZE -30	$TABLE	$MINH	 777.51		48000
f [ $TABLE + 24 ] 0 $SIZE -30	$TABLE	$MINH	 733.87		48000
f [ $TABLE + 25 ] 0 $SIZE -30	$TABLE	$MINH	 692.68		48000
f [ $TABLE + 26 ] 0 $SIZE -30	$TABLE	$MINH	 653.81		48000
f [ $TABLE + 27 ] 0 $SIZE -30	$TABLE	$MINH	 617.11		48000
f [ $TABLE + 28 ] 0 $SIZE -30	$TABLE	$MINH	 582.48		48000
f [ $TABLE + 29 ] 0 $SIZE -30	$TABLE	$MINH	 549.78		48000
f [ $TABLE + 30 ] 0 $SIZE -30	$TABLE	$MINH	 518.93		48000
f [ $TABLE + 31 ] 0 $SIZE -30	$TABLE	$MINH	 489.80		48000
f [ $TABLE + 32 ] 0 $SIZE -30	$TABLE	$MINH	 462.31		48000
f [ $TABLE + 33 ] 0 $SIZE -30	$TABLE	$MINH	 436.36		48000
f [ $TABLE + 34 ] 0 $SIZE -30	$TABLE	$MINH	 411.87		48000
f [ $TABLE + 35 ] 0 $SIZE -30	$TABLE	$MINH	 388.76		48000
f [ $TABLE + 36 ] 0 $SIZE -30	$TABLE	$MINH	 366.94		48000
f [ $TABLE + 37 ] 0 $SIZE -30	$TABLE	$MINH	 346.34		48000
f [ $TABLE + 38 ] 0 $SIZE -30	$TABLE	$MINH	 326.90		48000
f [ $TABLE + 39 ] 0 $SIZE -30	$TABLE	$MINH	 308.56		48000
f [ $TABLE + 40 ] 0 $SIZE -30	$TABLE	$MINH	 291.24		48000
f [ $TABLE + 41 ] 0 $SIZE -30	$TABLE	$MINH	 274.89		48000
f [ $TABLE + 42 ] 0 $SIZE -30	$TABLE	$MINH	 259.46		48000
f [ $TABLE + 43 ] 0 $SIZE -30	$TABLE	$MINH	 244.90		48000
f [ $TABLE + 44 ] 0 $SIZE -30	$TABLE	$MINH	 231.16		48000
f [ $TABLE + 45 ] 0 $SIZE -30	$TABLE	$MINH	 218.18		48000
f [ $TABLE + 46 ] 0 $SIZE -30	$TABLE	$MINH	 205.94		48000
f [ $TABLE + 47 ] 0 $SIZE -30	$TABLE	$MINH	 194.38		48000
f [ $TABLE + 48 ] 0 $SIZE -30	$TABLE	$MINH	 183.47		48000
f [ $TABLE + 49 ] 0 $SIZE -30	$TABLE	$MINH	 173.17		48000
f [ $TABLE + 50 ] 0 $SIZE -30	$TABLE	$MINH	 163.45		48000
f [ $TABLE + 51 ] 0 $SIZE -30	$TABLE	$MINH	 154.28		48000
f [ $TABLE + 52 ] 0 $SIZE -30	$TABLE	$MINH	 145.62		48000
f [ $TABLE + 53 ] 0 $SIZE -30	$TABLE	$MINH	 137.45		48000
f [ $TABLE + 54 ] 0 $SIZE -30	$TABLE	$MINH	 129.73		48000
f [ $TABLE + 55 ] 0 $SIZE -30	$TABLE	$MINH	 122.45		48000
f [ $TABLE + 56 ] 0 $SIZE -30	$TABLE	$MINH	 115.58		48000
f [ $TABLE + 57 ] 0 $SIZE -30	$TABLE	$MINH	 109.09		48000
f [ $TABLE + 58 ] 0 $SIZE -30	$TABLE	$MINH	 102.97		48000
f [ $TABLE + 59 ] 0 $SIZE -30	$TABLE	$MINH	  97.19		48000
f [ $TABLE + 60 ] 0 $SIZE -30	$TABLE	$MINH	  91.73		48000
f [ $TABLE + 61 ] 0 $SIZE -30	$TABLE	$MINH	  86.59		48000
f [ $TABLE + 62 ] 0 $SIZE -30	$TABLE	$MINH	  81.73		48000
f [ $TABLE + 63 ] 0 $SIZE -30	$TABLE	$MINH	  77.14		48000
f [ $TABLE + 64 ] 0 $SIZE -30	$TABLE	$MINH	  72.81		48000
f [ $TABLE + 65 ] 0 $SIZE -30	$TABLE	$MINH	  68.72		48000
f [ $TABLE + 66 ] 0 $SIZE -30	$TABLE	$MINH	  64.87		48000
f [ $TABLE + 67 ] 0 $SIZE -30	$TABLE	$MINH	  61.23		48000
f [ $TABLE + 68 ] 0 $SIZE -30	$TABLE	$MINH	  57.79		48000
f [ $TABLE + 69 ] 0 $SIZE -30	$TABLE	$MINH	  54.55		48000
f [ $TABLE + 70 ] 0 $SIZE -30	$TABLE	$MINH	  51.48		48000
f [ $TABLE + 71 ] 0 $SIZE -30	$TABLE	$MINH	  48.59		48000
f [ $TABLE + 72 ] 0 $SIZE -30	$TABLE	$MINH	  45.87		48000
f [ $TABLE + 73 ] 0 $SIZE -30	$TABLE	$MINH	  43.29		48000
f [ $TABLE + 74 ] 0 $SIZE -30	$TABLE	$MINH	  40.86		48000
f [ $TABLE + 75 ] 0 $SIZE -30	$TABLE	$MINH	  38.57		48000
f [ $TABLE + 76 ] 0 $SIZE -30	$TABLE	$MINH	  36.40		48000
f [ $TABLE + 77 ] 0 $SIZE -30	$TABLE	$MINH	  34.36		48000
f [ $TABLE + 78 ] 0 $SIZE -30	$TABLE	$MINH	  32.43		48000
f [ $TABLE + 79 ] 0 $SIZE -30	$TABLE	$MINH	  30.61		48000
f [ $TABLE + 80 ] 0 $SIZE -30	$TABLE	$MINH	  28.89		48000
f [ $TABLE + 81 ] 0 $SIZE -30	$TABLE	$MINH	  27.27		48000
f [ $TABLE + 82 ] 0 $SIZE -30	$TABLE	$MINH	  25.74		48000
f [ $TABLE + 83 ] 0 $SIZE -30	$TABLE	$MINH	  24.30		48000
f [ $TABLE + 84 ] 0 $SIZE -30	$TABLE	$MINH	  22.93		48000
f [ $TABLE + 85 ] 0 $SIZE -30	$TABLE	$MINH	  21.65		48000
f [ $TABLE + 86 ] 0 $SIZE -30	$TABLE	$MINH	  20.43		48000
f [ $TABLE + 87 ] 0 $SIZE -30	$TABLE	$MINH	  19.28		48000
f [ $TABLE + 88 ] 0 $SIZE -30	$TABLE	$MINH	  18.20		48000
f [ $TABLE + 89 ] 0 $SIZE -30	$TABLE	$MINH	  17.18		48000
f [ $TABLE + 90 ] 0 $SIZE -30	$TABLE	$MINH	  16.22		48000
f [ $TABLE + 91 ] 0 $SIZE -30	$TABLE	$MINH	  15.31		48000
f [ $TABLE + 92 ] 0 $SIZE -30	$TABLE	$MINH	  14.45		48000
f [ $TABLE + 93 ] 0 $SIZE -30	$TABLE	$MINH	  13.64		48000
f [ $TABLE + 94 ] 0 $SIZE -30	$TABLE	$MINH	  12.87		48000
f [ $TABLE + 95 ] 0 $SIZE -30	$TABLE	$MINH	  12.15		48000
f [ $TABLE + 96 ] 0 $SIZE -30	$TABLE	$MINH	  11.47		48000
f [ $TABLE + 97 ] 0 $SIZE -30	$TABLE	$MINH	  10.82		48000
f [ $TABLE + 98 ] 0 $SIZE -30	$TABLE	$MINH	  10.22		48000
f [ $TABLE + 99 ] 0 $SIZE -30	$TABLE	$MINH	   9.64		48000
f [ $TABLE + 100 ] 0 $SIZE -30	$TABLE	$MINH	   9.10		48000
f [ $TABLE + 101 ] 0 $SIZE -30	$TABLE	$MINH	   8.59		48000
f [ $TABLE + 102 ] 0 $SIZE -30	$TABLE	$MINH	   8.11		48000
f [ $TABLE + 103 ] 0 $SIZE -30	$TABLE	$MINH	   7.65		48000
f [ $TABLE + 104 ] 0 $SIZE -30	$TABLE	$MINH	   7.22		48000
f [ $TABLE + 105 ] 0 $SIZE -30	$TABLE	$MINH	   6.82		48000
f [ $TABLE + 106 ] 0 $SIZE -30	$TABLE	$MINH	   6.44		48000
f [ $TABLE + 107 ] 0 $SIZE -30	$TABLE	$MINH	   6.07		48000
f [ $TABLE + 108 ] 0 $SIZE -30	$TABLE	$MINH	   5.73		48000
f [ $TABLE + 109 ] 0 $SIZE -30	$TABLE	$MINH	   5.41		48000
f [ $TABLE + 110 ] 0 $SIZE -30	$TABLE	$MINH	   5.11		48000
f [ $TABLE + 111 ] 0 $SIZE -30	$TABLE	$MINH	   4.82		48000
f [ $TABLE + 112 ] 0 $SIZE -30	$TABLE	$MINH	   4.55		48000
f [ $TABLE + 113 ] 0 $SIZE -30	$TABLE	$MINH	   4.30		48000
f [ $TABLE + 114 ] 0 $SIZE -30	$TABLE	$MINH	   4.05		48000
f [ $TABLE + 115 ] 0 $SIZE -30	$TABLE	$MINH	   3.83		48000
f [ $TABLE + 116 ] 0 $SIZE -30	$TABLE	$MINH	   3.61		48000
f [ $TABLE + 117 ] 0 $SIZE -30	$TABLE	$MINH	   3.41		48000
f [ $TABLE + 118 ] 0 $SIZE -30	$TABLE	$MINH	   3.22		48000
f [ $TABLE + 119 ] 0 $SIZE -30	$TABLE	$MINH	   3.04		48000
f [ $TABLE + 120 ] 0 $SIZE -30	$TABLE	$MINH	   2.87		48000
f [ $TABLE + 121 ] 0 $SIZE -30	$TABLE	$MINH	   2.71		48000
f [ $TABLE + 122 ] 0 $SIZE -30	$TABLE	$MINH	   2.55		48000
f [ $TABLE + 123 ] 0 $SIZE -30	$TABLE	$MINH	   2.41		48000
f [ $TABLE + 124 ] 0 $SIZE -30	$TABLE	$MINH	   2.28		48000
f [ $TABLE + 125 ] 0 $SIZE -30	$TABLE	$MINH	   2.15		48000
f [ $TABLE + 126 ] 0 $SIZE -30	$TABLE	$MINH	   2.03		48000
f [ $TABLE + 127 ] 0 $SIZE -30	$TABLE	$MINH	   1.91		48000

#

f 257 0 16384 7 1 16384 -1		/* sawtooth wave */
$FGEN128(256'4096'257'1)

e	/* end of score */



-- 
+-----------------------------------------------------------+
  Erik de Castro Lopo
+-----------------------------------------------------------+
"Even Napoleon had his Watergate" -- Michael Spautz


-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems?  Stop!  Download the new AJAX search engine that makes
searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click
_______________________________________________
Csound-devel mailing list
Csound-devel@lists.sourceforge.net

Date2005-12-27 14:45
FromIstvan Varga
SubjectRe: [Cs-dev] Bug report : csound5 output has problems
AttachmentsNone  

Date2005-12-27 22:12
FromIstvan Varga
SubjectRe: [Cs-dev] Bug report : csound5 output has problems
AttachmentsNone  

Date2005-12-27 23:28
FromErik de Castro Lopo
SubjectRe: [Cs-dev] Bug report : csound5 output has problems
Istvan Varga wrote:

> Actually, the bug (which is NaN's due to calculating the logarithm of zero)
> is in the .orc file, although it is only triggered with some builds of Csound
> but not others, depending on compiler optimizations.

Thanks Istvan, that was a very helpful explanation. However it
does raise some further questions.

Should people writing .ORCs and .SCOs be tracking down problems
like this and adding denormal statements? For instance, I have a
pair of large files which worked perfectly under csound4 and 
had a similar problem to the bass drum problem. Unfortunately,
since the .ORC and .SCO were so large I was not able to track
the problem down.

If it is decided that the .ORC/.SCO author is responsible for
tracking these down, maybe it would be nice if csound had a
--detect-denormals option that print warning messages about 
the location of denormals. 

Cheers,
Erik
-- 
+-----------------------------------------------------------+
  Erik de Castro Lopo
+-----------------------------------------------------------+
The idea that Bill Gates has appeared like a knight in shining armour to
lead all customers out of a mire of technological chaos neatly ignores
the fact that it was he who, by peddling second-rate technology, led them
into it in the first place. - Douglas Adams in Guardian, 25-Aug-95


-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems?  Stop!  Download the new AJAX search engine that makes
searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click
_______________________________________________
Csound-devel mailing list
Csound-devel@lists.sourceforge.net