This project has moved and is read-only. For the latest updates, please go here.

Extended functionality contribution offer

Feb 23, 2013 at 4:44 PM
Edited Feb 23, 2013 at 7:26 PM
Hi Mark,

I have two small code classes (written in VB2010) whose functionality I would like to suggest to add to NAudio. These classes were developed to ease the process of creating DAW sampler plugin instruments.

A. SmplChunk

A simple wrapper for Sampler Chunk of a wav file as described in:
(refer to the Sampler Chunk - "smpl" section near the bottom of the page).

Of particular interest is the Midi Unity Note as well as the "List of Sample Loops":
  1. The MIDI Unity Note is a nice piece of metadata to have embedded in the file itself as opposed to relying on the filename to specify this info.
  2. If the sample loop points are defined in the wav file itself, files can be moved between DAW sampler formats without having to (externally) specify the loop points in the new sampler format.
Reading these parameters has been implemented; I have not completed the ability to update an existing WAV file with a missing smpl chunk or updated values.

Example usage:
Dim Filename As String = "c:\new_wloop.wav"
Dim myWavFile As New WavFile(Filename)
If myWavFile.SamplerChunk IsNot Nothing Then
    Dim I as Integer
    For I = 0 to myWavFile.SamplerChunk.SampleLoopCount - 1
End If

B. SFZdotNet

A simple wrapper around the sfz Sampler file format as described in:

SFZ is an open file format for samplers, currently evolving to a standard among many commercial samplers.
A partial list of samplers that support sfz:
(Windows binaries are available)

One application for this class is to programmatically generate sfz instrument files from a folder a wav files. At present, I've wrapped up ~25 of the most common Region parameters.

The class does not currently support reading/editing existing files; this is a bit more complicated primarily because the file can be organized in arbitrary order (groups, etc.); plus I didn't require this functionality at the time :)

Simple code example:
Dim mysfz As New SFZdotNET.sfz
mysfz.Comment.Add("This file was generated by a tool.")
mysfz.Comment.Add("Samples courtesy of")
mysfz.Group.Add(New SFZdotNET.Group)
mysfz.Group(0).loop_mode = SFZdotNET.Region.loop_mode_value.one_shot
Dim I As Integer
Dim myFiles() As String
myFiles = IO.Directory.GetFiles(Environment.GetFolderPath(Environment.SpecialFolder.Desktop) & "\Samples")
Dim StartingNoteNumber As Integer = 36
For Each aFile As String In myFiles
    mysfz.Group(0).Region.Add(New SFZdotNET.Region(IO.Path.GetFileName(aFile), I))
    I = I + 1
mysfz.Save(Environment.GetFolderPath(Environment.SpecialFolder.Desktop) & "\test.sfz")
Output file:

// This file was generated by a tool.
// Samples courtesy of

<group> loop_mode=one_shot
<region> sample=110641__canucklovingbrit__santa-ho-ho-ho-1_001.wav key=36
<region> sample=110641__canucklovingbrit__santa-ho-ho-ho-1_002.wav key=37
<region> sample=110641__canucklovingbrit__santa-ho-ho-ho-1_003.wav key=38
<region> sample=110641__canucklovingbrit__santa-ho-ho-ho-1_004.wav key=39
<region> sample=110641__canucklovingbrit__santa-ho-ho-ho-1_005.wav key=40

If you think either of these classes are a good addition to NAudio, please let me know.

Thanks again for NAudio.

Mar 2, 2013 at 9:24 AM
hi Greg, thanks for this. NAudio is in C#, so they would need to be converted. The sampChunk would be particularly nice if it could integrate with NAudio's existing WAV chunk support (convert from RiffChunk).

NAudio did include a sfz parser but I took it out because it wasn't fully featured. I'd probably just go with a demo app for sfz for now, and only move it into NAudio when both a reader and a writer are available.