コード例 #1
0
        /// <summary>
        /// Encodes the given sample data.
        /// </summary>
        /// <param name="inData">Array of samples.</param>
        /// <param name="inOffset">Start offset for the inData.</param>
        /// <param name="inCount">Number of samples to encode. Must be a multiple of <see cref="FrameSize"/>.</param>
        /// <param name="outData">The encoded data.</param>
        /// <param name="outOffset">Start offset when writing to outData</param>
        /// <param name="outCount">The length of the outData array (maximum number of bytes writting after encoding).</param>
        /// <returns>The bytes encoded.</returns>
        public int Encode(short[] inData, int inOffset, int inCount, byte[] outData, int outOffset, int outCount)
        {
            bits.Reset();
            int samplesProcessed = 0;
            int result           = 0;

            while (samplesProcessed < inCount)
            {
                // convert shorts into float samples,
                for (int i = 0; i < frameSize; i++)
                {
                    rawData[i] = inData[inOffset + i + samplesProcessed];
                }

                result           += encoder.Encode(bits, rawData);
                samplesProcessed += frameSize;
            }

            if (result == 0)
            {
                return(0);
            }

            return(bits.Write(outData, outOffset, outCount));
        }