ZynAddSubFX/PADsynth/Input and Output

Steps of the basic algorithm

edit
Input:
N - wavetable size. It's recomanded to be a power of 2.
    This is, usually,  a big number (like 262144)
samplerate - the samplerate (e.g. 44100)
f - frequency of the fundamental note (e.g. 440)
bw - bandwidth of first harmonic in cents (e.g. 50 cents)
     must be greater than zero
number_harmonics - the number of harmonics.
     Of course, number_harmonics<(samplerate/f)
A[1..number_harmonics] - amplitude of the harmonics

Output

smp[0..N-1]- the generated wavetable


Internal variables

freq_amp[0..N/2-1] = {0,0,0,0,...,0}
freq_phase[0..N/2-1]
etc...  

Functions

RND() returns a random value between 0 and 1
IFFT() is the inverse fourier transform
normalize_sample() normalizes samples
profile(fi,bwi){
   x=fi/bwi;
   return exp(-x*x)/bwi;
};


Steps

FOR nh = 1 to number_harmonics         
     bw_Hz=(pow(2,bw/1200)-1.0)*f*nh;
     bwi=bw_Hz/(2.0*samplerate);
     fi=f*nh/samplerate;
     FOR i=0 to N/2-1
        hprofile=profile((i/N)-fi,bwi);
        freq_amp[i]=freq_amp[i]+hprofile*A[nh];
     ENDFOR
ENDFOR
FOR i=0 to N/2-1
     freq_phase[i]=RND()*2*PI;
ENDFOR       
smp=IFFT(N,freq_amp,freq_phase);
normalize_sample(N,smp);
OUTPUT smp

The extended algorithm

edit

The differences between the extended algorithm and the basic algorithm are minor: There is an additional parameter:

  • bwscale: that specify how much the bandwidth of the harmonic increase according to its frequency.
  • Also, there is defined a function called relF(N) who returns the relative frequency of the N'th overtone. It allows to generate detuned harmonics or even metallic sounds (like bells).

The difference between the basic algorithm is at the computation of bw_Hz and fi:

bw_Hz=(pow(2.0,bw/1200.0)-1.0)*f*pow(relF(nh),bwscale);
fi=f*relF(nh)/samplerate;

If the relF(N) function returns N and the bwscale is equal to 1, this algorithm will be equivalent to the basic algorithm.

Example Graph of freq_amp array

edit

Graphs of the (basic algorithm) freq_amp array for N=262144, f=500 Hz, bw=100 cents, samplerate=44.1 kHz, and A[] where A[n]=1.0/sqrt(n)

   
Whole array Close-up of the array

Audio example of the output of this algorithm

edit