GEN09 — Generate composite waveforms made up of weighted sums of simple sinusoids.
These subroutines generate composite waveforms made up of weighted sums of simple sinusoids. The specification of each contributing partial requires 3 p-fields using GEN09.
size -- number of points in the table. Must be a power of 2 or power-of-2 plus 1 (see f statement).
pna, pnb, etc. -- partial no. (relative to a fundamental that would occupy size locations per cycle) of sinusoid a, sinusoid b, etc. Must be positive, but need not be a whole number, i.e., non-harmonic partials are permitted. Partials may be in any order.
stra, strb, etc. -- strength of partials pna, pnb, etc. These are relative strengths, since the composite waveform may be rescaled later. Negative values are permitted and imply a 180 degree phase shift.
phsa, phsb, etc. -- initial phase of partials pna, pnb, etc., expressed in degrees (0-360).
Note | |
---|---|
|
Here is a simple example of the GEN09 routine. It uses the file gen09.csd. It will generate a cosine wave, a sine wave with an initial phase of 90 degrees. Here is its diagram:
Example 558. A simple example of the GEN09 routine.
See the sections Real-time Audio and Command Line Flags for more information on using command line flags.
<CsoundSynthesizer> <CsOptions> ; Select audio/midi flags here according to platform ; Audio out Audio in -odac -iadc ;;;RT audio I/O ; For Non-realtime ouput leave only the line below: ; -o gen09.wav -W ;;; for file output any platform </CsOptions> <CsInstruments> ; Initialize the global variables. sr = 44100 kr = 4410 ksmps = 10 nchnls = 1 ; Instrument #1. instr 1 kamp = 30000 kcps = 440 ifn = 1 ; Play the waveform stored in Table #1. a1 oscil kamp, kcps, ifn out a1 endin </CsInstruments> <CsScore> ; Table #1: a cosine wave (using GEN09). ; This is a sine wave with an initial phase of 90 degrees. f 1 0 16384 9 1 1 90 ; Play Instrument #1 for 2 seconds. i 1 0 2 e </CsScore> </CsoundSynthesizer>
Here is another example of the GEN09 routine. It uses the file gen09square.csd. It combines partials l, 3 and 9 in the relative strengths in which they are found in a square wave, except that partial 9 is upside down. It will be rescaled, here is its diagram:
Example 559. A square wave generated by the GEN09 routine.
<CsoundSynthesizer> <CsOptions> ; Select audio/midi flags here according to platform ; Audio out Audio in -odac -iadc ;;;RT audio I/O ; For Non-realtime ouput leave only the line below: ; -o gen09square.wav -W ;;; for file output any platform </CsOptions> <CsInstruments> ; Initialize the global variables. sr = 44100 kr = 4410 ksmps = 10 nchnls = 1 ; Instrument #1. instr 1 kamp = 30000 kcps = 440 ifn = 1 ; Play the waveform stored in Table #1. a1 oscil kamp, kcps, ifn out a1 endin </CsInstruments> <CsScore> ; Table #1: an approximation of a square wave (using GEN09). f 1 0 16384 9 1 3 0 3 1 0 9 0.3333 180 ; Play Instrument #1 for 2 seconds. i 1 0 2 e </CsScore> </CsoundSynthesizer>