tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

audio-data.crossOriginIsolated.https.any.js (1284B)


      1 // META: global=window
      2 // META: script=/common/media.js
      3 // META: script=/webcodecs/utils.js
      4 
      5 var defaultInit = {
      6  timestamp: 1234,
      7  channels: 2,
      8  sampleRate: 8000,
      9  frames: 1,
     10 };
     11 
     12 function testAudioData(useView) {
     13  let localData =
     14      new SharedArrayBuffer(defaultInit.channels * defaultInit.frames * 4);
     15  let view = new Float32Array(localData);
     16  view[0] = -1.0;
     17  view[1] = 1.0;
     18 
     19  let audio_data_init = {
     20    timestamp: defaultInit.timestamp,
     21    data: useView ? view : localData,
     22    numberOfFrames: defaultInit.frames,
     23    numberOfChannels: defaultInit.channels,
     24    sampleRate: defaultInit.sampleRate,
     25    format: 'f32-planar',
     26  }
     27 
     28  let data = new AudioData(audio_data_init);
     29 
     30  let copyDest = new SharedArrayBuffer(data.allocationSize({planeIndex: 0}));
     31  let destView = new Float32Array(copyDest);
     32  data.copyTo(useView ? destView : copyDest, {planeIndex: 0});
     33  assert_equals(destView[0], -1.0, 'copyDest[0]');
     34  data.copyTo(useView ? destView : copyDest, {planeIndex: 1});
     35  assert_equals(destView[0], 1.0, 'copyDest[1]');
     36 }
     37 
     38 test(t => {
     39  testAudioData(/*useView=*/ false);
     40 }, 'Test construction and copyTo() using a SharedArrayBuffer');
     41 
     42 test(t => {
     43  testAudioData(/*useView=*/ true);
     44 }, 'Test construction and copyTo() using a Uint8Array(SharedArrayBuffer)');