Looks to me that p5’s web editor is doing some magic text replacement, preprocessing and replacing file names in code with the URL where they are served. Debug tools show that when the siren.ogg was fetched it was requested with the URL of “https://assets.editor.p5js.org/5dbbe32aa9d4bc00178410d4/441f7099-bc5a-443f-9ad2-5cc24e4cc10b.ogg” rather than just siren.ogg.
I modified the code to write to a different file name than what I wanted to fetch and it worked here so it’s an issue with p5.js’s online editor. The code I used is:
const orcCode = `
; Initialize the global variables.
; Initialize the global variables.
ksmps = 32
nchnls = 2
0dbfs = 1instr 1
prints “Hello”
aSiren, a2 diskin2 “myfile.ogg”, 1, 0, 1
outs aSiren, aSiren
endin
`;let csound;
let isPlaying = false;//imports files for use with Csound
function CopyUrlToLocal(name, file, callback = null) {
var xmlHttpRequest = new XMLHttpRequest();
xmlHttpRequest.onload = function() {
var data = new Uint8Array(xmlHttpRequest.response);
csound.writeToFS(name, data);
};
xmlHttpRequest.open(“get”, file, true);
xmlHttpRequest.responseType = “arraybuffer”;
xmlHttpRequest.send(null);
}CsoundObj.initialize().then(() => {
console.log(“loading… loaded!”);
csound = new CsoundObj();
csound.setOption(‘-m0d’);
csound.compileOrc(orcCode);
CopyUrlToLocal(“myfile.ogg”, “siren.ogg”);
csound.start();
});function mousePressed() {
if (csound && isPlaying === false) {
csound.audioContext.resume();
csound.readScore(‘i1 0 3600’);
isPlaying = true;
} else {
csound.stop();
csound.reset();
isPlaying = false;
}
}var waves = ;
var car;
var people;
//based on p5.js Web Editorfunction setup() {
createCanvas(windowWidth, windowHeight);
}function draw() {
background(0);}