flamo 0.1.6__py3-none-any.whl → 0.1.7__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
flamo/functional.py CHANGED
@@ -1,3 +1,4 @@
1
+ import math
1
2
  import torch
2
3
  import torch.nn as nn
3
4
  import numpy as np
@@ -175,11 +176,12 @@ def signal_gallery(
175
176
  - ``sweep``: A linear sweep from 20 Hz to 20 kHz.
176
177
  - ``wgn``: White Gaussian noise.
177
178
  - ``exp``: An exponential decay signal.
179
+ - ``velvet``: A velvet noise signal with density :attr:`rate` impulses per second.
178
180
  - ``reference``: A reference signal provided as argument :attr:`reference`.
179
181
 
180
182
  **Arguments**:
181
183
  - **batch_size** (int): The number of batches to generate.
182
- - **n_samples** (int): THe signal length in samples.
184
+ - **n_samples** (int): The signal length in samples.
183
185
  - **n_channel** (int): The number of channels in each signal.
184
186
  - **signal_type** (str, optional): The type of signal to generate. Defaults to 'impulse'.
185
187
  - **fs** (int, optional): The sampling frequency of the signals. Defaults to 48000.
@@ -198,6 +200,7 @@ def signal_gallery(
198
200
  "exp",
199
201
  "reference",
200
202
  "noise",
203
+ "velvet",
201
204
  }
202
205
 
203
206
  if signal_type not in signal_types:
@@ -243,6 +246,12 @@ def signal_gallery(
243
246
  .expand(batch_size, n_samples, n)
244
247
  .to(device)
245
248
  )
249
+ case "velvet":
250
+ x = torch.empty((batch_size, n_samples, n), device=device)
251
+ for i_batch in range(batch_size):
252
+ for i_ch in range(n):
253
+ x[i_batch, :, i_ch] = gen_velvet_noise(n_samples, fs, rate, device)
254
+ return x
246
255
  case "reference":
247
256
  if isinstance(reference, torch.Tensor):
248
257
  return reference.expand(batch_size, n_samples, n).to(device)
@@ -254,6 +263,38 @@ def signal_gallery(
254
263
  return torch.randn((batch_size, n_samples, n), device=device)
255
264
 
256
265
 
266
+ def gen_velvet_noise(n_samples: int, fs: int, density: float, device: str | torch.device = None) -> torch.Tensor:
267
+ r"""
268
+ Generate a velvet noise sequence.
269
+ **Arguments**:
270
+ - **n_samples** (int): The length of the signal in samples.
271
+ - **fs** (int): The sampling frequency of the signal in Hz.
272
+ - **density** (float): The density of impulses in impulses per second.
273
+ - **device** (str | torch.device): The device of constructed tensors.
274
+ **Returns**:
275
+ - torch.Tensor: A tensor of shape (n_samples,) containing the velvet noise sequence.
276
+ """
277
+ Td = fs / density # average distance between impulses
278
+ num_impulses = n_samples / Td # expected number of impulses
279
+ floor_impulses = math.floor(num_impulses)
280
+ grid = torch.arange(floor_impulses) * Td
281
+
282
+ jitter_factors = torch.rand(floor_impulses)
283
+ impulse_indices = torch.ceil(grid + jitter_factors * (Td - 1)).long()
284
+
285
+ # first impulse is at position 0 and all indices are within bounds
286
+ impulse_indices[0] = 0
287
+ impulse_indices = torch.clamp(impulse_indices, max=n_samples - 1)
288
+
289
+ # Generate random signs (+1 or -1)
290
+ signs = 2 * torch.randint(0, 2, (floor_impulses,)) - 1
291
+
292
+ # Construct sparse signal
293
+ sequence = torch.zeros(n_samples, device=device)
294
+ sequence[impulse_indices] = signs.float()
295
+
296
+ return sequence
297
+
257
298
  def hertz2rad(hertz: torch.Tensor, fs: int):
258
299
  r"""
259
300
  Convert frequency from Hz to rad.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: flamo
3
- Version: 0.1.6
3
+ Version: 0.1.7
4
4
  Summary: An Open-Source Library for Frequency-Domain Differentiable Audio Processing
5
5
  Project-URL: Homepage, https://github.com/gdalsanto/flamo
6
6
  Project-URL: Issues, https://github.com/gdalsanto/flamo/issues
@@ -1,5 +1,5 @@
1
1
  flamo/__init__.py,sha256=ujezWOJfD7DUoj4q1meeMUnB97rOEtNR7mYw_PE9LMg,49
2
- flamo/functional.py,sha256=9wl6fHkc8KMB5IMvbd_K7-z8Z2Miw0qOsNxWPItliPU,35138
2
+ flamo/functional.py,sha256=8cKYzR5GDzH4ph4ja7x1znNFL-8ufWoxa666QHaZR1A,36917
3
3
  flamo/utils.py,sha256=ypGKSABZMphgIrjCKgCH-zgR7BaupRbyzuUhsZFqAAM,3350
4
4
  flamo/auxiliary/__init__.py,sha256=7lVNh8OxHloZ4KPmp-iTUJnUbi8XbuRzGaQ3Z-NKXio,42
5
5
  flamo/auxiliary/eq.py,sha256=eIWMIq0ggizXLhTdeWWbgBXWUFXCJyoEbkBH7Gzasao,6779
@@ -18,7 +18,7 @@ flamo/optimize/utils.py,sha256=R5-KoZagRho3eykY88pC3UB2mc5SsE4Yv9X-ogskXdA,1610
18
18
  flamo/processor/__init__.py,sha256=paGdxGVZgA2VAs0tBwRd0bobzGxeyK79DS7ZGO8drkI,41
19
19
  flamo/processor/dsp.py,sha256=n92YJPrES-ydwHgXmZ9RkFevIC3n-Wh4X8I1QNZqcV0,126378
20
20
  flamo/processor/system.py,sha256=9XwLtaGEVs9glVOFvyiPnQpsnR_Wjrv6k1i1qCs8D1Q,42516
21
- flamo-0.1.6.dist-info/METADATA,sha256=n7uiBeQ1bqIP4Xwpmyx7Ah3FxCl2Xowucprz00lk2BM,7825
22
- flamo-0.1.6.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
23
- flamo-0.1.6.dist-info/licenses/LICENSE,sha256=smMocRH7xdPT5RvFNqSLtbSNzohXJM5G_rX1Qaej6vg,1120
24
- flamo-0.1.6.dist-info/RECORD,,
21
+ flamo-0.1.7.dist-info/METADATA,sha256=l7iOHLTNu4f4znfkj4uOFiAIMvFFo0gQKYycvQFpfZ0,7825
22
+ flamo-0.1.7.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
23
+ flamo-0.1.7.dist-info/licenses/LICENSE,sha256=smMocRH7xdPT5RvFNqSLtbSNzohXJM5G_rX1Qaej6vg,1120
24
+ flamo-0.1.7.dist-info/RECORD,,
File without changes