Extended functionality contribution offer

Feb 23, 2013 at 3:44 PM
Edited Feb 23, 2013 at 6: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:

http://www.sonicspot.com/guide/wavefiles.html
(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
    Console.WriteLine(myWavFile.SamplerChunk.MidiUnityNote)
    Console.WriteLine(myWavFile.SamplerChunk.SampleLoopCount)
    Dim I as Integer
    For I = 0 to myWavFile.SamplerChunk.SampleLoopCount - 1
        Console.WriteLine(myWavFile.SamplerChunk.SampleLoop(I).Start)
        Console.WriteLine(myWavFile.SamplerChunk.SampleLoop(I)._End)
    Next 
End If

B. SFZdotNet

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

http://www.cakewalk.com/DevXchange/article.aspx?aid=108

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:

http://www.linuxsampler.org/sfz/
(Windows binaries are available)

http://www.plogue.com/products/sforzando/

http://www.cakewalk.com/Download/sfz.aspx

http://www.camelaudio.com/AlchemyPlayer.php

http://www.zampler.de/


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.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
    Next
mysfz.Save(Environment.GetFolderPath(Environment.SpecialFolder.Desktop) & "\test.sfz")
Output file:

// This file was generated by a tool.
// Samples courtesy of http://www.freesound.org/people/canucklovingbrit/

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

Greg
Coordinator
Mar 2, 2013 at 8: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.

Mark