@@ -329,13 +329,12 @@ function LFOsReducer (state, action) {
329329}
330330
331331// Update the computed waveform based on the current algorithm.
332- function computeWaveform ( channelDataA , channelDataB , algorithm ) {
332+ function computeWaveform ( channelDataA , channelDataB , algorithm , cycles ) {
333333 if ( ! channelDataA || ! channelDataB || ! algorithm ) {
334334 return [ ]
335335 }
336336
337- let cycles = 256 // 1 can be min. 1024 might be a good max.
338- let samplesCount = ( 600 * cycles ) // - (overlap * cycles)
337+ let samplesCount = ( 600 * cycles )
339338 let interpolatedData = new Float32Array ( samplesCount * 2 )
340339 let time = 0
341340
@@ -350,20 +349,24 @@ function computeWaveform (channelDataA, channelDataB, algorithm) {
350349 time = ( k - samplesCount ) / ( samplesCount ) // Time starts at half way point.
351350 interpolatedData [ k ] = slerp ( channelDataB [ k % 600 ] , channelDataA [ k % 600 ] , time , algorithm )
352351 }
352+
353353 return interpolatedData
354354}
355355
356356// Modified lerp function based on algorithm chosen.
357357// The 'minus' algorithm uses the normal lerp function.
358358function slerp ( v0 , v1 , t , algorithm ) {
359359 if ( algorithm === 'p' ) {
360- return limit ( - 1 , 1 , v0 * ( 1 + t ) + v1 * t ) || 0.00001
361- } else if ( algorithm === 'm' ) {
362360 return limit ( - 1 , 1 , v0 * ( 1 - t ) + v1 * t ) || 0.00001 // Normal lerp function.
361+ } else if ( algorithm === 'm' ) {
362+ t = Math . pow ( t , 5 )
363+ return limit ( - 1 , 1 , v0 * ( 1 - t ) + v1 * t ) || 0.00001
363364 } else if ( algorithm === 'd' ) {
364- return limit ( - 1 , 1 , v0 * ( 1 / t ) + v1 * t ) || 0.00001
365+ t = Math . pow ( t , 20 )
366+ return limit ( - 1 , 1 , v0 * ( 1 - t ) + v1 * t ) || 0.00001
365367 } else if ( algorithm === 'x' ) {
366- return limit ( - 1 , 1 , v0 * ( 1 * t ) + v1 * t ) || 0.00001
368+ t = Math . log ( t + 1 )
369+ return limit ( - 1 , 1 , v0 * ( 1 + t ) + v1 * t ) || 0.00001
367370 }
368371}
369372
@@ -407,9 +410,12 @@ function OscillatorsReducer (state, action) {
407410 } else if ( action . side === 'B' ) {
408411 osc . channelDataB = action . channelData
409412 }
410- // When both files have loaded, compute the combined waveform.
411- if ( osc . channelDataA . length && osc . channelDataB . length ) {
412- osc . computedChannelData = computeWaveform ( osc . channelDataA , osc . channelDataB , osc . algorithm )
413+ // If both are noise, just return noise.
414+ if ( osc . fileA === 'noise' && osc . fileB === 'noise' ) {
415+ osc . computedChannelData = osc . channelDataA
416+ } else if ( osc . channelDataA . length && osc . channelDataB . length ) {
417+ // When both files have loaded, compute the combined waveform.
418+ osc . computedChannelData = computeWaveform ( osc . channelDataA , osc . channelDataB , osc . algorithm , osc . cycles )
413419 }
414420 }
415421 return osc
@@ -422,8 +428,12 @@ function OscillatorsReducer (state, action) {
422428 if ( osc . id === action . id ) {
423429 osc . algorithm = action . algorithm
424430 updateURL ( osc . id + 'al' , action . algorithm )
431+ if ( osc . fileA === 'noise' && osc . fileB === 'noise' ) {
432+ osc . computedChannelData = osc . channelDataA
433+ } else {
434+ osc . computedChannelData = computeWaveform ( osc . channelDataA , osc . channelDataB , osc . algorithm , osc . cycles )
435+ }
425436 }
426- osc . computedChannelData = computeWaveform ( osc . channelDataA , osc . channelDataB , osc . algorithm )
427437 return osc
428438 } )
429439 return [ ...state ]
@@ -439,11 +449,17 @@ function OscillatorsReducer (state, action) {
439449 // Updates local osc values, detune, octave, and amt.
440450 case 'OSC_CYCLES_CHANGED' :
441451 state = state . map ( function ( osc ) {
442- if ( osc . id === action . id ) {
452+ if ( osc . id === action . id && osc . cycles !== action . value ) {
443453 osc . cycles = action . value
444454 const paramName = osc . id + 'c' // id + first letter of param.
445455 updateURL ( paramName , action . value )
456+ if ( osc . fileA === 'noise' && osc . fileB === 'noise' ) {
457+ osc . computedChannelData = osc . channelDataA
458+ } else {
459+ osc . computedChannelData = computeWaveform ( osc . channelDataA , osc . channelDataB , osc . algorithm , osc . cycles )
460+ }
446461 }
462+
447463 return osc
448464 } )
449465 return [ ...state ]
0 commit comments