AudioBufferSourceNode.detune

detuneAudioBufferSourceNode インターフェイスのプロパティで、k-rateAudioParam 再生時の離調をセント単位で表します。

例えば、 +100 と -100 の値は半音ずつ上下に離調し、 +1200 と -1200 の値は 1 オクターブずつ上下に離調します。

A k-rate AudioParam whose value indicates the detuning of oscillation in cents.

メモ: AudioParam は読み取り専用の値を返しますが、値は読み取り専用ではありません。

js
const audioCtx = new AudioContext();

const channelCount = 2;
const frameCount = audioCtx.sampleRate * 2.0; // 2 seconds

const myArrayBuffer = audioCtx.createBuffer(
  channelCount,
  frameCount,
  audioCtx.sampleRate,
);

for (let channel = 0; channel < channelCount; channel++) {
  const nowBuffering = myArrayBuffer.getChannelData(channel);
  for (let i = 0; i < frameCount; i++) {
    nowBuffering[i] = Math.random() * 2 - 1;
  }
}

const source = audioCtx.createBufferSource();
source.buffer = myArrayBuffer;
source.connect(audioCtx.destination);
source.detune.value = 100; // value in cents
source.start();

仕様書

Specification
Web Audio API
# dom-audiobuffersourcenode-detune

ブラウザーの互換性

BCD tables only load in the browser

関連情報