lib/consume-wav.js
/**
 * Sums 2 arrays of equal length N into 1 array.
 * Not sure if this is the fastest way to do it, so don't rely on for intense performance just yet.
 * @param stereo - array of size 2, each entity of which contain an array of samples with equal length N
 * @returns {Array} - mono array of size equal to the stereo input's sample length N if input is good, otherwise []
 */
Sums 2 arrays of equal length N into 1 array.
Not sure if this is the fastest way to do it, so don't rely on for intense performance just yet.
@param stereo - array of size 2, each entity of which contain an array of samples with equal length N
@returns {Array} - mono array of size equal to the stereo input's sample length N if input is good, otherwise []
Sums 2 arrays of equal length N into 1 array . Not sure if this is the fastest way to do it so don ' t rely on for intense performance just yet . @param stereo - array of size 2 each entity of which contain an array of samples with equal length N @returns { Array } - mono array of size equal to the stereo input ' s sample length N if input is good otherwise []
function mixStereoToMono (stereo) {
    const inputDoesNotHaveTwoChannels = stereo.length !== 2 && stereo[0].length && stereo[1].length;
    if (inputDoesNotHaveTwoChannels) {
        return [];
    }
    const inputDoesNotHaveEqualSampleLength = stereo[0].length !== stereo[1].length;
    if (inputDoesNotHaveEqualSampleLength) {
        return [];
    }
    const scaleDownFactor = 1; 
    return stereo[0].map((val, i) => {
        const sum = (val + stereo[1][i]) * scaleDownFactor;
        if (sum > 1) {
            console.log('CLIPPING WARNING', sum);
        }
        return sum > 1 ? 1 : sum;
    })
}
function mixStereoToMono ( stereo ) { const inputDoesNotHaveTwoChannels = stereo . length !== 2 && stereo [ 0 ] . length && stereo [ 1 ] . length ; if ( inputDoesNotHaveTwoChannels ) { return [ ] ; } const inputDoesNotHaveEqualSampleLength = stereo [ 0 ] . length !== stereo [ 1 ] . length ; if ( inputDoesNotHaveEqualSampleLength ) { return [ ] ; } const scaleDownFactor = 1 ; return stereo [ 0 ] . map ( ( val , i ) => { const sum = ( val + stereo [ 1 ] [ i ] ) * scaleDownFactor ; if ( sum > 1 ) { console . log ( 'CLIPPING WARNING' , sum ) ; } return sum > 1 ? 1 : sum ; } ) }
Sums 2 arrays of equal length N into 1 array.
Sums 2 arrays of equal length N into 1 array .
// Validation upfront // Mixdown //0.5; // TODO continue research on whether or not this is important