Move .NET code into dotnet/

This commit is contained in:
Chris Cannam
2021-02-10 13:47:14 +00:00
parent cfb4bd6b4f
commit 2b06851c75
14 changed files with 41 additions and 0 deletions

View File

@@ -0,0 +1,81 @@
<#
rubberband-sharp
A consumer of the rubberband DLL that wraps the RubberBandStretcher
object exposed by the DLL in a managed .NET type.
Copyright 2018-2019 Jonathan Gilbert
Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use, copy,
modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR
ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Except as contained in this notice, the name of Jonathan Gilbert
shall not be used in advertising or otherwise to promote the sale,
use or other dealings in this Software without prior written
authorization.
#>
Param
(
$InstallPath,
$ToolsPath,
$Package,
$Project
)
# Save current project state.
$Project.Save()
# Load project XML.
$ProjectFullName = $Project.FullName
$Doc = New-Object System.Xml.XmlDocument
$Doc.Load($ProjectFullName)
$Namespace = 'http://schemas.microsoft.com/developer/msbuild/2003'
# Find the node containing the file. The tag "Content" may be replace by "None" depending of the case, check your .csproj file.
$ContentNodes = Select-Xml "//msb:Project/msb:ItemGroup/msb:Content[starts-with(@Include, 'rubberband-dll-') and (substring(@Include, string-length(@Include) - 3) = '.dll')]" $Doc -Namespace @{msb = $Namespace}
#check if the node exists.
If ($ContentNodes -ne $Null)
{
$CopyNodeName = "CopyToOutputDirectory"
ForEach ($ContentNode In $ContentNodes)
{
$NoneNode = $Doc.CreateElement("None", $Namespace)
$NoneNode.SetAttribute("Include", $ContentNode.Node.Attributes["Include"].Value)
$CopyNode = $Doc.CreateElement($CopyNodeName, $Namespace)
$CopyNode.InnerText = "PreserveNewest"
$NoneNode.AppendChild($CopyNode)
$ContentNode.Node.ParentNode.ReplaceChild($NoneNode, $ContentNode.Node)
}
$DTE = $Project.DTE
$Project.Select("vsUISelectionTypeSelect")
$DTE.ExecuteCommand("Project.UnloadProject")
$Doc.Save($ProjectFullName)
$DTE.ExecuteCommand("Project.ReloadProject")
}

View File

@@ -0,0 +1,289 @@
/*
rubberband-sharp
A consumer of the rubberband DLL that wraps the RubberBandStretcher
object exposed by the DLL in a managed .NET type.
Copyright 2018-2019 Jonathan Gilbert
Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use, copy,
modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR
ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Except as contained in this notice, the name of Jonathan Gilbert
shall not be used in advertising or otherwise to promote the sale,
use or other dealings in this Software without prior written
authorization.
*/
using System;
using System.Runtime.InteropServices;
namespace RubberBand
{
internal class RubberBandNativeMethods
{
public static IntPtr RubberBandStretcher_Create(IntPtr sampleRate, IntPtr channels, int options = 0, double initialTimeRatio = 1.0, double initialPitchScale = 1.0)
{
if (IntPtr.Size == 8)
return RubberBandNativeMethodsx64.RubberBandStretcher_Create(sampleRate, channels, options, initialTimeRatio, initialPitchScale);
else
return RubberBandNativeMethodsWin32.RubberBandStretcher_Create(sampleRate, channels, options, initialTimeRatio, initialPitchScale);
}
public static void RubberBandStretcher_Delete(IntPtr rbs)
{
if (IntPtr.Size == 8)
RubberBandNativeMethodsx64.RubberBandStretcher_Delete(rbs);
else
RubberBandNativeMethodsWin32.RubberBandStretcher_Delete(rbs);
}
public static void RubberBandStretcher_Reset(IntPtr rbs)
{
if (IntPtr.Size == 8)
RubberBandNativeMethodsx64.RubberBandStretcher_Reset(rbs);
else
RubberBandNativeMethodsWin32.RubberBandStretcher_Reset(rbs);
}
public static void RubberBandStretcher_SetTimeRatio(IntPtr rbs, double ratio)
{
if (IntPtr.Size == 8)
RubberBandNativeMethodsx64.RubberBandStretcher_SetTimeRatio(rbs, ratio);
else
RubberBandNativeMethodsWin32.RubberBandStretcher_SetTimeRatio(rbs, ratio);
}
public static void RubberBandStretcher_SetPitchScale(IntPtr rbs, double scale)
{
if (IntPtr.Size == 8)
RubberBandNativeMethodsx64.RubberBandStretcher_SetPitchScale(rbs, scale);
else
RubberBandNativeMethodsWin32.RubberBandStretcher_SetPitchScale(rbs, scale);
}
public static double RubberBandStretcher_GetTimeRatio(IntPtr rbs)
{
if (IntPtr.Size == 8)
return RubberBandNativeMethodsx64.RubberBandStretcher_GetTimeRatio(rbs);
else
return RubberBandNativeMethodsWin32.RubberBandStretcher_GetTimeRatio(rbs);
}
public static double RubberBandStretcher_GetPitchScale(IntPtr rbs)
{
if (IntPtr.Size == 8)
return RubberBandNativeMethodsx64.RubberBandStretcher_GetPitchScale(rbs);
else
return RubberBandNativeMethodsWin32.RubberBandStretcher_GetPitchScale(rbs);
}
public static IntPtr RubberBandStretcher_GetLatency(IntPtr rbs)
{
if (IntPtr.Size == 8)
return RubberBandNativeMethodsx64.RubberBandStretcher_GetLatency(rbs);
else
return RubberBandNativeMethodsWin32.RubberBandStretcher_GetLatency(rbs);
}
public static void RubberBandStretcher_SetTransientsOption(IntPtr rbs, int options)
{
if (IntPtr.Size == 8)
RubberBandNativeMethodsx64.RubberBandStretcher_SetTransientsOption(rbs, options);
else
RubberBandNativeMethodsWin32.RubberBandStretcher_SetTransientsOption(rbs, options);
}
public static void RubberBandStretcher_SetDetectorOption(IntPtr rbs, int options)
{
if (IntPtr.Size == 8)
RubberBandNativeMethodsx64.RubberBandStretcher_SetDetectorOption(rbs, options);
else
RubberBandNativeMethodsWin32.RubberBandStretcher_SetDetectorOption(rbs, options);
}
public static void RubberBandStretcher_SetPhaseOption(IntPtr rbs, int options)
{
if (IntPtr.Size == 8)
RubberBandNativeMethodsx64.RubberBandStretcher_SetPhaseOption(rbs, options);
else
RubberBandNativeMethodsWin32.RubberBandStretcher_SetPhaseOption(rbs, options);
}
public static void RubberBandStretcher_SetFormantOption(IntPtr rbs, int options)
{
if (IntPtr.Size == 8)
RubberBandNativeMethodsx64.RubberBandStretcher_SetFormantOption(rbs, options);
else
RubberBandNativeMethodsWin32.RubberBandStretcher_SetFormantOption(rbs, options);
}
public static void RubberBandStretcher_SetPitchOption(IntPtr rbs, int options)
{
if (IntPtr.Size == 8)
RubberBandNativeMethodsx64.RubberBandStretcher_SetPitchOption(rbs, options);
else
RubberBandNativeMethodsWin32.RubberBandStretcher_SetPitchOption(rbs, options);
}
public static void RubberBandStretcher_SetExpectedInputDuration(IntPtr rbs, IntPtr samples)
{
if (IntPtr.Size == 8)
RubberBandNativeMethodsx64.RubberBandStretcher_SetExpectedInputDuration(rbs, samples);
else
RubberBandNativeMethodsWin32.RubberBandStretcher_SetExpectedInputDuration(rbs, samples);
}
public static void RubberBandStretcher_SetMaxProcessSize(IntPtr rbs, IntPtr samples)
{
if (IntPtr.Size == 8)
RubberBandNativeMethodsx64.RubberBandStretcher_SetMaxProcessSize(rbs, samples);
else
RubberBandNativeMethodsWin32.RubberBandStretcher_SetMaxProcessSize(rbs, samples);
}
public static IntPtr RubberBandStretcher_GetSamplesRequired(IntPtr rbs)
{
if (IntPtr.Size == 8)
return RubberBandNativeMethodsx64.RubberBandStretcher_GetSamplesRequired(rbs);
else
return RubberBandNativeMethodsWin32.RubberBandStretcher_GetSamplesRequired(rbs);
}
public static void RubberBandStretcher_SetKeyFrameMap(IntPtr rbs, IntPtr[] mappingData, int numberOfMappings)
{
if (IntPtr.Size == 8)
RubberBandNativeMethodsx64.RubberBandStretcher_SetKeyFrameMap(rbs, mappingData, numberOfMappings);
else
RubberBandNativeMethodsWin32.RubberBandStretcher_SetKeyFrameMap(rbs, mappingData, numberOfMappings);
}
public static void RubberBandStretcher_Study(IntPtr rbs, float[] input, IntPtr samples, int channels, bool final)
{
if (IntPtr.Size == 8)
RubberBandNativeMethodsx64.RubberBandStretcher_Study(rbs, input, samples, channels, final);
else
RubberBandNativeMethodsWin32.RubberBandStretcher_Study(rbs, input, samples, channels, final);
}
public static void RubberBandStretcher_Process(IntPtr rbs, float[] input, IntPtr samples, int channels, bool final)
{
if (IntPtr.Size == 8)
RubberBandNativeMethodsx64.RubberBandStretcher_Process(rbs, input, samples, channels, final);
else
RubberBandNativeMethodsWin32.RubberBandStretcher_Process(rbs, input, samples, channels, final);
}
public static int RubberBandStretcher_Available(IntPtr rbs)
{
if (IntPtr.Size == 8)
return RubberBandNativeMethodsx64.RubberBandStretcher_Available(rbs);
else
return RubberBandNativeMethodsWin32.RubberBandStretcher_Available(rbs);
}
public static IntPtr RubberBandStretcher_Retrieve(IntPtr rbs, float[] output, IntPtr samples, int channels)
{
if (IntPtr.Size == 8)
return RubberBandNativeMethodsx64.RubberBandStretcher_Retrieve(rbs, output, samples, channels);
else
return RubberBandNativeMethodsWin32.RubberBandStretcher_Retrieve(rbs, output, samples, channels);
}
public static float RubberBandStretcher_GetFrequencyCutoff(IntPtr rbs, int n)
{
if (IntPtr.Size == 8)
return RubberBandNativeMethodsx64.RubberBandStretcher_GetFrequencyCutoff(rbs, n);
else
return RubberBandNativeMethodsWin32.RubberBandStretcher_GetFrequencyCutoff(rbs, n);
}
public static void RubberBandStretcher_SetFrequencyCutoff(IntPtr rbs, int n, float f)
{
if (IntPtr.Size == 8)
RubberBandNativeMethodsx64.RubberBandStretcher_SetFrequencyCutoff(rbs, n, f);
else
RubberBandNativeMethodsWin32.RubberBandStretcher_SetFrequencyCutoff(rbs, n, f);
}
public static IntPtr RubberBandStretcher_GetInputIncrement(IntPtr rbs)
{
if (IntPtr.Size == 8)
return RubberBandNativeMethodsx64.RubberBandStretcher_GetInputIncrement(rbs);
else
return RubberBandNativeMethodsWin32.RubberBandStretcher_GetInputIncrement(rbs);
}
public static IntPtr RubberBandStretcher_GetOutputIncrements(IntPtr rbs, int[] buffer, IntPtr bufferSize)
{
if (IntPtr.Size == 8)
return RubberBandNativeMethodsx64.RubberBandStretcher_GetOutputIncrements(rbs, buffer, bufferSize);
else
return RubberBandNativeMethodsWin32.RubberBandStretcher_GetOutputIncrements(rbs, buffer, bufferSize);
}
public static IntPtr RubberBandStretcher_GetPhaseResetCurve(IntPtr rbs, float[] buffer, IntPtr bufferSize)
{
if (IntPtr.Size == 8)
return RubberBandNativeMethodsx64.RubberBandStretcher_GetPhaseResetCurve(rbs, buffer, bufferSize);
else
return RubberBandNativeMethodsWin32.RubberBandStretcher_GetPhaseResetCurve(rbs, buffer, bufferSize);
}
public static IntPtr RubberBandStretcher_GetExactTimePoints(IntPtr rbs, int[] buffer, IntPtr bufferSize)
{
if (IntPtr.Size == 8)
return RubberBandNativeMethodsx64.RubberBandStretcher_GetExactTimePoints(rbs, buffer, bufferSize);
else
return RubberBandNativeMethodsWin32.RubberBandStretcher_GetExactTimePoints(rbs, buffer, bufferSize);
}
public static IntPtr RubberBandStretcher_GetChannelCount(IntPtr rbs)
{
if (IntPtr.Size == 8)
return RubberBandNativeMethodsx64.RubberBandStretcher_GetChannelCount(rbs);
else
return RubberBandNativeMethodsWin32.RubberBandStretcher_GetChannelCount(rbs);
}
public static void RubberBandStretcher_CalculateStretch(IntPtr rbs)
{
if (IntPtr.Size == 8)
RubberBandNativeMethodsx64.RubberBandStretcher_CalculateStretch(rbs);
else
RubberBandNativeMethodsWin32.RubberBandStretcher_CalculateStretch(rbs);
}
public static void RubberBandStretcher_SetDebugLevel(IntPtr rbs, int level)
{
if (IntPtr.Size == 8)
RubberBandNativeMethodsx64.RubberBandStretcher_SetDebugLevel(rbs, level);
else
RubberBandNativeMethodsWin32.RubberBandStretcher_SetDebugLevel(rbs, level);
}
public static void RubberBandStretcher_SetDefaultDebugLevel(int level)
{
if (IntPtr.Size == 8)
RubberBandNativeMethodsx64.RubberBandStretcher_SetDefaultDebugLevel(level);
else
RubberBandNativeMethodsWin32.RubberBandStretcher_SetDefaultDebugLevel(level);
}
}
}

View File

@@ -0,0 +1,104 @@
/*
rubberband-sharp
A consumer of the rubberband DLL that wraps the RubberBandStretcher
object exposed by the DLL in a managed .NET type.
Copyright 2018-2019 Jonathan Gilbert
Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use, copy,
modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR
ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Except as contained in this notice, the name of Jonathan Gilbert
shall not be used in advertising or otherwise to promote the sale,
use or other dealings in this Software without prior written
authorization.
*/
using System;
using System.Runtime.InteropServices;
namespace RubberBand
{
internal class RubberBandNativeMethodsWin32
{
[DllImport("rubberband-dll-Win32", CallingConvention = CallingConvention.Cdecl)]
public static extern IntPtr RubberBandStretcher_Create(IntPtr sampleRate, IntPtr channels, int options = 0, double initialTimeRatio = 1.0, double initialPitchScale = 1.0);
[DllImport("rubberband-dll-Win32", CallingConvention = CallingConvention.Cdecl)]
public static extern void RubberBandStretcher_Delete(IntPtr rbs);
[DllImport("rubberband-dll-Win32", CallingConvention = CallingConvention.Cdecl)]
public static extern void RubberBandStretcher_Reset(IntPtr rbs);
[DllImport("rubberband-dll-Win32", CallingConvention = CallingConvention.Cdecl)]
public static extern void RubberBandStretcher_SetTimeRatio(IntPtr rbs, double ratio);
[DllImport("rubberband-dll-Win32", CallingConvention = CallingConvention.Cdecl)]
public static extern void RubberBandStretcher_SetPitchScale(IntPtr rbs, double scale);
[DllImport("rubberband-dll-Win32", CallingConvention = CallingConvention.Cdecl)]
public static extern double RubberBandStretcher_GetTimeRatio(IntPtr rbs);
[DllImport("rubberband-dll-Win32", CallingConvention = CallingConvention.Cdecl)]
public static extern double RubberBandStretcher_GetPitchScale(IntPtr rbs);
[DllImport("rubberband-dll-Win32", CallingConvention = CallingConvention.Cdecl)]
public static extern IntPtr RubberBandStretcher_GetLatency(IntPtr rbs);
[DllImport("rubberband-dll-Win32", CallingConvention = CallingConvention.Cdecl)]
public static extern void RubberBandStretcher_SetTransientsOption(IntPtr rbs, int options);
[DllImport("rubberband-dll-Win32", CallingConvention = CallingConvention.Cdecl)]
public static extern void RubberBandStretcher_SetDetectorOption(IntPtr rbs, int options);
[DllImport("rubberband-dll-Win32", CallingConvention = CallingConvention.Cdecl)]
public static extern void RubberBandStretcher_SetPhaseOption(IntPtr rbs, int options);
[DllImport("rubberband-dll-Win32", CallingConvention = CallingConvention.Cdecl)]
public static extern void RubberBandStretcher_SetFormantOption(IntPtr rbs, int options);
[DllImport("rubberband-dll-Win32", CallingConvention = CallingConvention.Cdecl)]
public static extern void RubberBandStretcher_SetPitchOption(IntPtr rbs, int options);
[DllImport("rubberband-dll-Win32", CallingConvention = CallingConvention.Cdecl)]
public static extern void RubberBandStretcher_SetExpectedInputDuration(IntPtr rbs, IntPtr samples);
[DllImport("rubberband-dll-Win32", CallingConvention = CallingConvention.Cdecl)]
public static extern void RubberBandStretcher_SetMaxProcessSize(IntPtr rbs, IntPtr samples);
[DllImport("rubberband-dll-Win32", CallingConvention = CallingConvention.Cdecl)]
public static extern IntPtr RubberBandStretcher_GetSamplesRequired(IntPtr rbs);
[DllImport("rubberband-dll-Win32", CallingConvention = CallingConvention.Cdecl)]
public static extern void RubberBandStretcher_SetKeyFrameMap(IntPtr rbs, IntPtr[] mappingData, int numberOfMappings);
[DllImport("rubberband-dll-Win32", CallingConvention = CallingConvention.Cdecl)]
public static extern void RubberBandStretcher_Study(IntPtr rbs, float[] input, IntPtr samples, int channels, bool final);
[DllImport("rubberband-dll-Win32", CallingConvention = CallingConvention.Cdecl)]
public static extern void RubberBandStretcher_Process(IntPtr rbs, float[] input, IntPtr samples, int channels, bool final);
[DllImport("rubberband-dll-Win32", CallingConvention = CallingConvention.Cdecl)]
public static extern int RubberBandStretcher_Available(IntPtr rbs);
[DllImport("rubberband-dll-Win32", CallingConvention = CallingConvention.Cdecl)]
public static extern IntPtr RubberBandStretcher_Retrieve(IntPtr rbs, float[] output, IntPtr samples, int channels);
[DllImport("rubberband-dll-Win32", CallingConvention = CallingConvention.Cdecl)]
public static extern float RubberBandStretcher_GetFrequencyCutoff(IntPtr rbs, int n);
[DllImport("rubberband-dll-Win32", CallingConvention = CallingConvention.Cdecl)]
public static extern void RubberBandStretcher_SetFrequencyCutoff(IntPtr rbs, int n, float f);
[DllImport("rubberband-dll-Win32", CallingConvention = CallingConvention.Cdecl)]
public static extern IntPtr RubberBandStretcher_GetInputIncrement(IntPtr rbs);
[DllImport("rubberband-dll-Win32", CallingConvention = CallingConvention.Cdecl)]
public static extern IntPtr RubberBandStretcher_GetOutputIncrements(IntPtr rbs, int[] buffer, IntPtr bufferSize);
[DllImport("rubberband-dll-Win32", CallingConvention = CallingConvention.Cdecl)]
public static extern IntPtr RubberBandStretcher_GetPhaseResetCurve(IntPtr rbs, float[] buffer, IntPtr bufferSize);
[DllImport("rubberband-dll-Win32", CallingConvention = CallingConvention.Cdecl)]
public static extern IntPtr RubberBandStretcher_GetExactTimePoints(IntPtr rbs, int[] buffer, IntPtr bufferSize);
[DllImport("rubberband-dll-Win32", CallingConvention = CallingConvention.Cdecl)]
public static extern IntPtr RubberBandStretcher_GetChannelCount(IntPtr rbs);
[DllImport("rubberband-dll-Win32", CallingConvention = CallingConvention.Cdecl)]
public static extern void RubberBandStretcher_CalculateStretch(IntPtr rbs);
[DllImport("rubberband-dll-Win32", CallingConvention = CallingConvention.Cdecl)]
public static extern void RubberBandStretcher_SetDebugLevel(IntPtr rbs, int level);
[DllImport("rubberband-dll-Win32", CallingConvention = CallingConvention.Cdecl)]
public static extern void RubberBandStretcher_SetDefaultDebugLevel(int level);
}
}

View File

@@ -0,0 +1,104 @@
/*
rubberband-sharp
A consumer of the rubberband DLL that wraps the RubberBandStretcher
object exposed by the DLL in a managed .NET type.
Copyright 2018-2019 Jonathan Gilbert
Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use, copy,
modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR
ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Except as contained in this notice, the name of Jonathan Gilbert
shall not be used in advertising or otherwise to promote the sale,
use or other dealings in this Software without prior written
authorization.
*/
using System;
using System.Runtime.InteropServices;
namespace RubberBand
{
internal class RubberBandNativeMethodsx64
{
[DllImport("rubberband-dll-x64")]
public static extern IntPtr RubberBandStretcher_Create(IntPtr sampleRate, IntPtr channels, int options = 0, double initialTimeRatio = 1.0, double initialPitchScale = 1.0);
[DllImport("rubberband-dll-x64")]
public static extern void RubberBandStretcher_Delete(IntPtr rbs);
[DllImport("rubberband-dll-x64")]
public static extern void RubberBandStretcher_Reset(IntPtr rbs);
[DllImport("rubberband-dll-x64")]
public static extern void RubberBandStretcher_SetTimeRatio(IntPtr rbs, double ratio);
[DllImport("rubberband-dll-x64")]
public static extern void RubberBandStretcher_SetPitchScale(IntPtr rbs, double scale);
[DllImport("rubberband-dll-x64")]
public static extern double RubberBandStretcher_GetTimeRatio(IntPtr rbs);
[DllImport("rubberband-dll-x64")]
public static extern double RubberBandStretcher_GetPitchScale(IntPtr rbs);
[DllImport("rubberband-dll-x64")]
public static extern IntPtr RubberBandStretcher_GetLatency(IntPtr rbs);
[DllImport("rubberband-dll-x64")]
public static extern void RubberBandStretcher_SetTransientsOption(IntPtr rbs, int options);
[DllImport("rubberband-dll-x64")]
public static extern void RubberBandStretcher_SetDetectorOption(IntPtr rbs, int options);
[DllImport("rubberband-dll-x64")]
public static extern void RubberBandStretcher_SetPhaseOption(IntPtr rbs, int options);
[DllImport("rubberband-dll-x64")]
public static extern void RubberBandStretcher_SetFormantOption(IntPtr rbs, int options);
[DllImport("rubberband-dll-x64")]
public static extern void RubberBandStretcher_SetPitchOption(IntPtr rbs, int options);
[DllImport("rubberband-dll-x64")]
public static extern void RubberBandStretcher_SetExpectedInputDuration(IntPtr rbs, IntPtr samples);
[DllImport("rubberband-dll-x64")]
public static extern void RubberBandStretcher_SetMaxProcessSize(IntPtr rbs, IntPtr samples);
[DllImport("rubberband-dll-x64")]
public static extern IntPtr RubberBandStretcher_GetSamplesRequired(IntPtr rbs);
[DllImport("rubberband-dll-x64")]
public static extern void RubberBandStretcher_SetKeyFrameMap(IntPtr rbs, IntPtr[] mappingData, int numberOfMappings);
[DllImport("rubberband-dll-x64")]
public static extern void RubberBandStretcher_Study(IntPtr rbs, float[] input, IntPtr samples, int channels, bool final);
[DllImport("rubberband-dll-x64")]
public static extern void RubberBandStretcher_Process(IntPtr rbs, float[] input, IntPtr samples, int channels, bool final);
[DllImport("rubberband-dll-x64")]
public static extern int RubberBandStretcher_Available(IntPtr rbs);
[DllImport("rubberband-dll-x64")]
public static extern IntPtr RubberBandStretcher_Retrieve(IntPtr rbs, float[] output, IntPtr samples, int channels);
[DllImport("rubberband-dll-x64")]
public static extern float RubberBandStretcher_GetFrequencyCutoff(IntPtr rbs, int n);
[DllImport("rubberband-dll-x64")]
public static extern void RubberBandStretcher_SetFrequencyCutoff(IntPtr rbs, int n, float f);
[DllImport("rubberband-dll-x64")]
public static extern IntPtr RubberBandStretcher_GetInputIncrement(IntPtr rbs);
[DllImport("rubberband-dll-x64")]
public static extern IntPtr RubberBandStretcher_GetOutputIncrements(IntPtr rbs, int[] buffer, IntPtr bufferSize);
[DllImport("rubberband-dll-x64")]
public static extern IntPtr RubberBandStretcher_GetPhaseResetCurve(IntPtr rbs, float[] buffer, IntPtr bufferSize);
[DllImport("rubberband-dll-x64")]
public static extern IntPtr RubberBandStretcher_GetExactTimePoints(IntPtr rbs, int[] buffer, IntPtr bufferSize);
[DllImport("rubberband-dll-x64")]
public static extern IntPtr RubberBandStretcher_GetChannelCount(IntPtr rbs);
[DllImport("rubberband-dll-x64")]
public static extern void RubberBandStretcher_CalculateStretch(IntPtr rbs);
[DllImport("rubberband-dll-x64")]
public static extern void RubberBandStretcher_SetDebugLevel(IntPtr rbs, int level);
[DllImport("rubberband-dll-x64")]
public static extern void RubberBandStretcher_SetDefaultDebugLevel(int level);
}
}

View File

@@ -0,0 +1,345 @@
/*
rubberband-sharp
A consumer of the rubberband DLL that wraps the RubberBandStretcher
object exposed by the DLL in a managed .NET type.
Copyright 2018-2019 Jonathan Gilbert
Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use, copy,
modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR
ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Except as contained in this notice, the name of Jonathan Gilbert
shall not be used in advertising or otherwise to promote the sale,
use or other dealings in this Software without prior written
authorization.
*/
using System;
using System.Collections.Generic;
namespace RubberBand
{
public class RubberBandStretcher : IDisposable
{
public enum Options
{
None = 0,
ProcessOffline = 0x00000000,
ProcessRealTime = 0x00000001,
StretchElastic = 0x00000000,
StretchPrecise = 0x00000010,
TransientsCrisp = 0x00000000,
TransientsMixed = 0x00000100,
TransientsSmooth = 0x00000200,
DetectorCompound = 0x00000000,
DetectorPercussive = 0x00000400,
DetectorSoft = 0x00000800,
PhaseLaminar = 0x00000000,
PhaseIndependent = 0x00002000,
ThreadingAuto = 0x00000000,
ThreadingNever = 0x00010000,
ThreadingAlways = 0x00020000,
WindowStandard = 0x00000000,
WindowShort = 0x00100000,
WindowLong = 0x00200000,
SmoothingOff = 0x00000000,
SmoothingOn = 0x00800000,
FormantShifted = 0x00000000,
FormantPreserved = 0x01000000,
PitchHighSpeed = 0x00000000,
PitchHighQuality = 0x02000000,
PitchHighConsistency = 0x04000000,
ChannelsApart = 0x00000000,
ChannelsTogether = 0x10000000,
}
public const Options DefaultOptions = Options.None;
public const Options PercussiveOptions = Options.WindowShort | Options.PhaseIndependent;
IntPtr _rbs;
public RubberBandStretcher(int sampleRate, int channels, Options options = DefaultOptions, double initialTimeRatio = 1.0, double initialPitchScale = 1.0)
{
_rbs = RubberBandNativeMethods.RubberBandStretcher_Create(new IntPtr(sampleRate), new IntPtr(channels), (int)options, initialTimeRatio, initialPitchScale);
}
public void Dispose()
{
if (_rbs != IntPtr.Zero)
{
RubberBandNativeMethods.RubberBandStretcher_Delete(_rbs);
_rbs = IntPtr.Zero;
}
}
public void Reset()
{
RubberBandNativeMethods.RubberBandStretcher_Reset(_rbs);
}
public void SetTimeRatio(double ratio)
{
RubberBandNativeMethods.RubberBandStretcher_SetTimeRatio(_rbs, ratio);
}
public void SetPitchScale(double scale)
{
RubberBandNativeMethods.RubberBandStretcher_SetPitchScale(_rbs, scale);
}
public double GetTimeRatio()
{
return RubberBandNativeMethods.RubberBandStretcher_GetTimeRatio(_rbs);
}
public double GetPitchScale()
{
return RubberBandNativeMethods.RubberBandStretcher_GetPitchScale(_rbs);
}
public long GetLatency()
{
return RubberBandNativeMethods.RubberBandStretcher_GetLatency(_rbs).ToInt64();
}
public void SetTransientsOption(Options options)
{
RubberBandNativeMethods.RubberBandStretcher_SetTransientsOption(_rbs, (int)options);
}
public void SetDetectorOption(Options options)
{
RubberBandNativeMethods.RubberBandStretcher_SetDetectorOption(_rbs, (int)options);
}
public void SetPhaseOption(Options options)
{
RubberBandNativeMethods.RubberBandStretcher_SetPhaseOption(_rbs, (int)options);
}
public void SetFormantOption(Options options)
{
RubberBandNativeMethods.RubberBandStretcher_SetFormantOption(_rbs, (int)options);
}
public void SetPitchOption(Options options)
{
RubberBandNativeMethods.RubberBandStretcher_SetPitchOption(_rbs, (int)options);
}
public void SetExpectedInputDuration(long samples)
{
RubberBandNativeMethods.RubberBandStretcher_SetExpectedInputDuration(_rbs, new IntPtr(samples));
}
public void SetMaxProcessSize(long samples)
{
RubberBandNativeMethods.RubberBandStretcher_SetMaxProcessSize(_rbs, new IntPtr(samples));
}
public long GetSamplesRequired()
{
return RubberBandNativeMethods.RubberBandStretcher_GetSamplesRequired(_rbs).ToInt64();
}
public void SetKeyFrameMap(SortedDictionary<long, long> map)
{
var mappingData = new List<IntPtr>();
foreach (var mapping in map)
{
mappingData.Add(new IntPtr(mapping.Key));
mappingData.Add(new IntPtr(mapping.Value));
}
RubberBandNativeMethods.RubberBandStretcher_SetKeyFrameMap(_rbs, mappingData.ToArray(), mappingData.Count / 2);
}
float[] _studyBuffer = new float[1024];
public void Study(float[][] input, bool final)
{
for (int i = 1; i < input.Length; i++)
if (input[i].Length != input[0].Length)
throw new Exception("Invalid input data: Not all channels have the same number of samples");
Study(input, input[0].Length, final);
}
public void Study(float[][] input, long samples, bool final)
{
for (int i = 0; i < input.Length; i++)
if (input[i].Length < samples)
throw new Exception("Invalid input data: Channel " + i + " does not have " + samples + " samples of data");
long totalSamples = input.Length * samples;
if (totalSamples > _studyBuffer.Length)
_studyBuffer = new float[totalSamples];
for (int i = 0; i < input.Length; i++)
Array.Copy(input[i], 0, _studyBuffer, i * samples, samples);
RubberBandNativeMethods.RubberBandStretcher_Study(_rbs, _studyBuffer, new IntPtr(samples), input.Length, final);
}
float[] _processBuffer = new float[1024];
public void Process(float[][] input, bool final)
{
for (int i = 1; i < input.Length; i++)
if (input[i].Length != input[0].Length)
throw new Exception("Invalid input data: Not all channels have the same number of samples");
Process(input, input[0].Length, final);
}
public void Process(float[][] input, long samples, bool final)
{
for (int i = 0; i < input.Length; i++)
if (input[i].Length < samples)
throw new Exception("Invalid input data: Channel " + i + " does not have " + samples + " samples of data");
long totalSamples = input.Length * samples;
if (totalSamples > _processBuffer.Length)
_processBuffer = new float[totalSamples];
for (int i = 0; i < input.Length; i++)
Array.Copy(input[i], 0, _processBuffer, i * samples, samples);
RubberBandNativeMethods.RubberBandStretcher_Process(_rbs, _processBuffer, new IntPtr(samples), input.Length, final);
}
public int Available()
{
return RubberBandNativeMethods.RubberBandStretcher_Available(_rbs);
}
float[] _outputBuffer = new float[1024];
public long Retrieve(float[][] output)
{
for (int i = 1; i < output.Length; i++)
if (output[i].Length != output[0].Length)
throw new Exception("Invalid output buffer: Not all channels have the same number of samples");
return Retrieve(output, output[0].Length);
}
public long Retrieve(float[][] output, long samples)
{
for (int i = 0; i < output.Length; i++)
if (output[i].Length < samples)
throw new Exception("Invalid output buffer: Channel " + i + " does not have enough space for " + samples + " samples");
long totalSamples = output.Length * samples;
if (totalSamples > _outputBuffer.Length)
_outputBuffer = new float[totalSamples];
long actualSamples = RubberBandNativeMethods.RubberBandStretcher_Retrieve(_rbs, _outputBuffer, new IntPtr(samples), output.Length).ToInt64();
for (int i = 0; i < output.Length; i++)
Array.Copy(_outputBuffer, i * samples, output[i], 0, actualSamples);
return actualSamples;
}
public float GetFrequencyCutoff(int n)
{
return RubberBandNativeMethods.RubberBandStretcher_GetFrequencyCutoff(_rbs, n);
}
public void SetFrequencyCutoff(int n, float f)
{
RubberBandNativeMethods.RubberBandStretcher_SetFrequencyCutoff(_rbs, n, f);
}
public long GetInputIncrement()
{
return RubberBandNativeMethods.RubberBandStretcher_GetInputIncrement(_rbs).ToInt64();
}
public int[] GetOutputIncrements()
{
long numberOfIncrements = RubberBandNativeMethods.RubberBandStretcher_GetOutputIncrements(_rbs, null, IntPtr.Zero).ToInt64();
int[] buffer = new int[numberOfIncrements];
RubberBandNativeMethods.RubberBandStretcher_GetOutputIncrements(_rbs, buffer, new IntPtr(buffer.Length));
return buffer;
}
public float[] GetPhaseResetCurve()
{
long numberOfCurveElements = RubberBandNativeMethods.RubberBandStretcher_GetPhaseResetCurve(_rbs, null, IntPtr.Zero).ToInt64();
float[] buffer = new float[numberOfCurveElements];
RubberBandNativeMethods.RubberBandStretcher_GetPhaseResetCurve(_rbs, buffer, new IntPtr(buffer.Length));
return buffer;
}
public int[] GetExactTimePoints()
{
long numberOfTimePoints = RubberBandNativeMethods.RubberBandStretcher_GetExactTimePoints(_rbs, null, IntPtr.Zero).ToInt64();
int[] buffer = new int[numberOfTimePoints];
RubberBandNativeMethods.RubberBandStretcher_GetExactTimePoints(_rbs, buffer, new IntPtr(buffer.Length));
return buffer;
}
public long GetChannelCount()
{
return RubberBandNativeMethods.RubberBandStretcher_GetChannelCount(_rbs).ToInt64();
}
public void CalculateStretch()
{
RubberBandNativeMethods.RubberBandStretcher_CalculateStretch(_rbs);
}
public void SetDebugLevel(int level)
{
RubberBandNativeMethods.RubberBandStretcher_SetDebugLevel(_rbs, level);
}
public static void SetDefaultDebugLevel(int level)
{
RubberBandNativeMethods.RubberBandStretcher_SetDefaultDebugLevel(level);
}
}
}

View File

@@ -0,0 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<RootNamespace>rubberband_sharp</RootNamespace>
<AssemblyVersion>1.0.0.0</AssemblyVersion>
<FileVersion>1.0.0.0</FileVersion>
</PropertyGroup>
</Project>

View File

@@ -0,0 +1,21 @@
<?xml version="1.0"?>
<package >
<metadata>
<id>rubberband-sharp</id>
<version>1.0.0</version>
<title>Rubber Band Library .NET Wrapper</title>
<authors>JonathanG@iQmetrix.com</authors>
<description>C# wrapper for the Rubber Band Library audio time-stretching and pitch-shifting library.</description>
</metadata>
<files>
<!-- Content files the new way: With the new .csproj format, NuGet will import project definition from rubberband-sharp.targets, which sets up the files -->
<file src="rubberband-sharp.targets" target="build" />
<file src="..\Release\rubberband-dll-Win32.dll" target="build" />
<file src="..\x64\Release\rubberband-dll-x64.dll" target="build" />
<!-- Content files the old way: NuGet will add the .dll files as Content items, then Install.ps1 script converts them to None items with a CopyToOutputDirectory attribute. -->
<file src="Install.ps1" target="tools\Install.ps1" />
<file src="..\Release\rubberband-dll-Win32.dll" target="content" />
<file src="..\x64\Release\rubberband-dll-x64.dll" target="content" />
</files>
</package>

View File

@@ -0,0 +1,12 @@
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<None Include="$(MSBuildThisFileDirectory)rubberband-dll-Win32.dll">
<Link>rubberband-dll-Win32.dll</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="$(MSBuildThisFileDirectory)rubberband-dll-x64.dll">
<Link>rubberband-dll-x64.dll</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
</Project>