Bug 251350

Summary: The PCM data that get from audioWorklet is less than the SampleRate i set
Product: WebKit Reporter: 294434941
Component: Web AudioAssignee: Nobody <webkit-unassigned>
Status: NEW ---    
Severity: Major CC: cdumez, jer.noble, webkit-bug-importer, youennf
Priority: P2 Keywords: InRadar
Version: Safari 16   
Hardware: iPhone / iPad   
OS: iOS 16   
Attachments:
Description Flags
the pcmdata i record,sanplerate is 8000, channels is 1, type is 16bitInt
none
test demo none

Description 294434941 2023-01-30 01:09:18 PST
if I get PCM data by AudioWorkletNode in ios, i find the actual PCM data is less than i set. For example, if i set SampleRate 8000, but Per second i get the PCM data is 6016. Especially, if i set 16000, i get 12032.

#Step#
Firstly, I use MediaDevices.getUserMedia() to get MediaStream; Secondly, I using new window.AudioContext() to creat AudioContext instance and set the SampleRate of AudioContext; Thirdly, I use AudioContext.createMediaStreamSource() to creat audioInputNode by MediaStream and AudioContext; Fourthly, I use AudioWorkletNode() and audioWorklet to creat AudioWorkletNode, in AudioWorkletNode i use  this.port.postMessage() to post PCM data.

#Hardware and Version#
I test my demo in Safari on ipone with IOS 15.6, 16.1 and 16.2 all find this bug, then in safari16.2 on MacOs is ok.

#Code#
//audioPcmProces.js
class VoiceDataGet extends AudioWorkletProcessor {
 
    constructor() {
        super();
    }
 
    process (inputList, outputList, parameters) {
        const output = outputList[0];
        const input = inputList[0];
      if(inputList.length>0&&inputList[0].length>0){
        this.port.postMessage(inputList[0]);
      }
      return true;
    }
}

registerProcessor('audioPcmProces', VoiceDataGet)

/**************************************************************************************/

//auidoprocess.js
   
    this.aduiocontext = new (window.AudioContext || window.webkitAudioContext)({sampleRate:this.config.outputSampleRate}); //set sampleRate
    this.audioInputNode = this.aduiocontext.createMediaStreamSource(this.stream); 
    await this.aduiocontext.audioWorklet.addModule('audioPcmProces.js');
    this.workNode = new AudioWorkletNode(this.aduiocontext, 'audioPcmProces');
    var messagePort = this.workNode.port;
    messagePort.onmessage = (e) => {
        var channelData = e.data;
        transPcm(channelData);
    }
    this.audioInputNode.connect(this.workNode);
Comment 1 294434941 2023-01-30 19:40:59 PST
Created attachment 464773 [details]
the pcmdata i record,sanplerate is 8000, channels is 1, type is 16bitInt

the pcmdata i post in attachment, the data is cut off when i get
Comment 2 294434941 2023-01-30 23:07:42 PST
Created attachment 464777 [details]
test demo

getting and recording PCM data which is 8000 samplerate and Float32Array
Comment 3 Radar WebKit Bug Importer 2023-02-06 01:10:16 PST
<rdar://problem/105073030>