1 /*
2     pvsbasic.h:
3     basic opcodes for transformation of streaming PV signals
4 
5     Copyright (c) Victor Lazzarini, 2004
6 
7     This file is part of Csound.
8 
9     The Csound Library is free software; you can redistribute it
10     and/or modify it under the terms of the GNU Lesser General Public
11     License as published by the Free Software Foundation; either
12     version 2.1 of the License, or (at your option) any later version.
13 
14     Csound is distributed in the hope that it will be useful,
15     but WITHOUT ANY WARRANTY; without even the implied warranty of
16     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17     GNU Lesser General Public License for more details.
18 
19     You should have received a copy of the GNU Lesser General Public
20     License along with Csound; if not, write to the Free Software
21     Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
22     02110-1301 USA
23 */
24 
25 /*
26    PVSMOOTH:
27    fsig  pvsmooth  fsigin, kcfa, kcff
28 
29    Smooths the spectral functions of a pvs signal.
30 
31    fsigin: input signal
32    kcfa:  cutoff frequency amount of LP filter applied to amplitudes
33           (0 - 1)
34    kcff: cutoff frequency amount of LP filter applied to frequencies
35           (0 - 1)
36 
37    PVSFREEZE:
38    fsig pvsfreeze fsigin, kfreeza, freezf
39 
40    Freeze a spectral frame.
41 
42    fsigin: input
43    kfreeza: amplitude freezing (1=on, 0=off)
44    kfreezf: frequency freezing (1=on, 0=off)
45 
46    PVSMIX:
47    fsig  pvsmix  fsigin1, fsigin2
48 
49    Mix 'seamlessly' two pv signals.
50 
51    fsigin1, fsigin2: input signals.
52 
53    PVSFILTER:
54    fsig pvsfilter  fsigin, fsigfil, kdepth[, igain]
55 
56    Multiply amplitudes of fsigin by those of fsigfil, according to kdepth
57 
58    fsigin: input signal
59    fsigfil: filtering signal
60    kdepth: depth of filtering
61    igain: amplitude scaling
62 
63    PVSCALE:
64    fsig pvscale  fsigin, kscal[, ikeepform, igain]
65 
66    Scale the frequency components of a pv signal, resulting
67    in pitch shift.
68 
69    fsigin: input signal
70    kscal: scaling ratio
71    ikeepform: attempt to keep input signal formants; 0: do not keep formants;
72    1: keep formants by imposing original amps; 2: keep formants by filtering using
73    the original spec envelope (defaults to 0)
74    igain: amplitude scaling (defaults to 1)
75 
76    PVSHIFT:
77    fsig pvshift  fsigin, kshift, klowest [,ikeepform, igain]
78 
79    Shift the frequency components of a pv signal.
80 
81    fsigin: input signal
82    kshift: shift amount (in Hz)
83    klowest: lowest freq affected by the process.
84    ikeepform: attempt to keep input signal formants; 0: do not keep formants;
85    1: keep formants by imposing original amps; 2: keep formants by filtering using
86    the original spec envelope (defaults to 0)
87    igain: amplitude scaling (defaults to 1)
88 
89    PVBLUR:
90    fsig pvsblur  fsigin, kblurtime, imaxdel
91 
92    Average the amp/freq time functions of each analysis channel for
93    a specified time (truncated to number of frames).
94    The input signal will be delayed by that amount.
95 
96    fsigin: input signal
97    kblurtime: time in secs during which windows will be averaged.
98    imaxdel: max delay time, used for allocating memory for the averaging
99    operation.
100 
101    PVSTENCIL:
102    fsig pvstencil  fsigin, kgain, klevel, iftable
103 
104    Transforms a signal according to a masking function table; if the
105    signal normalised amplitude is below the value of the function for
106    a specific PV channel, it applies a gain to that channel.
107 
108    fsigin: input signal
109    kgain: 'stencil' gain
110    klevel: mask function level (ftable is scaled by this value prior to 'stenciling')
111    iftable: masking function table
112 
113    opcode table entries:
114    {"pvscale", S(PVSSCALE), 3,"f", "fkop", pvsscaleset, pvsscale, NULL },
115    {"pvshift", S(PVSSHIFT), 3,"f", "fkopo", pvsshiftset, pvsshift, NULL },
116    {"pvsmix", S(PVSMIX), 3, "f", "ff", pvsmixset, pvsmix, NULL},
117    {"pvsfilter", S(PVSFILTER), 3, "f", "ffkp", pvsfilterset, pvsfilter, NULL},
118    {"pvsblur", S(PVSBLUR), 3, "f", "fki", pvsblurset, pvsblur, NULL},
119    {"pvstencil", S(PVSTENCIL), 3, "f", "fkki", pvstencilset, pvstencil, NULL}
120    {"pvsinit", S(PVSINI), 3, "f", "", pvsinit, NULL, NULL}
121 */
122 
123 #ifndef _PVSBASIC_H
124 #define _PVSBASIC_H
125 
126 #include "pstream.h"
127 
128 typedef struct _pvsini {
129     OPDS    h;
130     PVSDAT  *fout;
131     MYFLT   *framesize, *olap, *winsize, *wintype, *format;
132     uint32  lastframe;
133 } PVSINI;
134 
135 typedef struct _pvsosc {
136     OPDS    h;
137     PVSDAT  *fout;
138     MYFLT   *ka, *kf, *type;
139     MYFLT   *framesize, *olap, *winsize, *wintype, *format;
140     MYFLT incr;
141     uint32  lastframe;
142 } PVSOSC;
143 
144 typedef struct _pvsbin {
145     OPDS    h;
146     MYFLT   *kamp, *kfreq;
147     PVSDAT  *fin;
148     MYFLT   *kbin;
149     uint32  lastframe;
150 } PVSBIN;
151 
152 typedef struct _pvsfreez {
153     OPDS    h;
154     PVSDAT  *fout;
155     PVSDAT  *fin;
156     MYFLT   *kfra, *kfrf;
157     AUXCH   freez;
158     uint32  lastframe;
159 } PVSFREEZE;
160 
161 typedef struct _pvsmooth {
162     OPDS    h;
163     PVSDAT  *fout;
164     PVSDAT  *fin;
165     MYFLT   *kfra, *kfrf;
166     AUXCH   del;
167     uint32  lastframe;
168 } PVSMOOTH;
169 
170 typedef struct _pvsmix {
171     OPDS    h;
172     PVSDAT  *fout;
173     PVSDAT  *fa;
174     PVSDAT  *fb;
175     uint32  lastframe;
176 } PVSMIX;
177 
178 static int32_t pvsmixset(CSOUND *, PVSMIX *p);
179 static int32_t pvsmix(CSOUND *, PVSMIX *p);
180 
181 typedef struct _pvsfilter {
182     OPDS    h;
183     PVSDAT  *fout;
184     PVSDAT  *fin;
185     PVSDAT  *fil;
186     MYFLT   *kdepth;
187     MYFLT   *gain;
188     uint32  lastframe;
189 } PVSFILTER;
190 
191 static int32_t pvsfilterset(CSOUND *, PVSFILTER *p);
192 static int32_t pvsfilter(CSOUND *, PVSFILTER *p);
193 
194 
195 typedef struct _pvsblur {
196     OPDS    h;
197     PVSDAT  *fout;
198     PVSDAT  *fin;
199     MYFLT   *kdel;
200     MYFLT   *maxdel;
201     AUXCH   delframes;
202     MYFLT   frpsec;
203     int32   count;
204     uint32  lastframe;
205 } PVSBLUR;
206 
207 static int32_t pvsblurset(CSOUND *, PVSBLUR *p);
208 static int32_t pvsblur(CSOUND *, PVSBLUR *p);
209 
210 typedef struct _pvstencil {
211     OPDS    h;
212     PVSDAT  *fout;
213     PVSDAT  *fin;
214     MYFLT   *kgain;
215     MYFLT   *klevel;
216     MYFLT   *ifn;
217     FUNC    *func;
218     uint32  lastframe;
219 } PVSTENCIL;
220 
221 static int32_t pvstencilset(CSOUND *, PVSTENCIL *p);
222 static int32_t
223 pvstencil(CSOUND *, PVSTENCIL *p);
224 
225 #endif
226 
227