-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathDiffSvc.hpp
180 lines (162 loc) · 6.31 KB
/
DiffSvc.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
/**
* FileName: DiffSvc.hpp
* Note: MoeVoiceStudioCore Onnx DiffusionSvc
*
* Copyright (C) 2022-2024 NaruseMioShirakana ([email protected])
*
* This file is part of DragonianLib.
* DragonianLib is free software: you can redistribute it and/or modify it under the terms of the
* GNU Affero General Public License as published by the Free Software Foundation, either version 3
* of the License, or any later version.
*
* DragonianLib is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License along with Foobar.
* If not, see <https://www.gnu.org/licenses/agpl-3.0.html>.
*
* date: 2022-10-17 Create
*/
#pragma once
#include "SVC.hpp"
_D_Dragonian_Lib_Lib_Singing_Voice_Conversion_Header
/**
* @class DiffusionSvc
* @brief Diffusion model class, inherits from SingingVoiceConversion
*/
class DiffusionSvc : public SingingVoiceConversion
{
public:
/**
* @brief Constructor
* @param _Hps Hyperparameters
* @param _ProgressCallback Progress callback function
* @param ExecutionProvider_ Execution provider
* @param DeviceID_ Device ID
* @param ThreadCount_ Number of threads
*/
DiffusionSvc(
const Hparams& _Hps,
const ProgressCallback& _ProgressCallback,
ExecutionProviders ExecutionProvider_ = ExecutionProviders::CPU,
unsigned DeviceID_ = 0,
unsigned ThreadCount_ = 0
);
/**
* @brief Destructor
*/
~DiffusionSvc() override;
/**
* @brief Perform inference on a single audio slice
* @param _Slice Audio slice
* @param _Params Inference parameters
* @param _Process Processing progress
* @return Inference result
*/
[[nodiscard]] DragonianLibSTL::Vector<float> SliceInference(
const SingleSlice& _Slice,
const InferenceParams& _Params,
size_t& _Process
) const override;
/**
* @brief Perform inference on PCM data
* @param _PCMData PCM data
* @param _SrcSamplingRate Source sampling rate
* @param _Params Inference parameters
* @return Inference result
*/
[[nodiscard]] DragonianLibSTL::Vector<float> InferPCMData(
const DragonianLibSTL::Vector<float>& _PCMData,
long _SrcSamplingRate,
const InferenceParams& _Params
) const override;
/**
* @brief Perform shallow diffusion inference
* @param _16KAudioHubert 16K audio data
* @param _Params Inference parameters
* @param _Mel Mel spectrogram data
* @param _SrcF0 Source F0 data
* @param _SrcVolume Source volume data
* @param _SrcSpeakerMap Source speaker map data
* @param Process Processing progress
* @param SrcSize Source data size
* @return Inference result
*/
[[nodiscard]] DragonianLibSTL::Vector<float> ShallowDiffusionInference(
DragonianLibSTL::Vector<float>& _16KAudioHubert,
const InferenceParams& _Params,
std::pair<DragonianLibSTL::Vector<float>, int64_t>& _Mel,
const DragonianLibSTL::Vector<float>& _SrcF0,
const DragonianLibSTL::Vector<float>& _SrcVolume,
const DragonianLibSTL::Vector<DragonianLibSTL::Vector<float>>& _SrcSpeakerMap,
size_t& Process,
int64_t SrcSize
) const override;
/**
* @brief Get the maximum step
* @return Maximum step
*/
[[nodiscard]] int64_t GetMaxStep() const override
{
return MaxStep;
}
/**
* @brief Check if using old version
* @return True if using old version, otherwise false
*/
[[nodiscard]] bool OldVersion() const
{
return OldDiffSvc.get();
}
/**
* @brief Get the union svc version
* @return Union svc version
*/
[[nodiscard]] const std::wstring& GetUnionSvcVer() const override
{
return DiffSvcVersion;
}
/**
* @brief Get the number of Mel bins
* @return Number of Mel bins
*/
[[nodiscard]] int64_t GetMelBins() const override
{
return MelBins;
}
/**
* @brief Normalize Mel spectrogram
* @param MelSpec Mel spectrogram data
*/
void NormMel(
DragonianLibSTL::Vector<float>& MelSpec
) const override;
private:
std::shared_ptr<Ort::Session> PreEncoder = nullptr; ///< Pre-encoder
std::shared_ptr<Ort::Session> DiffusionDenoiser = nullptr; ///< Diffusion denoiser
std::shared_ptr<Ort::Session> NoisePredictor = nullptr; ///< Noise predictor
std::shared_ptr<Ort::Session> PostDecoder = nullptr; ///< Post-decoder
std::shared_ptr<Ort::Session> AlphaCumprod = nullptr; ///< Alpha cumulative product
std::shared_ptr<Ort::Session> NaiveModel = nullptr; ///< Naive model
std::shared_ptr<Ort::Session> OldDiffSvc = nullptr; ///< Old diffusion svc
int64_t MelBins = 128; ///< Number of Mel bins
int64_t Pndms = 100; ///< PNDMS value
int64_t MaxStep = 1000; ///< Maximum step
float SpecMin = -12; ///< Minimum spectrogram value
float SpecMax = 2; ///< Maximum spectrogram value
std::wstring DiffSvcVersion = L"DiffSvc"; ///< Diffusion svc version
static inline const std::vector<const char*> nsfInput = { "c", "f0" }; ///< NSF input
static inline const std::vector<const char*> nsfOutput = { "audio" }; ///< NSF output
static inline const std::vector<const char*> DiffInput = { "hubert", "mel2ph", "spk_embed", "f0", "initial_noise", "speedup" }; ///< Diffusion input
static inline const std::vector<const char*> DiffOutput = { "mel_pred", "f0_pred" }; ///< Diffusion output
static inline const std::vector<const char*> afterInput = { "x" }; ///< Post-processing input
static inline const std::vector<const char*> afterOutput = { "mel_out" }; ///< Post-processing output
static inline const std::vector<const char*> naiveOutput = { "mel" }; ///< Naive output
public:
DiffusionSvc(const DiffusionSvc&) = default; ///< Copy constructor
DiffusionSvc(DiffusionSvc&&) = default; ///< Move constructor
DiffusionSvc& operator=(const DiffusionSvc&) = default; ///< Copy assignment operator
DiffusionSvc& operator=(DiffusionSvc&&) = default; ///< Move assignment operator
};
_D_Dragonian_Lib_Lib_Singing_Voice_Conversion_End