Skip to content

Commit

Permalink
super sampling
Browse files Browse the repository at this point in the history
  • Loading branch information
egonelbre committed Jan 23, 2011
1 parent b11c155 commit b1ff09d
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 14 deletions.
3 changes: 1 addition & 2 deletions index.html
Expand Up @@ -26,11 +26,11 @@
}
.button-set {
float: left;

padding-left: 20px;
margin-left: 20px;
border-left: 1px dotted #666;
}

.clear {
clear : both;
}
Expand Down Expand Up @@ -83,7 +83,6 @@ <h1>jsFx</h1>
</header>

<div id="main">
<h2>Parameters:</h2>
<div id="button-panel">
<div class="button-set">
<button onclick="jsfx.reset()">Reset</button>
Expand Down
43 changes: 31 additions & 12 deletions js/jsfx.js
Expand Up @@ -53,14 +53,20 @@ var jsfx = {};
ap("LP Filter Resonance", 0, 100, 50);
ap("HP Filter Cutoff", 0, 100, 50);
ap("HP Filter Cutoff Sweep", 0, 100, 50);
};

grp++;
ap("Super Sampling Quality", 0, 16, 0);
};

this.generate = function(params){
// useful consts
var TAU = 2 * Math.PI;
var SampleRate = audio.SampleRate;

// super sampling
// SampleRate = SampleRate * 4;
var super_sampling_quality = params.SuperSamplingQuality | 0;
if(super_sampling_quality < 1) super_sampling_quality = 1;
SampleRate = SampleRate * super_sampling_quality;

// useful functions
var sin = Math.sin;
Expand Down Expand Up @@ -107,9 +113,11 @@ var jsfx = {};
var phase = 0;
var phase_speed = params.StartFrequency * TAU / SampleRate;

// phase slide calculation
// phase slide calculation
var phase_slide = 1.0 + Math.pow(params.Slide, 3.0) * 3.0 / SampleRate;
var phase_delta_slide = Math.pow(params.DeltaSlide, 3.0) / (SampleRate * 1000);
var phase_delta_slide = Math.pow(params.DeltaSlide, 3.0) / (SampleRate * 1000);
if (super_sampling_quality !== undefined)
phase_delta_slide /= super_sampling_quality; // correction

// frequency limiter
if(params.MinFrequency > params.StartFrequency)
Expand Down Expand Up @@ -153,7 +161,6 @@ var jsfx = {};

// repeat
var repeat_time = 0;
console.debug(params.RepeatSpeed);
var repeat_limit = totalSamples;
if (params.RepeatSpeed > 0){
repeat_limit = Math.pow(1 - params.RepeatSpeed, 2.0) * SampleRate + 32;
Expand All @@ -173,6 +180,8 @@ var jsfx = {};
// phase slide reset
var phase_slide = 1.0 + Math.pow(params.Slide, 3.0) * 3.0 / SampleRate;
var phase_delta_slide = Math.pow(params.DeltaSlide, 3.0) / (SampleRate * 1000);
if (super_sampling_quality !== undefined)
phase_delta_slide /= super_sampling_quality; // correction
// arpeggiator reset
var arpeggiator_time = 0;
var arpeggiator_limit = params.ChangeSpeed * SampleRate;
Expand Down Expand Up @@ -267,14 +276,20 @@ var jsfx = {};
out[i] = sample;
}

/* super sampling
var tn = (totalSamples/4)|0;
var rout = new Array(tn);
for(var i = 0 ; i < tn; i++){
rout[i] = (out[i*4] + out[i*4 + 1] + out[i*4 + 2] + out[i*4 + 3]) / 4;
// super sampling
if(super_sampling_quality > 1){
var smooth_totalSamples = (totalSamples/super_sampling_quality)|0;
var smooth_out = new Array(smooth_totalSamples);
for(var i = 0 ; i < smooth_totalSamples; i++){
smooth_out[i] = 0;
var b = i * super_sampling_quality;
for(var z = 0; z < super_sampling_quality; z++)
smooth_out[i] += out[b + z];
smooth_out[i] /= super_sampling_quality;
}
out = smooth_out;
}
out = rout;
// */

return out;
}

Expand Down Expand Up @@ -368,6 +383,10 @@ var jsfx = {};
this.play();
}

this.randomSample = function(id){
// this should randomize based on some values
}

this.reset = function () {
var len = Parameters.length;
for (var i = 0; i < len; i += 1) {
Expand Down

0 comments on commit b1ff09d

Please sign in to comment.