Packing a lot of sound files into an application is one method of including audio. Another method is the runtime generation of sound data. We'll produce some simple sine tones in this recipe, which vary based upon detected touch pressure.
We will examine how to generate audio sample byte data based upon user touch pressure and feed this into a Sound
object to generate a variety of tones:
1. First, import the following classes into your project:
import flash.display.Sprite; import flash.display.StageAlign; import flash.display.StageScaleMode; import flash.events.SampleDataEvent; import flash.events.TouchEvent; import flash.media.Sound; import flash.media.SoundChannel; import flash.ui.Multitouch; import flash.ui.MultitouchInputMode; import flash.utils.ByteArray; import flash.text.TextField; import flash.text.TextFormat;
2. For this recipe, we must declare a number of different objects up front. We will begin with a sound object pair consisting...