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

Question: how to phase oscillator by certain degree #340

Closed
beckend opened this issue Apr 1, 2022 · 2 comments
Closed

Question: how to phase oscillator by certain degree #340

beckend opened this issue Apr 1, 2022 · 2 comments

Comments

@beckend
Copy link

beckend commented Apr 1, 2022

import { osc, sin } from '@thi.ng/dsp'

const FS = 44100;

const o = osc(sin, 100 / FS, 0.5);

// starts with [0, ...]
console.log(o.take(10)

how to phase it by exact degrees and take values from that?

@postspectacular
Copy link
Member

Hi @beckend - I just pushed some changes which will allow specifying start phase at creation time. Until this is released you can also achieve this like so:

const o = osc(sin, 100 / FS, 0.5);
o.setFreq(100 / FS, 0.25 /** 1/2π */); // normalized phase as 2nd arg
o.take(10);
// [
//   0.5,
//   0.4999492524336743,
//   0.49979702003595905,
//   0.49954333370854914,
//   0.4991882449472994,
//   0.4987318258317718,
//   0.4981741690106035,
//   0.49751538768270076,
//   0.49675561557426,
//   0.49589500691162314
// ]

Hope that helps!

@beckend
Copy link
Author

beckend commented Apr 1, 2022

Thank you @postspectacular

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