DavidDiazGuerra / gpuRIR

Python library for Room Impulse Response (RIR) simulation with GPU acceleration
GNU Affero General Public License v3.0
477 stars 91 forks source link

Source directivity and various extensions to gpuRIR #27

Open fuerbringer opened 2 years ago

fuerbringer commented 2 years ago

As part of a semester project at uni we've expanded gpuRIR with the following features:

Source Directivity (fixes #16)

You can now steer the source and apply polar patterns with the new parameters orV_src and spkr_pattern.

For this purpose we've generated polar plots of the various patterns by rotating the source by 360 degrees:

polar_plot

Note: The source directivity features has been merged in #28

Extensions

We've developed various filters to make the Room impulse responses generated by gpuRIR more realistic. They're located in gpuRIR/extensions and can be imported as gpuRIR.extensions.*.

You can see them in action in our example scripts examples/mono_filters.py and examples/stereo_filters.py. Also consult the readme: gpuRIR/extensions/README.md.

We've uploaded the speech+guitar tracks which we've convolved with the RIRs that have gone through our filters: https://soundcloud.com/user-500297940/sets/gpurir-sound-samples

For reference, here's a spectrogram of a RIR generated by gpuRIR without any filters:

no_filter_spektro

Air absorption

We've created filters to apply the effects or air absorption to the RIRs. For this we've devised two options: Using the Short-time fourier transform or a bandpassed variant to apply the attenuations. The result is higher frequencies decaying much faster than lower frequencies which immidiately makes the RIRs sound more realistic.

STFT

stft_airabs_spektro

Bandpass

bandpass_airabs_spektro

Source and receiver characteristics

We've created filters to model frequency responses for speakers and microphones. Here's the Shure SM57 simulated:

char_sm57_spektro

Binaural Receivers

You can generate stereo RIRs (two channels). You can specify a position where the head shall be placed and the direction it looks towards. Then our code automatically places receivers where the "ears" should be. Here you can see a head placed in 3d space:

hrtf_3d

Head-related transfer function HRTF

We apply the effects of the HRTF to the RIRs generated by gpuRIR by using HRIRs from the CIPIC database. Note that we solely use the direct path vector between the head and source to calculate the azimuth and elevation.

image_2021-12-15_20-39-03

Frequency dependant wall absorption coefficients

Sound is reflected by sources dependant on the frequency. For this, we've consulted literature and extracted coefficients for various materials and frequencies. You can now define the materials the six walls in a room are made out of.

Here's a room made out of wallpapers on lime cement plaster, glued parquet floors and a concrete ceiling:

Freq_dep_mono


We think our extensions demonstrate the great usefulness and possible application of gpuRIR. If you feel like the extensions fit in the upstream repo, then we'd greatly appreciate it. Otherwise we can also keep the on our fork and only leave the source directivity in this PR.

If there's anything unclear or change suggestions, please tell us.

Thanks to our advisor(s) @schmiph2 for the very helpful support throughout the project and @DavidDiazGuerra for answering our questions regarding source directivity in great detail.

Best regards, Severin (@fuerbringer) and Oliver (@corrooli)

DavidDiazGuerra commented 2 years ago

Thank you very much @fuerbringer and @corrooli for all this work. By now, I have merged your PR with the source directivity implementation and I'll review the rest of the features during the next month.

DavidDiazGuerra commented 2 years ago

Hello!

I've made a couple of commits to the master branch of my repo today. fa32eb31f52b40e0bab9e7bda035268e6c5e44c0 fixes a bug you had with the shared memory of calcAmpTau_kernel (I don't know why GitHub says that I changed the whole src/gpuRIR_cuda.cu file when I just made minor changes in lines 313 and 805) and ae84cabb3e0f6416eb228c7e31f2d59d48f74e69 avoid copying the orientation of the sources and receivers to shared memory for omnidirectional directivity patterns so you can compute more RIRs in that case.

Could you add those commits to your branch so I can test your PR with that bug fixed?

DavidDiazGuerra commented 2 years ago

I could do it myself. I'll take a look at the extensions you propose in the following days/weeks.

fuerbringer commented 2 years ago

Sorry about that bug! Glad it could be fixed, though. We're currently in our end-of-semester exam phase until the end of January, so couldn't respond right away. Looking forward to see what you think of the extensions.

DavidDiazGuerra commented 2 years ago

Don't worry about the bug, that things happen. I know this isn't a good time for students, good luck with your exams!

DavidDiazGuerra commented 2 years ago

Hi @fuerbringer and @corrooli,

The extensions that you developed are really interesting, especially those about air absorption and frequency-dependent wall coefficients. I would love to integrate them better with the rest of the library, but I've been trying to find some time to do it during the past weeks and it was just impossible. I hope to be able to find some time for this in the future, but for now, I think I will accept the PR as you developed it.

However, before accepting the PR, I think it would be interesting if you include in extensions/README.md the references for the techniques that you used for your implementations. Most of them are approximations and there might be several ways to do them in the literature, so users could be interested in knowing which techniques are you using so they can be aware of their limitations when using the library.

Best regards, David

fuerbringer commented 2 years ago

Hi @DavidDiazGuerra

We could definitely reference the literature used and point out the limitations of our extensions. But we're in a similar situation, barely finding time for anything. We're currently working on our bachelor's thesis (computational acoustics based on parallel Adaptive Rectangular Decomposition) and job hunting and all that. Hopefully we'll find a free afternoon this semester to do it though.

DavidDiazGuerra commented 2 years ago

Ok, don't worry about this, there's no hurry. Just try to add the references when you have some time.

Good luck with your bachelor's thesis, it sounds really interesting and I'm sure you'll do a great job.