[Csnd] Csound wasm hrtfmove loading files
Date | 2022-11-28 20:45 |
From | Tarmo Johannes |
Subject | [Csnd] Csound wasm hrtfmove loading files |
Hi! Inspired by the work on Csound-wasm and Vicor's examples on https://github.com/vlazzarini/vanilla/ I wanted to try a web solution of binaural audio and hrtfmove opcode. Following the examples I was able to load an audio file and play it with diskin2 but for the hrtf analysis files Csound complained: cannot load hrtf-44100-left.dat, or SADIR undefined hrtf-44100-left.dat and -right.dat are in the same folder as the html file and csd. I tried also setting SADIR: But not sure what it should actually be. Is it supposed to work? How can I debug this problem? Can I check somehow which files are actually loaded to the filesystem? I am using csound.js v6.18.1 form Victor's vanilla repo. The code for loading the files that I used: const csd = "test.csd"; let filename = "sound.wav"; const hrftL = "hrtf-44100-left.dat", hrftR = "hrtf-44100-right.dat"; --- await copyUrlToLocal(csd, csd) await copyUrlToLocal(filename, filename); await copyUrlToLocal(hrftL, hrftL); await copyUrlToLocal(hrftR, hrftR); --- let srcfile = await fetch(src, {cache: "no-store"}) let dat = await srcfile.arrayBuffer(); await csound.fs.writeFile(dest, new Uint8Array(dat)); console.log("Finished loading: ", dest); } Thanks! tarmo |
Date | 2022-11-29 08:43 |
From | Victor Lazzarini |
Subject | Re: [Csnd] [EXTERNAL] [Csnd] Csound wasm hrtfmove loading files |
There’s a difference between diskin and hrtfmove. Diskin opens files for reading and reads blocks from it, whereas hrtfmove uses memory files, where the whole file is put into memory and data is read from there. Looking at Engine/memfiles.c: Load_File_() , I see three possibilities for failure: 1) The file cannot be opened (e.g. it is not found, or permissions are not given). 2) The file length is zero: fseek and ftell are used to find how much data is there, and if it is less than 1 byte, it fails. 3) The file reading (fread) fails to read all the data. Any of these can lead to the error message you got (the code does not distinguish between them). Given that files are being copied OK, I would think 1 and possibly 2 are unlikely to be the cause. In any case, it seems that there may be a problem loading memory files. You can try to see if Csound can open the dat files using another open (fopen? diskin perhaps) and if that is the case, then you know the problem is not with copying the data into the local fs. ======================== Prof. Victor Lazzarini Maynooth University Ireland > On 28 Nov 2022, at 20:45, Tarmo Johannes |
Date | 2022-11-29 11:20 |
From | Tarmo Johannes |
Subject | Re: [Csnd] [EXTERNAL] [Csnd] Csound wasm hrtfmove loading files |
Attachments | agemove.csd |
Hi! Thanks for the suggestions! The results are strange. Using a simple test instument: instr 1 Sfile = "nofile.dat" ; "hrtf-44100-left.dat" prints Sfile ihandle fiopen Sfile, 3 print ihandle endin on desktop I get ann error as expected: nofile.datINIT ERROR in instr 1 (opcode fiopen) line 21: error opening file 'nofile.dat' (and with Sfile = "hrtf-44100-left.dat" it opens as expected) But on the web it reports no error on both cases, even if there is no file with that name. So I don't know... Another test: instr 1 kvalue readk "hrtf-44100-left.dat", 6, 0.001 printk2 kvalue endin Prints the same values on desktop and on the web browser, so the file is copied to memory correctly, just hrtfmove2 cannot read it. I attach the csd for any case. Tarmo Kontakt Victor Lazzarini (<Victor.Lazzarini@mu.ie>) kirjutas kuupäeval T, 29. november 2022 kell 10:43: There’s a difference between diskin and hrtfmove. Diskin opens files for reading and reads blocks from it, |
Date | 2022-11-29 12:06 |
From | Victor Lazzarini |
Subject | Re: [Csnd] [EXTERNAL] [Csnd] Csound wasm hrtfmove loading files |
Thanks Now that you confirmed with readk that the file is found and opened, we can confirm the problem is in memory files, because readk uses csound->fileOpen2() and reads data directly from file. It’s not hrtfmove that can’t read it. The message comes from memfiles.c, so the problem is there. Other opcodes that use memory files in the same way are the atsa opcodes. They should have the same problem. Perhaps Hlodver or Steven could have a look to see what’s going on. I would need a local build of wasm, which I don’t have the tools for. I should note that the hrtf opcodes used to work with the Emscripten build of Csound WASM, we used them here in 2019 for a research project, so this is some form of regression. ======================== Prof. Victor Lazzarini Maynooth University Ireland > On 29 Nov 2022, at 11:20, Tarmo Johannes |
Date | 2022-11-29 12:36 |
From | Hlöðver Sigurðsson |
Subject | Re: [Csnd] [EXTERNAL] [Csnd] Csound wasm hrtfmove loading files |
My first instinct was that it must use a different file open handler. I just never bumped into this issue until now. I don't think it will be too difficult to fix. Sounds like it will need to be fixed on binary level and not with the bindings. I'll update here Tarmo when I have a new patch release. On Tue, 29 Nov 2022 at 13:06, Victor Lazzarini <Victor.Lazzarini@mu.ie> wrote: Thanks |
Date | 2022-11-29 13:02 |
From | Victor Lazzarini |
Subject | Re: [Csnd] [EXTERNAL] [Csnd] Csound wasm hrtfmove loading files |
It doesn’t look different to me: it uses fopen() and fread(). See memfiles.c:Load_File_() ======================== Prof. Victor Lazzarini Maynooth University Ireland > On 29 Nov 2022, at 12:36, Hlöðver Sigurðsson |
Date | 2022-11-29 16:05 |
From | Hlöðver Sigurðsson |
Subject | Re: [Csnd] Csound wasm hrtfmove loading files |
It's fixed in @csound/browser 6.18.4 On Mon, 28 Nov 2022 at 21:46, Tarmo Johannes <trmjhnns@gmail.com> wrote:
|
Date | 2022-11-29 16:55 |
From | Tarmo Johannes |
Subject | Re: [Csnd] Csound wasm hrtfmove loading files |
Splendid! I can confirm that hrtfmove works now with @csound/browser 6.18.4. Thank you, Hlödver for so quick fix! tarmo Kontakt Hlöðver Sigurðsson (<hlolli@gmail.com>) kirjutas kuupäeval T, 29. november 2022 kell 18:06:
|
Date | 2022-11-29 17:00 |
From | Victor Lazzarini |
Subject | Re: [Csnd] [EXTERNAL] [Csnd] Csound wasm hrtfmove loading files |
Great, thanks Hlodver! ======================== Prof. Victor Lazzarini Maynooth University Ireland > On 29 Nov 2022, at 16:55, Tarmo Johannes |