Csound Csound-dev Csound-tekno Search About

[Csnd] File reference in waaw csound

Date2018-11-05 10:37
FromAndreas Bergsland
Subject[Csnd] File reference in waaw csound

Hi

I was trying out the examples on https://waaw.csound.com/ to understand how web audio with csound works. I was trying to use diskin2 with a sound file, but couldn’t get csound to locate the file.

I tried both using relative path (same as the html file), absolute path locally and http: address on a web server. All gave “failed to open file” errors.

Is there a particular way of referencing files when using web audio?

Best,

Andreas

 

-- 

Andreas Bergsland

 

Associate professor - førsteamanuensis

Study Programme Leader - studieprogramleder

Music Technology Programme - Musikkteknologiseksjonen

Department of Music - Institutt for musikk

Olavskvartalet

NTNU (Norwegian University of Science and Technology)

7491 Trondheim, NORWAY

 

Visiting address/besøksadresse: Fjordgt.1 (3.etg.)

e-mail: andreas.bergsland@ntnu.no

Office phone (Skype for business):7359 0096

Mobil: 4566 3316

http://folk.ntnu.no/andbe

https://www.vibra.no/

https://www.ntnu.edu/artec


Date2018-11-05 11:11
FromEdward Costello
SubjectRe: [Csnd] File reference in waaw csound
Csound on the web uses it’s own sandboxed file system provided by Emscripten. In the Csound web api, there is a method on CsoundObj.js called writeToFs, I believe this takes a binary blob and a path to where you want to put the file in the file system. So theoretically I think the procedure is the use the browser file api to get a file from your computer using FileReader, read it as binary, then upload that to the Csound file system using writeToFs.
Ed 

On 5 Nov 2018, at 10:37, Andreas Bergsland <andreas.bergsland@NTNU.NO> wrote:

Hi

I was trying out the examples on https://waaw.csound.com/ to understand how web audio with csound works. I was trying to use diskin2 with a sound file, but couldn’t get csound to locate the file.

I tried both using relative path (same as the html file), absolute path locally and http: address on a web server. All gave “failed to open file” errors.

Is there a particular way of referencing files when using web audio?

Best, 

Andreas

 

-- 

Andreas Bergsland

 

Associate professor - førsteamanuensis

Study Programme Leader - studieprogramleder

Music Technology Programme - Musikkteknologiseksjonen

Department of Music - Institutt for musikk

Olavskvartalet

NTNU (Norwegian University of Science and Technology)

7491 Trondheim, NORWAY

 

Visiting address/besøksadresse: Fjordgt.1 (3.etg.)

Office phone (Skype for business):7359 0096

Mobil: 4566 3316

Csound mailing list Csound@listserv.heanet.ie https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to https://github.com/csound/csound/issuesDiscussions of bugs and features can be posted here


Date2018-11-06 14:18
FromAndreas Bergsland
SubjectRe: [Csnd] File reference in waaw csound

Sorry, but I am very much a newbie when it comes to javascript for web. I tried to search the web for some examples with the use of FileReader, but wasn’t sure exactly how to use it. E.g. should one use readAsArrayBuffer or readAsDataURL? (The writeToFs seemed more straightforward to use.)

You wouldn’t have some example code to show how it is used?

Best,

Andreas

 

From: A discussion list for users of Csound <CSOUND@LISTSERV.HEANET.IE> on behalf of Edward Costello <phasereset@GMAIL.COM>
Reply-To: A discussion list for users of Csound <CSOUND@LISTSERV.HEANET.IE>
Date: Monday, 5 November 2018 at 12:11
To: "CSOUND@LISTSERV.HEANET.IE" <CSOUND@LISTSERV.HEANET.IE>
Subject: Re: [Csnd] File reference in waaw csound

 

Csound on the web uses it’s own sandboxed file system provided by Emscripten. In the Csound web api, there is a method on CsoundObj.js called writeToFs, I believe this takes a binary blob and a path to where you want to put the file in the file system. So theoretically I think the procedure is the use the browser file api to get a file from your computer using FileReader, read it as binary, then upload that to the Csound file system using writeToFs.

Ed 



On 5 Nov 2018, at 10:37, Andreas Bergsland <andreas.bergsland@NTNU.NO> wrote:

 

Hi

I was trying out the examples on https://waaw.csound.com/ to understand how web audio with csound works. I was trying to use diskin2 with a sound file, but couldn’t get csound to locate the file.

I tried both using relative path (same as the html file), absolute path locally and http: address on a web server. All gave “failed to open file” errors.

Is there a particular way of referencing files when using web audio?

Best, 

Andreas

 

-- 

Andreas Bergsland

 

Associate professor - førsteamanuensis

Study Programme Leader - studieprogramleder

Music Technology Programme - Musikkteknologiseksjonen

Department of Music - Institutt for musikk

Olavskvartalet

NTNU (Norwegian University of Science and Technology)

7491 Trondheim, NORWAY

 

Visiting address/besøksadresse: Fjordgt.1 (3.etg.)

Office phone (Skype for business):7359 0096

Mobil: 4566 3316

Csound mailing list Csound@listserv.heanet.ie https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to https://github.com/csound/csound/issuesDiscussions of bugs and features can be posted here

 

Csound mailing list Csound@listserv.heanet.ie https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to https://github.com/csound/csound/issues Discussions of bugs and features can be posted here


Date2018-11-06 15:19
FromVictor Lazzarini
SubjectRe: [Csnd] File reference in waaw csound
Did you look in csound.js? there is a use there that might give you some idea. Here’s
a function that copies data to the FS so that it becomes available (as a file) in
Csound.

    /**
     * Copies a URL file to local/. (not persistent).
     *
     * NB: works with the origin URL and CORS-ready URLs
     *
     * @param {string} url  The url name
     * @param {string} name The file name
     * @param {function} callback completion callback
     */
    function CopyUrlToLocal(url, name, callback = null) {
        var xmlHttpRequest = new XMLHttpRequest();
        xmlHttpRequest.onload = function() {
            var data = new Uint8Array(xmlHttpRequest.response);
            csound.Csound.writeToFS(name, data);
            callback();
        };
        xmlHttpRequest.open("get", url, true);
        xmlHttpRequest.responseType = "arraybuffer";
        xmlHttpRequest.send(null);

    }

The following code in midiplayer.html shows how it can be used

function handleFileSelect(evt) {
            if (!loaded) {
                var files = evt.target.files;
                var f = files[0];
                var objectURL = window.URL.createObjectURL(f);
                csound.CopyUrlToLocal(objectURL, "midifile.mid", function() {
                    loaded = true;
                    console.log("Ready to play. \n");
                });
            } else {
                csound.UpdateStatus("to load a new file, first refresh page!")
            }
        }



========================
Prof. Victor Lazzarini
Dean of Arts, Celtic Studies, and Philosophy,
Maynooth University,
Maynooth, Co Kildare, Ireland
Tel: 00 353 7086936
Fax: 00 353 1 7086952 

> On 6 Nov 2018, at 14:18, Andreas Bergsland  wrote:
> 
> Sorry, but I am very much a newbie when it comes to javascript for web. I tried to search the web for some examples with the use of FileReader, but wasn’t sure exactly how to use it. E.g. should one use readAsArrayBuffer or readAsDataURL? (The writeToFs seemed more straightforward to use.)
> You wouldn’t have some example code to show how it is used?
> Best, 
> Andreas
>  
> From: A discussion list for users of Csound  on behalf of Edward Costello 
> Reply-To: A discussion list for users of Csound 
> Date: Monday, 5 November 2018 at 12:11
> To: "CSOUND@LISTSERV.HEANET.IE" 
> Subject: Re: [Csnd] File reference in waaw csound
>  
> Csound on the web uses it’s own sandboxed file system provided by Emscripten. In the Csound web api, there is a method on CsoundObj.js called writeToFs, I believe this takes a binary blob and a path to where you want to put the file in the file system. So theoretically I think the procedure is the use the browser file api to get a file from your computer using FileReader, read it as binary, then upload that to the Csound file system using writeToFs.
> Ed 
> 
> 
> On 5 Nov 2018, at 10:37, Andreas Bergsland  wrote:
>  
> Hi
> I was trying out the examples on https://waaw.csound.com/ to understand how web audio with csound works. I was trying to use diskin2 with a sound file, but couldn’t get csound to locate the file.
> I tried both using relative path (same as the html file), absolute path locally and http: address on a web server. All gave “failed to open file” errors.
> Is there a particular way of referencing files when using web audio?
> Best, 
> Andreas
>  
> -- 
> Andreas Bergsland
>  
> Associate professor - førsteamanuensis
> Study Programme Leader - studieprogramleder
> Music Technology Programme - Musikkteknologiseksjonen
> Department of Music - Institutt for musikk
> Olavskvartalet
> NTNU (Norwegian University of Science and Technology)
> 7491 Trondheim, NORWAY
>  
> Visiting address/besøksadresse: Fjordgt.1 (3.etg.)
> e-mail: andreas.bergsland@ntnu.no
> Office phone (Skype for business):7359 0096
> Mobil: 4566 3316
> http://folk.ntnu.no/andbe
> https://www.vibra.no/
> https://www.ntnu.edu/artec
> Csound mailing list Csound@listserv.heanet.ie https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to https://github.com/csound/csound/issuesDiscussions of bugs and features can be posted here
>  
> Csound mailing list Csound@listserv.heanet.ie https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to https://github.com/csound/csound/issues Discussions of bugs and features can be posted here
> Csound mailing list Csound@listserv.heanet.ie https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports tohttps://github.com/csound/csound/issues Discussions of bugs and features can be posted here


Csound mailing list
Csound@listserv.heanet.ie
https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
Send bugs reports to
        https://github.com/csound/csound/issues
Discussions of bugs and features can be posted here

Date2018-11-06 21:54
FromAndreas Bergsland
SubjectRe: [Csnd] File reference in waaw csound
Thanks for pointing me to this, Victor. I think I will have to study javascript a bit more before proceeding on this.
Andreas

On 06/11/2018, 16:20, "A discussion list for users of Csound on behalf of Victor Lazzarini"  wrote:

    Did you look in csound.js? there is a use there that might give you some idea. Here’s
    a function that copies data to the FS so that it becomes available (as a file) in
    Csound.
    
        /**
         * Copies a URL file to local/. (not persistent).
         *
         * NB: works with the origin URL and CORS-ready URLs
         *
         * @param {string} url  The url name
         * @param {string} name The file name
         * @param {function} callback completion callback
         */
        function CopyUrlToLocal(url, name, callback = null) {
            var xmlHttpRequest = new XMLHttpRequest();
            xmlHttpRequest.onload = function() {
                var data = new Uint8Array(xmlHttpRequest.response);
                csound.Csound.writeToFS(name, data);
                callback();
            };
            xmlHttpRequest.open("get", url, true);
            xmlHttpRequest.responseType = "arraybuffer";
            xmlHttpRequest.send(null);
    
        }
    
    The following code in midiplayer.html shows how it can be used
    
    function handleFileSelect(evt) {
                if (!loaded) {
                    var files = evt.target.files;
                    var f = files[0];
                    var objectURL = window.URL.createObjectURL(f);
                    csound.CopyUrlToLocal(objectURL, "midifile.mid", function() {
                        loaded = true;
                        console.log("Ready to play. \n");
                    });
                } else {
                    csound.UpdateStatus("to load a new file, first refresh page!")
                }
            }
    
    
    
    ========================
    Prof. Victor Lazzarini
    Dean of Arts, Celtic Studies, and Philosophy,
    Maynooth University,
    Maynooth, Co Kildare, Ireland
    Tel: 00 353 7086936
    Fax: 00 353 1 7086952 
    
    > On 6 Nov 2018, at 14:18, Andreas Bergsland  wrote:
    > 
    > Sorry, but I am very much a newbie when it comes to javascript for web. I tried to search the web for some examples with the use of FileReader, but wasn’t sure exactly how to use it. E.g. should one use readAsArrayBuffer or readAsDataURL? (The writeToFs seemed more straightforward to use.)
    > You wouldn’t have some example code to show how it is used?
    > Best, 
    > Andreas
    >  
    > From: A discussion list for users of Csound  on behalf of Edward Costello 
    > Reply-To: A discussion list for users of Csound 
    > Date: Monday, 5 November 2018 at 12:11
    > To: "CSOUND@LISTSERV.HEANET.IE" 
    > Subject: Re: [Csnd] File reference in waaw csound
    >  
    > Csound on the web uses it’s own sandboxed file system provided by Emscripten. In the Csound web api, there is a method on CsoundObj.js called writeToFs, I believe this takes a binary blob and a path to where you want to put the file in the file system. So theoretically I think the procedure is the use the browser file api to get a file from your computer using FileReader, read it as binary, then upload that to the Csound file system using writeToFs.
    > Ed 
    > 
    > 
    > On 5 Nov 2018, at 10:37, Andreas Bergsland  wrote:
    >  
    > Hi
    > I was trying out the examples on https://waaw.csound.com/ to understand how web audio with csound works. I was trying to use diskin2 with a sound file, but couldn’t get csound to locate the file.
    > I tried both using relative path (same as the html file), absolute path locally and http: address on a web server. All gave “failed to open file” errors.
    > Is there a particular way of referencing files when using web audio?
    > Best, 
    > Andreas
    >  
    > -- 
    > Andreas Bergsland
    >  
    > Associate professor - førsteamanuensis
    > Study Programme Leader - studieprogramleder
    > Music Technology Programme - Musikkteknologiseksjonen
    > Department of Music - Institutt for musikk
    > Olavskvartalet
    > NTNU (Norwegian University of Science and Technology)
    > 7491 Trondheim, NORWAY
    >  
    > Visiting address/besøksadresse: Fjordgt.1 (3.etg.)
    > e-mail: andreas.bergsland@ntnu.no
    > Office phone (Skype for business):7359 0096
    > Mobil: 4566 3316
    > http://folk.ntnu.no/andbe
    > https://www.vibra.no/
    > https://www.ntnu.edu/artec
    > Csound mailing list Csound@listserv.heanet.ie https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to https://github.com/csound/csound/issuesDiscussions of bugs and features can be posted here
    >  
    > Csound mailing list Csound@listserv.heanet.ie https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to https://github.com/csound/csound/issues Discussions of bugs and features can be posted here
    > Csound mailing list Csound@listserv.heanet.ie https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports tohttps://github.com/csound/csound/issues Discussions of bugs and features can be posted here
    
    
    Csound mailing list
    Csound@listserv.heanet.ie
    https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
    Send bugs reports to
            https://github.com/csound/csound/issues
    Discussions of bugs and features can be posted here
    


Csound mailing list
Csound@listserv.heanet.ie
https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
Send bugs reports to
        https://github.com/csound/csound/issues
Discussions of bugs and features can be posted here