A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from http://developer.mozilla.org/ja/docs/Web/API/AudioWorkletNode/parameters below:

AudioWorkletNode: parameters プãƒãƒ‘ティ - Web API

独自の AudioParam の作成と使用のデモを行うため、AudioWorkletNode ページにある例を拡張します。このページでは、ホワイトノイズを出力する単純なノードを作成しました。ここでは、独自のゲインパラメーターを追加し、出力の音量を直接変えることができるようにします。(これは GainNode を用いてもできますが)

まず、独自の AudioWorkletProcessor を定義して登録する必要があります。 これは別のファイルで行うことに注意してください。

処理器を拡張し、静的な parameterDescriptors ゲッターを追加します。これは AudioWorkletNode のコンストラクター内部で parameters に生成した AudioParam オブジェクトを入れるのに用いられます。

// white-noise-processor.js
class WhiteNoiseProcessor extends AudioWorkletProcessor {
  static get parameterDescriptors() {
    return [
      {
        name: "customGain",
        defaultValue: 1,
        minValue: 0,
        maxValue: 1,
        automationRate: "a-rate",
      },
    ];
  }

  process(inputs, outputs, parameters) {
    const output = outputs[0];
    output.forEach((channel) => {
      for (let i = 0; i < channel.length; i++) {
        channel[i] =
          (Math.random() * 2 - 1) *
          (parameters["customGain"].length > 1
            ? parameters["customGain"][i]
            : parameters["customGain"][0]);
        // メモ: パラメーターは 128 個の値の配列です。(128 サンプルのそれぞれについて 1 個ずつ)
        // ただし、現在自動処理がスケジュールされていない場合、
        // 128 サンプル全てで用いる値が 1 個だけ入っていることがあります。
      }
    });
    return true;
  }
}

registerProcessor("white-noise-processor", WhiteNoiseProcessor);

次に、メインスクリプトで処理器を読み込み、処理器の名前を渡して AudioWorkletNode のインスタンスを作成し、このノードを音声グラフに接続します。

const audioContext = new AudioContext();
await audioContext.audioWorklet.addModule("white-noise-processor.js");
const whiteNoiseNode = new AudioWorkletNode(
  audioContext,
  "white-noise-processor",
);
whiteNoiseNode.connect(audioContext.destination);

すると、ノードのゲインをこのようにして変えることができます。

const gainParam = whiteNoiseNode.parameters.get("customGain");
gainParam.setValueAtTime(0, audioContext.currentTime);
gainParam.linearRampToValueAtTime(0.5, audioContext.currentTime + 0.5);

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4