Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Signal Processing with JavaScript JSConf Colombia

Signal Processing with JavaScript JSConf Colombia

Nowadays we have native options to deal with media signals on javascript! How can we use the available APIs to process it? This talk is about amazing uses to Web Audio API and the Video tag like sampling, quantization, filtering, etc. Can we synthesize guitar effects?

Rafael Specht da Silva

October 17, 2015
Tweet

More Decks by Rafael Specht da Silva

Other Decks in Programming

Transcript

  1. var numbers = [1, 2, 3, 4]; numbers.map(function (item) {

    return item + 3; }); // [4, 5, 6, 7]
  2. var playBuffer = function (buffer) { source = context.createBufferSource(); source.buffer

    = buffer; var processor = context.createScriptProcessor(512, 2, 2); processor.onaudioprocess = onAudioProcess; source.connect(processor); processor.connect(context.destination); source.start(0, startOffset % buffer.duration); }
  3. var onAudioProcess = function (ev) { inputBuffer = ev.inputBuffer; outputBuffer

    = ev.outputBuffer; inputData = inputBuffer.getChannelData(0); outputData0 = outputBuffer.getChannelData(0); outputData1 = outputBuffer.getChannelData(1); for (var sample = 0, len = inputData.length; sample < len; sample++) { outputData0[sample] = (1 - panelX) * inputData[sample]; outputData1[sample] = panelX * inputData[sample]; } }
  4. var canvas = document.getElementById('canvas'); var ctx = canvas.getContext('2d'); function make_base(src)

    { base_image = new Image(); base_image.src = src; base_image.onload = function(){ ctx.drawImage(base_image, 0, 0); imageLoaded(base_image); } }
  5. img.height // number img.width // number img.data // Uint8ClampedArray r

    g b a r g b a [65, 113, 130, 255, 65, 113, 130, 255, ...
  6. // Run Length Encoding (RLE) // Original (19) [1, 2,

    2, 2, 2, 3, 3, 3, 3] // Compressed (15) [1, ‘2 4’, ‘3 4’]
  7. var red = []; var green = []; var blue

    = []; var alpha = []; for (var i = 4; i < imgData.data.length; i+=4) { red.push(imgData.data[i]) green.push(imgData.data[i+1]) blue.push(imgData.data[i+2]) alpha.push(imgData.data[i+3]) }