NAudio icon indicating copy to clipboard operation
NAudio copied to clipboard

Conversion of G722 Audio codec to PCM resulted in noise in the channel and audio quality degrade.

Open royranadeep opened this issue 2 years ago • 1 comments

### We have used the following block of code to convert the G722 data to PCM format :

public static byte[] DecodeG722(byte[] g722Data, int bitRate)
        {
            var codec = new G722Codec();
            var state = new G722CodecState(bitRate, G722Flags.SampleRate8000);
            var decodedLength = g722Data.Length * 2;
            var outputBuffer = new byte[decodedLength];
            var wb = new WaveBuffer(outputBuffer);
            var length = codec.Decode(state, wb.ShortBuffer, g722Data, g722Data.Length) * 2;

            if (length != outputBuffer.Length)
            {
                var outputBuffer2 = new byte[length];
                Buffer.BlockCopy(outputBuffer, 0, outputBuffer2, 0, length);
                outputBuffer = outputBuffer2;
            }

            return outputBuffer;
        }

audioCodecBitrate: 64000 sampleRate: 8000 channels: 1 bitRate: 16 packetizationTime: 20

Could you help us how to go about reducing noise and raise the quality of the audio.

royranadeep avatar Jul 19 '23 15:07 royranadeep

I suggest that you create only one codec and codec state object and pass each encrypted block in, rather than creating a new instance of each every block you receive.

markheath avatar Jul 28 '23 20:07 markheath