Can't save my soundFile with P5.sound

Hi,

I play sounds and record the sum of these sounds using the P5.sound.js library but i can't save to .wav anymore.

If I create a standalone code it worked but when I put it in my main code wich also use THREE.js and FileSaver.js the "save" & "saveSound" functions from P5.sound don't work.

Playing and recording works fine. I can even play the recorded file but i can't save it.

I've tried to go around the problem but can't find a solution.

Are there interaction between the librarys ? Why can't I past my Soundfile into a blob to save using FileSaver.js?

Thank you

edit : can I use yet another library to record the sound in the window ?

Answers

  • Answer ✓

    Are there interaction between the librarys ?

    Make sure you use p5 in instance mode to avoid any such interactions. p5js pollutes the global scope heavily and this is unlikely to play well with other libraries. Also check the browser console (F12) for any error messages that will give you a clue to what's going wrong...

  • edited June 2016

    p5js pollutes the global scope heavily and this is unlikely to play well with other libraries.

    It's true that p5js can "taint" the global scope and that's "frowned" upon. :-w
    But that isn't the source of any bugs, even when interacting w/ other libraries. @-)

    I've already explained that issue other few times and gonna repeat it here again:
    As long as only 1 library "pollutes" the global scope, that's completely "safe"! =P~
    Only when more than 1 library decides to do the same that API name crashing may occur. :-\"

    In short, assuming both "three.js" & "filesaver.js" libs behave, "p5js.js" is "allowed" to be "naughty"! >:)

  • Thank you.

    The instance mode worked. I was planning to rewrite some of my code. But I tried something and it worked. I juste wrote :

    var myP5;
    var sketch = function (p) {
    myP5 = p;};
    new p5(sketch);
    

    At the beginning of my project and used myP5.save(soundfile,"name.wav"); instead of juste save(soundfile,"name.wav"); and it worked !

    Can I use that technique to just use a few P5.js functions or should I rewrite some part in my p5 sketch ?

  • @belgicanos I'm amused instance mode solved your problem; despite @GoToLoop's skepticism. He is right though; to some extent: if other libraries protect their scope they should work alongside p5 in global mode; but IMO that's a rather facile answer to a complex problem. It's simply safer to run p5 in instance mode where it's sandboxed and less likely to cause unexpected interactions...

    Note that the other advantage is that your global variable names won't clash with p5 globals. It also allows you to create a global reference to your p5 instance which you can then call from outside your sketch code (the alternative is to pass references around as function parameters). Both of these may explain why instance mode worked for you...

Sign In or Register to comment.