automatic f0 setting

This commit is contained in:
wataru 2023-02-15 05:09:38 +09:00
parent f73178b9b0
commit 25a673b66f
2 changed files with 15 additions and 3 deletions

File diff suppressed because one or more lines are too long

View File

@ -1,4 +1,4 @@
import React, { useMemo, useState } from "react"
import React, { useEffect, useMemo, useState } from "react"
import { ClientState } from "@dannadori/voice-changer-client-js";
export type UseSpeakerSettingProps = {
@ -9,6 +9,18 @@ export const useSpeakerSetting = (props: UseSpeakerSettingProps) => {
const [editSpeakerTargetId, setEditSpeakerTargetId] = useState<number>(0)
const [editSpeakerTargetName, setEditSpeakerTargetName] = useState<string>("")
useEffect(() => {
const src = props.clientState.clientSetting.setting.correspondences?.find(x => {
return x.sid == props.clientState.serverSetting.setting.srcId
})
const dst = props.clientState.clientSetting.setting.correspondences?.find(x => {
return x.sid == props.clientState.serverSetting.setting.dstId
})
const recommendedF0Factor = dst && src ? dst.correspondence / src.correspondence : 0
props.clientState.serverSetting.setF0Factor(recommendedF0Factor)
}, [props.clientState.serverSetting.setting.srcId, props.clientState.serverSetting.setting.dstId])
const srcIdRow = useMemo(() => {
const selected = props.clientState.clientSetting.setting.correspondences?.find(x => {
return x.sid == props.clientState.serverSetting.setting.srcId
@ -132,7 +144,7 @@ export const useSpeakerSetting = (props: UseSpeakerSettingProps) => {
<input type="range" className="body-item-input-slider" min="0.1" max="5.0" step="0.1" value={props.clientState.serverSetting.setting.f0Factor} onChange={(e) => {
props.clientState.serverSetting.setF0Factor(Number(e.target.value))
}}></input>
<span className="body-item-input-slider-val">{props.clientState.serverSetting.setting.f0Factor}</span>
<span className="body-item-input-slider-val">{props.clientState.serverSetting.setting.f0Factor.toFixed(1)}</span>
</div>
<div className="body-item-text"></div>
<div className="body-item-text">recommend: {recommendedF0Factor.toFixed(1)}</div>