Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect playback of 11025Hz audio. #11

Closed
GoogleCodeExporter opened this issue Apr 17, 2015 · 12 comments
Closed

Incorrect playback of 11025Hz audio. #11

GoogleCodeExporter opened this issue Apr 17, 2015 · 12 comments

Comments

@GoogleCodeExporter
Copy link

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
Copy link
Author

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
Copy link
Author

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
Copy link
Author

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
Copy link
Author

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
Copy link
Author

Thanks! Will give it a whirl.

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

@GoogleCodeExporter
Copy link
Author

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
Copy link
Author

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
Copy link
Author

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
Copy link
Author

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
Copy link
Author

Thanks, should be an OK fix for the time being.

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

@GoogleCodeExporter
Copy link
Author

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

  • Changed state: Accepted
  • Added labels: Priority-High, Usability
  • Removed labels: Priority-Medium

@GoogleCodeExporter
Copy link
Author

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

  • Changed state: Duplicate

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant