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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Real time synthesis with oscillator_bank #3788

Open
peastman opened this issue May 11, 2024 · 0 comments
Open

Real time synthesis with oscillator_bank #3788

peastman opened this issue May 11, 2024 · 0 comments

Comments

@peastman
Copy link

馃殌 The feature

I suggest adding another input and another output to oscillator_bank(). The new argument would contain the initial phases of the oscillators. The new output would contain the final phases at the end of the generated waveform.

To avoid roundoff error that grows with time, the returned phases should always be wrapped to the interval $[0, 2\pi]$.

Motivation, pitch

I want to use TorchAudio for real time synthesis. In this context, you generate just a small amount of audio at a time, perhaps a few milliseconds. You do this repeatedly, varying the synthesis parameters based on actions by the user, to create a live performance.

This requires the phases of the oscillators to be continuous across multiple calls to oscillator_bank(). Otherwise you get a discontinuity in the waveform.

Code to use it would look something like this.

phases = torch.zeros(num_oscillators)
while still_playing():
    waveform, phases = oscillator_bank(get_frequencies(), get_amplitudes(), sample_rate, phases)
    play_audio(waveform)

Alternatives

An alternative would be to create an OscillatorBank object that would internally store the phases, guaranteeing continuity across multiple calls. In that case the code might look like

oscillators = OscillatorBank(num_oscillators, sample_rate)
while still_playing():
    waveform = oscillators(get_frequencies(), get_amplitudes())
    play_audio(waveform)

Additional context

No response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant