From 33058f2b292b3a581333bdfb21b8f671898c5060 Mon Sep 17 00:00:00 2001 From: Peter Bengtsson Date: Tue, 8 Dec 2020 14:40:17 -0500 Subject: initial commit --- .../web/api/audiobuffer/getchanneldata/index.html | 146 +++++++++++++++++++++ 1 file changed, 146 insertions(+) create mode 100644 files/ja/web/api/audiobuffer/getchanneldata/index.html (limited to 'files/ja/web/api/audiobuffer/getchanneldata') diff --git a/files/ja/web/api/audiobuffer/getchanneldata/index.html b/files/ja/web/api/audiobuffer/getchanneldata/index.html new file mode 100644 index 0000000000..4e81aaa476 --- /dev/null +++ b/files/ja/web/api/audiobuffer/getchanneldata/index.html @@ -0,0 +1,146 @@ +--- +title: AudioBuffer.getChannelData() +slug: Web/API/AudioBuffer/getChannelData +translation_of: Web/API/AudioBuffer/getChannelData +--- +

{{ APIRef("Web Audio API") }}

+ +
+

{{ domxref("AudioBuffer") }}インターフェースのgetChannelData()メソッドは、引数channel(0が最初のチャンネル)に結び付けられたPCMデータを{{domxref("Float32Array")}}で返します。

+
+ +

構文

+ +
var myArrayBuffer = audioCtx.createBuffer(2, frameCount, audioCtx.sampleRate);
+var nowBuffering = myArrayBuffer.getChannelData(channel);
+ +

戻り値

+ +

{{domxref("Float32Array")}}

+ +

+ +

次の例は、2秒間のバッファを生成し、ホワイトノイズを書き込み、{{ domxref("AudioBufferSourceNode") }}で再生します。コメントは何をしているかを簡単に説明しています。コードをすぐに実行することや、ソースコードを閲覧することもできます。

+ +
var audioCtx = new (window.AudioContext || window.webkitAudioContext)();
+var button = document.querySelector('button');
+var pre = document.querySelector('pre');
+var myScript = document.querySelector('script');
+
+pre.innerHTML = myScript.innerHTML;
+
+// ステレオ
+var channels = 2;
+// AudioContextのサンプルレートで2秒間の空のステレオバッファを生成する
+var frameCount = audioCtx.sampleRate * 2.0;
+
+var myArrayBuffer = audioCtx.createBuffer(2, frameCount, audioCtx.sampleRate);
+
+button.onclick = function() {
+  // バッファにホワイトノイズを書き込む;
+  // 単なる-1.0から1.0の間の乱数の値である
+  for (var channel = 0; channel < channels; channel++) {
+   // 実際のデータの配列を得る
+   var nowBuffering = myArrayBuffer.getChannelData(channel);
+   for (var i = 0; i < frameCount; i++) {
+     // Math.random()は[0; 1.0]である
+     // 音声は[-1.0; 1.0]である必要がある
+     nowBuffering[i] = Math.random() * 2 - 1;
+   }
+  }
+
+  // AudioBufferSourceNodeを得る
+  // これはAudioBufferを再生するときに使うAudioNodeである
+  var source = audioCtx.createBufferSource();
+  // AudioBufferSourceNodeにバッファを設定する
+  source.buffer = myArrayBuffer;
+  // AudioBufferSourceNodeを出力先に接続すると音声が聞こえるようになる
+  source.connect(audioCtx.destination);
+  // 音源の再生を始める
+  source.start();
+}
+ +

引数

+ +
+
channel
+
channelプロパティはデータを得るチャンネルの番号である。0が最初のチャンネルを表す。channelが{{domxref("AudioBuffer.numberOfChannels")}}以上ならば、INDEX_SIZE_ERR例外が発生する。
+
+ +

使用

+ + + + + + + + + + + + + + +
SpecificationStatusComment
{{SpecName('Web Audio API', '#widl-AudioBuffer-getChannelData-Float32Array-unsigned-long-channel', 'getChannelData')}}{{Spec2('Web Audio API')}} 
+ +

ブラウザ互換性

+ +
{{CompatibilityTable}}
+ +
+ + + + + + + + + + + + + + + + + + + +
FeatureChromeFirefox (Gecko)Internet ExplorerOperaSafari (WebKit)
Basic support14 {{property_prefix("webkit")}}23{{CompatNo}}15 {{property_prefix("webkit")}}
+ 22 (unprefixed)
6 {{property_prefix("webkit")}}
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
FeatureAndroidChromeFirefox Mobile (Gecko)Firefox OSIE PhoneOpera MobileSafari Mobile
Basic support{{CompatNo}}28 {{property_prefix("webkit")}}251.2{{CompatNo}}{{CompatNo}}6 {{property_prefix("webkit")}}
+
+ +

参考

+ + -- cgit v1.2.3-54-g00ecf