rserota / wad

Web Audio DAW. Use the Web Audio API for dynamic sound synthesis. It's like jQuery for your ears.
MIT License
1.9k stars 160 forks source link

Apply effects on play, rather than on initialize? #30

Closed jescalan closed 9 years ago

jescalan commented 9 years ago

Just a quick question -- it doesn't appear as if there is a way to, but can you apply effects for mic recording when play is called, rather than when the mic is initialized? The use case for this is if you want to allow the user to choose a vocal effect without having to re-initialize/accept the mic usage thing each time.

If there isn't, could you potentially push me in the right direction for implementation? I'd be happy to pull request it in, but don't have a vast amount of experience with the web audio API.

rserota commented 9 years ago

It wasn't possible previously, but I just added that feature in. If you pull down fresh code, it should work how you want it to.

You can still set effects when the mic is initialized, but if you pass arguments to the play() method, then the previous effects will be discarded, and the effects from the play() arguments will be used instead. You should be able to change the effects as much as you want, but you will only need to give your browser access to your microphone once. I've updated the readme to reflect this change. Let me know if this fix doesn't meet your needs.

jescalan commented 9 years ago

Woah, this is amazing! Thanks so much @rserota -- this saved me hours of time. I owe you a :beer: no question. :sparkling_heart:

rserota commented 9 years ago

You're welcome! I'm glad this worked for you.

jescalan commented 9 years ago

So I just tested this out with code like this:

voice.play({
  reverb: {
    wet: 0.4,
    impulse: '/path/to/impulse.wav'
  }
});

and sadly it had no effect on the output, just sounds like normal. Passing the same thing to the constructer made a clear difference though. Am I doing something wrong in the way I'm passing the arguments or something? I dug into the code and made sure the constructReverb function was firing and it was...

jescalan commented 9 years ago

I also tried it with a delay effect, and got undefined is not a function throwing from this line :cry:

rserota commented 9 years ago

It was working when I tested it recently. Can you post more of your code? I'd like to see how you initialize all the objects, what order you call methods, etc.

It sounds like you stumbled on a bug, but I think I know what's going on here. I'll have some time to investigate this issue tonight.

jescalan commented 9 years ago

Sure, I can reproduce it with the following code:

var voice = new Wad({ source: 'mic' });

// for reverb (plays, but no effect)
voice.play({
  reverb: {
    wet: 0.4,
    impulse: '/path/to/impulse.wav'
  }
});

// for delay (errors out, does not play)
voice.play({
  delay: {
      delayTime: .5,
      wet: .25,
      feedback: .25,
  }
});
rserota commented 9 years ago

Both of those bugs should be fixed now. If you pull down the latest version of Wad.js, your code should work as you expect.

Let me know if you continue having trouble.

jescalan commented 9 years ago

Working perfectly now, thank you! :sparkles: :sparkling_heart: :sparkles: