I am working on a synth with the Web audio API. Right now I am struggling to load the impulse response for a reverb into an arrayBuffer
, so that I can use it with the audio context.
As I am working locally, I tried to simply read the file with the IR (located in the same folder as the index.html, under audio/IR/irHall.ogg
) from the filesystem as I do in Ruby projects. Now I think to understand that this is not possible due to security issues when running Javascript code in the browser.
So I tried this approach that I found in a tutorial
function loadAudio( object, url) {
var request = new XMLHttpRequest();
request.open('GET', url, true);
request.responseType = 'arraybuffer';
request.onload = function() {
context.decodeAudioData(request.response, function(buffer) {
object.buffer = buffer;
});
}
request.send();
}
In my app, when I call this function with url = 'audio/IR/irHall.ogg'
it gives
me this error':
dub-machine.js:63 XMLHttpRequest cannot load file:///Users/bla/projects/dub-machine/audio/IR/irHall.ogg. Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https, chrome-extension-resource.`
I am sorry If it comes across as if I didn't research a lot. Matter of fact I am googling around for a solution for hours and keep getting more confused.
Can someone give me an idea what is the best/common way to load a file from the project to use its content in a javascript context?
Thanks!