10.1. Composing Sounds Through AdditionCreating sounds digitally that didn't exist previously is lots of fun. Rather than simply moving around samples or multiplying them, we actually change their valuesadd waves together. The result are sounds that never existed until you made them. In physics, adding sounds involves issues of canceling waves out and enforcing other factors. In math, it's about matrices. In computer science, it's the easiest process in the world! Let's say that you've got a sound, source, that you want to add in to the current Sound object. Simply add the values at the same index numbers! That's it! // loop through all of the source for (int i = 0; i < source.getLength(); i++) { // add source sound value and this sound value value = this.getSampleValueAt(i) + source.getSampleValueAt(i); // set the value in this sound to the new value this.setSampleValueAt(i,value); } |