Feb 23, 2013 at 3:44 PM
Edited Feb 23, 2013 at 6:26 PM
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 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":
- 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.
- 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.
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
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 http://www.freesound.org/people/canucklovingbrit/")
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")
// This file was generated by a tool.
// Samples courtesy of
<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.