Closed GoogleCodeExporter closed 9 years ago
I haven't tested multiple files yet, trying to play a WAV file that was
encoded, mono, 22050Hz, 16 bit also plays too fast irrespective of
AudioSetting. Basically I suspect the play method isn't working correctly for
source data other than 44.1KHz.
I worked around this by limiting use of as3wavsound to decoding the WAV and
using wavePlayback.extract to pull the samples into my own byte array. Then set
up my sound channel as normal using that extracted byte array.
Note: wavePlayback.extract is currently marked "No idea if this works. Alpha
state.", but for me is working better than wavePlayback.play :)
Original comment by crea...@gmail.com
on 21 Feb 2012 at 4:42
Ran into the same issue. Might you be able to provide some code for your work
around? Much appreciated!
Original comment by laurence...@gmail.com
on 27 Mar 2012 at 5:04
These are snippets of code plucked out of my test. My class has the following
properties:
protected var waveLoader :URLLoader = new URLLoader();
protected var wavePlayback :WavSound;
protected var decodedWavBytes :ByteArray = new ByteArray;
I use the loader to pull in the .wav file then the completion handler looks
something like this...
protected function handleWaveLoaded(event:Event):void
{
// BRING THE DATA INTO OUR WAVSOUND OBJECT
var aSetting:AudioSetting = new AudioSetting( 1, 22050, 16 ); // KNOWN SOURCE SETTINGS
wavePlayback = new WavSound( waveLoader.data, aSetting );
//CLEAR DOWN EXISTING BYTES OR NEW ONES WILL BE APPENDED
decodedWavBytes.clear();
//DECODE THE WAV
var samples:Number = wavePlayback.extract( decodedWavBytes, waveLoader.bytesLoaded );
}
Once that's done, playing the decodedWavBytes looks like this...
protected function playbackDecodeSamples(event:SampleDataEvent):void
{
for( var i:int = 0; i < 8192 && decodedWavBytes.bytesAvailable > 0; i++ )
{
var sample:Number = decodedWavBytes.readFloat();
event.data.writeFloat( sample );
event.data.writeFloat( sample );
}
}
The above worked for me, unless I've mangled it in extracting the relevant
bits. Good luck.
Original comment by crea...@gmail.com
on 27 Mar 2012 at 8:03
oh and playbackDecodeSamples is called via the sound channel's event handler...
private function playLoadedWaveFile():void
{
decodedWavBytes.position = 0;
var sound : Sound = new Sound;
var channel : SoundChannel;
sound.addEventListener(
SampleDataEvent.SAMPLE_DATA,
playbackDecodeSamples );
channel = sound.play();
channel.addEventListener(
Event.SOUND_COMPLETE,
playBackComplete );
}
Original comment by crea...@gmail.com
on 27 Mar 2012 at 8:07
Thanks! Will give it a whirl.
Original comment by laurence...@gmail.com
on 12 Apr 2012 at 3:52
Unfortunately still no luck. Audio is saved fine, plays back OK in windows
media player but playback is sped up in flash. Changing aSetting to various
sample rates has no effect. Thoughts?
thanks again in advance.
Original comment by laurence...@gmail.com
on 12 Apr 2012 at 5:03
That you are changing aSetting without effect makes me think you might be
playing back the source rather than the extract? Double-check that you are
playing bytes from decodedWavBytes rather than from your source recording or
from waveLoader.data.
Original comment by crea...@gmail.com
on 12 Apr 2012 at 5:21
agh, this is killing me! my code below, from inside loader complete listener.
Attached audio file.
///
var wavePlayback :WavSound;
var decodedWavBytes :ByteArray = new ByteArray;
var aSetting:AudioSetting = new AudioSetting( 1, 11025, 16 ); // KNOWN SOURCE
SETTINGS
wavePlayback = new WavSound( e.target.data, aSetting );
decodedWavBytes.clear();
var samples:Number = wavePlayback.extract( decodedWavBytes,
e.target.data.length );
decodedWavBytes.position = 0;
var sound : Sound = new Sound;
var channel : SoundChannel;
sound.addEventListener(SampleDataEvent.SAMPLE_DATA, playbackDecodeSamples );
channel = sound.play();
function playbackDecodeSamples(event:SampleDataEvent):void{
for( var i:int = 0; i < 8192 && decodedWavBytes.bytesAvailable > 0; i++ )
{
var sample:Number = decodedWavBytes.readFloat();
event.data.writeFloat( sample );
event.data.writeFloat( sample );
}
}
Original comment by laurence...@gmail.com
on 12 Apr 2012 at 5:54
Attachments:
I concur that your file is mono, 11KHz 16bit. I also hear the problem using my
own code. I guess extract isn't working as i expected. I have a rough
workaround for you...
Extract has decoded the samples from the wav, but hasn't done any
transformation to our required playback target or 44KHz Stereo. If you crudely
change playbackDecodeSamples as follows, you will solve your speed problem, but
the audio will sound metallic - inherent in the sample rate you are using.
There is nothing performing any smoothing of the sound wave...
function playbackDecodeSamples(event:SampleDataEvent):void{
for( var i:int = 0; i < 4096 && decodedWavBytes.bytesAvailable > 0; i++ )
{
var sample:Number = decodedWavBytes.readFloat();
event.data.writeFloat( sample );
event.data.writeFloat( sample );
event.data.writeFloat( sample );
event.data.writeFloat( sample );
}
}
Original comment by crea...@gmail.com
on 12 Apr 2012 at 8:38
Thanks, should be an OK fix for the time being.
Original comment by laurence...@gmail.com
on 16 Apr 2012 at 1:59
Hey guys, sorry for my absence.
The problem is that as3wavsound doesn't do up- or down sampling and plays
everything at 44khz. So unless your sound is recorded or converted to 44khz,
the sound won't play correctly. I never got around to implement the math
related to sampling sound data. If you have suggestions, please tell.
Currently, I'm unable to fix this.
Original comment by b.bottema
on 14 Aug 2012 at 1:38
It seems issue 7 (of which this is actually a duplicate report) is closing in
on an acceptable solution. Please take a look!
http://code.google.com/p/as3wavsound/issues/detail?id=7
Original comment by b.bottema
on 14 Aug 2012 at 1:57
Original issue reported on code.google.com by
garretdw...@gmail.com
on 19 Jan 2012 at 6:27Attachments: