extendable-media-recorder-wav-encoder-worker
Version:
The worker which is used by the extendable-media-recorder-wav-encoder package.
32 lines (31 loc) • 1.26 kB
JavaScript
export const shiftChannelDataArrays = (channelDataArrays, numberOfSamples) => {
const shiftedChannelDataArrays = [];
let numberOfShiftedSamples = 0;
shiftChannelDataArrays: while (numberOfShiftedSamples < numberOfSamples) {
const length = channelDataArrays.length;
for (let i = 0; i < length; i += 1) {
const channelDataArray = channelDataArrays[i];
if (shiftedChannelDataArrays[i] === void 0) {
shiftedChannelDataArrays[i] = [];
}
const channelData = channelDataArray.shift();
if (channelData === void 0) {
break shiftChannelDataArrays;
}
shiftedChannelDataArrays[i].push(channelData);
if (i === 0) {
numberOfShiftedSamples += channelData.length;
}
}
}
if (numberOfShiftedSamples > numberOfSamples) {
const unnecessarySamples = numberOfShiftedSamples - numberOfSamples;
shiftedChannelDataArrays.forEach((shiftedChannelDataArray, index) => {
const channelData = shiftedChannelDataArray.pop();
const offset = channelData.length - unnecessarySamples;
shiftedChannelDataArray.push(channelData.subarray(0, offset));
channelDataArrays[index].unshift(channelData.subarray(offset));
});
}
return shiftedChannelDataArrays;
};