bartolsthoorn / NVDSP

iOS/OSX DSP for audio (with Novocaine)
MIT License
413 stars 80 forks source link

Blending Two Audio Samples #6

Closed neox38 closed 10 years ago

neox38 commented 10 years ago

Ok so lets say I had two samples like a cat meowing and a dark barking. Would there be a way to use NVDSP to blend the two so I could have 20% of the cat sound and 80% of the dog sound?

bartolsthoorn commented 10 years ago

Just use the overall gain with 0.8 and 0.2 for 80% and 20% respectively. Then play them both at the same time. The audio buffer is just an array of floats, so you could also loop or find a vDSP (in the apple docs) to add the floats. So if cat = [a1, a2, a3] and dog = [b1, b2, b3] then result = [a1+b1, a2+b2, a3+a3]. But if you play the samples at the same time (which is like sending them to the master track) the underlying audio engine will do this for you.