p5.js-sound icon indicating copy to clipboard operation
p5.js-sound copied to clipboard

Failed to execute 'createBuffer' on 'BaseAudioContext'

Open andreyzagoruy opened this issue 6 years ago • 8 comments

When recording audio I get this error on recent Chrome(v71): Failed to execute 'createBuffer' on 'BaseAudioContext': The number of frames provided (0) is less than or equal to the minimum bound (0).

The first trace producing this error is here: p5.SoundFile.prototype.setBuffer = function (buf) { var numChannels = buf.length; var size = buf[0].length; var newBuffer = ac.createBuffer(numChannels, size, ac.sampleRate); <--- here

can anybody help?

andreyzagoruy avatar Jan 08 '19 14:01 andreyzagoruy

Same here on both Mac OSX and Win10. Also, the recording demo is broken in v71. [EDIT] this one: https://p5js.org/examples/sound-record-save-audio.html

dirkk0 avatar Jan 18 '19 08:01 dirkk0

The solution seems to be to include getAudioContext().resume() as a first line in mousePressed (or touchStart, respectively).

dirkk0 avatar Jan 18 '19 08:01 dirkk0

this also happens when you're opening more than one instance of the save audio page.

romaad avatar Apr 26 '19 01:04 romaad

The solution seems to be to include getAudioContext().resume() as a first line in mousePressed (or touchStart, respectively).

Hi, did you solve the problem? I got the same issue today, but I don't really get how to solve the problem? Could you help with this? Thx a lot!

JerryHanZD avatar Jun 05 '19 10:06 JerryHanZD

Oh no! It seems createBuffer was removed from the spec. We can use the asynchronous method decodeAudioData instead.

via https://developer.mozilla.org/en-US/docs/Web/API/BaseAudioContext/createBuffer

Note: createBuffer() used to be able to take compressed data and give back decoded samples, but this ability was removed from the spec, because all the decoding was done on the main thread, therefore createBuffer() was blocking other code execution. The asynchronous method decodeAudioData() does the same thing — takes compressed audio, say, an MP3 file, and directly gives you back an AudioBuffer that you can then set to play via in an AudioBufferSourceNode. For simple uses like playing an MP3, decodeAudioData() is what you should be using.

There are a few uses of createBuffer: https://github.com/processing/p5.js-sound/search?q=createbuffer&unscoped_q=createbuffer

Please comment if you'd like to tackle this issue, and I will do the same if I start on it!

therewasaguy avatar Aug 18 '19 22:08 therewasaguy

I'm getting this error too. Chrome version 80.0.3987.149. So I guess p5 sound no longer works for recording audio in Chrome? Unless there's a workaround I'm unaware of?

I'm also getting a "NotSupportedError" for createBuffer in Safari (version 12.1).

Since neither createBuffer or decodeAudioData are supported in Safari on iOS, it probably wouldn't work there even after fixing it? So that's... unfortunate.

j-or avatar Apr 01 '20 08:04 j-or

@jackscode what version of p5.sound are you using?

This example is "working for me" ™️ on Chrome 80.0.3987.149 and Safari 12.1 with p5 sound version 0.3.12 https://p5js.org/reference/#/p5.SoundRecorder

I'm not sure if createBuffer was the issue, or if the issue was creating a buffer that was empty because the audio context hadn't started, and 0.3.12 has fixed related to that.

therewasaguy avatar Apr 01 '20 23:04 therewasaguy

I ran into this same issue when trying to re-run an old script I wrote against an old version of p5.sound.js.

The solution for me was to make sure 'userStartAudio()' is called (which the example linked above does do).

fahadfalls avatar Feb 08 '22 23:02 fahadfalls