Skip to content

Commit

Permalink
BugFix
Browse files Browse the repository at this point in the history
  • Loading branch information
NaruseMioShirakana committed May 23, 2024
1 parent ec928cf commit f5ee2a6
Show file tree
Hide file tree
Showing 15 changed files with 396 additions and 104 deletions.
16 changes: 16 additions & 0 deletions CSharpDemo/CSharpDemo.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,26 @@
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<AllowUnsafeBlocks>True</AllowUnsafeBlocks>
<Configurations>Debug;Release</Configurations>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\DotNetApi\DotNetApi.csproj" />
</ItemGroup>

<ItemGroup>
<Compile Update="Properties\Resources.Designer.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>Resources.resx</DependentUpon>
</Compile>
</ItemGroup>

<ItemGroup>
<EmbeddedResource Update="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
</EmbeddedResource>
</ItemGroup>

</Project>
13 changes: 11 additions & 2 deletions CSharpDemo/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ void PrintProgress(ulong arg1, ulong arg2)

LibSvc.SlicerSettings slicerSettings = new();
UInt64Vector SlicePos = LibSvc.Factory.SliceAudio(ref Audio, ref slicerSettings);
SlicePos.Resize(3);
Console.WriteLine(SlicePos.Size());

Slices slices = LibSvc.Factory.Preprocess(ref Audio, ref SlicePos);
Expand All @@ -44,10 +45,18 @@ void PrintProgress(ulong arg1, ulong arg2)
VocoderModel Vocoder = LibSvc.Factory.LoadVocoderModel(ref VocoderPath);

LibSvc.Params _params = new();
_params.Step = 100;
_params.Pndm = 10;
_params.SetVocoder(ref Vocoder);
ulong Proc = 0;
Slice slice = slices[0];
Slice slice = slices[1];
Audio = Model.Inference(slice, ref _params, ref Proc);
Console.WriteLine((double)slice.SrcLength() * Config.SamplingRate / slicerSettings.SamplingRate);
Console.WriteLine(Audio.Size());
GC.KeepAlive(Callback);
Callback(1, 2);
GC.KeepAlive(Callback);
GC.KeepAlive(Vocoder);

LibSvc.Factory.WriteAudio(Audio, "Out1.wav", Config.SamplingRate);
Audio.Insert(ref Audio);
LibSvc.Factory.WriteAudio(Audio, "Out2.wav", Config.SamplingRate);
63 changes: 63 additions & 0 deletions CSharpDemo/Properties/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

101 changes: 101 additions & 0 deletions CSharpDemo/Properties/Resources.resx
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 1.3
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">1.3</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1">this is my long string</data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
[base64 mime encoded serialized .NET Framework object]
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
[base64 mime encoded string representing a byte array form of the .NET Framework object]
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->

<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>1.3</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.3500.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.3500.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>
8 changes: 8 additions & 0 deletions CSharpDemo/Properties/launchSettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"profiles": {
"CSharpDemo": {
"commandName": "Project",
"nativeDebugging": true
}
}
}
2 changes: 1 addition & 1 deletion DotNetApi/DotNetApi.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<AllowUnsafeBlocks>True</AllowUnsafeBlocks>
<Configurations>Debug;Release;ReleaseDll</Configurations>
<Configurations>Debug;Release</Configurations>
<BaseOutputPath></BaseOutputPath>
</PropertyGroup>

Expand Down
30 changes: 30 additions & 0 deletions DotNetApi/LibSvcApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,11 @@ public void Resize(ulong _Size)
LibSvcSetAudioLength(Obj_, _Size);
}

public void Insert(ref Int16Vector _Input)
{
LibSvcInsertAudio(Obj_, _Input.Object);
}

[DllImport("libsvc.dll")]
private static extern short* LibSvcGetAudioData(void* _Obj);

Expand All @@ -122,6 +127,9 @@ public void Resize(ulong _Size)
[DllImport("libsvc.dll")]
private static extern void LibSvcSetAudioLength(void* _Obj, ulong _Size);

[DllImport("libsvc.dll")]
private static extern void LibSvcInsertAudio(void* _ObjA, void* _ObjB);

private void* Obj_ = null;
private bool Owner_ = false;
}
Expand Down Expand Up @@ -158,6 +166,11 @@ public ulong Size()
return LibSvcGetOffsetSize(Obj_);
}

public void Resize(ulong _Size)
{
LibSvcSetOffsetLength(Obj_, _Size);
}

[DllImport("libsvc.dll")]
private static extern ulong* LibSvcGetOffsetData(void* _Obj);

Expand All @@ -170,6 +183,9 @@ public ulong Size()
[DllImport("libsvc.dll")]
private static extern void LibSvcReleaseOffset(void* _Obj);

[DllImport("libsvc.dll")]
private static extern void LibSvcSetOffsetLength(void* _Obj, ulong _Size);

private void* Obj_ = null;
private bool Owner_ = false;
}
Expand Down Expand Up @@ -704,6 +720,7 @@ public static LibSvc Factory
public void Init()
{
LibSvcInit();
EnableFileLogger(false);
SetF0PredictorEnv(8, 0, 0);
}

Expand Down Expand Up @@ -807,6 +824,13 @@ public VocoderModel LoadVocoderModel(ref string _Path)
throw new Exception(GetError(0));
}

public void EnableFileLogger(bool _Cond) { LibSvcEnableFileLogger(_Cond); }

public void WriteAudio(Int16Vector _PCMData, string _OutputPath, int _SamplingRate)
{
LibSvcWriteAudioFile(_PCMData.Object, _OutputPath, _SamplingRate);
}

[DllImport("libsvc.dll")]
private static extern void LibSvcInit();

Expand Down Expand Up @@ -862,5 +886,11 @@ uint _ThreadCount

[DllImport("libsvc.dll", CharSet = CharSet.Unicode)]
private static extern int LibSvcReadAudio(string _AudioPath, int _SamplingRate, void* _Output);

[DllImport("libsvc.dll", CharSet = CharSet.Unicode)]
private static extern void LibSvcWriteAudioFile(void* _PCMData, string _OutputPath, int _SamplingRate);

[DllImport("libsvc.dll")]
private static extern void LibSvcEnableFileLogger(bool _Cond);
}
}
8 changes: 8 additions & 0 deletions DotNetApi/Properties/launchSettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"profiles": {
"DotNetApi": {
"commandName": "Project",
"nativeDebugging": true
}
}
}
8 changes: 8 additions & 0 deletions libsvc/Api/header/CAndDotNetApi.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,8 @@ extern "C" {

LibSvcApi void LibSvcSetAudioLength(void* _Obj, size_t _Size);

LibSvcApi void LibSvcInsertAudio(void* _ObjA, void* _ObjB);

LibSvcApi short* LibSvcGetAudioData(void* _Obj);

LibSvcApi size_t LibSvcGetAudioSize(void* _Obj);
Expand All @@ -143,6 +145,8 @@ extern "C" {

LibSvcApi void LibSvcReleaseOffset(void* _Obj);

LibSvcApi void LibSvcSetOffsetLength(void* _Obj, size_t _Size);

LibSvcApi size_t* LibSvcGetOffsetData(void* _Obj);

LibSvcApi size_t LibSvcGetOffsetSize(void* _Obj);
Expand Down Expand Up @@ -269,6 +273,10 @@ extern "C" {

LibSvcApi INT32 LibSvcReadAudio(LPWSTR _AudioPath, INT32 _SamplingRate, void* _Output);

LibSvcApi void LibSvcEnableFileLogger(bool _Cond);

LibSvcApi void LibSvcWriteAudioFile(void* _PCMData, LPWSTR _OutputPath, INT32 _SamplingRate);

#ifdef __cplusplus
}
#endif
Loading

0 comments on commit f5ee2a6

Please sign in to comment.