File: convolve.html

package info (click to toggle)
csound-doc 3.47b2-2
  • links: PTS
  • area: non-free
  • in suites: woody
  • size: 1,492 kB
  • ctags: 272
  • sloc: makefile: 36
file content (149 lines) | stat: -rw-r--r-- 9,227 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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
<HTML>
<HEAD>
   <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
   <META NAME="GENERATOR" CONTENT="Mozilla/4.03 [en] (X11; I; IRIX 6.3 IP32) [Netscape]">
   <TITLE>CONVOLVE</TITLE>
</HEAD>
<BODY>

<CENTER><A NAME="convolve"></A>
<HR><B><A HREF="../REFER.html">QUICK-REF</A></B> - <B><A HREF="../TITLE.html"><FONT SIZE=+1>C</FONT>soundManual</A></B>
- <B><A HREF="SIG_MOD.html">Top of this section</A></B> - <A HREF="reverb2.html">Previous</A>
- <A HREF="../CONTENTS.html">Contents</A> - <A HREF="../INDEX.html">Index</A>
- <B><A HREF="../Spectral/SPECTRAL.html">Next Section</A>&nbsp;</B>&nbsp;
<HR></CENTER>

<H2>
convolve</H2>

<PRE>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ar1[,ar2[,ar3[,ar4]]]&nbsp; <B>convolve</B>&nbsp; ain, ifilcod, ichannel</PRE>

<HR>
<H4>
<U>DESCRIPTION</U></H4>
Output is the convolution of signal <I>ain</I> and the impulse response
contained in <I>ifilcod</I>. If more than one output signal is supplied,
each will be convolved with the same impulse response. Note that it is
considerably more efficient to use one instance of the operator when processing
a mono input to create stereo, or quad, outputs.
<H4>
<U>INITIALIZATION</U></H4>
<I>ifilcod</I> - integer or character-string denoting an impulse response
data file. An integer denotes the suffix of a file <I>convolve.m</I>; a
character string (in double quotes) gives a filename, optionally a full
pathname. If not a fullpath, the file is sought first in the the current
directory, then in the one given by the environment variable <A HREF="../Syntax/dir.html">SADIR</A>
(if defined). The data file contains the Fourier transform of an impulse
response. Memory usage depends on the size of the data file, which is read
and held entirely in memory during computation, but which is shared by
multiple calls.
<H4>
<U>PERFORMANCE</U></H4>
CONVOLVE implements Fast Convolution. The output of this operator is delayed
with respect to the input. The following formulas should be used to calculate
the delay:
<PRE>For (1/kr) &lt;= IRdur:
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Delay = ceil(IRdur * kr) / kr
For (1/kr) > IRdur:&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Delay = IRdur * ceil(1/(kr*IRdur))
Where:
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; kr&nbsp; = Csound control rate
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; IRdur = duration, in seconds, of impulse response
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ceil(n) = smallest integer not smaller than n</PRE>
One should be careful to also take into account the initial delay, if any,
of the impulse response. For example, if an impulse response is created
from a recording, the soundfile may not have the initial delay included.
Thus, one should either ensure that the soundfile has the correct amount
of zero padding at the start, or, preferably, compensate for this delay
in the orchestra. (the latter method is more efficient). To compensate
for the delay in the orchestra, _subtract_ the initial delay from the result
calculated using the above formula(s), when calculating the required delay
to introduce into the 'dry' audio path.

<P>For typical applications, such as reverb, the delay will be in the order
of 0.5 to 1.5 seconds, or even longer. This renders the current implementation
unsuitable for real time applications. It could conceivably be used for
real time filtering however, if the number of taps is is small enough.

<P>The author intends to create a higher-level operator at some stage,
that would mix the wet &amp; dry signals, using the correct amount of delay
automatically.
<H4>
<U>EXAMPLE:</U></H4>
- Create frequency domain impulse response file:
<PRE>&nbsp; c:\> csound -Ucvanal l1_44.wav l1_44.cv</PRE>
- Determine duration of impulse response. For high accuracy, determine
the number of sample frames in the impulse response soundfile, and then
compute the duration with:
<PRE>&nbsp; duration = (sample frames)/(sample rate of soundfile)</PRE>
This is due to the fact that the SNDINFO utility only reports the duration
to the nearest 10ms. If you have a utility that reports the duration to
the required accuracy, then you can simply use the reported value directly.
<PRE>&nbsp; c:\> sndinfo l1_44.wav&nbsp;
&nbsp; length = 60822 samples, sample rate = 44100
&nbsp;
&nbsp; Duration = 60822/44100 = 1.379s.</PRE>
- Determine initial delay, if any, of impulse response. If the impulse
response has not had the initial delay removed, then you can skip this
step. If it has been removed, then the only way you will know the initial
delay is if the information has been provided separately. For this example,
let's assume that the initial delay is 60ms. (0.06s)

<P>- Determine the required delay to apply to the dry signal, to align
it with the convolved signal:
<PRE>&nbsp;
&nbsp; If kr = 441:
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1/kr = 0.0023, which is &lt;= IRdur (1.379s), so:
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Delay1&nbsp; = ceil(IRdur * kr) / kr
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; = ceil(608.14) / 441
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; = 609/441
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; = 1.38s
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp; Accounting for the initial delay:
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Delay2&nbsp; = 0.06s
&nbsp; Total delay&nbsp;&nbsp; = delay1 - delay2
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; = 1.38 - 0.06
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; = 1.32s</PRE>
- Create .orc file, e.g:
<PRE>&nbsp;; Simple demonstration of CONVOLVE operator, to apply reverb.
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sr = 44100
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; kr = 441
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ksmps = 100
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; nchnls = 2
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; instr&nbsp;&nbsp; 1
imix = 0.22 ; Wet/dry mix. Vary as desired.
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ; NB: 'Small' reverbs often require a much higher
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ; percentage of wet signal to sound interesting. 'Large'
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ; reverbs seem require less. Experiment! The wet/dry mix is
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ; very important - a small change can make a large difference.&nbsp;
ivol = 0.9&nbsp; ; Overall volume level of reverb. May need to adjust&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ; when wet/dry mix is changed, to avoid clipping.
idel = 1.32 ; Required delay to align dry audio with output of convolve.
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ; This can be automatically calculated within the orc file,&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ; if desired.
adry&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <B>soundin</B> "anechoic.wav"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ; input (dry) audio
awet1,awet2&nbsp;&nbsp;&nbsp;&nbsp; <B>convolve</B> adry,"l1_44.cv"&nbsp;&nbsp;&nbsp; ; stereo convolved (wet) audio
adrydel&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <B>delay</B>&nbsp;&nbsp; (1-imix)*adry,idel&nbsp; ; Delay dry signal, to align it with&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ; convolved signal. Apply level&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ; adjustment here too.
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <B>outs</B>&nbsp;&nbsp;&nbsp; ivol*(adrydel+imix*awet1),ivol*(adrydel+imix*awet2)&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ; Mix wet &amp; dry signals, and output
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; endin</PRE>
<B><U>AUTHOR:&nbsp;<BR>
<BR>
</U></B>Greg Sullivan<BR>
1996
<CENTER><P>
<HR><B><A HREF="../REFER.html">QUICK-REF</A></B> - <B><A HREF="../TITLE.html"><FONT SIZE=+1>C</FONT>soundManual</A></B>
- <B><A HREF="SIG_MOD.html">Top of this section</A></B> - <A HREF="reverb2.html">Previous</A>
- <A HREF="../CONTENTS.html">Contents</A> - <A HREF="../INDEX.html">Index</A>
- <B><A HREF="../Spectral/SPECTRAL.html">Next Section</A>&nbsp;</B>&nbsp;
<HR></CENTER>


<P><CENTER>
<B><I><FONT COLOR="#006600">HTML Csound Manual - <FONT SIZE=-1>&copy;
Jean Pich&eacute; &amp; Peter J. Nix, 1994-97</FONT></FONT></I></B>&nbsp;
</CENTER>
</HTML>