Skip to content

Commit 252811c

Browse files
noise floor
1 parent 13f4cd1 commit 252811c

5 files changed

Lines changed: 36 additions & 1 deletion

File tree

all-panels/index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ <h2>Input</h2>
4444
<div class="slider" id="frequency-slider"></div>
4545
<div class="slider" id="num-harmonics-slider"></div>
4646
<div class="slider" id="amplitude-slider"></div>
47+
<div class="slider" id="noise-floor-slider"></div>
4748
</div>
4849
<button class="play-button" id="play-input">Play</button>
4950
</div>

delta-sigma-panels/index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ <h2>Input</h2>
4242
<div class="slider" id="frequency-slider"></div>
4343
<div class="slider" id="num-harmonics-slider"></div>
4444
<div class="slider" id="amplitude-slider"></div>
45+
<div class="slider" id="noise-floor-slider"></div>
4546
</div>
4647
<button class="play-button" id="play-input">Play</button>
4748
</div>

slider.js

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ class AudioInputTypeSlider extends Slider{
121121
resize(x, y, w, p) {
122122
this.inputSelect.width = w / 3;
123123
this.oddEvenSel.width = w / 3;
124-
this.inputSelect.position(x, y);
124+
this.inputSelect. position(x, y);
125125
this.oddEvenSel.position(x + this.inputSelect.width,y);
126126
this.slopeSel.position(x + this.inputSelect.width + this.oddEvenSel.width,y);
127127
}
@@ -164,6 +164,31 @@ class FreqSlider extends RangedSlider{
164164
}
165165
}
166166

167+
class NoiseFloorSlider extends RangedSlider {
168+
setup(p,settings){
169+
this.settings = settings;
170+
this.name ="Noise floor (dB)";
171+
this.propName = "noiseFloor";
172+
this.min = -96;
173+
this.max = 0 ;
174+
this.initial = -96;
175+
this.step = 1.0;
176+
this.displayVal = this.initial;
177+
this.makeSlider(p);
178+
}
179+
180+
calcSliderVal(){
181+
// override this with any calculations needed to convert textbox val to slider val (%, etc)
182+
return this.textBox.value() === "-infinity" ? -96 : this.textBox.value();
183+
}
184+
calcDisplayVal(){
185+
// override this with any calculations needed to convert stored variable to display val (%, etc)
186+
return this.settings[this.propName] <= -96 ? "-infinity" : this.settings[this.propName];
187+
}
188+
189+
190+
}
191+
167192
class DeltaSigmaStepSlider extends RangedSlider {
168193
setup(p, settings) {
169194
this.settings = settings;

waves.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,12 @@ function getSamples(settings, destination) {
227227
}
228228
}
229229
}
230+
if (settings.noiseFloor > -96) {
231+
const noiseGain = Math.pow(10, settings.noiseFloor / 20);
232+
destination.forEach((x, n, arr) => {
233+
arr[n] = x + (Math.random() * 2 - 1) * noiseGain;
234+
});
235+
}
230236
}
231237

232238
function normalize(arr, targetAmplitude) {

widget.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ function getDefaultSettings() {
4343
, fundFreq: 1250 // input signal fundamental freq
4444
, sampleRate: WEBAUDIO_MAX_SAMPLERATE
4545
, downsamplingFactor: 2
46+
, noiseFloor: -96
4647
, numHarm: 2 //Number of harmonics
4748
, harmType: "All" // Harmonic series to evaluate - Odd, even or all
4849
, harmSlope: "1/x" // Amplitude scaling for harmonics. can be used to create different shapes like saw or square
@@ -102,6 +103,7 @@ let sliderIdLookups = {
102103
'audio-input-type-slider' : AudioInputTypeSlider,
103104
'amplitude-slider' : AmplitudeSlider,
104105
'frequency-slider' : FreqSlider,
106+
'noise-floor-slider' : NoiseFloorSlider,
105107
'num-harmonics-slider' : NumHarmSlider,
106108
'antialiasing-filter-order-slider': AntialiasingSlider,
107109
'filter-type-slider' : FilterTypeSlider,

0 commit comments

Comments
 (0)