Convolution Reverb / コンボリューションリバーブ

p5.Convolver は、畳み込みを使用して実際の空間の音を再現できます。畳み込みは、インパルス応答(部屋の残響音)を取り、それを使用してその空間の音を再現します。クリックして、畳み込みを通してサウンドを再生します。クリックするたびに、サウンドは異なるインパルス応答で畳み込まれます。

convolution impulse response reverb
Sound Effects

View Source Code

/**
 * @name Convolution Reverb
 * @arialabel Sound with reverb plays when the user clicks the screen and lime green bars appear based on the amplitude of the sound
 * @description <p>The p5.Convolver can recreate the sound of actual
 * spaces using convolution. Convolution takes an Impulse Response,
 * (the sound of a room reverberating), and uses that to
 * recreate the sound of that space.</p><p>Click to play a sound through
 * convolution. Every time you click, the sound is convolved with
 * a different Impulse Response. To hear the Impulse Response itself,
 * press any key.</p>
 *
 * <p><em><span class="small">To run this example locally, you will need the
 * <a href="http://p5js.org/reference/#/libraries/p5.sound">p5.sound library</a>
 * a sound file, and a running <a href="https://github.com/processing/p5.js/wiki/Local-server">local server</a>.
 * These convolution samples are Creative Commons BY
 * <a href="https://www.freesound.org/people/recordinghopkins/">
 * recordinghopkins</a></em></span></p>
 */
let sound, env, cVerb, fft;
let currentIR = 0;
let rawImpulse;

function preload() {
  // we have included both MP3 and OGG versions of all the impulses/sounds
  soundFormats('ogg', 'mp3');

  // create a p5.Convolver
  // cVerb = createConvolver('assets/bx-spring');
  cVerb = createConvolver('../../../../p5js-website-legacy-examples/assets/bx-spring');

  // add Impulse Responses to cVerb.impulses array, in addition to bx-spring
  // cVerb.addImpulse('assets/small-plate');
  cVerb.addImpulse('../../../../p5js-website-legacy-examples/assets/small-plate');
  // cVerb.addImpulse('assets/drum');
  cVerb.addImpulse('../../../../p5js-website-legacy-examples/assets/drum');
  // cVerb.addImpulse('assets/beatbox');
  cVerb.addImpulse('../../../../p5js-website-legacy-examples/assets/beatbox');
  // cVerb.addImpulse('assets/concrete-tunnel');
  cVerb.addImpulse('../../../../p5js-website-legacy-examples/assets/concrete-tunnel');

  // load a sound that will be processed by the p5.ConvultionReverb
  // sound = loadSound('assets/Damscray_DancingTiger');
  sound = loadSound('../../../../p5js-website-legacy-examples/assets/Damscray_DancingTiger');
}

function setup() {
  // createCanvas(710, 400);
  createCanvas(windowWidth, windowHeight);
  // rawImpulse = loadSound('assets/' + cVerb.impulses[currentIR].name);
  rawImpulse = loadSound('../../../../p5js-website-legacy-examples/assets/' + cVerb.impulses[currentIR].name);

  // disconnect from master output...
  sound.disconnect();
  // ... and process with cVerb
  // so that we only hear the reverb
  cVerb.process(sound);

  fft = new p5.FFT();
}

function draw() {
  background(30);
  fill(0, 255, 40);

  let spectrum = fft.analyze();

  // Draw every value in the frequencySpectrum array as a rectangle
  noStroke();
  for (let i = 0; i < spectrum.length; i++) {
    let x = map(i, 0, spectrum.length, 0, width);
    let h = -height + map(spectrum[i], 0, 255, height, 0);
    rect(x, height, width / spectrum.length, h);
  }
}

function mousePressed() {
  // cycle through the array of cVerb.impulses
  currentIR++;
  if (currentIR >= cVerb.impulses.length) {
    currentIR = 0;
  }
  cVerb.toggleImpulse(currentIR);

  // play the sound through the impulse
  sound.play();

  // display the current Impulse Response name (the filepath)
  println('Convolution Impulse Response: ' + cVerb.impulses[currentIR].name);

  // rawImpulse.setPath('assets/' + cVerb.impulses[currentIR].name);
  rawImpulse.setPath('../../../../p5js-website-legacy-examples/assets/' + cVerb.impulses[currentIR].name);
}

// play the impulse (without convolution)
function keyPressed() {
  rawImpulse.play();
}

License

Source code is available on GitHub p5.js website legacy.

All examples are licensed under CC BY-NC-SA 4.0.