Đang chuẩn bị liên kết để tải về tài liệu:
Học Actionscript 3.0 - p 35
Đang chuẩn bị nút TẢI XUỐNG, xin hãy chờ
Tải xuống
Visualizing Sound Data The Waveform class The first dozen or so lines of the Waveform class will be familiar to you if you’ve been reading this book linearly. Line 1 declares the class’s package path as this class is part of the learningactionscript3 code library developed throughout this book. Lines 3 through 7 import all the other classes required by this class. Line 9 declares the class and extends Sprite so it can inherit all accessible properties, methods, and events from the Sprite class. As discussed extensively in Chapter 6, this is important for things like being able to access properties like. | Visualizing Sound Data The Waveform class The first dozen or so lines of the Waveform class will be familiar to you if you ve been reading this book linearly. Line 1 declares the class s package path as this class is part of the learningactionscript3 code library developed throughout this book. Lines 3 through 7 import all the other classes required by this class. Line 9 declares the class and extends Sprite so it can inherit all accessible properties methods and events from the Sprite class. As discussed extensively in Chapter 6 this is important for things like being able to access properties like graphics use event listeners and add instances of this class to the display list. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 package com.learningactionscript3.sound import flash.display.Graphics import flash.display.Sprite import flash.events.Event import flash.media.SoundMixer import flash.utils.ByteArray public class Waveform extends Sprite private var _bytes ByteArray new ByteArray private var _fft Boolean private var _g Graphics public function Waveform fft Boolean false _fft fft _g this.graphics this.addEventListener Event.ENTER_FRAME onVisualize false 0 true private function onVisualize evt Event void SoundMixer.computeSpectrum _bytes _fft _g.clear plotWaveform 0x009900 50 plotWaveform 0xFF0000 100 private function plotWaveform col uint chanBaseline Number void _g.lineStyle 1 col _g.beginFill col 0.5 _g.moveTo 0 chanBaseline for var i Number 0 i 256 i _g.lineTo i chanBaseline -_bytes.readFloat 50 _g.lineTo i chanBaseline _g.endFill Chapter 11 Sound 319 Download from Wow eBook www.wowebook.com Visualizing Sound Data NOTE Using two loops of 256 values rather than 1 loop of 512 values makes it easier for us to draw the left and right channels separately. For example because the loop counter i ranges from 0 to 255 we can use it as an x coordinate for each point of our waves. If we used a .