@@ -225,7 +225,8 @@ function renderWavesImpl(settings, fft, p) { return (playback = false) => {
225225 // downsampling factor
226226 if ( playback ) {
227227 settings . downsampled_pb = new Float32Array ( p . round ( original . length / settings . downsamplingFactor ) ) ;
228- settings . quantNoise_pb = new Float32Array ( p . round ( original . length / settings . downsamplingFactor ) ) ;
228+ settings . quantNoise_pb = new Float32Array ( p . round ( original . length ) ) ;
229+
229230 } else {
230231 settings . downsampled = new Float32Array ( p . round ( original . length / settings . downsamplingFactor ) ) ;
231232 settings . quantNoise = new Float32Array ( p . round ( original . length / settings . downsamplingFactor ) ) ;
@@ -236,34 +237,51 @@ function renderWavesImpl(settings, fft, p) { return (playback = false) => {
236237 quantNoiseStuffed . fill ( 0 ) ;
237238
238239 // calculate the maximum integer value representable with the given bit depth
239- let maxInt = p . pow ( 2 , settings . bitDepth ) - 1 ;
240+ let maxInt = 1 ;
240241
241242 let stepSize = ( settings . quantType == "midTread" ) ? 2 / ( maxInt - 1 ) : 2 / ( maxInt ) ;
242243
244+ let currentAmp = 0 ;
245+ for ( let x = 0 ; x < downsampled . length ; x ++ ) {
246+ if ( original [ Math . floor ( x / downsampled . length * original . length ) ] > currentAmp ) {
247+ currentAmp += settings . deltaStep ;
248+ } else {
249+ currentAmp -= settings . deltaStep ;
250+ }
251+ currentAmp = ( currentAmp > 1.0 ) ? currentAmp = 1.0 : ( currentAmp < - 1.0 ) ? currentAmp = - 1.0 : currentAmp = currentAmp ;
252+ downsampled [ x ] = currentAmp ;
253+
254+ /* let xpos = Math.round(panel.plotLeft + x * panel.settings.downsamplingFactor*panel.settings.timeZoom);
255+ panel.buffer.curveVertex(xpos, ypos);
256+ if (pixel_max * signal[Math.floor((x/visibleSamples)*panel.plotWidth/panel.settings.timeZoom)]*panel.settings.ampZoom < panel.halfh - ypos) {
257+ ypos += panel.settings.deltaStep*panel.plotHeight;
258+ //if (ypos >= panel.plotBottom) ypos -= 2*panel.settings.deltaStep*panel.plotHeight; //Prevent signal from going below bounds
259+ } else {
260+ ypos -= panel.settings.deltaStep*panel.plotHeight;
261+ //if (ypos <= panel.plotTop) ypos += 2*panel.settings.deltaStep*panel.plotHeight; //Same for the top bound
262+ }
263+ ypos = (ypos<panel.plotTop)? ypos=panel.plotTop : (ypos>panel.plotBottom)? ypos= panel.plotBottom: ypos=ypos;
264+ panel.buffer.curveVertex(xpos, ypos); */
265+ }
266+ console . log ( settings . downsamplingFactor , quantNoise . length , reconstructed . length , original . length ) ;
267+ for ( let x = 0 ; x < reconstructed . length ; x ++ ) {
268+ reconstructed [ x ] = downsampled [ Math . floor ( x / reconstructed . length * downsampled . length ) ] ;
269+ let currentAmp = original [ x ] - reconstructed [ x ] ;
270+ currentAmp = ( currentAmp > 1.0 ) ? currentAmp = 1.0 : ( currentAmp < - 1.0 ) ? currentAmp = - 1.0 : currentAmp = currentAmp ;
271+ quantNoise [ Math . floor ( x / reconstructed . length * quantNoise . length ) ] = currentAmp ;
272+ quantNoiseStuffed [ Math . floor ( x / reconstructed . length * quantNoiseStuffed . length ) ] = currentAmp ;
273+ }
274+
243275 // generate the output of the simulated ADC process by "sampling" (actually
244276 // just downsampling), and quantizing with dither. During this process, we
245277 // also load the buffer for the reconstructed signal with the sampled values;
246278 // this allows us to skip an explicit zero-stuffing step later
247-
248- downsampled . forEach ( ( _ , n , arr ) => {
279+ /* downsampled.forEach( (_, n, arr) => {
249280
250281 // keep only every kth sample where k is the integer downsampling factor
251282 let y = original[n * settings.downsamplingFactor];
252283 y = y > 1.0 ? 1.0 : y < -1.0 ? -1.0 : y; // apply clipping
253284
254- // if the bit depth is set to the maximum, we skip quantization and dither
255- if ( settings . bitDepth == BIT_DEPTH_MAX ) {
256-
257- // record the sampled output of the ADC process
258- arr [ n ] = y ;
259-
260- // sparsely fill the reconstruction and zero stuffed buffers to avoid
261- // having to explicitly zero-stuff
262- reconstructed [ n * settings . downsamplingFactor ] = y ;
263- stuffed [ n * settings . downsamplingFactor ] = y * settings . downsamplingFactor ;
264- return ;
265- }
266-
267285 // generate dither noise
268286 let dither = (2 * Math.random() - 1) * settings.dither;
269287
@@ -289,12 +307,12 @@ function renderWavesImpl(settings, fft, p) { return (playback = false) => {
289307 // record the quantization error
290308 quantNoise[n] = quantized - y;
291309 quantNoiseStuffed[n * settings.downsamplingFactor] = quantNoise[n];
292- } ) ;
310+ }); */
293311
294312 // render reconstructed wave by low pass filtering the zero stuffed array----
295313
296314 // specify filter parameters; as before, the cutoff is set to the Nyquist
297- var filterCoeffs = firCalculator . lowpass (
315+ /* var filterCoeffs = firCalculator.lowpass(
298316 { order: 200
299317 , Fs: WEBAUDIO_MAX_SAMPLERATE
300318 , Fc: (WEBAUDIO_MAX_SAMPLERATE / settings.downsamplingFactor) / 2
@@ -314,7 +332,7 @@ function renderWavesImpl(settings, fft, p) { return (playback = false) => {
314332
315333 // time shift the signal by half the filter order to compensate for the delay
316334 // introduced by the FIR filter
317- reconstructed . forEach ( ( x , n , arr ) => arr [ n - 100 ] = x ) ;
335+ reconstructed.forEach( (x, n, arr) => arr[n - 100] = x ); */
318336
319337 // render FFTs --------------------------------------------------------------
320338 // TODO: apply windows?
0 commit comments