Search code examples
csound

How does Csound's gen09 work?


I'm trying to understand Csound's gen09, and I tried this line:

gigen   ftgen 1, 0, 16384, 9,   1, 1, 0,   1, 1, 180

The way I understood how gen09 works, the second partial in this case is supposed to cancel the first, because they are both at the fundamental frequency (1), and the phase is inverted (0 and 180). But instead of silence, I get a wave that looks like this:

3 cycles of the output wave

What exactly is happening here to create this waveform?


Solution

  • What is happening here is that because rescaling is on (positive GEN number), the small errors in the calculation are amplified (so the max value is 1). If you constructed the table with -9, you will see that the result is what you expected.

    Try this

    <CsoundSynthesizer>
    <CsOptions>
    </CsOptions>
    <CsInstruments>
    
     instr 1
      a1 oscili 0dbfs,A4,1
      out a1
     endin
    </CsInstruments>
    <CsScore>
     f1 0 16384 -9 1 1 0 1 1 180
     i1 0 1
    </CsScore>
    </CsoundSynthesizer>
    

    The result should be

    SECTION 1:
    ftable 1:
    new alloc for instr 1:
    B  0.000 ..  1.000 T  1.000 TT  1.000 M:      0.0
    Score finished in csoundPerformKsmps().
    inactive allocs returned to freespace
    end of score.          overall amps:      0.0
       overall samples out of range:        0