generate sinewaves with given frequencies, add Hann envelope and store in channel-last layout
(length, frequencies)
| 18 | |
| 19 | |
| 20 | def generate_waveforms(length, frequencies): |
| 21 | """ |
| 22 | generate sinewaves with given frequencies, |
| 23 | add Hann envelope and store in channel-last layout |
| 24 | """ |
| 25 | n = int(math.ceil(length)) |
| 26 | X = np.arange(n, dtype=np.float32) |
| 27 | |
| 28 | def window(x): |
| 29 | x = 2 * x / length - 1 |
| 30 | np.clip(x, -1, 1, out=x) |
| 31 | return 0.5 * (1 + np.cos(x * math.pi)) |
| 32 | |
| 33 | wave = np.sin(X[:, np.newaxis] * (np.array(frequencies) * (2 * math.pi))) |
| 34 | return wave * window(X)[:, np.newaxis] |
| 35 | |
| 36 | |
| 37 | def rosa_resample(input, in_rate, out_rate): |
no test coverage detected