import { WaveformHD } from 'src/types' ; /**
 * Extracts a specific bitmask, shifting it to the bitmask.
 */ export const extractBitMask = ( val , mask ) : number => ( val & mask ) >> Math . log2 ( mask & - mask ) ; /**
 * Pioneer colors are 3 bits, convert this to a percentage.
 */ export const extractColor = ( val , mask ) : number => extractBitMask ( val , mask ) / 0b111 ; /**
 * Utility to generate an filled with byte offsets for each segment
 */ export const makeOffsetArray = ( byteLength , segmentSize ) => new Array ( byteLength / segmentSize ) . fill ( null ) . map ( ( _ , i ) => i * segmentSize ) ; /**
 * Convert raw waveform HD data into the structured WaveformHD type
 */ export const convertWaveformHDData = ( data ) : WaveformHD => { const redMask = 57344 ; const greenMask = 7168 ; const blueMask = 896 ; const heightMask = 124 ; const ec = extractColor ; return makeOffsetArray ( data . length , 0x02 ) . map ( byteOffset => data . readUInt16BE ( byteOffset ) ) . map ( v => ( { height : extractBitMask ( v , heightMask ) , color : [ ec ( v , redMask ) , ec ( v , greenMask ) , ec ( v , blueMask ) ] , } ) ) ; } ;