NLayer 3.0.0
dotnet add package NLayer --version 3.0.0
NuGet\Install-Package NLayer -Version 3.0.0
<PackageReference Include="NLayer" Version="3.0.0" />
<PackageVersion Include="NLayer" Version="3.0.0" />
<PackageReference Include="NLayer" />
paket add NLayer --version 3.0.0
#r "nuget: NLayer, 3.0.0"
#:package NLayer@3.0.0
#addin nuget:?package=NLayer&version=3.0.0
#tool nuget:?package=NLayer&version=3.0.0
NLayer
NLayer is a fully managed, MIT-licensed MP3 to WAV decoder implemented in C# based on the MPEG specifications.
NLayer targets netstandard2.0 and net8.0, so it runs on .NET Framework 4.6.1+, .NET 8+, Unity, and Mono.
NLayer.NAudioSupport targets net9.0, because NAudio 3 does — see
Which NLayer.NAudioSupport version? below.
Usage
To use NLayer for decoding MP3, first reference NLayer.
using NLayer;
Then create an MpegFile, pass a file name or a stream to the constructor, and use ReadSamples for decoding the content:
// samples per second times channel count
const int samplesCount = 44100;
var fileName = "myMp3File.mp3";
var mpegFile = new MpegFile(filename);
float[] samples = new float[samplesCount];
int readCount = mpegFile.ReadSamples(samples, 0, samplesCount);
More information could be found in code documents.
Use with NAudio
NLayer is capable of using in conjunction with NAudio for file conversion and real-time playback.
You need to reference NAudio, NLayer and NLayer.NAudioSupport first.
using NAudio.Wave;
using NLayer.NAudioSupport;
Then create an Mp3FileReader, passing in a FrameDecompressorBuilder that uses the Mp3FrameDecompressor from NLayer.NAudioSupport:
var fileName = "myMp3File.mp3";
var builder = new Mp3FileReader.FrameDecompressorBuilder(wf => new Mp3FrameDecompressor(wf));
var reader = new Mp3FileReaderBase(fileName, builder);
// play or process the file, e.g.:
waveOut.Init(reader);
waveOut.Play();
Which NLayer.NAudioSupport version?
NAudio 3 dropped .NET Framework and netstandard2.0: NAudio.Core 3.x ships a
single net9.0 assembly. NLayer.NAudioSupport therefore comes in two lines,
and picking the wrong one is not a compile error — NuGet will happily unify
NAudio.Core up to 3.x behind the rest of an NAudio 2 install and fail at
runtime instead.
| NLayer.NAudioSupport | Targets | Works with |
|---|---|---|
| 3.x | net9.0 |
NAudio 3 |
| 2.x | netstandard2.0, net8.0 |
NAudio 2 |
If you are still on NAudio 2, or need .NET Framework / Unity / Mono, stay on
NLayer.NAudioSupport 2.x. The NLayer package itself is unaffected: it is
still netstandard2.0 and net8.0 on both lines, so the decoder remains
available everywhere it always was.
On 3.x, Mp3FrameDecompressor and ManagedMpegStream implement NAudio 3's
Span<byte> overloads directly, so decoding does not bounce through a pooled
byte[]. MpegFile and MpegFrameDecoder gained matching Span<T> overloads
for that; they are compiled into the net8.0 asset only, so the
netstandard2.0 build stays free of a System.Memory dependency.
Building
dotnet build NLayer.sln -c Release
dotnet test NLayer.sln -c Release
Every push and pull request is built and tested by the build GitHub Actions
workflow.
Assemblies are strong-named with NLayerStrongNameKey.snk (checked into the
repo root). Compiler warnings are treated as errors; the broader .NET
code-analysis (CA) analyzers are not enabled — turning them on surfaces ~110
mostly-mechanical style/perf suggestions that can be addressed incrementally.
Releasing
Versioning is centralised in Directory.Build.props (<VersionPrefix>) and
shared by both the NLayer and NLayer.NAudioSupport packages. Release notes
live in RELEASE_NOTES.md. Packages are published to NuGet by the release
workflow, which uses NuGet trusted publishing (OIDC) — no API key is stored in
the repository.
- Pre-release: run the
releaseworkflow manually (Actions → release → Run workflow) frommain. It publishes<VersionPrefix>-preview.<run>, or pass amilestonesuch asrc.1for<VersionPrefix>-rc.1. - Final release: bump
<VersionPrefix>, rename the### Unreleasedheading inRELEASE_NOTES.mdto### <version> (DD MMM YYYY), commit, then push a matchingv<version>tag (e.g.v2.0.0). The workflow packs, pushes to NuGet, and creates a GitHub Release.
See Docs/Releasing.md for the full step-by-step guide,
trusted-publishing setup, and troubleshooting.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. 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 is compatible. 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 was computed. 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 | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
| .NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
| MonoAndroid | monoandroid was computed. |
| MonoMac | monomac was computed. |
| MonoTouch | monotouch was computed. |
| Tizen | tizen40 was computed. tizen60 was computed. |
| Xamarin.iOS | xamarinios was computed. |
| Xamarin.Mac | xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- No dependencies.
-
net8.0
- No dependencies.
NuGet packages (15)
Showing the top 5 NuGet packages that depend on NLayer:
| Package | Downloads |
|---|---|
|
NLayer.NAudioSupport
NAudio support for NLayer |
|
|
SCPSL-AudioManagerAPI
Shared audio management system for SCP:SL plugins using LabAPI speakers with ID isolation and caching. |
|
|
HPD-Agent.Framework
A middleware-driven agentic AI framework built on Microsoft.Extensions.AI for building intelligent, tool-using agents. |
|
|
YellowDogMan.CSCoreFork
Fork of CSCore by filoe |
|
|
EggEncoder
Audio encoding/decoding toolkit for .NET — native MP3 (LAME) and FLAC codec bindings, managed AAC and WMA decode/encode, waveform generation, and audio probing/cutting, fully in-process. Built for high-throughput music distribution pipelines. |
GitHub repositories (6)
Showing the top 6 popular GitHub repositories that depend on NLayer:
| Repository | Stars |
|---|---|
|
ValveResourceFormat/ValveResourceFormat
Source 2 Viewer is an all-in-one tool to browse VPK archives, view, extract, and decompile Source 2 assets, including maps, models, materials, textures, sounds, and more.
|
|
|
Pyrdacor/Ambermoon.net
Ambermoon rewrite in C#
|
|
|
zhongkaifu/TensorSharp
A native .NET LLM inference engine for GGUF models. TensorSharp provides a console application, a web-based chatbot interface, and Ollama/OpenAI-compatible HTTP APIs for programmatic access. It supports Windows/MacOS/Linux with full GPU capability
|
|
|
leezer3/OpenBVE
OpenBVE- A free train simulator
|
|
|
Angel2mp3/AudioAuditor
A powerful, open-source toolkit for audio analysis and playback. Verify lossless quality, detect AI-generated tracks, and explore your library with a built-in hi-res player and advanced EQ.
|
|
|
bernatvadell/muonline
|
- **`NLayer.NAudioSupport` now targets NAudio 3** (`NAudio.Core` 3.0.1). NAudio 3
dropped .NET Framework and `netstandard2.0`, so this package is now `net9.0`
only. Consumers on NAudio 2, .NET Framework, Unity or Mono should stay on
`NLayer.NAudioSupport` 2.x — mixing 3.x with an NAudio 2 install resolves
`NAudio.Core` up to 3.x and fails at runtime rather than at compile time.
- `NLayer` itself is unchanged and still targets `netstandard2.0` and `net8.0`,
so the decoder remains available on every platform it already supported. The
major version bump only reflects the lockstep versioning of the two packages.
- `Mp3FrameDecompressor` and `ManagedMpegStream` now implement NAudio 3's
`Span<byte>` overloads (`IMp3FrameDecompressor.DecompressFrame` and
`Stream.Read`) directly. NAudio 3 calls the span overload for every frame, and
its default implementation rents a pooled `byte[]` and copies through it; that
round trip is now gone.
- `MpegFile.ReadSamples` and `MpegFrameDecoder.DecodeFrame` gained `Span<byte>`
and `Span<float>` overloads to support the above. They are compiled into the
`net8.0` asset only, so the `netstandard2.0` build keeps its dependency-free
package graph.
- Added tests covering the NAudio bridge (`Mp3FrameDecompressor`,
`ManagedMpegStream` and `Mp3FileReaderBase` end to end) against NAudio 3, and
tests pinning the span paths to byte-for-byte parity with the array ones.
- Fixed reading from a non-seekable stream, broken since 2.0.1. Such a stream has
no known sample count, which the end-of-stream trimming added in 2.0.1
represented as `long.MaxValue`; subtracting the read position from it and
truncating to `int` wrapped negative, so the very first read threw
`ArgumentOutOfRangeException`.