# Loading samples with Web Csound?

**URL:** <https://forum.csound.com/t/loading-samples-with-web-csound/137>\
**Category:** Web Csound\
**Created:** [February 2, 2021, 8:20pm UTC](https://forum.csound.com/t/loading-samples-with-web-csound/137 "2021-02-02T20:20:46Z")\
**Posts on this page:** 1\
**Showing post:** 6

<div class="post-metadata">

**Author:** ![stevenyi](https://forum.csound.com/user_avatar/forum.csound.com/stevenyi/32/4_2.png) [@stevenyi](https://forum.csound.com/u/stevenyi)\
**Post date:** [February 2, 2021, 11:15pm UTC](https://forum.csound.com/t/loading-samples-with-web-csound/137/6 "2021-02-02T23:15:23Z")

</div>

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](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 = 1
> 
> instr 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 Editor](https://editor.p5js.org/7eter/collections)
> 
> function setup() {  
> createCanvas(windowWidth, windowHeight);  
> }
> 
> function draw() {  
> background(0);
> 
> }

---

_[View the full topic](https://forum.csound.com/t/loading-samples-with-web-csound/137)._
