AudioBuffer: phương thức copyToChannel()

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since April 2021.

Phương thức copyToChannel() của giao diện AudioBuffer sao chép các mẫu từ mảng nguồn vào kênh được chỉ định của AudioBuffer.

Cú pháp

js
copyToChannel(source, channelNumber)
copyToChannel(source, channelNumber, startInChannel)

Tham số

source

Một Float32Array mà dữ liệu kênh sẽ được sao chép từ đó.

channelNumber

Số thứ tự kênh của AudioBuffer hiện tại để sao chép dữ liệu kênh vào. Nếu channelNumber lớn hơn hoặc bằng AudioBuffer.numberOfChannels, một INDEX_SIZE_ERR sẽ được ném ra.

startInChannel Optional

Độ lệch tùy chọn để sao chép dữ liệu vào. Nếu startInChannel lớn hơn AudioBuffer.length, một INDEX_SIZE_ERR sẽ được ném ra.

Giá trị trả về

Không có (undefined).

Ví dụ

js
const myArrayBuffer = audioCtx.createBuffer(2, frameCount, audioCtx.sampleRate);
const anotherArray = new Float32Array();
// Sao chép dữ liệu kênh từ kênh thứ hai của myArrayBuffer.
myArrayBuffer.copyFromChannel(anotherArray, 1, 0);
// Sao chép dữ liệu từ anotherArray vào kênh đầu tiên của myArrayBuffer.
// Giờ đây cả hai kênh đều có cùng dữ liệu.
myArrayBuffer.copyToChannel(anotherArray, 0, 0);

Thông số kỹ thuật

Specification
Web Audio API
# dom-audiobuffer-copytochannel

Tương thích trình duyệt

Xem thêm