Exemplo n.º 1
0
        private static byte[] EncodeALAC(byte[] buffer)
        {
            // Frame size is set as 4096 samples, stereo
            //BitBuffer bitbuf = new BitBuffer((4096 * 2 * 2) + 3);
            BitBuffer bitbuf = new BitBuffer((BufferSize) + 3);

            bitbuf.WriteBits(1, 3);  // channels -- 0 mono, 1 stereo
            bitbuf.WriteBits(0, 4);  // unknown
            bitbuf.WriteBits(0, 12); // unknown
            bitbuf.WriteBits(0, 1);  // 'has size' flag
            bitbuf.WriteBits(0, 2);  // unknown
            bitbuf.WriteBits(1, 1);  // 'no compression' flag

            for (int i = 0; i < buffer.Length; i += 2)
            {
                // endian swap 16 bit samples
                bitbuf.WriteBits(buffer[i + 1], 8);
                bitbuf.WriteBits(buffer[i], 8);
            }

            return bitbuf.Buffer;
        }