Properly trimming PCM data from a ByteArray

Posted by Lowgain on Stack Overflow See other posts from Stack Overflow or by Lowgain
Published on 2010-05-31T18:12:06Z Indexed on 2010/05/31 18:13 UTC
Read the original article Hit count: 301

Filed under:
|
|

I have a situation where I need to trim a small amount of audio from the beginning of a recorded clip (generally somewhere between 110-150ms, it is an inconsistent amount).

I'm recording in 44100 frequency and 16 bitrate. This is the code I'm using:

public function get trimmedData():ByteArray {
        var ba:ByteArray = new ByteArray();
        var bitPosition:uint = 44100 * 16 * (recordGap / 1000);
        bitPosition -= int(bitPosition % 16); //should keep snapped to nearest sample, I hope
        ba.writeBytes(_rawData, (bitPosition / 8));
        return ba;
    }

This seems to work time-wise, but all the recorded audio gets staticy and gross. Is something off about my rounding? This is the first time I've needed to alter raw PCM data so I'm not sure about the finer details of it.

Thanks!

© Stack Overflow or respective owner

Related posts about bytearray

Related posts about as3