|
9 | 9 | source
|
10 | 10 |
|
11 | 11 | """
|
12 |
| -from . import nfchoa |
13 |
| -from . import wfs |
| 12 | +from . import source as _source |
| 13 | +from .. import util as _util |
| 14 | +import numpy as np |
| 15 | + |
| 16 | + |
| 17 | +def secondary_source_point(c): |
| 18 | + """Create a point source for use in `sfs.time.synthesize()`.""" |
| 19 | + |
| 20 | + def secondary_source(position, _, signal, observation_time, grid): |
| 21 | + return _source.point(position, signal, observation_time, grid, c=c) |
| 22 | + |
| 23 | + return secondary_source |
| 24 | + |
| 25 | + |
| 26 | +def apply_delays(signal, delays): |
| 27 | + """Apply delays for every channel. |
| 28 | +
|
| 29 | + Parameters |
| 30 | + ---------- |
| 31 | + signal : (N,) array_like + float |
| 32 | + Excitation signal consisting of (mono) audio data and a sampling |
| 33 | + rate (in Hertz). A `DelayedSignal` object can also be used. |
| 34 | + delays : (C,) array_like |
| 35 | + Delay in seconds for each channel (C), negative values allowed. |
| 36 | +
|
| 37 | + Returns |
| 38 | + ------- |
| 39 | + `DelayedSignal` |
| 40 | + A tuple containing the delayed signals (in a `numpy.ndarray` |
| 41 | + with shape ``(N, C)``), followed by the sampling rate (in Hertz) |
| 42 | + and a (possibly negative) time offset (in seconds). |
| 43 | +
|
| 44 | + """ |
| 45 | + data, samplerate, initial_offset = _util.as_delayed_signal(signal) |
| 46 | + data = _util.asarray_1d(data) |
| 47 | + delays = _util.asarray_1d(delays) |
| 48 | + delays += initial_offset |
| 49 | + |
| 50 | + delays_samples = np.rint(samplerate * delays).astype(int) |
| 51 | + offset_samples = delays_samples.min() |
| 52 | + delays_samples -= offset_samples |
| 53 | + out = np.zeros((delays_samples.max() + len(data), len(delays_samples))) |
| 54 | + for column, row in enumerate(delays_samples): |
| 55 | + out[row:row + len(data), column] = data |
| 56 | + return _util.DelayedSignal(out, samplerate, offset_samples / samplerate) |
| 57 | + |
14 | 58 |
|
15 | 59 | from . import source
|
16 | 60 |
|
17 |
| -from .. import util as _util |
| 61 | +from . import nfchoa |
| 62 | +from . import wfs |
| 63 | + |
18 | 64 | from .. import array as _array
|
19 | 65 |
|
20 | 66 |
|
|
0 commit comments