Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Ray tracing method for RIR (#2850) #3234

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

nateanl
Copy link
Member

@nateanl nateanl commented Apr 3, 2023

Summary:
This PR adds the ray_tracing() helper to compute a RIR (part of #2624). The implementation is heavily based on pyroomacoustics.

Pull Request resolved: #2850

Differential Revision: D41764237

Pulled By: nateanl

@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D41764237

@nateanl
Copy link
Member Author

nateanl commented Apr 5, 2023

cc @fakufaku @JupiterEthan ray_tracing function should be ready, would like to hear thoughts from you. Thanks!

Comment on lines +50 to +58
const torch::Tensor& _absorption,
const torch::Tensor& _scattering,
const torch::Tensor& _normal,
const torch::Tensor& _origin)
: absorption(std::move(_absorption)),
reflection((scalar_t)1. - _absorption),
scattering(std::move(_scattering)),
normal(std::move(_normal)),
origin(std::move(_origin)) {}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Applying std::move to const reference is strange.
You can probably remove std::move and copy construct them.

Comment on lines +60 to +62
torch::Tensor get_absorption() {
return absorption;
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seems not used.

Comment on lines +63 to +68
torch::Tensor get_reflection() {
return reflection;
}
torch::Tensor get_scattering() {
return scattering;
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably, making it a attribute and accessing directly would do.

false; // TODO: remove this once hybrid method is supported
const int ISM_ORDER = 10; // TODO: remove this once ISM method is supported
#define EPS ((scalar_t)(1e-5))
#define VAL(t) (*((t).template data_ptr<scalar_t>()))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this macro is necessary. Simply calling item method should do.

Comment on lines +536 to +537
auto num_mics = mic_array.size(0);
auto num_bands = absorption.size(0);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cannot call size(0), without first checking the ndim >= 1

scalar_t _energy_thres,
scalar_t _time_thres,
scalar_t _hist_bin_size)
: room(_room),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the dimension of room is not checked.

time_thres(_time_thres),
hist_bin_size(_hist_bin_size),
max_dist(VAL(room.norm()) + (scalar_t)1.),
D(room.size(0)),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

D is unbounded. Need validation

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather, I'd make D a template parameter.


assert hist.shape == expected_shape

def test_ray_tracing_input_errors(self):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

need more of these. currently the implementation does not reject the invalid shapes like empty tensors.

scattering=scattering,
)

assert hist.shape == expected_shape
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use self.assertEqual. (Buck does not report numbers with assert)

Comment on lines +143 to +148
/**
* The main (and only) public entry point of this class. The histograms Tensor
* reference is passed along and modified in the subsequent private method
* calls. This method spawns num_rays rays in all directions from the source
* and calls simul_ray() on each of them.
*/
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use // for comment so that later it's easy to block the whole thing

Comment on lines +560 to +561
histograms = histograms.transpose(
1, 2); // back into shape (num_mics, num_bands, num_bins)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you move the comment to separate line? It's easier to read that way.

travel_dist += hit_distance;
transmitted *= wall.get_reflection();

// Let's shoot the scattered ray induced by the rebound on the wall
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// Let's shoot the scattered ray induced by the rebound on the wall
// Let's shoot the scattered ray induced by the rebound on the wall

Comment on lines +35 to +36
const bool IS_HYBRID_SIM =
false; // TODO: remove this once hybrid method is supported
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please move the comment to separate line

@pytorch-bot
Copy link

pytorch-bot bot commented Sep 8, 2023

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/audio/3234

Note: Links to docs will display an error until the docs builds have been completed.

❌ 7 New Failures

As of commit ca69eaa with merge base 5e893d6 (image):

NEW FAILURES - The following jobs have failed:

This comment was automatically generated by Dr. CI and updates every 15 minutes.

nateanl pushed a commit to nateanl/audio that referenced this pull request Sep 8, 2023
Summary:

This PR adds the `ray_tracing()` helper to compute a RIR (part of pytorch#2624). The implementation is heavily based on `pyroomacoustics`.


Differential Revision: D41764237

Pulled By: nateanl
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D41764237

}

if (intersection_found) {
next_wall_index = 2 * d[0] + ind_inc;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nateanl I feel like this should be d[0] + 2 * ind_inc. Do we have test to verify this is correct?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nateanl Actually, this is correct for 3D but not for 2D. Because for 2D the order of wall is SENW, while for 3D it's WESNCF.

Summary:

This PR adds the `ray_tracing()` helper to compute a RIR (part of pytorch#2624). The implementation is heavily based on `pyroomacoustics`.


Differential Revision: D41764237

Pulled By: nateanl
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D41764237

@mthrok mthrok mentioned this pull request Sep 12, 2023
mthrok added a commit to mthrok/audio that referenced this pull request Sep 12, 2023
Summary: Revamped version of pytorch#3234 (which was also revamp of pytorch#2850)

Differential Revision: D49197174
mthrok added a commit to mthrok/audio that referenced this pull request Sep 13, 2023
Summary:

Revamped version of pytorch#3234 (which was also revamp of pytorch#2850)

Differential Revision: D49197174
mthrok added a commit to mthrok/audio that referenced this pull request Sep 13, 2023
Summary:

Revamped version of pytorch#3234 (which was also revamp of pytorch#2850)

Differential Revision: D49197174
mthrok added a commit to mthrok/audio that referenced this pull request Oct 2, 2023
mthrok added a commit to mthrok/audio that referenced this pull request Oct 2, 2023
mthrok added a commit to mthrok/audio that referenced this pull request Oct 2, 2023
Summary:
Revamped version of pytorch#3234 (which was also revamp of pytorch#2850)

Differential Revision: D49197174

Pulled By: mthrok
mthrok added a commit to mthrok/audio that referenced this pull request Oct 2, 2023
Summary:
Revamped version of pytorch#3234 (which was also revamp of pytorch#2850)

Differential Revision: D49197174

Pulled By: mthrok
mthrok added a commit to mthrok/audio that referenced this pull request Oct 2, 2023
Summary:
Revamped version of pytorch#3234 (which was also revamp of pytorch#2850)

Differential Revision: D49197174

Pulled By: mthrok
mthrok added a commit that referenced this pull request Oct 2, 2023
mthrok added a commit to mthrok/audio that referenced this pull request Oct 2, 2023
Summary:
Revamped version of pytorch#3234 (which was also revamp of pytorch#2850)

Differential Revision: D49197174

Pulled By: mthrok
mthrok added a commit to mthrok/audio that referenced this pull request Oct 2, 2023
Summary:
Revamped version of pytorch#3234 (which was also revamp of pytorch#2850)

Differential Revision: D49197174

Pulled By: mthrok
mthrok added a commit to mthrok/audio that referenced this pull request Oct 3, 2023
Summary:
Revamped version of pytorch#3234 (which was also revamp of pytorch#2850)

Differential Revision: D49197174

Pulled By: mthrok
mthrok added a commit to mthrok/audio that referenced this pull request Oct 3, 2023
Summary:
Revamped version of pytorch#3234 (which was also revamp of pytorch#2850)

Differential Revision: D49197174

Pulled By: mthrok
mthrok added a commit to mthrok/audio that referenced this pull request Oct 3, 2023
Summary:
Revamped version of pytorch#3234 (which was also revamp of pytorch#2850)

Differential Revision: D49197174

Pulled By: mthrok
mthrok added a commit to mthrok/audio that referenced this pull request Oct 3, 2023
Summary:
Revamped version of pytorch#3234 (which was also revamp of pytorch#2850)

Differential Revision: D49197174

Pulled By: mthrok
mthrok added a commit to mthrok/audio that referenced this pull request Oct 3, 2023
Summary:
Revamped version of pytorch#3234 (which was also revamp of pytorch#2850)

Differential Revision: D49197174

Pulled By: mthrok
mthrok added a commit to mthrok/audio that referenced this pull request Oct 3, 2023
Summary:
Revamped version of pytorch#3234 (which was also revamp of pytorch#2850)

Differential Revision: D49197174

Pulled By: mthrok
mthrok added a commit to mthrok/audio that referenced this pull request Oct 4, 2023
Summary:
Revamped version of pytorch#3234 (which was also revamp of pytorch#2850)

Differential Revision: D49197174

Pulled By: mthrok
mthrok added a commit to mthrok/audio that referenced this pull request Oct 4, 2023
Summary:
Revamped version of pytorch#3234 (which was also revamp of pytorch#2850)

Differential Revision: D49197174

Pulled By: mthrok
mthrok added a commit to mthrok/audio that referenced this pull request Oct 4, 2023
Summary:
Revamped version of pytorch#3234 (which was also revamp of pytorch#2850)

Differential Revision: D49197174

Pulled By: mthrok
mthrok added a commit to mthrok/audio that referenced this pull request Oct 4, 2023
Summary:
Revamped version of pytorch#3234 (which was also revamp of pytorch#2850)

Differential Revision: D49197174

Pulled By: mthrok
mthrok added a commit to mthrok/audio that referenced this pull request Oct 5, 2023
Summary:
Revamped version of pytorch#3234 (which was also revamp of pytorch#2850)

Differential Revision: D49197174

Pulled By: mthrok
mthrok added a commit to mthrok/audio that referenced this pull request Oct 5, 2023
Summary:
Revamped version of pytorch#3234 (which was also revamp of pytorch#2850)

Differential Revision: D49197174

Pulled By: mthrok
mthrok added a commit to mthrok/audio that referenced this pull request Oct 5, 2023
Summary:
Revamped version of pytorch#3234 (which was also revamp of pytorch#2850)

Differential Revision: D49197174

Pulled By: mthrok
mthrok added a commit to mthrok/audio that referenced this pull request Oct 5, 2023
Summary:
Revamped version of pytorch#3234 (which was also revamp of pytorch#2850)

Differential Revision: D49197174

Pulled By: mthrok
mthrok added a commit to mthrok/audio that referenced this pull request Oct 5, 2023
Summary:
Revamped version of pytorch#3234 (which was also revamp of pytorch#2850)

Differential Revision: D49197174

Pulled By: mthrok
mthrok added a commit to mthrok/audio that referenced this pull request Oct 9, 2023
Summary:
Revamped version of pytorch#3234 (which was also revamp of pytorch#2850)

Differential Revision: D49197174

Pulled By: mthrok
mthrok added a commit to mthrok/audio that referenced this pull request Oct 9, 2023
Summary:
Revamped version of pytorch#3234 (which was also revamp of pytorch#2850)

Differential Revision: D49197174

Pulled By: mthrok
mthrok added a commit to mthrok/audio that referenced this pull request Oct 9, 2023
Summary:
Revamped version of pytorch#3234 (which was also revamp of pytorch#2850)

Differential Revision: D49197174

Pulled By: mthrok
mthrok added a commit to mthrok/audio that referenced this pull request Oct 13, 2023
Summary:
Revamped version of pytorch#3234 (which was also revamp of pytorch#2850)

Differential Revision: D49197174

Pulled By: mthrok
@mthrok mthrok mentioned this pull request Oct 13, 2023
mthrok added a commit that referenced this pull request Oct 13, 2023
Summary:
Revamped version of #3234
(which was also revamp of #2850)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants