This translation is incomplete. Please help translate this article from English.

Interfața AudioBuffer reprezintă un scurt material audio care se află în memorie, creat de un fișier audio folosind metoda AudioContext.decodeAudioData() sau date brute folosind AudioContext.createBuffer(). Odată pus în AudioBuffer, audio-ul poate atunci fi rulat prin plasarea lui într-un AudioBufferSourceNode.

Obiectele de acest tip sunt concepute pentru a păstra fragmente audio mici, de obicei mai puțin de 45 de secunde. Pentru sunete mai lungi, obiectele care implementează MediaElementAudioSourceNode sunt mai potrivite. Tamponul conține date în următorul format: PCM liniar IEEE754 pe 32 biți intercalate, cu un interval nominal între -1 și +1, adică 32 biți tampon în virgulă mobilă, cu fiecare eșantion între -1,0 și 1,0. Dacă AudioBuffer are mai multe canale, ele sunt stocate în tampon separat.

Constructor

AudioBuffer()
Creează și returnează un nouă instanță a obiectului AudioBuffer.

Proprietăți

AudioBuffer.sampleRate Read only
Returnează un număr flotant, reprezentând rata de eșantionare, în eșantioane pe secundă, a datelor PCM stocate în buffer.
AudioBuffer.length Read only
Returnează un număr întreg reprezentând lungimea, în cadrele de eșantionare, a datelor PCM stocate în buffer.
AudioBuffer.duration Read only
Returnează un număr double reprezentând durata, în secunde, a datelor PCM stocate în buffer.
AudioBuffer.numberOfChannels Read only
Returnează un număr întreg reprezentând numărul de canale audio discrete descrise de datele PCM stocate în buffer.

Metode

AudioBuffer.getChannelData()
Returnează un Float32Array care conține datele PCM asociate canalului, definite de parametrul channel (cu 0 reprezentând primul canal).
AudioBuffer.copyFromChannel()
Copiază probele din canalul specificat alfat în AudioBuffer in tabloul destinație.
AudioBuffer.copyToChannel()
Copiază probele în canalul specificat alfat în  AudioBuffer, din tabloul sursă.

Exemple

Următorul exemplu simple arată cum se creează un AudioBuffer și cum se umple cu sunet alb. Puteți găsi întregul cod sură pe site-ul nostru webaudio-examples; de asemenea, o versiune de rulare live este disponibilă.

var audioCtx = new (window.AudioContext || window.webkitAudioContext)();

// Create an empty three-second stereo buffer at the sample rate of the AudioContext
var myArrayBuffer = audioCtx.createBuffer(2, audioCtx.sampleRate * 3, audioCtx.sampleRate);

// Fill the buffer with white noise;
// just random values between -1.0 and 1.0
for (var channel = 0; channel < myArrayBuffer.numberOfChannels; channel++) {
  // This gives us the actual array that contains the data
  var nowBuffering = myArrayBuffer.getChannelData(channel);
  for (var i = 0; i < myArrayBuffer.length; i++) {
    // Math.random() is in [0; 1.0]
    // audio needs to be in [-1.0; 1.0]
    nowBuffering[i] = Math.random() * 2 - 1;
  }
}

// Get an AudioBufferSourceNode.
// This is the AudioNode to use when we want to play an AudioBuffer
var source = audioCtx.createBufferSource();

// set the buffer in the AudioBufferSourceNode
source.buffer = myArrayBuffer;

// connect the AudioBufferSourceNode to the
// destination so we can hear the sound
source.connect(audioCtx.destination);

// start the source playing
source.start();

Specificații

Specification Status Comment
Web Audio API
The definition of 'AudioBuffer' in that specification.
Working Draft definiție inițială.

Compatibilitatea browser-ului

Update compatibility data on GitHub
DesktopMobile
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidEdge MobileFirefox for AndroidOpera for AndroidSafari on iOSSamsung Internet
Basic supportChrome Full support 14Edge Full support YesFirefox Full support 25IE No support NoOpera Full support 15Safari Full support 6WebView Android Full support YesChrome Android Full support 18Edge Mobile Full support YesFirefox Android Full support 26Opera Android Full support 15Safari iOS ? Samsung Internet Android Full support Yes
AudioBuffer() constructorChrome Full support 55
Notes
Full support 55
Notes
Notes The context parameter was supported up until version 57, but has now been removed.
Edge ? Firefox Full support 53IE No support NoOpera Full support 42
Notes
Full support 42
Notes
Notes The context parameter was supported up until version 44, but has now been removed.
Safari ? WebView Android Full support 55
Notes
Full support 55
Notes
Notes The context parameter was supported up until version 57, but has now been removed.
Chrome Android Full support 55
Notes
Full support 55
Notes
Notes The context parameter was supported up until version 57, but has now been removed.
Edge Mobile ? Firefox Android Full support 53Opera Android Full support 42
Notes
Full support 42
Notes
Notes The context parameter was supported up until version 44, but has now been removed.
Safari iOS ? Samsung Internet Android Full support 6.0
durationChrome Full support 14Edge Full support 12Firefox Full support 25IE No support NoOpera Full support 15Safari Full support 6WebView Android Full support YesChrome Android Full support 18Edge Mobile Full support YesFirefox Android Full support 26Opera Android Full support 15Safari iOS ? Samsung Internet Android Full support Yes
lengthChrome Full support 14Edge Full support 12Firefox Full support 25IE No support NoOpera Full support 15Safari Full support 6WebView Android Full support YesChrome Android Full support 18Edge Mobile Full support YesFirefox Android Full support 26Opera Android Full support 15Safari iOS ? Samsung Internet Android Full support Yes
numberOfChannelsChrome Full support 14Edge Full support 12Firefox Full support 25IE No support NoOpera Full support 15Safari Full support 6WebView Android Full support YesChrome Android Full support 18Edge Mobile Full support YesFirefox Android Full support 26Opera Android Full support 15Safari iOS ? Samsung Internet Android Full support Yes
sampleRateChrome Full support 14Edge Full support 12Firefox Full support 25IE No support NoOpera Full support 15Safari Full support 6WebView Android Full support YesChrome Android Full support 18Edge Mobile Full support YesFirefox Android Full support 26Opera Android Full support 15Safari iOS ? Samsung Internet Android Full support Yes
copyFromChannelChrome Full support 14Edge Full support 13Firefox Full support 25IE No support NoOpera Full support 15Safari Full support 6WebView Android Full support YesChrome Android Full support 18Edge Mobile Full support YesFirefox Android Full support 26Opera Android Full support 15Safari iOS ? Samsung Internet Android Full support Yes
copyToChannelChrome Full support 14Edge Full support 13Firefox Full support 25IE No support NoOpera Full support 15Safari Full support 6WebView Android Full support YesChrome Android Full support 18Edge Mobile Full support YesFirefox Android Full support 26Opera Android Full support 15Safari iOS ? Samsung Internet Android Full support Yes
getChannelDataChrome Full support 14Edge Full support 12Firefox Full support 25IE No support NoOpera Full support 15Safari Full support 6WebView Android Full support YesChrome Android Full support 18Edge Mobile Full support YesFirefox Android Full support 26Opera Android Full support 15Safari iOS ? Samsung Internet Android Full support Yes

Legend

Full support  
Full support
No support  
No support
Compatibility unknown  
Compatibility unknown
See implementation notes.
See implementation notes.

Vezi și următoarele:

Document Tags and Contributors

Contributors to this page: vsambor
Last updated by: vsambor,