[Csnd] Creating an impulse response

Hey hey,
I've just started work on a simple tool to create an impulse response with Csound. I created an exponential sine sweep (ESS) and the inverse/reversed version of that, together with an ftable that holds the scaling factor k.

Now, I wonder, where to go from here? Should I really create all those f-tables from the raw sine sweep or should I already bring the recorded room response in there? Is there perhaps an example of that method in Csound?

Best wishes,

Jeanette

Hi Jeanette,

if you have these, I would think the way forward is to put together some code to do the convolution of the recorded sound and the inverse sweep. That can then just be rendered to a file.

Now that I think of it, it would be a nice utility for Csound. Once you have the mechanism fully ready in Csound, it could be converted into C code.

That's really nice anyway, we don't have an example I think, unless Iain has already written one.

best
Prof. Victor Lazzarini
Maynooth University
Ireland

Hey hey,
I've just started work on a simple tool to create an impulse response with Csound. I created an exponential sine sweep ESS and the inverse/reversed version of that, together with an ftable that holds the scaling factor k.

Now, I wonder, where to go from here? Should I really create all those f-tables from the raw sine sweep or should I already bring the recorded room response in there? Is there perhaps an example of that method in Csound?

Best wishes,

Jeanette

--
* PeerTube: Jeanette C. - MakerTube
* GitHub: jeanette-c · GitHub
* Youtube: https://www.youtube.com/channel/UCMS4rfGrTwz8W7jhC1Jnv7g

Csound mailing list
Csound@listserv.heanet.ie
LISTSERV 16.5 - CSOUND List at LISTSERV.HEANET.IE
Send bugs reports to
      Issues · csound/csound · GitHub
Discussions of bugs and features can be posted here

The information contained in this email may be confidential and privileged. It is intended only for the addressees stated above. If you are not an addressee any use, dissemination, distribution, publication or copying of the information contained in this email is strictly prohibited. If you have received this email in error, please immediately notify us by email at dataprotection@mu.ie<mailto:dataprotection@mu.ie> and delete this email from your system.

Please note that Maynooth University is subject to Freedom of Information and Data Protection laws. We may be required to disclose the content of emails under the FOI Act 2014, the Data Protection Act 2018 or GDPR.

Is don seolaí / do na seolaithe thuasluaite amháin an ríomhphost seo. D’fhéadfadh an t-eolas atá ann a bheith rúnda agus faoi phribhléid. Mura seolaí tú, tá cosc iomlán ar aon eolas atá sa ríomhphost seo a úsáid, a scaipeadh, a dháileadh, a fhoilsiú nó a chóipeáil. Má fuair tú an ríomhphost seo trí thimpiste, cuir sin in iúl dúinn láithreach trí ríomhphost a chur chuig dataprotection@mu.ie<mailto:dataprotection@mu.ie> agus scrios an ríomhphost seo ó do chóras.

Tabhair faoi deara go bhfuil Ollscoil Mhá Nuad faoi réir dhlíthe um Shaoráil Faisnéise agus um Chosaint Sonraí. D’fhéadfadh ceangal a bheith orainn ábhar ríomhphoist a nochtadh faoin Acht um Shaoráil Faisnéise 2014, faoin Acht um Chosaint Sonraí 2018 nó faoi GDPR.

Registered charity number 20037130

Csound mailing list
Csound@listserv.heanet.ie

Send bugs reports to
        Issues · csound/csound · GitHub
Discussions of bugs and features can be posted here

Hi Victor,
thank you. I'll try that and start with a Csound reverb to test. It's sort of how I understood it.

Just one question that had me bothered. If I do this, the generated file will be as long as the sine sweep plus the length of the reverb. Right? All other IR audio files I have seen, at least sound like a kind of impulse followed by the reverb and thus would, basically, have only the length of the reverb.

Best wishes,

Jeanette

Victor Lazzarini, May 6 2026:

I would expect that you would generate an IR with a length trying to match the reverb time of
the space you want to recreate. So for that a sine sweep of that length, then IR capture,
deconvolution, generates an IR of that same length.

The actual convolution length will be the length of your reverb input + IR (-1 sample),
so there will be a tail corresponding to the reverb time you used.

best

yes, but that’s a synthetic IR generator. We were talking about empirical IR capture using a sine sweep.
Jeanette was testing it with a reverb opcode just to see if the idea worked.

I’ve written the outline of a util as a Python script, for a proof-of-concept:

import numpy as np
import scipy.io.wavfile as wave
import matplotlib.pyplot as plt
import sys

if sys.argv[1] == "-g":
   twopi = 2*np.pi
   fs = 44100
   fname = sys.argv[2]
   siz = float(sys.argv[3])
   e = siz*fs
   t = np.arange(0,e)
   f = np.linspace(1,np.log(fs/2),int(e))
   sweep = np.zeros(e)
   ph = 0
   for n in t:
    sweep[n] = np.sin(ph)
    ph += np.exp(f[n])*twopi/fs
   wave.write(fname, fs, sweep)
else:
   fname = sys.argv[1]
   sname = sys.argv[2]
   oname = sys.argv[3]
   fs, sweep = wave.read(sname)
   fs, data = wave.read(fname)
   e = len(sweep)
   t = np.arange(0,e)
   f = np.linspace(1,np.log(fs/2),e)
   swp = np.zeros(2*e)
   inp = np.zeros(2*e)
   inp[:e] = data[:e]
   swp[:e] = sweep[:e]
   spec = 1/np.fft.rfft(swp)
   dspc = np.fft.rfft(inp)
   ir = np.fft.irfft(dspc*spec)
   wave.write(oname, fs, ir[:e])

It should be run twice - first to generate the sweep (-g flag), then with the captured recording and the sweep used to do it as
inputs, it generates an IR. If you have a sweep, it only needs the second action.

Next, I’ll code it into C and add it as a new standard utility (makeir, ?)

Hi Joachim,
thanks for sharing the code. As Victor said, my project is somewhat adjacent to yours, but we share enough common ground to take a few things here and there, which is helpful.

Thanks for sharing and best wishes,

Jeanette

Hi Victor,
thanks again for your script. The actual convolution is something I'd like to convert to Csound using its fft/ifft or rfft/rifft functions with a loop.

In my current version, I'm right at the stage where I trim the raw IR. The raw IR preoduced by convolving the recorded reverb with the inverse/reverse sine sweep produces a file with a quieter version of the original sine sweep at the beginning and then goes into the actual IR, as you would expect it.

My approach here is to detect samples crossing a certain onset threshhold, something like 10% of maximum as a starter. Is that even necessary, or should I just cut away the length of the original sweep? If the onset threshhold is the better way: should I look back to the nearest 0-crossing?

Best wishes,

Jeanette

Hi Jeanette,

I had a quick glance at the inverse sweep you generate and I think the deconvolution with it creates an IR that is rotated by 1/2 frame. So the actual IR starts midway, the first half is a time-aliased version. If you crop the result to 1/2 size by discarding the first part then you should be good to go.

In my Python code, the IR is the first half of the frame, second half is the time-aliased bit.

Prof. Victor Lazzarini
Maynooth University
Ireland

*Warning*

This email originated from outside of Maynooth University's Mail System. Do not reply, click links or open attachments unless you recognise the sender and know the content is safe.

Hi Victor,
thanks again for your script. The actual convolution is something I'd like to
convert to Csound using its fft/ifft or rfft/rifft functions with a loop.

In my current version, I'm right at the stage where I trim the raw IR. The raw
IR preoduced by convolving the recorded reverb with the inverse/reverse sine
sweep produces a file with a quieter version of the original sine sweep at the
beginning and then goes into the actual IR, as you would expect it.

My approach here is to detect samples crossing a certain onset threshhold,
something like 10% of maximum as a starter. Is that even necessary, or should
I just cut away the length of the original sweep? If the onset threshhold is
the better way: should I look back to the nearest 0-crossing?

Best wishes,

Jeanette

--
* PeerTube: Jeanette C. - MakerTube
* GitHub: jeanette-c · GitHub
* Youtube: https://www.youtube.com/channel/UCMS4rfGrTwz8W7jhC1Jnv7g

Csound mailing list
Csound@listserv.heanet.ie
LISTSERV 16.5 - CSOUND List at LISTSERV.HEANET.IE
Send bugs reports to
      Issues · csound/csound · GitHub
Discussions of bugs and features can be posted here

The information contained in this email may be confidential and privileged. It is intended only for the addressees stated above. If you are not an addressee any use, dissemination, distribution, publication or copying of the information contained in this email is strictly prohibited. If you have received this email in error, please immediately notify us by email at dataprotection@mu.ie<mailto:dataprotection@mu.ie> and delete this email from your system.

Please note that Maynooth University is subject to Freedom of Information and Data Protection laws. We may be required to disclose the content of emails under the FOI Act 2014, the Data Protection Act 2018 or GDPR.

Is don seolaí / do na seolaithe thuasluaite amháin an ríomhphost seo. D’fhéadfadh an t-eolas atá ann a bheith rúnda agus faoi phribhléid. Mura seolaí tú, tá cosc iomlán ar aon eolas atá sa ríomhphost seo a úsáid, a scaipeadh, a dháileadh, a fhoilsiú nó a chóipeáil. Má fuair tú an ríomhphost seo trí thimpiste, cuir sin in iúl dúinn láithreach trí ríomhphost a chur chuig dataprotection@mu.ie<mailto:dataprotection@mu.ie> agus scrios an ríomhphost seo ó do chóras.

Tabhair faoi deara go bhfuil Ollscoil Mhá Nuad faoi réir dhlíthe um Shaoráil Faisnéise agus um Chosaint Sonraí. D’fhéadfadh ceangal a bheith orainn ábhar ríomhphoist a nochtadh faoin Acht um Shaoráil Faisnéise 2014, faoin Acht um Chosaint Sonraí 2018 nó faoi GDPR.

Registered charity number 20037130

Csound mailing list
Csound@listserv.heanet.ie

Send bugs reports to
        Issues · csound/csound · GitHub
Discussions of bugs and features can be posted here

I’ve added the utility now

https://github.com/csound/csound/pull/2549

Prof. Victor Lazzarini
Maynooth University
Ireland

Also added an opcode, deconv, which may be handy:

instr 1
len:i = filelen("sweep.wav")*sr
tab:i = ftgen(1, 0, len, 2, 0)
swp:k[] init len+ksmps
inp:k[] init len+ksmps
cnt:k init 0
while cnt < len do
   swp shiftin diskin:a("sweep.wav”)
   inp shiftin diskin:a("rev.wav”)
   cnt += ksmps
od
outp:k[] deconv swp[:len-1], inp
copya2ftab outp, tab
turnoff
endin

very interesting.
should tab:i = ftgen(1, 0, len, 2, 0) not read len*sr?

Hello everyone,
my IR creator is done. Yes, a little late to the party for everyone who uses the latest Csound devel, but:
https://www.dropbox.com/scl/fi/yvvv8jlpeh7zm9sao6pss/ir_creator.zip?rlkey=3iovzi5orepqpujaf7j5yi25x
As you can see and hear, it works. You just need to run the CSDs in order.

One question: testing my created IR, it sound like the reverb plus the original. I compared it with fox.wav, which is inside the zip file. Is there a way to get rid of this?

When I generated the IR, I saved reverb with dry signal, because that would happen in a real environment. Is my inverse sine sweep wrong, missing a factor?

Best wishes,

Jeanette

Hi Joachim,
no, he used filelen("input.wav")*sr. Very sneaky. :slight_smile:

Best wishes,

Jeanette

joachim heintz, May 9 2026:

I guess so, but copya2ftab is probably resizing the table to fit the array

yes, you’re right, I can’t even read my own code.

I would think you should just save the reverb output. The sweep corresponds to the impulse (after deconv),
and the output is the impulse response (also after deconv). Keeping sweep adds an impulse to
the start, which corresponds to the dry signal. It’s actually up to you and what you want to get.

ah yes, sure, you are right ...

Hi Victor,
in Csound I could definitely record just the output of the reverb. But what happens in the real world? I suppose, there I can't help recording the original sweep as well. That was, why I created a mix of sweep and reverb to mimic that situation. Or do I not get something here? Quite possible.

Best wishes,

Jeanette

Victor Lazzarini, May 9 2026:

In the real world, it would depend on where you put the mics in relation to the sweep
source, and also whether you use directional or omni mics. I'd say it is possible to capture the room with very little of the original impulse.
Also we can go and edit the resulting IR, setting the first sample to zero, that'll cut off the direct sound completely. I'd say that might be the simplest way to prepare an IR.

So it depends on what effect is required.

Prof. Victor Lazzarini
Maynooth University
Ireland

Hi Victor,
in Csound I could definitely record just the output of the reverb. But what happens in the real world? I suppose, there I can't help recording the original sweep as well. That was, why I created a mix of sweep and reverb to mimic that situation. Or do I not get something here? Quite possible.

Best wishes,

Jeanette

Victor Lazzarini, May 9 2026:

I would think you should just save the reverb output. The sweep corresponds to the impulse after deconv,
and the output is the impulse response also after deconv. Keeping sweep adds an impulse to
the start, which corresponds to the dry signal. It’s actually up to you and what you want to get.

========================
Prof. Victor Lazzarini
Maynooth University
Ireland

Hello everyone,
my IR creator is done. Yes, a little late to the party for everyone who uses the latest Csound devel, but:
Dropbox
As you can see and hear, it works. You just need to run the CSDs in order.

One question: testing my created IR, it sound like the reverb plus the original. I compared it with fox.wav, which is inside the zip file. Is there a way to get rid of this?

When I generated the IR, I saved reverb with dry signal, because that would happen in a real environment. Is my inverse sine sweep wrong, missing a factor?

Best wishes,

Jeanette

--
* PeerTube: Jeanette C. - MakerTube
* GitHub: jeanette-c · GitHub
* Youtube: https://www.youtube.com/channel/UCMS4rfGrTwz8W7jhC1Jnv7g

Csound mailing list
Csound@listserv.heanet.ie
LISTSERV 16.5 - CSOUND List at LISTSERV.HEANET.IE
Send bugs reports to
     Issues · csound/csound · GitHub
Discussions of bugs and features can be posted here

The information contained in this email may be confidential and privileged. It is intended only for the addressees stated above. If you are not an addressee any use, dissemination, distribution, publication or copying of the information contained in this email is strictly prohibited. If you have received this email in error, please immediately notify us by email at dataprotection@mu.ie<mailto:dataprotection@mu.ie> and delete this email from your system.

Please note that Maynooth University is subject to Freedom of Information and Data Protection laws. We may be required to disclose the content of emails under the FOI Act 2014, the Data Protection Act 2018 or GDPR.

Is don seolaí / do na seolaithe thuasluaite amháin an ríomhphost seo. D’fhéadfadh an t-eolas atá ann a bheith rúnda agus faoi phribhléid. Mura seolaí tú, tá cosc iomlán ar aon eolas atá sa ríomhphost seo a úsáid, a scaipeadh, a dháileadh, a fhoilsiú nó a chóipeáil. Má fuair tú an ríomhphost seo trí thimpiste, cuir sin in iúl dúinn láithreach trí ríomhphost a chur chuig dataprotection@mu.ie<mailto:dataprotection@mu.ie> agus scrios an ríomhphost seo ó do chóras.

Tabhair faoi deara go bhfuil Ollscoil Mhá Nuad faoi réir dhlíthe um Shaoráil Faisnéise agus um Chosaint Sonraí. D’fhéadfadh ceangal a bheith orainn ábhar ríomhphoist a nochtadh faoin Acht um Shaoráil Faisnéise 2014, faoin Acht um Chosaint Sonraí 2018 nó faoi GDPR.

Registered charity number 20037130

Csound mailing list
Csound@listserv.heanet.ie
LISTSERV 16.5 - CSOUND List at LISTSERV.HEANET.IE
Send bugs reports to
      Issues · csound/csound · GitHub
Discussions of bugs and features can be posted here

--
* PeerTube: Jeanette C. - MakerTube
* GitHub: jeanette-c · GitHub
* Youtube: https://www.youtube.com/channel/UCMS4rfGrTwz8W7jhC1Jnv7g

Csound mailing list
Csound@listserv.heanet.ie
LISTSERV 16.5 - CSOUND List at LISTSERV.HEANET.IE
Send bugs reports to
      Issues · csound/csound · GitHub
Discussions of bugs and features can be posted here

The information contained in this email may be confidential and privileged. It is intended only for the addressees stated above. If you are not an addressee any use, dissemination, distribution, publication or copying of the information contained in this email is strictly prohibited. If you have received this email in error, please immediately notify us by email at dataprotection@mu.ie<mailto:dataprotection@mu.ie> and delete this email from your system.

Please note that Maynooth University is subject to Freedom of Information and Data Protection laws. We may be required to disclose the content of emails under the FOI Act 2014, the Data Protection Act 2018 or GDPR.

Is don seolaí / do na seolaithe thuasluaite amháin an ríomhphost seo. D’fhéadfadh an t-eolas atá ann a bheith rúnda agus faoi phribhléid. Mura seolaí tú, tá cosc iomlán ar aon eolas atá sa ríomhphost seo a úsáid, a scaipeadh, a dháileadh, a fhoilsiú nó a chóipeáil. Má fuair tú an ríomhphost seo trí thimpiste, cuir sin in iúl dúinn láithreach trí ríomhphost a chur chuig dataprotection@mu.ie<mailto:dataprotection@mu.ie> agus scrios an ríomhphost seo ó do chóras.

Tabhair faoi deara go bhfuil Ollscoil Mhá Nuad faoi réir dhlíthe um Shaoráil Faisnéise agus um Chosaint Sonraí. D’fhéadfadh ceangal a bheith orainn ábhar ríomhphoist a nochtadh faoin Acht um Shaoráil Faisnéise 2014, faoin Acht um Chosaint Sonraí 2018 nó faoi GDPR.

Registered charity number 20037130

Csound mailing list
Csound@listserv.heanet.ie

Send bugs reports to
        Issues · csound/csound · GitHub
Discussions of bugs and features can be posted here

Hi Victor,
ah, there was something. I forgot to consider the convolver's partition size of 64 samples. I have adjusted it and it works very well. Of course, I couldn't compare waveforms or anything, but it sounds very close, neigh identical.

Best wishes,

Jeanette