import { XAudioBuffer } from '../XAudioBuffer' ; /**
 * Compare two XAudioBuffers, quantum by quantum.
 *
 * When I attempted to use a simple jest matcher for each channel, or even the
 * audio data, the entire node process hung and never completed. For example:
 *  expect(received.getChannelData(0)).toEqual(expected.getChannelData(0));
 * This bypasses that problem, and also adds context for which quantums
 * differed to help aid debugging the problem.
 */ export function expectQuantums ( received , expected , quantumSize ) { const requiredQuantums = expected . length / quantumSize ; for ( let i = 0 ; i < requiredQuantums ; i ++ ) { for ( let j = 0 ; j < expected . numberOfChannels ; j ++ ) { const msg = `channel: ${ j }, sampleIndex: ${ i * quantumSize }, quantumIndex: ${ i }` ; const start = i * quantumSize ; const end = ( i + 1 ) * quantumSize ; const receivedQuantum = received . getChannelData ( 0 ) . subarray ( start , end ) ; const expectedQuantum = expected . getChannelData ( 0 ) . subarray ( start , end ) ; expect ( { msg , data : receivedQuantum } ) . toEqual ( { msg , data : expectedQuantum } ) ; } } }