naudio / NAudio

Audio and MIDI library for .NET
MIT License
5.38k stars 1.09k forks source link

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

Open royranadeep opened 11 months ago

royranadeep commented 11 months ago

### 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.

markheath commented 11 months ago

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.