/flash/flash-audio/src/com/ryanberdeen/audio/SoundSampleSource.as
ActionScript | 43 lines | 28 code | 6 blank | 9 comment | 2 complexity | 9d3e07a746767f99247e1dc8b127e393 MD5 | raw file
1/* 2 * Copyright 2009 Ryan Berdeen. All rights reserved. 3 * Distributed under the terms of the MIT License. 4 * See accompanying file LICENSE.txt 5 */ 6 7package com.ryanberdeen.audio { 8 import flash.media.Sound; 9 import flash.utils.ByteArray; 10 11 /** 12 * <code>ISampleSource</code> that provides samples unaltered from a 13 * <code>Sound</code>. 14 */ 15 public class SoundSampleSource implements ISampleSource { 16 private var sound:Sound; 17 private var startPosition:Number; 18 private var _length:Number; 19 20 public function SoundSampleSource(sound:Sound):void { 21 this.sound = sound; 22 startPosition = 0; 23 _length = Math.ceil(sound.length * 44.1); 24 } 25 26 public function extract(target:ByteArray, length:Number, startPosition:Number = -1):Number { 27 if (startPosition == -1) { 28 startPosition = this.startPosition; 29 } 30 var result:Number = sound.extract(target, length, startPosition); 31 this.startPosition = startPosition + length; 32 return result; 33 } 34 35 public function toSourcePosition(position:Number):Number { 36 return position; 37 } 38 39 public function get length():Number { 40 return _length; 41 } 42 } 43}