Skip to content

Commit

Permalink
Merge pull request #762 from tidalcycles/fix-addivite-synthesis-phases
Browse files Browse the repository at this point in the history
Fix addivite synthesis phases
  • Loading branch information
felixroos authored Oct 27, 2023
2 parents 4761e25 + c085694 commit 1c7c823
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
15 changes: 8 additions & 7 deletions packages/superdough/synth.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -73,22 +73,23 @@ export function waveformN(partials, type) {
const ac = getAudioContext();
const osc = ac.createOscillator();

const amplitudes = {
sawtooth: (n) => 1 / n,
square: (n) => (n % 2 === 0 ? 0 : 1 / n),
triangle: (n) => (n % 2 === 0 ? 0 : 1 / (n * n)),
const terms = {
sawtooth: (n) => [0, -1 / n],
square: (n) => [0, n % 2 === 0 ? 0 : 1 / n],
triangle: (n) => [n % 2 === 0 ? 0 : 1 / (n * n), 0],
};

if (!amplitudes[type]) {
if (!terms[type]) {
throw new Error(`unknown wave type ${type}`);
}

real[0] = 0; // dc offset
imag[0] = 0;
let n = 1;
while (n <= partials) {
real[n] = amplitudes[type](n);
imag[n] = 0;
const [r, i] = terms[type](n);
real[n] = r;
imag[n] = i;
n++;
}

Expand Down
2 changes: 1 addition & 1 deletion packages/webaudio/scope.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export function drawTimeScope(

for (let i = triggerIndex; i < bufferSize; i++) {
const v = dataArray[i] + 1;
const y = (scale * (v - 1) + pos) * canvas.height;
const y = (1 - (scale * (v - 1) + pos)) * canvas.height;

if (i === 0) {
ctx.moveTo(x, y);
Expand Down

0 comments on commit 1c7c823

Please sign in to comment.