如何增加16位PCM音频流的音量?

时间:2020-11-09 15:14:51

标签: voip rtp pcm

将PCM字节流转换为RTP之后,SIP客户端的音量很小,但在其他客户端(例如WebRTC,基于多播的设备以及媒体文件)中可以正常工作。有什么办法可以增加16位PCM字节流的容量?请检查我下面的代码示例:

var mulawData = Utils.LinearToMulaw(pcm, 16, 1);  //pcm=320 byte array


public static Byte[] LinearToMulaw(Byte[] bytes, int bitsPerSample, int channels)
{
    int blockAlign = channels * bitsPerSample / 8;

    Byte[] result = new Byte[bytes.Length / blockAlign];
    int resultIndex = 0;
    for (int i = 0; i < result.Length; i++)
    {
        switch (bitsPerSample)
        {
            case 8:
                switch (channels)
                {
                    //8 Bit 1 Channel
                    case 1:
                        result[i] = linear2ulaw(bytes[resultIndex]);
                        resultIndex += 1;
                        break;

                    //8 Bit 2 Channel
                    case 2:
                        result[i] = linear2ulaw(bytes[resultIndex]);
                        resultIndex += 2;
                        break;
                }
                break;

            case 16:
                switch (channels)
                {
                    //16 Bit 1 Channel
                    case 1:
                        result[i] = linear2ulaw(BitConverter.ToInt16(bytes, resultIndex));
                        resultIndex += 2;
                        break;

                    //16 Bit 2 Channels
                    case 2:
                        result[i] = linear2ulaw(BitConverter.ToInt16(bytes, resultIndex));
                        resultIndex += 4;
                        break;
                }
                break;
        }
    }

    return result;
}

0 个答案:

没有答案