[Csnd] HRTF-Neutralization of in-file
| Date | 2018-07-05 15:52 |
| From | SteffenE |
| Subject | [Csnd] HRTF-Neutralization of in-file |
Hello List,
for a project I’ve tried to create an opcode that would neutralise the Head
Related Transfer Function between the loudspeakers and the ear-drum by using
a inverse Head Related Impulse Response that would be convoluted to a sound
file, in order to create the illusion the sound comes from an elevation of
0°. I only want to neutralize the elevation cue, therefore azimuth = 0° and
not even mentioned anywhere in the code below.
So when the sound would come from speakers that are at an elevation of
negative 30 degrees, I would take the inverse of the HRIR from the recorded
file that carries the -30° HRIR in order to equalise the directivity.
Well, I know, for ideal conditions I’d have to take personalised HRIR
recordings but I take what I can get and in this case I have the recordings
from the MIT
(http://sound.media.mit.edu/resources/KEMAR.html (I took the full.zip -
which contains time-domain recodings, not spectrum tables)) and maybe the
results aren’t too bad.
In theory, I’d have to convolute the reciprocal of the Fourier-transform of
the matching HRIR file with a soundfile.
I was wondering what would be the right approach to do this. I’m not very
confident with the available commands that I’d need for this, but I was
prototyping it like this:
1. Read-in the incoming sound file (diskin2)
2. Choose the right HRIR file based on a elevation parameter (if elseif)
3. Read-in the HRIR file (f-table or diskin2 ?)
4. FFT of the HRIR file (rfft?)
5. Reciprocal of the FFT (divz)
6. Convolute the result with the sound file (dconv)
7. Return the convolution result
My prototype:
---------------------------------------------------------
|
| Date | 2018-07-05 16:50 |
| From | jpff |
| Subject | Re: [Csnd] HRTF-Neutralization of in-file |
Should nt your ftgen have an extra argument like 1? gen10 needs to know the weight of each parial On Thu, 5 Jul 2018, SteffenE wrote: > Hello List, > > for a project I?ve tried to create an opcode that would neutralise the Head > Related Transfer Function between the loudspeakers and the ear-drum by using > a inverse Head Related Impulse Response that would be convoluted to a sound > file, in order to create the illusion the sound comes from an elevation of > 0?. I only want to neutralize the elevation cue, therefore azimuth = 0? and > not even mentioned anywhere in the code below. > > So when the sound would come from speakers that are at an elevation of > negative 30 degrees, I would take the inverse of the HRIR from the recorded > file that carries the -30? HRIR in order to equalise the directivity. > > Well, I know, for ideal conditions I?d have to take personalised HRIR > recordings but I take what I can get and in this case I have the recordings > from the MIT > (http://sound.media.mit.edu/resources/KEMAR.html (I took the full.zip - > which contains time-domain recodings, not spectrum tables)) and maybe the > results aren?t too bad. > > In theory, I?d have to convolute the reciprocal of the Fourier-transform of > the matching HRIR file with a soundfile. > > I was wondering what would be the right approach to do this. I?m not very > confident with the available commands that I?d need for this, but I was > prototyping it like this: > > 1. Read-in the incoming sound file (diskin2) > 2. Choose the right HRIR file based on a elevation parameter (if elseif) > 3. Read-in the HRIR file (f-table or diskin2 ?) > 4. FFT of the HRIR file (rfft?) > 5. Reciprocal of the FFT (divz) > 6. Convolute the result with the sound file (dconv) > 7. Return the convolution result > > My prototype: > > --------------------------------------------------------- > > |
| Date | 2018-07-05 17:36 |
| From | SteffenE |
| Subject | Re: [Csnd] HRTF-Neutralization of in-file |
Wait, so generating a f-table inside the instrument code is possible?
Well, good! But the content of the table at creation doesnt matter anyway so
I'd rather create an empty table if possible.
So I've appended a "1" in the parameter list and - tada it passes the line,
and an error occurs at the "dconv" command. dconf expects a f-table and I'd
like to tell it to take the last table, which is number 14.
But the "14" is interpreted as a "c" (meaning constant?).
How exactly can I reference the table in which I copied the reciprocal HRIR?
(copya2ftab kReci_HRIR_FD, 14) - which I now assume to not function as
intended..
--
Sent from: http://csound.1045644.n5.nabble.com/Csound-General-f1093014.html
Csound mailing list
Csound@listserv.heanet.ie
https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
Send bugs reports to
https://github.com/csound/csound/issues
Discussions of bugs and features can be posted here |
| Date | 2018-07-05 17:58 |
| From | SteffenE |
| Subject | Re: [Csnd] HRTF-Neutralization of in-file |
Thanks for the hint!
I tweaked the code at the f-table part.
iDuration filelen p4
iTabSize = sr * iDuration
giOutSndTab ftgen 14, 0, iTabSize, 10, 1
copya2ftab kReci_HRIR_FD, 14
ares dconv audioFile, k(512), 14
But the referencing to the f-table is not working this way.
I also tried with
iTable init 14
and then use the variable instead, but I guess I'm doing something wrong
giving the table argument.
--
Sent from: http://csound.1045644.n5.nabble.com/Csound-General-f1093014.html
Csound mailing list
Csound@listserv.heanet.ie
https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
Send bugs reports to
https://github.com/csound/csound/issues
Discussions of bugs and features can be posted here |
| Date | 2018-07-05 18:14 |
| From | jpff |
| Subject | Re: [Csnd] HRTF-Neutralization of in-file |
Use the result of the fgen opcode. c is indeed constant but shoukd be
coercable to i or k. Not had time to look at the code.....
On Thu, 5 Jul 2018, SteffenE wrote:
> Wait, so generating a f-table inside the instrument code is possible?
> Well, good! But the content of the table at creation doesnt matter anyway so
> I'd rather create an empty table if possible.
>
> So I've appended a "1" in the parameter list and - tada it passes the line,
> and an error occurs at the "dconv" command. dconf expects a f-table and I'd
> like to tell it to take the last table, which is number 14.
> But the "14" is interpreted as a "c" (meaning constant?).
> How exactly can I reference the table in which I copied the reciprocal HRIR?
> (copya2ftab kReci_HRIR_FD, 14) - which I now assume to not function as
> intended..
>
>
>
> --
> Sent from: http://csound.1045644.n5.nabble.com/Csound-General-f1093014.html
>
> Csound mailing list
> Csound@listserv.heanet.ie
> https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
> Send bugs reports to
> https://github.com/csound/csound/issues
> Discussions of bugs and features can be posted here
>
Csound mailing list
Csound@listserv.heanet.ie
https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
Send bugs reports to
https://github.com/csound/csound/issues
Discussions of bugs and features can be posted here |
| Date | 2018-07-05 18:18 |
| From | jpff |
| Subject | Re: [Csnd] HRTF-Neutralization of in-file |
dconv takes one audio argument anf two i-rte, Your use of k(512) is
wrong, use 512 direct.
On Thu, 5 Jul 2018, SteffenE wrote:
> Thanks for the hint!
> I tweaked the code at the f-table part.
>
> iDuration filelen p4
> iTabSize = sr * iDuration
> giOutSndTab ftgen 14, 0, iTabSize, 10, 1
>
> copya2ftab kReci_HRIR_FD, 14
>
> ares dconv audioFile, k(512), 14
>
> But the referencing to the f-table is not working this way.
> I also tried with
>
> iTable init 14
>
> and then use the variable instead, but I guess I'm doing something wrong
> giving the table argument.
>
>
>
> --
> Sent from: http://csound.1045644.n5.nabble.com/Csound-General-f1093014.html
>
> Csound mailing list
> Csound@listserv.heanet.ie
> https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
> Send bugs reports to
> https://github.com/csound/csound/issues
> Discussions of bugs and features can be posted here
>
Csound mailing list
Csound@listserv.heanet.ie
https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
Send bugs reports to
https://github.com/csound/csound/issues
Discussions of bugs and features can be posted here |
| Date | 2018-07-05 18:26 |
| From | joachim heintz |
| Subject | Re: [Csnd] HRTF-Neutralization of in-file |
hi steffen -
i cannot really run your csd, because i don't have all the files. but
i see something in your dconv call wich i don't understand:
ares dconv audioFile, k(512), 14
why k(512)? actually dconv expects isize, not ksize.
and: do you really mean to use direct convolution with a table of size
7*44100? i cannot imagine this to work.
best -
joachim
On 05/07/18 18:58, SteffenE wrote:
> Thanks for the hint!
> I tweaked the code at the f-table part.
>
> iDuration filelen p4
> iTabSize = sr * iDuration
> giOutSndTab ftgen 14, 0, iTabSize, 10, 1
>
> copya2ftab kReci_HRIR_FD, 14
>
> ares dconv audioFile, k(512), 14
>
> But the referencing to the f-table is not working this way.
> I also tried with
>
> iTable init 14
>
> and then use the variable instead, but I guess I'm doing something wrong
> giving the table argument.
>
>
>
> --
> Sent from: http://csound.1045644.n5.nabble.com/Csound-General-f1093014.html
>
> Csound mailing list
> Csound@listserv.heanet.ie
> https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
> Send bugs reports to
> https://github.com/csound/csound/issues
> Discussions of bugs and features can be posted here
>
Csound mailing list
Csound@listserv.heanet.ie
https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
Send bugs reports to
https://github.com/csound/csound/issues
Discussions of bugs and features can be posted here |
| Date | 2018-07-05 21:33 |
| From | SteffenE |
| Subject | Re: [Csnd] HRTF-Neutralization of in-file |
joachim-3 wrote
> why k(512)? actually dconv expects isize, not ksize.
>
> and: do you really mean to use direct convolution with a table of size
> 7*44100? i cannot imagine this to work.
The k(512) indeed was a mistake. I corrected it and it works. Thanks! I dont
know why I did that.
The direct convolution with the 7 seconds sample works, altough the result
sounds heavily distorted.
I also get a sinus plotted in the terminal which is the result of the gen10
- and I'm not sure if this f-table really gets overwritten by the
"copyf2array" command.
Because
1. there is no evidence to it / no monitoring of the process.
2. I'm not sure if just writing "14" as a parameter is a proper reference to
the 14th f-table. (same goes for the line with the ftgen command).
--
Sent from: http://csound.1045644.n5.nabble.com/Csound-General-f1093014.html
Csound mailing list
Csound@listserv.heanet.ie
https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
Send bugs reports to
https://github.com/csound/csound/issues
Discussions of bugs and features can be posted here |
| Date | 2018-07-05 21:49 |
| From | joachim heintz |
| Subject | Re: [Csnd] HRTF-Neutralization of in-file |
yes, 14 is a proper reference to the table. you can also write
ares dconv audioFile, k(512), giOutSndTab
but when you have
copya2ftab kReci_HRIR_FD, giOutSndTab
it will only copy the array to the first 512 points of the 7*sr sized
giOutSndTab, not?
On 05/07/18 22:33, SteffenE wrote:
> joachim-3 wrote
>> why k(512)? actually dconv expects isize, not ksize.
>>
>> and: do you really mean to use direct convolution with a table of size
>> 7*44100? i cannot imagine this to work.
>
> The k(512) indeed was a mistake. I corrected it and it works. Thanks! I dont
> know why I did that.
> The direct convolution with the 7 seconds sample works, altough the result
> sounds heavily distorted.
>
> I also get a sinus plotted in the terminal which is the result of the gen10
> - and I'm not sure if this f-table really gets overwritten by the
> "copyf2array" command.
> Because
> 1. there is no evidence to it / no monitoring of the process.
> 2. I'm not sure if just writing "14" as a parameter is a proper reference to
> the 14th f-table. (same goes for the line with the ftgen command).
>
>
>
>
>
> --
> Sent from: http://csound.1045644.n5.nabble.com/Csound-General-f1093014.html
>
> Csound mailing list
> Csound@listserv.heanet.ie
> https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
> Send bugs reports to
> https://github.com/csound/csound/issues
> Discussions of bugs and features can be posted here
>
Csound mailing list
Csound@listserv.heanet.ie
https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
Send bugs reports to
https://github.com/csound/csound/issues
Discussions of bugs and features can be posted here |
| Date | 2018-07-06 09:38 |
| From | SteffenE |
| Subject | Re: [Csnd] HRTF-Neutralization of in-file |
joachim-3 wrote
> yes, 14 is a proper reference to the table. you can also write
> ares dconv audioFile, k(512), giOutSndTab
>
> but when you have
> copya2ftab kReci_HRIR_FD, giOutSndTab
> it will only copy the array to the first 512 points of the 7*sr sized
> giOutSndTab, not?
Oh yes of course. That's a mistake too. The table doesnt need to be 7
seconds long anyway..
This is the table in which I want to copy the 512 samples reciprocal HRIR.
The name of the table is also wrong then. This is not the table that carries
the outgoing sound.
So the code is now:
until kCnt == lenarray(kHRIR_FD) do
printk 0.0001, kHRIR_FD[kCnt]
kReci_HRIR_FD[kCnt] divz k(1.0), kHRIR_FD[kCnt], k(0.0)
kCnt += 1
od
giReci_HRIR_FD ftgen 14, 0, 512, 10, 1
copya2ftab kReci_HRIR_FD, 14
ares dconv audioFile, 512, 14 ; dconv needs a f-table number... how?
out ares
But I'm wondering why the "printk" command in the until statement doesnt
print anything to the console.
Any hints? I was using this if loop before:
if kCnt < 512 then
printk 0.0001, kHRIR_FD[kCnt] ; rfft produces negative values!?
kReci_HRIR_FD[kCnt] divz k(1.0), kHRIR_FD[kCnt], k(0.0)
kCnt += ksmps
endif
In which I had the printed FFT results, which btw, produces negative values.
So 1. I'd like to print these values and 2. Why are the rfft values
negative? I thought these were the magnitudes.
--
Sent from: http://csound.1045644.n5.nabble.com/Csound-General-f1093014.html
Csound mailing list
Csound@listserv.heanet.ie
https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
Send bugs reports to
https://github.com/csound/csound/issues
Discussions of bugs and features can be posted here |
| Date | 2018-07-06 18:19 |
| From | joachim heintz |
| Subject | Re: [Csnd] HRTF-Neutralization of in-file |
for the print, try
printf "bin %d = %f\n", kCnt+1, kCnt, kHRIR_FD[kCnt]
perhaps printk2 works, too. printk is not updating in a loop, i think.
as to rfft, victor lazzarini should be able to tell.
j
On 06/07/18 10:38, SteffenE wrote:
> joachim-3 wrote
>> yes, 14 is a proper reference to the table. you can also write
>> ares dconv audioFile, k(512), giOutSndTab
>>
>> but when you have
>> copya2ftab kReci_HRIR_FD, giOutSndTab
>> it will only copy the array to the first 512 points of the 7*sr sized
>> giOutSndTab, not?
>
> Oh yes of course. That's a mistake too. The table doesnt need to be 7
> seconds long anyway..
> This is the table in which I want to copy the 512 samples reciprocal HRIR.
> The name of the table is also wrong then. This is not the table that carries
> the outgoing sound.
>
> So the code is now:
>
> until kCnt == lenarray(kHRIR_FD) do
> printk 0.0001, kHRIR_FD[kCnt]
> kReci_HRIR_FD[kCnt] divz k(1.0), kHRIR_FD[kCnt], k(0.0)
> kCnt += 1
> od
>
> giReci_HRIR_FD ftgen 14, 0, 512, 10, 1
>
> copya2ftab kReci_HRIR_FD, 14
>
> ares dconv audioFile, 512, 14 ; dconv needs a f-table number... how?
>
> out ares
>
> But I'm wondering why the "printk" command in the until statement doesnt
> print anything to the console.
> Any hints? I was using this if loop before:
>
> if kCnt < 512 then
> printk 0.0001, kHRIR_FD[kCnt] ; rfft produces negative values!?
> kReci_HRIR_FD[kCnt] divz k(1.0), kHRIR_FD[kCnt], k(0.0)
> kCnt += ksmps
> endif
>
> In which I had the printed FFT results, which btw, produces negative values.
> So 1. I'd like to print these values and 2. Why are the rfft values
> negative? I thought these were the magnitudes.
>
>
>
> --
> Sent from: http://csound.1045644.n5.nabble.com/Csound-General-f1093014.html
>
> Csound mailing list
> Csound@listserv.heanet.ie
> https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
> Send bugs reports to
> https://github.com/csound/csound/issues
> Discussions of bugs and features can be posted here
>
Csound mailing list
Csound@listserv.heanet.ie
https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
Send bugs reports to
https://github.com/csound/csound/issues
Discussions of bugs and features can be posted here |
| Date | 2018-07-09 19:13 |
| From | SteffenE |
| Subject | Re: [Csnd] HRTF-Neutralization of in-file |
joachim-3 wrote
> for the print, try
> printf "bin %d = %f\n", kCnt+1, kCnt, kHRIR_FD[kCnt]
>
> perhaps printk2 works, too. printk is not updating in a loop, i think.
>
> as to rfft, victor lazzarini should be able to tell.
Thank you very much joachim. Your advice helped me a lot so far!
I hope victor lazzarini joins the conversation. I'm quite clueless with the
rfft in this case,
especially because the official manual to it states that it returns non
negative values only.
> The output is another array containing the transform, non-redundant,
> non-negative spectrum only.
I'm not quite sure if the rfft and the dconv do what I think they do.
The console output is:
> ...
> bin 508 = 0.005435
> bin 509 = -0.000138
> bin 510 = 0.002948
> bin 511 = -0.002092
> B 0.000 .. 6.000 T 6.000 TT 6.000 M:7278.71896 0.00000
> number of samples out of range: 264231 0
> Score finished in csoundPerform().
> inactive allocs returned to freespace
> end of score. overall amps:7278.71896 0.00000
> overall samples out of range: 264231 0
> 0 errors in performance
> Elapsed time at end of performance: real: 7.361s, CPU: 1.914s
> closing device
> 2068 256 sample blks of 64-bit floats written to dac
How can there be samples out of range? Out of which range?
--
Sent from: http://csound.1045644.n5.nabble.com/Csound-General-f1093014.html
Csound mailing list
Csound@listserv.heanet.ie
https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
Send bugs reports to
https://github.com/csound/csound/issues
Discussions of bugs and features can be posted here |
| Date | 2018-07-10 18:14 |
| From | jpff |
| Subject | Re: [Csnd] HRTF-Neutralization of in-file |
On Mon, 9 Jul 2018, SteffenE wrote:
>> B 0.000 .. 6.000 T 6.000 TT 6.000 M:7278.71896 0.00000
>> number of samples out of range: 264231 0
>> Score finished in csoundPerform().
>> inactive allocs returned to freespace
>> end of score. overall amps:7278.71896 0.00000
>> overall samples out of range: 264231 0
>> 0 errors in performance
>> Elapsed time at end of performance: real: 7.361s, CPU: 1.914s
>> closing device
>> 2068 256 sample blks of 64-bit floats written to dac
>
> How can there be samples out of range? Out of which range?
>
Therange in question is -0dbfs to +0dbfs
I am guessing you did not set 0ddfs so the default value is 32k
There are mny reason why an algorithm may exceed the range if any
modification is made to a signal.
Csound mailing list
Csound@listserv.heanet.ie
https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
Send bugs reports to
https://github.com/csound/csound/issues
Discussions of bugs and features can be posted here |
| Date | 2018-07-12 10:53 |
| From | SteffenE |
| Subject | Re: [Csnd] HRTF-Neutralization of in-file |
jpff wrote
> On Mon, 9 Jul 2018, SteffenE wrote:
>
>
>>> B 0.000 .. 6.000 T 6.000 TT 6.000 M:7278.71896 0.00000
>>> number of samples out of range: 264231 0
>>> Score finished in csoundPerform().
>>> inactive allocs returned to freespace
>>> end of score. overall amps:7278.71896 0.00000
>>> overall samples out of range: 264231 0
>>> 0 errors in performance
>>> Elapsed time at end of performance: real: 7.361s, CPU: 1.914s
>>> closing device
>>> 2068 256 sample blks of 64-bit floats written to dac
>>
>> How can there be samples out of range? Out of which range?
>>
>
> Therange in question is -0dbfs to +0dbfs
>
> I am guessing you did not set 0ddfs so the default value is 32k
>
> There are mny reason why an algorithm may exceed the range if any
> modification is made to a signal.
>
> Csound mailing list
> Csound@.heanet
> https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
> Send bugs reports to
> https://github.com/csound/csound/issues
> Discussions of bugs and features can be posted here
Thank you for your answer. At first I thought of a array range, instead of a
amplitude range...
I did set the 0dbfs to 1.0.
The reason the amplitude is out of range is because I convolute the signal
with the reciprocal of a rather low amplitude signal, which results in very
high factors. I'm pretty sure that I have to normalize the HRIR files before
I use them, so that the reciprocal doesn't result in such extreme values.
But even then, I think I'll have to limit the convolution result.
Still... there is something odd with rfft. It shouldn't return negative
values and I dont know why it does.
--
Sent from: http://csound.1045644.n5.nabble.com/Csound-General-f1093014.html
Csound mailing list
Csound@listserv.heanet.ie
https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
Send bugs reports to
https://github.com/csound/csound/issues
Discussions of bugs and features can be posted here |