Csound Csound-dev Csound-tekno Search About

Re: Bug in linseg (recent versions)

Date1999-05-13 19:06
FromTobias Kunze
SubjectRe: Bug in linseg (recent versions)
> I can confirm that it works well with Csound versions up to 3.48

Not for me.  Csound Version 3.473 (Mar  9 1998) has a linseg
opcode that resembles more an IIR filter than a line generator.

Set sr=kr=10 and amplify by 256:

  ; foo.orc
  sr=10	        ; just 10 samples
  kr=10 
  ksmps=1
  nchnls=1
  instr    1
  a1 linseg 0,1/kr,1,2/kr,-1,1/kr,0,p3-4/kr,0
  out a1*256    ; easy to read in hex, not too small, not too large
  endin

  ; foo.sco
  i1 0 1


Then create a soundfile without header and check out the cool 
impulse response (all numbers in hex):

  % csound -h -s -o foo foo.orc foo.sco
  ovarall amps: 640.0
  result:       0000 0100 0200 0080 ff00 fd80 0000 0280 0215 01aa
    decimal:       0  256  512  128 -256 -640    0  640  533   26
  expected:     0000 0100 0000 ff00 0000 0000 0000 0000 0000 0000 
    decimal:       0  256    0 -256    0    0    0    0    0    0


Lowering kr does only worsen the problem:

  % csound -h -s -o foo foo.orc foo.sco
  ovarall amps: 1024.0
  result:       0000 0080 0100 0180 0200 0080 ff00 fd80 fc00 fe00
    decimal:       0  128  256  384  512  128 -256 -640-1024 -512
  expected:     0000 0080 0100 0080 0000 ff80 ff00 ff80 0000 0000
    decimal:       0  128  256  128    0 -128 -256 -128    0    0


The filter does not taper off (gets rounded off to 0) until
sr=kr=200.  Also, note that it doesn't overshoot that much (only
269.1 instead of the expected 256 maxamp):

  % csound -r 200 -k 200 -h -s -o foo foo.orc foo.sco
  ovarall amps: 269.1
  result:       0000 000c 0019 0026 0033 0040 004c 0059 0066 0073
		0080 008c 0099 00a6 00b3 00c0 00cc 00d9 00e6 00f3
		0100 010c 00ff 00f2 00e5 00d8 00cb 00be 00b0 00a3
		0096 0089 007c 006f 0062 0055 0048 003a 002d 0020
		0013 0006 fffa ffed ffe0 ffd2 ffc5 ffb8 ffab ff9e
		ff91 ff84 ff77 ff69 ff5c ff4f ff42 ff35 ff28 ff1b
		ff0e ff01 fef3 ff01 ff0e ff1c ff29 ff37 ff44 ff52
		ff5f ff6c ff7a ff87 ff95 ffa2 ffb0 ffbd ffcb ffd8
		ffe6 fff3 0000 000d 000d 000d 000d 000d 000c 000c
		000c 000c 000c 000c 000c 000c 000b 000b 000b 000b
		000b 000b 000b 000b 000b 000a 000a 000a 000a 000a
		000a 000a 000a 000a 0009 0009 0009 0009 0009 0009
		0009 0009 0009 0008 0008 0008 0008 0008 0008 0008
		0008 0008 0007 0007 0007 0007 0007 0007 0007 0007
		0007 0006 0006 0006 0006 0006 0006 0006 0006 0006
		0005 0005 0005 0005 0005 0005 0005 0005 0005 0004
		0004 0004 0004 0004 0004 0004 0004 0004 0003 0003
		0003 0003 0003 0003 0003 0003 0003 0002 0002 0002
		0002 0002 0002 0002 0002 0002 0001 0001 0001 0001
		0001 0001 0001 0001 0001 0000 0000 0000 0000 0000
  expected:     you know what


As one might expect, this overshoot probably approaches 256 as 
sr=kr goes towards infinity.  Here are some values:

  sr=kr=      400:  262.5
  sr=kr=    2,000:  257.3
  sr=kr=    4,000:  256.6
  sr=kr=   20,000:  256.1
  sr=kr=   40,000:  256.1
  sr=kr=  200,000:  256.0   ; Bingo!
  sr=kr=  400,000:  255.9
  sr=kr=2,000,000:  256.3
  sr=kr=4,000,000:  256.4
  ...


-Tobias

______________________________________________________________________

Tobias Kunze                     tkunze@ccrma.stanford.edu