Hacker News new | ask | show | jobs
by TheActualWalko 1986 days ago
Hey cool! Here's essentially the same encoder in a few lines of JS, you can run this on https://wavtool.com by pressing cmd+;

  (() => {
    const message = 'asdf';
    const messageBinary = message.split('').map(c => c.charCodeAt(0).toString(2)).join('').split('').map(Number);
    const bitDurationSeconds = 0.1;
    const shiftSize = 0.1;
    return wavtool.mapSamplesCommand((sample, index, channelData, settings, context) => {
      const bitIndex = Math.floor(index / (bitDurationSeconds * context.sampleRate));
      const shift = bitIndex < messageBinary.length 
        ? (2 * (messageBinary[bitIndex] - 0.5)) // [0,1] => [-1,1]
        : 0;
      return sample + shift * shiftSize;
    }); 
  })()
1 comments

You legend. Thanks.