[flocking-users] How to read in a file and play it?

Colin Clark colin at colinclark.org
Mon Feb 9 06:56:30 EST 2015


Hi Derek,

It doesn't look like your code is valid JavaScript. What happens if you try this instead?

var synth = flock.synth({
    synthDef: {
        ugen: "flock.ugen.scope",
        options: {
            canvas: "#gfx"
        },
        source: {
            id: "player",
            ugen: "flock.ugen.playBuffer",
            buffer: {
                id: "toPlay",                    // The sound file will be loaded into an environment buffer named "toPlay."
                url: "sounds/zap.wav" 
            },
            speed: 1.0,
            loop: 0.0
        }
    }
});


You'll notice I changed a few things. First, I'm assigning the synth to a variable called "synth" using an equal sign (the assignment operator). You were using a colon instead, which is only valid inside an object literal (i.e. for defining properties on an object).

Secondly, I added the "canvas" option to the scope unit generator so that its output is displayed in the Playground's #gfx container, which is the canvas up at the top right.

Thirdly, I changed your "buffer" definition to use the a "url" property instead of the "selector" property, since it looks like you were trying to load a sound file from a URL, rather than loading it via a file input element (which is what the "selector" property is for).

This example in the Playground might be helpful:

http://flockingjs.org/demos/interactive/html/playground.html#playBuffer <http://flockingjs.org/demos/interactive/html/playground.html#playBuffer>

I hope this helps,

Colin


> On Feb 7, 2015, at 5:06 AM, derek riemer <Derek.Riemer at Colorado.EDU> wrote:
> 
> Hi,
> I am reading in a file, and trying to play it. When I try to read it in like so I get this baffling syntax error in firefoxes console. 
> """
>     SyntaxError: An invalid or illegal string was specified
> flocking-all.js
> :22152:0
> """
> Any idea what would cause this?
> I am doing this for my synth. Is this the correct way to read in a file named zap.wav in ./sounds?
> Thanks,
> Derek
> 
> --code--
> synth:flock.synth({
>             synthDef:{
>                 ugen: "flock.ugen.scope",
>                 source: {
>                     id: "player",
>                     ugen: "flock.ugen.playBuffer",
>                     buffer: {
>                         id: "toPlay",                    // The sound file will be loaded into an environment buffer named "toPlay."
>                         selector: "sounds/zap.wav"  // The File object selected by the #fileBrowser input element will be read.
>                     },
>                     speed: 1.0,
>                     loop: 0.0
>                 },
>                 
>             }
>         })
> 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.idrc.ocad.ca/pipermail/flocking/attachments/20150209/209d7830/attachment.html>


More information about the flocking mailing list