1 #ifndef PITCH_H
2 #define PITCH_H
3 /*
4     pitch.h:
5 
6     Copyright (C) 1999 John ffitch, Istvan Varga, Peter Neub�cker,
7                        rasmus ekman, Phil Burk
8 
9     This file is part of Csound.
10 
11     The Csound Library is free software; you can redistribute it
12     and/or modify it under the terms of the GNU Lesser General Public
13     License as published by the Free Software Foundation; either
14     version 2.1 of the License, or (at your option) any later version.
15 
16     Csound is distributed in the hope that it will be useful,
17     but WITHOUT ANY WARRANTY; without even the implied warranty of
18     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19     GNU Lesser General Public License for more details.
20 
21     You should have received a copy of the GNU Lesser General Public
22     License along with Csound; if not, write to the Free Software
23     Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
24     02110-1301 USA
25 */
26 
27                         /*                                      PITCH.H */
28 #include "spectra.h"
29 #include "uggab.h"
30 
31 typedef struct {
32         OPDS    h;
33         MYFLT   *koct, *kamp;
34         MYFLT   *asig;
35         MYFLT   *iprd, *ilo, *ihi, *idbthresh;
36                                 /* Optional */
37         MYFLT   *ifrqs, *iconf, *istrt, *iocts, *iq, *inptls, *irolloff, *istor;
38         double  c1, c2, prvq;
39 #define MAXFRQS 120
40         SPECDAT wsig;
41         int32_t     nfreqs, ncoefs, dbout, scountdown, timcount;
42         MYFLT   curq, *sinp, *cosp, *linbufp;
43         int32_t     winlen[MAXFRQS], offset[MAXFRQS];
44         DOWNDAT downsig;
45         WINDAT  sinwindow, octwindow;
46         AUXCH   auxch1, auxch2;
47         int32_t     pdist[MAXPTL], nptls, rolloff;
48         MYFLT   pmult[MAXPTL], confact, kvalsav, kval, kavl, kinc, kanc;
49         MYFLT   *flop, *fhip, *fundp, *oct0p, threshon, threshoff;
50         int32_t     winpts, jmpcount, playing;
51         SPECDAT wfund;
52 } PITCH;
53 
54 typedef struct {
55         OPDS    h;
56         MYFLT   *cnt;
57         void    *clk;
58         int32_t     c;
59 } CLOCK;
60 
61 typedef struct {
62         OPDS    h;
63         MYFLT   *r;
64         MYFLT   *a;
65         void    *clk;
66 } CLKRD;
67 
68 typedef struct {
69         OPDS    h;
70         MYFLT   *val;
71         MYFLT   *index;
72 } SCRATCHPAD;
73 
74 typedef struct {
75         OPDS    h;
76         MYFLT   *ins;
77         MYFLT   *onoff;
78 } MUTE;
79 
80 typedef struct {
81         OPDS    h;
82         MYFLT   *cnt;
83         MYFLT   *ins;
84         MYFLT   *opt;
85         MYFLT   *norel;
86 } INSTCNT;
87 
88 typedef struct {
89     OPDS        h;
90     MYFLT       *instrnum, *ipercent, *iopc;    /* IV - Oct 31 2002 */
91 } CPU_PERC;
92 
93 typedef struct {
94     OPDS    h;
95     MYFLT   *sr, *kamp, *kcps, *ifn, *ifreqtbl, *iamptbl, *icnt, *iphs;
96     FUNC    *ftp;
97     FUNC    *freqtp;
98     FUNC    *amptp;
99     uint32_t     count;
100     int32_t     inerr;
101     AUXCH   lphs;
102 } ADSYNT;
103 
104 typedef struct {
105     OPDS        h;
106     MYFLT       *sr, *kamp, *ktona, *kbrite, *ibasef, *ifn;
107     MYFLT       *imixtbl, *ioctcnt, *iphs;
108     int32       lphs[10];
109     int32_t         octcnt;
110     MYFLT       prevamp;
111     FUNC        *ftp;
112     FUNC        *mixtp;
113 } HSBOSC;
114 
115 typedef struct {
116     OPDS    h;
117     MYFLT   *kcps, *krms, *asig, *imincps, *imaxcps, *icps,
118             *imedi, *idowns, *iexcps, *irmsmedi;
119     MYFLT   srate;
120     MYFLT   lastval;
121     int32   downsamp;
122     int32   upsamp;
123     int32   minperi;
124     int32   maxperi;
125     int32   index;
126     int32   readp;
127     int32   size;
128     int32   peri;
129     int32   medisize;
130     int32   mediptr;
131     int32   rmsmedisize;
132     int32   rmsmediptr;
133     int32_t     inerr;
134     AUXCH   median;
135     AUXCH   rmsmedian;
136     AUXCH   buffer;
137 } PITCHAMDF;
138 
139 typedef struct {
140         OPDS    h;
141         MYFLT   *sr, *xcps, *kindx, *icnt, *iphs;
142         AUXCH   curphs;
143 } PHSORBNK;
144 
145 /* pinkish opcode... Two methods for generating pink noise */
146 
147 /* Gardner method space req */
148 #define GRD_MAX_RANDOM_ROWS   (32)
149 
150 typedef struct {
151     OPDS        h;
152     MYFLT       *aout;
153     MYFLT       *xin, *imethod, *iparam1, *iseed, *iskip;
154     int32       ampinc;         /* Scale output to range */
155     uint32      randSeed;     /* Used by local random generator */
156                                 /* for Paul Kellet's filter bank */
157     double      b0, b1, b2, b3, b4, b5, b6;
158                                 /* for Gardner method */
159     int32       grd_Rows[GRD_MAX_RANDOM_ROWS];
160     int32       grd_NumRows;    /* Number of rows (octave bands of noise) */
161     int32       grd_RunningSum; /* Used to optimize summing of generators. */
162     int32_t         grd_Index;      /* Incremented each sample. */
163     int32_t         grd_IndexMask;  /* Index wrapped by ANDing with this mask. */
164     MYFLT       grd_Scalar;     /* Used to scale to normalize generated noise. */
165 } PINKISH;
166 
167 typedef struct {
168         OPDS    h;
169         MYFLT   *aout;
170         MYFLT   *ain, *imethod, *limit, *iarg;
171         MYFLT   arg, lim, k1, k2;
172         int32_t     meth;
173 } CLIP;
174 
175 typedef struct {
176         OPDS    h;
177         MYFLT   *ar;
178         MYFLT   *amp, *freq, *offset;
179         uint32_t     next;
180 } IMPULSE;
181 
182 typedef struct {
183         int32   cnt,acnt;
184         MYFLT   alpha;
185         MYFLT   val, nxtpt;
186         MYFLT   c1;
187 } NSEG;
188 
189 typedef struct {
190         OPDS    h;
191         MYFLT   *rslt, *argums[VARGMAX];
192         NSEG    *cursegp;
193         int32   nsegs;
194         int32   segsrem, curcnt;
195         MYFLT   curval, curinc, alpha;
196         MYFLT   curx;
197         AUXCH   auxch;
198         int32   xtra;
199         MYFLT   finalval, lastalpha;
200 } TRANSEG;
201 
202 typedef struct {
203         OPDS    h;
204         MYFLT   *rslt, *kamp, *beta;
205         MYFLT   last, lastbeta, sq1mb2, ampmod;
206         int32_t     ampinc;
207 } VARI;
208 
209 typedef struct {
210         OPDS    h;
211         MYFLT   *ar, *ain, *fco, *res, *dist, *istor;
212         MYFLT   ay1, ay2, aout, lastin;
213 } LPF18;
214 
215 typedef struct {
216         OPDS    h;
217         MYFLT   *ar, *ain, *rep, *len;
218         AUXCH   auxch;
219         int32_t     length;         /* Length of buffer */
220         int32_t     cnt;            /* Repetions of current cycle */
221         int32_t     start;          /* Start of current cycle */
222         int32_t     current;        /* takeout point */
223         int32_t     direction;      /* Need to check direction of crossing */
224         int32_t     end;            /* Insert point */
225         MYFLT   lastsamp;       /* So we can test changes */
226         int32_t     noinsert;       /* Flag to say we are losing input */
227 } BARRI;
228 
229 typedef struct {
230         OPDS    h;
231         MYFLT   *sr, *xamp, *xcps, *ifn, *iphs;
232         MYFLT   lphs;
233         FUNC    *ftp;
234 } XOSC;
235 
236 typedef struct {
237         OPDS    h;
238         MYFLT   *ans;
239         MYFLT   *pnum;
240 } PFUN;
241 
242 typedef struct {
243         OPDS    h;
244         MYFLT   *ans;
245         MYFLT   *pnum;
246         AUXCH   pfield;
247 } PFUNK;
248 
249 typedef struct {
250         OPDS    h;
251         MYFLT   *ans;
252         MYFLT   *asig;
253         MYFLT   *kwind;
254         MYFLT   *imaxsize;
255         MYFLT   *iskip;
256         AUXCH   b;
257         MYFLT   *buff;
258         MYFLT   *med;
259         int32_t     ind;
260         int32_t     maxwind;
261 } MEDFILT;
262 
263 int32_t Foscaa(CSOUND *, XOSC *p);
264 int32_t Foscak(CSOUND *, XOSC *p);
265 int32_t Foscka(CSOUND *, XOSC *p);
266 int32_t Fosckk(CSOUND *, XOSC *p);
267 int32_t Foscset(CSOUND *, XOSC *p);
268 int32_t GardnerPink_init(CSOUND *, PINKISH *p);
269 int32_t GardnerPink_perf(CSOUND *, PINKISH *p);
270 int32_t adsynt(CSOUND *, ADSYNT *p);
271 int32_t adsyntset(CSOUND *, ADSYNT *p);
272 int32_t clip(CSOUND *, CLIP *p);
273 int32_t clip_set(CSOUND *, CLIP *p);
274 int32_t clockoff(CSOUND *, CLOCK *p);
275 int32_t clockon(CSOUND *, CLOCK *p);
276 int32_t clockread(CSOUND *, CLKRD *p);
277 int32_t clockset(CSOUND *, CLOCK *p);
278 int32_t scratchread(CSOUND *, SCRATCHPAD *p);
279 int32_t scratchwrite(CSOUND *, SCRATCHPAD *p);
280 int32_t cpuperc(CSOUND *, CPU_PERC *p);
281 int32_t cpuperc_S(CSOUND *, CPU_PERC *p);
282 int32_t hsboscil(CSOUND *, HSBOSC *p);
283 int32_t hsboscset(CSOUND *, HSBOSC *p);
284 int32_t impulse(CSOUND *, IMPULSE *p);
285 int32_t impulse_set(CSOUND *, IMPULSE *p);
286 int32_t instcount(CSOUND *, INSTCNT *p);
287 int32_t instcount_S(CSOUND *, INSTCNT *p);
288 int32_t totalcount(CSOUND *, INSTCNT *p);
289 int32_t kphsorbnk(CSOUND *, PHSORBNK *p);
290 int32_t ktrnseg(CSOUND *, TRANSEG *p);
291 int32_t ktrnsegr(CSOUND *csound, TRANSEG *p);
292 int32_t lpf18db(CSOUND *, LPF18 *p);
293 int32_t lpf18set(CSOUND *, LPF18 *p);
294 int32_t mac(CSOUND *, SUM *p);
295 int32_t maca(CSOUND *, SUM *p);
296 int32_t macset(CSOUND *, SUM *p);
297 int32_t maxalloc(CSOUND *, CPU_PERC *p);
298 int32_t mute_inst(CSOUND *, MUTE *p);
299 int32_t maxalloc_S(CSOUND *, CPU_PERC *p);
300 int32_t mute_inst_S(CSOUND *, MUTE *p);
301 int32_t pfun(CSOUND *, PFUN *p);
302 int32_t pfunk_init(CSOUND *, PFUNK *p);
303 int32_t pfunk(CSOUND *, PFUNK *p);
304 int32_t phsbnkset(CSOUND *, PHSORBNK *p);
305 int32_t phsorbnk(CSOUND *, PHSORBNK *p);
306 int32_t pinkish(CSOUND *, PINKISH *p);
307 int32_t pinkset(CSOUND *, PINKISH *p);
308 int32_t pitch(CSOUND *, PITCH *p);
309 int32_t pitchamdf(CSOUND *, PITCHAMDF *p);
310 int32_t pitchamdfset(CSOUND *, PITCHAMDF *p);
311 int32_t pitchset(CSOUND *, PITCH *p);
312 int32_t trnseg(CSOUND *, TRANSEG *p);
313 int32_t trnsegr(CSOUND *csound, TRANSEG *p);
314 int32_t trnset(CSOUND *, TRANSEG *p);
315 int32_t trnset_bkpt(CSOUND *, TRANSEG *p);
316 int32_t trnsetr(CSOUND *csound, TRANSEG *p);
317 int32_t varicol(CSOUND *, VARI *p);
318 int32_t varicolset(CSOUND *, VARI *p);
319 int32_t waveset(CSOUND *, BARRI *p);
320 int32_t wavesetset(CSOUND *, BARRI *p);
321 int32_t medfiltset(CSOUND *, MEDFILT *p);
322 int32_t medfilt(CSOUND *, MEDFILT *p);
323 int32_t kmedfilt(CSOUND *, MEDFILT *p);
324 #endif /* PITCH_H */
325 
326