Skip to content

Commit

Permalink
再次支持VITS
Browse files Browse the repository at this point in the history
添加对BertVits的支持
  • Loading branch information
NaruseMioShirakana committed Nov 11, 2023
1 parent 4aadbbd commit 6ecf944
Show file tree
Hide file tree
Showing 34 changed files with 3,128 additions and 448 deletions.
17 changes: 16 additions & 1 deletion Lib/MJson/MJson.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,8 @@ class MJsonValue
{
if (!IsArray() && !IsString())
return true;
const auto _max = yyjson_arr_size(_Ptr);
auto _max = yyjson_arr_size(_Ptr);
if (IsString()) _max = yyjson_get_len(_Ptr);
return !_max;
}
[[nodiscard]] size_t GetMemberCount() const
Expand All @@ -148,6 +149,10 @@ class MJsonValue
}
return ret;
}
[[nodiscard]] bool HasMember(const std::string& _key) const
{
return yyjson_obj_get(_Ptr, _key.c_str());
}
private:
yyjson_val* _Ptr = nullptr;
};
Expand All @@ -163,6 +168,16 @@ class MJson
throw std::exception("Json Parse Error !");
root = yyjson_doc_get_root(_document);
}
MJson(const std::string& _data, bool _read_from_string)
{
if (_read_from_string)
_document = yyjson_read(_data.c_str(), _data.length(), YYJSON_READ_NOFLAG);
else
_document = yyjson_read_file(_data.c_str(), YYJSON_READ_NOFLAG, nullptr, nullptr);
if (!_document)
throw std::exception("Json Parse Error !");
root = yyjson_doc_get_root(_document);
}
~MJson()
{
if(_document)
Expand Down
52 changes: 49 additions & 3 deletions MoeVoiceStudioSvc - Core - Cmd/LibDLVoiceCodec/base.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <string>
#include <cassert>
#include <iostream>
#include <unordered_map>
#define LibDLVoiceCodecBegin namespace libdlvcodec {
#define LibDLVoiceCodecEnd }
#define LIBDVCND [[nodiscard]]
Expand All @@ -24,6 +25,12 @@ using uint16 = uint16_t;
using uint32 = uint32_t;
using uint64 = uint64_t;

class TensorView;
class Tensor;

const std::unordered_map<std::string, size_t> __Dtype {{"int8", 1}, { "int16", 2 }, { "int32", 4 }, { "int64", 8 },
{ "float8", 1 }, { "float16", 2 }, { "bfloat16", 2 }, { "float32", 4 }, { "float64", 8 }, { "bool", 1 } };

template<typename T>
class BaseAllocator
{
Expand Down Expand Up @@ -54,12 +61,16 @@ class MResource
{
data_ = allocator_.allocate(_Count * 2);
size_ = _Count;
this_ = data_ + _Count;
end_ = data_ + _Count * 2;
}

MResource(size_t _Count, Type _Value)
{
data_ = allocator_.allocate(_Count * 2);
size_ = _Count;
this_ = data_ + _Count;
end_ = data_ + _Count * 2;
auto _ptr = data_;
const auto _end = data_ + size_;
while (_ptr != _end)
Expand All @@ -73,12 +84,16 @@ class MResource
{
data_ = _Ptr;
size_ = _Size;
this_ = data_ + _Size;
end_ = data_ + _Size;
}

MResource(const MResource& _Left)
{
size_ = _Left.size_;
data_ = allocator_.allocate(_Left.size_);
data_ = allocator_.allocate(_Left.capacity());
this_ = data_ + size_;
end_ = data_ + _Left.capacity();
auto _ptr = data_, _ptrl = _Left.data_;
const auto _end = data_ + size_;
while (_ptr != _end)
Expand All @@ -93,6 +108,8 @@ class MResource
{
size_ = _Right.size_;
data_ = _Right.data_;
this_ = _Right.this_;
end_ = _Right.end_;
_Right.size_ = 0ull;
_Right.data_ = nullptr;
}
Expand All @@ -118,7 +135,7 @@ class MResource

LIBDVCND ptr_t end() const
{
return data_ + size_;
return this_;
}

ptr_t release()
Expand All @@ -134,12 +151,37 @@ class MResource
return *(data_ + _Index);
}

template<typename __Ty>
reference at(size_t _Index) const
{
assert(_Index * sizeof(__Ty) < size_);
return *((__Ty*)data_ + _Index);
}

reference at(size_t _Index) const
{
assert(_Index < size_);
return *(data_ + _Index);
}

LIBDVCND size_t size() const
{
return size_;
}

LIBDVCND size_t capacity() const
{
return end_ - data_;
}

MResource& operator=(const MResource& _Left)
{
if (&_Left == this)
return *this;
size_ = _Left.size_;
data_ = allocator_.allocate(_Left.size_);
data_ = allocator_.allocate(_Left.capacity());
this_ = data_ + size_;
end_ = data_ + _Left.capacity();
auto _ptr = data_, _ptrl = _Left.data_;
const auto _end = data_ + size_;
while (_ptr != _end)
Expand All @@ -155,12 +197,16 @@ class MResource
{
size_ = _Right.size_;
data_ = _Right.data_;
this_ = _Right.this_;
end_ = _Right.end_;
_Right.size_ = 0ull;
_Right.data_ = nullptr;
return *this;
}
protected:
ptr_t data_ = nullptr;
ptr_t this_ = nullptr;
ptr_t end_ = nullptr;
size_t size_ = 0ull;
Allocator allocator_;
};
Expand Down
7 changes: 7 additions & 0 deletions MoeVoiceStudioSvc - Core - Cmd/LibDLVoiceCodec/operator.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#include "operator.h"
#include "value.h"
#include <cblas.h>

LibDLVoiceCodecBegin

LibDLVoiceCodecEnd
27 changes: 27 additions & 0 deletions MoeVoiceStudioSvc - Core - Cmd/LibDLVoiceCodec/operator.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#pragma once
#include "base.h"

LibDLVoiceCodecBegin
Tensor equal(const Tensor& _A, const Tensor& _B);
Tensor add(const Tensor& _A, const Tensor& _B);
Tensor sub(const Tensor& _A, const Tensor& _B);
Tensor mul(const Tensor& _A, const Tensor& _B);
Tensor div(const Tensor& _A, const Tensor& _B);
void selfAdd(Tensor& _Self, const Tensor& _O);
void selfSub(Tensor& _Self, const Tensor& _O);
void selfMul(Tensor& _Self, const Tensor& _O);
void selfDiv(Tensor& _Self, const Tensor& _O);
Tensor matmul(const Tensor& _A, const Tensor& _B);
Tensor conv1d(const Tensor& _Input, const Tensor& _Weight, const Tensor& _Bias,
int64 _Stride = 1, int64 _Padding = 0, int64 _Dilation = 1, int64 _Groups = 1);
Tensor conv2d(const Tensor& _Input, const Tensor& _Weight, const Tensor& _Bias,
int64 _Stride = 1, int64 _Padding = 0, int64 _Dilation = 1, int64 _Groups = 1);
Tensor conv3d(const Tensor& _Input, const Tensor& _Weight, const Tensor& _Bias,
int64 _Stride = 1, int64 _Padding = 0, int64 _Dilation = 1, int64 _Groups = 1);
Tensor conv_transpose1d(const Tensor& _Input, const Tensor& _Weight, const Tensor& _Bias,
int64 _Stride = 1, int64 _Padding = 0, int64 _OutputPadding = 0, int64 _Dilation = 1, int64 _Groups = 1);
Tensor conv_transpose2d(const Tensor& _Input, const Tensor& _Weight, const Tensor& _Bias,
int64 _Stride = 1, int64 _Padding = 0, int64 _OutputPadding = 0, int64 _Dilation = 1, int64 _Groups = 1);
Tensor conv_transpose3d(const Tensor& _Input, const Tensor& _Weight, const Tensor& _Bias,
int64 _Stride = 1, int64 _Padding = 0, int64 _OutputPadding = 0, int64 _Dilation = 1, int64 _Groups = 1);
LibDLVoiceCodecEnd
Loading

0 comments on commit 6ecf944

Please sign in to comment.