Skip to content

Commit

Permalink
整理: コアCDLL型付けの切り出し (#843)
Browse files Browse the repository at this point in the history
* Refactor: コアCDLL型付けの切り出し

* Fix: 参照渡しの戻し廃止
  • Loading branch information
tarepan authored Dec 11, 2023
1 parent cc10270 commit 89a8b53
Showing 1 changed file with 61 additions and 29 deletions.
90 changes: 61 additions & 29 deletions voicevox_engine/synthesis_engine/core_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,64 @@ def load_core(core_dir: Path, use_gpu: bool) -> CDLL:
raise RuntimeError(f"このコンピュータのアーキテクチャ {platform.machine()} で利用可能なコアがありません")


def _type_yukarin_s_forward(core_cdll: CDLL) -> None:
"""
コアDLL `yukarin_s_forward` 関数の型付け
Parameters
----------
core_cdll : CDLL
コアDLL
"""
core_cdll.yukarin_s_forward.argtypes = (
c_int,
POINTER(c_long),
POINTER(c_long),
POINTER(c_float),
)
core_cdll.yukarin_s_forward.restype = c_bool


def _type_yukarin_sa_forward(core_cdll: CDLL) -> None:
"""
コアDLL `yukarin_sa_forward` 関数の型付け
Parameters
----------
core_cdll : CDLL
コアDLL
"""
core_cdll.yukarin_sa_forward.argtypes = (
c_int,
POINTER(c_long),
POINTER(c_long),
POINTER(c_long),
POINTER(c_long),
POINTER(c_long),
POINTER(c_long),
POINTER(c_long),
POINTER(c_float),
)
core_cdll.yukarin_sa_forward.restype = c_bool


def _type_decode_forward(core_cdll: CDLL) -> None:
"""
コアDLL `decode_forward` 関数の型付け
Parameters
----------
core_cdll : CDLL
コアDLL
"""
core_cdll.decode_forward.argtypes = (
c_int,
c_int,
POINTER(c_float),
POINTER(c_float),
POINTER(c_long),
POINTER(c_float),
)
core_cdll.decode_forward.restype = c_bool


class CoreWrapper:
def __init__(
self,
Expand All @@ -393,9 +451,9 @@ def __init__(

self.core.initialize.restype = c_bool
self.core.metas.restype = c_char_p
self.core.yukarin_s_forward.restype = c_bool
self.core.yukarin_sa_forward.restype = c_bool
self.core.decode_forward.restype = c_bool
_type_yukarin_s_forward(self.core)
_type_yukarin_sa_forward(self.core)
_type_decode_forward(self.core)
self.core.last_error_message.restype = c_char_p

self.exist_supported_devices = False
Expand Down Expand Up @@ -426,32 +484,6 @@ def __init__(
self.exist_finalize = True
exist_cpu_num_threads = True

self.core.yukarin_s_forward.argtypes = (
c_int,
POINTER(c_long),
POINTER(c_long),
POINTER(c_float),
)
self.core.yukarin_sa_forward.argtypes = (
c_int,
POINTER(c_long),
POINTER(c_long),
POINTER(c_long),
POINTER(c_long),
POINTER(c_long),
POINTER(c_long),
POINTER(c_long),
POINTER(c_float),
)
self.core.decode_forward.argtypes = (
c_int,
c_int,
POINTER(c_float),
POINTER(c_float),
POINTER(c_long),
POINTER(c_float),
)

cwd = os.getcwd()
os.chdir(core_dir)
try:
Expand Down

0 comments on commit 89a8b53

Please sign in to comment.