Created
January 31, 2010 21:05
-
-
Save also/291245 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Index: main/src/com/noteflight/standingwave2/output/AudioSampleHandler.as | |
=================================================================== | |
--- main/src/com/noteflight/standingwave2/output/AudioSampleHandler.as (revision 25) | |
+++ main/src/com/noteflight/standingwave2/output/AudioSampleHandler.as (working copy) | |
@@ -115,6 +115,7 @@ | |
var endFrame:Number; | |
var sample:Sample; | |
var length:Number; | |
+ var sampleLength:Number; | |
var chan0:Vector.<Number>; | |
var chan1:Vector.<Number>; | |
@@ -144,12 +145,13 @@ | |
} | |
sample = _source.getSample(length); | |
+ sampleLength = sample.frameCount; | |
switch (sample.descriptor.channels) | |
{ | |
case AudioDescriptor.CHANNELS_MONO: | |
chan0 = sample.channelData[0]; | |
- for (i = 0; i < length; i++) | |
+ for (i = 0; i < sampleLength; i++) | |
{ | |
e.data.writeFloat(chan0[i] * gainFactor); | |
e.data.writeFloat(chan0[i] * gainFactor); | |
@@ -159,7 +161,7 @@ | |
case AudioDescriptor.CHANNELS_STEREO: | |
chan0 = sample.channelData[0]; | |
chan1 = sample.channelData[1]; | |
- for (i = 0; i < length; i++) | |
+ for (i = 0; i < sampleLength; i++) | |
{ | |
e.data.writeFloat(chan0[i] * gainFactor); | |
e.data.writeFloat(chan1[i] * gainFactor); | |
@@ -178,12 +180,13 @@ | |
var halfLength:Number = length >> 1; | |
sample = _source.getSample(halfLength); | |
+ sampleLength = sample.frameCount; | |
var signal:Number; | |
switch (sample.descriptor.channels) | |
{ | |
case AudioDescriptor.CHANNELS_MONO: | |
chan0 = sample.channelData[0]; | |
- for (i = 0; i < halfLength ; i++) | |
+ for (i = 0; i < sampleLength ; i++) | |
{ | |
signal = chan0[i] * gainFactor; | |
e.data.writeFloat(signal); | |
@@ -191,7 +194,7 @@ | |
e.data.writeFloat(signal); | |
e.data.writeFloat(signal); | |
} | |
- if ((length & 1) == 1) | |
+ if ((sampleLength & 1) == 1) | |
{ | |
signal = chan0[length-1] * gainFactor; | |
e.data.writeFloat(signal); | |
@@ -202,7 +205,7 @@ | |
case AudioDescriptor.CHANNELS_STEREO: | |
chan0 = sample.channelData[0]; | |
chan1 = sample.channelData[1]; | |
- for (i = 0; i < halfLength ; i++) | |
+ for (i = 0; i < sampleLength ; i++) | |
{ | |
signal = chan0[i] * gainFactor; | |
e.data.writeFloat(chan0[i] * gainFactor); | |
@@ -210,10 +213,10 @@ | |
e.data.writeFloat(chan0[i] * gainFactor); | |
e.data.writeFloat(chan1[i] * gainFactor); | |
} | |
- if ((length & 1) == 1) | |
+ if ((sampleLength & 1) == 1) | |
{ | |
- e.data.writeFloat(chan0[length-1] * gainFactor); | |
- e.data.writeFloat(chan1[length-1] * gainFactor); | |
+ e.data.writeFloat(chan0[sampleLength-1] * gainFactor); | |
+ e.data.writeFloat(chan1[sampleLength-1] * gainFactor); | |
} | |
break; | |
} | |
@@ -227,7 +230,7 @@ | |
_sourceStarted = false; | |
dispatchEvent(new Event(Event.COMPLETE)); | |
} | |
- else if (length > 0 && length < framesPerCallback) | |
+ else if (length > 0 && sampleLength < framesPerCallback) | |
{ | |
// Fill out remainder of sample block source could not supply all frames. | |
for (i = length; i < framesPerCallback; i++) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment