Skip to content

Commit 0602e83

Browse files
fix minor issues
1 parent 1d30935 commit 0602e83

6 files changed

Lines changed: 81 additions & 45 deletions

File tree

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ This software is licensed under the MIT License.
22

33
fft.js copyright Fedor Indutny, 2017.
44
fili.js copyright (c) 2014 Florian Markert
5-
All other files copyright (c) 2020 The Input Devices and Musical Interaction Laboratory (IDMIL), McGill University
5+
All other files copyright (c) 2020-2026 The Input Devices and Musical Interaction Laboratory (IDMIL), McGill University, and the Centre for Interdisciplinary Research in Music Media and Technology (CIRMMT).
66

77
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
88

all-panels/index.html

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,7 @@ <h2>Filter</h2>
6969
<div class="slider" id="antialiasing-filter-order-slider"></div>
7070
<div class="slider" id="filter-type-slider"></div>
7171
</div>
72-
<button class="play-button" id="play-filter-kernel">Play kernel</button>
73-
<button class="play-button" id="play-filtered-input">Play filtered input</button>
72+
<button class="play-button" id="play-filtered-input">Play</button>
7473
</div>
7574
</div>
7675
<div class="section" id="samplerate-section">
@@ -88,42 +87,29 @@ <h2>Sample Rate</h2>
8887
<div class="row sliders">
8988
<div class="slider" id="sample-rate-slider"></div>
9089
</div>
91-
<button class="play-button" id="play-sample-rate">Play</button>
9290
</div>
9391
</div>
94-
<div class="section" id="dither-section">
92+
<div class="section" id="quantization-section">
9593
<div class="titlebar">
9694
<div class="section-title">
97-
<h2>Dither</h2>
95+
<h2>Dither Quantization</h2>
9896
</div>
99-
<button class="collapse-button" id="coll-dither" onclick="collapseClick(this.id)"></button>
100-
97+
<button class="collapse-button" id="coll-quantization" onclick="collapseClick(this.id)"></button>
10198
</div>
10299
<div class="collapse">
103100
<div class="row panels">
104101
<div class="panel" id="dither-histogram"></div>
102+
<div class="panel" id="downsampled-quantized"></div>
105103
</div>
106-
<div class="row sliders">
107-
<div class="slider" id="dither-slider"></div>
108-
</div>
109-
</div>
110-
</div>
111-
<div class="section" id="quantization-section">
112-
<div class="titlebar">
113-
<div class="section-title">
114-
<h2>Quantization</h2>
115-
</div>
116-
<button class="collapse-button" id="coll-quantization" onclick="collapseClick(this.id)"></button>
117-
</div>
118-
<div class="collapse">
119104
<div class="row panels">
120105
<div class="panel" id="quantization-noise"></div>
121106
<div class="panel" id="quantization-noise-fft"></div>
122107
</div>
123108
<div class="row sliders">
109+
<div class="slider" id="dither-slider"></div>
124110
<div class="slider" id="quantization-slider"></div>
125111
</div>
126-
<button class="play-button" id="play-quantized-noise">Play</button>
112+
<button class="play-button" id="play-quantized-noise">Play quantization noise</button>
127113
</div>
128114
</div>
129115
<div class="section" id="reconstructed-section">

panel.js

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -143,8 +143,6 @@ class Panel {
143143

144144
const increment = Math.max(1, Math.floor(0.5/iToXScale));
145145

146-
console.log("inc", increment, "scale", iToXScale);
147-
148146
for (let i = 0; i < signal.length; i += increment) {
149147
let x = i * iToXScale;
150148
let pixel_amp = signal[i] * pixel_per_fullscale;
@@ -698,6 +696,7 @@ class QuantNoisePanel extends Panel{
698696
this.description = 'This plot shows the difference between the sampled signal before and after quantization, representing the error introduced by the quantization process. '
699697
+ time_ticks_doc + amp_ticks_doc + midline_doc;
700698
}
699+
701700
drawPanel(){
702701
this.drawDiscreteSignal(this.settings.buffers.quantNoise.display);
703702
this.drawMidLine();
@@ -707,6 +706,25 @@ class QuantNoisePanel extends Panel{
707706
}
708707
}
709708

709+
class QuantizedSignalPanel extends Panel{
710+
constructor(){
711+
super()
712+
this.strokeWeight=1;
713+
this.ellipseSize=5;
714+
this.name ="Quantized Signal";
715+
this.description = 'This plot shows the quantized signal in the time domain. '
716+
+ time_ticks_doc + amp_ticks_doc + midline_doc;
717+
}
718+
719+
drawPanel(){
720+
this.drawDiscreteSignal(this.settings.buffers.downsampledWithQuantization.display);
721+
this.drawMidLine();
722+
this.drawName();
723+
this.drawSignalAmplitudeTicks(this.plotHeight/2, 4);
724+
this.drawTimeTicks(this.numTimeTicks/this.settings.timeZoom, 1/(this.settings.timeZoom*this.settings.sampleRate));
725+
}
726+
}
727+
710728
class QuantNoiseFFTPanel extends FreqPanel {
711729
constructor(){
712730
super();
@@ -781,7 +799,6 @@ class AllSignalsPanel extends Panel {
781799
this.name = "Input (solid), Sampled (lollipop), Reconstructed (dotted), Time Domain";
782800
this.description = 'This plot combines the input signal, sampled signal, and reconstructed signal time domain plots. See the documentation for each individual plot for more information. ';
783801
this.ellipseSize = 5;
784-
785802
}
786803

787804
drawPanel() {
@@ -794,5 +811,5 @@ class AllSignalsPanel extends Panel {
794811
this.drawName();
795812
this.drawSignalAmplitudeTicks(this.plotHeight/2, 4);
796813
this.drawTimeTicks(this.numTimeTicks/this.settings.timeZoom, 1/(this.settings.timeZoom*this.settings.sampleRate));
797-
}
814+
}
798815
}

slider.js

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ class RangedSlider extends Slider {
5353
// this.button.size(200)
5454
this.button.mousePressed(this.buttonPressed.bind(this));
5555
this.button.mouseReleased(this.onEdit.bind(this));
56-
}
56+
}
5757

5858
resize(x, y, w, p){
5959
let width = w - (20 + this.labelWidth + this.sliderWidth);
@@ -93,14 +93,20 @@ class AudioInputTypeSlider extends Slider{
9393
this.inputSelect.option("cello");
9494
this.inputSelect.option("drums");
9595
this.inputSelect.option("sweep");
96-
this.inputSelect.changed(()=>this.settings.inputType = this.inputSelect.value());
96+
this.inputSelect.changed(()=>{
97+
this.settings.inputType = this.inputSelect.value();
98+
this.onEdit();
99+
});
97100

98101
this.oddEvenSel = p.createSelect();
99102
this.oddEvenSel.option("All");
100103
this.oddEvenSel.option("Odd");
101104
this.oddEvenSel.option("Even");
102105
this.oddEvenSel.selected(this.settings.harmType);
103-
this.oddEvenSel.changed(()=>this.settings.harmType = this.oddEvenSel.value());
106+
this.oddEvenSel.changed(()=>{
107+
this.settings.harmType = this.oddEvenSel.value();
108+
this.onEdit();
109+
});
104110

105111
this.slopeSel = p.createSelect();
106112
this.slopeSel.option("1/x");
@@ -115,7 +121,10 @@ class AudioInputTypeSlider extends Slider{
115121
this.slopeSel.option("vowel o");
116122
this.slopeSel.option("vowel u");
117123
this.slopeSel.selected(this.settings.harmSlope);
118-
this.slopeSel.changed(()=>this.settings.harmSlope = this.slopeSel.value());
124+
this.slopeSel.changed(()=>{
125+
this.settings.harmSlope = this.slopeSel.value();
126+
this.onEdit();
127+
});
119128
}
120129

121130
resize(x, y, w, p) {
@@ -140,7 +149,10 @@ class FilterTypeSlider extends Slider {
140149
this.inputSelect = p.createSelect();
141150
this.inputSelect.option("FIR");
142151
this.inputSelect.option("Butterworth");
143-
this.inputSelect.changed(() => this.settings.filterType = this.inputSelect.value());
152+
this.inputSelect.changed(() => {
153+
this.settings.filterType = this.inputSelect.value();
154+
this.onEdit();
155+
});
144156
}
145157

146158
resize(x, y, w, p) {
@@ -274,7 +286,10 @@ class DitherSlider extends RangedSlider {
274286
this.ditherTypeSel.option("Gaussian");
275287

276288
this.ditherTypeSel.selected(this.settings.ditherType);
277-
this.ditherTypeSel.changed(()=>this.settings.ditherType = this.ditherTypeSel.value());
289+
this.ditherTypeSel.changed(()=>{
290+
this.settings.ditherType = this.ditherTypeSel.value();
291+
this.onEdit();
292+
});
278293

279294
this.makeSlider(p);
280295
}
@@ -315,6 +330,16 @@ class BitDepthSlider extends RangedSlider {
315330
this.makeSlider(p);
316331
}
317332

333+
calcSliderVal(){
334+
// override this with any calculations needed to convert textbox val to slider val (%, etc)
335+
return this.textBox.value() === "unquantized" ? 16 : this.textBox.value();
336+
}
337+
calcDisplayVal(){
338+
// override this with any calculations needed to convert stored variable to display val (%, etc)
339+
return this.settings[this.propName] >= 16 ? "unquantized" : this.settings[this.propName];
340+
}
341+
342+
318343
}
319344

320345
class AmplitudeSlider extends RangedSlider {

waves.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -529,17 +529,23 @@ function downsampleWithQuantization(settings, fft, playback) {
529529
// downsampling factor
530530
let original = playback ? settings.buffers.original.playback : settings.buffers.original.display;
531531

532-
if (playback) {
532+
if (playback && settings.buffers.downsampled.playback.length !== Math.round(original.length / settings.downsamplingFactor)) {
533+
533534
settings.buffers.downsampled.playback = new Float32Array(Math.round(original.length / settings.downsamplingFactor));
535+
settings.buffers.downsampledWithQuantization.playback = new Float32Array(Math.round(original.length / settings.downsamplingFactor));
534536
settings.buffers.quantNoise.playback = new Float32Array(Math.round(original.length / settings.downsamplingFactor));
535-
} else {
537+
538+
} else if (settings.buffers.downsampled.display.length !==Math.round(original.length / settings.downsamplingFactor)) {
539+
536540
settings.buffers.downsampled.display = new Float32Array(Math.round(original.length / settings.downsamplingFactor));
541+
settings.buffers.downsampledWithQuantization.display = new Float32Array(Math.round(original.length / settings.downsamplingFactor));
537542
settings.buffers.quantNoise.display = new Float32Array(Math.round(original.length / settings.downsamplingFactor));
538543
}
539544

540545
let reconstructed = playback ? settings.buffers.reconstructed.playback : settings.buffers.reconstructed.display;
541546
let stuffed = playback ? settings.buffers.stuffed.playback : settings.buffers.stuffed.display;
542547
let downsampled = playback ? settings.buffers.downsampled.playback : settings.buffers.downsampled.display;
548+
let downsampledWithQuantization = playback ? settings.buffers.downsampledWithQuantization.playback : settings.buffers.downsampledWithQuantization.display;
543549
let quantNoise = playback ? settings.buffers.quantNoise.playback : settings.buffers.quantNoise.display;
544550
let quantNoiseStuffed = playback ? settings.buffers.quantNoiseStuffed.playback : settings.buffers.quantNoise.display;
545551

@@ -587,6 +593,7 @@ function downsampleWithQuantization(settings, fft, playback) {
587593
// sparsely fill the reconstruction buffer to avoid having to zero-stuff
588594
reconstructed[n * settings.downsamplingFactor] = quantized;
589595
arr[n] = y;
596+
downsampledWithQuantization[n] = quantized;
590597
stuffed[n * settings.downsamplingFactor] = quantized * settings.downsamplingFactor;
591598

592599
// record the quantization error

widget.js

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,10 @@ function getDefaultSettings() {
3131
original: createBuffers(),
3232
filterKernel: createBuffers(),
3333
stuffed: createBuffers(),
34+
downsampled: createBuffers(),
3435
quantNoise: createBuffers(),
3536
quantNoiseStuffed: createBuffers(),
36-
downsampled: createBuffers(),
37+
downsampledWithQuantization : createBuffers(),
3738
reconstructed: createBuffers(),
3839
reconstructedFiltered: createBuffers(),
3940
deltaSigma: createBuffers()
@@ -92,6 +93,7 @@ let panelIdLookups = {
9293
'dither-histogram' : DitherDistributionHistogramPanel,
9394
'quantization-noise' : QuantNoisePanel,
9495
'quantization-noise-fft' : QuantNoiseFFTPanel,
96+
'downsampled-quantized' : QuantizedSignalPanel,
9597
'reconstructed' : ReconstructedSigPanel,
9698
'reconstructed-fft' : ReconstructedSigFFTPanel,
9799
'filter-kernel' : FilterKernelPanel,
@@ -199,27 +201,26 @@ function createWidgets() {
199201

200202
const playButtons = document.getElementsByClassName('play-button');
201203

202-
function buttonPlayFunction(buffer) {
204+
function buttonPlayFunction(buffer, samplerate=WEBAUDIO_MAX_SAMPLERATE) {
203205
settings.render(true);
204206
if (!settings.snd) settings.snd = new (window.AudioContext || window.webkitAudioContext)();
205-
playWave(buffer, WEBAUDIO_MAX_SAMPLERATE, settings.snd);
207+
console.log(samplerate);
208+
playWave(buffer, samplerate, settings.snd);
206209
}
207210

208211
for (const playButton of playButtons) {
209212
const id = playButton.getAttribute('id');
210213
if (id === "play-input") {
211-
playButton.onclick = () => { buttonPlayFunction(settings.buffers.originalUnfiltered.playback)};
212-
} else if (id === "play-filter-kernel") {
213-
playButton.onclick = () => { buttonPlayFunction(settings.buffers.filterKernel.playback)};
214+
playButton.onclick = () => { buttonPlayFunction(settings.buffers.originalUnfiltered.playback);};
214215
} else if (id === "play-filtered-input") {
215-
playButton.onclick = () => { buttonPlayFunction(settings.buffers.original.playback)};
216+
playButton.onclick = () => { buttonPlayFunction(settings.buffers.original.playback);};
216217
} else if (id === "play-quantized-noise") {
217-
playButton.onclick = () => { buttonPlayFunction(settings.buffers.quantNoise.playback); };
218+
playButton.onclick = () => { buttonPlayFunction(settings.buffers.quantNoiseStuffed.playback);};
218219
} else if (id === "play-reconstructed") {
219-
playButton.onclick = () => { buttonPlayFunction(settings.buffers.reconstructed.playback); };
220+
playButton.onclick = () => { buttonPlayFunction(settings.buffers.reconstructed.playback);};
220221
} else if (id === "play-delta-sigma") {
221-
playButton.onclick = () => {buttonPlayFunction(settings.buffers.deltaSigma.playback)};
222-
}
222+
playButton.onclick = () => {buttonPlayFunction(settings.buffers.deltaSigma.playback);};
223+
}
223224
}
224225

225226

0 commit comments

Comments
 (0)