Beispiel #1
0
 public static void generateMixPCMData(short[] mixPCMData, int mixDataCount, short channelCount, byte[] dataBuffer, int bufferSize)
 {
     // 如果单声道,则直接将mDataBuffer的数据拷贝到mMixPCMData中
     if (channelCount == 1)
     {
         for (int i = 0; i < mixDataCount; ++i)
         {
             byte[] byteData0 = new byte[2];
             byteData0[0]  = (byte)dataBuffer[2 * i + 0];
             byteData0[1]  = (byte)dataBuffer[2 * i + 1];
             mixPCMData[i] = BinaryUtility.bytesToShort(byteData0);
         }
     }
     // 如果有两个声道,则将左右两个声道的平均值赋值到mMixPCMData中
     else if (channelCount == 2)
     {
         for (int i = 0; i < mixDataCount; ++i)
         {
             byte[] byteData0 = new byte[2];
             byteData0[0] = (byte)dataBuffer[4 * i + 0];
             byteData0[1] = (byte)dataBuffer[4 * i + 1];
             short  shortData0 = BinaryUtility.bytesToShort(byteData0);
             byte[] byteData1  = new byte[2];
             byteData1[0] = (byte)dataBuffer[4 * i + 2];
             byteData1[1] = (byte)dataBuffer[4 * i + 3];
             short shortData1 = BinaryUtility.bytesToShort(byteData1);
             mixPCMData[i] = (short)((shortData0 + shortData1) * 0.5f);
         }
     }
 }
Beispiel #2
0
    public void read(ref short value)
    {
        int readLen = sizeof(short);

        if (!readCheck(readLen))
        {
            return;
        }
        byte[] dest = BinaryUtility.toBytes(value);
        BinaryUtility.memcpy(dest, mBuffer, 0, mIndex, readLen);
        value   = BinaryUtility.bytesToShort(dest);
        mIndex += readLen;
    }