1 /*
2     ugens8.h:
3 
4     Copyright (C) 1991, 1998, 2000 Dan Ellis, Richard Karpen, Richard Dobson
5 
6     This file is part of Csound.
7 
8     The Csound Library is free software; you can redistribute it
9     and/or modify it under the terms of the GNU Lesser General Public
10     License as published by the Free Software Foundation; either
11     version 2.1 of the License, or (at your option) any later version.
12 
13     Csound is distributed in the hope that it will be useful,
14     but WITHOUT ANY WARRANTY; without even the implied warranty of
15     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16     GNU Lesser General Public License for more details.
17 
18     You should have received a copy of the GNU Lesser General Public
19     License along with Csound; if not, write to the Free Software
20     Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
21     02110-1301 USA
22 */
23 
24 /*                                                              UGENS8.H    */
25 #ifndef _UGENS8_H_
26 #define _UGENS8_H_
27 #define     PVFRAMSIZE      8192                /* i.e. max FFT point size */
28 #define     PVFFTSIZE       (2*PVFRAMSIZE)      /* 2x for real + imag */
29 #define     PVDATASIZE      (1+PVFRAMSIZE/2)    /* Need 1/2 channels + mid */
30 #define     PVWINLEN        (4097)              /* time window 1st half */
31 
32 /* PVDATASIZE reflects the fact that for n point _real_ time data, the fourier
33  *  transform will only have n degrees of freedom, although it has 2n values
34  *  (n bins x {re,im} or {mag,phase}). This constraint is reflected by the top
35  *  n/2-1 bins (bins n/2+1 .. n-1) being complex conjugates of bins 1..n/2-1.
36  *  Bins 0 and n/2 do not have conjugate images, but they ARE always real,
37  *  so only contribute one degree of freedom each.  So the number of degrees of
38  *  freedom in the complex FFT is {re,im}*(n/2 - 1) +2 = n , as expected.
39  *  Thus we only need to store and process these independent values.  However,
40  *  for convenience, and because our analysis system records the phase of
41  *  bins 0 and n/2 as 0 or pi rather than making the magnitude negative, we
42  *  allow these 2 bins to have imaginary components too, so that FFT frames are
43  *  stored as Magnitude & phase for bins 0..n/2 = 2*(n/2 + 1) or n+2 values.
44  *  These are the n+2 channels interleaved in the PVOC analysis file, and
45  *  then stored and processed wherever you see PVDATA/FRDA (frame data) */
46 
47 #define     pvfrsiz(p)      (p->frSiz)
48 #define     pvffsiz(p)      (2* p->frSiz)
49 #define     pvdasiz(p)      ((uint32_t)(1 + (p->frSiz)/2)) /* as above, based on */
50 #define     pvfdsiz(p)      (2 + p->frSiz)      /*  ACTUAL frameSize in use */
51 
52 typedef struct {
53     OPDS    h;
54     MYFLT   *rslt, *ktimpnt, *kfmod, *ifilno, *ispecwp, *imode;
55     MYFLT   *ifreqlim, *igatefun;
56     int32   mems;
57     int32   kcnt, baseFr, maxFr, frSiz, prFlg, opBpos;
58     /* RWD 8:2001 for pvocex: need these too */
59     int32   frInc, chans;
60 
61     MYFLT   frPktim, frPrtim, scale, asr, lastPex;
62     MYFLT   PvMaxAmp;
63     float   *frPtr, *pvcopy;
64     FUNC    *AmpGateFunc;
65     AUXCH   auxch;
66     MYFLT   *lastPhase; /* [PVDATASIZE] Keep track of cum. phase */
67     MYFLT   *fftBuf;    /* [PVFFTSIZE]  FFT works on Real & Imag */
68     MYFLT   *dsBuf;     /* [PVFFTSIZE]  Output of downsampling may be 2x */
69     MYFLT   *outBuf;    /* [PVFFTSIZE]  Output buffer over win length */
70     MYFLT   *window;    /* [PVWINLEN]   Store 1/2 window */
71     MYFLT   *dsputil_env;
72     AUXCH   memenv;
73     PVOC_GLOBALS  *pp;
74 } PVOC;
75 
76 #endif
77 
78