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

iOS sometimes distorted #39

Closed mulhoon closed 9 years ago

mulhoon commented 9 years ago

Hi,

I've been working with wad on iOS 8 (phonegap/safari) loading small .m4a sounds, it's all good and wad is working well. Occasionally when I trigger many sounds it can start distorting. Do you have any tips for reducing memory? best file type, sample rate, poly volume, envelope usage?

I know this isn't stackoverflow, but wondered if you'd come across any tips that might be worth trying.

Thanks for the great work. n

rserota commented 9 years ago

I'm not sure which file types would be best, but if you're just playing small audio files, not songs, then I don't think the audio file format would be your biggest problem. I don't think you can even change the sample rate with web audio. Web audio just uses the sampling rate of your device's sound card. http://stackoverflow.com/questions/14387814/webaudio-api-sampling-rate I don't think the envelope or volume settings would have a large effect on performance. Are you using a lot of reverb? Reverb is probably the most expensive effect in wad.js, so you'll run out of memory fast if you use too much of it. Does your app do other things at the same time as playing the sounds? For example, if you're playing sound effects in a game when the player does some action, it's possible that the action is costing as much memory as the sound effects. When I build demos for wad.js, I tend to minimize the amount of animation I use to help the sound play smoothly on older devices. Are you using an older iPhone? I've heard a lot of people talk about getting bad performance when using an older iPhone with a newer version of iOS. Doesn't iOS have good profiling tools? You should be able to see if some objects are taking up more memory than you expected, or if some functions take a particularly long time to execute. Are you sure the issue is that you're running out of memory, and it's not a CPU issue?

That's all I can think of for right now. I hope that helps.

mulhoon commented 9 years ago

Hi Raphael,

Thanks so much for your response. Yes I don't think it's the file type, i'm using mp3 now.

I have a piano in my app that plays multiple short notes once (as a poly). I think the distortion is coming from the fact that these are layered to create a chord. The individual sounds don't clip on their own. On the iPhone 6 I can't really go above 50% volume or it will distort. I've tried making each note 0.33 volume (playing 3 sounds at once) but it's a little too quiet compared to other apps. I'm also thinking this might be to do with how much bass is playing. I've applied a hi-pass on each note to remove the bass, and made them mono and they don't distort as much.

Maybe if I place each note in a different stereo position I will get more volume. Or I thought I could use the poly compressor as a hard limiter to make sure the volume doesn't clip, but I wasn't sure how to achieve this.

Many thanks Nic

rserota commented 9 years ago

If you think the sound is clipping, then playing around with the compressor might be useful. I'm not exactly an expert on compression, but I think the default settings for the Wad.js compressor should be a good starting point.

rserota commented 9 years ago

I hope you can find some way to improve the performance on mobile. However, I don't think the problems you're experiencing are the result of a bug, so I'm going to close this issue. Feel free to reopen this issue if you can narrow down the problem to specific features that harm performance, or you have actionable ideas about improving the source code.

Either way, thanks for raising the issue.