1 /*
2     ugnorman.h:
3 
4     Copyright 2004 Alex Norman
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 /* ats-csound version 0.1
25  * Mon May 10 19:44:46 PDT 2004
26  * header file for all of the ATScsound functions by Alex Norman
27  */
28 
29 #include "stdopcod.h"
30 #include <stdlib.h>
31 #include <stdio.h>
32 #include <string.h>
33 #include <math.h>
34 
35 typedef struct atsdataloc {
36     double  amp;
37     double  freq;
38 } ATS_DATA_LOC;
39 
40 typedef struct _randiats { /* the data for the randi UG */
41     int32_t     size;   /* size of the frame in samples this should be sr/freq. */
42     int32_t     cnt;    /* sample position counter */
43     int32   a1;     /* first amplitude value */
44     int32   a2;     /* next  amplitude value */
45 } RANDIATS;
46 
47 typedef struct _atsnzaux {
48     double  buf[25];
49     MYFLT   phaseinc[25];
50     MYFLT   nfreq[25];
51     RANDIATS randinoise[25];
52 } atsnzAUX;
53 
54 typedef struct atsstruct {
55     double  magic;      /* ats magic number */
56     double  sampr;      /* sampling rate */
57     double  frmsz;      /* frame size in samples */
58     double  winsz;      /* window size in samples */
59     double  npartials;  /* number of partials */
60     double  nfrms;      /* number of frames */
61     double  ampmax;     /* max amplitude */
62     double  freqmax;    /* max frequency */
63     double  dur;        /* duration seconds */
64     double  type;       /* Ats Frame type 1-4 */
65 } ATSSTRUCT;
66 
67 typedef struct _atsinfo {
68     OPDS    h;
69     /* the return value, the ats file and a location selection */
70     MYFLT   *ireturn, *ifileno, *ilocation;
71 } ATSINFO;
72 
73 /* structures to pass data to the opcodes */
74 
75 typedef struct _atsread {
76     OPDS    h;
77     /* outputs (2) and inputs */
78     MYFLT   *kfreq, *kamp, *ktimpnt, *ifileno, *ipartial;
79     /* indicates the maximun frame */
80     int32_t     maxFr;
81     /* a flag used to indicate if we've steped out of the time range */
82     /* of the data, so we do not print too many warnings */
83     int32_t     prFlg;
84     /* points to the start of the data */
85     double  *datastart;
86     /* tells the location of the partal to output */
87     /* and the number of doubles to increment to get to the next frame */
88     int32_t     partialloc, frmInc;
89     MEMFIL  *atsmemfile;
90     double  timefrmInc;
91     /* indicates if the data file is byte swapped or not */
92     int32_t     swapped;
93 } ATSREAD;
94 
95 typedef struct _atsreadnz {
96     OPDS    h;
97     MYFLT   *kenergy, *ktimpnt, *ifileno, *inzbin; /* outputs (1) and inputs */
98     int32_t     maxFr;
99     /* a flag used to indicate if we've steped out of the time range */
100     /* of the data, so we do not print too many warnings */
101     int32_t     prFlg;
102     double  *datastart; /* points to the start of the data */
103     int32_t     nzbandloc, frmInc;
104     MEMFIL  *atsmemfile;
105     double  timefrmInc;
106     int32_t     swapped;    /* indicates if the data file is byte swapped or not */
107 } ATSREADNZ;
108 
109 typedef struct _atsadd {
110     OPDS    h;
111     /* audio output and k & i inputs */
112     MYFLT   *aoutput, *ktimpnt, *kfmod, *ifileno, *ifn, *iptls;
113     /* optional arguments */
114     MYFLT   *iptloffset, *iptlincr, *igatefun;
115     /* pointer to table with wave to synthesize sound */
116     FUNC    *ftp, *AmpGateFunc;
117     AUXCH   auxch;
118     MEMFIL  *atsmemfile;
119 
120     double  maxFr;
121     /* a flag used to indicate if we've steped out of the time range */
122     /* of the data, so we do not print too many warnings */
123     int32_t     prFlg;
124     double  timefrmInc;
125     double  MaxAmp;     /* maximum amplitude in anaylsis file */
126     int32_t     firstpartial, partialinc, frmInc;
127     double  *datastart;
128     double  *oscphase;  /* oscillator phase */
129     ATS_DATA_LOC *buf;
130     int32_t     swapped;    /* indicates if the data file is byte swapped or not */
131   MYFLT *oldamps;
132 } ATSADD;
133 
134 typedef struct _atsaddnz {
135     OPDS    h;
136     /* audio output and k & i inputs */
137     MYFLT   *aoutput, *ktimpnt, *ifileno, *ibands;
138     /* optional arguments */
139     MYFLT   *ibandoffset, *ibandincr;
140 
141     MEMFIL  *atsmemfile;  /* a pointer into the ATS file */
142 
143     double  maxFr;
144     int32_t     prFlg;
145     int32_t     frmInc; /* amount to increment frame pointer to get to next frame */
146     double  timefrmInc;
147     double  winsize;    /* size of windows in analysis file, used to */
148                         /*   compute RMS amplitude from energy in noise band */
149     double  *datastart;
150 
151     double  buf[25];      /* stores band information for passing data */
152     double  phaseinc[25]; /* to create an array of noise */
153     double  oscphase[25]; /* the phase of all the oscilators */
154     RANDIATS randinoise[25]; /* pointer to the interpolated random noise info */
155     double  nfreq[25];
156     int32_t     firstband;
157     int32_t     swapped;    /* indicates if the data file is byte swapped or not */
158     int32_t     bands, bandoffset, bandincr;
159     ATSSTRUCT atshead;
160 } ATSADDNZ;
161 
162 struct _atsbufread {
163     OPDS    h;
164     MYFLT   *ktimpnt, *kfmod, *ifileno, *iptls;
165     MYFLT   *iptloffset, *iptlincr;     /* optional arguments */
166     MEMFIL  *mfp;
167     int32_t     maxFr, prFlg;
168     /* base Frame (in frameData0) and maximum frame on file, ptr to fr, size */
169     AUXCH   auxch;
170     ATS_DATA_LOC *table;  /* store freq and amp info for later use */
171     ATS_DATA_LOC *utable; /* store freq and amp info for later use (unsorted) */
172     int32_t     frmInc; /* amount to increment frame pointer to get to next frame */
173     int32_t     firstpartial; /* location of first wanted partial in the frame */
174     int32_t     partialinc; /* amount to increment pointer by */
175                         /*   to get at the next partial in a frame */
176     double  timefrmInc;
177     MYFLT   MaxAmp;     /* maximum amplitude in anaylsis file */
178     double  *datastart; /* pointer to the data (past the header) */
179     ATSSTRUCT atshead;
180     int32_t     swapped;    /* indicates if the data file is byte swapped or not */
181 };
182 
183 typedef struct _atscross {
184     OPDS    h;
185     /* audio output and k & i inputs */
186     MYFLT   *aoutput, *ktimpnt, *kfmod, *ifileno, *ifn;
187     MYFLT   *kmyamp, *katsbufamp, *iptls;
188     /* optional arguments */
189     MYFLT   *iptloffset, *iptlincr, *igatefun, *kthresh;
190 
191     /* pointer to table with wave to synthesize sound */
192     FUNC    *ftp, *AmpGateFunc;
193     AUXCH   auxch;
194     MEMFIL  *atsmemfile;
195 
196     double  maxFr;
197     /* a flag used to indicate if we've steped out of the time range */
198     /* of the data, so we do not print too many warnings */
199     int32_t     prFlg;
200     double  timefrmInc;
201     double  MaxAmp;     /* maximum amplitude in anaylsis file */
202     int32_t     firstpartial, partialinc, frmInc;
203     double  *datastart;
204     double  *oscphase;  /* oscillator phase */
205     ATS_DATA_LOC *buf;
206     int32_t     swapped;    /* indicates if the data file is byte swapped or not */
207   MYFLT   *oldamps;
208 } ATSCROSS;             /* modified from atsadd */
209 
210 typedef struct _atssinnoi {
211     OPDS    h;
212     /* audio output and k & i inputs */
213     MYFLT   *aoutput, *ktimpnt, *ksinamp, *knzamp, *kfreq, *ifileno, *iptls;
214     /* optional arguments */
215     MYFLT   *iptloffset, *iptlincr, *igatefun;
216 
217     MEMFIL  *atsmemfile;  /* a pointer into the ATS file */
218     AUXCH   auxch;
219 
220     double  maxFr;
221     int32_t prFlg;
222     int32_t nzmemsize;
223  /* double  winsize; */   /* size of windows in analysis file, used to */
224                           /* compute RMS amplitude from energy in noise band */
225     double  *datastart;
226     double  *nzdata;
227 
228     int32_t firstpartial;
229     int32_t partialinc;
230     int32_t firstband;
231     int32_t frmInc; /* amount to increment frame pointer to get to next frame */
232     double  timefrmInc;
233     int32_t npartials;
234 
235     ATS_DATA_LOC *oscbuf; /* stores band information for passing data */
236 
237     double  *nzbuf;       /* stores band information for passing data */
238     double  *oscphase;    /* the phase of all the oscilators */
239     RANDIATS *randinoise; /* a pointer to the interpolated random noise info */
240     ATSSTRUCT *atshead;
241     char    *filename;
242     int32_t swapped;    /* indicates if the data file is byte swapped or not */
243     double noiphase[25];
244     double phaseinc[25];
245 
246 } ATSSINNOI;
247 
248 typedef struct _atspartialtap {
249     OPDS    h;
250     MYFLT   *kfreq, *kamp, *iparnum;    /* out: freq, amp, in: partialnumber */
251 } ATSPARTIALTAP;
252 
253 typedef struct _atsinterpread {
254     OPDS    h;
255     MYFLT   *kamp, *kfreq;              /* output amp, input: frequency */
256     int32_t     overflowflag;
257 } ATSINTERPREAD;
258 
259