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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AudioSynthWaveform::begin doesn't set the phase to 0 #312

Open
skybrian opened this issue Jan 14, 2020 · 3 comments
Open

AudioSynthWaveform::begin doesn't set the phase to 0 #312

skybrian opened this issue Jan 14, 2020 · 3 comments

Comments

@skybrian
Copy link

Calling AudioSynthWaveform::begin() sets phase_offset to zero, but it doesn't clear the phase_accumulator field, so the wave doesn't actually start from zero.

Similarly for phase(), although in that case, maybe you just want to shift the phase of the running waveform a bit, instead of restarting from the beginning? If so, maybe the documentation should be clarified.

I found this when playing two sawtooth waves that are slightly detuned; the note starts at a different place each time. (Sometimes that's what you want, but not always.)

@skybrian
Copy link
Author

Here is how I edited my local copy. (I also added the code disabling interrupts.)

	void begin(short t_type) {
		__disable_irq();
		phase_offset = 0;
		phase_accumulator = 0;
		tone_type = t_type;
		__enable_irq();
	}
	void begin(float t_amp, float t_freq, short t_type) {
		__disable_irq();
		amplitude(t_amp);
		frequency(t_freq);
		phase_offset = 0;
		phase_accumulator = 0;
		tone_type = t_type;
		__enable_irq();
	}

@ErikDorstel
Copy link

I also came across this problem some time ago. Since I also have the requirement to set the phase to a certain value during runtime, I came up with another solution.

#275

@skybrian
Copy link
Author

If begin() cleared the phase accumulator, you could call phase() immediately after to set the phase. That seems a bit obscure though, compared to phase() actually setting the phase.

Advancing the phase a bit would be more clearly written as something like: wave.phase(getPhase() + delta);

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

2 participants