{"action":"created","issue":{"url":"https://api.github.com/repos/chris-rudmin/DecodeToWav/issues/2","labels_url":"https://api.github.com/repos/chris-rudmin/DecodeToWav/issues/2/labels{/name}","comments_url":"https://api.github.com/repos/chris-rudmin/DecodeToWav/issues/2/comments","events_url":"https://api.github.com/repos/chris-rudmin/DecodeToWav/issues/2/events","html_url":"https://github.com/chris-rudmin/DecodeToWav/issues/2","id":111556068,"number":2,"title":"Playing directly to output","user":{"login":"mscdex","id":54666,"avatar_url":"https://avatars.githubusercontent.com/u/54666?v=3","gravatar_id":"","url":"https://api.github.com/users/mscdex","html_url":"https://github.com/mscdex","followers_url":"https://api.github.com/users/mscdex/followers","following_url":"https://api.github.com/users/mscdex/following{/other_user}","gists_url":"https://api.github.com/users/mscdex/gists{/gist_id}","starred_url":"https://api.github.com/users/mscdex/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mscdex/subscriptions","organizations_url":"https://api.github.com/users/mscdex/orgs","repos_url":"https://api.github.com/users/mscdex/repos","events_url":"https://api.github.com/users/mscdex/events{/privacy}","received_events_url":"https://api.github.com/users/mscdex/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":4,"created_at":"2015-10-15T06:51:37Z","updated_at":"2015-10-16T02:44:27Z","closed_at":"2015-10-16T02:44:27Z","body":"First off, I want to say thanks for the opus encoder example, it works great.\r\n\r\nI'm having a problem though playing back the encoded data back to the AudioContext with the decoder. The problem is I cannot find how to determine the correct value for the second argument for `audioContext.createBuffer()`. I'm calling this once for the entire audio recording, so it's supposed to be the number of samples (I think). Currently I'm doing something like this:\r\n\r\n```javascript\r\nvar pcm = [];\r\n\r\ndecoderWorker.onmessage = function(e) {\r\n  if (e.data === null)\r\n    playPCM();\r\n  else\r\n    pcm.push(e.data[0]); // Float32Array\r\n};\r\n\r\ndecoderWorker.postMessage({\r\n  command: 'init',\r\n  decoderSampleRate: 8000,\r\n  outputBufferSampleRate: audioContext.sampleRate\r\n});\r\n\r\n// Use copy so the original can be uploaded later\r\nvar pages = new Uint8Array(recording);\r\ndecoderWorker.postMessage({\r\n  command: 'decode',\r\n  pages: pages\r\n}, [pages.buffer] );\r\n\r\ndecoderWorker.postMessage({\r\n  command: 'done'\r\n});\r\n\r\nfunction playPCM() {\r\n  if (pcm.length) {\r\n    // `audioContext.sampleRate * pcm.length` is obviously not right ...\r\n    var myArrayBuffer = audioContext.createBuffer(1, audioContext.sampleRate * pcm.length, audioContext.sampleRate);\r\n    var nowBuffering = myArrayBuffer.getChannelData(0);\r\n    for (var p = 0, b = 0; p < pcm.length; ++p) {\r\n      var chunk = pcm[p];\r\n      for (var i = 0; i < chunk.length; ++i,++b)\r\n        nowBuffering[b] = chunk[i];\r\n    }\r\n    var source = this.currentSource = audioContext.createBufferSource();\r\n    source.onended = function() {\r\n      console.log('onended');\r\n    };\r\n    source.buffer = myArrayBuffer;\r\n    source.connect(audioContext.destination);\r\n    source.start(0);\r\n  }\r\n}\r\n```\r\n\r\nIs it a matter of passing some extra data from the worker or ?"},"comment":{"url":"https://api.github.com/repos/chris-rudmin/DecodeToWav/issues/comments/148582909","html_url":"https://github.com/chris-rudmin/DecodeToWav/issues/2#issuecomment-148582909","issue_url":"https://api.github.com/repos/chris-rudmin/DecodeToWav/issues/2","id":148582909,"user":{"login":"mscdex","id":54666,"avatar_url":"https://avatars.githubusercontent.com/u/54666?v=3","gravatar_id":"","url":"https://api.github.com/users/mscdex","html_url":"https://github.com/mscdex","followers_url":"https://api.github.com/users/mscdex/followers","following_url":"https://api.github.com/users/mscdex/following{/other_user}","gists_url":"https://api.github.com/users/mscdex/gists{/gist_id}","starred_url":"https://api.github.com/users/mscdex/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mscdex/subscriptions","organizations_url":"https://api.github.com/users/mscdex/orgs","repos_url":"https://api.github.com/users/mscdex/repos","events_url":"https://api.github.com/users/mscdex/events{/privacy}","received_events_url":"https://api.github.com/users/mscdex/received_events","type":"User","site_admin":false},"created_at":"2015-10-16T02:44:27Z","updated_at":"2015-10-16T02:44:27Z","body":"Setting the total buffer length as you described seems to work, thanks!"}}