G726Library 1.0.1

dotnet add package G726Library --version 1.0.1
                    
NuGet\Install-Package G726Library -Version 1.0.1
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="G726Library" Version="1.0.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="G726Library" Version="1.0.1" />
                    
Directory.Packages.props
<PackageReference Include="G726Library" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add G726Library --version 1.0.1
                    
#r "nuget: G726Library, 1.0.1"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package G726Library@1.0.1
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=G726Library&version=1.0.1
                    
Install as a Cake Addin
#tool nuget:?package=G726Library&version=1.0.1
                    
Install as a Cake Tool

Overview

G726Library is an ITU-T G.726 codec written in C#. It can take any input PCM, G.711A or G.711Mu sample and encode it into G.726 and vice versa. It also supports 16, 24, 32 and 40 Kbps modes.

Usage

Start by installing the G726Library NuGet package. Go to the Visual Studio NuGet Package Manager, search G726Library and install it. If you're using the .NET CLI, use dotnet add package G726Library.

Here are a few examples.

Encode G.726 samples from PCM (24Kbps)

using G726Library;

static void PcmToG726(short[] pcm, int[] g726)
{
	G726Codec codec = G726Codec.Create24Kbps();

	for (int i = 0; i < pcm.Length; i++)
	{
		g726[i] = codec.EncodeFromPcm(pcm[i]);
	}
}

Decode PCM samples from G.726 (24Kbps)

using G726Library;

static void G726toPcm(int[] g726, short[] pcm)
{
	G726Codec codec = G726Codec.Create24Kbps();

	for (int i = 0; i < g726.Length; i++)
	{
		pcm[i] = codec.DecodeToPcm(g726[i]);
	}
}

Decode G.711A samples from G.726 (24Kbps)

using G726Library;

static void G726toG711A(int[] g726, byte[] g711a)
{
	G726Codec codec = G726Codec.Create24Kbps();

	for (int i = 0; i < g726.Length; i++)
	{
		g711a[i] = (byte)codec.DecodeToG711A(g726[i]);
	}
}

Encode G.726 samples from G.711Mu (40Kbps)

using G726Library;

static void G711MuToG726(short[] g711, int[] g726)
{
	G726Codec codec = G726Codec.Create40Kbps();

	for (int i = 0; i < g711.Length; i++)
	{
		g726[i] = codec.EncodeFromG711Mu(g711[i]);
	}
}

Strengths

  • High compatibility. Any framework since .NET Framework 4.7.2 and .NET Core 2.1 is supported.
  • High performance. See Benchmarks below.
  • Permissive license (MIT), see LICENSE.txt. Free to use and open-source.
  • Simplicity. It is very easy to use.
  • Memory management. Unless we're talking overloads that return arrays of decoded/encoded samples, the codec performs no allocations at all.
  • Contributions are very welcome. You can ask questions, report bugs, or submit PRs.
  • Super lightweight. Only weighs around ~18KB.

Benchmarks

The following benchmarks demonstrate the codec performance of encoding 10 seconds of 40 Kbps audio into G.726, as well as decoding it back. This maps to about 80,000 unique samples.

BenchmarkDotNet v0.15.2, Windows 11 (10.0.22631.2861/23H2/2023Update/SunValley3)
13th Gen Intel Core i5-13420H 2.10GHz, 1 CPU, 12 logical and 8 physical cores
.NET SDK 11.0.100-preview.3.26207.106
  [Host]     : .NET 10.0.9 (10.0.926.27113), X64 RyuJIT AVX2
  DefaultJob : .NET 10.0.9 (10.0.926.27113), X64 RyuJIT AVX2
Method Mean Error StdDev
Encode10SecondsOfAudio40Kbps 3.799 ms 0.0129 ms 0.0114 ms
Decode10SecondsOfAudio40Kbps 3.167 ms 0.0066 ms 0.0058 ms

Doing some math, in 40 Kbps mode alone, you can:

  • Encode 43 minutes of audio per second
  • Decode 52 minutes of audio per second

This is well beyond the performance you'll have to hit for real-time communication.

Realistically, hitting those speeds may take some time due to the .NET JIT compiler having to jit all methods, but you can always compile against ReadyToRun (R2R) to make things several times faster.

Compatibility

The library supports:

  • .NET Framework 4.7.2 and later
  • .NET Core 2.1 and later

Licensing

The library is licensed under the MIT License, you can find details in the LICENSE.txt file. It is completely free to use.

Contributions

You are free to ask questions, submit bug reports, propose new features, or submit PRs to this repo and I will make sure to look into it.

Credits

I used some code from Sun Microsystems' implementation (which is in C) to write this library.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
.NET Core netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.1 is compatible. 
.NET Framework net472 is compatible.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .NETFramework 4.7.2

  • .NETStandard 2.1

    • No dependencies.
  • net10.0

    • No dependencies.
  • net6.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.1 91 7/13/2026
1.0.0 92 7/12/2026

Enabled documentation comments