A (175)

(Tuis.) #1
APPENDIX A: Audio Concepts, Terminology, and Codecs 663

The bottom line is that you need to be extremely smart in how you are doing things with SoundPool.
This is not as much about how you write your code (although that is certainly important), but more
about how you set up your audio samples so that they use less memory and can be leveraged
farther in your application.


A common mistake many Android developers make regarding SoundPool is trying to use it more like
a sequencer than as an audio synthesizer. Users focus on SoundPool’s ability to load multiple audio
file waveforms into memory, but do not leverage its processing capability for creating a myriad of
new waveforms, by using a few basic waveforms with SoundPool’s pitch-shift capability.


Here you are again, back to that same memory vs. processor trade-off that you invariably have in
the Android OS, regarding the use of almost all of these new media capabilities which Android offers.


If you use SoundPool as an audio sequencer, system memory can overload, and this can shut down
SoundPool’s functionality. Android developers must harness all of SoundPool features optimally, and
at the same time, they must optimize each of their digital audio samples as much as possible.


Here is a great example of this. SoundPool allows pitch-shifting across two full octaves, from a
setting of 0.5 (down one full octave, or half of your original sample waveform) up to 2.0 (or up one full
octave, or twice of your original waveform width). Remember that the waveform height equates to
amplitude, which is commonly referred to as volume.


Most users don’t use this pitch-shifting feature, but instead, use different samples to achieve
different notes. This fills up memory rapidly, and the end result is the app works less and less well
across older devices. The correct way to use SoundPool is to take your samples—say a one string
pluck from a guitar, one horn blow from a saxophone, one piano key strike, and three different
drum samples—and using only six short Mono 48kHz 16-bit high-quality samples, make a basic
synthesizer that has all four basic Jazz instruments.


Using this basic synthesizer set-up, your user could play instruments up and down two full octaves.
This application would use only a few hundred kilobytes of memory to hold these 16-bit 48kHz
uncompressed samples. If you used a high-quality microphone for your sampling process, you
would be amazed at the high-quality results that you can obtain these days using a 16-bit 48kHz
Mono sampling format. If you wanted to save memory, you could also use a Mono 16-bit 44.1kHz
CD-quality audio or Mono 16-bit 32kHz audio with similarly acceptable results.


I hope I have covered enough digital audio sampling and synthesis concepts in this appendix to give
you some insight as to how to optimize your digital audio assets for use with the SoundPool engine!

Free download pdf