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);
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
Created attachment 464777 [details] test demo getting and recording PCM data which is 8000 samplerate and Float32Array
<rdar://problem/105073030>