Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

convert to markdown for web/api zh-CN #7705

Merged
merged 2 commits into from
Aug 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
93 changes: 0 additions & 93 deletions files/zh-cn/web/api/analysernode/fftsize/index.html

This file was deleted.

92 changes: 92 additions & 0 deletions files/zh-cn/web/api/analysernode/fftsize/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
---
title: AnalyserNode.fftSize
slug: Web/API/AnalyserNode/fftSize
---
{{ APIRef("Web Audio API") }}

{{ domxref("AnalyserNode") }} 接口的 `fftSize` 属性的值是一个无符号长整型的值,表示(信号)样本的窗口大小。当执行[快速傅里叶变换](/zh-CN/docs/)(Fast Fourier Transfor (FFT))时,这些(信号)样本被用来获取频域数据。

fftSize 属性的值必须是从 32 到 32768 范围内的 2 的非零幂; 其默认值为 2048.

> **备注:** 如果其值不是 2 的幂,或者它在指定范围之外,则抛出异常 INDEX_SIZE_ERR.

## 语法

```js
var audioCtx = new AudioContext();
var analyser = audioCtx.createAnalyser();
analyser.fftSize = 2048;
```

### 值

一个无符号长整型。

## 例子

下面的例子展示了 [`AudioContext`](/zh-CN/docs/Web/API/AudioContext) 创建一个 `AnalyserNode`, 然后用 [`requestAnimationFrame`](/zh-CN/docs/Web/API/Window/requestAnimationFrame) 和 [`<canvas>`](/zh-CN/docs/Web/HTML/Element/canvas) 去反复收集当前音频的时域数据,并绘制为一个示波器风格的输出 (频谱).

更多的例子/信息,查看 [Voice-change-O-matic](http://mdn.github.io/voice-change-o-matic/) 演示 (相关代码在 [app.js 在 128 行\~205 行](https://github.com/mdn/voice-change-o-matic/blob/gh-pages/scripts/app.js#L128-L205)).

```js
var audioCtx = new (window.AudioContext || window.webkitAudioContext)();
var analyser = audioCtx.createAnalyser();

...

analyser.fftSize = 2048;
var bufferLength = analyser.fftSize;
var dataArray = new Uint8Array(bufferLength);
analyser.getByteTimeDomainData(dataArray);

// draw an oscilloscope of the current audio source

function draw() {

drawVisual = requestAnimationFrame(draw);

analyser.getByteTimeDomainData(dataArray);

canvasCtx.fillStyle = 'rgb(200, 200, 200)';
canvasCtx.fillRect(0, 0, WIDTH, HEIGHT);

canvasCtx.lineWidth = 2;
canvasCtx.strokeStyle = 'rgb(0, 0, 0)';

canvasCtx.beginPath();

var sliceWidth = WIDTH * 1.0 / bufferLength;
var x = 0;

for(var i = 0; i < bufferLength; i++) {

var v = dataArray[i] / 128.0;
var y = v * HEIGHT/2;

if(i === 0) {
canvasCtx.moveTo(x, y);
} else {
canvasCtx.lineTo(x, y);
}

x += sliceWidth;
}

canvasCtx.lineTo(canvas.width, canvas.height/2);
canvasCtx.stroke();
};

draw();
```

## 规范

{{Specifications}}

## 浏览器兼容性

{{Compat("api.AnalyserNode.fftSize")}}

## 相关内容

- [Using the Web Audio API](/zh-CN/docs/Web_Audio_API/Using_Web_Audio_API)
169 changes: 0 additions & 169 deletions files/zh-cn/web/api/analysernode/index.html

This file was deleted.

Loading