alejandrovelozb / wami-recorder

Automatically exported from code.google.com/p/wami-recorder
0 stars 0 forks source link

Trying to understand why I can't play 8kHz recording #19

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
I need to be able to save and play, but I need 8kHz recording for the save. I 
could transcode it on the fly, but thought I'd dig in and try to understand why 
the player cannot play 8kHz recordings?

Any thoughts?

Original issue reported on code.google.com by b...@smartots.com on 4 May 2012 at 9:35

GoogleCodeExporter commented 8 years ago
Because Flash only plays 44.1kHz.  So we can only easily resample divisors 
thereof.

Original comment by mcgrawian@gmail.com on 8 May 2012 at 11:30

GoogleCodeExporter commented 8 years ago

Original comment by mcgrawian@gmail.com on 8 May 2012 at 11:30

GoogleCodeExporter commented 8 years ago
Got it - maybe there's a way to play the audio from memory, but save as 8kHz 
file?

Original comment by b...@smartots.com on 10 May 2012 at 12:48

GoogleCodeExporter commented 8 years ago
If you find a way, let us know, but as far as I know you can only set the 
sample rate in one place, so you're stuck resampling either way.

Original comment by mcgrawian@gmail.com on 10 May 2012 at 1:39

GoogleCodeExporter commented 8 years ago
You can replace the decode() function in DecodePipe.as with the following:

        private function decode(bytes:ByteArray):ByteArray
        {
            var decoded:ByteArray = new ByteArray();
            var destTime:Number = 0;
            var destIncrement:Number = format.rate/44100.0;
            var sourceTime:Number = 0;

            while (bytes.bytesAvailable)
            {
                var sample1:Number = getSample(bytes);
                var sample2:Number = sample1;
                if (format.channels == 2)
                {
                    sample2 = getSample(bytes);
                }
                sourceTime += 1;

                while(destTime<sourceTime) {
                    destTime += destIncrement;
                    decoded.writeFloat(sample1);
                    decoded.writeFloat(sample2);
                }
            }

            decoded.position = 0;
            return decoded;
        }

this provides a simple resampler that will work with any sample rate.

Original comment by il.demon...@gmail.com on 4 Dec 2012 at 10:28

GoogleCodeExporter commented 8 years ago
Is the above code working in 8K sampled file? My case didn't work. Help!

Original comment by jha...@gmail.com on 2 Oct 2013 at 1:21