Skip to content

Commit

Permalink
Remove duplicate functions present in both sounds.js and soundToneMat…
Browse files Browse the repository at this point in the history
…rix.js (#928)
  • Loading branch information
iskandarzulkarnaien authored Sep 12, 2019
1 parent e00a7bd commit ceaec63
Showing 1 changed file with 0 additions and 46 deletions.
46 changes: 0 additions & 46 deletions public/externalLibs/sound/soundToneMatrix.js
Original file line number Diff line number Diff line change
Expand Up @@ -431,52 +431,6 @@ function midi_note_to_frequency(note) {
return 8.1757989156 * Math.pow(2, (note / 12));
}

function square_sound(freq, duration) {
function fourier_expansion_square(t) {
var answer = 0;
for (var i = 1; i <= fourier_expansion_level; i++) {
answer = answer +
Math.sin(2 * Math.PI * (2 * i - 1) * freq * t)
/
(2 * i - 1);
}
return answer;
}
return make_sound(t =>
(4 / Math.PI) * fourier_expansion_square(t),
duration);
}

function triangle_sound(freq, duration) {
function fourier_expansion_triangle(t) {
var answer = 0;
for (var i = 0; i < fourier_expansion_level; i++) {
answer = answer +
Math.pow(-1, i) *
Math.sin((2 * i + 1) * t * freq * Math.PI * 2)
/
Math.pow((2 * i + 1), 2);
}
return answer;
}
return make_sound(t =>
(8 / Math.PI / Math.PI) * fourier_expansion_triangle(t),
duration);
}

function sawtooth_sound(freq, duration) {
function fourier_expansion_sawtooth(t) {
var answer = 0;
for (var i = 1; i <= fourier_expansion_level; i++) {
answer = answer + Math.sin(2 * Math.PI * i * freq * t) / i;
}
return answer;
}
return make_sound(t =>
(1 / 2) - (1 / Math.PI) * fourier_expansion_sawtooth(t),
duration);
}

function linear_decay(decay_period) {
return function (t) {
if ((t > decay_period) || (t < 0)) {
Expand Down

0 comments on commit ceaec63

Please sign in to comment.