File: oscbank.c

package info (click to toggle)
pd-fftease 3.0.1-8
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,112 kB
  • sloc: ansic: 14,552; makefile: 208; sh: 93; cpp: 19; perl: 9
file content (88 lines) | stat: -rw-r--r-- 2,614 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#include "fftease.h"

void fftease_oscbank( t_fftease *fft )
{
    int    amp,freq,chan, n;

    t_float    a,ainc,f,finc,address;
    int D = fft->D;
    int I = D;
    int L = fft->L;
    t_float synt = fft->synt;
    t_float P  = fft->P;
    int R = fft->R;
    t_float Iinv = 1./fft->D;
    t_float pitch_increment = fft->pitch_increment;
    t_float *table = fft->table;
    t_float *lastamp = fft->lastamp ;
    t_float *lastfreq = fft->lastfreq ;
    t_float *bindex = fft->bindex;
    t_float *channel = fft->channel;
    t_float *output = fft->output;
    int hi_bin = fft->hi_bin;
    int lo_bin = fft->lo_bin;
    t_float maxamp = 0.0;
    t_float localthresh, testamp;
    short noalias = fft->noalias;
    t_float nyquist = fft->nyquist;
    if(! fft->init_status ){ // means memory alloc in effect
        goto exit;
    }
    if(R == 0){
        post("oscbank got 0 SR");
        return;
    }
    pitch_increment = P * (t_float) L / (t_float) R;

    if( synt > 0.0 ){
        maxamp = 0.0;
        for ( chan = lo_bin; chan < hi_bin; chan++ ){
            amp = chan << 1;
            testamp = fabs( channel[amp] );
            if( testamp > maxamp )
                maxamp = testamp;
        }
    }
    localthresh = synt * maxamp;

    for ( chan = lo_bin; chan < hi_bin; chan++ ) {
        if(! fft->init_status ){ // means memory alloc in effect
            goto exit;
        }
        freq = ( amp = ( chan << 1 ) ) + 1;
        if(noalias){
            if( channel[freq] * P >= nyquist )
                channel[amp] = 0;
        }
        if ( channel[amp] > localthresh ){
            channel[freq] *= pitch_increment;
            finc = ( channel[freq] - ( f = lastfreq[chan] ) )*Iinv;
            ainc = ( channel[amp] - ( a = lastamp[chan] ) )*Iinv;
            address = bindex[chan];
            if( address < 0 || address >= L){
                address = 0.0;
                // post("limited oscbank: bad address");
            }
            for ( n = 0; n < I; n++ ) {
                // taking this out now:

                if(! fft->init_status ){ // means memory alloc in effect
                    goto exit;
                }

                output[n] += a*table[ (int) address ];
                address += f;
                while ( address >= L )
                    address -= L;
                while ( address < 0 )
                    address += L;
                a += ainc;
                f += finc;
            }
            lastfreq[chan] = channel[freq];
            lastamp[chan] = channel[amp];
            bindex[chan] = address;
        }
    }
exit:;
}