sevengo8378 / as3wavsound

Automatically exported from code.google.com/p/as3wavsound
Other
0 stars 0 forks source link

Incorrect playback of 11025Hz audio. #11

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
The attached WAV file (the Devanagari letter "ka" with a horrible goraa accent) 
plays fine in VLC Media Player. With AWS, it makes me sound like a 
chipmunk---if chipmunks spoke Hindi.

Here's the code I'm using in ActionScript3 in an SWF on IE9 on Windows 7 
Professional 64-bit:

    var urlRequest:URLRequest = new URLRequest(soundURI);
    var wav:URLLoader = new URLLoader();
    wav.dataFormat = "binary";
    wav.addEventListener(Event.COMPLETE, playWAV);
    wav.load(urlRequest);  

...

private final function playWAV(e:Event):void
{  
    var tts:WavSound = new WavSound(e.target.data as ByteArray);  
    tts.play();
}   

Original issue reported on code.google.com by garretdw...@gmail.com on 19 Jan 2012 at 6:27

Attachments:

GoogleCodeExporter commented 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

GoogleCodeExporter commented 9 years ago
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

GoogleCodeExporter commented 9 years ago
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

GoogleCodeExporter commented 9 years ago
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

GoogleCodeExporter commented 9 years ago
Thanks! Will give it a whirl.

Original comment by laurence...@gmail.com on 12 Apr 2012 at 3:52

GoogleCodeExporter commented 9 years ago
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

GoogleCodeExporter commented 9 years ago
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

GoogleCodeExporter commented 9 years ago
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:

GoogleCodeExporter commented 9 years ago
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

GoogleCodeExporter commented 9 years ago
Thanks, should be an OK fix for the time being.

Original comment by laurence...@gmail.com on 16 Apr 2012 at 1:59

GoogleCodeExporter commented 9 years ago
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

GoogleCodeExporter commented 9 years ago
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