Created
November 12, 2024 08:56
-
-
Save francescopapaleo/aeec4b3a4a7dd076dc6641ed6880bb7b to your computer and use it in GitHub Desktop.
Lambda functions with Torch for basic DSP conversions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import torch | |
| torch.pi = torch.acos(torch.zeros(1)).item() * 2 # which is 3.1415927410125732 | |
| db_to_mag = lambda x: 10 ** (x / 20) | |
| mag_to_db = lambda x: 20 * torch.log10(x) | |
| normalize = lambda x: x / torch.max(torch.abs(x), dim=1, keepdim=True)[0] | |
| midi_to_hz = lambda x: 440 * (2 ** ((x - 69) / 12)) | |
| hz_to_midi = lambda x: 12 * torch.log2(x / 440) + 69 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment