Csound Csound-dev Csound-tekno Search About

[Csnd] HRTF-Neutralization of in-file

Date2018-07-05 15:52
FromSteffenE
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:

---------------------------------------------------------






sr = 44100
ksmps = 1
nchnls = 2
0dbfs = 1.0

instr 1
	kCnt init 0
	
	kHRIR_TD[] init 512		; (Time-Domain) Original HRIR soundfile in a k-rate
array
	kHRIR_FD[] init 512		; (Frequency-Domain) HRIR Soundfile
	kReci_HRIR_FD[] init 512	; Reciprocal of the (Frequency-Domain) HRIR 
	
	idur			= p3
	ifilename		= p4
	igain			= (p5 > 0.0 ? (p5) : (10^(p5*0.05)))
	igainenvelope	= p6
	kElevation 		= p7
	
	; 1 Step: Read in the sound file
	
	audioFile diskin2 ifilename, 1,0,1	

	; 2. Step: Choose the right HRIR file based on a elevation parameter
	
	if (kElevation >= -40.0 && kElevation <= -30.0) then 
	
	; 3. Step: Read-in the HRIR file (f-table or diskin2 ?)
		
		; aHRIR diskin2 "./full/elev-40/L-40e000a.wav"
		; or
		copyf2array kHRIR_TD, 1
			
	elseif (kElevation >= -30.0 && kElevation <= -20.0) then 
		copyf2array kHRIR_TD, 2		
	;elseif (kElevation >= -20.0 && kElevation <= -10.0) then
	;	copyf2array kHRIR_TD, 3
	;elseif (kElevation >= -10.0 && kElevation <= 0.0) then
	;	copyf2array kHRIR_TD, 4
	;elseif (kElevation >= 00.0 && kElevation <= 10.0) then
	;	copyf2array kHRIR_TD, 5
	;elseif (kElevation >= 10.0 && kElevation <= 20.0) then
	;	copyf2array kHRIR_TD, 6
	;elseif (kElevation >= 20.0 && kElevation <= 30.0) then
	;	copyf2array kHRIR_TD, 7
	;elseif (kElevation >= 20.0 && kElevation <= 40.0) then
	;	copyf2array kHRIR_TD, 8
	;elseif (kElevation >= 40.0 && kElevation <= 50.0) then
	;	copyf2array kHRIR_TD, 9
	;elseif (kElevation >= 50.0 && kElevation <= 60.0) then 
	;	copyf2array kHRIR_TD, 10
	;elseif (kElevation >= 60.0 && kElevation <= 70.0) then 
	;	copyf2array kHRIR_TD, 11
	;elseif (kElevation >= 70.0 && kElevation <= 80.0) then 
	;	copyf2array kHRIR_TD, 12
	;elseif (kElevation >= 	80.0 && kElevation <= 90.0) then 
	;	copyf2array kHRIR_TD, 13
	endif
	
	
	; 4. Step: FFT of the HRIR file
	
	kHRIR_FD[] rfft kHRIR_TD
	
	
	; 5. Step: Reciprocal of the FFT (divz)
	
	until kCnt == lenarray(kHRIR_FD) do
		kReci_HRIR_FD[kCnt] divz k(1.0), kHRIR_FD[kCnt], k(0.0)
		kCnt += 1
		od
		
	iTabSize = sr * 7   ; ...drums_mono.wav is 7 seconds in duration...
	giOutSndTab ftgen 14, 0, iTabSize, 10  ; ... dconv needs a f-table
	copya2ftab kReci_HRIR_FD, giOutSndTab  
	
	
	; 6. Step: Convolute the result with the sound file (dconv)
	
	ares dconv audioFile, k(512), 14 	; dconv needs a f-table number... how?
	
	
	; 7. Step: 
	
	out ares
endin




; # start-time samples gen-routine	file						skiptime 	format num-channels
f  1 0 		512 		1 		"./full/elev-40/L-40e000a.wav" 	0 		4 		1
f  2 0 		512 		1 		"./full/elev-30/L-30e000a.wav" 	0 		4 		1
f  3 0 		512 		1 		"./full/elev-20/L-20e000a.wav" 	0 		4 		1
f  4 0 		512 		1 		"./full/elev-10/L-10e000a.wav" 	0 		4 		1
f  5 0 		512 		1 		"./full/elev0/L0e000a.wav" 		0 		4 		1
f  6 0 		512 		1 		"./full/elev10/L10e000a.wav" 	0 		4 		1
f  7 0 		512 		1 		"./full/elev20/L20e000a.wav" 	0 		4 		1
f  8 0 		512 		1 		"./full/elev30/L30e000a.wav" 	0 		4 		1
f  9 0 		512 		1 		"./full/elev40/L40e000a.wav" 	0 		4 		1
f 10 0 		512 		1 		"./full/elev50/L50e000a.wav" 	0 		4 		1
f 11 0 		512 		1 		"./full/elev60/L60e000a.wav" 	0 		4 		1
f 12 0 		512 		1 		"./full/elev70/L70e000a.wav" 	0 		4 		1
f 13 0 		512 		1 		"./full/elev80/L80e000a.wav" 	0 		4 		1

i 1 0 6 "drums_mono.wav" 0.00 1000.00 -40.0




------------------------------------------------- 

So currently the code produces an error at Step 5, where I try to use
"ftgen" inside the instrument code, just so I can use "dconv" afterwards.
Well if "dconv" needs a f-table then "dconv" is not the command to use,
maybe... The "convolve" command takes an impulse-response file as an
argument, which I dont know how to produce. Then there is pconvolve which I
could use I guess when I safe the reciprocal of the HRIR back into a wav
file, correct me if I'm wrong. 
What is the right (or most suitable) approach to do this?

Thanks in advance.




--
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

Date2018-07-05 16:50
Fromjpff
SubjectRe: [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:
>
> ---------------------------------------------------------
>
> 
> 
> 
> 
>
> sr = 44100
> ksmps = 1
> nchnls = 2
> 0dbfs = 1.0
>
> instr 1
> 	kCnt init 0
>
> 	kHRIR_TD[] init 512		; (Time-Domain) Original HRIR soundfile in a k-rate
> array
> 	kHRIR_FD[] init 512		; (Frequency-Domain) HRIR Soundfile
> 	kReci_HRIR_FD[] init 512	; Reciprocal of the (Frequency-Domain) HRIR
>
> 	idur			= p3
> 	ifilename		= p4
> 	igain			= (p5 > 0.0 ? (p5) : (10^(p5*0.05)))
> 	igainenvelope	= p6
> 	kElevation 		= p7
>
> 	; 1 Step: Read in the sound file
>
> 	audioFile diskin2 ifilename, 1,0,1
>
> 	; 2. Step: Choose the right HRIR file based on a elevation parameter
>
> 	if (kElevation >= -40.0 && kElevation <= -30.0) then
>
> 	; 3. Step: Read-in the HRIR file (f-table or diskin2 ?)
>
> 		; aHRIR diskin2 "./full/elev-40/L-40e000a.wav"
> 		; or
> 		copyf2array kHRIR_TD, 1
>
> 	elseif (kElevation >= -30.0 && kElevation <= -20.0) then
> 		copyf2array kHRIR_TD, 2
> 	;elseif (kElevation >= -20.0 && kElevation <= -10.0) then
> 	;	copyf2array kHRIR_TD, 3
> 	;elseif (kElevation >= -10.0 && kElevation <= 0.0) then
> 	;	copyf2array kHRIR_TD, 4
> 	;elseif (kElevation >= 00.0 && kElevation <= 10.0) then
> 	;	copyf2array kHRIR_TD, 5
> 	;elseif (kElevation >= 10.0 && kElevation <= 20.0) then
> 	;	copyf2array kHRIR_TD, 6
> 	;elseif (kElevation >= 20.0 && kElevation <= 30.0) then
> 	;	copyf2array kHRIR_TD, 7
> 	;elseif (kElevation >= 20.0 && kElevation <= 40.0) then
> 	;	copyf2array kHRIR_TD, 8
> 	;elseif (kElevation >= 40.0 && kElevation <= 50.0) then
> 	;	copyf2array kHRIR_TD, 9
> 	;elseif (kElevation >= 50.0 && kElevation <= 60.0) then
> 	;	copyf2array kHRIR_TD, 10
> 	;elseif (kElevation >= 60.0 && kElevation <= 70.0) then
> 	;	copyf2array kHRIR_TD, 11
> 	;elseif (kElevation >= 70.0 && kElevation <= 80.0) then
> 	;	copyf2array kHRIR_TD, 12
> 	;elseif (kElevation >= 	80.0 && kElevation <= 90.0) then
> 	;	copyf2array kHRIR_TD, 13
> 	endif
>
>
> 	; 4. Step: FFT of the HRIR file
>
> 	kHRIR_FD[] rfft kHRIR_TD
>
>
> 	; 5. Step: Reciprocal of the FFT (divz)
>
> 	until kCnt == lenarray(kHRIR_FD) do
> 		kReci_HRIR_FD[kCnt] divz k(1.0), kHRIR_FD[kCnt], k(0.0)
> 		kCnt += 1
> 		od
>
> 	iTabSize = sr * 7   ; ...drums_mono.wav is 7 seconds in duration...
> 	giOutSndTab ftgen 14, 0, iTabSize, 10  ; ... dconv needs a f-table
> 	copya2ftab kReci_HRIR_FD, giOutSndTab
>
>
> 	; 6. Step: Convolute the result with the sound file (dconv)
>
> 	ares dconv audioFile, k(512), 14 	; dconv needs a f-table number... how?
>
>
> 	; 7. Step:
>
> 	out ares
> endin
>
> 
> 
>
> ; # start-time samples gen-routine	file						skiptime 	format num-channels
> f  1 0 		512 		1 		"./full/elev-40/L-40e000a.wav" 	0 		4 		1
> f  2 0 		512 		1 		"./full/elev-30/L-30e000a.wav" 	0 		4 		1
> f  3 0 		512 		1 		"./full/elev-20/L-20e000a.wav" 	0 		4 		1
> f  4 0 		512 		1 		"./full/elev-10/L-10e000a.wav" 	0 		4 		1
> f  5 0 		512 		1 		"./full/elev0/L0e000a.wav" 		0 		4 		1
> f  6 0 		512 		1 		"./full/elev10/L10e000a.wav" 	0 		4 		1
> f  7 0 		512 		1 		"./full/elev20/L20e000a.wav" 	0 		4 		1
> f  8 0 		512 		1 		"./full/elev30/L30e000a.wav" 	0 		4 		1
> f  9 0 		512 		1 		"./full/elev40/L40e000a.wav" 	0 		4 		1
> f 10 0 		512 		1 		"./full/elev50/L50e000a.wav" 	0 		4 		1
> f 11 0 		512 		1 		"./full/elev60/L60e000a.wav" 	0 		4 		1
> f 12 0 		512 		1 		"./full/elev70/L70e000a.wav" 	0 		4 		1
> f 13 0 		512 		1 		"./full/elev80/L80e000a.wav" 	0 		4 		1
>
> i 1 0 6 "drums_mono.wav" 0.00 1000.00 -40.0
>
> 
> 
>
> -------------------------------------------------
>
> So currently the code produces an error at Step 5, where I try to use
> "ftgen" inside the instrument code, just so I can use "dconv" afterwards.
> Well if "dconv" needs a f-table then "dconv" is not the command to use,
> maybe... The "convolve" command takes an impulse-response file as an
> argument, which I dont know how to produce. Then there is pconvolve which I
> could use I guess when I safe the reciprocal of the HRIR back into a wav
> file, correct me if I'm wrong.
> What is the right (or most suitable) approach to do this?
>
> Thanks in advance.
>
>
>
>
> --
> 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

Date2018-07-05 17:36
FromSteffenE
SubjectRe: [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

Date2018-07-05 17:58
FromSteffenE
SubjectRe: [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

Date2018-07-05 18:14
Fromjpff
SubjectRe: [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

Date2018-07-05 18:18
Fromjpff
SubjectRe: [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

Date2018-07-05 18:26
Fromjoachim heintz
SubjectRe: [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

Date2018-07-05 21:33
FromSteffenE
SubjectRe: [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

Date2018-07-05 21:49
Fromjoachim heintz
SubjectRe: [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

Date2018-07-06 09:38
FromSteffenE
SubjectRe: [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

Date2018-07-06 18:19
Fromjoachim heintz
SubjectRe: [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

Date2018-07-09 19:13
FromSteffenE
SubjectRe: [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

Date2018-07-10 18:14
Fromjpff
SubjectRe: [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

Date2018-07-12 10:53
FromSteffenE
SubjectRe: [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